Skip to content

Commit 604dcdd

Browse files
committed
added label propagation
Signed-off-by: Arsh Sharma <[email protected]>
1 parent 26ba569 commit 604dcdd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pkg/controller/instance/controller_reconcile.go

+29
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package instance
1616
import (
1717
"context"
1818
"fmt"
19+
"strings"
1920

2021
"github.com/go-logr/logr"
2122
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -225,6 +226,7 @@ func (igr *instanceGraphReconciler) handleResourceCreation(
225226
if found {
226227
if val, ok := annotations["kro.run/propagate-labels"]; ok && val == "true" {
227228
igr.log.V(1).Info("Found propage labels annotation")
229+
igr.propagateLabelsToResource(resource)
228230
}
229231
}
230232

@@ -240,6 +242,33 @@ func (igr *instanceGraphReconciler) handleResourceCreation(
240242
return igr.delayedRequeue(fmt.Errorf("awaiting resource creation completion"))
241243
}
242244

245+
func (igr *instanceGraphReconciler) propagateLabelsToResource(resource *unstructured.Unstructured) {
246+
// Get labels from the RGI
247+
rgiLabels, found := igr.runtime.GetInstance().Object["metadata"].(map[string]interface{})["labels"].(map[string]interface{})
248+
249+
if !found {
250+
igr.log.V(1).Info("No user labels found on the RGI for propagation")
251+
return
252+
}
253+
254+
userLabels := filterUserLabels(rgiLabels)
255+
unstructured.SetNestedStringMap(resource.Object, userLabels, "metadata", "labels")
256+
igr.log.V(1).Info("User labels propagated to resource")
257+
}
258+
259+
// filterUserLabels extracts non-"kro.run/" labels
260+
func filterUserLabels(labels map[string]interface{}) map[string]string {
261+
userLabels := make(map[string]string)
262+
for key, value := range labels {
263+
if !strings.HasPrefix(key, "kro.run/") {
264+
if strValue, ok := value.(string); ok {
265+
userLabels[key] = strValue
266+
}
267+
}
268+
}
269+
return userLabels
270+
}
271+
243272
// updateResource handles updates to an existing resource.
244273
// Currently performs basic state management, but could be extended to include
245274
// more sophisticated update logic and diffing.

0 commit comments

Comments
 (0)