mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-07-04 03:48:58 +00:00
🐛 Fix a data race in pod watching
This commit is contained in:
parent
6e0f2aa10a
commit
1c31f5df01
@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kubeshark/kubeshark/docker"
|
"github.com/kubeshark/kubeshark/docker"
|
||||||
@ -34,11 +35,18 @@ type tapState struct {
|
|||||||
|
|
||||||
var state tapState
|
var state tapState
|
||||||
var connector *connect.Connector
|
var connector *connect.Connector
|
||||||
var hubPodReady bool
|
|
||||||
var frontPodReady bool
|
type Readiness struct {
|
||||||
var proxyDone bool
|
Hub bool
|
||||||
|
Front bool
|
||||||
|
Proxy bool
|
||||||
|
sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
var ready *Readiness
|
||||||
|
|
||||||
func tap() {
|
func tap() {
|
||||||
|
ready = &Readiness{}
|
||||||
state.startTime = time.Now()
|
state.startTime = time.Now()
|
||||||
docker.SetRegistry(config.Config.Tap.Docker.Registry)
|
docker.SetRegistry(config.Config.Tap.Docker.Registry)
|
||||||
docker.SetTag(config.Config.Tap.Docker.Tag)
|
docker.SetTag(config.Config.Tap.Docker.Tag)
|
||||||
@ -178,12 +186,23 @@ func watchHubPod(ctx context.Context, kubernetesProvider *kubernetes.Provider, c
|
|||||||
|
|
||||||
if modifiedPod.Status.Phase == core.PodRunning && !isPodReady {
|
if modifiedPod.Status.Phase == core.PodRunning && !isPodReady {
|
||||||
isPodReady = true
|
isPodReady = true
|
||||||
hubPodReady = true
|
|
||||||
|
ready.Lock()
|
||||||
|
ready.Hub = true
|
||||||
|
ready.Unlock()
|
||||||
postHubStarted(ctx, kubernetesProvider, cancel)
|
postHubStarted(ctx, kubernetesProvider, cancel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ready.Lock()
|
||||||
|
proxyDone := ready.Proxy
|
||||||
|
hubPodReady := ready.Hub
|
||||||
|
frontPodReady := ready.Front
|
||||||
|
ready.Unlock()
|
||||||
|
|
||||||
if !proxyDone && hubPodReady && frontPodReady {
|
if !proxyDone && hubPodReady && frontPodReady {
|
||||||
proxyDone = true
|
ready.Lock()
|
||||||
|
ready.Proxy = true
|
||||||
|
ready.Unlock()
|
||||||
postFrontStarted(ctx, kubernetesProvider, cancel)
|
postFrontStarted(ctx, kubernetesProvider, cancel)
|
||||||
}
|
}
|
||||||
case kubernetes.EventBookmark:
|
case kubernetes.EventBookmark:
|
||||||
@ -258,11 +277,21 @@ func watchFrontPod(ctx context.Context, kubernetesProvider *kubernetes.Provider,
|
|||||||
|
|
||||||
if modifiedPod.Status.Phase == core.PodRunning && !isPodReady {
|
if modifiedPod.Status.Phase == core.PodRunning && !isPodReady {
|
||||||
isPodReady = true
|
isPodReady = true
|
||||||
frontPodReady = true
|
ready.Lock()
|
||||||
|
ready.Front = true
|
||||||
|
ready.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ready.Lock()
|
||||||
|
proxyDone := ready.Proxy
|
||||||
|
hubPodReady := ready.Hub
|
||||||
|
frontPodReady := ready.Front
|
||||||
|
ready.Unlock()
|
||||||
|
|
||||||
if !proxyDone && hubPodReady && frontPodReady {
|
if !proxyDone && hubPodReady && frontPodReady {
|
||||||
proxyDone = true
|
ready.Lock()
|
||||||
|
ready.Proxy = true
|
||||||
|
ready.Unlock()
|
||||||
postFrontStarted(ctx, kubernetesProvider, cancel)
|
postFrontStarted(ctx, kubernetesProvider, cancel)
|
||||||
}
|
}
|
||||||
case kubernetes.EventBookmark:
|
case kubernetes.EventBookmark:
|
||||||
|
Loading…
Reference in New Issue
Block a user