From b848a20d44f215e710c6c58b1cf2952a2943123d Mon Sep 17 00:00:00 2001 From: Deepak Sharma Date: Thu, 25 Mar 2021 20:17:33 +0530 Subject: [PATCH 1/8] session with round tripper keep alive --- controllers/vspherecluster_controller.go | 9 ++- controllers/vspherevm_controller.go | 10 +++- pkg/services/govmomi/create_test.go | 4 +- pkg/services/govmomi/vcenter/clone_test.go | 6 +- pkg/session/session.go | 64 +++++++++++++++++++--- 5 files changed, 76 insertions(+), 17 deletions(-) diff --git a/controllers/vspherecluster_controller.go b/controllers/vspherecluster_controller.go index d57c11a3b9..5c9d825003 100644 --- a/controllers/vspherecluster_controller.go +++ b/controllers/vspherecluster_controller.go @@ -335,8 +335,13 @@ func cloudProviderConfigurationAvailable(ctx *context.ClusterContext) bool { } func (r clusterReconciler) reconcileVCenterConnectivity(ctx *context.ClusterContext) error { - _, err := session.GetOrCreate(ctx, ctx.VSphereCluster.Spec.Server, - ctx.VSphereCluster.Spec.CloudProviderConfiguration.Workspace.Datacenter, ctx.Username, ctx.Password, ctx.VSphereCluster.Spec.Thumbprint) + _, err := session.GetOrCreate(session.NewGetOrCreateContext(ctx.Context, ctx.Logger), + ctx.VSphereCluster.Spec.Server, + ctx.VSphereCluster.Spec.CloudProviderConfiguration.Workspace.Datacenter, + ctx.Username, + ctx.Password, + ctx.VSphereCluster.Spec.Thumbprint, + session.DefaultFeature()) return err } diff --git a/controllers/vspherevm_controller.go b/controllers/vspherevm_controller.go index 4ac4861067..7397406bd1 100644 --- a/controllers/vspherevm_controller.go +++ b/controllers/vspherevm_controller.go @@ -137,9 +137,13 @@ func (r vmReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, reterr error) } // Get or create an authenticated session to the vSphere endpoint. - authSession, err := session.GetOrCreate(r.Context, - vsphereVM.Spec.Server, vsphereVM.Spec.Datacenter, - r.ControllerManagerContext.Username, r.ControllerManagerContext.Password, vsphereVM.Spec.Thumbprint) + authSession, err := session.GetOrCreate(session.NewGetOrCreateContext(r.Context, r.Logger), + vsphereVM.Spec.Server, + vsphereVM.Spec.Datacenter, + r.ControllerManagerContext.Username, + r.ControllerManagerContext.Password, + vsphereVM.Spec.Thumbprint, + session.DefaultFeature()) if err != nil { return reconcile.Result{}, errors.Wrap(err, "failed to create vSphere session") } diff --git a/pkg/services/govmomi/create_test.go b/pkg/services/govmomi/create_test.go index bdf69b9dd6..eef4bac252 100644 --- a/pkg/services/govmomi/create_test.go +++ b/pkg/services/govmomi/create_test.go @@ -47,9 +47,9 @@ func TestCreate(t *testing.T) { vmContext.VSphereVM.Spec.Server = s.URL.Host authSession, err := session.GetOrCreate( - vmContext, + session.NewGetOrCreateContext(vmContext.Context, vmContext.Logger), vmContext.VSphereVM.Spec.Server, "", - s.URL.User.Username(), pass, "") + s.URL.User.Username(), pass, "", session.DefaultFeature()) if err != nil { t.Fatal(err) } diff --git a/pkg/services/govmomi/vcenter/clone_test.go b/pkg/services/govmomi/vcenter/clone_test.go index d8cca659e4..8ed95fd135 100644 --- a/pkg/services/govmomi/vcenter/clone_test.go +++ b/pkg/services/govmomi/vcenter/clone_test.go @@ -24,6 +24,7 @@ import ( "github.com/vmware/govmomi/object" "github.com/vmware/govmomi/simulator" "github.com/vmware/govmomi/vim25/types" + "k8s.io/klog/v2/klogr" "sigs.k8s.io/cluster-api-provider-vsphere/api/v1alpha3" "sigs.k8s.io/cluster-api-provider-vsphere/pkg/context" "sigs.k8s.io/cluster-api-provider-vsphere/pkg/session" @@ -142,9 +143,10 @@ func initSimulator(t *testing.T) (*simulator.Model, *session.Session, *simulator pass, _ := server.URL.User.Password() authSession, err := session.GetOrCreate( - ctx.TODO(), + session.NewGetOrCreateContext(ctx.TODO(), klogr.New()), server.URL.Host, "", - server.URL.User.Username(), pass, "") + server.URL.User.Username(), pass, "", + session.DefaultFeature()) if err != nil { t.Fatal(err) } diff --git a/pkg/session/session.go b/pkg/session/session.go index 215834d1fb..024f0b7e33 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -20,7 +20,9 @@ import ( "context" "net/url" "sync" + "time" + "github.com/go-logr/logr" "github.com/pkg/errors" "github.com/vmware/govmomi" "github.com/vmware/govmomi/find" @@ -42,18 +44,48 @@ type Session struct { datacenter *object.Datacenter } +type GetOrCreateContext struct { + context context.Context + logger logr.Logger +} + +func NewGetOrCreateContext(ctx context.Context, logger logr.Logger) GetOrCreateContext { + return GetOrCreateContext{ + context: ctx, + logger: logger.WithName("session"), + } +} + + +type Feature struct { + EnableKeepAlive bool + KeepAliveDuration time.Duration +} + +func DefaultFeature() Feature { + return Feature{ + EnableKeepAlive: false, + KeepAliveDuration: 0, + } +} + // GetOrCreate gets a cached session or creates a new one if one does not // already exist. func GetOrCreate( - ctx context.Context, - server, datacenter, username, password string, thumbprint string) (*Session, error) { + ctx GetOrCreateContext, + server, datacenter, username, password string, thumbprint string, feature Feature) (*Session, error) { sessionMU.Lock() defer sessionMU.Unlock() sessionKey := server + username + datacenter if session, ok := sessionCache[sessionKey]; ok { - if ok, _ := session.SessionManager.SessionIsActive(ctx); ok { + // if keepalive is enabled we depend upon roundtripper to reestablish the connection + // and remove the key if it could not + if feature.EnableKeepAlive { + return &session, nil + } + if ok, _ := session.SessionManager.SessionIsActive(ctx.context); ok { return &session, nil } } @@ -67,7 +99,7 @@ func GetOrCreate( } soapURL.User = url.UserPassword(username, password) - client, err := newClient(ctx, soapURL, thumbprint) + client, err := newClient(ctx, sessionKey, soapURL, thumbprint, feature) if err != nil { return nil, err } @@ -79,7 +111,7 @@ func GetOrCreate( session.Finder = find.NewFinder(session.Client.Client, false) // Assign the datacenter if one was specified. - dc, err := session.Finder.DatacenterOrDefault(ctx, datacenter) + dc, err := session.Finder.DatacenterOrDefault(ctx.context, datacenter) if err != nil { return nil, errors.Wrapf(err, "unable to find datacenter %q", datacenter) } @@ -95,22 +127,38 @@ func GetOrCreate( return &session, nil } -func newClient(ctx context.Context, url *url.URL, thumprint string) (*govmomi.Client, error) { +func newClient(ctx GetOrCreateContext, sessionKey string, url *url.URL, thumprint string, feature Feature) (*govmomi.Client, error) { insecure := thumprint == "" soapClient := soap.NewClient(url, insecure) if !insecure { soapClient.SetThumbprint(url.Host, thumprint) } - vimClient, err := vim25.NewClient(ctx, soapClient) + vimClient, err := vim25.NewClient(ctx.context, soapClient) if err != nil { return nil, err } + c := &govmomi.Client{ Client: vimClient, SessionManager: session.NewManager(vimClient), } - if err := c.Login(ctx, url.User); err != nil { + + if feature.EnableKeepAlive { + vimClient.RoundTripper = session.KeepAliveHandler(vimClient.RoundTripper, feature.KeepAliveDuration * time.Minute, func(tripper soap.RoundTripper) error { + if ok, _ := c.SessionManager.SessionIsActive(ctx.context); ok { + return nil + } + if err := c.Login(ctx.context, url.User); err != nil { + ctx.logger.V(0).Info("unable to reestablish connection, resetting cache") + delete(sessionCache, sessionKey) + return errors.Wrap(err, "unable to reestablish connection") + } + return nil + }) + } + + if err := c.Login(ctx.context, url.User); err != nil { return nil, err } From 32909036c6b3e18a40b75f5ba2f3a3682e831b91 Mon Sep 17 00:00:00 2001 From: Deepak Sharma Date: Fri, 26 Mar 2021 11:02:31 +0530 Subject: [PATCH 2/8] add command line args for keep alive feature --- controllers/vspherecluster_controller.go | 5 ++++- controllers/vspherevm_controller.go | 5 ++++- main.go | 11 +++++++++++ pkg/context/controller_manager_context.go | 13 +++++++++++-- pkg/manager/constants.go | 5 +++++ pkg/manager/manager.go | 2 ++ pkg/manager/options.go | 8 ++++++++ 7 files changed, 45 insertions(+), 4 deletions(-) diff --git a/controllers/vspherecluster_controller.go b/controllers/vspherecluster_controller.go index 5c9d825003..1da5e0e14d 100644 --- a/controllers/vspherecluster_controller.go +++ b/controllers/vspherecluster_controller.go @@ -341,7 +341,10 @@ func (r clusterReconciler) reconcileVCenterConnectivity(ctx *context.ClusterCont ctx.Username, ctx.Password, ctx.VSphereCluster.Spec.Thumbprint, - session.DefaultFeature()) + session.Feature{ + EnableKeepAlive: r.EnableKeepAlive, + KeepAliveDuration: r.KeepAliveDuration, + }) return err } diff --git a/controllers/vspherevm_controller.go b/controllers/vspherevm_controller.go index 7397406bd1..2b5c340540 100644 --- a/controllers/vspherevm_controller.go +++ b/controllers/vspherevm_controller.go @@ -143,7 +143,10 @@ func (r vmReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, reterr error) r.ControllerManagerContext.Username, r.ControllerManagerContext.Password, vsphereVM.Spec.Thumbprint, - session.DefaultFeature()) + session.Feature{ + EnableKeepAlive: r.EnableKeepAlive, + KeepAliveDuration: r.KeepAliveDuration, + }) if err != nil { return reconcile.Result{}, errors.Wrap(err, "failed to create vSphere session") } diff --git a/main.go b/main.go index a42aa5a2ef..ac76cc7c5a 100644 --- a/main.go +++ b/main.go @@ -49,6 +49,8 @@ var ( defaultLeaderElectionID = manager.DefaultLeaderElectionID defaultPodName = manager.DefaultPodName defaultWebhookPort = manager.DefaultWebhookServiceContainerPort + defaultEnableKeepAlive = manager.DefaultEnableKeepAlive + defaultKeepAliveDuration = manager.DefaultKeepAliveDuration ) // nolint:gocognit @@ -117,6 +119,15 @@ func main() { "/etc/capv/credentials.yaml", "path to CAPV's credentials file", ) + flag.BoolVar(&managerOpts.EnableKeepAlive, + "enable-keep-alive", + defaultEnableKeepAlive, + "feature to enable keep alive handler in vsphere sessions") + + flag.DurationVar(&managerOpts.KeepAliveDuration, + "keep-alive-duration", + defaultKeepAliveDuration, + "idle time interval in between send() requests in keepalive handler") flag.Parse() diff --git a/pkg/context/controller_manager_context.go b/pkg/context/controller_manager_context.go index 11d2e3974d..df5d3e5d0f 100644 --- a/pkg/context/controller_manager_context.go +++ b/pkg/context/controller_manager_context.go @@ -19,14 +19,14 @@ package context import ( "context" "sync" + "time" "github.com/go-logr/logr" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/cluster-api-provider-vsphere/pkg/record" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/event" - - "sigs.k8s.io/cluster-api-provider-vsphere/pkg/record" ) // ControllerManagerContext is the context of the controller that owns the @@ -77,6 +77,15 @@ type ControllerManagerContext struct { // endpoints. Password string + + // EnableKeepAlive is a session feature to enable keep alive handler + // for better load management on vSphere api server + EnableKeepAlive bool + + // KeepAliveDuration is the idle time interval in between send() requests + // in keepalive handler + KeepAliveDuration time.Duration + genericEventCache sync.Map } diff --git a/pkg/manager/constants.go b/pkg/manager/constants.go index 58456d387a..d40eb2ae1b 100644 --- a/pkg/manager/constants.go +++ b/pkg/manager/constants.go @@ -29,6 +29,11 @@ const ( // manager option. DefaultSyncPeriod = time.Minute * 10 + // DefaultEnableKeepAlive is false by default + DefaultEnableKeepAlive = false + + DefaultKeepAliveDuration = time.Duration(0) + // DefaultPodName is the default value for the eponymous manager option. DefaultPodName = defaultPrefix + "controller-manager" diff --git a/pkg/manager/manager.go b/pkg/manager/manager.go index ff11a7265a..a713eaeaca 100644 --- a/pkg/manager/manager.go +++ b/pkg/manager/manager.go @@ -95,6 +95,8 @@ func New(opts Options) (Manager, error) { Scheme: opts.Scheme, Username: opts.Username, Password: opts.Password, + EnableKeepAlive: opts.EnableKeepAlive, + KeepAliveDuration: opts.KeepAliveDuration, } // Add the requested items to the manager. diff --git a/pkg/manager/options.go b/pkg/manager/options.go index 62fbddbd92..14651fc254 100644 --- a/pkg/manager/options.go +++ b/pkg/manager/options.go @@ -98,6 +98,14 @@ type Options struct { // endpoints. Password string + // EnableKeepAlive is a session feature to enable keep alive handler + // for better load management on vSphere api server + EnableKeepAlive bool + + // KeepAliveDuration is the idle time interval in between send() requests + // in keepalive handler + KeepAliveDuration time.Duration + // WebhookPort is the port that the webhook server serves at. WebhookPort int From f33a6165cb77b4aadcf0ad3963da7adce254b89d Mon Sep 17 00:00:00 2001 From: Deepak Sharma Date: Fri, 26 Mar 2021 11:11:27 +0530 Subject: [PATCH 3/8] go fmt --- main.go | 14 +++++++------- pkg/manager/manager.go | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index ac76cc7c5a..fbac351a96 100644 --- a/main.go +++ b/main.go @@ -43,13 +43,13 @@ import ( var ( setupLog = ctrllog.Log.WithName("entrypoint") - managerOpts manager.Options - defaultProfilerAddr = os.Getenv("PROFILER_ADDR") - defaultSyncPeriod = manager.DefaultSyncPeriod - defaultLeaderElectionID = manager.DefaultLeaderElectionID - defaultPodName = manager.DefaultPodName - defaultWebhookPort = manager.DefaultWebhookServiceContainerPort - defaultEnableKeepAlive = manager.DefaultEnableKeepAlive + managerOpts manager.Options + defaultProfilerAddr = os.Getenv("PROFILER_ADDR") + defaultSyncPeriod = manager.DefaultSyncPeriod + defaultLeaderElectionID = manager.DefaultLeaderElectionID + defaultPodName = manager.DefaultPodName + defaultWebhookPort = manager.DefaultWebhookServiceContainerPort + defaultEnableKeepAlive = manager.DefaultEnableKeepAlive defaultKeepAliveDuration = manager.DefaultKeepAliveDuration ) diff --git a/pkg/manager/manager.go b/pkg/manager/manager.go index a713eaeaca..cd8c26b424 100644 --- a/pkg/manager/manager.go +++ b/pkg/manager/manager.go @@ -95,8 +95,8 @@ func New(opts Options) (Manager, error) { Scheme: opts.Scheme, Username: opts.Username, Password: opts.Password, - EnableKeepAlive: opts.EnableKeepAlive, - KeepAliveDuration: opts.KeepAliveDuration, + EnableKeepAlive: opts.EnableKeepAlive, + KeepAliveDuration: opts.KeepAliveDuration, } // Add the requested items to the manager. From 3fea8d4fd4430c59bde3948782bc0d1cbebbc159 Mon Sep 17 00:00:00 2001 From: Deepak Sharma Date: Sun, 28 Mar 2021 09:58:27 +0530 Subject: [PATCH 4/8] change deafults update keepalivehandler --- pkg/manager/constants.go | 4 ++-- pkg/session/session.go | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/pkg/manager/constants.go b/pkg/manager/constants.go index d40eb2ae1b..a4c1abcd60 100644 --- a/pkg/manager/constants.go +++ b/pkg/manager/constants.go @@ -30,9 +30,9 @@ const ( DefaultSyncPeriod = time.Minute * 10 // DefaultEnableKeepAlive is false by default - DefaultEnableKeepAlive = false + DefaultEnableKeepAlive = true - DefaultKeepAliveDuration = time.Duration(0) + DefaultKeepAliveDuration = time.Duration(5) // DefaultPodName is the default value for the eponymous manager option. DefaultPodName = defaultPrefix + "controller-manager" diff --git a/pkg/session/session.go b/pkg/session/session.go index 024f0b7e33..dfee83217d 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -29,6 +29,7 @@ import ( "github.com/vmware/govmomi/object" "github.com/vmware/govmomi/session" "github.com/vmware/govmomi/vim25" + "github.com/vmware/govmomi/vim25/methods" "github.com/vmware/govmomi/vim25/soap" "sigs.k8s.io/cluster-api-provider-vsphere/api/v1alpha3" @@ -146,15 +147,18 @@ func newClient(ctx GetOrCreateContext, sessionKey string, url *url.URL, thumprin if feature.EnableKeepAlive { vimClient.RoundTripper = session.KeepAliveHandler(vimClient.RoundTripper, feature.KeepAliveDuration * time.Minute, func(tripper soap.RoundTripper) error { - if ok, _ := c.SessionManager.SessionIsActive(ctx.context); ok { - return nil + // we tried implementing + // c.Login here but the client once logged out + // keeps errong in invalid username or password + // we tried with cached username and password in session still the error persisted + // hence we just clear the cache and expect the client to + // be recreated in next GetOrCreate call + _, err := methods.GetCurrentTime(ctx.context, vimClient.RoundTripper) + if err != nil { + ctx.logger.Error(err, "failed to keep alive govmomi client") + ClearCache(sessionKey) } - if err := c.Login(ctx.context, url.User); err != nil { - ctx.logger.V(0).Info("unable to reestablish connection, resetting cache") - delete(sessionCache, sessionKey) - return errors.Wrap(err, "unable to reestablish connection") - } - return nil + return err }) } @@ -165,6 +169,12 @@ func newClient(ctx GetOrCreateContext, sessionKey string, url *url.URL, thumprin return c, nil } +func ClearCache(sessionKey string) { + sessionMU.Lock() + defer sessionMU.Unlock() + delete(sessionCache, sessionKey) +} + // FindByBIOSUUID finds an object by its BIOS UUID. // // To avoid comments about this function's name, please see the Golang From 831239e8b2d29f5fc94cc3c9d2c41b6481fb498b Mon Sep 17 00:00:00 2001 From: Deepak Sharma Date: Sun, 28 Mar 2021 15:51:41 +0530 Subject: [PATCH 5/8] use session from func --- pkg/session/session.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/session/session.go b/pkg/session/session.go index dfee83217d..3344d4c135 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -153,7 +153,7 @@ func newClient(ctx GetOrCreateContext, sessionKey string, url *url.URL, thumprin // we tried with cached username and password in session still the error persisted // hence we just clear the cache and expect the client to // be recreated in next GetOrCreate call - _, err := methods.GetCurrentTime(ctx.context, vimClient.RoundTripper) + _, err := methods.GetCurrentTime(ctx.context, tripper) if err != nil { ctx.logger.Error(err, "failed to keep alive govmomi client") ClearCache(sessionKey) From f55ecb971269cae63c6656407e904a36554b362a Mon Sep 17 00:00:00 2001 From: Deepak Sharma Date: Mon, 29 Mar 2021 09:31:33 +0530 Subject: [PATCH 6/8] keepalive default to false specify unit --- main.go | 2 +- pkg/manager/constants.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index fbac351a96..af58fe4de5 100644 --- a/main.go +++ b/main.go @@ -127,7 +127,7 @@ func main() { flag.DurationVar(&managerOpts.KeepAliveDuration, "keep-alive-duration", defaultKeepAliveDuration, - "idle time interval in between send() requests in keepalive handler") + "idle time interval(minutes) in between send() requests in keepalive handler") flag.Parse() diff --git a/pkg/manager/constants.go b/pkg/manager/constants.go index a4c1abcd60..02f21d36ac 100644 --- a/pkg/manager/constants.go +++ b/pkg/manager/constants.go @@ -30,8 +30,9 @@ const ( DefaultSyncPeriod = time.Minute * 10 // DefaultEnableKeepAlive is false by default - DefaultEnableKeepAlive = true + DefaultEnableKeepAlive = false + // KeepaliveDuration unit minutes DefaultKeepAliveDuration = time.Duration(5) // DefaultPodName is the default value for the eponymous manager option. From ddfee6bed5d4c2406880fce43c61a8d5b43c9a2c Mon Sep 17 00:00:00 2001 From: Deepak Sharma Date: Mon, 29 Mar 2021 11:31:31 +0530 Subject: [PATCH 7/8] duration unit changes --- pkg/manager/constants.go | 2 +- pkg/session/session.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/manager/constants.go b/pkg/manager/constants.go index 02f21d36ac..13eec26fba 100644 --- a/pkg/manager/constants.go +++ b/pkg/manager/constants.go @@ -33,7 +33,7 @@ const ( DefaultEnableKeepAlive = false // KeepaliveDuration unit minutes - DefaultKeepAliveDuration = time.Duration(5) + DefaultKeepAliveDuration = time.Minute * 5 // DefaultPodName is the default value for the eponymous manager option. DefaultPodName = defaultPrefix + "controller-manager" diff --git a/pkg/session/session.go b/pkg/session/session.go index 3344d4c135..a6282e91b3 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -146,7 +146,7 @@ func newClient(ctx GetOrCreateContext, sessionKey string, url *url.URL, thumprin } if feature.EnableKeepAlive { - vimClient.RoundTripper = session.KeepAliveHandler(vimClient.RoundTripper, feature.KeepAliveDuration * time.Minute, func(tripper soap.RoundTripper) error { + vimClient.RoundTripper = session.KeepAliveHandler(vimClient.RoundTripper, feature.KeepAliveDuration, func(tripper soap.RoundTripper) error { // we tried implementing // c.Login here but the client once logged out // keeps errong in invalid username or password From 1dc2499f1ab0d270161d52d345ae3253e44f3513 Mon Sep 17 00:00:00 2001 From: Deepak Sharma Date: Mon, 29 Mar 2021 20:09:12 +0530 Subject: [PATCH 8/8] fix go-lint --- pkg/context/controller_manager_context.go | 1 - pkg/manager/options.go | 8 ++++---- pkg/session/session.go | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pkg/context/controller_manager_context.go b/pkg/context/controller_manager_context.go index df5d3e5d0f..87f8ba284a 100644 --- a/pkg/context/controller_manager_context.go +++ b/pkg/context/controller_manager_context.go @@ -77,7 +77,6 @@ type ControllerManagerContext struct { // endpoints. Password string - // EnableKeepAlive is a session feature to enable keep alive handler // for better load management on vSphere api server EnableKeepAlive bool diff --git a/pkg/manager/options.go b/pkg/manager/options.go index 14651fc254..24e2fabbbe 100644 --- a/pkg/manager/options.go +++ b/pkg/manager/options.go @@ -47,6 +47,10 @@ type Options struct { // LeaderElectionEnabled is a flag that enables leader election. LeaderElectionEnabled bool + // EnableKeepAlive is a session feature to enable keep alive handler + // for better load management on vSphere api server + EnableKeepAlive bool + // LeaderElectionID is the name of the config map to use as the // locking resource when configuring leader election. LeaderElectionID string @@ -98,10 +102,6 @@ type Options struct { // endpoints. Password string - // EnableKeepAlive is a session feature to enable keep alive handler - // for better load management on vSphere api server - EnableKeepAlive bool - // KeepAliveDuration is the idle time interval in between send() requests // in keepalive handler KeepAliveDuration time.Duration diff --git a/pkg/session/session.go b/pkg/session/session.go index a6282e91b3..c426654c15 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -47,7 +47,7 @@ type Session struct { type GetOrCreateContext struct { context context.Context - logger logr.Logger + logger logr.Logger } func NewGetOrCreateContext(ctx context.Context, logger logr.Logger) GetOrCreateContext { @@ -57,9 +57,8 @@ func NewGetOrCreateContext(ctx context.Context, logger logr.Logger) GetOrCreateC } } - type Feature struct { - EnableKeepAlive bool + EnableKeepAlive bool KeepAliveDuration time.Duration }