-
Notifications
You must be signed in to change notification settings - Fork 61
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Add support for customizing additional provider deployments #538
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
{{- define "recursivePrinter" }} | ||
{{- range $key, $value := . }} | ||
{{- if kindIs "map" $value }} | ||
{{ $key }}: | ||
{{- include "recursivePrinter" $value | indent 2 }} | ||
{{- else }} | ||
{{ $key }}: {{ $value }} | ||
{{- end }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function allows the chart to print out |
||
{{- end }} | ||
{{- end }} | ||
# Infrastructure providers | ||
{{- if .Values.infrastructure }} | ||
{{- $infrastructures := split ";" .Values.infrastructure }} | ||
|
@@ -40,7 +50,7 @@ metadata: | |
"helm.sh/hook": "post-install" | ||
"helm.sh/hook-weight": "2" | ||
"argocd.argoproj.io/sync-wave": "2" | ||
{{- if or $infrastructureVersion $.Values.configSecret.name $.Values.manager }} | ||
{{- if or $infrastructureVersion $.Values.configSecret.name $.Values.manager $.Values.additionalDeployments }} | ||
spec: | ||
{{- end }} | ||
{{- if $infrastructureVersion }} | ||
|
@@ -66,5 +76,9 @@ spec: | |
namespace: {{ $.Values.configSecret.namespace }} | ||
{{- end }} | ||
{{- end }} | ||
{{- if $.Values.additionalDeployments }} | ||
additionalDeployments: | ||
{{- include "recursivePrinter" $.Values.additionalDeployments | indent 2 }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,25 +73,41 @@ func customizeObjectsFn(provider operatorv1.GenericProvider) func(objs []unstruc | |
})) | ||
} | ||
|
||
//nolint:nestif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if a nolint is allowed here. I'll have to create a few helper functions if not. lmk which approach is better! |
||
if o.GetKind() == deploymentKind { | ||
d := &appsv1.Deployment{} | ||
if err := scheme.Scheme.Convert(&o, d, nil); err != nil { | ||
return nil, err | ||
} | ||
|
||
providerDeployment := provider.GetSpec().Deployment | ||
providerManager := provider.GetSpec().Manager | ||
|
||
// If there are multiple deployments, check if we specify customizations for those deployments. | ||
// 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 | ||
// and the deployment name doesn't follow "ca*-controller-manager" pattern, or the provider | ||
// doesn't specify customizations for the deployment. | ||
// 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 | ||
additionalDeployments := provider.GetSpec().AdditionalDeployments | ||
// Skip the deployment if there are no additional deployments specified. | ||
if additionalDeployments == nil { | ||
results = append(results, o) | ||
continue | ||
} | ||
|
||
additionalProviderCustomization, ok := additionalDeployments[o.GetName()] | ||
if !ok { | ||
results = append(results, o) | ||
continue | ||
} | ||
|
||
providerDeployment = additionalProviderCustomization.Deployment | ||
providerManager = additionalProviderCustomization.Manager | ||
} | ||
|
||
d := &appsv1.Deployment{} | ||
if err := scheme.Scheme.Convert(&o, d, nil); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := customizeDeployment(provider.GetSpec(), d); err != nil { | ||
if err := customizeDeployment(providerDeployment, providerManager, d); err != nil { | ||
return nil, err | ||
} | ||
|
||
|
@@ -108,28 +124,26 @@ func customizeObjectsFn(provider operatorv1.GenericProvider) func(objs []unstruc | |
} | ||
|
||
// customizeDeployment customize provider deployment base on provider spec input. | ||
func customizeDeployment(pSpec operatorv1.ProviderSpec, d *appsv1.Deployment) error { | ||
func customizeDeployment(dSpec *operatorv1.DeploymentSpec, mSpec *operatorv1.ManagerSpec, d *appsv1.Deployment) error { | ||
// Customize deployment spec first. | ||
if pSpec.Deployment != nil { | ||
customizeDeploymentSpec(pSpec, d) | ||
if dSpec != nil { | ||
customizeDeploymentSpec(*dSpec, d) | ||
} | ||
|
||
// Run the customizeManagerContainer after, so it overrides anything in the deploymentSpec. | ||
if pSpec.Manager != nil { | ||
if mSpec != nil { | ||
container := findManagerContainer(&d.Spec) | ||
if container == nil { | ||
return fmt.Errorf("cannot find %q container in deployment %q", managerContainerName, d.Name) | ||
} | ||
|
||
customizeManagerContainer(pSpec.Manager, container) | ||
customizeManagerContainer(mSpec, container) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func customizeDeploymentSpec(pSpec operatorv1.ProviderSpec, d *appsv1.Deployment) { | ||
dSpec := pSpec.Deployment | ||
|
||
func customizeDeploymentSpec(dSpec operatorv1.DeploymentSpec, d *appsv1.Deployment) { | ||
if dSpec.Replicas != nil { | ||
d.Spec.Replicas = ptr.To(int32(*dSpec.Replicas)) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexander-demicev not sure if this is the best way to do it, but I refactored the code to include an
AdditionalDeployments
field that maps the name of the deployment to the Manager and Deployment spec, where the additional deployments can be customized. Is this a good way to go about it?