Skip to content

Commit

Permalink
Set correct fqdn on private cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaiandreiratoiu committed Nov 7, 2023
1 parent ebec548 commit 09bb886
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions azure/services/managedclusters/managedclusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ func (s *Service) Reconcile(ctx context.Context) error {
Host: pointer.StringDeref(managedCluster.ManagedClusterProperties.Fqdn, ""),
Port: 443,
}
if pointer.BoolDeref(managedCluster.ManagedClusterProperties.APIServerAccessProfile.EnablePrivateCluster, false) &&
!pointer.BoolDeref(managedCluster.ManagedClusterProperties.APIServerAccessProfile.EnablePrivateClusterPublicFQDN, false) {
endpoint = clusterv1.APIEndpoint{
Host: pointer.StringDeref(managedCluster.ManagedClusterProperties.PrivateFQDN, ""),
Port: 443,
}
}
s.Scope.SetControlPlaneEndpoint(endpoint)

// Update kubeconfig data
Expand Down
30 changes: 30 additions & 0 deletions azure/services/managedclusters/managedclusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,36 @@ func TestReconcile(t *testing.T) {
s.UpdatePutStatus(infrav1.ManagedClusterRunningCondition, serviceName, nil)
},
},
{
name: "create managed private cluster succeeds",
expectedError: "",
expect: func(m *mock_managedclusters.MockCredentialGetterMockRecorder, s *mock_managedclusters.MockManagedClusterScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.ManagedClusterSpec().Return(fakeManagedClusterSpec)
r.CreateOrUpdateResource(gomockinternal.AContext(), fakeManagedClusterSpec, serviceName).Return(containerservice.ManagedCluster{
ManagedClusterProperties: &containerservice.ManagedClusterProperties{
APIServerAccessProfile: &containerservice.ManagedClusterAPIServerAccessProfile{
EnablePrivateCluster: pointer.Bool(true),
EnablePrivateClusterPublicFQDN: pointer.Bool(false),
},
PrivateFQDN: pointer.String("my-managedcluster-fqdn.private"),
ProvisioningState: pointer.String("Succeeded"),
IdentityProfile: map[string]*containerservice.UserAssignedIdentity{
kubeletIdentityKey: {
ResourceID: pointer.String("kubelet-id"),
},
},
},
}, nil)
s.SetControlPlaneEndpoint(clusterv1.APIEndpoint{
Host: "my-managedcluster-fqdn.private",
Port: 443,
})
m.GetCredentials(gomockinternal.AContext(), "my-rg", "my-managedcluster").Return([]byte("credentials"), nil)
s.SetKubeConfigData([]byte("credentials"))
s.SetKubeletIdentity("kubelet-id")
s.UpdatePutStatus(infrav1.ManagedClusterRunningCondition, serviceName, nil)
},
},
{
name: "fail to get managed cluster credentials",
expectedError: "failed to get credentials for managed cluster: internal server error",
Expand Down

0 comments on commit 09bb886

Please sign in to comment.