Skip to content

Commit fd64db4

Browse files
authored
NO-ISSUE: Fix agent cluster controller orphaning tests (#148)
While updating the dependencies of the project I noticed that these two tests started to fail because the agent cluster object doesn't have the `apiVersion` and `kind` fields populated, and that is used by the new versions of the functions that compare owner references. But when I fixed that the test started to fail because the setup of the agent cluster isn't correct for the test: it needs to have a valid `status.clusterDeploymentRef` and a valid `spec.controlPlaneEndpoint`, otherwise the reconciler will not do the orphaning logic, or will reject the object completely. This patch fixes those tests so that they work now and will also work when updated to newer versions of the dependencies. Signed-off-by: Juan Hernandez <[email protected]>
1 parent ea7fe84 commit fd64db4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

controllers/agentcluster_controller_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ func newAgentClusterRequest(agentCluster *capiproviderv1.AgentCluster) ctrl.Requ
4242

4343
func newAgentCluster(name, namespace string, spec capiproviderv1.AgentClusterSpec) *capiproviderv1.AgentCluster {
4444
return &capiproviderv1.AgentCluster{
45+
TypeMeta: metav1.TypeMeta{
46+
Kind: "AgentCluster",
47+
APIVersion: capiproviderv1.GroupVersion.String(),
48+
},
4549
ObjectMeta: metav1.ObjectMeta{
4650
Name: name,
4751
Namespace: namespace,
@@ -334,7 +338,17 @@ var _ = Describe("agentcluster reconcile", func() {
334338
Expect(clusterutilv1.IsOwnedByObject(clusterDeployment, agentCluster)).To(BeFalse())
335339
})
336340
It("recovers its cluster deployment when unpaused", func() {
341+
// For this test the agent cluster needs to have a valid cluster deployment reference, otherwise
342+
// the reconcilation will not orphan it. It also needs a valid control plane endpoint because
343+
// that is verified by the reconciler.
337344
agentCluster := createDefaultResources(ctx, c, clusterName, testNamespace, baseDomain, pullSecret, kubeconfig, kubeadminPassword)
345+
agentCluster.Spec.ControlPlaneEndpoint.Host = "1.2.3.4"
346+
agentCluster.Spec.ControlPlaneEndpoint.Port = 1234
347+
Expect(c.Update(ctx, agentCluster)).To(Succeed())
348+
agentCluster.Status.ClusterDeploymentRef.Namespace = testNamespace
349+
agentCluster.Status.ClusterDeploymentRef.Name = clusterName
350+
Expect(c.Status().Update(ctx, agentCluster)).To(Succeed())
351+
338352
createClusterDeployment(c, ctx, agentCluster, clusterName, baseDomain, pullSecret)
339353

340354
clusterDeployment := &hivev1.ClusterDeployment{}
@@ -362,7 +376,13 @@ var _ = Describe("agentcluster reconcile", func() {
362376
Expect(clusterutilv1.IsOwnedByObject(clusterDeployment, agentCluster)).To(BeTrue())
363377
})
364378
It("doesn't delete the cluster deployment when paused and agent cluster gets deleted", func() {
379+
// For this test the agent cluster needs to have a valid cluster deployment reference, otherwise
380+
// the reconcilation will not orphan it.
365381
agentCluster := createDefaultResources(ctx, c, clusterName, testNamespace, baseDomain, pullSecret, kubeconfig, kubeadminPassword)
382+
agentCluster.Status.ClusterDeploymentRef.Namespace = testNamespace
383+
agentCluster.Status.ClusterDeploymentRef.Name = clusterName
384+
Expect(c.Status().Update(ctx, agentCluster)).To(Succeed())
385+
366386
createClusterDeployment(c, ctx, agentCluster, clusterName, baseDomain, pullSecret)
367387

368388
clusterDeployment := &hivev1.ClusterDeployment{}

0 commit comments

Comments
 (0)