Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#1171 from srm09/add-logger-stmt
Browse files Browse the repository at this point in the history
Adds log statements to get/create session
  • Loading branch information
k8s-ci-robot authored Apr 16, 2021
2 parents e59ac1d + f495983 commit 5271576
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.15

require (
github.com/antihax/optional v1.0.0
github.com/go-logr/logr v0.3.0
github.com/go-logr/logr v0.4.0
github.com/google/go-cmp v0.5.2
github.com/google/uuid v1.1.2
github.com/onsi/ginkgo v1.14.1
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/logr v0.3.0 h1:q4c+kbcR0d5rSurhBR8dIgieOaYpXtsdTYfx22Cu6rs=
github.com/go-logr/logr v0.3.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/logr v0.4.0 h1:K7/B1jt6fIBQVd4Owv2MqGQClcgf0R266+7C/QjRcLc=
github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/zapr v0.2.0 h1:v6Ji8yBW77pva6NkJKQdHLAJKrIJKRHz0RXwPqCHSR4=
github.com/go-logr/zapr v0.2.0/go.mod h1:qhKdvif7YF5GI9NWEpyxTSSBdGmzkNguibrdCNVPunU=
github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0=
Expand Down
13 changes: 7 additions & 6 deletions pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/vmware/govmomi/session"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/soap"
ctrl "sigs.k8s.io/controller-runtime"

"sigs.k8s.io/cluster-api-provider-vsphere/api/v1alpha4"
)
Expand All @@ -47,14 +48,15 @@ type Session struct {
func GetOrCreate(
ctx context.Context,
server, datacenter, username, password string, thumbprint string) (*Session, error) {

logger := ctrl.LoggerFrom(ctx)
sessionMU.Lock()
defer sessionMU.Unlock()

sessionKey := server + username + datacenter
if session, ok := sessionCache[sessionKey]; ok {
if ok, _ := session.SessionManager.SessionIsActive(ctx); ok {
return &session, nil
if cachedSession, ok := sessionCache[sessionKey]; ok {
if ok, _ := cachedSession.SessionManager.SessionIsActive(ctx); ok {
logger.V(2).Info("found active cached vSphere client session", "server", server, "datacenter", datacenter)
return &cachedSession, nil
}
}

Expand Down Expand Up @@ -89,8 +91,7 @@ func GetOrCreate(
// Cache the session.
sessionCache[sessionKey] = session

// TODO(akutz) Reintroduce the logger.
//ctx.Logger.V(2).Info("cached vSphere client session", "server", server, "datacenter", datacenter)
logger.V(2).Info("cached vSphere client session", "server", server, "datacenter", datacenter)

return &session, nil
}
Expand Down

0 comments on commit 5271576

Please sign in to comment.