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

generate: default CSV admissionReviewVersions and sideEffects #3903

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/fragments/csv-whdescs-defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
entries:
- description: >
Default a CSV's `spec.webhookDefinition[].admissionReviewVersions` to "v1beta1".
kind: addition
- description: >
Default a CSV's `spec.webhookDefinition[].sideEffects` to "None".
kind: addition
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ func applyWebhooks(c *collector.Manifests, csv *operatorsv1alpha1.ClusterService
csv.Spec.WebhookDefinitions = webhookDescriptions
}

// The default AdmissionReviewVersions set in a CSV if not set in the source webhook.
var defaultAdmissionReviewVersions = []string{"v1beta1"}

// validatingToWebhookDescription transforms webhook into a WebhookDescription.
func validatingToWebhookDescription(webhook admissionregv1.ValidatingWebhook, depName string) operatorsv1alpha1.WebhookDescription {
description := operatorsv1alpha1.WebhookDescription{
Expand All @@ -303,6 +306,13 @@ func validatingToWebhookDescription(webhook admissionregv1.ValidatingWebhook, de
TimeoutSeconds: webhook.TimeoutSeconds,
AdmissionReviewVersions: webhook.AdmissionReviewVersions,
}
if len(description.AdmissionReviewVersions) == 0 {
description.AdmissionReviewVersions = defaultAdmissionReviewVersions
}
if description.SideEffects == nil {
seNone := admissionregv1.SideEffectClassNone
description.SideEffects = &seNone
}

if serviceRef := webhook.ClientConfig.Service; serviceRef != nil {
if serviceRef.Port != nil {
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 include containerPort too?
The reason being this.

Copy link
Member Author

Choose a reason for hiding this comment

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

We shouldn't actually be defaulting this value, since a ServiceReference already does to 443. If OLM or a validator requires this value be set, that should change instead of the SDK potentially incorrectly defaulting this value. @awgreene @kevinrizza.

Copy link
Member

Choose a reason for hiding this comment

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

ContainerPort is not a required field and OLM defaults to 443 if the value is not set.

Expand Down Expand Up @@ -331,6 +341,13 @@ func mutatingToWebhookDescription(webhook admissionregv1.MutatingWebhook, depNam
AdmissionReviewVersions: webhook.AdmissionReviewVersions,
ReinvocationPolicy: webhook.ReinvocationPolicy,
}
if len(description.AdmissionReviewVersions) == 0 {
description.AdmissionReviewVersions = defaultAdmissionReviewVersions
}
if description.SideEffects == nil {
seNone := admissionregv1.SideEffectClassNone
description.SideEffects = &seNone
}

if serviceRef := webhook.ClientConfig.Service; serviceRef != nil {
if serviceRef.Port != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ spec:
url: https://your.domain
version: 0.0.1
webhookdefinitions:
- admissionReviewVersions: null
- admissionReviewVersions:
- v1beta1
deploymentName: memcached-operator-controller-manager
failurePolicy: Fail
generateName: vmemcached.kb.io
Expand All @@ -198,10 +199,11 @@ spec:
- UPDATE
resources:
- memcacheds
sideEffects: null
sideEffects: None
type: ValidatingAdmissionWebhook
webhookPath: /validate-cache-my-domain-v1alpha1-memcached
- admissionReviewVersions: null
- admissionReviewVersions:
- v1beta1
deploymentName: memcached-operator-controller-manager
failurePolicy: Fail
generateName: mmemcached.kb.io
Expand All @@ -215,6 +217,6 @@ spec:
- UPDATE
resources:
- memcacheds
sideEffects: null
sideEffects: None
type: MutatingAdmissionWebhook
webhookPath: /mutate-cache-my-domain-v1alpha1-memcached