Skip to content

Commit f4d7b6f

Browse files
authored
Fix generation of already present resources (#892)
* Fix generation of already present resources Signed-off-by: David Cassany <dcassany@suse.com> * Fix legacy name Signed-off-by: David Cassany <dcassany@suse.com> --------- Signed-off-by: David Cassany <dcassany@suse.com>
1 parent a729705 commit f4d7b6f

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

.obs/chartfile/elemental-operator-helm/templates/channels.yaml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{{ $defChannelName := "" }}
2+
{{ $defChannels := .Values.defaultChannels }}
3+
24
{{ if and .Values.channel .Values.channel.image .Values.channel.tag .Values.channel.name }}
35
{{ $defChannelName := .Values.channel.name }}
46
apiVersion: elemental.cattle.io/v1beta1
@@ -12,8 +14,14 @@ spec:
1214
type: custom
1315
{{ end }}
1416

15-
{{ range $key, $channel := .Values.defaultChannels }}
16-
{{ if and $channel.included (not (lookup "elemental.cattle.io/v1beta1" "ManagedOSVersionChannel" "fleet-default" "$channel.name")) }}
17+
{{ $includedChannels := dict }}
18+
{{ range $key, $channel := $defChannels }}
19+
{{ if $channel.included }}
20+
{{ $_ := set $includedChannels $channel.name $channel }}
21+
{{ end }}
22+
{{ end }}
23+
24+
{{ range $_, $channel := $defChannels }}
1725
---
1826
apiVersion: elemental.cattle.io/v1beta1
1927
kind: ManagedOSVersionChannel
@@ -26,14 +34,11 @@ spec:
2634
options:
2735
image: {{ $channel.image }}
2836
type: custom
29-
{{ end }}
3037
{{ end }}
3138

32-
33-
# Keep pre-existing channels managed by Helm if they do not match with the current default
34-
# this way if an upgrade introduces a new channel any pre-existing channel managed by Helm is not deleted
35-
{{ range $index, $channel := (lookup "elemental.cattle.io/v1beta1" "ManagedOSVersionChannel" "fleet-default" "").items }}
36-
{{ if and (eq (index $channel.metadata.labels "app.kubernetes.io/managed-by") "Helm") (ne $channel.metadata.name $defChannelName) }}
39+
{{ range $_, $channel := (lookup "elemental.cattle.io/v1beta1" "ManagedOSVersionChannel" "fleet-default" "").items }}
40+
{{ if and (eq (index $channel.metadata.labels "app.kubernetes.io/managed-by") "Helm") (not (hasKey $includedChannels $channel.metadata.name)) }}
41+
{{ if and (ne $channel.metadata.name "unstable-testing-channel") (ne $channel.metadata.name $defChannelName) }}
3742
---
3843
apiVersion: elemental.cattle.io/v1beta1
3944
kind: ManagedOSVersionChannel
@@ -42,5 +47,6 @@ metadata:
4247
namespace: fleet-default
4348
spec:
4449
{{- toYaml $channel.spec | nindent 2}}
45-
{{ end }}
50+
{{ end }}
51+
{{ end }}
4652
{{ end }}

.obs/chartfile/elemental-operator-helm/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ defaultChannels:
3737
deleteNoLongerInSyncVersions: true
3838
slMicro60RT:
3939
included: true
40-
name: sle-micro-6.1-rt
40+
name: sl-micro-6.1-rt
4141
enabled: false
4242
image: "%%IMG_REPO%%/rancher/elemental-channel/sl-micro:6.1-rt"
4343
deleteNoLongerInSyncVersions: true

0 commit comments

Comments
 (0)