Skip to content

Commit

Permalink
fix: concurrent map read and map write caused by reloading in ks-apis…
Browse files Browse the repository at this point in the history
…erver.

Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io>
  • Loading branch information
hongzhouzi committed Jan 12, 2023
1 parent c114d51 commit 5f99c9f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cmd/ks-apiserver/app/options/options.go
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"net/http"
"strings"
"sync"

openpitrixv1 "kubesphere.io/kubesphere/pkg/kapis/openpitrix/v1"
"kubesphere.io/kubesphere/pkg/utils/clusterclient"
Expand Down Expand Up @@ -58,9 +59,8 @@ type ServerRunOptions struct {
ConfigFile string
GenericServerRunOptions *genericoptions.ServerRunOptions
*apiserverconfig.Config

//
DebugMode bool
schemeOnce sync.Once
DebugMode bool

// Enable gops or not.
GOPSEnabled bool
Expand All @@ -70,6 +70,7 @@ func NewServerRunOptions() *ServerRunOptions {
s := &ServerRunOptions{
GenericServerRunOptions: genericoptions.NewServerRunOptions(),
Config: apiserverconfig.New(),
schemeOnce: sync.Once{},
}

return s
Expand Down Expand Up @@ -241,9 +242,11 @@ func (s *ServerRunOptions) NewAPIServer(stopCh <-chan struct{}) (*apiserver.APIS
}

sch := scheme.Scheme
if err := apis.AddToScheme(sch); err != nil {
klog.Fatalf("unable add APIs to scheme: %v", err)
}
s.schemeOnce.Do(func() {
if err := apis.AddToScheme(sch); err != nil {
klog.Fatalf("unable add APIs to scheme: %v", err)
}
})

apiServer.RuntimeCache, err = runtimecache.New(apiServer.KubernetesClient.Config(), runtimecache.Options{Scheme: sch})
if err != nil {
Expand Down

0 comments on commit 5f99c9f

Please sign in to comment.