Skip to content

Commit 3046d4a

Browse files
flawedmatrixAidan Obley
and
Aidan Obley
authored
Ensure GetControlPlaneEndpoint can still return an IP (#177)
* Ensure GetControlPlaneEndpoint can still return an IP Even if the cluster-controlplane-endpoint annotation or ClusterClass topology variable for apiServerEndpoint are not set, it can still retrieve the control plane endpoint from the cluster.Spec.ControlPlaneEndpoint.Host. Co-authored-by: Aidan Obley <[email protected]> * Fix integration test flakes - Modifying the cluster object directly in Golang also somehow modifies it on the fake API side --------- Co-authored-by: Aidan Obley <[email protected]>
1 parent ce32f01 commit 3046d4a

File tree

5 files changed

+48
-9
lines changed

5 files changed

+48
-9
lines changed

controllers/akodeploymentconfig/akodeploymentconfig_controller_intg_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ func intgTestAkoDeploymentConfigController() {
309309
latestCluster := &clusterv1.Cluster{}
310310
if err := getCluster(latestCluster, cluster.Name, cluster.Namespace); err == nil {
311311
latestCluster.Finalizers = nil
312-
updateObjects(latestCluster)
313312
deleteObjects(latestCluster)
314313
ensureRuntimeObjectMatchExpectation(client.ObjectKey{
315314
Name: cluster.Name,
@@ -378,7 +377,6 @@ func intgTestAkoDeploymentConfigController() {
378377
latestCluster := &clusterv1.Cluster{}
379378
if err := getCluster(latestCluster, cluster.Name, cluster.Namespace); err == nil {
380379
latestCluster.Finalizers = nil
381-
updateObjects(latestCluster)
382380
deleteObjects(latestCluster)
383381
ensureRuntimeObjectMatchExpectation(client.ObjectKey{
384382
Name: cluster.Name,

controllers/machine/machine_controller_intg_test.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ func intgTestMachineController() {
9393
})
9494
It("Corresponding Endpoints should be created", func() {
9595
ep := &corev1.Endpoints{}
96-
Eventually(func() bool {
97-
err := ctx.Client.Get(ctx.Context, client.ObjectKey{Name: cluster.Namespace + "-" + cluster.Name + "-control-plane", Namespace: cluster.Namespace}, ep)
98-
return err == nil
99-
}).Should(BeTrue())
100-
Expect(ep.Subsets).ShouldNot(BeNil())
101-
Expect(ep.Subsets[0].Addresses).ShouldNot(BeNil())
102-
Expect(len(ep.Subsets[0].Addresses)).Should(Equal(1))
96+
Eventually(func() error {
97+
return ctx.Client.Get(ctx.Context, client.ObjectKey{Name: cluster.Namespace + "-" + cluster.Name + "-control-plane", Namespace: cluster.Namespace}, ep)
98+
}).Should(Succeed())
99+
Eventually(func() int {
100+
if len(ep.Subsets) == 0 {
101+
return 0
102+
}
103+
return len(ep.Subsets[0].Addresses)
104+
}).Should(Equal(1))
103105
Expect(ep.Subsets[0].Addresses[0].IP).Should(Equal("1.1.1.1"))
104106
})
105107
It("Should add one more machine", func() {

pkg/ako-operator/lib.go

+4
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ func GetControlPlaneEndpoint(cluster *clusterv1.Cluster) (string, error) {
110110
}
111111
}
112112
}
113+
if apiServerEndpoint == "" {
114+
apiServerEndpoint = cluster.Spec.ControlPlaneEndpoint.Host
115+
}
116+
113117
return apiServerEndpoint, nil
114118
}
115119

pkg/ako-operator/lib_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,16 @@ var _ = Describe("AKO Operator lib unit test", func() {
353353
Expect(endpoint).Should(Equal(""))
354354
Expect(err).ShouldNot(HaveOccurred())
355355
})
356+
When("ControlPlaneEndpoint.Hosts is set", func() {
357+
BeforeEach(func() {
358+
cluster.Spec.ControlPlaneEndpoint.Host = "10.1.10.1"
359+
})
360+
It("returns that value for the endpoint", func() {
361+
endpoint, err := GetControlPlaneEndpoint(cluster)
362+
Expect(endpoint).Should(Equal("10.1.10.1"))
363+
Expect(err).ShouldNot(HaveOccurred())
364+
})
365+
})
356366
})
357367
When("invalid input ", func() {
358368
var cluster *clusterv1.Cluster

pkg/haprovider/haprovider_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,31 @@ var _ = Describe("Control Plane HA provider", func() {
172172
})
173173
})
174174

175+
When("cluster has ControlPlaneEndpoint.Host set", func() {
176+
BeforeEach(func() {
177+
cluster = &clusterv1.Cluster{
178+
ObjectMeta: v1.ObjectMeta{
179+
Name: "test-cluster",
180+
Namespace: "default",
181+
Annotations: map[string]string{"tkg.tanzu.vmware.com/cluster-controlplane-endpoint": "2.2.2.2"},
182+
},
183+
Spec: clusterv1.ClusterSpec{
184+
ControlPlaneEndpoint: clusterv1.APIEndpoint{
185+
Host: "2.2.2.2",
186+
Port: 6443,
187+
},
188+
},
189+
}
190+
})
191+
It("should create service successfully", func() {
192+
svc, err = haProvider.createService(ctx, cluster)
193+
Expect(err).ShouldNot(HaveOccurred())
194+
Expect(svc.Spec.LoadBalancerIP).Should(Equal("2.2.2.2"))
195+
Expect(svc.Annotations[akoov1alpha1.AkoPreferredIPAnnotation]).Should(Equal("2.2.2.2"))
196+
Expect(haProvider.Client.Delete(ctx, svc)).ShouldNot(HaveOccurred())
197+
})
198+
})
199+
175200
When("cluster has valid FQDN control plane endpoint", func() {
176201
BeforeEach(func() {
177202
cluster = &clusterv1.Cluster{

0 commit comments

Comments
 (0)