Skip to content

Commit

Permalink
Add lock to avoid concurrent access (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcuisinier authored Jan 23, 2024
1 parent 4960fee commit b81d36c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var (
nodeSlice []string
maxNodeConcurrency int
podResourceLookup map[string]podContainers
lock sync.RWMutex
)

func getEnv(key, fallback string) string {
Expand Down Expand Up @@ -151,7 +152,9 @@ func getContainerRequestLimits(p v1.Pod) {
containers = append(containers, setContainer)
}

lock.Lock()
podResourceLookup[p.Name] = podContainers{containers: containers}
lock.Unlock()
}

func initGetPodsResourceLimits() {
Expand Down Expand Up @@ -297,7 +300,9 @@ func generateLabels(podName string, podNamespace string, nodeName string, usedBy
var labelsList []CollectMetric

if ephemeralStorageContainerLimitsPercentage {
lock.RLock()
podResult, ok := podResourceLookup[podName]
lock.RUnlock()
if ok {
for _, c := range podResult.containers {
labels := prometheus.Labels{"pod_namespace": podNamespace,
Expand Down

0 comments on commit b81d36c

Please sign in to comment.