@@ -14,6 +14,7 @@ import (
1414 "k8s.io/apimachinery/pkg/runtime"
1515 "sigs.k8s.io/controller-runtime/pkg/client"
1616 "sigs.k8s.io/controller-runtime/pkg/reconcile"
17+ "sigs.k8s.io/yaml"
1718
1819 fluxhelmv2 "github.com/fluxcd/helm-controller/api/v2"
1920 fluxsourcev1 "github.com/fluxcd/source-controller/api/v1"
@@ -35,6 +36,7 @@ const (
3536
3637 providerName = "dns-service"
3738 providerNamespace = "test"
39+ environment = "default"
3840 managedByValue = providerName + "." + cluster .ControllerName
3941)
4042
@@ -46,13 +48,7 @@ func defaultTestSetup(testDirPathSegments ...string) *testutils.Environment {
4648 WithInitObjectPath (testDirPathSegments ... ).
4749 WithDynamicObjectsWithStatus (& clustersv1alpha1.AccessRequest {}).
4850 WithReconcilerConstructor (func (c client.Client ) reconcile.Reconciler {
49- cRec := cluster .NewClusterReconciler (clusters .NewTestClusterFromClient (platformCluster , c ), nil , providerName , providerNamespace )
50- cRec .FakeClientMapping = map [string ]client.Client {
51- "cluster-01" : nil ,
52- "cluster-02" : nil ,
53- "cluster-03" : nil ,
54- }
55- return cRec
51+ return cluster .NewClusterReconciler (clusters .NewTestClusterFromClient (platformCluster , c ), nil , providerName , providerNamespace , environment )
5652 }).
5753 Build ()
5854
@@ -476,6 +472,37 @@ var _ = Describe("ClusterReconciler", func() {
476472 }))
477473 })
478474
475+ It ("should replace the special keywords in the values correctly" , func () {
476+ env := defaultTestSetup ("testdata" , "test-03" )
477+
478+ cfg := & dnsv1alpha1.DNSServiceConfig {}
479+ Expect (env .Client ().Get (env .Ctx , client.ObjectKey {Name : providerName }, cfg )).To (Succeed ())
480+
481+ c1 := & clustersv1alpha1.Cluster {}
482+ Expect (env .Client ().Get (env .Ctx , client.ObjectKey {Name : "cluster-01" , Namespace : "foo" }, c1 )).To (Succeed ())
483+ rr := env .ShouldReconcile (testutils .RequestFromObject (c1 ))
484+ Expect (rr .RequeueAfter ).To (BeNumerically (">" , 0 ))
485+ fakeAccessRequestReadiness (env , c1 )
486+ rr = env .ShouldReconcile (testutils .RequestFromObject (c1 ))
487+ Expect (rr .RequeueAfter ).To (BeZero ())
488+
489+ // verify that the correct resources were created
490+ expectedLabels := map [string ]string {
491+ openmcpconst .ManagedByLabel : managedByValue ,
492+ openmcpconst .ManagedPurposeLabel : c1 .Name ,
493+ }
494+ hrs := & fluxhelmv2.HelmReleaseList {}
495+ Expect (env .Client ().List (env .Ctx , hrs , client .InNamespace (c1 .Namespace ), client .MatchingLabels (expectedLabels ))).To (Succeed ())
496+ Expect (hrs .Items ).To (HaveLen (1 ))
497+ valueData := map [string ]any {}
498+ Expect (yaml .Unmarshal (hrs .Items [0 ].Spec .Values .Raw , & valueData )).To (Succeed ())
499+ Expect (valueData ).To (HaveKeyWithValue ("clusterName" , c1 .Name ))
500+ Expect (valueData ).To (HaveKeyWithValue ("clusterNamespace" , c1 .Namespace ))
501+ Expect (valueData ).To (HaveKeyWithValue ("environment" , environment ))
502+ Expect (valueData ).To (HaveKeyWithValue ("providerName" , providerName ))
503+ Expect (valueData ).To (HaveKeyWithValue ("providerNamespace" , providerNamespace ))
504+ })
505+
479506})
480507
481508func fakeAccessRequestReadiness (env * testutils.Environment , c * clustersv1alpha1.Cluster ) {
0 commit comments