From f0428fb8df6746b882cd82da64feaedbd3fdaf6c Mon Sep 17 00:00:00 2001 From: Xiujuan Xiang Date: Sun, 18 Jun 2023 16:35:36 +0800 Subject: [PATCH] don't call session logout for keephandler --- pkg/session/session.go | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/pkg/session/session.go b/pkg/session/session.go index 30d7c3adb3..ab8c44b748 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -136,9 +136,14 @@ func GetOrCreate(ctx context.Context, params *Params) (*Session, error) { logger.V(2).Info("found active cached vSphere client session") return s, nil } - } - clearCache(logger, sessionKey) + logger.V(2).Info("logout the session because it is inactive") + if err := s.Client.Logout(ctx); err != nil { + logger.Error(err, "unable to logout session") + } else { + logger.Info("logout session succeed") + } + } // soap.ParseURL expects a valid URL. In the case of a bare, unbracketed // IPv6 address (e.g fd00::1) ParseURL will fail. Surround unbracketed IPv6 @@ -215,7 +220,8 @@ func newClient(ctx context.Context, logger logr.Logger, sessionKey string, url * _, err := methods.GetCurrentTime(ctx, vimClient) if err != nil { logger.Error(err, "failed to keep alive govmomi client") - clearCache(logger, sessionKey) + logger.Info("clearing the session", "key", sessionKey) + sessionCache.Delete(sessionKey) } return err }) @@ -228,18 +234,6 @@ func newClient(ctx context.Context, logger logr.Logger, sessionKey string, url * return c, nil } -func clearCache(logger logr.Logger, sessionKey string) { - if cachedSession, ok := sessionCache.Load(sessionKey); ok { - s := cachedSession.(*Session) - - logger.Info("performing session log out and clearing session", "key", sessionKey) - if err := s.Logout(context.Background()); err != nil { - logger.Error(err, "unable to logout session") - } - } - sessionCache.Delete(sessionKey) -} - // newManager creates a Manager that encompasses the REST Client for the VSphere tagging API. func newManager(ctx context.Context, logger logr.Logger, sessionKey string, client *vim25.Client, user *url.Userinfo, feature Feature) (*tags.Manager, error) { rc := rest.NewClient(client) @@ -253,8 +247,8 @@ func newManager(ctx context.Context, logger logr.Logger, sessionKey string, clie return nil } - logger.Info("rest client session expired, clearing cache") - clearCache(logger, sessionKey) + logger.Info("rest client session expired, clearing session", "key", sessionKey) + sessionCache.Delete(sessionKey) return errors.New("rest client session expired") }) }