Skip to content

Commit

Permalink
Merge pull request #4724 from AndiDog/logging-fixes
Browse files Browse the repository at this point in the history
🌱 Fix some logging and error cases
  • Loading branch information
k8s-ci-robot authored Jan 11, 2024
2 parents 2234387 + 322649c commit f8b9cfd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions controllers/awscluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 12 additions & 7 deletions controlplane/eks/controllers/awsmanagedcontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -168,20 +170,23 @@ 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
}

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)
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud/services/eks/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/cloud/services/eks/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit f8b9cfd

Please sign in to comment.