Skip to content

Commit 01e64cb

Browse files
Fix panic when use generators
Function InitGenerators depends on s.environment.IstioConfigStore initialized in function initControllers.initConfigController, IstioConfigStore is initialized after Function InitGenerator。 Move from the previously initialized position to the current position, and no function using Generators is found in the middle
1 parent 0be1075 commit 01e64cb

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

pilot/pkg/bootstrap/server.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"errors"
2323
"fmt"
2424
"io/ioutil"
25-
"istio.io/istio/pilot/pkg/networking/apigen"
2625
"net"
2726
"net/http"
2827
"os"
@@ -266,7 +265,7 @@ func NewServer(args *PilotArgs, initFuncs ...func(*Server)) (*Server, error) {
266265
return nil, err
267266
}
268267

269-
s.XDSServer.Generators["api"] = apigen.NewGenerator(e.IstioConfigStore)
268+
s.XDSServer.InitGenerators(e, args.Namespace)
270269

271270
// Initialize workloadTrustBundle after CA has been initialized
272271
if err := s.initWorkloadTrustBundle(args); err != nil {

pilot/pkg/xds/discovery.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ func NewDiscoveryServer(env *model.Environment, plugins []string, instanceID str
196196

197197
out.initJwksResolver()
198198

199-
out.initGenerators(env, systemNameSpace)
200-
201199
if features.EnableXDSCaching {
202200
out.Cache = model.NewXdsCache()
203201
}
@@ -536,8 +534,8 @@ func (s *DiscoveryServer) sendPushes(stopCh <-chan struct{}) {
536534
doSendPushes(stopCh, s.concurrentPushLimit, s.pushQueue)
537535
}
538536

539-
// initGenerators initializes generators to be used by XdsServer.
540-
func (s *DiscoveryServer) initGenerators(env *model.Environment, systemNameSpace string) {
537+
// InitGenerators initializes generators to be used by XdsServer.
538+
func (s *DiscoveryServer) InitGenerators(env *model.Environment, systemNameSpace string) {
541539
edsGen := &EdsGenerator{Server: s}
542540
s.StatusGen = NewStatusGen(s)
543541
s.Generators[v3.ClusterType] = &CdsGenerator{Server: s}

pilot/pkg/xds/fake.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func NewFakeDiscoveryServer(t test.Failer, opts FakeOptions) *FakeDiscoveryServe
115115
// Init with a dummy environment, since we have a circular dependency with the env creation.
116116
s := NewDiscoveryServer(&model.Environment{PushContext: model.NewPushContext()}, []string{plugin.AuthzCustom, plugin.Authn, plugin.Authz},
117117
"pilot-123", "istio-system")
118+
s.InitGenerators(&model.Environment{PushContext: model.NewPushContext()}, "istio-system")
118119
t.Cleanup(func() {
119120
s.JwtKeyResolver.Close()
120121
s.pushQueue.ShutDown()

pilot/pkg/xds/simple.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func NewXDS(stop chan struct{}) *SimpleServer {
8080
env.Init()
8181

8282
ds := NewDiscoveryServer(env, nil, "istiod", "istio-system")
83+
ds.InitGenerators(env, "istio-system")
8384
ds.CachesSynced()
8485

8586
// Config will have a fixed format:

0 commit comments

Comments
 (0)