From 322649c90d1da80a77f4fccca95bdac07c5bc17a Mon Sep 17 00:00:00 2001 From: Andreas Sommer Date: Fri, 5 Jan 2024 10:29:22 +0100 Subject: [PATCH] Fix some logging and error cases --- controllers/awscluster_controller.go | 4 ++-- .../awsmanagedcontrolplane_controller.go | 19 ++++++++++++------- pkg/cloud/services/eks/config.go | 4 ++-- pkg/cloud/services/eks/roles.go | 8 ++++---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/controllers/awscluster_controller.go b/controllers/awscluster_controller.go index 49de7add0a..8fa29f610c 100644 --- a/controllers/awscluster_controller.go +++ b/controllers/awscluster_controller.go @@ -162,13 +162,13 @@ func (r *AWSClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) return reconcile.Result{}, nil } + log = log.WithValues("cluster", klog.KObj(cluster)) + if capiannotations.IsPaused(cluster, awsCluster) { log.Info("AWSCluster or linked Cluster is marked as paused. Won't reconcile") return reconcile.Result{}, nil } - log = log.WithValues("cluster", klog.KObj(cluster)) - // Create the scope. clusterScope, err := scope.NewClusterScope(scope.ClusterScopeParams{ Client: r.Client, diff --git a/controlplane/eks/controllers/awsmanagedcontrolplane_controller.go b/controlplane/eks/controllers/awsmanagedcontrolplane_controller.go index 2a8ff4f9c0..2ed1579ec1 100644 --- a/controlplane/eks/controllers/awsmanagedcontrolplane_controller.go +++ b/controlplane/eks/controllers/awsmanagedcontrolplane_controller.go @@ -149,16 +149,18 @@ func (r *AWSManagedControlPlaneReconciler) Reconcile(ctx context.Context, req ct log := logger.FromContext(ctx) // Get the control plane instance - awsControlPlane := &ekscontrolplanev1.AWSManagedControlPlane{} - if err := r.Client.Get(ctx, req.NamespacedName, awsControlPlane); err != nil { + awsManagedControlPlane := &ekscontrolplanev1.AWSManagedControlPlane{} + if err := r.Client.Get(ctx, req.NamespacedName, awsManagedControlPlane); err != nil { if apierrors.IsNotFound(err) { return ctrl.Result{}, nil } - return ctrl.Result{Requeue: true}, nil + return ctrl.Result{}, err } + log = log.WithValues("awsManagedControlPlane", klog.KObj(awsManagedControlPlane)) + // Get the cluster - cluster, err := util.GetOwnerCluster(ctx, r.Client, awsControlPlane.ObjectMeta) + cluster, err := util.GetOwnerCluster(ctx, r.Client, awsManagedControlPlane.ObjectMeta) if err != nil { log.Error(err, "Failed to retrieve owner Cluster from the API Server") return ctrl.Result{}, err @@ -168,7 +170,9 @@ func (r *AWSManagedControlPlaneReconciler) Reconcile(ctx context.Context, req ct return ctrl.Result{}, nil } - if capiannotations.IsPaused(cluster, awsControlPlane) { + log = log.WithValues("cluster", klog.KObj(cluster)) + + if capiannotations.IsPaused(cluster, awsManagedControlPlane) { log.Info("Reconciliation is paused for this object") return ctrl.Result{}, nil } @@ -176,12 +180,13 @@ func (r *AWSManagedControlPlaneReconciler) Reconcile(ctx context.Context, req ct managedScope, err := scope.NewManagedControlPlaneScope(scope.ManagedControlPlaneScopeParams{ Client: r.Client, Cluster: cluster, - ControlPlane: awsControlPlane, + ControlPlane: awsManagedControlPlane, ControllerName: strings.ToLower(awsManagedControlPlaneKind), EnableIAM: r.EnableIAM, AllowAdditionalRoles: r.AllowAdditionalRoles, Endpoints: r.Endpoints, TagUnmanagedNetworkResources: r.TagUnmanagedNetworkResources, + Logger: log, }) if err != nil { return reconcile.Result{}, fmt.Errorf("failed to create scope: %w", err) @@ -221,7 +226,7 @@ func (r *AWSManagedControlPlaneReconciler) Reconcile(ctx context.Context, req ct } }() - if !awsControlPlane.ObjectMeta.DeletionTimestamp.IsZero() { + if !awsManagedControlPlane.ObjectMeta.DeletionTimestamp.IsZero() { // Handle deletion reconciliation loop. return r.reconcileDelete(ctx, managedScope) } diff --git a/pkg/cloud/services/eks/config.go b/pkg/cloud/services/eks/config.go index 7298e9f61a..8559c2fa7f 100644 --- a/pkg/cloud/services/eks/config.go +++ b/pkg/cloud/services/eks/config.go @@ -64,10 +64,10 @@ func (s *Service) reconcileKubeconfig(ctx context.Context, cluster *eks.Cluster) cluster, &clusterRef, ); createErr != nil { - return fmt.Errorf("creating kubeconfig secret: %w", err) + return fmt.Errorf("creating kubeconfig secret: %w", createErr) } } else if updateErr := s.updateCAPIKubeconfigSecret(ctx, configSecret, cluster); updateErr != nil { - return fmt.Errorf("updating kubeconfig secret: %w", err) + return fmt.Errorf("updating kubeconfig secret: %w", updateErr) } // Set initialized to true to indicate the kubconfig has been created diff --git a/pkg/cloud/services/eks/roles.go b/pkg/cloud/services/eks/roles.go index 3d10314432..f6892545ed 100644 --- a/pkg/cloud/services/eks/roles.go +++ b/pkg/cloud/services/eks/roles.go @@ -105,7 +105,7 @@ func (s *Service) reconcileControlPlaneIAMRole() error { } if s.IsUnmanaged(role, s.scope.Name()) { - s.scope.Debug("Skipping, EKS control plane role policy assignment as role is unamanged") + s.scope.Debug("Skipping, EKS control plane role policy assignment as role is unmanaged") return nil } @@ -156,7 +156,7 @@ func (s *Service) deleteControlPlaneIAMRole() error { } if s.IsUnmanaged(role, s.scope.Name()) { - s.Debug("Skipping, EKS control plane iam role deletion as role is unamanged") + s.Debug("Skipping, EKS control plane iam role deletion as role is unmanaged") return nil } @@ -213,7 +213,7 @@ func (s *NodegroupService) reconcileNodegroupIAMRole() error { } if s.IsUnmanaged(role, s.scope.ClusterName()) { - s.scope.Debug("Skipping, EKS nodegroup role policy assignment as role is unamanged") + s.scope.Debug("Skipping, EKS nodegroup role policy assignment as role is unmanaged") return nil } @@ -278,7 +278,7 @@ func (s *NodegroupService) deleteNodegroupIAMRole() (reterr error) { } if s.IsUnmanaged(role, s.scope.ClusterName()) { - s.Debug("Skipping, EKS Nodegroup iam role deletion as role is unamanged") + s.Debug("Skipping, EKS Nodegroup iam role deletion as role is unmanaged") return nil }