-
Notifications
You must be signed in to change notification settings - Fork 201
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
feat(validation): add webhook validations for CVC replica scale #1621
Changes from 1 commit
2cff86a
206dba7
1184cab
c5a22c5
b72733c
b9c0771
c0c51db
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 |
---|---|---|
|
@@ -66,7 +66,6 @@ func validateCVCSpecChanges(cvcOldObj, cvcNewObj *apis.CStorVolumeClaim) error { | |
validateFuncList := []validateFunc{validateReplicaCount, | ||
validatePoolListChanges, | ||
validateReplicaScaling, | ||
validateStatusPoolList, | ||
} | ||
for _, f := range validateFuncList { | ||
err := f(cvcOldObj, cvcNewObj) | ||
|
@@ -106,12 +105,14 @@ func validateReplicaCount(cvcOldObj, cvcNewObj *apis.CStorVolumeClaim) error { | |
// validatePoolListChanges returns error if user modified existing pool names with new | ||
// pool name(s) or if user performed more than one replica scale down at a time | ||
func validatePoolListChanges(cvcOldObj, cvcNewObj *apis.CStorVolumeClaim) error { | ||
oldDesiredPoolNames := cvc.GetDesiredReplicaPoolNames(cvcOldObj) | ||
// Check the new CVC spec changes with old CVC status(Comparing with status | ||
// is more appropriate than comparing with spec) | ||
oldCurrentPoolNames := cvcOldObj.Status.PoolInfo | ||
newDesiredPoolNames := cvc.GetDesiredReplicaPoolNames(cvcNewObj) | ||
modifiedPoolNames := util.ListDiff(oldDesiredPoolNames, newDesiredPoolNames) | ||
if len(newDesiredPoolNames) >= len(oldDesiredPoolNames) { | ||
// If no.of pools on new spec >= no.of pools in old spec(scaleup as well | ||
// as migration then there all the pools in old spec must present in new | ||
modifiedPoolNames := util.ListDiff(oldCurrentPoolNames, newDesiredPoolNames) | ||
if len(newDesiredPoolNames) >= len(oldCurrentPoolNames) { | ||
// If no.of pools on new spec >= no.of pools in old status(scaleup as well | ||
// as migration case then all the pools in old status must present in new | ||
// spec) | ||
if len(modifiedPoolNames) > 0 { | ||
return errors.Errorf( | ||
|
@@ -120,7 +121,7 @@ func validatePoolListChanges(cvcOldObj, cvcNewObj *apis.CStorVolumeClaim) error | |
) | ||
} | ||
} else { | ||
// If no.of pools in new spec < no.of pools in old spec(scale down | ||
// If no.of pools in new spec < no.of pools in old status(scale down | ||
// volume replica case) then there should at most one change in | ||
// oldSpec.PoolInfo - newSpec.PoolInfo | ||
if len(modifiedPoolNames) > 1 { | ||
|
@@ -130,6 +131,23 @@ func validatePoolListChanges(cvcOldObj, cvcNewObj *apis.CStorVolumeClaim) error | |
) | ||
} | ||
} | ||
// Reject the request if someone perform scaling when CVC is not in Bound | ||
// state | ||
// NOTE: We should not reject the controller request which Updates status as | ||
// Bound as well as pool info in status and spec | ||
// TODO: Make below check as cvcOldObj.ISBound() | ||
// If CVC Status is not bound then reject | ||
if cvcOldObj.Status.Phase != apis.CStorVolumeClaimPhaseBound { | ||
// If controller is updating pool info then new CVC will be in bound state | ||
if cvcNewObj.Status.Phase != apis.CStorVolumeClaimPhaseBound && | ||
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. you can remove this check 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. We can't remove this check if we remove then update from CVC controller filling [pool info] |
||
// Performed scaling operation on CVC | ||
len(oldCurrentPoolNames) != len(newDesiredPoolNames) { | ||
return errors.Errorf( | ||
"Can't perform scaling of volume replicas when CVC is not in %s state", | ||
apis.CStorVolumeClaimPhaseBound, | ||
) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
|
@@ -148,30 +166,6 @@ func validateReplicaScaling(cvcOldObj, cvcNewObj *apis.CStorVolumeClaim) error { | |
return nil | ||
} | ||
|
||
// validateStatusPoolList return error if content of pools under status doesn't | ||
// match with desired pool names(spec.poolNames) | ||
// NOTE: This validation is only to reject invalid changes of pool information | ||
// on CVC status. | ||
func validateStatusPoolList(cvcOldObj, cvcNewObj *apis.CStorVolumeClaim) error { | ||
replicaPoolNames := []string{} | ||
if len(cvcOldObj.Spec.Policy.ReplicaPoolInfo) == 0 && | ||
len(cvcOldObj.Status.PoolInfo) == 0 { | ||
// Might be a case where controller updating Bound status along with | ||
// spec and status pool names | ||
replicaPoolNames = cvc.GetDesiredReplicaPoolNames(cvcNewObj) | ||
} else { | ||
replicaPoolNames = cvc.GetDesiredReplicaPoolNames(cvcOldObj) | ||
} | ||
// get pool names which are in status but not under spec | ||
invalidStatusPoolNames := util.ListDiff(cvcNewObj.Status.PoolInfo, replicaPoolNames) | ||
if len(invalidStatusPoolNames) > 0 { | ||
return errors.Errorf("invalid poolInfo %v changes on CVC status", | ||
invalidStatusPoolNames, | ||
) | ||
} | ||
return nil | ||
} | ||
|
||
// validatePoolNames returns error if there is repeatition of pool names either | ||
// under spec or status of cvc | ||
func validatePoolNames(cvcObj *apis.CStorVolumeClaim) error { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this new changes to top of function