Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/controllers/reconciliation/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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:
Expand Down
54 changes: 54 additions & 0 deletions internal/controllers/reconciliation/controller_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package reconciliation

import (
"fmt"
"testing"
"time"

Expand All @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion internal/controllers/symphony/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 0 additions & 1 deletion internal/controllers/watch/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading