From aee5b981801aaa1bd458649c91d078a661d426b4 Mon Sep 17 00:00:00 2001 From: Pablo Castellanos Date: Mon, 20 Mar 2023 14:33:14 -0300 Subject: [PATCH 1/4] Added feature step chart --- charts/feature-step/.helmignore | 23 ++++ charts/feature-step/Chart.yaml | 6 + charts/feature-step/templates/_helpers.tpl | 68 +++++++++++ charts/feature-step/templates/configmap.yaml | 13 ++ charts/feature-step/templates/deployment.yaml | 113 ++++++++++++++++++ charts/feature-step/templates/hpa.yaml | 28 +++++ charts/feature-step/templates/namespace.yaml | 6 + charts/feature-step/templates/secret.yaml | 26 ++++ charts/feature-step/templates/service.yaml | 15 +++ charts/feature-step/values.yaml | 67 +++++++++++ 10 files changed, 365 insertions(+) create mode 100644 charts/feature-step/.helmignore create mode 100644 charts/feature-step/Chart.yaml create mode 100644 charts/feature-step/templates/_helpers.tpl create mode 100644 charts/feature-step/templates/configmap.yaml create mode 100644 charts/feature-step/templates/deployment.yaml create mode 100644 charts/feature-step/templates/hpa.yaml create mode 100644 charts/feature-step/templates/namespace.yaml create mode 100644 charts/feature-step/templates/secret.yaml create mode 100644 charts/feature-step/templates/service.yaml create mode 100644 charts/feature-step/values.yaml diff --git a/charts/feature-step/.helmignore b/charts/feature-step/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/feature-step/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/feature-step/Chart.yaml b/charts/feature-step/Chart.yaml new file mode 100644 index 0000000..341f7e9 --- /dev/null +++ b/charts/feature-step/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +appVersion: "rc" +description: Step for feature calculation +name: feature-step +type: application +version: 0.1.0 diff --git a/charts/feature-step/templates/_helpers.tpl b/charts/feature-step/templates/_helpers.tpl new file mode 100644 index 0000000..4ef25fe --- /dev/null +++ b/charts/feature-step/templates/_helpers.tpl @@ -0,0 +1,68 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "feature-step.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "feature-step.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "feature-step.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "feature-step.labels" -}} +helm.sh/chart: {{ include "feature-step.chart" . }} +{{ include "feature-step.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "feature-step.selectorLabels" -}} +app.kubernetes.io/name: {{ include "feature-step.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "feature-step.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "feature-step.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{- define "imagePullSecret" }} +{{- with .Values.imageCredentials }} +{{- printf "{\"auths\":{\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}}}" .registry .username .password .email (printf "%s:%s" .username .password | b64enc) | b64enc }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/feature-step/templates/configmap.yaml b/charts/feature-step/templates/configmap.yaml new file mode 100644 index 0000000..c73918f --- /dev/null +++ b/charts/feature-step/templates/configmap.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "feature-step.fullname" . }} + namespace: {{ .Values.namespace }} +data: + consumer-topics: {{ .Values.configmap.consumerTopics }} + internal-server: {{ .Values.configmap.internalServer }} + producer-topic: {{ .Values.configmap.producerTopic }} + db-engine: {{ .Values.configmap.dbEngine }} + db-host: {{ .Values.configmap.dbHost }} + db-port: "{{ .Values.configmap.dbPort }}" + db-name: {{ .Values.configmap.dbName }} diff --git a/charts/feature-step/templates/deployment.yaml b/charts/feature-step/templates/deployment.yaml new file mode 100644 index 0000000..a876d18 --- /dev/null +++ b/charts/feature-step/templates/deployment.yaml @@ -0,0 +1,113 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "feature-step.fullname" . }} + namespace: {{ .Values.namespace }} + labels: + {{- include "feature-step.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "feature-step.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "feature-step.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: metrics + containerPort: 8000 + protocol: TCP + resources: + {{- toYaml .Values.resources | nindent 12 }} + env: + - name: CONSUMER_TOPICS + valueFrom: + configMapKeyRef: + name: {{ include "feature-step.fullname" . }} + key: consumer-topics + - name: CONSUMER_SERVER + valueFrom: + configMapKeyRef: + name: {{ include "feature-step.fullname" . }} + key: internal-server + - name: CONSUMER_GROUP_ID + value: {{ include "feature-step.fullname" . }} + - name: PRODUCER_SERVER + valueFrom: + configMapKeyRef: + name: {{ include "feature-step.fullname" . }} + key: internal-server + - name: PRODUCER_TOPIC + valueFrom: + configMapKeyRef: + name: {{ include "feature-step.fullname" . }} + key: producer-topic + - name: METRICS_HOST + valueFrom: + configMapKeyRef: + name: {{ include "feature-step.fullname" . }} + key: internal-server + - name: METRICS_TOPIC + value: "metrics" + - name: DB_ENGINE + valueFrom: + configMapKeyRef: + name: {{ include "lc-classifier-step.fullname" . }} + key: db-engine + - name: DB_HOST + valueFrom: + configMapKeyRef: + name: {{ include "lc-classifier-step.fullname" . }} + key: db-host + - name: DB_PORT + valueFrom: + configMapKeyRef: + name: {{ include "lc-classifier-step.fullname" . }} + key: db-port + - name: DB_NAME + valueFrom: + configMapKeyRef: + name: {{ include "lc-classifier-step.fullname" . }} + key: db-name + - name: DB_USER + valueFrom: + secretKeyRef: + name: '{{ include "lc-classifier-step.fullname" . }}-db' + key: username + - name: DB_PASSWORD + valueFrom: + secretKeyRef: + name: '{{ include "lc-classifier-step.fullname" . }}-db' + key: password + {{- if .Values.secrets.kafkaAuth.enabled }} + - name: KAFKA_USERNAME + valueFrom: + secretKeyRef: + name: kafka-auth + key: username + - name: KAFKA_PASSWORD + valueFrom: + secretKeyRef: + name: kafka-auth + key: password + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/feature-step/templates/hpa.yaml b/charts/feature-step/templates/hpa.yaml new file mode 100644 index 0000000..b5cf6ee --- /dev/null +++ b/charts/feature-step/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "feature-step.fullname" . }} + labels: + {{- include "feature-step.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "feature-step.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/feature-step/templates/namespace.yaml b/charts/feature-step/templates/namespace.yaml new file mode 100644 index 0000000..4df0747 --- /dev/null +++ b/charts/feature-step/templates/namespace.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: {{ .Values.namespace }} + labels: + name: {{ .Values.namespace }} \ No newline at end of file diff --git a/charts/feature-step/templates/secret.yaml b/charts/feature-step/templates/secret.yaml new file mode 100644 index 0000000..6acc7ee --- /dev/null +++ b/charts/feature-step/templates/secret.yaml @@ -0,0 +1,26 @@ +apiVersion: v1 +kind: Secret +metadata: + name: '{{ include "lc-classifier-step.fullname" . }}-db' + namespace: {{ .Values.namespace }} +stringData: + username: {{ .Values.secrets.db.username }} + password: {{ .Values.secrets.db.password }} +--- +apiVersion: v1 +kind: Secret +metadata: + name: image-pull-access + namespace: {{ .Values.namespace }} +type: kubernetes.io/dockerconfigjson +data: + .dockerconfigjson: {{ template "imagePullSecret" . }} +--- +apiVersion: v1 +kind: Secret +metadata: + name: kafka-auth + namespace: {{ .Values.namespace }} +stringData: + username: {{ .Values.secrets.kafkaAuth.username }} + password: {{ .Values.secrets.kafkaAuth.password }} diff --git a/charts/feature-step/templates/service.yaml b/charts/feature-step/templates/service.yaml new file mode 100644 index 0000000..eb66980 --- /dev/null +++ b/charts/feature-step/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "feature-step.fullname" . }} + labels: + {{- include "feature-step.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "feature-step.selectorLabels" . | nindent 4 }} diff --git a/charts/feature-step/values.yaml b/charts/feature-step/values.yaml new file mode 100644 index 0000000..5346282 --- /dev/null +++ b/charts/feature-step/values.yaml @@ -0,0 +1,67 @@ +# Default values for step_starter. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +namespace: feature-step + +image: + repository: ghcr.io/alercebroker/feature-step + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: + - name: "image-pull-access" +nameOverride: "" +fullnameOverride: "" + +podAnnotations: {} + +service: + type: ClusterIP + port: 8000 + +resources: {} + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: eks.amazonaws.com/nodegroup + operator: In + ## Override this value with the NodeGroup tag accordingly + values: [] + +configmap: + consumerTopics: "" + internalServer: "" + producerTopic: "" + dbEngine: "" + dbHost: "" + dbPort: "" + dbName: "" + +secrets: + db: + username: "" + password: "" + kafkaAuth: + enabled: false + username: "" + password: "" + +imageCredentials: + registry: "" + username: "" + password: "" + email: "" From 75e10e2ebea03a67a3f1755f73344be0096def38 Mon Sep 17 00:00:00 2001 From: Pablo Castellanos Date: Mon, 20 Mar 2023 14:48:42 -0300 Subject: [PATCH 2/4] Using always as pull policy --- charts/feature-step/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/feature-step/values.yaml b/charts/feature-step/values.yaml index 5346282..23896e6 100644 --- a/charts/feature-step/values.yaml +++ b/charts/feature-step/values.yaml @@ -8,7 +8,7 @@ namespace: feature-step image: repository: ghcr.io/alercebroker/feature-step - pullPolicy: IfNotPresent + pullPolicy: Always # Overrides the image tag whose default is the chart appVersion. tag: "" From e2bebacd28f45cca35968368ac7f758e6c25418d Mon Sep 17 00:00:00 2001 From: Pablo Castellanos Date: Mon, 20 Mar 2023 14:58:26 -0300 Subject: [PATCH 3/4] fix: wrong chart name in options --- charts/feature-step/templates/deployment.yaml | 12 ++++++------ charts/feature-step/templates/secret.yaml | 2 +- charts/feature-step/values.yaml | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/charts/feature-step/templates/deployment.yaml b/charts/feature-step/templates/deployment.yaml index a876d18..e5337ea 100644 --- a/charts/feature-step/templates/deployment.yaml +++ b/charts/feature-step/templates/deployment.yaml @@ -68,32 +68,32 @@ spec: - name: DB_ENGINE valueFrom: configMapKeyRef: - name: {{ include "lc-classifier-step.fullname" . }} + name: {{ include "feature-step.fullname" . }} key: db-engine - name: DB_HOST valueFrom: configMapKeyRef: - name: {{ include "lc-classifier-step.fullname" . }} + name: {{ include "feature-step.fullname" . }} key: db-host - name: DB_PORT valueFrom: configMapKeyRef: - name: {{ include "lc-classifier-step.fullname" . }} + name: {{ include "feature-step.fullname" . }} key: db-port - name: DB_NAME valueFrom: configMapKeyRef: - name: {{ include "lc-classifier-step.fullname" . }} + name: {{ include "feature-step.fullname" . }} key: db-name - name: DB_USER valueFrom: secretKeyRef: - name: '{{ include "lc-classifier-step.fullname" . }}-db' + name: '{{ include "feature-step.fullname" . }}-db' key: username - name: DB_PASSWORD valueFrom: secretKeyRef: - name: '{{ include "lc-classifier-step.fullname" . }}-db' + name: '{{ include "feature-step.fullname" . }}-db' key: password {{- if .Values.secrets.kafkaAuth.enabled }} - name: KAFKA_USERNAME diff --git a/charts/feature-step/templates/secret.yaml b/charts/feature-step/templates/secret.yaml index 6acc7ee..84ddd1e 100644 --- a/charts/feature-step/templates/secret.yaml +++ b/charts/feature-step/templates/secret.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: Secret metadata: - name: '{{ include "lc-classifier-step.fullname" . }}-db' + name: '{{ include "feature-step.fullname" . }}-db' namespace: {{ .Values.namespace }} stringData: username: {{ .Values.secrets.db.username }} diff --git a/charts/feature-step/values.yaml b/charts/feature-step/values.yaml index 23896e6..5cf192c 100644 --- a/charts/feature-step/values.yaml +++ b/charts/feature-step/values.yaml @@ -7,7 +7,7 @@ replicaCount: 1 namespace: feature-step image: - repository: ghcr.io/alercebroker/feature-step + repository: ghcr.io/alercebroker/feature_step pullPolicy: Always # Overrides the image tag whose default is the chart appVersion. tag: "" From 02cac31ed10c4afa81f805f295fab67b987e159f Mon Sep 17 00:00:00 2001 From: Pablo Castellanos Date: Mon, 20 Mar 2023 15:11:05 -0300 Subject: [PATCH 4/4] Added variables for step/feature version --- charts/feature-step/templates/configmap.yaml | 2 ++ charts/feature-step/templates/deployment.yaml | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/charts/feature-step/templates/configmap.yaml b/charts/feature-step/templates/configmap.yaml index c73918f..2ab93f9 100644 --- a/charts/feature-step/templates/configmap.yaml +++ b/charts/feature-step/templates/configmap.yaml @@ -7,6 +7,8 @@ data: consumer-topics: {{ .Values.configmap.consumerTopics }} internal-server: {{ .Values.configmap.internalServer }} producer-topic: {{ .Values.configmap.producerTopic }} + feature-version: {{ .Values.configmap.featureVersion }} + step-version: {{ .Values.configmap.stepVersion }} db-engine: {{ .Values.configmap.dbEngine }} db-host: {{ .Values.configmap.dbHost }} db-port: "{{ .Values.configmap.dbPort }}" diff --git a/charts/feature-step/templates/deployment.yaml b/charts/feature-step/templates/deployment.yaml index e5337ea..1734a57 100644 --- a/charts/feature-step/templates/deployment.yaml +++ b/charts/feature-step/templates/deployment.yaml @@ -65,6 +65,16 @@ spec: key: internal-server - name: METRICS_TOPIC value: "metrics" + - name: FEATURE_VERSION + valueFrom: + configMapKeyRef: + name: {{ include "feature-step.fullname" . }} + key: feature-version + - name: STEP_VERSION + valueFrom: + configMapKeyRef: + name: {{ include "feature-step.fullname" . }} + key: step-version - name: DB_ENGINE valueFrom: configMapKeyRef: