@@ -2,22 +2,15 @@ package vsphere
22
33import (
44 "context"
5- "crypto/tls"
6- "encoding/pem"
75 "errors"
86 "fmt"
9- "net/url"
107 "reflect"
118 "strconv"
129 "strings"
1310
1411 "github.com/davecgh/go-spew/spew"
1512 "github.com/vmware/govmomi/cns"
1613 cnstypes "github.com/vmware/govmomi/cns/types"
17- "github.com/vmware/govmomi/sts"
18- "github.com/vmware/govmomi/vapi/rest"
19- "github.com/vmware/govmomi/vapi/tags"
20- "github.com/vmware/govmomi/vim25"
2114 "github.com/vmware/govmomi/vim25/soap"
2215 "github.com/vmware/govmomi/vim25/types"
2316 "sigs.k8s.io/vsphere-csi-driver/v3/pkg/common/config"
@@ -201,6 +194,12 @@ func GetVirtualCenterConfig(ctx context.Context, cfg *config.Config) (*VirtualCe
201194 ListVolumeThreshold : cfg .Global .ListVolumeThreshold ,
202195 MigrationDataStoreURL : cfg .VirtualCenter [host ].MigrationDataStoreURL ,
203196 FileVolumeActivated : cfg .VirtualCenter [host ].FileVolumeActivated ,
197+ VCSessionManagerURL : cfg .VirtualCenter [host ].VCSessionManagerURL ,
198+ VCSessionManagerToken : cfg .VirtualCenter [host ].VCSessionManagerToken ,
199+ }
200+
201+ if vcConfig .VCSessionManagerURL != "" {
202+ log .Infof ("Using Shared Session Manager: %s" , vcConfig .VCSessionManagerURL )
204203 }
205204
206205 log .Debugf ("Setting the queryLimit = %v, ListVolumeThreshold = %v" , vcConfig .QueryLimit , vcConfig .ListVolumeThreshold )
@@ -247,6 +246,8 @@ func GetVirtualCenterConfigs(ctx context.Context, cfg *config.Config) ([]*Virtua
247246 QueryLimit : cfg .Global .QueryLimit ,
248247 ListVolumeThreshold : cfg .Global .ListVolumeThreshold ,
249248 FileVolumeActivated : cfg .VirtualCenter [vCenterIP ].FileVolumeActivated ,
249+ VCSessionManagerURL : cfg .VirtualCenter [vCenterIP ].VCSessionManagerURL ,
250+ VCSessionManagerToken : cfg .VirtualCenter [vCenterIP ].VCSessionManagerToken ,
250251 }
251252 if vcConfig .CAFile == "" {
252253 vcConfig .CAFile = cfg .Global .CAFile
@@ -307,62 +308,6 @@ func CompareKubernetesMetadata(ctx context.Context, k8sMetaData *cnstypes.CnsKub
307308 return labelsMatch
308309}
309310
310- // Signer decodes the certificate and private key and returns SAML token needed
311- // for authentication.
312- func signer (ctx context.Context , client * vim25.Client , username string , password string ) (* sts.Signer , error ) {
313- pemBlock , _ := pem .Decode ([]byte (username ))
314- if pemBlock == nil {
315- return nil , nil
316- }
317- certificate , err := tls .X509KeyPair ([]byte (username ), []byte (password ))
318- if err != nil {
319- return nil , fmt .Errorf ("failed to load X509 key pair. Error: %+v" , err )
320- }
321- tokens , err := sts .NewClient (ctx , client )
322- if err != nil {
323- return nil , fmt .Errorf ("failed to create STS client. err: %+v" , err )
324- }
325- req := sts.TokenRequest {
326- Certificate : & certificate ,
327- Delegatable : true ,
328- }
329- signer , err := tokens .Issue (ctx , req )
330- if err != nil {
331- return nil , fmt .Errorf ("failed to issue SAML token. err: %+v" , err )
332- }
333- return signer , nil
334- }
335-
336- // GetTagManager returns tagManager connected to given VirtualCenter.
337- func GetTagManager (ctx context.Context , vc * VirtualCenter ) (* tags.Manager , error ) {
338- log := logger .GetLogger (ctx )
339- // Validate input.
340- if vc == nil || vc .Client == nil || vc .Client .Client == nil {
341- return nil , fmt .Errorf ("vCenter not initialized" )
342- }
343-
344- restClient := rest .NewClient (vc .Client .Client )
345- signer , err := signer (ctx , vc .Client .Client , vc .Config .Username , vc .Config .Password )
346- if err != nil {
347- return nil , fmt .Errorf ("failed to create the Signer. Error: %v" , err )
348- }
349- if signer == nil {
350- user := url .UserPassword (vc .Config .Username , vc .Config .Password )
351- err = restClient .Login (ctx , user )
352- } else {
353- err = restClient .LoginByToken (restClient .WithSigner (ctx , signer ))
354- }
355- if err != nil {
356- return nil , fmt .Errorf ("failed to login for the rest client. Error: %v" , err )
357- }
358- tagManager := tags .NewManager (restClient )
359- if tagManager == nil {
360- return nil , fmt .Errorf ("failed to create a tagManager" )
361- }
362- log .Infof ("New tag manager with useragent '%s'" , tagManager .UserAgent )
363- return tagManager , nil
364- }
365-
366311// GetCandidateDatastoresInClusters gets the shared datastores and vSAN-direct
367312// managed datastores of given VC clusters from GetCandidateDatastoresInCluster and
368313// returns a map of clusterID -> array of datastores
0 commit comments