@@ -16,6 +16,7 @@ package instance
16
16
import (
17
17
"context"
18
18
"fmt"
19
+ "strings"
19
20
20
21
"github.com/go-logr/logr"
21
22
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -225,6 +226,7 @@ func (igr *instanceGraphReconciler) handleResourceCreation(
225
226
if found {
226
227
if val , ok := annotations ["kro.run/propagate-labels" ]; ok && val == "true" {
227
228
igr .log .V (1 ).Info ("Found propage labels annotation" )
229
+ igr .propagateLabelsToResource (resource )
228
230
}
229
231
}
230
232
@@ -240,6 +242,33 @@ func (igr *instanceGraphReconciler) handleResourceCreation(
240
242
return igr .delayedRequeue (fmt .Errorf ("awaiting resource creation completion" ))
241
243
}
242
244
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
+
243
272
// updateResource handles updates to an existing resource.
244
273
// Currently performs basic state management, but could be extended to include
245
274
// more sophisticated update logic and diffing.
0 commit comments