Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generation of already present resources #892

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure none of the generated here is already listed as default channel or testing channel

---
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 }}
Loading