From cd194342124c956c0a8f7b2e17bf17dface8992a Mon Sep 17 00:00:00 2001 From: David Cassany Viladomat Date: Mon, 9 Dec 2024 15:53:49 +0100 Subject: [PATCH] Fix generation of already present resources (#892) * Fix generation of already present resources Signed-off-by: David Cassany * Fix legacy name Signed-off-by: David Cassany --------- Signed-off-by: David Cassany --- .../templates/channels.yaml | 24 ++++++++++++------- .../elemental-operator-helm/values.yaml | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.obs/chartfile/elemental-operator-helm/templates/channels.yaml b/.obs/chartfile/elemental-operator-helm/templates/channels.yaml index c4e22cbc..9385f962 100644 --- a/.obs/chartfile/elemental-operator-helm/templates/channels.yaml +++ b/.obs/chartfile/elemental-operator-helm/templates/channels.yaml @@ -1,4 +1,6 @@ {{ $defChannelName := "" }} +{{ $defChannels := .Values.defaultChannels }} + {{ if and .Values.channel .Values.channel.image .Values.channel.tag .Values.channel.name }} {{ $defChannelName := .Values.channel.name }} apiVersion: elemental.cattle.io/v1beta1 @@ -12,8 +14,14 @@ spec: type: custom {{ end }} -{{ range $key, $channel := .Values.defaultChannels }} - {{ if and $channel.included (not (lookup "elemental.cattle.io/v1beta1" "ManagedOSVersionChannel" "fleet-default" "$channel.name")) }} +{{ $includedChannels := dict }} +{{ range $key, $channel := $defChannels }} + {{ if $channel.included }} + {{ $_ := set $includedChannels $channel.name $channel }} + {{ end }} +{{ end }} + +{{ range $_, $channel := $defChannels }} --- apiVersion: elemental.cattle.io/v1beta1 kind: ManagedOSVersionChannel @@ -26,14 +34,11 @@ spec: options: image: {{ $channel.image }} type: custom - {{ end }} {{ end }} - -# Keep pre-existing channels managed by Helm if they do not match with the current default -# this way if an upgrade introduces a new channel any pre-existing channel managed by Helm is not deleted -{{ range $index, $channel := (lookup "elemental.cattle.io/v1beta1" "ManagedOSVersionChannel" "fleet-default" "").items }} - {{ if and (eq (index $channel.metadata.labels "app.kubernetes.io/managed-by") "Helm") (ne $channel.metadata.name $defChannelName) }} +{{ range $_, $channel := (lookup "elemental.cattle.io/v1beta1" "ManagedOSVersionChannel" "fleet-default" "").items }} + {{ if and (eq (index $channel.metadata.labels "app.kubernetes.io/managed-by") "Helm") (not (hasKey $includedChannels $channel.metadata.name)) }} + {{ if and (ne $channel.metadata.name "unstable-testing-channel") (ne $channel.metadata.name $defChannelName) }} --- apiVersion: elemental.cattle.io/v1beta1 kind: ManagedOSVersionChannel @@ -42,5 +47,6 @@ metadata: namespace: fleet-default spec: {{- toYaml $channel.spec | nindent 2}} - {{ end }} + {{ end }} + {{ end }} {{ end }} diff --git a/.obs/chartfile/elemental-operator-helm/values.yaml b/.obs/chartfile/elemental-operator-helm/values.yaml index 745e2680..ce3f9e6f 100644 --- a/.obs/chartfile/elemental-operator-helm/values.yaml +++ b/.obs/chartfile/elemental-operator-helm/values.yaml @@ -37,7 +37,7 @@ defaultChannels: deleteNoLongerInSyncVersions: true slMicro60RT: included: true - name: sle-micro-6.1-rt + name: sl-micro-6.1-rt enabled: false image: "%%IMG_REPO%%/rancher/elemental-channel/sl-micro:6.1-rt" deleteNoLongerInSyncVersions: true