Skip to content

Commit

Permalink
fix: mutex on ensureToolsNode to avoid duplicate container name causi…
Browse files Browse the repository at this point in the history
…ng error (#952)
  • Loading branch information
iwilltry42 authored Feb 1, 2022
1 parent 9d00a64 commit 33bcd4d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/client/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,13 @@ func runToolsNode(ctx context.Context, runtime runtimes.Runtime, cluster *k3d.Cl
return node, nil
}

var EnsureToolsNodeMutex sync.Mutex

func EnsureToolsNode(ctx context.Context, runtime runtimes.Runtime, cluster *k3d.Cluster) (*k3d.Node, error) {
// Mutex to prevent simultaneous creation of two tools-nodes, e.g. due to slow network connection cause the image pulling to take too long
// FIXME: could be prevented completely by having a smarter image pre-pulling mechanism
EnsureToolsNodeMutex.Lock()
defer EnsureToolsNodeMutex.Unlock()

var toolsNode *k3d.Node
toolsNode, err := runtime.GetNode(ctx, &k3d.Node{Name: fmt.Sprintf("%s-%s-tools", k3d.DefaultObjectNamePrefix, cluster.Name)})
Expand Down

0 comments on commit 33bcd4d

Please sign in to comment.