diff --git a/pkg/cluster/https.go b/pkg/cluster/https.go index 0e9f1000b0..6429b9440b 100644 --- a/pkg/cluster/https.go +++ b/pkg/cluster/https.go @@ -55,7 +55,8 @@ func (c *Cluster) initClusterAndHTTPS(ctx context.Context) error { return err } - l, handler, err = c.initClusterDB(ctx, l, handler) + // Config the cluster database and allow it to add additional request handlers + handler, err = c.initClusterDB(ctx, handler) if err != nil { return err } diff --git a/pkg/cluster/managed.go b/pkg/cluster/managed.go index 9e7682cc8c..ab95dbf20f 100644 --- a/pkg/cluster/managed.go +++ b/pkg/cluster/managed.go @@ -52,9 +52,10 @@ func (c *Cluster) start(ctx context.Context) error { return c.managedDB.Start(ctx, c.clientAccessInfo) } -func (c *Cluster) initClusterDB(ctx context.Context, l net.Listener, handler http.Handler) (net.Listener, http.Handler, error) { +// initClusterDB registers routes for database info with the http request handler +func (c *Cluster) initClusterDB(ctx context.Context, handler http.Handler) (http.Handler, error) { if c.managedDB == nil { - return l, handler, nil + return handler, nil } if !strings.HasPrefix(c.config.Datastore.Endpoint, c.managedDB.EndpointName()+"://") { @@ -63,7 +64,7 @@ func (c *Cluster) initClusterDB(ctx context.Context, l net.Listener, handler htt } } - return c.managedDB.Register(ctx, c.config, l, handler) + return c.managedDB.Register(ctx, c.config, handler) } func (c *Cluster) assignManagedDriver(ctx context.Context) error { diff --git a/pkg/cluster/managed/drivers.go b/pkg/cluster/managed/drivers.go index a099bffc83..febcd5caf9 100644 --- a/pkg/cluster/managed/drivers.go +++ b/pkg/cluster/managed/drivers.go @@ -2,7 +2,6 @@ package managed import ( "context" - "net" "net/http" "github.com/rancher/k3s/pkg/clientaccess" @@ -16,7 +15,7 @@ var ( type Driver interface { IsInitialized(ctx context.Context, config *config.Control) (bool, error) - Register(ctx context.Context, config *config.Control, l net.Listener, handler http.Handler) (net.Listener, http.Handler, error) + Register(ctx context.Context, config *config.Control, handler http.Handler) (http.Handler, error) Reset(ctx context.Context, clientAccessInfo *clientaccess.Info) error Start(ctx context.Context, clientAccessInfo *clientaccess.Info) error Test(ctx context.Context, clientAccessInfo *clientaccess.Info) error diff --git a/pkg/etcd/etcd.go b/pkg/etcd/etcd.go index 6e3500ab1c..066a86e04d 100644 --- a/pkg/etcd/etcd.go +++ b/pkg/etcd/etcd.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io/ioutil" - "net" "net/http" "net/url" "os" @@ -276,20 +275,20 @@ func (e *ETCD) join(ctx context.Context, clientAccessInfo *clientaccess.Info) er }) } -// Register configures a new etcd client and adds db info routes for the http listener. -func (e *ETCD) Register(ctx context.Context, config *config.Control, l net.Listener, handler http.Handler) (net.Listener, http.Handler, error) { +// Register configures a new etcd client and adds db info routes for the http request handler. +func (e *ETCD) Register(ctx context.Context, config *config.Control, handler http.Handler) (http.Handler, error) { e.config = config e.runtime = config.Runtime client, err := getClient(ctx, e.runtime, endpoint) if err != nil { - return nil, nil, err + return nil, err } e.client = client address, err := getAdvertiseAddress(config.AdvertiseIP) if err != nil { - return nil, nil, err + return nil, err } e.address = address @@ -299,10 +298,10 @@ func (e *ETCD) Register(ctx context.Context, config *config.Control, l net.Liste e.config.Datastore.Config.KeyFile = e.runtime.ClientETCDKey if err := e.setName(false); err != nil { - return nil, nil, err + return nil, err } - return l, e.handler(handler), err + return e.handler(handler), err } // setName sets a unique name for this cluster member. The first time this is called,