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 poddecoration concurrent map writes #309

Merged
merged 1 commit into from
Dec 2, 2024
Merged
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
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
Loading