Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/ES.Kubernetes.Reflector/Mirroring/Core/ResourceMirror.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,17 @@ private async Task ResourceReflect(NamespacedName sourceNsName, NamespacedName r
foreach (var patchAnnotation in patchAnnotations)
annotations[patchAnnotation.Key] = patchAnnotation.Value;
patchDoc.Replace(e => e.Metadata.Annotations, annotations);


// Merge labels: preserve any existing labels on the reflection but ensure labels from the source
// are present (source labels take precedence).
var labels = reflectionObj.Metadata.Labels is null
? new Dictionary<string, string>()
: new Dictionary<string, string>(reflectionObj.Metadata.Labels);
if (source.Metadata?.Labels is not null)
foreach (var kv in source.Metadata.Labels)
labels[kv.Key] = kv.Value;
patchDoc.Replace(e => e.Metadata.Labels, labels);

await OnResourceConfigurePatch(source, patchDoc);

var patch = JsonConvert.SerializeObject(patchDoc, Formatting.Indented);
Expand Down
15 changes: 14 additions & 1 deletion src/ES.Kubernetes.Reflector/Mirroring/SecretMirror.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ protected override async Task OnResourceApplyPatch(V1Patch patch, NamespacedName
protected override Task OnResourceConfigurePatch(V1Secret source, JsonPatchDocument<V1Secret> patchDoc)
{
patchDoc.Replace(e => e.Data, source.Data);

// Ensure any labels on the source secret are reflected as well
patchDoc.Replace(e => e.Metadata.Labels, source.Metadata?.Labels ?? new Dictionary<string, string>());

return Task.CompletedTask;
}

Expand All @@ -38,7 +42,16 @@ protected override Task<V1Secret> OnResourceClone(V1Secret sourceResource) =>
ApiVersion = sourceResource.ApiVersion,
Kind = sourceResource.Kind,
Type = sourceResource.Type,
Data = sourceResource.Data
Data = sourceResource.Data,

// Preserve labels from the source so tools that rely on labels can discover mirrored secrets
Metadata = new k8s.Models.V1ObjectMeta
{
Labels = sourceResource.Metadata?.Labels is null
? null
: new Dictionary<string, string>(sourceResource.Metadata.Labels)
}

});

protected override async Task OnResourceDelete(NamespacedName resourceId)
Expand Down