-
Notifications
You must be signed in to change notification settings - Fork 25
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
Ver 97254 shutdown webhook #979
base: main
Are you sure you want to change the base?
Conversation
api/v1/verticadb_webhook.go
Outdated
statusSclusterIndexMap := v.GenStatusSClusterIndexMap() | ||
oldSclusterMap := oldObj.GenSubclusterMap() | ||
newSclusterIndexMap := v.GenSubclusterIndexMap() | ||
for subclusterName, sandboxName := range newSclusterSboxMap { |
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.
This loop will only check subclusters in the sandbox. What if the subclusters not in a sandbox?
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.
Withdraw my previous comment. I thought you were talking about the other function. You are right. I will make change to adopt that scenario.
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.
Isn't this function for this rule: you cannot scale (up/down) a subcluster with shutdown true(spec or status)?
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.
This will not include subclusters in the main cluster. You should iterate over new.spec.subclusters
, for each subcluster , check if size has changed, if true, check if shutdown(spec/status) is true, if true append an error, then check if it is part of a sandbox, if true check sandbox.Shutdown, if true, append an 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.
Rectification, given that there is already a rule that prevents scaling a subcluster that is part of a sandbox, you do not need to check the sandbox.
api/v1/verticadb_webhook.go
Outdated
newSandboxMap := v.GenSandboxMap() | ||
statusSclusterIndexMap := v.GenStatusSClusterIndexMap() | ||
sandboxWithError := map[string]bool{} | ||
for subclusterName, sandboxName := range newSclusterSboxMap { |
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.
Minor: rename subclusterName to newSC, sandboxName to newSB for bettern readability.
api/v1/verticadb_webhook.go
Outdated
// or an existing subcluster (found in status), the latter of which includes two scenarios: | ||
// 1 the subcluster was in a sandbox (whose name is different from current sandbox name) | ||
// 2 the subcluster was not in a sandbox previously | ||
if !isInOldSandbox || isInOldSandbox && oldSandboxName != sandboxName { |
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.
Use parenthesis to separate the conditions for readability.
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.
The case isInOldSandbox && oldSandboxName != sandboxName
is for unsandboxing. I remember this is checked in another rule. Will we get two errors for this case from two different rules?
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.
Good memory! Here is the related rule from my previous PR:
You cannot unsandbox a subcluster with shutdown
true(spec and/or status) or part of a sandbox with shutdown
true
There will be two error messages:
When a subcluster is moved from one sandbox to another,
- this related rule will raise an error for unsandboxing scenario.
- The rule implmented in this PR will raise another error messages for sandboxing scenario.
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.
Removed this check "isInOldSandbox && oldSandboxName != sandboxName" per offline discussion to avoid duplicate error messages.
api/v1/verticadb_webhook.go
Outdated
statusSclusterIndexMap := v.GenStatusSClusterIndexMap() | ||
oldSclusterMap := oldObj.GenSubclusterMap() | ||
newSclusterIndexMap := v.GenSubclusterIndexMap() | ||
for subclusterName, sandboxName := range newSclusterSboxMap { |
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.
Isn't this function for this rule: you cannot scale (up/down) a subcluster with shutdown true(spec or status)?
api/v1/verticadb_webhook.go
Outdated
oldSandboxName, isInOldSandbox := statusScluterSboxMap[subclusterName] | ||
_, foundSubcluster := newSclusterMap[subclusterName] | ||
for newSC, newSB := range newSclusterSboxMap { | ||
_, foundSubcluster := newSclusterMap[newSC] | ||
if !foundSubcluster { | ||
continue // avoid panic. this error should have been reported by other functions | ||
} | ||
// the subcluster to be sandboxed is either a new subcluster to be added (not found in status) | ||
// or an existing subcluster (found in status), the latter of which includes two scenarios: | ||
// 1 the subcluster was in a sandbox (whose name is different from current sandbox name) |
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.
Remove this line and modify the comment accordingly.
api/v1/verticadb_webhook.go
Outdated
if !foundSubcluster { | ||
continue // avoid panic. this error should have been reported by other functions | ||
} | ||
// the subcluster to be sandboxed is either a new subcluster to be added (not found in status) | ||
// or an existing subcluster (found in status), the latter of which includes two scenarios: | ||
// 1 the subcluster was in a sandbox (whose name is different from current sandbox name) | ||
// 2 the subcluster was not in a sandbox previously | ||
if !isInOldSandbox || isInOldSandbox && oldSandboxName != sandboxName { |
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.
We still need the condition if !isInOldSandbox
to cover the case 2: the subcluster was not in a sandbox previously
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.
After testing, I have to put back the condition "isInOldSandbox && oldSandboxName != sandboxName".
This is what I found:
When a subcluster is moved from sandbox A to sandbox B and A is shut down, , the previous rule kicks in.
When A is not shut down but B is shut down, the new rule applies.
Only when both A and B are shut down, there will be two different error messages: one from unsandboxing and one from sandboxing.
api/v1/verticadb_webhook.go
Outdated
subclustersToBeRemoved := vutil.MapKeyDiff(oldSubclusterMap, newSubclusterMap) | ||
for _, subclusterToBeRemoved := range subclustersToBeRemoved { | ||
subclusterstatus, foundInStatus := statusSubclusterMap[subclusterToBeRemoved] | ||
if oldSubclusterMap[subclusterToBeRemoved].Shutdown || foundInStatus && subclusterstatus.Shutdown { |
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.
minor
if oldSubclusterMap[subclusterToBeRemoved].Shutdown || foundInStatus && subclusterstatus.Shutdown { | |
if oldSubclusterMap[subclusterToBeRemoved].Shutdown || (foundInStatus && subclusterstatus.Shutdown) { |
api/v1/verticadb_webhook.go
Outdated
for _, subclusterToBeRemoved := range subclustersToBeRemoved { | ||
subclusterstatus, foundInStatus := statusSubclusterMap[subclusterToBeRemoved] | ||
if oldSubclusterMap[subclusterToBeRemoved].Shutdown || foundInStatus && subclusterstatus.Shutdown { | ||
p := field.NewPath("spec").Child("subclusters") |
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.
Set this outside of the loop.
subclusterstatus, foundInStatus := statusSubclusterMap[subclusterToBeRemoved] | ||
if oldSubclusterMap[subclusterToBeRemoved].Shutdown || foundInStatus && subclusterstatus.Shutdown { | ||
p := field.NewPath("spec").Child("subclusters") | ||
err := field.Invalid(p, |
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.
err := field.Invalid(p, | |
err := field.Invalid(p.Index(...), |
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.
The subcluster is already removed. We cannot further drill down and give the index.
api/v1/verticadb_webhook.go
Outdated
statusSclusterIndexMap := v.GenStatusSClusterIndexMap() | ||
oldSclusterMap := oldObj.GenSubclusterMap() | ||
newSclusterIndexMap := v.GenSubclusterIndexMap() | ||
for subclusterName, sandboxName := range newSclusterSboxMap { |
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.
This will not include subclusters in the main cluster. You should iterate over new.spec.subclusters
, for each subcluster , check if size has changed, if true, check if shutdown(spec/status) is true, if true append an error, then check if it is part of a sandbox, if true check sandbox.Shutdown, if true, append an error
Here are the rules implemented in this PR: