diff --git a/controllers/vspherecluster_reconciler.go b/controllers/vspherecluster_reconciler.go index 7d2391e007..9a0217f60e 100644 --- a/controllers/vspherecluster_reconciler.go +++ b/controllers/vspherecluster_reconciler.go @@ -271,11 +271,7 @@ func (r *clusterReconciler) reconcileIdentitySecret(ctx context.Context, cluster func (r *clusterReconciler) reconcileVCenterConnectivity(ctx context.Context, clusterCtx *capvcontext.ClusterContext) (*session.Session, error) { params := session.NewParams(). WithServer(clusterCtx.VSphereCluster.Spec.Server). - WithThumbprint(clusterCtx.VSphereCluster.Spec.Thumbprint). - WithFeatures(session.Feature{ - EnableKeepAlive: r.ControllerManagerContext.EnableKeepAlive, - KeepAliveDuration: r.ControllerManagerContext.KeepAliveDuration, - }) + WithThumbprint(clusterCtx.VSphereCluster.Spec.Thumbprint) if clusterCtx.VSphereCluster.Spec.IdentityRef != nil { creds, err := identity.GetCredentials(ctx, r.Client, clusterCtx.VSphereCluster, r.ControllerManagerContext.Namespace) diff --git a/controllers/vspheredeploymentzone_controller.go b/controllers/vspheredeploymentzone_controller.go index 8932cc6097..ab306cc9b7 100644 --- a/controllers/vspheredeploymentzone_controller.go +++ b/controllers/vspheredeploymentzone_controller.go @@ -191,11 +191,7 @@ func (r vsphereDeploymentZoneReconciler) getVCenterSession(ctx context.Context, params := session.NewParams(). WithServer(deploymentZoneCtx.VSphereDeploymentZone.Spec.Server). WithDatacenter(datacenter). - WithUserInfo(r.ControllerManagerContext.Username, r.ControllerManagerContext.Password). - WithFeatures(session.Feature{ - EnableKeepAlive: r.EnableKeepAlive, - KeepAliveDuration: r.KeepAliveDuration, - }) + WithUserInfo(r.ControllerManagerContext.Username, r.ControllerManagerContext.Password) clusterList := &infrav1.VSphereClusterList{} if err := r.Client.List(ctx, clusterList); err != nil { diff --git a/controllers/vspherevm_controller.go b/controllers/vspherevm_controller.go index c71050e998..edc34d4db5 100644 --- a/controllers/vspherevm_controller.go +++ b/controllers/vspherevm_controller.go @@ -587,11 +587,8 @@ func (r vmReconciler) retrieveVcenterSession(ctx context.Context, vsphereVM *inf WithServer(vsphereVM.Spec.Server). WithDatacenter(vsphereVM.Spec.Datacenter). WithUserInfo(r.ControllerManagerContext.Username, r.ControllerManagerContext.Password). - WithThumbprint(vsphereVM.Spec.Thumbprint). - WithFeatures(session.Feature{ - EnableKeepAlive: r.ControllerManagerContext.EnableKeepAlive, - KeepAliveDuration: r.ControllerManagerContext.KeepAliveDuration, - }) + WithThumbprint(vsphereVM.Spec.Thumbprint) + cluster, err := clusterutilv1.GetClusterFromMetadata(ctx, r.Client, vsphereVM.ObjectMeta) if err != nil { log.V(4).Info("Using credentials provided to the manager to create the authenticated session, VSphereVM is missing cluster label or cluster does not exist") diff --git a/main.go b/main.go index ad0b586e57..f10fb5f101 100644 --- a/main.go +++ b/main.go @@ -53,7 +53,6 @@ import ( "sigs.k8s.io/cluster-api-provider-vsphere/controllers" "sigs.k8s.io/cluster-api-provider-vsphere/feature" "sigs.k8s.io/cluster-api-provider-vsphere/internal/webhooks" - "sigs.k8s.io/cluster-api-provider-vsphere/pkg/constants" capvcontext "sigs.k8s.io/cluster-api-provider-vsphere/pkg/context" "sigs.k8s.io/cluster-api-provider-vsphere/pkg/manager" "sigs.k8s.io/cluster-api-provider-vsphere/pkg/session" @@ -88,13 +87,11 @@ var ( tlsOptions = capiflags.TLSOptions{} diagnosticsOptions = capiflags.DiagnosticsOptions{} - defaultProfilerAddr = os.Getenv("PROFILER_ADDR") - defaultSyncPeriod = manager.DefaultSyncPeriod - defaultLeaderElectionID = manager.DefaultLeaderElectionID - defaultPodName = manager.DefaultPodName - defaultWebhookPort = manager.DefaultWebhookServiceContainerPort - defaultEnableKeepAlive = constants.DefaultEnableKeepAlive - defaultKeepAliveDuration = constants.DefaultKeepAliveDuration + defaultProfilerAddr = os.Getenv("PROFILER_ADDR") + defaultSyncPeriod = manager.DefaultSyncPeriod + defaultLeaderElectionID = manager.DefaultLeaderElectionID + defaultPodName = manager.DefaultPodName + defaultWebhookPort = manager.DefaultWebhookServiceContainerPort ) // InitFlags initializes the flags. @@ -143,21 +140,7 @@ func InitFlags(fs *pflag.FlagSet) { "/etc/capv/credentials.yaml", "path to CAPV's credentials file", ) - fs.BoolVar( - &managerOpts.EnableKeepAlive, - "enable-keep-alive", - defaultEnableKeepAlive, - "feature to enable keep alive handler in vsphere sessions. This functionality is disabled by default.") - _ = fs.MarkDeprecated("enable-keep-alive", "This flag has been deprecated and will be removed in a "+ - "future release. Note: This feature has been disabled per default because we determined that we already keep alive "+ - "sessions just by our regular reconciles. So we don't need an additional keep alive handler. Enabling "+ - "this feature may lead to a deadlock in controllers communicating with vCenter.") - fs.DurationVar( - &managerOpts.KeepAliveDuration, - "keep-alive-duration", - defaultKeepAliveDuration, - "idle time interval(minutes) in between send() requests in keepalive handler", - ) + fs.StringVar( &managerOpts.NetworkProvider, "network-provider", diff --git a/pkg/clustermodule/session.go b/pkg/clustermodule/session.go index de8052c8c6..2c3fcb4b71 100644 --- a/pkg/clustermodule/session.go +++ b/pkg/clustermodule/session.go @@ -42,11 +42,7 @@ func (s *service) fetchSessionForObject(ctx context.Context, clusterCtx *capvcon func (s *service) newParams(clusterCtx capvcontext.ClusterContext) *session.Params { return session.NewParams(). WithServer(clusterCtx.VSphereCluster.Spec.Server). - WithThumbprint(clusterCtx.VSphereCluster.Spec.Thumbprint). - WithFeatures(session.Feature{ - EnableKeepAlive: s.ControllerManagerContext.EnableKeepAlive, - KeepAliveDuration: s.ControllerManagerContext.KeepAliveDuration, - }) + WithThumbprint(clusterCtx.VSphereCluster.Spec.Thumbprint) } func (s *service) fetchSession(ctx context.Context, clusterCtx *capvcontext.ClusterContext, params *session.Params) (*session.Session, error) { diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index d990b8e3aa..e763b54708 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -18,8 +18,6 @@ limitations under the License. package constants import ( - "time" - infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1" ) @@ -52,12 +50,6 @@ const ( // cluster are in maintenance mode. MaintenanceAnnotationLabel = "capv." + infrav1.GroupName + "/maintenance" - // DefaultEnableKeepAlive is false by default. - DefaultEnableKeepAlive = false - - // DefaultKeepAliveDuration unit minutes. - DefaultKeepAliveDuration = time.Minute * 5 - // NodeLabelPrefix is the prefix for node labels. NodeLabelPrefix = "node.cluster.x-k8s.io" diff --git a/pkg/context/controller_manager_context.go b/pkg/context/controller_manager_context.go index 47b68eabe7..564955ab42 100644 --- a/pkg/context/controller_manager_context.go +++ b/pkg/context/controller_manager_context.go @@ -18,7 +18,6 @@ package context import ( "sync" - "time" "github.com/go-logr/logr" "k8s.io/apimachinery/pkg/runtime" @@ -67,14 +66,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 - - // KeepAliveDuration is the idle time interval in between send() requests - // in keepalive handler - KeepAliveDuration time.Duration - // NetworkProvider is the network provider used by Supervisor based clusters NetworkProvider string diff --git a/pkg/manager/manager.go b/pkg/manager/manager.go index 5a4d99fc5d..db690296b7 100644 --- a/pkg/manager/manager.go +++ b/pkg/manager/manager.go @@ -87,8 +87,6 @@ func New(ctx context.Context, opts Options) (Manager, error) { Scheme: opts.Scheme, Username: opts.Username, Password: opts.Password, - EnableKeepAlive: opts.EnableKeepAlive, - KeepAliveDuration: opts.KeepAliveDuration, NetworkProvider: opts.NetworkProvider, WatchFilterValue: opts.WatchFilterValue, } diff --git a/pkg/manager/options.go b/pkg/manager/options.go index 376a47e8eb..0a26a11eb7 100644 --- a/pkg/manager/options.go +++ b/pkg/manager/options.go @@ -20,7 +20,6 @@ import ( "context" "os" "strings" - "time" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/rest" @@ -41,10 +40,6 @@ type AddToManagerFunc func(context.Context, *capvcontext.ControllerManagerContex type Options struct { ctrlmgr.Options - // EnableKeepAlive is a session feature to enable keep alive handler - // for better load management on vSphere api server - EnableKeepAlive bool - // PodNamespace is the namespace in which the pod running the controller // maintains a leader election lock. // @@ -64,10 +59,6 @@ type Options struct { // endpoints. Password string - // KeepAliveDuration is the idle time interval in between send() requests - // in keepalive handler - KeepAliveDuration time.Duration - // CredentialsFile is the file that contains credentials of CAPV CredentialsFile string diff --git a/pkg/session/session.go b/pkg/session/session.go index 0b101e7bfa..acd467ab60 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -24,7 +24,6 @@ import ( "net/netip" "net/url" "sync" - "time" "github.com/blang/semver" "github.com/pkg/errors" @@ -32,16 +31,13 @@ import ( "github.com/vmware/govmomi/find" "github.com/vmware/govmomi/object" "github.com/vmware/govmomi/session" - "github.com/vmware/govmomi/session/keepalive" "github.com/vmware/govmomi/vapi/rest" "github.com/vmware/govmomi/vapi/tags" "github.com/vmware/govmomi/vim25" - "github.com/vmware/govmomi/vim25/methods" "github.com/vmware/govmomi/vim25/soap" ctrl "sigs.k8s.io/controller-runtime" infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1" - "sigs.k8s.io/cluster-api-provider-vsphere/pkg/constants" ) var ( @@ -62,16 +58,11 @@ type Session struct { } // Feature is a set of Features of the session. -type Feature struct { - EnableKeepAlive bool - KeepAliveDuration time.Duration -} +type Feature struct{} // DefaultFeature sets the default values for features. func DefaultFeature() Feature { - return Feature{ - EnableKeepAlive: constants.DefaultEnableKeepAlive, - } + return Feature{} } // Params are the parameters of a VCenter session. @@ -191,7 +182,7 @@ func GetOrCreate(ctx context.Context, params *Params) (*Session, error) { } soapURL.User = params.userinfo - client, err := newClient(ctx, sessionKey, soapURL, params.thumbprint, params.feature) + client, err := newClient(ctx, soapURL, params.thumbprint, params.feature) if err != nil { return nil, errors.Wrapf(err, "failed to create vCenter session") } @@ -202,7 +193,7 @@ func GetOrCreate(ctx context.Context, params *Params) (*Session, error) { // Assign the finder to the session. session.Finder = find.NewFinder(session.Client.Client, false) // Assign tag manager to the session. - manager, err := newManager(ctx, sessionKey, client.Client, soapURL.User, params.feature) + manager, err := newManager(ctx, client.Client, soapURL.User, params.feature) if err != nil { log.Error(err, "Failed to create tags manager, will logout") // Logout of previously logged session to not leak @@ -238,9 +229,7 @@ func GetOrCreate(ctx context.Context, params *Params) (*Session, error) { return &session, nil } -func newClient(ctx context.Context, sessionKey string, url *url.URL, thumbprint string, feature Feature) (*govmomi.Client, error) { - log := ctrl.LoggerFrom(ctx) - +func newClient(ctx context.Context, url *url.URL, thumbprint string, _ Feature) (*govmomi.Client, error) { insecure := thumbprint == "" soapClient := soap.NewClient(url, insecure) if !insecure { @@ -258,20 +247,6 @@ func newClient(ctx context.Context, sessionKey string, url *url.URL, thumbprint SessionManager: session.NewManager(vimClient), } - if feature.EnableKeepAlive { - vimClient.RoundTripper = session.KeepAliveHandler(vimClient.RoundTripper, feature.KeepAliveDuration, func(tripper soap.RoundTripper) error { - _, err := methods.GetCurrentTime(ctx, tripper) - if err != nil { - log.Error(err, "Failed to keep alive govmomi client, Clearing the session now") - if errLogout := c.Logout(ctx); errLogout != nil { - log.Error(err, "Failed to logout keepalive failed session") - } - sessionCache.Delete(sessionKey) - } - return err - }) - } - if err := c.Login(ctx, url.User); err != nil { return nil, errors.Wrapf(err, "failed to create client: failed to login") } @@ -280,29 +255,8 @@ func newClient(ctx context.Context, sessionKey string, url *url.URL, thumbprint } // newManager creates a Manager that encompasses the REST Client for the VSphere tagging API. -func newManager(ctx context.Context, sessionKey string, client *vim25.Client, user *url.Userinfo, feature Feature) (*tags.Manager, error) { - log := ctrl.LoggerFrom(ctx) - +func newManager(ctx context.Context, client *vim25.Client, user *url.Userinfo, _ Feature) (*tags.Manager, error) { rc := rest.NewClient(client) - if feature.EnableKeepAlive { - rc.Transport = keepalive.NewHandlerREST(rc, feature.KeepAliveDuration, func() error { - s, err := rc.Session(ctx) - if s != nil && err == nil { - return nil - } - - if err != nil { - log.Error(err, "Failed to keep alive REST client") - } - - log.Info("REST client session expired, clearing session") - if errLogout := rc.Logout(ctx); errLogout != nil { - log.Error(err, "Failed to logout keepalive failed REST session") - } - sessionCache.Delete(sessionKey) - return errors.New("REST client session expired") - }) - } if err := rc.Login(ctx, user); err != nil { return nil, errors.Wrapf(err, "failed to create tags manager: failed to login REST client") } diff --git a/pkg/session/session_test.go b/pkg/session/session_test.go index a37fa99f39..c7f6f6e3de 100644 --- a/pkg/session/session_test.go +++ b/pkg/session/session_test.go @@ -112,63 +112,3 @@ func assertSessionCountEqualTo(g *WithT, simr *vcsim.Simulator, count int) { return sessions == count }, 30*time.Second).Should(BeTrue()) } - -func TestGetSessionWithKeepAlive(t *testing.T) { - g := NewWithT(t) - ctrl.SetLogger(klog.Background()) - - model := simulator.VPX() - model.Cluster = 2 - - simr, err := vcsim.NewBuilder(). - WithModel(model).Build() - if err != nil { - t.Fatalf("failed to create VC simulator") - } - defer simr.Destroy() - - params := NewParams(). - WithServer(simr.ServerURL().Host). - WithUserInfo(simr.Username(), simr.Password()). - WithDatacenter("*") - - // Get first Session - ctx := context.Background() - s, err := GetOrCreate(ctx, params) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(s).ToNot(BeNil()) - assertSessionCountEqualTo(g, simr, 1) - - // Get session key - sessionInfo, err := s.SessionManager.UserSession(ctx) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(sessionInfo).ToNot(BeNil()) - firstSession := sessionInfo.Key - - // Get the session again - // as keep alive is enabled and session is - // not expired we must get the same cached session - s, err = GetOrCreate(ctx, params) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(s).ToNot(BeNil()) - sessionInfo, err = s.SessionManager.UserSession(ctx) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(sessionInfo).ToNot(BeNil()) - g.Expect(sessionInfo.Key).To(BeEquivalentTo(firstSession)) - assertSessionCountEqualTo(g, simr, 1) - - // Try to remove vim session - g.Expect(s.Logout(ctx)).To(Succeed()) - - // after logging out old session must be deleted, - // we must get a new different session - // total session count must remain 1 - s, err = GetOrCreate(ctx, params) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(s).ToNot(BeNil()) - sessionInfo, err = s.SessionManager.UserSession(ctx) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(sessionInfo).ToNot(BeNil()) - g.Expect(sessionInfo.Key).ToNot(BeEquivalentTo(firstSession)) - assertSessionCountEqualTo(g, simr, 1) -} diff --git a/test/framework/vmoperator/vmoperator.go b/test/framework/vmoperator/vmoperator.go index 7a7c3e8a40..e693860a8c 100644 --- a/test/framework/vmoperator/vmoperator.go +++ b/test/framework/vmoperator/vmoperator.go @@ -710,7 +710,7 @@ func ReconcileDependencies(ctx context.Context, c client.Client, dependenciesCon } // GetVCenterSession returns a VCenter session from vm-operator config. -func GetVCenterSession(ctx context.Context, c client.Client, enableKeepAlive bool, keepAliveDuration time.Duration) (*session.Session, error) { +func GetVCenterSession(ctx context.Context, c client.Client) (*session.Session, error) { configMap := &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: configMapName, @@ -760,16 +760,12 @@ func GetVCenterSession(ctx context.Context, c client.Client, enableKeepAlive boo WithServer(serverURL). WithDatacenter(datacenter). WithUserInfo(username, password). - WithThumbprint(thumbprint). - WithFeatures(session.Feature{ - EnableKeepAlive: enableKeepAlive, - KeepAliveDuration: keepAliveDuration, - }) + WithThumbprint(thumbprint) return session.GetOrCreate(ctx, params) } -// GetDistributedPortGroup returns a the DistributedPortGroup from vm-operator config. +// GetDistributedPortGroup returns a DistributedPortGroup from vm-operator config. func GetDistributedPortGroup(ctx context.Context, c client.Client) (string, error) { configMap := &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ diff --git a/test/infrastructure/net-operator/controllers/networkinterface_controller.go b/test/infrastructure/net-operator/controllers/networkinterface_controller.go index d1b5556765..6d7e528b6c 100644 --- a/test/infrastructure/net-operator/controllers/networkinterface_controller.go +++ b/test/infrastructure/net-operator/controllers/networkinterface_controller.go @@ -18,7 +18,6 @@ package controllers import ( "context" - "time" "github.com/pkg/errors" netopv1alpha1 "github.com/vmware-tanzu/net-operator-api/api/v1alpha1" @@ -36,9 +35,7 @@ import ( ) type NetworkInterfaceReconciler struct { - Client client.Client - EnableKeepAlive bool - KeepAliveDuration time.Duration + Client client.Client // WatchFilterValue is the label value used to filter events prior to reconciliation. WatchFilterValue string @@ -76,7 +73,7 @@ func (r *NetworkInterfaceReconciler) Reconcile(ctx context.Context, req ctrl.Req }() if networkInterface.Status.NetworkID == "" { - s, err := vmoperator.GetVCenterSession(ctx, r.Client, r.EnableKeepAlive, r.KeepAliveDuration) + s, err := vmoperator.GetVCenterSession(ctx, r.Client) if err != nil { return reconcile.Result{}, errors.Wrapf(err, "failed to get vcenter session") } diff --git a/test/infrastructure/net-operator/main.go b/test/infrastructure/net-operator/main.go index 66c0da82f2..d865a0939e 100644 --- a/test/infrastructure/net-operator/main.go +++ b/test/infrastructure/net-operator/main.go @@ -50,7 +50,6 @@ import ( ctrlmgr "sigs.k8s.io/controller-runtime/pkg/manager" vmwarev1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/vmware/v1beta1" - "sigs.k8s.io/cluster-api-provider-vsphere/pkg/constants" "sigs.k8s.io/cluster-api-provider-vsphere/test/infrastructure/net-operator/controllers" ) @@ -76,9 +75,6 @@ var ( logOptions = logs.NewOptions() // net operator specific flags. networkInterfaceConcurrency int - // vsphere session specific flags. - enableKeepAlive bool - keepAliveDuration time.Duration ) func init() { @@ -130,12 +126,6 @@ func InitFlags(fs *pflag.FlagSet) { fs.StringVar(&healthAddr, "health-addr", ":9440", "The address the health endpoint binds to.") - fs.BoolVar(&enableKeepAlive, "enable-keep-alive", constants.DefaultEnableKeepAlive, - "feature to enable keep alive handler in vsphere sessions. This functionality is enabled by default.") - - fs.DurationVar(&keepAliveDuration, "keep-alive-duration", constants.DefaultKeepAliveDuration, - "idle time interval(minutes) in between send() requests in keepalive handler") - flags.AddDiagnosticsOptions(fs, &diagnosticsOptions) feature.MutableGates.AddFlag(fs) @@ -205,13 +195,6 @@ func main() { }, }, }, - // WebhookServer: webhook.NewServer( - // webhook.Options{ - // Port: webhookPort, - // CertDir: webhookCertDir, - // TLSOpts: tlsOptionOverrides, - // }, - // ), } mgr, err := ctrl.NewManager(restConfig, ctrlOptions) @@ -267,10 +250,8 @@ func setupIndexes(_ context.Context, _ ctrl.Manager, _ bool) { func setupReconcilers(ctx context.Context, mgr ctrl.Manager, _ bool) { if err := (&controllers.NetworkInterfaceReconciler{ - Client: mgr.GetClient(), - EnableKeepAlive: enableKeepAlive, - KeepAliveDuration: keepAliveDuration, - WatchFilterValue: watchFilterValue, + Client: mgr.GetClient(), + WatchFilterValue: watchFilterValue, }).SetupWithManager(ctx, mgr, concurrency(networkInterfaceConcurrency)); err != nil { setupLog.Error(err, "unable to create controller", "controller", "NetworkInterfaceReconciler") os.Exit(1) diff --git a/test/infrastructure/vcsim/controllers/virtualmachine_controller.go b/test/infrastructure/vcsim/controllers/virtualmachine_controller.go index c799d8bd25..3c805a1fda 100644 --- a/test/infrastructure/vcsim/controllers/virtualmachine_controller.go +++ b/test/infrastructure/vcsim/controllers/virtualmachine_controller.go @@ -20,7 +20,6 @@ import ( "context" "fmt" "path" - "time" "github.com/pkg/errors" vmoprv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha1" @@ -50,11 +49,9 @@ import ( ) type VirtualMachineReconciler struct { - Client client.Client - InMemoryManager inmemoryruntime.Manager - APIServerMux *inmemoryserver.WorkloadClustersMux - EnableKeepAlive bool - KeepAliveDuration time.Duration + Client client.Client + InMemoryManager inmemoryruntime.Manager + APIServerMux *inmemoryserver.WorkloadClustersMux // WatchFilterValue is the label value used to filter events prior to reconciliation. WatchFilterValue string @@ -252,9 +249,7 @@ func (r *VirtualMachineReconciler) reconcileDelete(ctx context.Context, cluster func (r *VirtualMachineReconciler) getVMIpReconciler(cluster *clusterv1.Cluster, virtualMachine *vmoprv1.VirtualMachine) *vmIPReconciler { return &vmIPReconciler{ - Client: r.Client, - EnableKeepAlive: r.EnableKeepAlive, - KeepAliveDuration: r.KeepAliveDuration, + Client: r.Client, // Type specific functions; those functions wraps the differences between govmomi and supervisor types, // thus allowing to use the same vmIPReconciler in both scenarios. @@ -294,7 +289,7 @@ func (r *VirtualMachineReconciler) getVMBootstrapReconciler(virtualMachine *vmop } func (r *VirtualMachineReconciler) getVCenterSession(ctx context.Context) (*session.Session, error) { - return vmoperator.GetVCenterSession(ctx, r.Client, r.EnableKeepAlive, r.KeepAliveDuration) + return vmoperator.GetVCenterSession(ctx, r.Client) } // SetupWithManager will add watches for this controller. diff --git a/test/infrastructure/vcsim/controllers/vmip_controller.go b/test/infrastructure/vcsim/controllers/vmip_controller.go index 5a7415bf3d..8d325b7679 100644 --- a/test/infrastructure/vcsim/controllers/vmip_controller.go +++ b/test/infrastructure/vcsim/controllers/vmip_controller.go @@ -18,7 +18,6 @@ package controllers import ( "context" - "time" "github.com/pkg/errors" "github.com/vmware/govmomi/vim25/types" @@ -31,9 +30,7 @@ import ( ) type vmIPReconciler struct { - Client client.Client - EnableKeepAlive bool - KeepAliveDuration time.Duration + Client client.Client IsVMWaitingforIP func() bool GetVCenterSession func(ctx context.Context) (*session.Session, error) diff --git a/test/infrastructure/vcsim/controllers/vspherevm_controller.go b/test/infrastructure/vcsim/controllers/vspherevm_controller.go index 4572d9a598..bd2c542c78 100644 --- a/test/infrastructure/vcsim/controllers/vspherevm_controller.go +++ b/test/infrastructure/vcsim/controllers/vspherevm_controller.go @@ -20,7 +20,6 @@ import ( "context" "fmt" "path" - "time" "github.com/pkg/errors" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -52,11 +51,9 @@ import ( const capvNamespace = "capv-system" type VSphereVMReconciler struct { - Client client.Client - InMemoryManager inmemoryruntime.Manager - APIServerMux *inmemoryserver.WorkloadClustersMux - EnableKeepAlive bool - KeepAliveDuration time.Duration + Client client.Client + InMemoryManager inmemoryruntime.Manager + APIServerMux *inmemoryserver.WorkloadClustersMux // WatchFilterValue is the label value used to filter events prior to reconciliation. WatchFilterValue string @@ -254,9 +251,7 @@ func (r *VSphereVMReconciler) reconcileDelete(ctx context.Context, cluster *clus func (r *VSphereVMReconciler) getVMIpReconciler(vSphereCluster *infrav1.VSphereCluster, vSphereVM *infrav1.VSphereVM) *vmIPReconciler { return &vmIPReconciler{ - Client: r.Client, - EnableKeepAlive: r.EnableKeepAlive, - KeepAliveDuration: r.KeepAliveDuration, + Client: r.Client, // Type specific functions; those functions wraps the differences between govmomi and supervisor types, // thus allowing to use the same vmIPReconciler in both scenarios. @@ -308,11 +303,7 @@ func (r *VSphereVMReconciler) getVCenterSession(ctx context.Context, vSphereClus WithServer(vSphereVM.Spec.Server). WithDatacenter(vSphereVM.Spec.Datacenter). WithUserInfo(creds.Username, creds.Password). - WithThumbprint(vSphereVM.Spec.Thumbprint). - WithFeatures(session.Feature{ - EnableKeepAlive: r.EnableKeepAlive, - KeepAliveDuration: r.KeepAliveDuration, - }) + WithThumbprint(vSphereVM.Spec.Thumbprint) return session.GetOrCreate(ctx, params) } diff --git a/test/infrastructure/vcsim/main.go b/test/infrastructure/vcsim/main.go index 6f4b56421e..86423c38eb 100644 --- a/test/infrastructure/vcsim/main.go +++ b/test/infrastructure/vcsim/main.go @@ -57,7 +57,6 @@ import ( infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1" vmwarev1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/vmware/v1beta1" - "sigs.k8s.io/cluster-api-provider-vsphere/pkg/constants" vcsimv1 "sigs.k8s.io/cluster-api-provider-vsphere/test/infrastructure/vcsim/api/v1alpha1" "sigs.k8s.io/cluster-api-provider-vsphere/test/infrastructure/vcsim/controllers" ) @@ -90,9 +89,6 @@ var ( controlPlaneEndpointConcurrency int envsubstConcurrency int vmOperatorDependenciesConcurrency int - // vsphere session specific flags. - enableKeepAlive bool - keepAliveDuration time.Duration ) func init() { @@ -171,12 +167,6 @@ func InitFlags(fs *pflag.FlagSet) { fs.StringVar(&healthAddr, "health-addr", ":9440", "The address the health endpoint binds to.") - fs.BoolVar(&enableKeepAlive, "enable-keep-alive", constants.DefaultEnableKeepAlive, - "feature to enable keep alive handler in vsphere sessions. This functionality is enabled by default.") - - fs.DurationVar(&keepAliveDuration, "keep-alive-duration", constants.DefaultKeepAliveDuration, - "idle time interval(minutes) in between send() requests in keepalive handler") - flags.AddDiagnosticsOptions(fs, &diagnosticsOptions) feature.MutableGates.AddFlag(fs) @@ -353,12 +343,10 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager, supervisorMode bool if supervisorMode { if err := (&controllers.VirtualMachineReconciler{ - Client: mgr.GetClient(), - InMemoryManager: inmemoryManager, - APIServerMux: apiServerMux, - EnableKeepAlive: enableKeepAlive, - KeepAliveDuration: keepAliveDuration, - WatchFilterValue: watchFilterValue, + Client: mgr.GetClient(), + InMemoryManager: inmemoryManager, + APIServerMux: apiServerMux, + WatchFilterValue: watchFilterValue, }).SetupWithManager(ctx, mgr, concurrency(virtualMachineConcurrency)); err != nil { setupLog.Error(err, "unable to create controller", "controller", "VirtualMachineReconciler") os.Exit(1) @@ -373,12 +361,10 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager, supervisorMode bool } } else { if err := (&controllers.VSphereVMReconciler{ - Client: mgr.GetClient(), - InMemoryManager: inmemoryManager, - APIServerMux: apiServerMux, - EnableKeepAlive: enableKeepAlive, - KeepAliveDuration: keepAliveDuration, - WatchFilterValue: watchFilterValue, + Client: mgr.GetClient(), + InMemoryManager: inmemoryManager, + APIServerMux: apiServerMux, + WatchFilterValue: watchFilterValue, }).SetupWithManager(ctx, mgr, concurrency(vSphereVMConcurrency)); err != nil { setupLog.Error(err, "unable to create controller", "controller", "VSphereVMReconciler") os.Exit(1)