diff --git a/api/v1alpha1/zz_generated.conversion.go b/api/v1alpha1/zz_generated.conversion.go index c4b828ad..f7776163 100644 --- a/api/v1alpha1/zz_generated.conversion.go +++ b/api/v1alpha1/zz_generated.conversion.go @@ -891,6 +891,7 @@ func autoConvert_v1alpha2_ManagerSpec_To_v1alpha1_ManagerSpec(in *v1alpha2.Manag out.MaxConcurrentReconciles = in.MaxConcurrentReconciles out.Verbosity = in.Verbosity out.FeatureGates = *(*map[string]bool)(unsafe.Pointer(&in.FeatureGates)) + // WARNING: in.CRDPattern requires manual conversion: does not exist in peer-type return nil } diff --git a/api/v1alpha2/provider_types.go b/api/v1alpha2/provider_types.go index 9cfdcc31..1f43a526 100644 --- a/api/v1alpha2/provider_types.go +++ b/api/v1alpha2/provider_types.go @@ -123,6 +123,11 @@ type ManagerSpec struct { // in as container args to the provider's controller manager. // Controller Manager flag is --feature-gates. FeatureGates map[string]bool `json:"featureGates,omitempty"` + + // CRDPattern is a regular expression that matches the CRDs that the provider + // is expected to manage. + // +optional + CRDPattern string `json:"crdPattern,omitempty"` } // DeploymentSpec defines the properties that can be enabled on the Deployment for the provider. diff --git a/config/crd/bases/operator.cluster.x-k8s.io_addonproviders.yaml b/config/crd/bases/operator.cluster.x-k8s.io_addonproviders.yaml index d96fe7a8..6e976db0 100644 --- a/config/crd/bases/operator.cluster.x-k8s.io_addonproviders.yaml +++ b/config/crd/bases/operator.cluster.x-k8s.io_addonproviders.yaml @@ -1369,6 +1369,11 @@ spec: description: RecoverPanic indicates if panics should be recovered. type: boolean type: object + crdPattern: + description: |- + CRDPattern is a regular expression that matches the CRDs that the provider + is expected to manage. + type: string featureGates: additionalProperties: type: boolean diff --git a/config/crd/bases/operator.cluster.x-k8s.io_bootstrapproviders.yaml b/config/crd/bases/operator.cluster.x-k8s.io_bootstrapproviders.yaml index 84e4a56e..e8eee98a 100644 --- a/config/crd/bases/operator.cluster.x-k8s.io_bootstrapproviders.yaml +++ b/config/crd/bases/operator.cluster.x-k8s.io_bootstrapproviders.yaml @@ -2954,6 +2954,11 @@ spec: description: RecoverPanic indicates if panics should be recovered. type: boolean type: object + crdPattern: + description: |- + CRDPattern is a regular expression that matches the CRDs that the provider + is expected to manage. + type: string featureGates: additionalProperties: type: boolean diff --git a/config/crd/bases/operator.cluster.x-k8s.io_controlplaneproviders.yaml b/config/crd/bases/operator.cluster.x-k8s.io_controlplaneproviders.yaml index 61109668..b03eb577 100644 --- a/config/crd/bases/operator.cluster.x-k8s.io_controlplaneproviders.yaml +++ b/config/crd/bases/operator.cluster.x-k8s.io_controlplaneproviders.yaml @@ -2956,6 +2956,11 @@ spec: description: RecoverPanic indicates if panics should be recovered. type: boolean type: object + crdPattern: + description: |- + CRDPattern is a regular expression that matches the CRDs that the provider + is expected to manage. + type: string featureGates: additionalProperties: type: boolean diff --git a/config/crd/bases/operator.cluster.x-k8s.io_coreproviders.yaml b/config/crd/bases/operator.cluster.x-k8s.io_coreproviders.yaml index c6e7a0fb..2b5a7ba1 100644 --- a/config/crd/bases/operator.cluster.x-k8s.io_coreproviders.yaml +++ b/config/crd/bases/operator.cluster.x-k8s.io_coreproviders.yaml @@ -2954,6 +2954,11 @@ spec: description: RecoverPanic indicates if panics should be recovered. type: boolean type: object + crdPattern: + description: |- + CRDPattern is a regular expression that matches the CRDs that the provider + is expected to manage. + type: string featureGates: additionalProperties: type: boolean diff --git a/config/crd/bases/operator.cluster.x-k8s.io_infrastructureproviders.yaml b/config/crd/bases/operator.cluster.x-k8s.io_infrastructureproviders.yaml index 0e6b5772..f9e99680 100644 --- a/config/crd/bases/operator.cluster.x-k8s.io_infrastructureproviders.yaml +++ b/config/crd/bases/operator.cluster.x-k8s.io_infrastructureproviders.yaml @@ -2956,6 +2956,11 @@ spec: description: RecoverPanic indicates if panics should be recovered. type: boolean type: object + crdPattern: + description: |- + CRDPattern is a regular expression that matches the CRDs that the provider + is expected to manage. + type: string featureGates: additionalProperties: type: boolean diff --git a/config/crd/bases/operator.cluster.x-k8s.io_ipamproviders.yaml b/config/crd/bases/operator.cluster.x-k8s.io_ipamproviders.yaml index aa535916..fc963f0e 100644 --- a/config/crd/bases/operator.cluster.x-k8s.io_ipamproviders.yaml +++ b/config/crd/bases/operator.cluster.x-k8s.io_ipamproviders.yaml @@ -1369,6 +1369,11 @@ spec: description: RecoverPanic indicates if panics should be recovered. type: boolean type: object + crdPattern: + description: |- + CRDPattern is a regular expression that matches the CRDs that the provider + is expected to manage. + type: string featureGates: additionalProperties: type: boolean diff --git a/config/crd/bases/operator.cluster.x-k8s.io_runtimeextensionproviders.yaml b/config/crd/bases/operator.cluster.x-k8s.io_runtimeextensionproviders.yaml index 45d6fc61..22e3a2f7 100644 --- a/config/crd/bases/operator.cluster.x-k8s.io_runtimeextensionproviders.yaml +++ b/config/crd/bases/operator.cluster.x-k8s.io_runtimeextensionproviders.yaml @@ -1371,6 +1371,11 @@ spec: description: RecoverPanic indicates if panics should be recovered. type: boolean type: object + crdPattern: + description: |- + CRDPattern is a regular expression that matches the CRDs that the provider + is expected to manage. + type: string featureGates: additionalProperties: type: boolean diff --git a/hack/charts/cluster-api-operator/templates/infra.yaml b/hack/charts/cluster-api-operator/templates/infra.yaml index 5f813a22..c89896f3 100644 --- a/hack/charts/cluster-api-operator/templates/infra.yaml +++ b/hack/charts/cluster-api-operator/templates/infra.yaml @@ -56,6 +56,9 @@ spec: {{- end }} {{- end }} {{- end }} +{{- if $.Values.manager.crdPattern }} + crdPattern: {{ $.Values.manager.crdPattern }} +{{- end }} {{- end }} {{- if $.Values.configSecret.name }} configSecret: diff --git a/internal/controller/component_customizer.go b/internal/controller/component_customizer.go index c5754396..9dc8c7f0 100644 --- a/internal/controller/component_customizer.go +++ b/internal/controller/component_customizer.go @@ -73,7 +73,13 @@ func customizeObjectsFn(provider operatorv1.GenericProvider) func(objs []unstruc })) } + //nolint:nestif if o.GetKind() == deploymentKind { + d := &appsv1.Deployment{} + if err := scheme.Scheme.Convert(&o, d, nil); err != nil { + return nil, err + } + // We need to skip the deployment customization if there are several deployments available // and the deployment name doesn't follow "ca*-controller-manager" pattern. // Currently it is applicable only for CAPZ manifests, which contain 2 deployments: @@ -81,20 +87,20 @@ func customizeObjectsFn(provider operatorv1.GenericProvider) func(objs []unstruc // This is a temporary fix until CAPI provides a contract to distinguish provider deployments. // TODO: replace this check and just compare labels when CAPI provides the contract for that. if isMultipleDeployments && !isProviderManagerDeploymentName(o.GetName()) { - results = append(results, o) - - continue + // If the deployment is azureserviceoperator-controller-manager, customize the deployment + // to support configurable CRD Pattern. This is to enable installing additional ASO CRDs. + if strings.HasPrefix(o.GetName(), "azureserviceoperator") { + if err := customizeASODeployment(provider.GetSpec(), d); err != nil { + return nil, err + } + } else { + continue + } + } else { + if err := customizeDeployment(provider.GetSpec(), d); err != nil { + return nil, err + } } - - d := &appsv1.Deployment{} - if err := scheme.Scheme.Convert(&o, d, nil); err != nil { - return nil, err - } - - if err := customizeDeployment(provider.GetSpec(), d); err != nil { - return nil, err - } - if err := scheme.Scheme.Convert(d, &o, nil); err != nil { return nil, err } @@ -127,6 +133,21 @@ func customizeDeployment(pSpec operatorv1.ProviderSpec, d *appsv1.Deployment) er return nil } +// customizeASODeployment customize ASO provider deployment base on provider spec input. +func customizeASODeployment(pSpec operatorv1.ProviderSpec, d *appsv1.Deployment) error { + // Run the customizeManagerContainer after, so it overrides anything in the deploymentSpec. + if pSpec.Manager != nil { + container := findManagerContainer(&d.Spec) + if container == nil { + return fmt.Errorf("cannot find %q container in deployment %q", managerContainerName, d.Name) + } + + customizeASOManagerContainer(pSpec.Manager, container) + } + + return nil +} + func customizeDeploymentSpec(pSpec operatorv1.ProviderSpec, d *appsv1.Deployment) { dSpec := pSpec.Deployment @@ -253,6 +274,13 @@ func customizeManagerContainer(mSpec *operatorv1.ManagerSpec, c *corev1.Containe } } +// customizeManagerContainer customize ASO manager container base on provider spec input. +func customizeASOManagerContainer(mSpec *operatorv1.ManagerSpec, c *corev1.Container) { + if mSpec.CRDPattern != "" { + c.Args = setArgs(c.Args, "--crd-pattern", mSpec.CRDPattern) + } +} + // customizeContainer customize provider container base on provider spec input. func customizeContainer(cSpec operatorv1.ContainerSpec, d *appsv1.Deployment) { for j, c := range d.Spec.Template.Spec.Containers { diff --git a/test/e2e/resources/full-chart-install.yaml b/test/e2e/resources/full-chart-install.yaml index 20a59818..223bc50d 100644 --- a/test/e2e/resources/full-chart-install.yaml +++ b/test/e2e/resources/full-chart-install.yaml @@ -1386,6 +1386,11 @@ spec: description: RecoverPanic indicates if panics should be recovered. type: boolean type: object + crdPattern: + description: |- + CRDPattern is a regular expression that matches the CRDs that the provider + is expected to manage. + type: string featureGates: additionalProperties: type: boolean @@ -4589,6 +4594,11 @@ spec: description: RecoverPanic indicates if panics should be recovered. type: boolean type: object + crdPattern: + description: |- + CRDPattern is a regular expression that matches the CRDs that the provider + is expected to manage. + type: string featureGates: additionalProperties: type: boolean @@ -7794,6 +7804,11 @@ spec: description: RecoverPanic indicates if panics should be recovered. type: boolean type: object + crdPattern: + description: |- + CRDPattern is a regular expression that matches the CRDs that the provider + is expected to manage. + type: string featureGates: additionalProperties: type: boolean @@ -10998,6 +11013,11 @@ spec: description: RecoverPanic indicates if panics should be recovered. type: boolean type: object + crdPattern: + description: |- + CRDPattern is a regular expression that matches the CRDs that the provider + is expected to manage. + type: string featureGates: additionalProperties: type: boolean @@ -14203,6 +14223,11 @@ spec: description: RecoverPanic indicates if panics should be recovered. type: boolean type: object + crdPattern: + description: |- + CRDPattern is a regular expression that matches the CRDs that the provider + is expected to manage. + type: string featureGates: additionalProperties: type: boolean @@ -15822,6 +15847,11 @@ spec: description: RecoverPanic indicates if panics should be recovered. type: boolean type: object + crdPattern: + description: |- + CRDPattern is a regular expression that matches the CRDs that the provider + is expected to manage. + type: string featureGates: additionalProperties: type: boolean @@ -17442,6 +17472,11 @@ spec: description: RecoverPanic indicates if panics should be recovered. type: boolean type: object + crdPattern: + description: |- + CRDPattern is a regular expression that matches the CRDs that the provider + is expected to manage. + type: string featureGates: additionalProperties: type: boolean