@@ -419,7 +419,8 @@ private async Task ResourceReflect(KubeRef sourceId, KubeRef targetId, TResource
419
419
{
420
420
source = sourceResource ;
421
421
}
422
-
422
+
423
+ var sourceProperties = source . GetReflectionProperties ( ) ;
423
424
424
425
var patchAnnotations = new Dictionary < string , string >
425
426
{
@@ -448,6 +449,17 @@ private async Task ResourceReflect(KubeRef sourceId, KubeRef targetId, TResource
448
449
newResourceAnnotations [ Annotations . Reflection . MetaReflectedAt ] =
449
450
JsonConvert . SerializeObject ( DateTimeOffset . UtcNow ) ;
450
451
452
+ if ( sourceProperties . Labels )
453
+ {
454
+ newResource . Metadata . Labels ??= new Dictionary < string , string > ( ) ;
455
+ var newResourceLabels = newResource . Metadata . Labels ;
456
+ foreach ( var label in source . Metadata . Labels )
457
+ {
458
+ if ( sourceProperties . CanLabelBeReflected ( label . Key ) )
459
+ newResourceLabels [ label . Key ] = label . Value ;
460
+ }
461
+ }
462
+
451
463
try
452
464
{
453
465
await OnResourceCreate ( newResource , targetId . Namespace ) ;
@@ -476,6 +488,19 @@ private async Task ResourceReflect(KubeRef sourceId, KubeRef targetId, TResource
476
488
annotations [ patchAnnotation . Key ] = patchAnnotation . Value ;
477
489
patchDoc . Replace ( e => e . Metadata . Annotations , annotations ) ;
478
490
491
+ if ( sourceProperties . Labels && source . Metadata . Labels != null )
492
+ {
493
+ var labels = new Dictionary < string , string > ( ) ;
494
+ if ( targetResource . Metadata . Labels != null )
495
+ labels = new Dictionary < string , string > ( targetResource . Metadata . Labels ) ;
496
+ foreach ( var label in source . Metadata . Labels )
497
+ {
498
+ if ( sourceProperties . CanLabelBeReflected ( label . Key ) )
499
+ labels [ label . Key ] = label . Value ;
500
+ }
501
+ patchDoc . Replace ( e => e . Metadata . Labels , labels ) ;
502
+ }
503
+
479
504
await OnResourceConfigurePatch ( source , patchDoc ) ;
480
505
481
506
var patch = JsonConvert . SerializeObject ( patchDoc , Formatting . Indented ) ;
0 commit comments