diff --git a/internal/controllers/reconciliation/controller.go b/internal/controllers/reconciliation/controller.go index ffabbb45..7959c4ae 100644 --- a/internal/controllers/reconciliation/controller.go +++ b/internal/controllers/reconciliation/controller.go @@ -340,7 +340,7 @@ func (c *Controller) reconcileSnapshot(ctx context.Context, comp *apiv1.Composit dryRunPrev := snap.Unstructured() err = c.upstreamClient.Patch(ctx, dryRunPrev, client.Apply, client.ForceOwnership, client.FieldOwner("eno"), client.DryRunAll) if err != nil { - logger.Error(err, "faile dto get managedFields values") + logger.Error(err, "failed to get managedFields values") return false, fmt.Errorf("getting managed fields values for previous version: %w", err) } @@ -506,7 +506,9 @@ func summarizeError(err error) string { metav1.StatusReasonMethodNotAllowed, metav1.StatusReasonGone, metav1.StatusReasonForbidden, - metav1.StatusReasonUnauthorized: + metav1.StatusReasonUnauthorized, + metav1.StatusReasonInvalid, + metav1.StatusReasonInternalError: return status.Message default: diff --git a/internal/controllers/reconciliation/controller_test.go b/internal/controllers/reconciliation/controller_test.go index edb3d0fb..b8653211 100644 --- a/internal/controllers/reconciliation/controller_test.go +++ b/internal/controllers/reconciliation/controller_test.go @@ -1,6 +1,7 @@ package reconciliation import ( + "fmt" "testing" "time" @@ -12,7 +13,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -119,6 +122,57 @@ func TestShouldFailOpen(t *testing.T) { assert.True(t, c.shouldFailOpen(&resource.Resource{FailOpen: ptr.To(true)})) } +func TestSummarizeError(t *testing.T) { + tests := []struct { + name string + err error + expected string + }{ + { + name: "nil error returns empty string", + err: nil, + expected: "", + }, + { + name: "non-status error returns empty string", + err: fmt.Errorf("some random error"), + expected: "", + }, + { + name: "StatusReasonInvalid is captured", + err: errors.NewInvalid(schema.GroupKind{Group: "apps", Kind: "Deployment"}, "kube-apiserver", nil), + expected: "Deployment.apps \"kube-apiserver\" is invalid", + }, + { + name: "StatusReasonInternalError is captured", + err: errors.NewInternalError(fmt.Errorf("failed calling webhook")), + expected: "Internal error occurred: failed calling webhook", + }, + { + name: "StatusReasonBadRequest is captured", + err: errors.NewBadRequest("bad request"), + expected: "bad request", + }, + { + name: "StatusReasonForbidden is captured", + err: errors.NewForbidden(schema.GroupResource{Group: "apps", Resource: "deployments"}, "test", fmt.Errorf("not allowed")), + expected: "deployments.apps \"test\" is forbidden: not allowed", + }, + { + name: "StatusReasonNotFound is not captured", + err: errors.NewNotFound(schema.GroupResource{Group: "apps", Resource: "deployments"}, "test"), + expected: "", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := summarizeError(tt.err) + assert.Equal(t, tt.expected, result) + }) + } +} + func TestRequeueDoesNotPanic(t *testing.T) { type testState struct { snapshot *resource.Snapshot diff --git a/internal/controllers/symphony/controller.go b/internal/controllers/symphony/controller.go index 0de6ba06..b054ef92 100644 --- a/internal/controllers/symphony/controller.go +++ b/internal/controllers/symphony/controller.go @@ -143,7 +143,6 @@ func (c *symphonyController) reconcileReverse(ctx context.Context, symph *apiv1. labelInSync := symph.DeletionTimestamp == nil || (comp.Labels != nil && comp.Labels[deletionLabelKey] == "true") alreadyDeleted := comp.DeletionTimestamp != nil if shouldExist || (alreadyDeleted && labelInSync) { - logger.Info("composition should exist or is already being deleted properly", "compositionName", comp.Name, "compositionNamespace", comp.Namespace) continue } diff --git a/internal/controllers/watch/pruning.go b/internal/controllers/watch/pruning.go index 401522cd..e5341dc4 100644 --- a/internal/controllers/watch/pruning.go +++ b/internal/controllers/watch/pruning.go @@ -40,7 +40,6 @@ func (c *pruningController) Reconcile(ctx context.Context, req ctrl.Request) (ct for i, ir := range comp.Status.InputRevisions { if hasBindingKey(comp, synth, ir.Key) { - logger.Info("input revision still has binding, keeping", "key", ir.Key, "revision", ir.Revision) continue } logger.Info("pruning input revision - no longer has binding", "key", ir.Key, "revision", ir.Revision, "index", i)