Skip to content

Commit f8b9cfd

Browse files
authored
Merge pull request #4724 from AndiDog/logging-fixes
🌱 Fix some logging and error cases
2 parents 2234387 + 322649c commit f8b9cfd

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

controllers/awscluster_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ func (r *AWSClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
162162
return reconcile.Result{}, nil
163163
}
164164

165+
log = log.WithValues("cluster", klog.KObj(cluster))
166+
165167
if capiannotations.IsPaused(cluster, awsCluster) {
166168
log.Info("AWSCluster or linked Cluster is marked as paused. Won't reconcile")
167169
return reconcile.Result{}, nil
168170
}
169171

170-
log = log.WithValues("cluster", klog.KObj(cluster))
171-
172172
// Create the scope.
173173
clusterScope, err := scope.NewClusterScope(scope.ClusterScopeParams{
174174
Client: r.Client,

controlplane/eks/controllers/awsmanagedcontrolplane_controller.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,18 @@ func (r *AWSManagedControlPlaneReconciler) Reconcile(ctx context.Context, req ct
149149
log := logger.FromContext(ctx)
150150

151151
// Get the control plane instance
152-
awsControlPlane := &ekscontrolplanev1.AWSManagedControlPlane{}
153-
if err := r.Client.Get(ctx, req.NamespacedName, awsControlPlane); err != nil {
152+
awsManagedControlPlane := &ekscontrolplanev1.AWSManagedControlPlane{}
153+
if err := r.Client.Get(ctx, req.NamespacedName, awsManagedControlPlane); err != nil {
154154
if apierrors.IsNotFound(err) {
155155
return ctrl.Result{}, nil
156156
}
157-
return ctrl.Result{Requeue: true}, nil
157+
return ctrl.Result{}, err
158158
}
159159

160+
log = log.WithValues("awsManagedControlPlane", klog.KObj(awsManagedControlPlane))
161+
160162
// Get the cluster
161-
cluster, err := util.GetOwnerCluster(ctx, r.Client, awsControlPlane.ObjectMeta)
163+
cluster, err := util.GetOwnerCluster(ctx, r.Client, awsManagedControlPlane.ObjectMeta)
162164
if err != nil {
163165
log.Error(err, "Failed to retrieve owner Cluster from the API Server")
164166
return ctrl.Result{}, err
@@ -168,20 +170,23 @@ func (r *AWSManagedControlPlaneReconciler) Reconcile(ctx context.Context, req ct
168170
return ctrl.Result{}, nil
169171
}
170172

171-
if capiannotations.IsPaused(cluster, awsControlPlane) {
173+
log = log.WithValues("cluster", klog.KObj(cluster))
174+
175+
if capiannotations.IsPaused(cluster, awsManagedControlPlane) {
172176
log.Info("Reconciliation is paused for this object")
173177
return ctrl.Result{}, nil
174178
}
175179

176180
managedScope, err := scope.NewManagedControlPlaneScope(scope.ManagedControlPlaneScopeParams{
177181
Client: r.Client,
178182
Cluster: cluster,
179-
ControlPlane: awsControlPlane,
183+
ControlPlane: awsManagedControlPlane,
180184
ControllerName: strings.ToLower(awsManagedControlPlaneKind),
181185
EnableIAM: r.EnableIAM,
182186
AllowAdditionalRoles: r.AllowAdditionalRoles,
183187
Endpoints: r.Endpoints,
184188
TagUnmanagedNetworkResources: r.TagUnmanagedNetworkResources,
189+
Logger: log,
185190
})
186191
if err != nil {
187192
return reconcile.Result{}, fmt.Errorf("failed to create scope: %w", err)
@@ -221,7 +226,7 @@ func (r *AWSManagedControlPlaneReconciler) Reconcile(ctx context.Context, req ct
221226
}
222227
}()
223228

224-
if !awsControlPlane.ObjectMeta.DeletionTimestamp.IsZero() {
229+
if !awsManagedControlPlane.ObjectMeta.DeletionTimestamp.IsZero() {
225230
// Handle deletion reconciliation loop.
226231
return r.reconcileDelete(ctx, managedScope)
227232
}

pkg/cloud/services/eks/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ func (s *Service) reconcileKubeconfig(ctx context.Context, cluster *eks.Cluster)
6464
cluster,
6565
&clusterRef,
6666
); createErr != nil {
67-
return fmt.Errorf("creating kubeconfig secret: %w", err)
67+
return fmt.Errorf("creating kubeconfig secret: %w", createErr)
6868
}
6969
} else if updateErr := s.updateCAPIKubeconfigSecret(ctx, configSecret, cluster); updateErr != nil {
70-
return fmt.Errorf("updating kubeconfig secret: %w", err)
70+
return fmt.Errorf("updating kubeconfig secret: %w", updateErr)
7171
}
7272

7373
// Set initialized to true to indicate the kubconfig has been created

pkg/cloud/services/eks/roles.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (s *Service) reconcileControlPlaneIAMRole() error {
105105
}
106106

107107
if s.IsUnmanaged(role, s.scope.Name()) {
108-
s.scope.Debug("Skipping, EKS control plane role policy assignment as role is unamanged")
108+
s.scope.Debug("Skipping, EKS control plane role policy assignment as role is unmanaged")
109109
return nil
110110
}
111111

@@ -156,7 +156,7 @@ func (s *Service) deleteControlPlaneIAMRole() error {
156156
}
157157

158158
if s.IsUnmanaged(role, s.scope.Name()) {
159-
s.Debug("Skipping, EKS control plane iam role deletion as role is unamanged")
159+
s.Debug("Skipping, EKS control plane iam role deletion as role is unmanaged")
160160
return nil
161161
}
162162

@@ -213,7 +213,7 @@ func (s *NodegroupService) reconcileNodegroupIAMRole() error {
213213
}
214214

215215
if s.IsUnmanaged(role, s.scope.ClusterName()) {
216-
s.scope.Debug("Skipping, EKS nodegroup role policy assignment as role is unamanged")
216+
s.scope.Debug("Skipping, EKS nodegroup role policy assignment as role is unmanaged")
217217
return nil
218218
}
219219

@@ -278,7 +278,7 @@ func (s *NodegroupService) deleteNodegroupIAMRole() (reterr error) {
278278
}
279279

280280
if s.IsUnmanaged(role, s.scope.ClusterName()) {
281-
s.Debug("Skipping, EKS Nodegroup iam role deletion as role is unamanged")
281+
s.Debug("Skipping, EKS Nodegroup iam role deletion as role is unmanaged")
282282
return nil
283283
}
284284

0 commit comments

Comments
 (0)