Skip to content

Commit

Permalink
fix poddecoration concurrent map writes (#309)
Browse files Browse the repository at this point in the history
fix concurrent map writes
  • Loading branch information
Eikykun authored Dec 2, 2024
1 parent d0d8c66 commit 70ed38b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/controllers/utils/poddecoration/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package poddecoration
import (
"context"
"fmt"
"sync"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -28,6 +29,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

appsv1alpha1 "kusionstack.io/kube-api/apps/v1alpha1"

"kusionstack.io/kuperator/pkg/controllers/utils/poddecoration/anno"
"kusionstack.io/kuperator/pkg/controllers/utils/poddecoration/strategy"
"kusionstack.io/kuperator/pkg/utils"
Expand All @@ -47,6 +49,8 @@ type namespacedPodDecorationManager struct {
latestPodDecorations []*appsv1alpha1.PodDecoration
latestPodDecorationNames sets.String
revisions map[string]*appsv1alpha1.PodDecoration

mu sync.RWMutex
}

func NewPodDecorationGetter(c client.Client, namespace string) (Getter, error) {
Expand Down Expand Up @@ -86,6 +90,8 @@ func (n *namespacedPodDecorationManager) GetOnPod(ctx context.Context, pod *core
}

func (n *namespacedPodDecorationManager) GetByRevisions(ctx context.Context, revisions ...string) (map[string]*appsv1alpha1.PodDecoration, error) {
n.mu.Lock()
defer n.mu.Unlock()
res := map[string]*appsv1alpha1.PodDecoration{}
var err error
for _, rev := range revisions {
Expand Down

0 comments on commit 70ed38b

Please sign in to comment.