diff --git a/internal/resource/resource.go b/internal/resource/resource.go index 94826036..c81f6bae 100644 --- a/internal/resource/resource.go +++ b/internal/resource/resource.go @@ -244,7 +244,7 @@ func NewResource(ctx context.Context, slice *apiv1.ResourceSlice, index int) (*R if str, ok := anno[reconcileIntervalKey]; ok { reconcileInterval, err := time.ParseDuration(str) if anno[reconcileIntervalKey] != "" && err != nil { - logger.V(0).Info("invalid reconcile interval - ignoring") + return nil, fmt.Errorf("invalid reconcile interval, %s", str) } res.ReconcileInterval = &metav1.Duration{Duration: reconcileInterval} } @@ -259,7 +259,7 @@ func NewResource(ctx context.Context, slice *apiv1.ResourceSlice, index int) (*R if js, ok := anno[overridesKey]; ok { err = json.Unmarshal([]byte(js), &res.Overrides) if err != nil { - logger.Error(err, "invalid override json") + return nil, fmt.Errorf("invalid override json, %s", err) } } @@ -267,10 +267,9 @@ func NewResource(ctx context.Context, slice *apiv1.ResourceSlice, index int) (*R if str, ok := anno[readinessGroupKey]; ok { rg, err := strconv.Atoi(str) if err != nil { - logger.V(0).Info("invalid readiness group - ignoring") - } else { - res.ReadinessGroup = rg + return nil, fmt.Errorf("invalid readiness group, %s", str) } + res.ReadinessGroup = rg } for key, value := range anno { diff --git a/internal/resource/resource_test.go b/internal/resource/resource_test.go index 1e6a8108..0eea12e7 100644 --- a/internal/resource/resource_test.go +++ b/internal/resource/resource_test.go @@ -262,22 +262,6 @@ var newResourceTests = []struct { }, r.parsed) }, }, - { - Name: "invalid-override-json", - Manifest: `{ - "apiVersion": "v1", - "kind": "ConfigMap", - "metadata": { - "name": "foo", - "annotations": { - "eno.azure.io/overrides": "not json" - } - } - }`, - Assert: func(t *testing.T, r *Resource) { - assert.Len(t, r.Overrides, 0) - }, - }, { Name: "labels", Manifest: `{ @@ -328,6 +312,70 @@ func TestNewResource(t *testing.T) { } } +func TestNewResourceFailures(t *testing.T) { + ctx := context.Background() + tests := []struct { + name string + manifest string + wantErr string + }{ + { + name: "invalid-override-json", + manifest: `{ + "apiVersion": "v1", + "kind": "ConfigMap", + "metadata": { + "name": "foo", + "annotations": { + "eno.azure.io/overrides": "[{\"path\":\".foo\", invalid json" + } + } + }`, + wantErr: "invalid override json", + }, + { + name: "bad-duration-reconcile-interval", + manifest: `{ + "apiVersion": "v1", + "kind": "ConfigMap", + "metadata": { + "name": "foo", + "annotations": { + "eno.azure.io/reconcile-interval": "not-a-duration" + } + } + }`, + wantErr: "invalid reconcile interval", + }, + { + name: "not-a-number-readiness-group", + manifest: `{ + "apiVersion": "v1", + "kind": "ConfigMap", + "metadata": { + "name": "foo", + "annotations": { + "eno.azure.io/readiness-group": "not-a-number" + } + } + }`, + wantErr: "invalid readiness group", + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + _, err := NewResource(ctx, &apiv1.ResourceSlice{ + Spec: apiv1.ResourceSliceSpec{ + Resources: []apiv1.Manifest{{Manifest: tc.manifest}}, + }, + }, 0) + require.Error(t, err) + assert.Contains(t, err.Error(), tc.wantErr) + }) + } +} + func TestResourceOrdering(t *testing.T) { resources := []*Resource{ {ManifestHash: []byte("a")},