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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃尡 envtest: allow to ignore scheme.Convertible check for CRDs #2555

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 13 additions & 11 deletions pkg/envtest/crd.go
Expand Up @@ -371,17 +371,19 @@ func modifyConversionWebhooks(crds []*apiextensionsv1.CustomResourceDefinition,
if crds[i].Spec.PreserveUnknownFields {
continue
}
// Continue if the GroupKind isn't registered as being convertible,
// and remove any existing conversion webhooks if they exist.
// This is to prevent the CRD from being rejected by the apiserver, usually
// manifests that are generated by controller-gen will have a conversion
// webhook set, but we don't want to enable it if the type isn't registered.
if _, ok := convertibles[schema.GroupKind{
Group: crds[i].Spec.Group,
Kind: crds[i].Spec.Names.Kind,
}]; !ok {
crds[i].Spec.Conversion = nil
continue
if !webhookOptions.IgnoreSchemeConvertible {
// Continue if the GroupKind isn't registered as being convertible,
// and remove any existing conversion webhooks if they exist.
// This is to prevent the CRD from being rejected by the apiserver, usually
// manifests that are generated by controller-gen will have a conversion
// webhook set, but we don't want to enable it if the type isn't registered.
if _, ok := convertibles[schema.GroupKind{
Group: crds[i].Spec.Group,
Kind: crds[i].Spec.Names.Kind,
}]; !ok {
crds[i].Spec.Conversion = nil
continue
}
}
if crds[i].Spec.Conversion == nil {
crds[i].Spec.Conversion = &apiextensionsv1.CustomResourceConversion{
Expand Down
10 changes: 8 additions & 2 deletions pkg/envtest/webhook.go
Expand Up @@ -49,6 +49,11 @@ type WebhookInstallOptions struct {
// ValidatingWebhooks is a list of ValidatingWebhookConfigurations to install
ValidatingWebhooks []*admissionv1.ValidatingWebhookConfiguration

// IgnoreSchemeConvertible, will modify any CRD conversion webhook to use the local serving host and port,
// bypassing the need to have the types registered in the Scheme. This is useful for testing CRD conversion webhooks
// with unregistered or unstructured types.
IgnoreSchemeConvertible bool

// IgnoreErrorIfPathMissing will ignore an error if a DirectoryPath does not exist when set to true
IgnoreErrorIfPathMissing bool

Expand Down Expand Up @@ -184,7 +189,8 @@ func defaultWebhookOptions(o *WebhookInstallOptions) {
func WaitForWebhooks(config *rest.Config,
mutatingWebhooks []*admissionv1.MutatingWebhookConfiguration,
validatingWebhooks []*admissionv1.ValidatingWebhookConfiguration,
options WebhookInstallOptions) error {
options WebhookInstallOptions,
) error {
waitingFor := map[schema.GroupVersionKind]*sets.Set[string]{}

for _, hook := range mutatingWebhooks {
Expand Down Expand Up @@ -242,7 +248,7 @@ func (p *webhookPoller) poll(ctx context.Context) (done bool, err error) {
continue
}
for _, name := range names.UnsortedList() {
var obj = &unstructured.Unstructured{}
obj := &unstructured.Unstructured{}
obj.SetGroupVersionKind(gvk)
err := c.Get(context.Background(), client.ObjectKey{
Namespace: "",
Expand Down