From 673044281cdce7eea56349a2680673ae35f170aa Mon Sep 17 00:00:00 2001 From: AaronH88 Date: Mon, 22 Apr 2024 10:39:48 +0100 Subject: [PATCH] Add mutex locks for KubeAPIWraper (#1013) --- pkg/workceptor/kubernetes.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/workceptor/kubernetes.go b/pkg/workceptor/kubernetes.go index 1f902eb5b..151910696 100644 --- a/pkg/workceptor/kubernetes.go +++ b/pkg/workceptor/kubernetes.go @@ -170,6 +170,8 @@ func (ku KubeAPIWrapper) NewFakeAlwaysRateLimiter() flowcontrol.RateLimiter { // It is instantiated in the NewkubeWorker function and available throughout the package. var KubeAPIWrapperInstance KubeAPIer +var KubeAPIWrapperLock *sync.RWMutex + // ErrPodCompleted is returned when pod has already completed before we could attach. var ErrPodCompleted = fmt.Errorf("pod ran to completion") @@ -1501,10 +1503,13 @@ func (cfg KubeWorkerCfg) NewkubeWorker(bwu BaseWorkUnitForWorkUnit, w *Workcepto } } + KubeAPIWrapperLock = &sync.RWMutex{} + KubeAPIWrapperLock.Lock() KubeAPIWrapperInstance = KubeAPIWrapper{} if kawi != nil { KubeAPIWrapperInstance = kawi } + KubeAPIWrapperLock.Unlock() ku := &KubeUnit{ BaseWorkUnitForWorkUnit: bwu,