Skip to content

Commit

Permalink
Fix generation of already present resources (#892)
Browse files Browse the repository at this point in the history
* Fix generation of already present resources

Signed-off-by: David Cassany <[email protected]>

* Fix legacy name

Signed-off-by: David Cassany <[email protected]>

---------

Signed-off-by: David Cassany <[email protected]>
  • Loading branch information
davidcassany committed Dec 9, 2024
1 parent 7211158 commit cd19434
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions .obs/chartfile/elemental-operator-helm/templates/channels.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -42,5 +47,6 @@ metadata:
namespace: fleet-default
spec:
{{- toYaml $channel.spec | nindent 2}}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
2 changes: 1 addition & 1 deletion .obs/chartfile/elemental-operator-helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cd19434

Please sign in to comment.