From 77cf93394c910c7ee85670180b5f61e45a2af617 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Mon, 9 Oct 2023 15:26:30 +0200 Subject: [PATCH 1/5] misc: address theoretical nil pointer dereference Signed-off-by: Hidde Beydals --- internal/controller/kustomization_controller.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/controller/kustomization_controller.go b/internal/controller/kustomization_controller.go index 3bb6d86d..eecdb32f 100644 --- a/internal/controller/kustomization_controller.go +++ b/internal/controller/kustomization_controller.go @@ -747,9 +747,10 @@ func (r *KustomizationReconciler) apply(ctx context.Context, if err != nil { return false, nil, err } - resultSet.Append(changeSet.Entries) if changeSet != nil && len(changeSet.Entries) > 0 { + resultSet.Append(changeSet.Entries) + log.Info("server-side apply for cluster definitions completed", "output", changeSet.ToMap()) for _, change := range changeSet.Entries { if HasChanged(change.Action) { @@ -772,9 +773,10 @@ func (r *KustomizationReconciler) apply(ctx context.Context, if err != nil { return false, nil, err } - resultSet.Append(changeSet.Entries) if changeSet != nil && len(changeSet.Entries) > 0 { + resultSet.Append(changeSet.Entries) + log.Info("server-side apply for cluster class types completed", "output", changeSet.ToMap()) for _, change := range changeSet.Entries { if HasChanged(change.Action) { @@ -798,9 +800,10 @@ func (r *KustomizationReconciler) apply(ctx context.Context, if err != nil { return false, nil, fmt.Errorf("%w\n%s", err, changeSetLog.String()) } - resultSet.Append(changeSet.Entries) if changeSet != nil && len(changeSet.Entries) > 0 { + resultSet.Append(changeSet.Entries) + log.Info("server-side apply completed", "output", changeSet.ToMap(), "revision", revision) for _, change := range changeSet.Entries { if HasChanged(change.Action) { From 87fd394ce4f59dfa1059b6349e5166d7e3f2a254 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Mon, 9 Oct 2023 15:30:27 +0200 Subject: [PATCH 2/5] misc: address `k8s.io/utils/pointer` deprecation Signed-off-by: Hidde Beydals --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 13e8ea91..12ab2d52 100644 --- a/main.go +++ b/main.go @@ -27,7 +27,7 @@ import ( clientgoscheme "k8s.io/client-go/kubernetes/scheme" _ "k8s.io/client-go/plugin/pkg/client/auth/azure" _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/cli-utils/pkg/kstatus/polling" "sigs.k8s.io/cli-utils/pkg/kstatus/polling/clusterreader" "sigs.k8s.io/cli-utils/pkg/kstatus/polling/engine" @@ -183,7 +183,7 @@ func main() { }, Controller: ctrlcfg.Controller{ MaxConcurrentReconciles: concurrent, - RecoverPanic: pointer.Bool(true), + RecoverPanic: ptr.To(true), }, }) if err != nil { From 364ce9f98a0ae35b512ece2909bbf00ff024b6db Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Mon, 9 Oct 2023 15:32:47 +0200 Subject: [PATCH 3/5] misc: fix formatting various errors Signed-off-by: Hidde Beydals --- internal/controller/kustomization_controller.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/controller/kustomization_controller.go b/internal/controller/kustomization_controller.go index eecdb32f..6ea02346 100644 --- a/internal/controller/kustomization_controller.go +++ b/internal/controller/kustomization_controller.go @@ -301,7 +301,7 @@ func (r *KustomizationReconciler) reconcile( conditions.MarkUnknown(obj, meta.ReadyCondition, meta.ProgressingReason, "Reconciliation in progress") conditions.MarkReconciling(obj, meta.ProgressingReason, progressingMsg) if err := r.patch(ctx, obj, patcher); err != nil { - return fmt.Errorf("failed to update status, error: %w", err) + return fmt.Errorf("failed to update status: %w", err) } // Create a snapshot of the current inventory. @@ -345,7 +345,7 @@ func (r *KustomizationReconciler) reconcile( progressingMsg = fmt.Sprintf("Building manifests for revision %s with a timeout of %s", revision, obj.GetTimeout().String()) conditions.MarkReconciling(obj, meta.ProgressingReason, progressingMsg) if err := r.patch(ctx, obj, patcher); err != nil { - return fmt.Errorf("failed to update status, error: %w", err) + return fmt.Errorf("failed to update status: %w", err) } // Configure the Kubernetes client for impersonation. @@ -405,7 +405,7 @@ func (r *KustomizationReconciler) reconcile( progressingMsg = fmt.Sprintf("Detecting drift for revision %s with a timeout of %s", revision, obj.GetTimeout().String()) conditions.MarkReconciling(obj, meta.ProgressingReason, progressingMsg) if err := r.patch(ctx, obj, patcher); err != nil { - return fmt.Errorf("failed to update status, error: %w", err) + return fmt.Errorf("failed to update status: %w", err) } // Validate and apply resources in stages. @@ -868,7 +868,7 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context, conditions.MarkReconciling(obj, meta.ProgressingReason, message) conditions.MarkUnknown(obj, kustomizev1.HealthyCondition, meta.ProgressingReason, message) if err := r.patch(ctx, obj, patcher); err != nil { - return fmt.Errorf("unable to update the healthy status to progressing, error: %w", err) + return fmt.Errorf("unable to update the healthy status to progressing: %w", err) } // Check the health with a default timeout of 30sec shorter than the reconciliation interval. @@ -879,7 +879,7 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context, }); err != nil { conditions.MarkFalse(obj, meta.ReadyCondition, kustomizev1.HealthCheckFailedReason, err.Error()) conditions.MarkFalse(obj, kustomizev1.HealthyCondition, kustomizev1.HealthCheckFailedReason, err.Error()) - return fmt.Errorf("Health check failed after %s: %w", time.Since(checkStart).String(), err) + return fmt.Errorf("health check failed after %s: %w", time.Since(checkStart).String(), err) } // Emit recovery event if the previous health check failed. @@ -890,7 +890,7 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context, conditions.MarkTrue(obj, kustomizev1.HealthyCondition, meta.SucceededReason, msg) if err := r.patch(ctx, obj, patcher); err != nil { - return fmt.Errorf("unable to update the healthy status to progressing, error: %w", err) + return fmt.Errorf("unable to update the healthy status to progressing: %w", err) } return nil From 205a0b4feac116b128f394ae544f088e5d465a9e Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Mon, 9 Oct 2023 15:33:37 +0200 Subject: [PATCH 4/5] misc: check err value in test Signed-off-by: Hidde Beydals --- internal/sops/keyservice/server_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/sops/keyservice/server_test.go b/internal/sops/keyservice/server_test.go index be17701b..7b32a695 100644 --- a/internal/sops/keyservice/server_test.go +++ b/internal/sops/keyservice/server_test.go @@ -133,6 +133,7 @@ func TestServer_EncryptDecrypt_HCVault_Fallback(t *testing.T) { Ciphertext: []byte("some ciphertext"), } _, err = s.Decrypt(context.TODO(), decReq) + g.Expect(err).To(HaveOccurred()) g.Expect(fallback.decryptReqs).To(HaveLen(1)) g.Expect(fallback.decryptReqs).To(ContainElement(decReq)) g.Expect(fallback.encryptReqs).To(HaveLen(0)) From af9368295ee2921a68590170f5c050ee8fd0bbcb Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Mon, 9 Oct 2023 16:33:44 +0200 Subject: [PATCH 5/5] misc: fix hypothetical implicit memory aliasing Signed-off-by: Hidde Beydals --- internal/controller/kustomization_indexers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/controller/kustomization_indexers.go b/internal/controller/kustomization_indexers.go index 226fa1e1..e3c6ce27 100644 --- a/internal/controller/kustomization_indexers.go +++ b/internal/controller/kustomization_indexers.go @@ -56,10 +56,10 @@ func (r *KustomizationReconciler) requestsForRevisionChangeOf(indexKey string) h return nil } var dd []dependency.Dependent - for _, d := range list.Items { + for i, d := range list.Items { // If the Kustomization is ready and the revision of the artifact equals // to the last attempted revision, we should not make a request for this Kustomization - if conditions.IsReady(&d) && repo.GetArtifact().HasRevision(d.Status.LastAttemptedRevision) { + if conditions.IsReady(&list.Items[i]) && repo.GetArtifact().HasRevision(d.Status.LastAttemptedRevision) { continue } dd = append(dd, d.DeepCopy())