Skip to content
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

Merged
merged 1 commit into from
Jan 15, 2024

Conversation

worryg0d
Copy link
Collaborator

@worryg0d worryg0d commented Jan 12, 2024

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

@worryg0d worryg0d self-assigned this Jan 12, 2024
@worryg0d worryg0d added the enhancement New feature or request label Jan 12, 2024
@worryg0d worryg0d changed the title Issue-654, Perhibiting cluster updation until they are running Issue-654, Prohibiting cluster updation until they are running Jan 12, 2024
@worryg0d worryg0d changed the title Issue-654, Prohibiting cluster updation until they are running Issue-654, Prohibiting cluster spec updating until they are running Jan 12, 2024
Comment on lines +262 to +263
// 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 {
Copy link
Contributor

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

Copy link
Collaborator Author

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

Copy link
Contributor

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

Copy link
Collaborator Author

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

Comment on lines +198 to +202
// 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
}

Copy link
Contributor

@DoodgeMatvey DoodgeMatvey Jan 12, 2024

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 }

Copy link
Collaborator Author

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.

Copy link
Contributor

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?

Copy link
Collaborator Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Comment on lines +198 to +202
// 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
}

Copy link
Contributor

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?

Comment on lines +198 to +202
// 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
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@worryg0d worryg0d merged commit 2f8008f into main Jan 15, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prohibit update operation until a cluster has NO_OPERATION state
4 participants