Skip to content

Commit

Permalink
Merge pull request #53 from kube-tarian/climon-separate
Browse files Browse the repository at this point in the history
climon made separate
  • Loading branch information
share2kanna committed Jan 31, 2023
2 parents 1603b1f + 828161a commit 9cf27ec
Show file tree
Hide file tree
Showing 63 changed files with 1,514 additions and 257 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/climon-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Climon Docker Image CI

on:
push:
paths-ignore:
- 'charts/**'
- '**.md'
branches: [ main ]
pull_request:
paths-ignore:
- 'helm/**'
- '**.md'
branches: [ main ]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build . --file dockerfiles/climon/Dockerfile --tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/climon:latest
- name: Docker push
run: |
docker login ${{ env.REGISTRY }} -u jebinjeb -p ${{ secrets.GITHUB_TOKEN }}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/climon:latest
if: github.event_name == 'push'
2 changes: 1 addition & 1 deletion .github/workflows/config-worker-docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Client Docker Image CI
name: Config worker Docker Image CI

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deployment-worker-docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Client Docker Image CI
name: Deployment worker Docker Image CI

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/server-docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Client Docker Image CI
name: Server Docker Image CI

on:
push:
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SERVER_APP_NAME := server
AGENT_APP_NAME := agent
DEPLOYMENT_WORKER_APP_NAME := deployment-worker
CONFIG_WORKER_APP_NAME := config-worker
CLIMON_APP_NAME := climon
BUILD := 0.1.1

gen-protoc:
Expand Down Expand Up @@ -37,4 +38,7 @@ docker-build-deployment:
docker-build-config:
docker build -f dockerfiles/config-worker/Dockerfile -t ${PREFIX}-${CONFIG_WORKER_APP_NAME}:${BUILD} .

docker-build: docker-build-kad docker-build-server
docker-build-climon:
docker build -f dockerfiles/climon/Dockerfile -t ${PREFIX}-${CLIMON_APP_NAME}:${BUILD} .

docker-build: docker-build-kad docker-build-server docker-build-climon
2 changes: 1 addition & 1 deletion charts/kad/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.12
version: 0.1.13

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
89 changes: 89 additions & 0 deletions charts/kad/templates/climon-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "kad.fullname" . }}-climon
labels:
{{- include "kad.labels" . | nindent 4 }}
app.kubernetes.io/component: climon
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "kad.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: climon
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "kad.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: climon
spec:
serviceAccountName: {{ include "kad.serviceAccountName" . }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}-climon
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.climon.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
livenessProbe:
httpGet:
path: /status
port: http
readinessProbe:
httpGet:
path: /status
port: http
env:
- name: TEMPORAL_SERVICE_URL
value: "{{ .Values.temporal.temporalServiceURL }}.{{ .Release.Namespace }}.svc.cluster.local:7233"
- name: PORT
value: "{{ .Values.service.port }}"
- name: CASSANDRA_SERVICE_URL
value: "{{ .Values.cassandra.serviceURL }}"
- name: CASSANDRA_KEYSPACE_NAME
value: "{{ .Values.cassandra.keyspaceName }}"
- name: CASSANDRA_TABLE_NAME
value: "{{ .Values.cassandra.name }}"
- name: CASSANDRA_USERNAME
value: "{{ .Values.cassandra.username }}"
- name: CASSANDRA_PASSWORD
value: "{{ .Values.cassandra.password }}"
# valueFrom:
# secretKeyRef:
# name: "{{ .Values.cassandra.secretName }}"
# key: "password"
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- mountPath: /tmp
name: tmp-volume
volumes:
- name: tmp-volume
emptyDir: {}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
2 changes: 1 addition & 1 deletion charts/kad/templates/cluster-role-binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ subjects:
namespace: {{ .Release.Namespace }}
roleRef:
kind: ClusterRole
name: {{ include "kad.fullname" . }}
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
36 changes: 18 additions & 18 deletions charts/kad/templates/cluster-role.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "kad.fullname" . }}
rules:
- apiGroups: ["*"]
#
# at the HTTP level, the name of the resource for accessing Secret
# objects is "secrets"
resources: ["*"]
verbs:
- get
- list
- watch
- create
- update
- patch
- delete
# apiVersion: rbac.authorization.k8s.io/v1
# kind: ClusterRole
# metadata:
# name: {{ include "kad.fullname" . }}
# rules:
# - apiGroups: ["*"]
# #
# # at the HTTP level, the name of the resource for accessing Secret
# # objects is "secrets"
# resources: ["*"]
# verbs:
# - get
# - list
# - watch
# - create
# - update
# - patch
# - delete

4 changes: 3 additions & 1 deletion charts/kad/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ deployment_worker:
repository: ghcr.io/kube-tarian/kad/deployment-worker
config_worker:
repository: ghcr.io/kube-tarian/kad/config-worker
climon:
repository: ghcr.io/kube-tarian/kad/climon

imagePullSecrets: []
nameOverride: ""
Expand Down Expand Up @@ -92,6 +94,6 @@ argocd:
cassandra:
username: user
secretName: "temporal-default-store"
serviceURL: "temporal-cassandra.default.svc.cluster"
serviceURL: "temporal-cassandra"
keyspaceName: "capten"
tableName: "tools"
2 changes: 1 addition & 1 deletion charts/server/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.8
version: 0.1.9

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
13 changes: 13 additions & 0 deletions dockerfiles/climon/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:1.19.4 AS builder
WORKDIR /
COPY ./integrator ./
RUN rm -rf vendor

RUN go mod download
RUN CGO_ENABLED=0 go build -o ./build/climon climon/main.go

FROM scratch
COPY --from=builder ./build/climon climon

USER 65532:65532
ENTRYPOINT ["./climon"]
5 changes: 2 additions & 3 deletions dockerfiles/deployment-worker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ COPY ./integrator ./
RUN rm -rf vendor

RUN go mod download
RUN go build -o ./build/deployment-worker deployment-worker/main.go
RUN CGO_ENABLED=0 go build -o ./build/deployment-worker deployment-worker/main.go

FROM alpine:3.16
RUN apk add --no-cache libc6-compat
FROM scratch
COPY --from=builder ./build/deployment-worker deployment-worker

USER 65532:65532
Expand Down
1 change: 1 addition & 0 deletions integrator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ build:
go mod download
CGO_ENABLED=0 go build -o build/deployment_worker deployment-worker/main.go
CGO_ENABLED=0 go build -o build/config_worker config-worker/main.go
CGO_ENABLED=0 go build -o build/climon climon/main.go
CGO_ENABLED=0 go build -o build/agent agent/cmd/agent/main.go

clean:
Expand Down
2 changes: 1 addition & 1 deletion integrator/agent/pkg/server/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (a *Agent) SubmitJob(ctx context.Context, request *agentpb.JobRequest) (*ag
func (a *Agent) getWorker(operatoin string) (workers.Worker, error) {
switch operatoin {
case "climon":
return workers.NewClimon(a.client), nil
return workers.NewClimon(a.client, a.log), nil
case "deployment":
return workers.NewDeployment(a.client, a.log), nil
case "config":
Expand Down
59 changes: 54 additions & 5 deletions integrator/agent/pkg/workers/climon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,33 @@ package workers
import (
"context"
"encoding/json"
"fmt"
"log"
"time"

"github.com/kube-tarian/kad/integrator/agent/pkg/model"
"github.com/kube-tarian/kad/integrator/agent/pkg/temporalclient"
"github.com/kube-tarian/kad/integrator/common-pkg/logging"
"go.temporal.io/sdk/client"
)

type climon struct {
type Climon struct {
client *temporalclient.Client
log logging.Logger
}

func NewClimon(client *temporalclient.Client) *climon {
return &climon{
func NewClimon(client *temporalclient.Client, log logging.Logger) *Climon {
return &Climon{
client: client,
log: log,
}
}

func (c *climon) GetWorkflowName() string {
func (c *Climon) GetWorkflowName() string {
return DeployWorkflowName
}

func (c *climon) SendEvent(ctx context.Context, deployPayload json.RawMessage) (client.WorkflowRun, error) {
func (c *Climon) SendEvent(ctx context.Context, deployPayload json.RawMessage) (client.WorkflowRun, error) {
options := client.StartWorkflowOptions{
ID: "helm-deploy-workflow",
TaskQueue: ClimonHelmTaskQueue,
Expand All @@ -48,5 +54,48 @@ func (c *climon) SendEvent(ctx context.Context, deployPayload json.RawMessage) (
}
//printResults(deployInfo, we.GetID(), we.GetRunID())

c.log.Infof("Started workflow, ID: %v, WorkflowName: %v RunID: %v", we.GetID(), DeploymentWorkerWorkflowName, we.GetRunID())

// Wait for 5mins till workflow finishes
// Timeout with 5mins
var result model.ResponsePayload
err = we.Get(ctx, &result)
if err != nil {
c.log.Errorf("Result for workflow ID: %v, workflowName: %v, runID: %v", we.GetID(), DeploymentWorkerWorkflowName, we.GetRunID())
c.log.Errorf("Workflow result failed, %v", err)
return we, err
}
c.log.Infof("workflow finished success, %+v", result.ToString())

return we, nil
}

func (d *Climon) getWorkflowStatusByLatestWorkflow(run client.WorkflowRun) error {
ticker := time.NewTicker(500 * time.Millisecond)
for {
select {
case <-ticker.C:
err := d.getWorkflowInformation(run)
if err != nil {
d.log.Errorf("get state of workflow failed: %v, retrying .....", err)
continue
}
return nil
case <-time.After(5 * time.Minute):
d.log.Errorf("Timed out waiting for state of workflow")
return fmt.Errorf("timedout waiting for the workflow to finish")
}
}
}

func (d *Climon) getWorkflowInformation(run client.WorkflowRun) error {
latestRun := d.client.TemporalClient.GetWorkflow(context.Background(), run.GetID(), "")

var result model.ResponsePayload
if err := latestRun.Get(context.Background(), &result); err != nil {
d.log.Errorf("Unable to decode query result", err)
return err
}
d.log.Debugf("Result info: %+v", result)
return nil
}
2 changes: 1 addition & 1 deletion integrator/agent/pkg/workers/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

const (
ClimonHelmTaskQueue = "CLIMON_HELM_TASK_QUEUE"
DeployWorkflowName = "DeployApp"
DeployWorkflowName = "Workflow"
)

type Worker interface {
Expand Down
12 changes: 12 additions & 0 deletions integrator/climon/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.19 AS builder
WORKDIR /
COPY ./ ./

RUN go mod download
RUN CGO_ENABLED=0 go build -o ./build/climon climon/main.go

FROM scratch
COPY --from=builder ./build/climon climon

USER 65532:65532
ENTRYPOINT ["./climon"]
Loading

0 comments on commit 9cf27ec

Please sign in to comment.