From bd0fef2fa44d92113c1a2d931724461e8a40ca9a Mon Sep 17 00:00:00 2001 From: Kjeld Schouten Date: Fri, 22 Dec 2023 13:56:50 +0100 Subject: [PATCH] fix(homepage integration): change structure of custom parameters (#640) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** Current parameters system is not displayable in SCALE. **โš™๏ธ Type of change** - [ ] โš™๏ธ 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 **โž• App addition** If this PR is an app addition please make sure you have done the following. - [ ] ๐Ÿชž I have opened a PR on [truecharts/containers](https://github.com/truecharts/containers) adding the container to TrueCharts mirror repo. - [ ] ๐Ÿ–ผ๏ธ 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 <47820033+stavros-k@users.noreply.github.com> --- .../tests/ingress/homepage_test.yaml | 49 +++++++++++++++++++ library/common/Chart.yaml | 2 +- .../lib/ingress/integrations/_homepage.tpl | 14 ++++++ library/common/values.yaml | 5 +- 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/library/common-test/tests/ingress/homepage_test.yaml b/library/common-test/tests/ingress/homepage_test.yaml index 2db526b8..9f4aaeaa 100644 --- a/library/common-test/tests/ingress/homepage_test.yaml +++ b/library/common-test/tests/ingress/homepage_test.yaml @@ -62,6 +62,11 @@ tests: custom: some-key: some-value some-other-key: some-other-value + customkv: + - key: some-key-slice + value: some-value-slice + - key: some-other-key-slice + value: some-other-value-slice hosts: &hosts - host: test-host paths: @@ -106,6 +111,8 @@ tests: gethomepage.dev/pod-selector: pod.name in (main,other) gethomepage.dev/widget.some-key: some-value gethomepage.dev/widget.some-other-key: some-other-value + gethomepage.dev/widget.some-key-slice: some-value-slice + gethomepage.dev/widget.some-other-key-slice: some-other-value-slice - documentIndex: *otherIngressDoc equal: path: metadata.name @@ -154,3 +161,45 @@ tests: asserts: - failedTemplate: errorMessage: Ingress - Expected [integrations.homepage.widget.custom] to be a [map], but got [string] + + - it: should fail with customkv widget not a slice + set: + operator: *operator + service: *service + ingress: + my-ingress1: + enabled: true + primary: true + integrations: + traefik: + enabled: false + homepage: + enabled: true + widget: + customkv: "not a slice" + hosts: *hosts + asserts: + - failedTemplate: + errorMessage: Ingress - Expected [integrations.homepage.widget.customkv] to be a [slice], but got [string] + + - it: should fail with customkv having empty key + set: + operator: *operator + service: *service + ingress: + my-ingress1: + enabled: true + primary: true + integrations: + traefik: + enabled: false + homepage: + enabled: true + widget: + customkv: + - key: "" + value: some-value + hosts: *hosts + asserts: + - failedTemplate: + errorMessage: Ingress - Expected non-empty [key] in [integrations.homepage.widget.customkv] diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 538a0a48..44fa72cb 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 16.2.10 +version: 16.2.11 diff --git a/library/common/templates/lib/ingress/integrations/_homepage.tpl b/library/common/templates/lib/ingress/integrations/_homepage.tpl index 94863efb..33d2177e 100644 --- a/library/common/templates/lib/ingress/integrations/_homepage.tpl +++ b/library/common/templates/lib/ingress/integrations/_homepage.tpl @@ -46,6 +46,9 @@ {{- range $k, $v := $homepage.widget.custom -}} {{- $_ := set $objectData.annotations (printf "gethomepage.dev/widget.%s" $k) (tpl $v $rootCtx | toString) -}} {{- end -}} + {{- range $homepage.widget.customkv -}} + {{- $_ := set $objectData.annotations (printf "gethomepage.dev/widget.%s" .key ) (tpl .value $rootCtx | toString) -}} + {{- end -}} {{- end -}} {{- with $homepage.podSelector -}} @@ -72,4 +75,15 @@ {{- fail (printf "Ingress - Expected [integrations.homepage.widget.custom] to be a [map], but got [%s]" (kindOf $homepage.widget.custom)) -}} {{- end -}} {{- end -}} + + {{- if $homepage.widget.customkv -}} + {{- if not (kindIs "slice" $homepage.widget.customkv) -}} + {{- fail (printf "Ingress - Expected [integrations.homepage.widget.customkv] to be a [slice], but got [%s]" (kindOf $homepage.widget.customkv)) -}} + {{- end -}} + {{- range $item := $homepage.widget.customkv -}} + {{- if not $item.key -}} + {{- fail "Ingress - Expected non-empty [key] in [integrations.homepage.widget.customkv]" -}} + {{- end -}} + {{- end -}} + {{- end -}} {{- end -}} diff --git a/library/common/values.yaml b/library/common/values.yaml index e530872b..33ec0c78 100644 --- a/library/common/values.yaml +++ b/library/common/values.yaml @@ -621,7 +621,10 @@ ingress: # Default to ingress host 0 url: "" custom: - # - somesetting: some value + # somesetting: some value + customkv: + # - key: some key + # value: some value certificate: {} # main: