From df30110bd12898a8378b776eb019f3ec0555b95c Mon Sep 17 00:00:00 2001 From: Saumil Macwan Date: Thu, 29 Aug 2024 14:08:34 -0400 Subject: [PATCH] fix: make broker servicename k8s api compliant[HYB-584] (#124) * fix: make broker servicename k8s api compliant * fix: updating chart version --- charts/snyk-broker/Chart.yaml | 2 +- charts/snyk-broker/templates/_helpers.tpl | 8 ++++++-- .../broker_deployment_disablesuffixes_test.yaml | 2 -- .../tests/broker_deployment_test.yaml | 2 -- .../tests/broker_servicename_length_test.yaml | 16 ++++++++++++++++ .../fixtures/default_values_disablesuffixes.yaml | 2 +- .../tests/fixtures/default_values_ha_on.yaml | 2 +- .../default_values_ha_on_4_replicas.yaml | 2 +- ..._values_ha_on_4_replicas_disablesuffixes.yaml | 2 +- .../default_values_ha_on_disablesuffixes.yaml | 2 +- .../fixtures/default_values_https_enabled.yaml | 2 +- .../fixtures/default_values_preflight_off.yaml | 2 +- ...ult_values_preflight_off_disablesuffixes.yaml | 2 +- charts/snyk-broker/values.schema.json | 3 +++ charts/snyk-broker/values.yaml | 4 ++++ 15 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 charts/snyk-broker/tests/broker_servicename_length_test.yaml diff --git a/charts/snyk-broker/Chart.yaml b/charts/snyk-broker/Chart.yaml index abe1a4e..78ee7b8 100644 --- a/charts/snyk-broker/Chart.yaml +++ b/charts/snyk-broker/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v2 name: snyk-broker -version: 2.7.5 +version: 2.7.6 description: A Helm chart for Kubernetes type: application diff --git a/charts/snyk-broker/templates/_helpers.tpl b/charts/snyk-broker/templates/_helpers.tpl index 191e2ed..6b877a0 100644 --- a/charts/snyk-broker/templates/_helpers.tpl +++ b/charts/snyk-broker/templates/_helpers.tpl @@ -109,9 +109,13 @@ Create the name of the broker service to use */}} {{- define "snyk-broker.brokerServiceName" -}} {{- if not .Values.disableSuffixes -}} -{{- .Values.scmType }}-broker-service-{{ .Release.Name }} +{{- $service := "-broker-service-" -}} +{{- $serviceLength := len $service -}} +{{- $releaseNameLength := len .Release.Name -}} +{{- $truncatedLength := int (sub 63 (add $serviceLength $releaseNameLength)) -}} +{{- .Values.scmType | trunc $truncatedLength }}{{ $service }}{{ .Release.Name }} {{- else }} -{{- .Values.scmType}}-broker-service +{{- .Values.scmType | trunc 47 }}-broker-service {{- end -}} {{- end -}} diff --git a/charts/snyk-broker/tests/broker_deployment_disablesuffixes_test.yaml b/charts/snyk-broker/tests/broker_deployment_disablesuffixes_test.yaml index d9d7784..686f197 100644 --- a/charts/snyk-broker/tests/broker_deployment_disablesuffixes_test.yaml +++ b/charts/snyk-broker/tests/broker_deployment_disablesuffixes_test.yaml @@ -6,8 +6,6 @@ templates: - broker_service.yaml - secrets.yaml - serviceaccount.yaml -values: - - ./fixtures/default_values.yaml tests: - it: default values diff --git a/charts/snyk-broker/tests/broker_deployment_test.yaml b/charts/snyk-broker/tests/broker_deployment_test.yaml index 458cc10..55e2f2b 100644 --- a/charts/snyk-broker/tests/broker_deployment_test.yaml +++ b/charts/snyk-broker/tests/broker_deployment_test.yaml @@ -6,8 +6,6 @@ templates: - broker_service.yaml - secrets.yaml - serviceaccount.yaml -values: - - ./fixtures/default_values.yaml tests: - it: default values diff --git a/charts/snyk-broker/tests/broker_servicename_length_test.yaml b/charts/snyk-broker/tests/broker_servicename_length_test.yaml new file mode 100644 index 0000000..9c5f6d8 --- /dev/null +++ b/charts/snyk-broker/tests/broker_servicename_length_test.yaml @@ -0,0 +1,16 @@ +suite: test broker servicename length +chart: + version: 0.0.0 +templates: + - broker_service.yaml + +tests: + - it: should truncate scmType correctly when combined with release name and suffix + values: + - ./fixtures/default_values_cra.yaml + release: + name: "myrelease-really-long-release-name" + asserts: + - equal: + path: metadata.name + value: "container-reg-broker-service-myrelease-really-long-release-name" \ No newline at end of file diff --git a/charts/snyk-broker/tests/fixtures/default_values_disablesuffixes.yaml b/charts/snyk-broker/tests/fixtures/default_values_disablesuffixes.yaml index 2841b34..09753c6 100644 --- a/charts/snyk-broker/tests/fixtures/default_values_disablesuffixes.yaml +++ b/charts/snyk-broker/tests/fixtures/default_values_disablesuffixes.yaml @@ -6,7 +6,7 @@ # Broker Token is a value from Snyk. Get this from the integration settings page or your Snyk Representative brokerToken: "12345a6b-78d9-1e2f-3abc-456def789123" - +snykToken: "12345a6b-78d9-1e2f-3abc-456def789123" # brokerClientUrl is the address of the broker. This needs to be the address of itself. In the case of Kubernetes, you need to ensure that you are pointing to the cluster ingress you have setup. # Ex: http://kubernetes-ingress.domain.com:8000/broker brokerClientUrl: "http://brokerclient" diff --git a/charts/snyk-broker/tests/fixtures/default_values_ha_on.yaml b/charts/snyk-broker/tests/fixtures/default_values_ha_on.yaml index a4f5820..aa8735e 100644 --- a/charts/snyk-broker/tests/fixtures/default_values_ha_on.yaml +++ b/charts/snyk-broker/tests/fixtures/default_values_ha_on.yaml @@ -6,7 +6,7 @@ # Broker Token is a value from Snyk. Get this from the integration settings page or your Snyk Representative brokerToken: "12345a6b-78d9-1e2f-3abc-456def789123" - +snykToken: "12345a6b-78d9-1e2f-3abc-456def789123" # brokerClientUrl is the address of the broker. This needs to be the address of itself. In the case of Kubernetes, you need to ensure that you are pointing to the cluster ingress you have setup. # Ex: http://kubernetes-ingress.domain.com:8000/broker brokerClientUrl: "http://brokerclient" diff --git a/charts/snyk-broker/tests/fixtures/default_values_ha_on_4_replicas.yaml b/charts/snyk-broker/tests/fixtures/default_values_ha_on_4_replicas.yaml index 77c35b2..9d722a2 100644 --- a/charts/snyk-broker/tests/fixtures/default_values_ha_on_4_replicas.yaml +++ b/charts/snyk-broker/tests/fixtures/default_values_ha_on_4_replicas.yaml @@ -6,7 +6,7 @@ # Broker Token is a value from Snyk. Get this from the integration settings page or your Snyk Representative brokerToken: "12345a6b-78d9-1e2f-3abc-456def789123" - +snykToken: "12345a6b-78d9-1e2f-3abc-456def789123" # brokerClientUrl is the address of the broker. This needs to be the address of itself. In the case of Kubernetes, you need to ensure that you are pointing to the cluster ingress you have setup. # Ex: http://kubernetes-ingress.domain.com:8000/broker brokerClientUrl: "http://brokerclient" diff --git a/charts/snyk-broker/tests/fixtures/default_values_ha_on_4_replicas_disablesuffixes.yaml b/charts/snyk-broker/tests/fixtures/default_values_ha_on_4_replicas_disablesuffixes.yaml index 5e672fa..664fd07 100644 --- a/charts/snyk-broker/tests/fixtures/default_values_ha_on_4_replicas_disablesuffixes.yaml +++ b/charts/snyk-broker/tests/fixtures/default_values_ha_on_4_replicas_disablesuffixes.yaml @@ -6,7 +6,7 @@ # Broker Token is a value from Snyk. Get this from the integration settings page or your Snyk Representative brokerToken: "12345a6b-78d9-1e2f-3abc-456def789123" - +snykToken: "12345a6b-78d9-1e2f-3abc-456def789123" # brokerClientUrl is the address of the broker. This needs to be the address of itself. In the case of Kubernetes, you need to ensure that you are pointing to the cluster ingress you have setup. # Ex: http://kubernetes-ingress.domain.com:8000/broker brokerClientUrl: "http://brokerclient" diff --git a/charts/snyk-broker/tests/fixtures/default_values_ha_on_disablesuffixes.yaml b/charts/snyk-broker/tests/fixtures/default_values_ha_on_disablesuffixes.yaml index 74e87de..2936521 100644 --- a/charts/snyk-broker/tests/fixtures/default_values_ha_on_disablesuffixes.yaml +++ b/charts/snyk-broker/tests/fixtures/default_values_ha_on_disablesuffixes.yaml @@ -6,7 +6,7 @@ # Broker Token is a value from Snyk. Get this from the integration settings page or your Snyk Representative brokerToken: "12345a6b-78d9-1e2f-3abc-456def789123" - +snykToken: "12345a6b-78d9-1e2f-3abc-456def789123" # brokerClientUrl is the address of the broker. This needs to be the address of itself. In the case of Kubernetes, you need to ensure that you are pointing to the cluster ingress you have setup. # Ex: http://kubernetes-ingress.domain.com:8000/broker brokerClientUrl: "http://brokerclient" diff --git a/charts/snyk-broker/tests/fixtures/default_values_https_enabled.yaml b/charts/snyk-broker/tests/fixtures/default_values_https_enabled.yaml index 3f2eca0..b6263f1 100644 --- a/charts/snyk-broker/tests/fixtures/default_values_https_enabled.yaml +++ b/charts/snyk-broker/tests/fixtures/default_values_https_enabled.yaml @@ -6,7 +6,7 @@ # Broker Token is a value from Snyk. Get this from the integration settings page or your Snyk Representative brokerToken: "12345a6b-78d9-1e2f-3abc-456def789123" - +snykToken: "12345a6b-78d9-1e2f-3abc-456def789123" # brokerClientUrl is the address of the broker. This needs to be the address of itself. In the case of Kubernetes, you need to ensure that you are pointing to the cluster ingress you have setup. # Ex: http://kubernetes-ingress.domain.com:8000/broker brokerClientUrl: "http://brokerclient" diff --git a/charts/snyk-broker/tests/fixtures/default_values_preflight_off.yaml b/charts/snyk-broker/tests/fixtures/default_values_preflight_off.yaml index 5e07e6b..c6f1832 100644 --- a/charts/snyk-broker/tests/fixtures/default_values_preflight_off.yaml +++ b/charts/snyk-broker/tests/fixtures/default_values_preflight_off.yaml @@ -6,7 +6,7 @@ # Broker Token is a value from Snyk. Get this from the integration settings page or your Snyk Representative brokerToken: "12345a6b-78d9-1e2f-3abc-456def789123" - +snykToken: "12345a6b-78d9-1e2f-3abc-456def789123" # brokerClientUrl is the address of the broker. This needs to be the address of itself. In the case of Kubernetes, you need to ensure that you are pointing to the cluster ingress you have setup. # Ex: http://kubernetes-ingress.domain.com:8000/broker brokerClientUrl: "http://brokerclient" diff --git a/charts/snyk-broker/tests/fixtures/default_values_preflight_off_disablesuffixes.yaml b/charts/snyk-broker/tests/fixtures/default_values_preflight_off_disablesuffixes.yaml index 0aa5b8c..ab33709 100644 --- a/charts/snyk-broker/tests/fixtures/default_values_preflight_off_disablesuffixes.yaml +++ b/charts/snyk-broker/tests/fixtures/default_values_preflight_off_disablesuffixes.yaml @@ -6,7 +6,7 @@ # Broker Token is a value from Snyk. Get this from the integration settings page or your Snyk Representative brokerToken: "12345a6b-78d9-1e2f-3abc-456def789123" - +snykToken: "12345a6b-78d9-1e2f-3abc-456def789123" # brokerClientUrl is the address of the broker. This needs to be the address of itself. In the case of Kubernetes, you need to ensure that you are pointing to the cluster ingress you have setup. # Ex: http://kubernetes-ingress.domain.com:8000/broker brokerClientUrl: "http://brokerclient" diff --git a/charts/snyk-broker/values.schema.json b/charts/snyk-broker/values.schema.json index 9edf1e1..d50e963 100644 --- a/charts/snyk-broker/values.schema.json +++ b/charts/snyk-broker/values.schema.json @@ -46,6 +46,9 @@ }, "additionalProperties": false }, + "disableSuffixes": { + "type": "boolean" + }, "brokerDispatcherUrl": { "type": "string", "default": "https://api.snyk.io", diff --git a/charts/snyk-broker/values.yaml b/charts/snyk-broker/values.yaml index fee9567..de9a420 100644 --- a/charts/snyk-broker/values.yaml +++ b/charts/snyk-broker/values.yaml @@ -31,6 +31,10 @@ replicaCount: 2 # Adds additional labels to broker deployment labels: {} +# Beginning with version 2.0.0, all created objects have a suffix based on the release name, allowing for multiple Brokers in the same namespace. +# For backward compatibility, version 2.1.0 introduces a disableSuffixes flag to revert to the 1.x.x behavior. +disableSuffixes: false + ##### SCM Generic ##### # scmType is used to define the Source Control that you are connecting to.