-
Notifications
You must be signed in to change notification settings - Fork 38
fix: use CRP defaulter to account for nil CRP policy in eviction controller #987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,11 +16,13 @@ import ( | |
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/util/intstr" | ||
| "k8s.io/utils/ptr" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
|
|
||
| placementv1alpha1 "go.goms.io/fleet/apis/placement/v1alpha1" | ||
| placementv1beta1 "go.goms.io/fleet/apis/placement/v1beta1" | ||
| "go.goms.io/fleet/pkg/utils/defaulter" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -31,6 +33,13 @@ const ( | |
| testEvictionName = "test-eviction" | ||
| ) | ||
|
|
||
| var ( | ||
| validationResultCmpOptions = []cmp.Option{ | ||
| cmp.AllowUnexported(evictionValidationResult{}), | ||
| cmpopts.IgnoreFields(metav1.ObjectMeta{}, "ResourceVersion"), | ||
| } | ||
| ) | ||
|
|
||
| func TestValidateEviction(t *testing.T) { | ||
| testCRP := &placementv1beta1.ClusterResourcePlacement{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
|
|
@@ -40,6 +49,18 @@ func TestValidateEviction(t *testing.T) { | |
| Policy: &placementv1beta1.PlacementPolicy{ | ||
| PlacementType: placementv1beta1.PickAllPlacementType, | ||
| }, | ||
| Strategy: placementv1beta1.RolloutStrategy{ | ||
| Type: placementv1beta1.RollingUpdateRolloutStrategyType, | ||
| RollingUpdate: &placementv1beta1.RollingUpdateConfig{ | ||
| MaxUnavailable: ptr.To(intstr.FromString(defaulter.DefaultMaxUnavailableValue)), | ||
| MaxSurge: ptr.To(intstr.FromString(defaulter.DefaultMaxSurgeValue)), | ||
| UnavailablePeriodSeconds: ptr.To(defaulter.DefaultUnavailablePeriodSeconds), | ||
| }, | ||
| ApplyStrategy: &placementv1beta1.ApplyStrategy{ | ||
| Type: placementv1beta1.ApplyStrategyTypeClientSideApply, | ||
| }, | ||
| }, | ||
| RevisionHistoryLimit: ptr.To(int32(defaulter.DefaultRevisionHistoryLimitValue)), | ||
| }, | ||
| } | ||
| testBinding1 := placementv1beta1.ClusterResourceBinding{ | ||
|
|
@@ -153,9 +174,14 @@ func TestValidateEviction(t *testing.T) { | |
| wantErr: nil, | ||
| }, | ||
| { | ||
| name: "valid eviction", | ||
| name: "CRP with empty spec - valid eviction", | ||
| eviction: buildTestEviction(testEvictionName, testCRPName, testClusterName), | ||
| crp: testCRP, | ||
| crp: &placementv1beta1.ClusterResourcePlacement{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "test-crp", | ||
| }, | ||
| Spec: placementv1beta1.ClusterResourcePlacementSpec{}, | ||
| }, | ||
| bindings: []placementv1beta1.ClusterResourceBinding{testBinding2}, | ||
| wantValidationResult: &evictionValidationResult{ | ||
| isValid: true, | ||
|
|
@@ -185,7 +211,7 @@ func TestValidateEviction(t *testing.T) { | |
| Client: fakeClient, | ||
| } | ||
| gotValidationResult, gotErr := r.validateEviction(ctx, tc.eviction) | ||
| if diff := cmp.Diff(tc.wantValidationResult, gotValidationResult, cmp.AllowUnexported(evictionValidationResult{}), cmpopts.IgnoreFields(placementv1beta1.ClusterResourceBinding{}, "ResourceVersion")); diff != "" { | ||
| if diff := cmp.Diff(tc.wantValidationResult, gotValidationResult, validationResultCmpOptions...); diff != "" { | ||
| t.Errorf("validateEviction() validation result mismatch (-want, +got):\n%s", diff) | ||
| } | ||
| gotInvalidCondition := tc.eviction.GetCondition(string(placementv1alpha1.PlacementEvictionConditionTypeValid)) | ||
|
|
@@ -503,16 +529,7 @@ func TestExecuteEviction(t *testing.T) { | |
| name: "PickAll CRP, Misconfigured PDB MaxUnavailable specified - eviction not executed", | ||
| validationResult: &evictionValidationResult{ | ||
| crb: availableBinding, | ||
| crp: &placementv1beta1.ClusterResourcePlacement{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: testCRPName, | ||
| }, | ||
| Spec: placementv1beta1.ClusterResourcePlacementSpec{ | ||
| Policy: &placementv1beta1.PlacementPolicy{ | ||
| PlacementType: placementv1beta1.PickAllPlacementType, | ||
| }, | ||
| }, | ||
| }, | ||
| crp: ptr.To(buildTestPickAllCRP(testCRPName)), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder why sometimes we use this while sometimes we just use testCRP
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. testCRP is only used for validateEviction test where we use defaulter to set default values on the CRP. For all the other tests we can build CRP which doesn't need to have all default values |
||
| }, | ||
| eviction: buildTestEviction(testEvictionName, testCRPName, testClusterName), | ||
| pdb: &placementv1alpha1.ClusterResourcePlacementDisruptionBudget{ | ||
|
|
@@ -539,16 +556,7 @@ func TestExecuteEviction(t *testing.T) { | |
| name: "PickAll CRP, Misconfigured PDB MinAvailable specified as percentage - eviction not executed", | ||
| validationResult: &evictionValidationResult{ | ||
| crb: availableBinding, | ||
| crp: &placementv1beta1.ClusterResourcePlacement{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: testCRPName, | ||
| }, | ||
| Spec: placementv1beta1.ClusterResourcePlacementSpec{ | ||
| Policy: &placementv1beta1.PlacementPolicy{ | ||
| PlacementType: placementv1beta1.PickAllPlacementType, | ||
| }, | ||
| }, | ||
| }, | ||
| crp: ptr.To(buildTestPickAllCRP(testCRPName)), | ||
| }, | ||
| eviction: buildTestEviction(testEvictionName, testCRPName, testClusterName), | ||
| pdb: &placementv1alpha1.ClusterResourcePlacementDisruptionBudget{ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.