Skip to content

Commit

Permalink
fix: allow updates of CRP with invalid fields when CRP is deleting (#878
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Arvindthiru committed Jul 17, 2024
1 parent d9fc197 commit dc3b75a
Show file tree
Hide file tree
Showing 7 changed files with 715 additions and 124 deletions.
65 changes: 24 additions & 41 deletions pkg/controllers/work/apply_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -85,22 +84,6 @@ var (
}}
)

// This interface is needed for testMapper abstract class.
type testMapper struct {
meta.RESTMapper
}

func (m testMapper) RESTMapping(gk schema.GroupKind, _ ...string) (*meta.RESTMapping, error) {
if gk.Kind == "Deployment" {
return &meta.RESTMapping{
Resource: utils.DeploymentGVR,
GroupVersionKind: testDeployment.GroupVersionKind(),
Scope: nil,
}, nil
}
return nil, errors.New("test error: mapping does not exist")
}

func TestSetManifestHashAnnotation(t *testing.T) {
// basic setup
manifestObj := appsv1.Deployment{
Expand Down Expand Up @@ -1568,7 +1551,7 @@ func TestApplyUnstructuredAndTrackAvailability(t *testing.T) {
client: &test.MockClient{},
spokeDynamicClient: dynamicClientNotFound,
spokeClient: &test.MockClient{},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
},
workObj: correctObj.DeepCopy(),
Expand All @@ -1581,7 +1564,7 @@ func TestApplyUnstructuredAndTrackAvailability(t *testing.T) {
client: &test.MockClient{},
spokeDynamicClient: generatedSpecDynamicClient,
spokeClient: &test.MockClient{},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
},
workObj: generatedSpecObj.DeepCopy(),
Expand All @@ -1594,7 +1577,7 @@ func TestApplyUnstructuredAndTrackAvailability(t *testing.T) {
client: &test.MockClient{},
spokeDynamicClient: dynamicClientError,
spokeClient: &test.MockClient{},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
},
workObj: correctObj.DeepCopy(),
Expand All @@ -1616,7 +1599,7 @@ func TestApplyUnstructuredAndTrackAvailability(t *testing.T) {
},
spokeDynamicClient: diffOwnerDynamicClient,
spokeClient: &test.MockClient{},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
},
workObj: correctObj.DeepCopy(),
Expand All @@ -1643,7 +1626,7 @@ func TestApplyUnstructuredAndTrackAvailability(t *testing.T) {
},
spokeDynamicClient: diffOwnerDynamicClient,
spokeClient: &test.MockClient{},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
},
allowCoOwnership: true,
Expand All @@ -1670,7 +1653,7 @@ func TestApplyUnstructuredAndTrackAvailability(t *testing.T) {
},
spokeDynamicClient: deploymentOwnedByAnotherWorkClient,
spokeClient: &test.MockClient{},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
},
workObj: correctObj.DeepCopy(),
Expand Down Expand Up @@ -1730,7 +1713,7 @@ func TestApplyUnstructuredAndTrackAvailability(t *testing.T) {
"happy path - with updates (three way merge patch)": {
reconciler: ApplyWorkReconciler{
spokeDynamicClient: diffSpecDynamicClient,
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
client: &test.MockClient{
MockGet: func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
Expand All @@ -1755,7 +1738,7 @@ func TestApplyUnstructuredAndTrackAvailability(t *testing.T) {
"test create succeeds for large manifest when object does not exist": {
reconciler: ApplyWorkReconciler{
spokeDynamicClient: dynamicClientLargeObjNotFound,
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
},
workObj: largeObj,
Expand All @@ -1766,7 +1749,7 @@ func TestApplyUnstructuredAndTrackAvailability(t *testing.T) {
"test apply succeeds on update for large manifest when object exists": {
reconciler: ApplyWorkReconciler{
spokeDynamicClient: dynamicClientLargeObjFound,
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
client: &test.MockClient{
MockGet: func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
Expand All @@ -1791,7 +1774,7 @@ func TestApplyUnstructuredAndTrackAvailability(t *testing.T) {
"test create fails for large manifest when object does not exist": {
reconciler: ApplyWorkReconciler{
spokeDynamicClient: dynamicClientLargeObjCreateFail,
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
},
workObj: largeObj,
Expand All @@ -1801,7 +1784,7 @@ func TestApplyUnstructuredAndTrackAvailability(t *testing.T) {
"test apply fails for large manifest when object exists": {
reconciler: ApplyWorkReconciler{
spokeDynamicClient: dynamicClientLargeObjApplyFail,
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
client: &test.MockClient{
MockGet: func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
Expand Down Expand Up @@ -1899,7 +1882,7 @@ func TestApplyManifest(t *testing.T) {
client: &test.MockClient{},
spokeDynamicClient: fakeDynamicClient,
spokeClient: &test.MockClient{},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
joined: atomic.NewBool(true),
},
Expand All @@ -1914,7 +1897,7 @@ func TestApplyManifest(t *testing.T) {
client: &test.MockClient{},
spokeDynamicClient: fakeDynamicClient,
spokeClient: &test.MockClient{},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
joined: atomic.NewBool(true),
},
Expand All @@ -1932,7 +1915,7 @@ func TestApplyManifest(t *testing.T) {
client: &test.MockClient{},
spokeDynamicClient: fakeDynamicClient,
spokeClient: &test.MockClient{},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
joined: atomic.NewBool(true),
},
Expand All @@ -1947,7 +1930,7 @@ func TestApplyManifest(t *testing.T) {
client: &test.MockClient{},
spokeDynamicClient: clientFailDynamicClient,
spokeClient: &test.MockClient{},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
joined: atomic.NewBool(true),
},
Expand Down Expand Up @@ -2095,7 +2078,7 @@ func TestReconcile(t *testing.T) {
client: &test.MockClient{},
spokeDynamicClient: happyDynamicClient,
spokeClient: &test.MockClient{},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
joined: atomic.NewBool(false),
},
Expand All @@ -2112,7 +2095,7 @@ func TestReconcile(t *testing.T) {
},
spokeDynamicClient: fakeDynamicClient,
spokeClient: &test.MockClient{},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
joined: atomic.NewBool(true),
},
Expand All @@ -2126,7 +2109,7 @@ func TestReconcile(t *testing.T) {
},
spokeDynamicClient: fakeDynamicClient,
spokeClient: &test.MockClient{},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
joined: atomic.NewBool(true),
},
Expand Down Expand Up @@ -2162,7 +2145,7 @@ func TestReconcile(t *testing.T) {
return nil
},
},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
joined: atomic.NewBool(true),
},
Expand All @@ -2187,7 +2170,7 @@ func TestReconcile(t *testing.T) {
},
spokeDynamicClient: fakeDynamicClient,
spokeClient: &test.MockClient{},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
joined: atomic.NewBool(true),
},
Expand Down Expand Up @@ -2218,7 +2201,7 @@ func TestReconcile(t *testing.T) {
return nil
},
},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
joined: atomic.NewBool(true),
},
Expand All @@ -2240,7 +2223,7 @@ func TestReconcile(t *testing.T) {
return nil
},
},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(2),
joined: atomic.NewBool(true),
},
Expand All @@ -2259,7 +2242,7 @@ func TestReconcile(t *testing.T) {
spokeClient: &test.MockClient{
MockGet: getMockAppliedWork,
},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(2),
joined: atomic.NewBool(true),
},
Expand All @@ -2281,7 +2264,7 @@ func TestReconcile(t *testing.T) {
return nil
},
},
restMapper: testMapper{},
restMapper: utils.TestMapper{},
recorder: utils.NewFakeRecorder(1),
joined: atomic.NewBool(true),
},
Expand Down
Loading

0 comments on commit dc3b75a

Please sign in to comment.