Skip to content

Commit

Permalink
(fix#5315) fatal error: concurrent map read and map write
Browse files Browse the repository at this point in the history
  • Loading branch information
tdiesler committed Apr 3, 2024
1 parent 105f0ee commit 9a20589
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"os"
"path/filepath"
"sync"

"github.com/sirupsen/logrus"
"k8s.io/client-go/scale"
Expand Down Expand Up @@ -53,6 +54,8 @@ const (
kubeConfigEnvVar = "KUBECONFIG"
)

var newClientMutex sync.Mutex

// Client is an abstraction for a k8s client.
type Client interface {
ctrl.Client
Expand Down Expand Up @@ -125,6 +128,13 @@ func NewClient(fastDiscovery bool) (Client, error) {

// NewClientWithConfig creates a new k8s client that can be used from outside or in the cluster.
func NewClientWithConfig(fastDiscovery bool, cfg *rest.Config) (Client, error) {

// The below call to apis.AddToScheme is not thread safe in the k8s API
// We try to synchronize here across all k8s clients
// https://github.com/apache/camel-k/issues/5315
newClientMutex.Lock()
defer newClientMutex.Unlock()

clientScheme := scheme.Scheme

// Setup Scheme for all resources
Expand Down

0 comments on commit 9a20589

Please sign in to comment.