Skip to content

Commit

Permalink
Add configurable CRDPattern field for manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
willie-yao committed May 31, 2024
1 parent fab98f2 commit 909dceb
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 13 deletions.
1 change: 1 addition & 0 deletions api/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions api/v1alpha2/provider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/operator.cluster.x-k8s.io_coreproviders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/operator.cluster.x-k8s.io_ipamproviders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions hack/charts/cluster-api-operator/templates/infra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- if $.Values.manager.crdPattern }}
crdPattern: {{ $.Values.manager.crdPattern }}
{{- end }}
{{- end }}
{{- if $.Values.configSecret.name }}
configSecret:
Expand Down
54 changes: 41 additions & 13 deletions internal/controller/component_customizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,34 @@ 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:
// capz-controller-manager and azureserviceoperator-controller-manager
// 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 {

Check failure on line 104 in internal/controller/component_customizer.go

View workflow job for this annotation

GitHub Actions / lint

if statements should only be cuddled with assignments (wsl)
return nil, err
}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down
35 changes: 35 additions & 0 deletions test/e2e/resources/full-chart-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 909dceb

Please sign in to comment.