Skip to content

Commit

Permalink
Merge pull request #2555 from vincepri/add-flag-ignore-convertible
Browse files Browse the repository at this point in the history
馃尡 envtest: allow to ignore scheme.Convertible check for CRDs
  • Loading branch information
k8s-ci-robot committed Oct 19, 2023
2 parents c033388 + 70141d0 commit 15d7928
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
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

0 comments on commit 15d7928

Please sign in to comment.