Skip to content

Commit

Permalink
added label propagation
Browse files Browse the repository at this point in the history
Signed-off-by: Arsh Sharma <[email protected]>
  • Loading branch information
RinkiyaKeDad committed Jan 29, 2025
1 parent 26ba569 commit 604dcdd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/controller/instance/controller_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package instance
import (
"context"
"fmt"
"strings"

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

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

func (igr *instanceGraphReconciler) propagateLabelsToResource(resource *unstructured.Unstructured) {
// Get labels from the RGI
rgiLabels, found := igr.runtime.GetInstance().Object["metadata"].(map[string]interface{})["labels"].(map[string]interface{})

if !found {
igr.log.V(1).Info("No user labels found on the RGI for propagation")
return
}

userLabels := filterUserLabels(rgiLabels)
unstructured.SetNestedStringMap(resource.Object, userLabels, "metadata", "labels")
igr.log.V(1).Info("User labels propagated to resource")
}

// filterUserLabels extracts non-"kro.run/" labels
func filterUserLabels(labels map[string]interface{}) map[string]string {
userLabels := make(map[string]string)
for key, value := range labels {
if !strings.HasPrefix(key, "kro.run/") {
if strValue, ok := value.(string); ok {
userLabels[key] = strValue
}
}
}
return userLabels
}

// updateResource handles updates to an existing resource.
// Currently performs basic state management, but could be extended to include
// more sophisticated update logic and diffing.
Expand Down

0 comments on commit 604dcdd

Please sign in to comment.