@@ -409,7 +409,8 @@ private async Task ResourceReflect(KubeRef sourceId, KubeRef targetId, TResource
409
409
{
410
410
source = sourceResource ;
411
411
}
412
-
412
+
413
+ var sourceProperties = source . GetReflectionProperties ( ) ;
413
414
414
415
var patchAnnotations = new Dictionary < string , string >
415
416
{
@@ -438,6 +439,17 @@ private async Task ResourceReflect(KubeRef sourceId, KubeRef targetId, TResource
438
439
newResourceAnnotations [ Annotations . Reflection . MetaReflectedAt ] =
439
440
JsonConvert . SerializeObject ( DateTimeOffset . UtcNow ) ;
440
441
442
+ if ( sourceProperties . Labels )
443
+ {
444
+ newResource . Metadata . Labels ??= new Dictionary < string , string > ( ) ;
445
+ var newResourceLabels = newResource . Metadata . Labels ;
446
+ foreach ( var label in source . Metadata . Labels )
447
+ {
448
+ if ( sourceProperties . CanLabelBeReflected ( label . Key ) )
449
+ newResourceLabels [ label . Key ] = label . Value ;
450
+ }
451
+ }
452
+
441
453
try
442
454
{
443
455
await OnResourceCreate ( newResource , targetId . Namespace ) ;
@@ -466,6 +478,19 @@ private async Task ResourceReflect(KubeRef sourceId, KubeRef targetId, TResource
466
478
annotations [ patchAnnotation . Key ] = patchAnnotation . Value ;
467
479
patchDoc . Replace ( e => e . Metadata . Annotations , annotations ) ;
468
480
481
+ if ( sourceProperties . Labels && source . Metadata . Labels != null )
482
+ {
483
+ var labels = new Dictionary < string , string > ( ) ;
484
+ if ( targetResource . Metadata . Labels != null )
485
+ labels = new Dictionary < string , string > ( targetResource . Metadata . Labels ) ;
486
+ foreach ( var label in source . Metadata . Labels )
487
+ {
488
+ if ( sourceProperties . CanLabelBeReflected ( label . Key ) )
489
+ labels [ label . Key ] = label . Value ;
490
+ }
491
+ patchDoc . Replace ( e => e . Metadata . Labels , labels ) ;
492
+ }
493
+
469
494
await OnResourceConfigurePatch ( source , patchDoc ) ;
470
495
471
496
var patch = JsonConvert . SerializeObject ( patchDoc , Formatting . Indented ) ;
0 commit comments