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

Add webhook phase 1 #2072

Merged
merged 35 commits into from
Oct 30, 2019
Merged

Add webhook phase 1 #2072

merged 35 commits into from
Oct 30, 2019

Conversation

anyasabo
Copy link
Contributor

Partially fixes #1769
Fixes #2068

This is just the first phase for re-adding the webhook validation for kubebuilder v2. In kubebuilder v2, webhooks are implemented with a receiver of the custom resource type. You can see the docs here. This leaves us in more or less the same position we were in before, but in a position to implement the webhook. I wanted to merge this sooner than later as it touches a lot of files. The changes in the future should mostly just be in the webhook handling code.

Unfortunately we had validation code in a few dependent packages, so this required a bit of refactoring to avoid circular dependencies. Including:

  • pkg/controller/elasticsearch/validation
  • pkg/controller/elasticsearch/name
  • pkg/controller/elasticsearch/settings

VerifySupportsExistingPods was also moved to the driver since that was the only caller and it seemed to make more sense there

Upstream validation funcs also returns field.ErrorLists, which are nice because it provides an easy way to point out exactly which part of the path is wrong and what the invalid value is. It meant a little rework in our validation funcs, but it seems easier to read imo.

  • Adds OpenAPI validation to ensure there's at least one node set (previously this was part of specUpdatedToBeta() and that the count of any node set is positive.

Still to do

  • Actually configure the operator to run as a webhook server. In the issue we also expressed desire to have the operator auto configure itself as a webhook, so that will likely be phase 3.

I had two things I was not sure about:

  • Do we want to actually generate the webhook yaml right now? It doesn't do anything right now, but it is necessary for the next phase

  • Do we want to double check that the nodeSet len is positive and that the nodeSet counts are positive in the validation funcs? In general I don't think we need to re-implement OpenAPI, but since we do not have OpenAPI validation right now I can see the argument for it. But hopefully we do by the time we cut a new release

@anyasabo anyasabo marked this pull request as ready for review October 29, 2019 03:04
Copy link
Contributor

@sebgl sebgl left a comment

Choose a reason for hiding this comment

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

LGTM

}

func (r *Elasticsearch) ValidateUpdate(old runtime.Object) error {
eslog.Info("validate update", "name", r.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

should it be debug level?

return errors.New("cannot cast old object to Elasticsearch type")
}
var errs field.ErrorList

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: move the variable declaration one line below?

duplicateNodeSets = "NodeSet names must be unique"
noDowngradesMsg = "Downgrades are not supported"
unsupportedVersionMsg = "Unsupported version"
unsupportedUpgradeMsg = "Unsupported version upgrade path"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use capitalize the first word of them all for consistency?

@anyasabo anyasabo merged commit 38ff3d3 into elastic:master Oct 30, 2019
@anyasabo anyasabo deleted the webhook branch October 30, 2019 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nodeSets.count set to -1 causes the operator to panic Update webhook for kubebuilder v2
2 participants