Skip to content

Commit 8b72968

Browse files
author
Per Goncalves da Silva
committed
Relax webhook preconditions
Signed-off-by: Per Goncalves da Silva <[email protected]>
1 parent 27b05e7 commit 8b72968

File tree

2 files changed

+18
-41
lines changed

2 files changed

+18
-41
lines changed

internal/operator-controller/rukpak/render/registryv1/validators/validator.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,26 @@ func CheckPackageNameNotEmpty(rv1 *bundle.RegistryV1) []error {
101101
return nil
102102
}
103103

104-
// CheckWebhookSupport checks that if the bundle cluster service version declares webhook definitions
105-
// that it is a singleton operator, i.e. that it only supports AllNamespaces mode. This keeps parity
106-
// with OLMv0 behavior for conversion webhooks,
104+
// CheckConversionWebhookSupport checks that if the bundle cluster service version declares conversion webhook definitions,
105+
// that the bundle also only supports AllNamespaces install mode. This keeps parity with OLMv0 behavior for conversion webhooks,
107106
// https://github.com/operator-framework/operator-lifecycle-manager/blob/dfd0b2bea85038d3c0d65348bc812d297f16b8d2/pkg/controller/install/webhook.go#L193
108-
// Since OLMv1 considers APIs to be cluster-scoped, we initially extend this constraint to validating and mutating webhooks.
109-
// While this might restrict the number of supported bundles, we can tackle the issue of relaxing this constraint in turn
110-
// after getting the webhook support working.
111-
func CheckWebhookSupport(rv1 *bundle.RegistryV1) []error {
112-
if len(rv1.CSV.Spec.WebhookDefinitions) > 0 {
107+
func CheckConversionWebhookSupport(rv1 *bundle.RegistryV1) []error {
108+
hasConversionWebhooks := false
109+
for _, wh := range rv1.CSV.Spec.WebhookDefinitions {
110+
if wh.Type == v1alpha1.ConversionWebhook {
111+
hasConversionWebhooks = true
112+
break
113+
}
114+
}
115+
116+
if hasConversionWebhooks {
113117
supportedInstallModes := sets.Set[v1alpha1.InstallModeType]{}
114118
for _, mode := range rv1.CSV.Spec.InstallModes {
115119
supportedInstallModes.Insert(mode.Type)
116120
}
117121
if len(supportedInstallModes) != 1 || !supportedInstallModes.Has(v1alpha1.InstallModeTypeAllNamespaces) {
118-
return []error{errors.New("bundle contains webhook definitions but supported install modes beyond AllNamespaces")}
122+
sortedModes := slices.Sorted(slices.Values(supportedInstallModes.UnsortedList()))
123+
return []error{fmt.Errorf("bundle contains conversion webhooks and supports install modes %v - conversion webhooks are only supported for bundles that only support AllNamespaces install mode", sortedModes)}
119124
}
120125
}
121126

internal/operator-controller/rukpak/render/registryv1/validators/validator_test.go

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -249,32 +249,6 @@ func Test_CheckWebhookSupport(t *testing.T) {
249249
bundle *bundle.RegistryV1
250250
expectedErrs []error
251251
}{
252-
{
253-
name: "accepts bundles with validating webhook definitions when they only support AllNamespaces install mode",
254-
bundle: &bundle.RegistryV1{
255-
CSV: MakeCSV(
256-
WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces),
257-
WithWebhookDefinitions(
258-
v1alpha1.WebhookDescription{
259-
Type: v1alpha1.ValidatingAdmissionWebhook,
260-
},
261-
),
262-
),
263-
},
264-
},
265-
{
266-
name: "accepts bundles with mutating webhook definitions when they only support AllNamespaces install mode",
267-
bundle: &bundle.RegistryV1{
268-
CSV: MakeCSV(
269-
WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces),
270-
WithWebhookDefinitions(
271-
v1alpha1.WebhookDescription{
272-
Type: v1alpha1.MutatingAdmissionWebhook,
273-
},
274-
),
275-
),
276-
},
277-
},
278252
{
279253
name: "accepts bundles with conversion webhook definitions when they only support AllNamespaces install mode",
280254
bundle: &bundle.RegistryV1{
@@ -289,7 +263,7 @@ func Test_CheckWebhookSupport(t *testing.T) {
289263
},
290264
},
291265
{
292-
name: "rejects bundles with validating webhook definitions when they support more modes than AllNamespaces install mode",
266+
name: "accepts bundles with validating webhook definitions when they support more modes than AllNamespaces install mode",
293267
bundle: &bundle.RegistryV1{
294268
CSV: MakeCSV(
295269
WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeSingleNamespace),
@@ -300,7 +274,6 @@ func Test_CheckWebhookSupport(t *testing.T) {
300274
),
301275
),
302276
},
303-
expectedErrs: []error{errors.New("bundle contains webhook definitions but supported install modes beyond AllNamespaces")},
304277
},
305278
{
306279
name: "accepts bundles with mutating webhook definitions when they support more modes than AllNamespaces install mode",
@@ -314,10 +287,9 @@ func Test_CheckWebhookSupport(t *testing.T) {
314287
),
315288
),
316289
},
317-
expectedErrs: []error{errors.New("bundle contains webhook definitions but supported install modes beyond AllNamespaces")},
318290
},
319291
{
320-
name: "accepts bundles with conversion webhook definitions when they support more modes than AllNamespaces install mode",
292+
name: "rejects bundles with conversion webhook definitions when they support more modes than AllNamespaces install mode",
321293
bundle: &bundle.RegistryV1{
322294
CSV: MakeCSV(
323295
WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeSingleNamespace),
@@ -328,11 +300,11 @@ func Test_CheckWebhookSupport(t *testing.T) {
328300
),
329301
),
330302
},
331-
expectedErrs: []error{errors.New("bundle contains webhook definitions but supported install modes beyond AllNamespaces")},
303+
expectedErrs: []error{errors.New("bundle contains conversion webhooks and supports install modes [AllNamespaces SingleNamespace] - conversion webhooks are only supported for bundles that only support AllNamespaces install mode")},
332304
},
333305
} {
334306
t.Run(tc.name, func(t *testing.T) {
335-
errs := validators.CheckWebhookSupport(tc.bundle)
307+
errs := validators.CheckConversionWebhookSupport(tc.bundle)
336308
require.Equal(t, tc.expectedErrs, errs)
337309
})
338310
}

0 commit comments

Comments
 (0)