@@ -21,7 +21,6 @@ import (
2121 apierrors "k8s.io/apimachinery/pkg/api/errors"
2222 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323 "k8s.io/apimachinery/pkg/types"
24- "k8s.io/utils/ptr"
2524 clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2625 "sigs.k8s.io/controller-runtime/pkg/reconcile"
2726
@@ -89,9 +88,9 @@ var _ = Describe("StackitCluster Controller", func() {
8988 Expect (got .Status .APIServerEndpoint ).To (Equal (got .Spec .ControlPlaneEndpoint ))
9089 Expect (got .Status .APIServerLoadBalancerID ).NotTo (BeEmpty ())
9190 Expect (got .Status .FailureDomains ).To (ConsistOf (
92- clusterv1.FailureDomain {Name : "eu01-1" , ControlPlane : ptr . To (true ), Attributes : map [string ]string {"region" : "eu01" }},
93- clusterv1.FailureDomain {Name : "eu01-2" , ControlPlane : ptr . To (true ), Attributes : map [string ]string {"region" : "eu01" }},
94- clusterv1.FailureDomain {Name : "eu01-3" , ControlPlane : ptr . To (true ), Attributes : map [string ]string {"region" : "eu01" }},
91+ clusterv1.FailureDomain {Name : "eu01-1" , ControlPlane : new (true ), Attributes : map [string ]string {"region" : "eu01" }},
92+ clusterv1.FailureDomain {Name : "eu01-2" , ControlPlane : new (true ), Attributes : map [string ]string {"region" : "eu01" }},
93+ clusterv1.FailureDomain {Name : "eu01-3" , ControlPlane : new (true ), Attributes : map [string ]string {"region" : "eu01" }},
9594 ))
9695 Expect (fakeCloud .LoadBalancerCount ()).To (Equal (1 ))
9796 expectCondition (got .Status .Conditions , infrav1 .ClusterReadyCondition , metav1 .ConditionTrue , "Available" )
@@ -212,51 +211,19 @@ var _ = Describe("StackitCluster Controller", func() {
212211 })
213212
214213 It ("creates the bastion with cloud-init user data from a ConfigMap" , func () {
215- got := & infrav1.StackitCluster {}
216- Expect (k8sClient .Get (ctx , stackitKey , got )).To (Succeed ())
217- cloudInitName := "bastion-cloud-init-" + clusterName
218- cloudInit := "#cloud-config\n packages:\n - htop\n "
219- createCloudInitConfigMap (ctx , cloudInitName , namespace , "userData" , cloudInit )
220- got .Spec .Bastion = validBastionSpec ()
221- got .Spec .Bastion .CloudInitRef = & infrav1.StackitBastionCloudInitRef {
222- Kind : "ConfigMap" ,
223- Name : cloudInitName ,
224- Key : "userData" ,
225- }
226- Expect (k8sClient .Update (ctx , got )).To (Succeed ())
227-
228- result , err := reconciler .Reconcile (ctx , request )
229- Expect (err ).NotTo (HaveOccurred ())
230- Expect (result ).To (Equal (reconcile.Result {}))
231-
232- Expect (k8sClient .Get (ctx , stackitKey , got )).To (Succeed ())
233- Expect (got .Status .Bastion .ServerID ).NotTo (BeEmpty ())
234- Expect (got .Status .Bastion .CloudInitHash ).To (Equal (bastionCloudInitHash ([]byte (cloudInit ))))
235- Expect (string (fakeCloud .ServerUserData (got .Status .Bastion .ServerID ))).To (Equal (cloudInit ))
214+ expectBastionCloudInit (
215+ ctx , reconciler , request , stackitKey , fakeCloud ,
216+ "ConfigMap" , "bastion-cloud-init-" + clusterName ,
217+ "#cloud-config\n packages:\n - htop\n " , createCloudInitConfigMap ,
218+ )
236219 })
237220
238221 It ("creates the bastion with cloud-init user data from a Secret" , func () {
239- got := & infrav1.StackitCluster {}
240- Expect (k8sClient .Get (ctx , stackitKey , got )).To (Succeed ())
241- cloudInitName := "bastion-cloud-init-secret-" + clusterName
242- cloudInit := "#cloud-config\n packages:\n - jq\n "
243- createCloudInitSecret (ctx , cloudInitName , namespace , "userData" , cloudInit )
244- got .Spec .Bastion = validBastionSpec ()
245- got .Spec .Bastion .CloudInitRef = & infrav1.StackitBastionCloudInitRef {
246- Kind : "Secret" ,
247- Name : cloudInitName ,
248- Key : "userData" ,
249- }
250- Expect (k8sClient .Update (ctx , got )).To (Succeed ())
251-
252- result , err := reconciler .Reconcile (ctx , request )
253- Expect (err ).NotTo (HaveOccurred ())
254- Expect (result ).To (Equal (reconcile.Result {}))
255-
256- Expect (k8sClient .Get (ctx , stackitKey , got )).To (Succeed ())
257- Expect (got .Status .Bastion .ServerID ).NotTo (BeEmpty ())
258- Expect (got .Status .Bastion .CloudInitHash ).To (Equal (bastionCloudInitHash ([]byte (cloudInit ))))
259- Expect (string (fakeCloud .ServerUserData (got .Status .Bastion .ServerID ))).To (Equal (cloudInit ))
222+ expectBastionCloudInit (
223+ ctx , reconciler , request , stackitKey , fakeCloud ,
224+ "Secret" , "bastion-cloud-init-secret-" + clusterName ,
225+ "#cloud-config\n packages:\n - jq\n " , createCloudInitSecret ,
226+ )
260227 })
261228
262229 It ("marks the bastion not ready when cloud-init ref is missing" , func () {
@@ -379,7 +346,7 @@ var _ = Describe("StackitCluster Controller", func() {
379346 It ("does not call the cloud API when the owning Cluster is paused" , func () {
380347 cluster := & clusterv1.Cluster {}
381348 Expect (k8sClient .Get (ctx , types.NamespacedName {Name : clusterName , Namespace : namespace }, cluster )).To (Succeed ())
382- cluster .Spec .Paused = ptr . To (true )
349+ cluster .Spec .Paused = new (true )
383350 Expect (k8sClient .Update (ctx , cluster )).To (Succeed ())
384351
385352 cloudClientFactoryCalls := 0
@@ -517,6 +484,36 @@ var _ = Describe("StackitCluster Controller", func() {
517484 })
518485})
519486
487+ func expectBastionCloudInit (
488+ ctx context.Context ,
489+ reconciler * StackitClusterReconciler ,
490+ request reconcile.Request ,
491+ stackitKey types.NamespacedName ,
492+ fakeCloud * cloudfake.Client ,
493+ kind , cloudInitName , cloudInit string ,
494+ createCloudInit func (context.Context , string , string , string , string ),
495+ ) {
496+ got := & infrav1.StackitCluster {}
497+ Expect (k8sClient .Get (ctx , stackitKey , got )).To (Succeed ())
498+ createCloudInit (ctx , cloudInitName , got .Namespace , "userData" , cloudInit )
499+ got .Spec .Bastion = validBastionSpec ()
500+ got .Spec .Bastion .CloudInitRef = & infrav1.StackitBastionCloudInitRef {
501+ Kind : kind ,
502+ Name : cloudInitName ,
503+ Key : "userData" ,
504+ }
505+ Expect (k8sClient .Update (ctx , got )).To (Succeed ())
506+
507+ result , err := reconciler .Reconcile (ctx , request )
508+ Expect (err ).NotTo (HaveOccurred ())
509+ Expect (result ).To (Equal (reconcile.Result {}))
510+
511+ Expect (k8sClient .Get (ctx , stackitKey , got )).To (Succeed ())
512+ Expect (got .Status .Bastion .ServerID ).NotTo (BeEmpty ())
513+ Expect (got .Status .Bastion .CloudInitHash ).To (Equal (bastionCloudInitHash ([]byte (cloudInit ))))
514+ Expect (string (fakeCloud .ServerUserData (got .Status .Bastion .ServerID ))).To (Equal (cloudInit ))
515+ }
516+
520517func newStackitCluster (name , namespace string , lbEnabled bool ) * infrav1.StackitCluster {
521518 return & infrav1.StackitCluster {
522519 ObjectMeta : metav1.ObjectMeta {
0 commit comments