Skip to content

Commit

Permalink
don't call session logout for keephandler
Browse files Browse the repository at this point in the history
  • Loading branch information
xiujuanx committed Jul 17, 2023
1 parent 6ae5075 commit f0428fb
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
})
Expand All @@ -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)
Expand All @@ -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")
})
}
Expand Down

0 comments on commit f0428fb

Please sign in to comment.