Skip to content

Make lables configureable #104

@maximiliantech

Description

@maximiliantech

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
Image

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...

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):

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.

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 
 })

Metadata

Metadata

Assignees

Labels

area/open-mcpAll ManagedControlPlane related issuesgood first issueNew to this repo? This is a good place to start

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions