-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Description
When using the service-provider-crossplane, we call code from this repository's Juggler package.
Currently, we have the issue that the word control-plane-operator
will be still attached as label to FluxComponents
such as HelmRepository
and HelmRelease
resources, see
Expected behaviour
It is expected that the label app.kubernetes.io/managed-by=service-provider-crossplane
would be applied.
Root cause analysis
This issue originates from this line of code...
control-plane-operator/pkg/juggler/fluxcd/flux_reconciler.go
Lines 218 to 219 in e0442e0
utils.SetManagedBy(obj) | |
utils.SetLabel(obj, r.labelComponentName, fluxComponent.GetName()) |
... where the Juggler statically calls these constants as part of the func SetManagedBy(obj v1.Object)
:
control-plane-operator/pkg/utils/meta.go
Lines 8 to 25 in e0442e0
const ( | |
labelManagedBy = "app.kubernetes.io/managed-by" | |
labelManagedByValue = "control-plane-operator" | |
LabelComponentName = "controlplane.core.orchestrate.cloud.sap/component" | |
) | |
func SetLabel(obj v1.Object, label string, value string) { | |
labels := obj.GetLabels() | |
if labels == nil { | |
labels = map[string]string{} | |
} | |
labels[label] = value | |
obj.SetLabels(labels) | |
} | |
func SetManagedBy(obj v1.Object) { | |
SetLabel(obj, labelManagedBy, labelManagedByValue) | |
} |
With #101, there was already the attempt to refactor this code to make it more configurable, but not all occurrences of labels where covered with e5abe40.
Solution proposal
Let's pass down a func ...(...) error
that will be executed during the CreateOrUpdate, so that you can make the applied labels configureable.
control-plane-operator/pkg/juggler/fluxcd/flux_reconciler.go
Lines 213 to 221 in e0442e0
result, errCU := controllerutil.CreateOrUpdate(ctx, r.localClient, obj, func() error { | |
if err := actual.Reconcile(desired); err != nil { | |
return err | |
} | |
utils.SetManagedBy(obj) | |
utils.SetLabel(obj, r.labelComponentName, fluxComponent.GetName()) | |
return nil | |
}) |
The solution could look like this:
result, errCU := controllerutil.CreateOrUpdate(ctx, r.localClient, obj, func() error {
if err := actual.Reconcile(desired); err != nil {
return err
}
// call function that applies labels and returns error
// error handling
return nil
})