Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kuma-cp): avoid concurrent access on resource meta (backport of #11997) #12021

Merged
merged 2 commits into from
Nov 13, 2024
Merged
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
8 changes: 0 additions & 8 deletions pkg/kds/util/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ func CloneResourceMeta(m model.ResourceMeta, fs ...CloneResourceMetaOpt) model.R
return meta
}

func kumaResourceMetaToResourceMeta(meta *mesh_proto.KumaResource_Meta) model.ResourceMeta {
return &resourceMeta{
name: meta.Name,
mesh: meta.Mesh,
labels: meta.GetLabels(),
}
}

func (r *resourceMeta) GetName() string {
return r.name
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/kds/util/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"fmt"
"maps"
"strings"

envoy_sd "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
Expand Down Expand Up @@ -56,7 +57,7 @@ func ToEnvoyResources(rlist model.ResourceList) ([]envoy_types.Resource, error)
Meta: &mesh_proto.KumaResource_Meta{
Name: r.GetMeta().GetName(),
Mesh: r.GetMeta().GetMesh(),
Labels: r.GetMeta().GetLabels(),
Labels: maps.Clone(r.GetMeta().GetLabels()),
Version: "",
},
Spec: pbany,
Expand Down Expand Up @@ -136,7 +137,11 @@ func toResources(resourceType model.ResourceType, krs []*mesh_proto.KumaResource
if err = model.FromAny(kr.Spec, obj.GetSpec()); err != nil {
return nil, err
}
obj.SetMeta(kumaResourceMetaToResourceMeta(kr.Meta))
obj.SetMeta(&resourceMeta{
name: kr.GetMeta().GetName(),
mesh: kr.GetMeta().GetMesh(),
labels: maps.Clone(kr.GetMeta().GetLabels()),
})
if err := list.AddItem(obj); err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/plugins/resources/memory/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package memory
import (
"context"
"fmt"
"maps"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -123,7 +124,7 @@ func (c *memoryStore) Create(_ context.Context, r core_model.Resource, fs ...sto
Version: initialVersion(),
CreationTime: opts.CreationTime,
ModificationTime: opts.CreationTime,
Labels: opts.Labels,
Labels: maps.Clone(opts.Labels),
}

// fill the meta
Expand Down Expand Up @@ -180,7 +181,7 @@ func (c *memoryStore) Update(_ context.Context, r core_model.Resource, fs ...sto
meta.Version = meta.Version.Next()
meta.ModificationTime = opts.ModificationTime
if opts.ModifyLabels {
meta.Labels = opts.Labels
meta.Labels = maps.Clone(opts.Labels)
}
r.SetMeta(meta)

Expand Down
5 changes: 3 additions & 2 deletions pkg/plugins/resources/remote/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"io"
"maps"
"net/http"
"strconv"

Expand Down Expand Up @@ -41,7 +42,7 @@ func (s *remoteStore) Create(ctx context.Context, res model.Resource, fs ...stor
Type: string(res.Descriptor().Name),
Name: opts.Name,
Mesh: opts.Mesh,
Labels: opts.Labels,
Labels: maps.Clone(opts.Labels),
}
if err := s.upsert(ctx, res, meta); err != nil {
return err
Expand All @@ -55,7 +56,7 @@ func (s *remoteStore) Update(ctx context.Context, res model.Resource, fs ...stor
Type: string(res.Descriptor().Name),
Name: res.GetMeta().GetName(),
Mesh: res.GetMeta().GetMesh(),
Labels: opts.Labels,
Labels: maps.Clone(opts.Labels),
}
if err := s.upsert(ctx, res, meta); err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions pkg/plugins/secrets/k8s/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func (s *KubernetesStore) Update(ctx context.Context, r core_model.Resource, fs
}

func setLabelsAnnotationsAndMesh(s *kube_core.Secret, mesh string, labels map[string]string) {
labels = maps.Clone(labels)
if labels == nil {
labels = map[string]string{}
}
Expand Down
Loading