From a759873bf5c32234778726591385c329573d9d13 Mon Sep 17 00:00:00 2001 From: Kjeld Schouten Date: Sat, 1 Feb 2025 22:52:32 +0100 Subject: [PATCH] feat(common): add existing secret support for pullsecret (#31500) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes #31324 **⚙️ Type of change** - [x] ⚙️ Feature/App addition - [ ] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code **🧪 How Has This Been Tested?** **📃 Notes:** **✔️ Checklist:** - [ ] ⚖️ My code follows the style guidelines of this project - [ ] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made corresponding changes to the documentation - [ ] ⚠️ My changes generate no new warnings - [ ] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [ ] ⬆️ I increased versions for any altered app according to semantic versioning - [ ] I made sure the title starts with `feat(chart-name):`, `fix(chart-name):` or `chore(chart-name):` **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --------- Co-authored-by: Stavros Kois --- charts/library/common-test/Chart.yaml | 2 +- .../tests/imagePullSecret/name_test.yaml | 5 ++ .../tests/pod/image_pull_secret_test.yaml | 4 + charts/library/common/Chart.yaml | 2 +- .../templates/lib/pod/_imagePullSecret.tpl | 4 + .../templates/spawner/_imagePullSecret.tpl | 3 + .../content/docs/common/imagePullSecret.md | 85 +++++++++++++------ 7 files changed, 77 insertions(+), 28 deletions(-) diff --git a/charts/library/common-test/Chart.yaml b/charts/library/common-test/Chart.yaml index b3aba11e104..ed12a9e8852 100644 --- a/charts/library/common-test/Chart.yaml +++ b/charts/library/common-test/Chart.yaml @@ -7,7 +7,7 @@ apiVersion: v2 appVersion: unknown dependencies: - name: common - version: ~25.5.0 + version: ~25.6.0 repository: file://../common/ condition: "" alias: "" diff --git a/charts/library/common-test/tests/imagePullSecret/name_test.yaml b/charts/library/common-test/tests/imagePullSecret/name_test.yaml index 67853ef457d..8ad4b615903 100644 --- a/charts/library/common-test/tests/imagePullSecret/name_test.yaml +++ b/charts/library/common-test/tests/imagePullSecret/name_test.yaml @@ -22,7 +22,12 @@ tests: username: user2 password: pass2 email: mail2 + my-pull-secret3: + enabled: true + existingSecret: some-existing-secret asserts: + - hasDocuments: + count: 2 - documentIndex: &secretDoc 0 isKind: of: Secret diff --git a/charts/library/common-test/tests/pod/image_pull_secret_test.yaml b/charts/library/common-test/tests/pod/image_pull_secret_test.yaml index 2df955d171a..d96b78bcde6 100644 --- a/charts/library/common-test/tests/pod/image_pull_secret_test.yaml +++ b/charts/library/common-test/tests/pod/image_pull_secret_test.yaml @@ -34,6 +34,9 @@ tests: username: user password: pass email: mail + pull-secret3: + enabled: true + existingSecret: some-existing-secret asserts: - documentIndex: &cronJobDoc 2 isKind: @@ -48,6 +51,7 @@ tests: value: - name: test-release-name-common-test-pull-secret1 - name: test-release-name-common-test-pull-secret2 + - name: some-existing-secret - documentIndex: &otherDeploymentDoc 3 isKind: of: Deployment diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index 96a22832c10..91cb30cfcc5 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -48,4 +48,4 @@ sources: - https://hub.docker.com/_/ - https://hub.docker.com/r/mikefarah/yq type: library -version: 25.5.0 +version: 25.6.0 diff --git a/charts/library/common/templates/lib/pod/_imagePullSecret.tpl b/charts/library/common/templates/lib/pod/_imagePullSecret.tpl index de0f23ecb04..87b4c0fe371 100644 --- a/charts/library/common/templates/lib/pod/_imagePullSecret.tpl +++ b/charts/library/common/templates/lib/pod/_imagePullSecret.tpl @@ -13,6 +13,10 @@ objectData: The object data to be used to render the Pod. {{- range $name, $imgPull := $rootCtx.Values.imagePullSecret -}} {{- $pullName := (printf "%s-%s" (include "tc.v1.common.lib.chart.names.fullname" $rootCtx) $name) -}} + {{- if $imgPull.existingSecret -}} + {{- $pullName = $imgPull.existingSecret -}} + {{- end -}} + {{- if $imgPull.enabled -}} {{/* If targetSelectAll is true */}} {{- if $imgPull.targetSelectAll -}} diff --git a/charts/library/common/templates/spawner/_imagePullSecret.tpl b/charts/library/common/templates/spawner/_imagePullSecret.tpl index 6c606f2d2c6..5dfb309a51b 100644 --- a/charts/library/common/templates/spawner/_imagePullSecret.tpl +++ b/charts/library/common/templates/spawner/_imagePullSecret.tpl @@ -13,6 +13,9 @@ "name" $name "caller" "Image Pull Secret" "key" "imagePullSecret")) -}} + {{- if $imgPullSecret.existingSecret -}} + {{- continue -}} + {{- end -}} {{- if eq $enabled "true" -}} {{/* Create a copy of the configmap */}} diff --git a/website/src/content/docs/common/imagePullSecret.md b/website/src/content/docs/common/imagePullSecret.md index e475adfd3c9..14e47ac1d06 100644 --- a/website/src/content/docs/common/imagePullSecret.md +++ b/website/src/content/docs/common/imagePullSecret.md @@ -41,8 +41,8 @@ Define image pull secrets | ---------- | ----------------- | | Key | `imagePullSecret` | | Type | `map` | -| Required | ❌ | -| Helm `tpl` | ❌ | +| Required | ❌ | +| Helm `tpl` | ❌ | | Default | `{}` | Example @@ -61,8 +61,8 @@ Define image pull secret | ---------- | ----------------------- | | Key | `imagePullSecret.$name` | | Type | `map` | -| Required | ✅ | -| Helm `tpl` | ❌ | +| Required | ✅ | +| Helm `tpl` | ❌ | | Default | `{}` | Example @@ -82,8 +82,8 @@ Enables or Disables the image pull secret | ---------- | ------------------------------- | | Key | `imagePullSecret.$name.enabled` | | Type | `bool` | -| Required | ✅ | -| Helm `tpl` | ✅ | +| Required | ✅ | +| Helm `tpl` | ✅ | | Default | `false` | Example @@ -96,6 +96,39 @@ imagePullSecret: --- +#### `existingSecret` + +Define the existing secret name + +:::note + +If this is defined, only the following keys are used: + +- `enabled` +- `targetSelectAll` +- `targetSelector` + +::: + +| | | +| ---------- | -------------------------------------- | +| Key | `imagePullSecret.$name.existingSecret` | +| Type | `string` | +| Required | ❌ | +| Helm `tpl` | ❌ | +| Default | - | + +Example + +```yaml +imagePullSecret: + pull-secret-name: + enabled: true + existingSecret: some-existing-secret +``` + +--- + #### `namespace` Define the namespace for this object @@ -104,8 +137,8 @@ Define the namespace for this object | ---------- | --------------------------------- | | Key | `imagePullSecret.$name.namespace` | | Type | `string` | -| Required | ❌ | -| Helm `tpl` | ✅ (On value only) | +| Required | ❌ | +| Helm `tpl` | ✅ (On value only) | | Default | `""` | Example @@ -126,8 +159,8 @@ Additional labels for image pull secret | ---------- | ------------------------------ | | Key | `imagePullSecret.$name.labels` | | Type | `map` | -| Required | ❌ | -| Helm `tpl` | ✅ (On value only) | +| Required | ❌ | +| Helm `tpl` | ✅ (On value only) | | Default | `{}` | Example @@ -149,8 +182,8 @@ Additional annotations for image pull secret | ---------- | ----------------------------------- | | Key | `imagePullSecret.$name.annotations` | | Type | `map` | -| Required | ❌ | -| Helm `tpl` | ✅ (On value only) | +| Required | ❌ | +| Helm `tpl` | ✅ (On value only) | | Default | `{}` | Example @@ -172,8 +205,8 @@ Whether to assign the secret to all pods or not | ---------- | --------------------------------------- | | Key | `imagePullSecret.$name.targetSelectAll` | | Type | `bool` | -| Required | ❌ | -| Helm `tpl` | ❌ | +| Required | ❌ | +| Helm `tpl` | ❌ | | Default | unset | Example @@ -194,8 +227,8 @@ Define the pod(s) to assign the secret | ---------- | -------------------------------------- | | Key | `imagePullSecret.$name.targetSelector` | | Type | `list` of `string` | -| Required | ❌ | -| Helm `tpl` | ❌ | +| Required | ❌ | +| Helm `tpl` | ❌ | | Default | `[]` | Example @@ -218,8 +251,8 @@ Define the data of the image pull secret | ---------- | ---------------------------- | | Key | `imagePullSecret.$name.data` | | Type | `map` | -| Required | ✅ | -| Helm `tpl` | ❌ | +| Required | ✅ | +| Helm `tpl` | ❌ | | Default | `{}` | Example @@ -240,8 +273,8 @@ Define the registry of the image pull secret | ---------- | ------------------------------------- | | Key | `imagePullSecret.$name.data.registry` | | Type | `string` | -| Required | ✅ | -| Helm `tpl` | ✅ | +| Required | ✅ | +| Helm `tpl` | ✅ | | Default | `""` | Example @@ -263,8 +296,8 @@ Define the username of the image pull secret | ---------- | ------------------------------------- | | Key | `imagePullSecret.$name.data.username` | | Type | `string` | -| Required | ✅ | -| Helm `tpl` | ✅ | +| Required | ✅ | +| Helm `tpl` | ✅ | | Default | `""` | Example @@ -286,8 +319,8 @@ Define the password of the image pull secret | ---------- | ------------------------------------- | | Key | `imagePullSecret.$name.data.password` | | Type | `string` | -| Required | ✅ | -| Helm `tpl` | ✅ | +| Required | ✅ | +| Helm `tpl` | ✅ | | Default | `""` | Example @@ -309,8 +342,8 @@ Define the email of the image pull secret | ---------- | ---------------------------------- | | Key | `imagePullSecret.$name.data.email` | | Type | `string` | -| Required | ✅ | -| Helm `tpl` | ✅ | +| Required | ✅ | +| Helm `tpl` | ✅ | | Default | `""` | Example