From b328ee7be7e58a3b1b16e4004179e94438dc0b44 Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Wed, 20 Aug 2025 13:15:31 -0600 Subject: [PATCH 1/5] fix: preserve falsy values in deepClean Signed-off-by: Tyler Gillson --- .../templates/_helpers.tpl | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/fleetconfig-controller/charts/fleetconfig-controller/templates/_helpers.tpl b/fleetconfig-controller/charts/fleetconfig-controller/templates/_helpers.tpl index 8e2959ac..758722bc 100644 --- a/fleetconfig-controller/charts/fleetconfig-controller/templates/_helpers.tpl +++ b/fleetconfig-controller/charts/fleetconfig-controller/templates/_helpers.tpl @@ -112,31 +112,46 @@ Works with arbitrary depth and handles maps, slices, and scalar values. */}} {{- define "deepClean" -}} {{- if and . (kindIs "map" .) -}} -{{- $clean := dict -}} -{{- range $key, $value := . -}} - {{- if $value -}} + {{- $clean := dict -}} + {{- range $key, $value := . -}} {{- if kindIs "map" $value -}} - {{- $cleanedValue := include "deepClean" $value | fromYaml -}} - {{- if $cleanedValue -}} - {{- $clean = set $clean $key $cleanedValue -}} + {{- $cleaned := include "deepClean" $value | fromYaml -}} + {{- if $cleaned -}} + {{- $clean = set $clean $key $cleaned -}} {{- end -}} {{- else if kindIs "slice" $value -}} - {{- $cleanArray := list -}} + {{- $arr := list -}} {{- range $value -}} - {{- if and . (ne . "") -}} - {{- $cleanArray = append $cleanArray . -}} + {{- if kindIs "map" . -}} + {{- $ec := include "deepClean" . | fromYaml -}} + {{- if $ec -}} + {{- $arr = append $arr $ec -}} + {{- end -}} + {{- else if kindIs "string" . -}} + {{- if ne (trim .) "" -}} + {{- $arr = append $arr . -}} + {{- end -}} + {{- else -}} + {{- $arr = append $arr . -}} {{- end -}} {{- end -}} - {{- if $cleanArray -}} - {{- $clean = set $clean $key $cleanArray -}} + {{- if $arr -}} + {{- $clean = set $clean $key $arr -}} {{- end -}} - {{- else if ne $value "" -}} + {{- else if kindIs "string" $value -}} + {{- if ne (trim $value) "" -}} + {{- $clean = set $clean $key $value -}} + {{- end -}} + {{- else -}} {{- $clean = set $clean $key $value -}} {{- end -}} {{- end -}} -{{- end -}} -{{- if $clean }}{{- $clean | toYaml }}{{- else }}{}{{- end -}} + {{- if $clean -}} + {{ $clean | toYaml -}} + {{- else -}} + {} + {{- end -}} {{- else -}} -{} + {} {{- end -}} {{- end -}} \ No newline at end of file From 771af075ba266caf507bee74216a85f28060f1de Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Wed, 20 Aug 2025 13:16:21 -0600 Subject: [PATCH 2/5] refactor: move addOnConfigs under hub & tighten kubeconfig template logic Signed-off-by: Tyler Gillson --- .../charts/fleetconfig-controller/README.md | 2 +- .../templates/fleetconfig.yaml | 18 ++++++++++-------- .../charts/fleetconfig-controller/values.yaml | 17 ++++++++--------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/fleetconfig-controller/charts/fleetconfig-controller/README.md b/fleetconfig-controller/charts/fleetconfig-controller/README.md index fe80adae..16adb81c 100644 --- a/fleetconfig-controller/charts/fleetconfig-controller/README.md +++ b/fleetconfig-controller/charts/fleetconfig-controller/README.md @@ -80,6 +80,7 @@ Resource specifications for all klusterlet-managed containers. | `fleetConfig.registrationAuth.driver` | The authentication driver to use (default: "csr"). Set to "awsirsa" to use AWS IAM Roles for Service Accounts (IRSA) for EKS FleetConfigs. | `csr` | | `fleetConfig.registrationAuth.hubClusterARN` | The ARN of the hub cluster. This is only required if configuring an EKS FleetConfig. Example: "arn:aws:eks:us-west-2::cluster/". | `""` | | `fleetConfig.registrationAuth.autoApprovedARNPatterns` | Optional list of spoke cluster name ARN patterns that the hub will auto-approve. | `[]` | +| `fleetConfig.hub.addOnConfigs` | Global add-on configuration for the hub cluster. | `[]` | | `fleetConfig.hub.clusterManager.enabled` | Whether to enable the cluster manager. Set to false if using Singleton Control Plane. | `true` | | `fleetConfig.hub.clusterManager.featureGates.DefaultClusterSet` | DefaultClusterSet feature gate. | `true` | | `fleetConfig.hub.clusterManager.featureGates.ManifestWorkReplicaSet` | ManifestWorkReplicaSet feature gate. | `true` | @@ -135,7 +136,6 @@ Resource specifications for all klusterlet-managed containers. | `fleetConfig.spokes[0].klusterlet.singleton` | If true, deploy klusterlet in singleton mode, with registration and work agents running in a single pod. This is an alpha stage flag. | `false` | | `fleetConfig.spokes[0].klusterlet.values` | Values to pass to the klusterlet Helm chart. | `{}` | | `fleetConfig.spokes[0].addOns` | Add-on configuration for the spoke clusters. | `[]` | -| `fleetConfig.addOnConfigs` | Global add-on configuration for the hub cluster. | `[]` | ### Topology Resources diff --git a/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml b/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml index 41fad394..c2682ef7 100644 --- a/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml +++ b/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml @@ -33,7 +33,8 @@ spec: registry: {{ .Values.fleetConfig.source.registry }} {{- end }} {{- if (.Values.fleetConfig.hub.singletonControlPlane | default dict).enabled }} - singleton: {{- toYaml .Values.fleetConfig.hub.singletonControlPlane | nindent 6 }} + {{- $scp := omit .Values.fleetConfig.hub.singletonControlPlane "enabled" -}} + singleton: {{- toYaml $scp | nindent 6 }} {{- end }} createNamespace: {{ .Values.fleetConfig.hub.createNamespace }} force: {{ .Values.fleetConfig.hub.force }} @@ -41,7 +42,7 @@ spec: kubeconfig: context: {{ .context | quote }} inCluster: {{ .inCluster }} - {{- if .secretReference }} + {{- if and .secretReference (not (empty .secretReference.name)) }} secretReference: {{ toYaml .secretReference | nindent 8 }} {{- end }} {{- end }} @@ -57,7 +58,7 @@ spec: kubeconfig: context: {{ .context | quote }} inCluster: {{ .inCluster }} - {{- if .secretReference }} + {{- if and .secretReference (not (empty .secretReference.name)) }} secretReference: {{ toYaml .secretReference | nindent 10 }} {{- end }} {{- end }} @@ -80,12 +81,13 @@ spec: forceInternalEndpointLookup: {{ .klusterlet.forceInternalEndpointLookup }} forceInternalEndpointLookupManaged: {{ .klusterlet.forceInternalEndpointLookupManaged }} singleton: {{ .klusterlet.singleton }} - {{- with .klusterlet.managedClusterKubeconfig }} + {{- $mck := .klusterlet.managedClusterKubeconfig -}} + {{- if or $mck.context $mck.inCluster (and $mck.secretReference (not (empty $mck.secretReference.name))) }} managedClusterKubeconfig: - context: {{ .context | quote }} - inCluster: {{ .inCluster }} - {{- if .secretReference }} - secretReference: {{ toYaml .secretReference | nindent 12 }} + context: {{ $mck.context | quote }} + inCluster: {{ $mck.inCluster }} + {{- if and $mck.secretReference (not (empty $mck.secretReference.name)) }} + secretReference: {{ toYaml $mck.secretReference | nindent 12 }} {{- end }} {{- end }} resources: {{- include "deepClean" .klusterlet.resources | nindent 10 }} diff --git a/fleetconfig-controller/charts/fleetconfig-controller/values.yaml b/fleetconfig-controller/charts/fleetconfig-controller/values.yaml index be055e19..452ef820 100644 --- a/fleetconfig-controller/charts/fleetconfig-controller/values.yaml +++ b/fleetconfig-controller/charts/fleetconfig-controller/values.yaml @@ -60,6 +60,14 @@ fleetConfig: autoApprovedARNPatterns: [] ## Configuration for the Hub cluster. hub: + ## @param fleetConfig.hub.addOnConfigs Global add-on configuration for the hub cluster. + addOnConfigs: [] + # - name: "" # Name of the add-on. + # manifests: "" # Manifests to install. Can either be inline or a URL. + # version: "v0.0.1" # Version of the add-on. + # clusterRoleBinding: "" # ClusterRoleBinding to apply to the add-on. + # hubRegistration: false # Enable the agent to register to the hub cluster. + # overwrite: false # Whether to overwrite the add-on if it already exists. ## Configuration for the Cluster Manager on the Hub cluster. clusterManager: ## @descriptionStart @@ -242,15 +250,6 @@ fleetConfig: # installNamespace: "" # Namespace to install the add-on. # annotations: {} # Annotations to apply to the add-on. - ## @param fleetConfig.addOnConfigs Global add-on configuration for the hub cluster. - addOnConfigs: [] - # - name: "" # Name of the add-on. - # manifests: "" # Manifests to install. Can either be inline or a URL. - # version: "v0.0.1" # Version of the add-on. - # clusterRoleBinding: "" # ClusterRoleBinding to apply to the add-on. - # hubRegistration: false # Enable the agent to register to the hub cluster. - # overwrite: false # Whether to overwrite the add-on if it already exists. - ## @section Topology Resources ## @param topologyResources.enabled Whether to create Namespaces and ManagedClusterSetBindings for the default ManagedClusterSets created when a FleetConfig is created with the DefaultClusterSet feature gate enabled. Additionally, a Namespace, ManagedClusterSet, and Placement are created for targeting all managed clusters that are not the hub running in hub-as-spoke mode. From 4052e0781368e16f9321738f01bb27ee9a166682 Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Wed, 20 Aug 2025 13:34:29 -0600 Subject: [PATCH 3/5] fix: update fleetconfig template Signed-off-by: Tyler Gillson --- .../charts/fleetconfig-controller/templates/fleetconfig.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml b/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml index c2682ef7..a962e66e 100644 --- a/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml +++ b/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml @@ -101,7 +101,7 @@ spec: addOns: {{- toYaml .addOns | nindent 8 }} {{- end }} {{- end }} - {{- if .Values.fleetConfig.addOnConfigs }} - addOnConfigs: {{- toYaml .Values.fleetConfig.addOnConfigs | nindent 4 }} + {{- if .Values.fleetConfig.hub.addOnConfigs }} + addOnConfigs: {{- toYaml .Values.fleetConfig.hub.addOnConfigs | nindent 4 }} {{- end }} {{- end }} From 80da63d72fe8edceacdee9fb8045bbad41f1c517 Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Wed, 20 Aug 2025 17:23:18 -0600 Subject: [PATCH 4/5] fix: addon templates & test values Signed-off-by: Tyler Gillson --- .../templates/ocm/add-ons.yaml | 4 ++-- .../test/data/fleetconfig-values.yaml | 23 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/fleetconfig-controller/charts/fleetconfig-controller/templates/ocm/add-ons.yaml b/fleetconfig-controller/charts/fleetconfig-controller/templates/ocm/add-ons.yaml index 26c452e4..84c60dfb 100644 --- a/fleetconfig-controller/charts/fleetconfig-controller/templates/ocm/add-ons.yaml +++ b/fleetconfig-controller/charts/fleetconfig-controller/templates/ocm/add-ons.yaml @@ -1,8 +1,8 @@ -{{- if .Values.fleetConfig.addOnConfigs }} +{{- if .Values.fleetConfig.hub.addOnConfigs }} {{- $namespace := .Release.Namespace }} {{- $labels := include "chart.labels" . }} {{- $annotations := include "chart.annotations" . }} -{{- range .Values.fleetConfig.addOnConfigs }} +{{- range .Values.fleetConfig.hub.addOnConfigs }} {{ $versionedName := printf "%s-%s" .name .version }} apiVersion: v1 kind: ConfigMap diff --git a/fleetconfig-controller/test/data/fleetconfig-values.yaml b/fleetconfig-controller/test/data/fleetconfig-values.yaml index 463147a4..a14e4786 100644 --- a/fleetconfig-controller/test/data/fleetconfig-values.yaml +++ b/fleetconfig-controller/test/data/fleetconfig-values.yaml @@ -1,20 +1,21 @@ fleetConfig: timeout: 300 logVerbosity: 5 - addOnConfigs: - - name: test-addon - version: "v1.0.0" - manifests: | - apiVersion: v1 - kind: Namespace - metadata: - name: test-addon - clusterRoleBinding: "" - hubRegistration: false - overwrite: false spokeAnnotations: foo: "not-bar" baz: "quux" + hub: + addOnConfigs: + - name: test-addon + version: "v1.0.0" + manifests: | + apiVersion: v1 + kind: Namespace + metadata: + name: test-addon + clusterRoleBinding: "" + hubRegistration: false + overwrite: false spokes: - name: hub-as-spoke createNamespace: true From 82e851d5683b6f531a97604b294a32b0ac140644 Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Wed, 20 Aug 2025 17:29:10 -0600 Subject: [PATCH 5/5] chore: remove extraneous/invalid addOnConfig.manifests field from FleetConfig template Signed-off-by: Tyler Gillson --- .../fleetconfig-controller/templates/fleetconfig.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml b/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml index a962e66e..7581b08c 100644 --- a/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml +++ b/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml @@ -102,6 +102,13 @@ spec: {{- end }} {{- end }} {{- if .Values.fleetConfig.hub.addOnConfigs }} - addOnConfigs: {{- toYaml .Values.fleetConfig.hub.addOnConfigs | nindent 4 }} + addOnConfigs: + {{- range .Values.fleetConfig.hub.addOnConfigs }} + - name: {{ .name }} + version: {{ .version }} + clusterRoleBinding: {{ .clusterRoleBinding }} + hubRegistration: {{ .hubRegistration }} + overwrite: {{ .overwrite }} + {{- end }} {{- end }} {{- end }}