Skip to content

Commit 75fd3dd

Browse files
Merge pull request #38 from ctrlplanedev/fix-aks-endpoint
fix(aks): correct the endpoint
2 parents ad56622 + f51ad57 commit 75fd3dd

File tree

1 file changed

+19
-12
lines changed
  • cmd/ctrlc/root/sync/azure/aks

1 file changed

+19
-12
lines changed

cmd/ctrlc/root/sync/azure/aks/aks.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,6 @@ func processCluster(_ context.Context, cluster *armcontainerservice.ManagedClust
223223
certificateAuthorityData := ""
224224
// The Azure SDK may not expose KubeConfig directly, we'll handle this gracefully
225225

226-
endpoint := ""
227-
if cluster.Properties.PrivateFQDN != nil {
228-
endpoint = *cluster.Properties.PrivateFQDN
229-
} else if cluster.Properties.Fqdn != nil {
230-
endpoint = *cluster.Properties.Fqdn
231-
}
232-
233226
return api.ResourceProviderResource{
234227
Version: "ctrlplane.dev/kubernetes/cluster/v1",
235228
Kind: "AzureKubernetesService",
@@ -239,7 +232,7 @@ func processCluster(_ context.Context, cluster *armcontainerservice.ManagedClust
239232
"name": *cluster.Name,
240233
"version": *cluster.Properties.KubernetesVersion,
241234
"server": map[string]any{
242-
"endpoint": endpoint,
235+
"endpoint": getEndpoint(cluster),
243236
"certificateAuthorityData": certificateAuthorityData,
244237
},
245238

@@ -389,13 +382,27 @@ func initClusterMetadata(cluster *armcontainerservice.ManagedCluster, subscripti
389382
}
390383

391384
func getEndpoint(cluster *armcontainerservice.ManagedCluster) string {
385+
endpoint := ""
392386
if cluster.Properties.PrivateFQDN != nil {
393-
return *cluster.Properties.PrivateFQDN
387+
endpoint = *cluster.Properties.PrivateFQDN
388+
} else if cluster.Properties.Fqdn != nil {
389+
endpoint = *cluster.Properties.Fqdn
394390
}
395-
if cluster.Properties.Fqdn != nil {
396-
return *cluster.Properties.Fqdn
391+
392+
if endpoint == "" {
393+
return ""
397394
}
398-
return ""
395+
396+
if !strings.HasPrefix(endpoint, "http://") && !strings.HasPrefix(endpoint, "https://") {
397+
endpoint = fmt.Sprintf("https://%s", endpoint)
398+
}
399+
400+
// AKS kubeconfig includes :443, and ArgoCD uses the exact server URL as identifier
401+
if !strings.Contains(endpoint, ":443") {
402+
endpoint = fmt.Sprintf("%s:443", endpoint)
403+
}
404+
405+
return endpoint
399406
}
400407

401408
func extractResourceGroupFromID(id string) string {

0 commit comments

Comments
 (0)