Skip to content

Commit

Permalink
fix: UpdateWithLabels for Secrets and Configs
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <[email protected]>
  • Loading branch information
michaelbeaumont committed Nov 8, 2024
1 parent 18ea8cd commit b505ea9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pkg/plugins/config/k8s/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (s *KubernetesStore) Update(ctx context.Context, r core_model.Resource, fs
if !ok {
return newInvalidTypeError()
}
opts := core_store.NewUpdateOptions(fs...)
cm := &kube_core.ConfigMap{
TypeMeta: kube_meta.TypeMeta{
Kind: "ConfigMap",
Expand All @@ -103,7 +104,12 @@ func (s *KubernetesStore) Update(ctx context.Context, r core_model.Resource, fs
},
}

labels, annotations := k8s.SplitLabelsAndAnnotations(cm.GetLabels(), cm.GetAnnotations())
updateLabels := cm.GetLabels()
if opts.ModifyLabels {
updateLabels = opts.Labels
}

labels, annotations := k8s.SplitLabelsAndAnnotations(updateLabels, cm.GetAnnotations())
cm.GetObjectMeta().SetLabels(labels)
cm.GetObjectMeta().SetAnnotations(annotations)

Expand Down
6 changes: 5 additions & 1 deletion pkg/plugins/secrets/k8s/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ func (s *KubernetesStore) Update(ctx context.Context, r core_model.Resource, fs
}
secret.Namespace = s.namespace

setLabelsAnnotationsAndMesh(secret, r.GetMeta().GetMesh(), opts.Labels)
updateLabels := r.GetMeta().GetLabels()
if opts.ModifyLabels {
updateLabels = opts.Labels
}
setLabelsAnnotationsAndMesh(secret, r.GetMeta().GetMesh(), updateLabels)

if err := s.writer.Update(ctx, secret); err != nil {
if kube_apierrs.IsConflict(err) {
Expand Down

0 comments on commit b505ea9

Please sign in to comment.