Skip to content

Commit a1a5a58

Browse files
author
Per Goncalves da Silva
committed
Update error messages
Signed-off-by: Per Goncalves da Silva <[email protected]>
1 parent 42f01b5 commit a1a5a58

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,29 @@ func CheckPackageNameNotEmpty(rv1 *bundle.RegistryV1) []error {
105105
// that the bundle also only supports AllNamespaces install mode. This keeps parity with OLMv0 behavior for conversion webhooks,
106106
// https://github.com/operator-framework/operator-lifecycle-manager/blob/dfd0b2bea85038d3c0d65348bc812d297f16b8d2/pkg/controller/install/webhook.go#L193
107107
func CheckConversionWebhookSupport(rv1 *bundle.RegistryV1) []error {
108-
hasConversionWebhooks := false
108+
var conversionWebhookNames []string
109109
for _, wh := range rv1.CSV.Spec.WebhookDefinitions {
110110
if wh.Type == v1alpha1.ConversionWebhook {
111-
hasConversionWebhooks = true
112-
break
111+
conversionWebhookNames = append(conversionWebhookNames, wh.GenerateName)
113112
}
114113
}
115114

116-
if hasConversionWebhooks {
115+
if len(conversionWebhookNames) > 0 {
117116
supportedInstallModes := sets.Set[v1alpha1.InstallModeType]{}
118117
for _, mode := range rv1.CSV.Spec.InstallModes {
119118
if mode.Supported {
120119
supportedInstallModes.Insert(mode.Type)
121120
}
122121
}
122+
slices.Sort(conversionWebhookNames)
123+
123124
if len(supportedInstallModes) != 1 || !supportedInstallModes.Has(v1alpha1.InstallModeTypeAllNamespaces) {
124125
sortedModes := slices.Sorted(slices.Values(supportedInstallModes.UnsortedList()))
125-
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)}
126+
errs := make([]error, len(conversionWebhookNames))
127+
for i, webhookName := range conversionWebhookNames {
128+
errs[i] = fmt.Errorf("bundle contains conversion webhook %q and supports install modes %v - conversion webhooks are only supported for bundles that only support AllNamespaces install mode", webhookName, sortedModes)
129+
}
130+
return errs
126131
}
127132
}
128133

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,24 @@ func Test_CheckWebhookSupport(t *testing.T) {
292292
name: "rejects bundles with conversion webhook definitions when they support more modes than AllNamespaces install mode",
293293
bundle: &bundle.RegistryV1{
294294
CSV: MakeCSV(
295-
WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeSingleNamespace),
295+
WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace, v1alpha1.InstallModeTypeAllNamespaces),
296296
WithWebhookDefinitions(
297297
v1alpha1.WebhookDescription{
298-
Type: v1alpha1.ConversionWebhook,
298+
GenerateName: "webhook-b",
299+
Type: v1alpha1.ConversionWebhook,
300+
},
301+
v1alpha1.WebhookDescription{
302+
GenerateName: "webhook-a",
303+
Type: v1alpha1.ConversionWebhook,
299304
},
300305
),
301306
),
302307
},
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")},
308+
expectedErrs: []error{
309+
// Webhook names and install modes are sorted in alphanumerical order
310+
errors.New("bundle contains conversion webhook \"webhook-a\" and supports install modes [AllNamespaces SingleNamespace] - conversion webhooks are only supported for bundles that only support AllNamespaces install mode"),
311+
errors.New("bundle contains conversion webhook \"webhook-b\" and supports install modes [AllNamespaces SingleNamespace] - conversion webhooks are only supported for bundles that only support AllNamespaces install mode"),
312+
},
304313
},
305314
} {
306315
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)