Skip to content

Commit

Permalink
Adding sort to reorder webhookDescription based on webhookType (#5177)
Browse files Browse the repository at this point in the history
* Adding sort to reorder webhookDescription based on webhookType

Signed-off-by: sujil02 <sujil.shah@gmail.com>

* Changing webhook definations order in the test output file

Signed-off-by: sujil02 <sujil.shah@gmail.com>

* Adds change log entry and make generate output

Signed-off-by: sujil02 <sujil.shah@gmail.com>
  • Loading branch information
sujil02 authored Sep 7, 2021
1 parent 0a3ef0b commit 2df56b5
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 62 deletions.
8 changes: 8 additions & 0 deletions changelog/fragments/fix_order_of_generated_webhooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
entries:
- description: >
Preserve the order of `webhookdefinitions` while generating bundles,
by sorting `webhookDescriptions` in CSV generator.
kind: bugfix
breaking: false
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ func applyWebhooks(c *collector.Manifests, csv *operatorsv1alpha1.ClusterService
webhookDescriptions = append(webhookDescriptions, des...)
}
}
// Sorts the WebhookDescriptions based on natural order of webhookDescriptions Type
sort.Slice(webhookDescriptions, func(i, j int) bool {
return webhookDescriptions[i].Type < webhookDescriptions[j].Type
})
csv.Spec.WebhookDefinitions = webhookDescriptions
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,23 @@ spec:
url: https://your.domain
version: 0.0.1
webhookdefinitions:
- admissionReviewVersions: null
containerPort: 443
conversionCRDs:
- memcacheds.cache.example.com
deploymentName: memcached-operator-controller-manager
generateName: cmemcacheds.kb.io
sideEffects: None
targetPort: 9443
type: ConversionWebhook
webhookPath: /convert
- admissionReviewVersions:
- v1
- v1beta1
containerPort: 443
deploymentName: memcached-operator-controller-manager
failurePolicy: Fail
generateName: vmemcached.kb.io
generateName: mmemcached.kb.io
rules:
- apiGroups:
- cache.example.com
Expand All @@ -227,15 +237,15 @@ spec:
- memcacheds
sideEffects: None
targetPort: 9443
type: ValidatingAdmissionWebhook
webhookPath: /validate-cache-example-com-v1alpha1-memcached
type: MutatingAdmissionWebhook
webhookPath: /mutate-cache-example-com-v1alpha1-memcached
- admissionReviewVersions:
- v1
- v1beta1
containerPort: 443
deploymentName: memcached-operator-controller-manager
failurePolicy: Fail
generateName: mmemcached.kb.io
generateName: vmemcached.kb.io
rules:
- apiGroups:
- cache.example.com
Expand All @@ -248,15 +258,5 @@ spec:
- memcacheds
sideEffects: None
targetPort: 9443
type: MutatingAdmissionWebhook
webhookPath: /mutate-cache-example-com-v1alpha1-memcached
- admissionReviewVersions: null
containerPort: 443
conversionCRDs:
- memcacheds.cache.example.com
deploymentName: memcached-operator-controller-manager
generateName: cmemcacheds.kb.io
sideEffects: None
targetPort: 9443
type: ConversionWebhook
webhookPath: /convert
type: ValidatingAdmissionWebhook
webhookPath: /validate-cache-example-com-v1alpha1-memcached
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,23 @@ spec:
type: AllNamespaces
version: 0.0.1
webhookdefinitions:
- admissionReviewVersions:
- v1beta1
containerPort: 443
conversionCRDs:
- memcacheds.cache.example.com
deploymentName: memcached-operator-controller-manager
generateName: cmemcacheds.kb.io
sideEffects: None
targetPort: 9443
type: ConversionWebhook
webhookPath: /convert
- admissionReviewVersions:
- v1beta1
containerPort: 443
deploymentName: memcached-operator-controller-manager
failurePolicy: Fail
generateName: vmemcached.kb.io
generateName: mmemcached.kb.io
rules:
- apiGroups:
- cache.example.com
Expand All @@ -175,14 +186,14 @@ spec:
- memcacheds
sideEffects: None
targetPort: 9443
type: ValidatingAdmissionWebhook
webhookPath: /validate-cache-my-domain-v1alpha1-memcached
type: MutatingAdmissionWebhook
webhookPath: /mutate-cache-my-domain-v1alpha1-memcached
- admissionReviewVersions:
- v1beta1
containerPort: 443
deploymentName: memcached-operator-controller-manager
failurePolicy: Fail
generateName: mmemcached.kb.io
generateName: vmemcached.kb.io
rules:
- apiGroups:
- cache.example.com
Expand All @@ -195,16 +206,5 @@ spec:
- memcacheds
sideEffects: None
targetPort: 9443
type: MutatingAdmissionWebhook
webhookPath: /mutate-cache-my-domain-v1alpha1-memcached
- admissionReviewVersions:
- v1beta1
containerPort: 443
conversionCRDs:
- memcacheds.cache.example.com
deploymentName: memcached-operator-controller-manager
generateName: cmemcacheds.kb.io
sideEffects: None
targetPort: 9443
type: ConversionWebhook
webhookPath: /convert
type: ValidatingAdmissionWebhook
webhookPath: /validate-cache-my-domain-v1alpha1-memcached
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,23 @@ spec:
url: https://your.domain
version: 0.0.1
webhookdefinitions:
- admissionReviewVersions:
- v1beta1
containerPort: 443
conversionCRDs:
- memcacheds.cache.example.com
deploymentName: memcached-operator-controller-manager
generateName: cmemcacheds.kb.io
sideEffects: None
targetPort: 9443
type: ConversionWebhook
webhookPath: /convert
- admissionReviewVersions:
- v1beta1
containerPort: 443
deploymentName: memcached-operator-controller-manager
failurePolicy: Fail
generateName: vmemcached.kb.io
generateName: mmemcached.kb.io
rules:
- apiGroups:
- cache.example.com
Expand All @@ -231,14 +242,14 @@ spec:
- memcacheds
sideEffects: None
targetPort: 9443
type: ValidatingAdmissionWebhook
webhookPath: /validate-cache-my-domain-v1alpha1-memcached
type: MutatingAdmissionWebhook
webhookPath: /mutate-cache-my-domain-v1alpha1-memcached
- admissionReviewVersions:
- v1beta1
containerPort: 443
deploymentName: memcached-operator-controller-manager
failurePolicy: Fail
generateName: mmemcached.kb.io
generateName: vmemcached.kb.io
rules:
- apiGroups:
- cache.example.com
Expand All @@ -251,16 +262,5 @@ spec:
- memcacheds
sideEffects: None
targetPort: 9443
type: MutatingAdmissionWebhook
webhookPath: /mutate-cache-my-domain-v1alpha1-memcached
- admissionReviewVersions:
- v1beta1
containerPort: 443
conversionCRDs:
- memcacheds.cache.example.com
deploymentName: memcached-operator-controller-manager
generateName: cmemcacheds.kb.io
sideEffects: None
targetPort: 9443
type: ConversionWebhook
webhookPath: /convert
type: ValidatingAdmissionWebhook
webhookPath: /validate-cache-my-domain-v1alpha1-memcached
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ spec:
containerPort: 443
deploymentName: memcached-operator-controller-manager
failurePolicy: Fail
generateName: vmemcached.kb.io
generateName: mmemcached.kb.io
rules:
- apiGroups:
- cache.example.com
Expand All @@ -210,14 +210,14 @@ spec:
- memcacheds
sideEffects: None
targetPort: 9443
type: ValidatingAdmissionWebhook
webhookPath: /validate-cache-example-com-v1alpha1-memcached
type: MutatingAdmissionWebhook
webhookPath: /mutate-cache-example-com-v1alpha1-memcached
- admissionReviewVersions:
- v1beta1
containerPort: 443
deploymentName: memcached-operator-controller-manager
failurePolicy: Fail
generateName: mmemcached.kb.io
generateName: vmemcached.kb.io
rules:
- apiGroups:
- cache.example.com
Expand All @@ -230,5 +230,5 @@ spec:
- memcacheds
sideEffects: None
targetPort: 9443
type: MutatingAdmissionWebhook
webhookPath: /mutate-cache-example-com-v1alpha1-memcached
type: ValidatingAdmissionWebhook
webhookPath: /validate-cache-example-com-v1alpha1-memcached
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ spec:
containerPort: 443
deploymentName: memcached-operator-controller-manager
failurePolicy: Fail
generateName: vmemcached.kb.io
generateName: mmemcached.kb.io
rules:
- apiGroups:
- cache.example.com
Expand All @@ -235,15 +235,15 @@ spec:
- memcacheds
sideEffects: None
targetPort: 9443
type: ValidatingAdmissionWebhook
webhookPath: /validate-cache-example-com-v1alpha1-memcached
type: MutatingAdmissionWebhook
webhookPath: /mutate-cache-example-com-v1alpha1-memcached
- admissionReviewVersions:
- v1
- v1beta1
containerPort: 443
deploymentName: memcached-operator-controller-manager
failurePolicy: Fail
generateName: mmemcached.kb.io
generateName: vmemcached.kb.io
rules:
- apiGroups:
- cache.example.com
Expand All @@ -256,5 +256,5 @@ spec:
- memcacheds
sideEffects: None
targetPort: 9443
type: MutatingAdmissionWebhook
webhookPath: /mutate-cache-example-com-v1alpha1-memcached
type: ValidatingAdmissionWebhook
webhookPath: /validate-cache-example-com-v1alpha1-memcached

0 comments on commit 2df56b5

Please sign in to comment.