From 0b8930536df613691fd137cbbc59bb89fa1b829f Mon Sep 17 00:00:00 2001 From: Greg Schohn Date: Thu, 31 Oct 2024 00:09:30 -0400 Subject: [PATCH] Cleanup to refactor the common helm helpers and to try to support installing the capture proxy by itself. Signed-off-by: Greg Schohn --- deployment/k8s/.gitignore | 1 + .../mockCustomerClusters/Chart.lock | 12 ++++++++++ .../mockCustomerClusters/Chart.yaml | 2 +- .../mockCustomerClusters/charts/captureProxy | 1 + .../charts/components/captureProxy/Chart.yaml | 4 ++++ .../captureProxy/charts/helm-common | 1 + .../{proxyService.yaml => deployment.yaml} | 18 ++------------ .../captureProxy/templates/service.yaml | 13 ++++++++++ .../components/captureProxy/values.yaml | 10 +++++++- .../charts/components/helm-common/.helmignore | 23 ++++++++++++++++++ .../charts/components/helm-common/Chart.yaml | 5 ++++ .../templates/_command.tpl | 4 ++-- .../_createConfigMapsForParameters.tpl | 4 ++-- .../templates/_createNamespace.tpl | 0 .../templates/_helpers.tpl | 0 .../_pullEnvVariablesFromConfigMap.tpl | 12 ++++++---- .../templates/_toSnakeCase.tpl | 0 .../helmValues/localTesting/captureProxy.yaml | 5 ++-- .../sourceElasticsearchCluster.yaml | 24 ++++++++++--------- .../localTesting/targetOpenSearchCluster.yaml | 13 +++++----- 20 files changed, 105 insertions(+), 47 deletions(-) create mode 100644 deployment/k8s/.gitignore create mode 100644 deployment/k8s/charts/aggregates/mockCustomerClusters/Chart.lock rename deployment/k8s/charts/{ => aggregates}/mockCustomerClusters/Chart.yaml (87%) create mode 120000 deployment/k8s/charts/aggregates/mockCustomerClusters/charts/captureProxy create mode 120000 deployment/k8s/charts/components/captureProxy/charts/helm-common rename deployment/k8s/charts/components/captureProxy/templates/{proxyService.yaml => deployment.yaml} (59%) create mode 100644 deployment/k8s/charts/components/captureProxy/templates/service.yaml create mode 100644 deployment/k8s/charts/components/helm-common/.helmignore create mode 100644 deployment/k8s/charts/components/helm-common/Chart.yaml rename deployment/k8s/charts/components/{captureProxy => helm-common}/templates/_command.tpl (90%) rename deployment/k8s/charts/components/{captureProxy => helm-common}/templates/_createConfigMapsForParameters.tpl (88%) rename deployment/k8s/charts/components/{captureProxy => helm-common}/templates/_createNamespace.tpl (100%) rename deployment/k8s/charts/components/{captureProxy => helm-common}/templates/_helpers.tpl (100%) rename deployment/k8s/charts/components/{captureProxy => helm-common}/templates/_pullEnvVariablesFromConfigMap.tpl (64%) rename deployment/k8s/charts/components/{captureProxy => helm-common}/templates/_toSnakeCase.tpl (100%) diff --git a/deployment/k8s/.gitignore b/deployment/k8s/.gitignore new file mode 100644 index 000000000..9060bbfc1 --- /dev/null +++ b/deployment/k8s/.gitignore @@ -0,0 +1 @@ +**/charts/*.tgz \ No newline at end of file diff --git a/deployment/k8s/charts/aggregates/mockCustomerClusters/Chart.lock b/deployment/k8s/charts/aggregates/mockCustomerClusters/Chart.lock new file mode 100644 index 000000000..0e9542e94 --- /dev/null +++ b/deployment/k8s/charts/aggregates/mockCustomerClusters/Chart.lock @@ -0,0 +1,12 @@ +dependencies: +- name: elasticsearch + repository: https://helm.elastic.co + version: 8.5.1 +- name: capture-proxy + repository: file://../../components/captureProxy + version: 0.1.0 +- name: opensearch + repository: https://opensearch-project.github.io/helm-charts/ + version: 2.23.1 +digest: sha256:4a32b1cb130067ad9ac20d5e12caaab2dcf4463bce2b214bc87107f407a2f592 +generated: "2024-10-28T23:14:40.432564-04:00" diff --git a/deployment/k8s/charts/mockCustomerClusters/Chart.yaml b/deployment/k8s/charts/aggregates/mockCustomerClusters/Chart.yaml similarity index 87% rename from deployment/k8s/charts/mockCustomerClusters/Chart.yaml rename to deployment/k8s/charts/aggregates/mockCustomerClusters/Chart.yaml index a22482d51..f10e4036b 100644 --- a/deployment/k8s/charts/mockCustomerClusters/Chart.yaml +++ b/deployment/k8s/charts/aggregates/mockCustomerClusters/Chart.yaml @@ -8,7 +8,7 @@ dependencies: alias: source - name: capture-proxy version: "0.1.0" - repository: file://../captureProxy + repository: file://../../components/captureProxy alias: proxy - name: opensearch version: "2.23.1" diff --git a/deployment/k8s/charts/aggregates/mockCustomerClusters/charts/captureProxy b/deployment/k8s/charts/aggregates/mockCustomerClusters/charts/captureProxy new file mode 120000 index 000000000..09f689d81 --- /dev/null +++ b/deployment/k8s/charts/aggregates/mockCustomerClusters/charts/captureProxy @@ -0,0 +1 @@ +../../../components/captureProxy \ No newline at end of file diff --git a/deployment/k8s/charts/components/captureProxy/Chart.yaml b/deployment/k8s/charts/components/captureProxy/Chart.yaml index 6c94eac68..3cee6b456 100644 --- a/deployment/k8s/charts/components/captureProxy/Chart.yaml +++ b/deployment/k8s/charts/components/captureProxy/Chart.yaml @@ -1,3 +1,7 @@ apiVersion: v2 name: capture-proxy version: 0.1.0 +dependencies: + - name: helm-common + repository: file://../helm-common + version: 0.1.0 \ No newline at end of file diff --git a/deployment/k8s/charts/components/captureProxy/charts/helm-common b/deployment/k8s/charts/components/captureProxy/charts/helm-common new file mode 120000 index 000000000..cc1d6ac60 --- /dev/null +++ b/deployment/k8s/charts/components/captureProxy/charts/helm-common @@ -0,0 +1 @@ +../../helm-common \ No newline at end of file diff --git a/deployment/k8s/charts/components/captureProxy/templates/proxyService.yaml b/deployment/k8s/charts/components/captureProxy/templates/deployment.yaml similarity index 59% rename from deployment/k8s/charts/components/captureProxy/templates/proxyService.yaml rename to deployment/k8s/charts/components/captureProxy/templates/deployment.yaml index 25cba70ea..fbac90a41 100644 --- a/deployment/k8s/charts/components/captureProxy/templates/proxyService.yaml +++ b/deployment/k8s/charts/components/captureProxy/templates/deployment.yaml @@ -19,25 +19,11 @@ spec: image: migrations/capture_proxy:latest imagePullPolicy: IfNotPresent env: - {{ include "generic.pullEnvVarsFromConfigMaps" (dict "PackageName" (include "generic.fullname" .) "Values" .Values "include" .Template.Include "Template" .Template) | indent 10 }} + {{- include "generic.pullEnvVarsFromConfigMaps" (dict "NameSpace" (include "generic.fullname" .) "Parameters" .Values.parameters "include" .Template.Include "Template" .Template) | indent 10 }} command: - "/bin/sh" - "-c" - | - {{- include "generic.buildCommandBuilderScript" (dict "Command" "/runJavaWithClasspath.sh org.opensearch.migrations.trafficcapture.proxyserver.CaptureProxy" "PackageName" (include "generic.fullname" .) "Values" .Values "include" .Template.Include "Template" .Template) | nindent 14 }} + {{- include "generic.buildCommandBuilderScript" (dict "Command" "/runJavaWithClasspath.sh org.opensearch.migrations.trafficcapture.proxyserver.CaptureProxy" "PackageName" (include "generic.fullname" .) "Parameters" .Values.parameters "include" .Template.Include "Template" .Template) | nindent 14 }} ports: - containerPort: 9200 ---- -apiVersion: v1 -kind: Service -metadata: - name: {{ include "generic.fullname" . }} -spec: - selector: - app: {{ include "generic.fullname" . }} - env: v1 - ports: - - protocol: TCP - port: 9200 - targetPort: 9200 - type: ClusterIP diff --git a/deployment/k8s/charts/components/captureProxy/templates/service.yaml b/deployment/k8s/charts/components/captureProxy/templates/service.yaml new file mode 100644 index 000000000..216ffd61d --- /dev/null +++ b/deployment/k8s/charts/components/captureProxy/templates/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "generic.fullname" . }} +spec: + selector: + app: {{ include "generic.fullname" . }} + env: v1 + ports: + - protocol: TCP + port: 9200 + targetPort: 9200 + type: ClusterIP diff --git a/deployment/k8s/charts/components/captureProxy/values.yaml b/deployment/k8s/charts/components/captureProxy/values.yaml index 2281230b4..62a74197e 100644 --- a/deployment/k8s/charts/components/captureProxy/values.yaml +++ b/deployment/k8s/charts/components/captureProxy/values.yaml @@ -1,6 +1,5 @@ nameOverride: "" fullnameOverride: "" -protectedParameterNamespace: "baseline" # Set to true if you want the chart to create the namespace createNamespace: true # Optional: specify namespace name (defaults to .Release.Namespace) @@ -19,9 +18,18 @@ parameters: noCapture: present: false allowRuntimeOverride: true + kafkaBrokersList: + list: + - kafka1 + - kafka2 insecureDestination: present: true allowRuntimeOverride: false + + # Proxy... --destinationUri "http://destination:9200" --listenPort 9200 --noCapture --kafkaBrokersList kafka1 kafka2 --insecureDestination + + + # TODO - setup cert management # sslConfigFile: # value: "/usr/share/elasticsearch/config/proxy_tls.yml" diff --git a/deployment/k8s/charts/components/helm-common/.helmignore b/deployment/k8s/charts/components/helm-common/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/deployment/k8s/charts/components/helm-common/.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/deployment/k8s/charts/components/helm-common/Chart.yaml b/deployment/k8s/charts/components/helm-common/Chart.yaml new file mode 100644 index 000000000..d7f0027c2 --- /dev/null +++ b/deployment/k8s/charts/components/helm-common/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v2 +name: helm-common +version: 0.1.0 +description: A common library for the Migration Assistant +type: library diff --git a/deployment/k8s/charts/components/captureProxy/templates/_command.tpl b/deployment/k8s/charts/components/helm-common/templates/_command.tpl similarity index 90% rename from deployment/k8s/charts/components/captureProxy/templates/_command.tpl rename to deployment/k8s/charts/components/helm-common/templates/_command.tpl index 8675fe5e6..7a62919a4 100644 --- a/deployment/k8s/charts/components/captureProxy/templates/_command.tpl +++ b/deployment/k8s/charts/components/helm-common/templates/_command.tpl @@ -3,7 +3,7 @@ set -e CMD="{{ .Command }}" {{- /* Default environment variables if not set */}} -{{- range $key, $param := .Values.parameters }} +{{- range $key, $param := .Parameters }} {{- $envVarName := include "toSnakeCase" $key }} if [ -z "${{ $envVarName }}" ]; then export {{ $envVarName }}="${{ $envVarName }}_DEFAULT" @@ -11,7 +11,7 @@ fi {{- end }} {{- /* Construct the command based on parameter types */}} -{{- range $key, $param := .Values.parameters }} +{{- range $key, $param := .Parameters }} {{- $envVarName := include "toSnakeCase" $key }} {{- if hasKey $param "value" }} if [ -n "${{ $envVarName }}" ]; then diff --git a/deployment/k8s/charts/components/captureProxy/templates/_createConfigMapsForParameters.tpl b/deployment/k8s/charts/components/helm-common/templates/_createConfigMapsForParameters.tpl similarity index 88% rename from deployment/k8s/charts/components/captureProxy/templates/_createConfigMapsForParameters.tpl rename to deployment/k8s/charts/components/helm-common/templates/_createConfigMapsForParameters.tpl index 3b27ba297..f255f1334 100644 --- a/deployment/k8s/charts/components/captureProxy/templates/_createConfigMapsForParameters.tpl +++ b/deployment/k8s/charts/components/helm-common/templates/_createConfigMapsForParameters.tpl @@ -6,7 +6,7 @@ apiVersion: v1 kind: ConfigMap metadata: - name: {{ $packageName }}-{{ $key | lower }}-default + name: {{ $key | lower }}-default namespace: {{ $namespace }} labels: type: default @@ -26,7 +26,7 @@ data: apiVersion: v1 kind: ConfigMap metadata: - name: {{ $packageName }}-{{ $key | lower }} + name: {{ $key | lower }} namespace: {{ $namespace }} labels: type: override diff --git a/deployment/k8s/charts/components/captureProxy/templates/_createNamespace.tpl b/deployment/k8s/charts/components/helm-common/templates/_createNamespace.tpl similarity index 100% rename from deployment/k8s/charts/components/captureProxy/templates/_createNamespace.tpl rename to deployment/k8s/charts/components/helm-common/templates/_createNamespace.tpl diff --git a/deployment/k8s/charts/components/captureProxy/templates/_helpers.tpl b/deployment/k8s/charts/components/helm-common/templates/_helpers.tpl similarity index 100% rename from deployment/k8s/charts/components/captureProxy/templates/_helpers.tpl rename to deployment/k8s/charts/components/helm-common/templates/_helpers.tpl diff --git a/deployment/k8s/charts/components/captureProxy/templates/_pullEnvVariablesFromConfigMap.tpl b/deployment/k8s/charts/components/helm-common/templates/_pullEnvVariablesFromConfigMap.tpl similarity index 64% rename from deployment/k8s/charts/components/captureProxy/templates/_pullEnvVariablesFromConfigMap.tpl rename to deployment/k8s/charts/components/helm-common/templates/_pullEnvVariablesFromConfigMap.tpl index 7eead28ef..8774b4382 100644 --- a/deployment/k8s/charts/components/captureProxy/templates/_pullEnvVariablesFromConfigMap.tpl +++ b/deployment/k8s/charts/components/helm-common/templates/_pullEnvVariablesFromConfigMap.tpl @@ -1,16 +1,18 @@ {{- define "generic.pullEnvVarsFromConfigMaps" }} -{{- $packageName := .PackageName }} -{{- range $key, $param := .Values.parameters }} +{{- $namespace := .NameSpace }} +{{- range $key, $param := .Parameters }} - name: {{ include "toSnakeCase" $key }}_DEFAULT valueFrom: configMapKeyRef: - name: {{ $packageName }}-{{ $key | lower }}-default - key: {{ if hasKey $param "value" }}value{{ else if hasKey $param "list" }}list{{ else }}present{{ end }} + name: {{ $key | lower }}-default + namespace: {{ $namespace }} + key: {{ if hasKey $param "value" }}value{{ else if hasKey $param "list" }}list{{ else }}present{{ end }} {{/*TODO be explicit*/}} {{- if hasKey $param "allowRuntimeOverride" | ternary $param.allowRuntimeOverride true }} - name: {{ include "toSnakeCase" $key }} valueFrom: configMapKeyRef: - name: {{ $packageName }}-{{ $key | lower }} + name: {{ $key | lower }} + namespace: {{ $namespace }} key: {{ if hasKey $param "value" }}value{{ else if hasKey $param "list" }}list{{ else }}present{{ end }} optional: true {{- end }} diff --git a/deployment/k8s/charts/components/captureProxy/templates/_toSnakeCase.tpl b/deployment/k8s/charts/components/helm-common/templates/_toSnakeCase.tpl similarity index 100% rename from deployment/k8s/charts/components/captureProxy/templates/_toSnakeCase.tpl rename to deployment/k8s/charts/components/helm-common/templates/_toSnakeCase.tpl diff --git a/deployment/k8s/helmValues/localTesting/captureProxy.yaml b/deployment/k8s/helmValues/localTesting/captureProxy.yaml index 0b06edbbd..cabfb00b9 100644 --- a/deployment/k8s/helmValues/localTesting/captureProxy.yaml +++ b/deployment/k8s/helmValues/localTesting/captureProxy.yaml @@ -1,2 +1,3 @@ -proxy: - destinationUrl: "http://elasticsearch:9200" \ No newline at end of file +parameters: + destinationUri: + value: "http://elasticsearch:9200" \ No newline at end of file diff --git a/deployment/k8s/helmValues/localTesting/sourceElasticsearchCluster.yaml b/deployment/k8s/helmValues/localTesting/sourceElasticsearchCluster.yaml index 436c7ee7d..64e6ccbfe 100644 --- a/deployment/k8s/helmValues/localTesting/sourceElasticsearchCluster.yaml +++ b/deployment/k8s/helmValues/localTesting/sourceElasticsearchCluster.yaml @@ -1,17 +1,19 @@ -source: - imageTag: 7.10.2 - image: docker.elastic.co/elasticsearch/elasticsearch-oss - replicas: 1 - minimumMasterNodes: 1 - roles: [master, data, ingest] - antiAffinity: "soft" - esJavaOpts: "-Xmx128m -Xms128m" - protocol: http +imageTag: "7.10.2" +image: "docker.elastic.co/elasticsearch/elasticsearch-oss" +fullnameOverride: "elasticsearch" +roles: [master, data, ingest] +antiAffinity: "soft" +esJavaOpts: "-Xmx128m -Xms128m" +protocol: http +# for simplest dev testing +replicas: 2 # k8s replica count, not ES shard replicas +createCert: false # esConfig: # elasticsearch.yml: | # discovery.type: single-node - createCert: false - fullnameOverride: "elasticsearch" + +# for load-testing deployments +minimumMasterNodes: 1 # extraEnvs: # - name: "xpack.security.enabled" diff --git a/deployment/k8s/helmValues/localTesting/targetOpenSearchCluster.yaml b/deployment/k8s/helmValues/localTesting/targetOpenSearchCluster.yaml index 179ba3076..f224ba78c 100644 --- a/deployment/k8s/helmValues/localTesting/targetOpenSearchCluster.yaml +++ b/deployment/k8s/helmValues/localTesting/targetOpenSearchCluster.yaml @@ -1,7 +1,6 @@ -target: - extraEnvs: - - name: OPENSEARCH_INITIAL_ADMIN_PASSWORD - value: myStrongPassword123! - singleNode: true - persistence: - enabled: false +extraEnvs: + - name: OPENSEARCH_INITIAL_ADMIN_PASSWORD + value: myStrongPassword123! +singleNode: true +persistence: + enabled: false