Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure GetControlPlaneEndpoint can still return an IP #177

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ func intgTestAkoDeploymentConfigController() {
latestCluster := &clusterv1.Cluster{}
if err := getCluster(latestCluster, cluster.Name, cluster.Namespace); err == nil {
latestCluster.Finalizers = nil
updateObjects(latestCluster)
deleteObjects(latestCluster)
ensureRuntimeObjectMatchExpectation(client.ObjectKey{
Name: cluster.Name,
Expand Down Expand Up @@ -378,7 +377,6 @@ func intgTestAkoDeploymentConfigController() {
latestCluster := &clusterv1.Cluster{}
if err := getCluster(latestCluster, cluster.Name, cluster.Namespace); err == nil {
latestCluster.Finalizers = nil
updateObjects(latestCluster)
deleteObjects(latestCluster)
ensureRuntimeObjectMatchExpectation(client.ObjectKey{
Name: cluster.Name,
Expand Down
16 changes: 9 additions & 7 deletions controllers/machine/machine_controller_intg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ func intgTestMachineController() {
})
It("Corresponding Endpoints should be created", func() {
ep := &corev1.Endpoints{}
Eventually(func() bool {
err := ctx.Client.Get(ctx.Context, client.ObjectKey{Name: cluster.Namespace + "-" + cluster.Name + "-control-plane", Namespace: cluster.Namespace}, ep)
return err == nil
}).Should(BeTrue())
Expect(ep.Subsets).ShouldNot(BeNil())
Expect(ep.Subsets[0].Addresses).ShouldNot(BeNil())
Expect(len(ep.Subsets[0].Addresses)).Should(Equal(1))
Eventually(func() error {
return ctx.Client.Get(ctx.Context, client.ObjectKey{Name: cluster.Namespace + "-" + cluster.Name + "-control-plane", Namespace: cluster.Namespace}, ep)
}).Should(Succeed())
Eventually(func() int {
if len(ep.Subsets) == 0 {
return 0
}
return len(ep.Subsets[0].Addresses)
}).Should(Equal(1))
Expect(ep.Subsets[0].Addresses[0].IP).Should(Equal("1.1.1.1"))
})
It("Should add one more machine", func() {
Expand Down
4 changes: 4 additions & 0 deletions pkg/ako-operator/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func GetControlPlaneEndpoint(cluster *clusterv1.Cluster) (string, error) {
}
}
}
if apiServerEndpoint == "" {
apiServerEndpoint = cluster.Spec.ControlPlaneEndpoint.Host
}

return apiServerEndpoint, nil
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/ako-operator/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@ var _ = Describe("AKO Operator lib unit test", func() {
Expect(endpoint).Should(Equal(""))
Expect(err).ShouldNot(HaveOccurred())
})
When("ControlPlaneEndpoint.Hosts is set", func() {
BeforeEach(func() {
cluster.Spec.ControlPlaneEndpoint.Host = "10.1.10.1"
})
It("returns that value for the endpoint", func() {
endpoint, err := GetControlPlaneEndpoint(cluster)
Expect(endpoint).Should(Equal("10.1.10.1"))
Expect(err).ShouldNot(HaveOccurred())
})
})
})
When("invalid input ", func() {
var cluster *clusterv1.Cluster
Expand Down
25 changes: 25 additions & 0 deletions pkg/haprovider/haprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,31 @@ var _ = Describe("Control Plane HA provider", func() {
})
})

When("cluster has ControlPlaneEndpoint.Host set", func() {
BeforeEach(func() {
cluster = &clusterv1.Cluster{
ObjectMeta: v1.ObjectMeta{
Name: "test-cluster",
Namespace: "default",
Annotations: map[string]string{"tkg.tanzu.vmware.com/cluster-controlplane-endpoint": "2.2.2.2"},
},
Spec: clusterv1.ClusterSpec{
ControlPlaneEndpoint: clusterv1.APIEndpoint{
Host: "2.2.2.2",
Port: 6443,
},
},
}
})
It("should create service successfully", func() {
svc, err = haProvider.createService(ctx, cluster)
Expect(err).ShouldNot(HaveOccurred())
Expect(svc.Spec.LoadBalancerIP).Should(Equal("2.2.2.2"))
Expect(svc.Annotations[akoov1alpha1.AkoPreferredIPAnnotation]).Should(Equal("2.2.2.2"))
Expect(haProvider.Client.Delete(ctx, svc)).ShouldNot(HaveOccurred())
})
})

When("cluster has valid FQDN control plane endpoint", func() {
BeforeEach(func() {
cluster = &clusterv1.Cluster{
Expand Down
Loading