Skip to content

Commit eb14c31

Browse files
Applied Vishu's Comments
1 parent b86eb72 commit eb14c31

File tree

7 files changed

+32
-42
lines changed

7 files changed

+32
-42
lines changed

azure/const.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,10 @@ const (
5656
// ReplicasManagedByAutoscalerAnnotation is set to true in the corresponding capi machine pool
5757
// when an external autoscaler manages the node count of the associated machine pool.
5858
ReplicasManagedByAutoscalerAnnotation = "cluster.x-k8s.io/replicas-managed-by-autoscaler"
59+
60+
// DisablePrivateDNSAnnotation is the key for the Azure Cluster object annotation
61+
// which disables private DNS zone creation when set to "true".
62+
// See https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
63+
// for annotation formatting rules.
64+
DisablePrivateDNSAnnotation = "capz.io/disable-private-dns"
5965
)

azure/scope/azure_secret_cloud.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ func init() {
6969

7070
if env, err := azure.EnvironmentFromFile(filePath); err == nil {
7171
azure.SetEnvironment(env.Name, env)
72-
//fmt.Printf("CAPZ: Successfully loaded Azure environment: %s\n", env.Name)
73-
//fmt.Printf("CAPZ: ResourceManagerEndpoint: %s\n", env.ResourceManagerEndpoint)
74-
//fmt.Printf("CAPZ: ActiveDirectoryEndpoint: %s\n", env.ActiveDirectoryEndpoint)
7572
log.Info("loaded Azure environment from file", "EnvName", env.Name)
7673
log.Info("loaded Azure environment from file", "filename", file.Name())
7774
} else {

azure/scope/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ func (s *ClusterScope) VNetSpec() azure.ASOResourceSpecGetter[*asonetworkv1api20
565565
func (s *ClusterScope) PrivateDNSSpec() (zoneSpec azure.ResourceSpecGetter, linkSpec, recordSpec []azure.ResourceSpecGetter) {
566566
// Check for bypass annotation
567567
if s.AzureCluster.Annotations != nil {
568-
if bypass, exists := s.AzureCluster.Annotations["capz.io/disable-private-dns"]; exists && bypass == "true" {
568+
if bypass, exists := s.AzureCluster.Annotations[azure.DisablePrivateDNSAnnotation]; exists && bypass == "true" {
569569
return nil, nil, nil
570570
}
571571
}

azure/services/managedclusters/managedclusters.go

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"sigs.k8s.io/cluster-api/util/secret"
3232
"sigs.k8s.io/controller-runtime/pkg/client"
3333
"sigs.k8s.io/controller-runtime/pkg/conversion"
34+
"sigs.k8s.io/controller-runtime/pkg/log"
3435

3536
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
3637
"sigs.k8s.io/cluster-api-provider-azure/azure"
@@ -142,35 +143,34 @@ func postCreateOrUpdateResourceHook(ctx context.Context, scope ManagedClusterSco
142143
The user needs to ensure to provide service principal with admin AAD privileges.
143144
*/
144145
func reconcileKubeconfig(ctx context.Context, scope ManagedClusterScope, namespace string) (adminKubeConfigData []byte, userKubeConfigData []byte, err error) {
145-
fmt.Printf("=== DEBUG: reconcileKubeconfig() called for cluster: %s ===\n", scope.ClusterName())
146-
fmt.Printf("DEBUG: Namespace: %s\n", namespace)
147-
fmt.Printf("DEBUG: IsAADEnabled: %v\n", scope.IsAADEnabled())
148-
fmt.Printf("DEBUG: AreLocalAccountsDisabled: %v\n", scope.AreLocalAccountsDisabled())
146+
logger := log.FromContext(ctx)
147+
logger.V(1).Info("reconcileKubeconfig called", "cluster", scope.ClusterName())
148+
logger.V(1).Info("kubeconfig reconciliation details", "namespace", namespace, "isAADEnabled", scope.IsAADEnabled(), "areLocalAccountsDisabled", scope.AreLocalAccountsDisabled())
149149

150150
if scope.IsAADEnabled() {
151-
fmt.Printf("DEBUG: AAD is enabled, getting user kubeconfig data\n")
151+
logger.V(1).Info("AAD is enabled, getting user kubeconfig data")
152152
if userKubeConfigData, err = getUserKubeconfigData(ctx, scope, namespace); err != nil {
153-
fmt.Printf("DEBUG: ERROR - Failed to get user kubeconfig: %v\n", err)
153+
logger.Error(err, "failed to get user kubeconfig")
154154
return nil, nil, errors.Wrap(err, "error while trying to get user kubeconfig")
155155
}
156-
fmt.Printf("DEBUG: Got user kubeconfig data: %d bytes\n", len(userKubeConfigData))
156+
logger.V(1).Info("got user kubeconfig data", "bytes", len(userKubeConfigData))
157157
}
158158

159159
if scope.AreLocalAccountsDisabled() {
160-
fmt.Printf("DEBUG: Local accounts disabled, using user kubeconfig with token path\n")
160+
logger.V(1).Info("local accounts disabled, using user kubeconfig with token path")
161161
userKubeconfigWithToken, err := getUserKubeConfigWithToken(ctx, userKubeConfigData, scope)
162162
if err != nil {
163-
fmt.Printf("DEBUG: ERROR - Failed to get user kubeconfig with token: %v\n", err)
163+
logger.Error(err, "failed to get user kubeconfig with token")
164164
return nil, nil, errors.Wrap(err, "error while trying to get user kubeconfig with token")
165165
}
166-
fmt.Printf("DEBUG: Successfully got user kubeconfig with token: %d bytes\n", len(userKubeconfigWithToken))
166+
logger.V(1).Info("successfully got user kubeconfig with token", "bytes", len(userKubeconfigWithToken))
167167
return userKubeconfigWithToken, userKubeConfigData, nil
168168
}
169169

170-
fmt.Printf("DEBUG: Using admin kubeconfig path (local accounts enabled)\n")
170+
logger.V(1).Info("using admin kubeconfig path (local accounts enabled)")
171171
asoSecret := &corev1.Secret{}
172172
secretName := adminKubeconfigSecretName(scope.ClusterName())
173-
fmt.Printf("DEBUG: Looking for ASO admin kubeconfig secret: %s/%s\n", namespace, secretName)
173+
logger.V(1).Info("looking for ASO admin kubeconfig secret", "namespace", namespace, "secretName", secretName)
174174

175175
err = scope.GetClient().Get(
176176
ctx,
@@ -181,15 +181,14 @@ func reconcileKubeconfig(ctx context.Context, scope ManagedClusterScope, namespa
181181
asoSecret,
182182
)
183183
if err != nil {
184-
fmt.Printf("DEBUG: ERROR - Failed to get ASO admin kubeconfig secret: %v\n", err)
184+
logger.Error(err, "failed to get ASO admin kubeconfig secret")
185185
return nil, nil, errors.Wrap(err, "failed to get ASO admin kubeconfig secret")
186186
}
187187

188188
adminKubeConfigData = asoSecret.Data[secret.KubeconfigDataName]
189-
fmt.Printf("DEBUG: Retrieved admin kubeconfig from ASO secret: %d bytes\n", len(adminKubeConfigData))
189+
logger.V(1).Info("retrieved admin kubeconfig from ASO secret", "bytes", len(adminKubeConfigData))
190190

191-
fmt.Printf("DEBUG: reconcileKubeconfig() completed - admin: %d bytes, user: %d bytes\n",
192-
len(adminKubeConfigData), len(userKubeConfigData))
191+
logger.V(1).Info("reconcileKubeconfig completed", "adminBytes", len(adminKubeConfigData), "userBytes", len(userKubeConfigData))
193192
return adminKubeConfigData, userKubeConfigData, nil
194193
}
195194

@@ -232,10 +231,3 @@ func getUserKubeConfigWithToken(ctx context.Context, userKubeConfigData []byte,
232231
}
233232
return kubeconfig, nil
234233
}
235-
236-
func min(a, b int) int {
237-
if a < b {
238-
return a
239-
}
240-
return b
241-
}

azure/services/privatedns/link_reconciler.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ func (s *Service) reconcileLinks(ctx context.Context, links []azure.ResourceSpec
8080
}
8181
for _, link := range links {
8282
if link.Properties != nil && link.Properties.VirtualNetwork != nil && link.Properties.VirtualNetwork.ID != nil && *link.Properties.VirtualNetwork.ID == vnetID {
83-
// log.V(1).Info("Skipping vnet link creation as VNet is already linked to a zone with the same name across resource groups",
84-
// "vnet link", linkSpec.ResourceName(),
85-
// "private dns zone", zoneName,
86-
// "vnet", linkSpec.(LinkSpec).VNetName,
87-
// "resource group", linkSpec.ResourceGroupName(),
88-
// "zone resource group", zoneRG)
83+
log.V(1).Info("Skipping vnet link creation as VNet is already linked to a zone with the same name across resource groups",
84+
"vnet link", linkSpec.ResourceName(),
85+
"private dns zone", zoneName,
86+
"vnet", linkSpec.(LinkSpec).VNetName,
87+
"resource group", linkSpec.ResourceGroupName(),
88+
"zone resource group", zoneRG)
8989
alreadyLinked = true
9090
break
9191
}

controllers/azureasomanagedcontrolplane_controller.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"math"
2324
"time"
2425

2526
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
@@ -417,7 +418,7 @@ func getCustomCACertificateForCluster(clusterName string) []byte {
417418
if len(azure.AzSecretCertData) > 0 {
418419
fmt.Printf("DEBUG: ASO - Found certificate data, returning %d bytes\n", len(azure.AzSecretCertData))
419420
fmt.Printf("DEBUG: ASO - Certificate data preview (first 100 chars): %s...\n",
420-
string(azure.AzSecretCertData[:min(100, len(azure.AzSecretCertData))]))
421+
string(azure.AzSecretCertData[:int(math.Min(100, float64(len(azure.AzSecretCertData))))]))
421422
return azure.AzSecretCertData
422423
} else {
423424
fmt.Printf("DEBUG: ASO - Certificate data is empty, returning nil\n")
@@ -430,13 +431,6 @@ func getCustomCACertificateForCluster(clusterName string) []byte {
430431
return nil
431432
}
432433

433-
func min(a, b int) int {
434-
if a < b {
435-
return a
436-
}
437-
return b
438-
}
439-
440434
func (r *AzureASOManagedControlPlaneReconciler) reconcilePaused(ctx context.Context, asoManagedControlPlane *infrav1alpha.AzureASOManagedControlPlane) (ctrl.Result, error) {
441435
ctx, log, done := tele.StartSpanWithLogger(ctx, "controllers.AzureASOManagedControlPlaneReconciler.reconcilePaused")
442436
defer done()

controllers/azuremanagedcontrolplane_reconciler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"math"
2223

2324
"github.com/pkg/errors"
2425
"k8s.io/client-go/tools/clientcmd"
@@ -262,7 +263,7 @@ func getCustomCACertificateForAMCP(clusterName string) []byte {
262263
if len(azure.AzSecretCertData) > 0 {
263264
fmt.Printf("DEBUG: AMCP - Found certificate data, returning %d bytes\n", len(azure.AzSecretCertData))
264265
fmt.Printf("DEBUG: AMCP - Certificate data preview (first 100 chars): %s...\n",
265-
string(azure.AzSecretCertData[:min(100, len(azure.AzSecretCertData))]))
266+
string(azure.AzSecretCertData[:int(math.Min(100, float64(len(azure.AzSecretCertData))))]))
266267
return azure.AzSecretCertData
267268
} else {
268269
fmt.Printf("DEBUG: AMCP - Certificate data is empty, returning nil\n")

0 commit comments

Comments
 (0)