Skip to content

Commit

Permalink
Drop dependency on the operator from the agent
Browse files Browse the repository at this point in the history
Agent -> pkg/xds -> debug.go -> inject/ -> operator/

Cut the chain at debug.go to not import inject/

Agent binary size 77.9mb -> 76.8mb
  • Loading branch information
howardjohn committed Nov 6, 2020
1 parent 32a5c49 commit 626ffea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 6 additions & 2 deletions pilot/pkg/bootstrap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,17 @@ func (s *Server) initIstiodAdminServer(args *PilotArgs, wh *inject.Webhook) erro
log.Info("initializing Istiod admin server")
}

whc := func() string {
return wh.Config.Template
}

// Debug Server.
s.XDSServer.InitDebug(s.monitoringMux, s.ServiceController(), args.ServerOptions.EnableProfiling, wh)
s.XDSServer.InitDebug(s.monitoringMux, s.ServiceController(), args.ServerOptions.EnableProfiling, whc)

// Debug handlers are currently added on monitoring mux and readiness mux.
// If monitoring addr is empty, the mux is shared and we only add it once on the shared mux .
if !shouldMultiplex {
s.XDSServer.AddDebugHandlers(s.httpMux, args.ServerOptions.EnableProfiling, wh)
s.XDSServer.AddDebugHandlers(s.httpMux, args.ServerOptions.EnableProfiling, whc)
}

// Monitoring Server.
Expand Down
11 changes: 5 additions & 6 deletions pilot/pkg/xds/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
v3 "istio.io/istio/pilot/pkg/xds/v3"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/schema/collection"
"istio.io/istio/pkg/kube/inject"
"istio.io/pkg/log"
)

Expand Down Expand Up @@ -124,7 +123,7 @@ type SyncedVersions struct {
}

// InitDebug initializes the debug handlers and adds a debug in-memory registry.
func (s *DiscoveryServer) InitDebug(mux *http.ServeMux, sctl *aggregate.Controller, enableProfiling bool, webhook *inject.Webhook) {
func (s *DiscoveryServer) InitDebug(mux *http.ServeMux, sctl *aggregate.Controller, enableProfiling bool, fetchWebhook func() string) {
// For debugging and load testing v2 we add an memory registry.
s.MemRegistry = memory.NewServiceDiscovery(nil)
s.MemRegistry.EDSUpdater = s
Expand All @@ -136,10 +135,10 @@ func (s *DiscoveryServer) InitDebug(mux *http.ServeMux, sctl *aggregate.Controll
ServiceDiscovery: s.MemRegistry,
Controller: s.MemRegistry.Controller,
})
s.AddDebugHandlers(mux, enableProfiling, webhook)
s.AddDebugHandlers(mux, enableProfiling, fetchWebhook)
}

func (s *DiscoveryServer) AddDebugHandlers(mux *http.ServeMux, enableProfiling bool, webhook *inject.Webhook) {
func (s *DiscoveryServer) AddDebugHandlers(mux *http.ServeMux, enableProfiling bool, webhook func() string) {
// Debug handlers on HTTP ports are added for backward compatibility.
// They will be exposed on XDS-over-TLS in future releases.
if !features.EnableDebugOnHTTP {
Expand Down Expand Up @@ -611,7 +610,7 @@ func (s *DiscoveryServer) configDump(conn *Connection) (*adminapi.ConfigDump, er

// InjectTemplateHandler dumps the injection template
// Replaces dumping the template at startup.
func (s *DiscoveryServer) InjectTemplateHandler(webhook *inject.Webhook) func(http.ResponseWriter, *http.Request) {
func (s *DiscoveryServer) InjectTemplateHandler(webhook func() string) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, req *http.Request) {
// TODO: we should split the inject template into smaller modules (separate one for dump core, etc),
// and allow pods to select which patches will be selected. When this happen, this should return
Expand All @@ -621,7 +620,7 @@ func (s *DiscoveryServer) InjectTemplateHandler(webhook *inject.Webhook) func(ht
return
}

_, _ = w.Write([]byte(webhook.Config.Template))
_, _ = w.Write([]byte(webhook()))
}
}

Expand Down

0 comments on commit 626ffea

Please sign in to comment.