-
Notifications
You must be signed in to change notification settings - Fork 0
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
Issue-654, Prohibiting cluster spec updating until they are running #672
Conversation
…y to be updated was added
// ensuring if the cluster is ready for the spec updating | ||
if (c.Status.CurrentClusterOperationStatus != models.NoOperation || c.Status.State != models.RunningStatus) && c.Generation != oldCluster.Generation { |
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.
Code should be self documented, I don't think that we need such comments
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.
I discussed it with teammates and we decided to keep it as it is because it enhances the readability of the following check
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.
Strange to write comment for check if no operation or not running status, but ok
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 comment refers to spec update only, no the general k8s resource update
// ensuring if the cluster is ready for the spec updating | ||
if (c.Status.CurrentClusterOperationStatus != models.NoOperation || c.Status.State != models.RunningStatus) && c.Generation != oldCluster.Generation { | ||
return models.ErrClusterIsNotReadyToUpdate | ||
} | ||
|
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.
Do we really need this check? c.Generation != oldCluster.Generation
We already have it in SetupWithManager
and there will be no update in false case.
And check all such cases where you use this check
if event.ObjectNew.GetGeneration() == event.ObjectOld.GetGeneration() { return false }
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 following logic prohibits updating the resource spec field. Validating webhooks trigger to update requests only on Patch
and Update
operation. However, we need to prevent any updations of the spec
, so we have to understand what triggered an update. If it changes the spec
it also changes the metadata.generation
field. If we don't ensure that this is a spec
update then it will denies any Update
requests, but controllers of the following resources also update resources by adding/deleting annotations/finalizers by using client.Update
and client.Patch
.
In summary, It helps to understand if it was an update of the resource spec
field or any other update, but we have to prohibit only updates of the spec
.
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.
Validating webhook can validate the request and potentially reject it based on our business logic.
During this phase, the Generation field of the resource has not yet been incremented because the update has not been persisted. So, why should we check this?
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.
For the incoming new object it is already changed, because this is a part of it and it is changes only by k8s
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.
Ok
// ensuring if the cluster is ready for the spec updating | ||
if (c.Status.CurrentClusterOperationStatus != models.NoOperation || c.Status.State != models.RunningStatus) && c.Generation != oldCluster.Generation { | ||
return models.ErrClusterIsNotReadyToUpdate | ||
} | ||
|
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.
Validating webhook can validate the request and potentially reject it based on our business logic.
During this phase, the Generation field of the resource has not yet been incremented because the update has not been persisted. So, why should we check this?
// ensuring if the cluster is ready for the spec updating | ||
if (c.Status.CurrentClusterOperationStatus != models.NoOperation || c.Status.State != models.RunningStatus) && c.Generation != oldCluster.Generation { | ||
return models.ErrClusterIsNotReadyToUpdate | ||
} | ||
|
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.
Ok
The PR adds validation to the update webhooks to prevent cluster spec updating until their state is
running
or there is no cluster operation.Also, it cleans up the codebase and adds some minor fixes.
closes #654