Skip to content

Conversation

@estroz
Copy link
Member

@estroz estroz commented Aug 19, 2020

Description of the change:

  • internal/generate: set webhook deployment name by searching for deployments selected by webhook services

Motivation for the change: an element of a CSV's spec.webhookDefinitions's deployment name was being inferred from the webhook config's service reference name, which often does not match the deployment's name. Instead, we can look up what service a webhook is using, then use the service's label selector to look up the deployment via labels on the pods for which the service will proxy.

/cc @varshaprasad96

Checklist

If the pull request includes user-facing changes, extra documentation is required:

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 19, 2020
@varshaprasad96
Copy link
Member

varshaprasad96 commented Aug 24, 2020

We need to not mention the volume mount point of server certs/ ports of web server in csv (though this is optional). However, there one another issue with the naming of certificates because of which #3762 and this are blocked.
Created an issue with controller runtime: kubernetes-sigs/controller-runtime#1135

@estroz estroz changed the title [WIP] generate: correctly set CSV webhookDefinition deployment names generate: correctly set CSV webhookDefinition deployment names Sep 14, 2020
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 14, 2020
@hasbro17
Copy link
Contributor

hasbro17 commented Sep 14, 2020

Does this need a CHANGELOG framgent?

csv.Spec.WebhookDefinitions = webhookDescriptions
}

var defaultAdmissionReviewVersions = []string{"v1beta1"}
Copy link
Contributor

Choose a reason for hiding this comment

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

This goes to v1 webhooks once we bump to controller-tools v0.4.0 right? Or rather plugins v3 I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

This has to do with what version of admission reviews the webhook server serves, which is still v1beta1 on controller-runtime's master.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah okay that's not linked to wehooks v1 then, although I imagine we'll want to bump that to v1 as well soon.

Comment on lines 388 to 397
sel := dep.Spec.Template.GetLabels()
// A null label selector matches no objects.
if sel == nil {
continue
}
// An empty label selector matches all objects.
if len(sel) == 0 {
depName = dep.GetName()
break
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you looking at the deployment's selector which is spec.Selector or the pod labels here?

If it's just the pod labels the var should be renamed to reflect that: sel := dep.Spec.Template.GetLabels() to podLabels := dep.Spec.Template.GetLabels()
Also the comments saying label selector.

Plus what does An empty label selector matches all objects mean here?
The label selector can't be empty. It's a required field. But even if it is, what does that signify here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Originally I was using the dep's selector, but that proved unnecessary (and much more difficult) because the webhook service already has a selector. Therefore the variable name and empty selector check are irrelevant, will change/remove.

Copy link
Member Author

Choose a reason for hiding this comment

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

Additionally the label comparison needs to check if service.Spec.Selector is a subset of dep.Spec.Template.GetLabels(), since the service provides the label constraint here.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes more sense, thanks for clarifying.

@estroz estroz force-pushed the bugfix/set-webhook-deployment-name branch 2 times, most recently from 4965a8f to b44edf5 Compare September 14, 2020 23:49
Copy link
Contributor

@hasbro17 hasbro17 left a comment

Choose a reason for hiding this comment

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

LGTM

if len(description.AdmissionReviewVersions) == 0 {
description.AdmissionReviewVersions = defaultAdmissionReviewVersions
}

Copy link
Member

Choose a reason for hiding this comment

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

Can we have a check here to see if description.SideEffects is null, if so set it to SideEffectClassNone? Because having it null causes installplan to fail.

Copy link
Member Author

Choose a reason for hiding this comment

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

I’ll do this in a follow-up. Ideally I wouldn’t be modifying admission review versions in this PR either since they’re unrelated to the deployment name fix, so I’ll break that out too.

if serviceRef := webhook.ClientConfig.Service; serviceRef != nil {
if serviceRef.Port != nil {
description.ContainerPort = *serviceRef.Port
}
Copy link
Member

@varshaprasad96 varshaprasad96 Sep 15, 2020

Choose a reason for hiding this comment

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

Also, if serviceRef.Port == nil and description.ContainerPort is not set, can we default it to 9443 which is used in case of cert-manager. It is a required field which needs to be defined in WebhookDescription. Since 443 (which olm defaults to) is restricted to root user, I suppose setting it to 9443 is a better option?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do in a follow-up.

if len(description.AdmissionReviewVersions) == 0 {
description.AdmissionReviewVersions = defaultAdmissionReviewVersions
}

Copy link
Member

Choose a reason for hiding this comment

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

The same sideEffects and containerPort as in validating WH needs to be set here too.

// findMatchingDeploymentAndServiceForWebhook matches a Service to a webhook's client config (if it uses a service)
// then matches that Service to a Deployment by comparing label selectors (if the Service uses label selectors).
// The names of both Service and Deployment are returned if found.
func findMatchingDeploymentAndServiceForWebhook(c *collector.Manifests, wcc admissionregv1.WebhookClientConfig) (depName, serviceName string) {
Copy link
Member

@varshaprasad96 varshaprasad96 Sep 15, 2020

Choose a reason for hiding this comment

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

I am not sure if this is in scope of this PR. But currently, if using Webhooks we need not specify volumeMounts and webhook server port in CSV. Could we have a check for that, and accordingly not append ContainerVolumeMounts in Deployment.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this will need discussion before changing. We can’t remove all volume mounts and/or ports since these will probably contain other values set by users; in general the generator should avoid modifying declarative manifests like that, which risks changing what they declare.

Instead we need to properly patch the deployment via kustomize before passing it to the generator. @joelanford had a thought or two on this.

@estroz estroz force-pushed the bugfix/set-webhook-deployment-name branch from b44edf5 to f1b533a Compare September 15, 2020 16:40
@estroz estroz force-pushed the bugfix/set-webhook-deployment-name branch from f1b533a to 71e21aa Compare September 15, 2020 16:54
@estroz estroz merged commit f3a767b into operator-framework:master Sep 17, 2020
@estroz estroz deleted the bugfix/set-webhook-deployment-name branch September 17, 2020 16:43
@joelanford
Copy link
Member

/cherry-pick v1.0.x

@openshift-cherrypick-robot

@joelanford: new pull request created: #3904

In response to this:

/cherry-pick v1.0.x

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants