Skip to content

Commit 2e79023

Browse files
kvapsclaude
andcommitted
refactor: replace Helm lookup with valuesFrom mechanism
Replace Helm lookup functions with FluxCD valuesFrom mechanism for reading cluster and namespace configuration. Changes: - Create Secret cozystack-values in each namespace with values.yaml key containing _cluster and _namespace configuration as nested YAML - Configure HelmReleases to read from this Secret via valuesFrom (valuesKey defaults to values.yaml, so it can be omitted) - Update cozy-lib helpers to access config via .Values._cluster - Add default values for required _cluster keys to ensure all fields exist - Update Go code (cozystack-api and helm reconciler) to use new format This eliminates the need for Helm lookup functions while maintaining the same configuration interface for charts. Co-Authored-By: Claude <[email protected]> Signed-off-by: Andrei Kvapil <[email protected]>
1 parent a868874 commit 2e79023

59 files changed

Lines changed: 488 additions & 501 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎cmd/cozystack-controller/main.go‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,6 @@ func main() {
200200
os.Exit(1)
201201
}
202202

203-
if err = (&controller.TenantHelmReconciler{
204-
Client: mgr.GetClient(),
205-
Scheme: mgr.GetScheme(),
206-
}).SetupWithManager(mgr); err != nil {
207-
setupLog.Error(err, "unable to create controller", "controller", "TenantHelmReconciler")
208-
os.Exit(1)
209-
}
210-
211-
if err = (&controller.CozystackConfigReconciler{
212-
Client: mgr.GetClient(),
213-
Scheme: mgr.GetScheme(),
214-
}).SetupWithManager(mgr); err != nil {
215-
setupLog.Error(err, "unable to create controller", "controller", "CozystackConfigReconciler")
216-
os.Exit(1)
217-
}
218-
219203
cozyAPIKind := "DaemonSet"
220204
if reconcileDeployment {
221205
cozyAPIKind = "Deployment"

‎internal/controller/cozystackresourcedefinition_helmreconciler.go‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,34 @@ func (r *CozystackResourceDefinitionHelmReconciler) updateHelmReleasesForCRD(ctx
9797
return nil
9898
}
9999

100-
// updateHelmReleaseChart updates the chart in HelmRelease based on CozystackResourceDefinition
100+
// expectedValuesFrom returns the expected valuesFrom configuration for HelmReleases
101+
func expectedValuesFrom() []helmv2.ValuesReference {
102+
return []helmv2.ValuesReference{
103+
{
104+
Kind: "Secret",
105+
Name: "cozystack-values",
106+
},
107+
}
108+
}
109+
110+
// valuesFromEqual compares two ValuesReference slices
111+
func valuesFromEqual(a, b []helmv2.ValuesReference) bool {
112+
if len(a) != len(b) {
113+
return false
114+
}
115+
for i := range a {
116+
if a[i].Kind != b[i].Kind ||
117+
a[i].Name != b[i].Name ||
118+
a[i].ValuesKey != b[i].ValuesKey ||
119+
a[i].TargetPath != b[i].TargetPath ||
120+
a[i].Optional != b[i].Optional {
121+
return false
122+
}
123+
}
124+
return true
125+
}
126+
127+
// updateHelmReleaseChart updates the chart and valuesFrom in HelmRelease based on CozystackResourceDefinition
101128
func (r *CozystackResourceDefinitionHelmReconciler) updateHelmReleaseChart(ctx context.Context, hr *helmv2.HelmRelease, crd *cozyv1alpha1.CozystackResourceDefinition) error {
102129
logger := log.FromContext(ctx)
103130
hrCopy := hr.DeepCopy()
@@ -154,6 +181,14 @@ func (r *CozystackResourceDefinitionHelmReconciler) updateHelmReleaseChart(ctx c
154181
}
155182
}
156183

184+
// Check and update valuesFrom configuration
185+
expected := expectedValuesFrom()
186+
if !valuesFromEqual(hrCopy.Spec.ValuesFrom, expected) {
187+
logger.V(4).Info("Updating HelmRelease valuesFrom", "name", hr.Name, "namespace", hr.Namespace)
188+
hrCopy.Spec.ValuesFrom = expected
189+
updated = true
190+
}
191+
157192
if updated {
158193
logger.V(4).Info("Updating HelmRelease chart", "name", hr.Name, "namespace", hr.Namespace)
159194
if err := r.Update(ctx, hrCopy); err != nil {

‎internal/controller/system_helm_reconciler.go‎

Lines changed: 0 additions & 140 deletions
This file was deleted.

‎internal/controller/tenant_helm_reconciler.go‎

Lines changed: 0 additions & 159 deletions
This file was deleted.

‎packages/apps/bucket/templates/bucketclaim.yaml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
{{- $myNS := lookup "v1" "Namespace" "" .Release.Namespace }}
2-
{{- $seaweedfs := index $myNS.metadata.annotations "namespace.cozystack.io/seaweedfs" }}
1+
{{- $seaweedfs := .Values._namespace.seaweedfs }}
32
apiVersion: objectstorage.k8s.io/v1alpha1
43
kind: BucketClaim
54
metadata:

‎packages/apps/bucket/templates/helmrelease.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ spec:
2121
force: true
2222
remediation:
2323
retries: -1
24+
valuesFrom:
25+
- kind: Secret
26+
name: cozystack-values
2427
values:
2528
bucketName: {{ .Release.Name }}

‎packages/apps/clickhouse/templates/chkeeper.yaml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
{{- $cozyConfig := lookup "v1" "ConfigMap" "cozy-system" "cozystack" }}
2-
{{- $clusterDomain := (index $cozyConfig.data "cluster-domain") | default "cozy.local" }}
1+
{{- $clusterDomain := (index .Values._cluster "cluster-domain") | default "cozy.local" }}
32

43
{{- if .Values.clickhouseKeeper.enabled }}
54
apiVersion: "clickhouse-keeper.altinity.com/v1"

0 commit comments

Comments
 (0)