Skip to content

Commit

Permalink
Merge pull request #405 from dantingl/nsx_connection
Browse files Browse the repository at this point in the history
Move nsxt connection part to a separate dir
  • Loading branch information
k8s-ci-robot authored Dec 1, 2020
2 parents 3f4e55e + ef7006c commit de7c878
Show file tree
Hide file tree
Showing 19 changed files with 628 additions and 295 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/prometheus/client_golang v1.7.1
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.4.0
github.com/vmware/govmomi v0.22.1
github.com/vmware/vsphere-automation-sdk-go/lib v0.2.0
github.com/vmware/vsphere-automation-sdk-go/runtime v0.2.0
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ github.com/go-openapi/analysis v0.19.2/go.mod h1:3P1osvZa9jKjb8ed2TPng3f0i/UY9sn
github.com/go-openapi/analysis v0.19.5/go.mod h1:hkEAkxagaIvIP7VTn8ygJNkd4kAYON2rCu0v0ObL0AU=
github.com/go-openapi/errors v0.17.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0=
github.com/go-openapi/errors v0.18.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0=
github.com/go-openapi/errors v0.19.2 h1:a2kIyV3w+OS3S97zxUndRVD46+FhGOUBDFY7nmu4CsY=
github.com/go-openapi/errors v0.19.2/go.mod h1:qX0BLWsyaKfvhluLejVpVNwNRdXZhEbTA4kxxpKBC94=
github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0=
github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M=
Expand Down Expand Up @@ -439,6 +440,7 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
Expand Down Expand Up @@ -504,6 +506,7 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/thecodeteam/goscaleio v0.1.0/go.mod h1:68sdkZAsK8bvEwBlbQnlLS+xU+hvLYM/iQ8KXej1AwM=
Expand Down Expand Up @@ -590,6 +593,7 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -708,9 +712,12 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200410194907-79a7a3126eef/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200616133436-c1934b75d054 h1:HHeAlu5H9b71C+Fx0K+1dGgVFN1DM1/wz4aoGOA5qS8=
golang.org/x/tools v0.0.0-20200616133436-c1934b75d054/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0=
Expand Down Expand Up @@ -796,7 +803,10 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.6 h1:W18jzjh8mfPez+AwGLxmOImucz/IFjpNlrKVnaj2YVc=
honnef.co/go/tools v0.0.1-2020.1.6/go.mod h1:pyyisuGw24ruLjrr1ddx39WE0y9OooInRzEYLhQB2YY=
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/gengo v0.0.0-20200428234225-8167cfdcfc14/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/heapster v1.2.0-beta.1/go.mod h1:h1uhptVXMwC8xtZBYsPXKVi8fpdlYkTs6k949KozGrM=
Expand Down
37 changes: 0 additions & 37 deletions pkg/cloudprovider/vsphere/loadbalancer/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package config

import (
"fmt"
"os"
"strconv"

"k8s.io/klog"
)
Expand All @@ -42,41 +40,6 @@ func (cfg *LoadBalancerConfig) IsEmpty() bool {
cfg.Tier1GatewayPath == ""
}

// FromEnv initializes the provided configuration object with values
// obtained from environment variables. If an environment variable is set
// for a property that's already initialized, the environment variable's value
// takes precedence.
func (cfg *NsxtConfig) FromEnv() error {
if v := os.Getenv("NSXT_MANAGER_HOST"); v != "" {
cfg.Host = v
}
if v := os.Getenv("NSXT_USERNAME"); v != "" {
cfg.User = v
}
if v := os.Getenv("NSXT_PASSWORD"); v != "" {
cfg.Password = v
}
if v := os.Getenv("NSXT_ALLOW_UNVERIFIED_SSL"); v != "" {
InsecureFlag, err := strconv.ParseBool(v)
if err != nil {
klog.Errorf("Failed to parse NSXT_ALLOW_UNVERIFIED_SSL: %s", err)
return fmt.Errorf("Failed to parse NSXT_ALLOW_UNVERIFIED_SSL: %s", err)
}
cfg.InsecureFlag = InsecureFlag
}
if v := os.Getenv("NSXT_CLIENT_AUTH_CERT_FILE"); v != "" {
cfg.ClientAuthCertFile = v
}
if v := os.Getenv("NSXT_CLIENT_AUTH_KEY_FILE"); v != "" {
cfg.ClientAuthKeyFile = v
}
if v := os.Getenv("NSXT_CA_FILE"); v != "" {
cfg.CAFile = v
}

return nil
}

/*
TODO:
When the INI based cloud-config is deprecated, the references to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (lbc *LBConfigINI) validateConfig() error {
return fmt.Errorf(msg)
}
}
return lbc.NSXT.validateConfig()
return lbc.NSXT.ValidateConfig()
}

func (lbc *LoadBalancerConfigINI) isEmpty() bool {
Expand All @@ -130,32 +130,6 @@ func (lbc *LoadBalancerConfigINI) isEmpty() bool {
lbc.Tier1GatewayPath == ""
}

func (lbc *NsxtConfigINI) validateConfig() error {
if lbc.VMCAccessToken != "" {
if lbc.VMCAuthHost == "" {
msg := "vmc auth host must be provided if auth token is provided"
klog.Errorf(msg)
return fmt.Errorf(msg)
}
} else if lbc.User != "" {
if lbc.Password == "" {
msg := "password is empty"
klog.Errorf(msg)
return fmt.Errorf(msg)
}
} else {
msg := "either user or vmc access token must be set"
klog.Errorf(msg)
return fmt.Errorf(msg)
}
if lbc.Host == "" {
msg := "host is empty"
klog.Errorf(msg)
return fmt.Errorf(msg)
}
return nil
}

// CompleteAndValidate sets default values, overrides by env and validates the resulting config
func (lbc *LBConfigINI) CompleteAndValidate() error {
if !lbc.isEnabled() {
Expand Down
28 changes: 1 addition & 27 deletions pkg/cloudprovider/vsphere/loadbalancer/config/config_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (lbc *LBConfigYAML) validateConfig() error {
return fmt.Errorf(msg)
}
}
return lbc.NSXT.validateConfig()
return lbc.NSXT.ValidateConfig()
}

func (lbc *LoadBalancerConfigYAML) isEmpty() bool {
Expand All @@ -129,32 +129,6 @@ func (lbc *LoadBalancerConfigYAML) isEmpty() bool {
lbc.Tier1GatewayPath == ""
}

func (lbc *NsxtConfigYAML) validateConfig() error {
if lbc.VMCAccessToken != "" {
if lbc.VMCAuthHost == "" {
msg := "vmc auth host must be provided if auth token is provided"
klog.Errorf(msg)
return fmt.Errorf(msg)
}
} else if lbc.User != "" {
if lbc.Password == "" {
msg := "password is empty"
klog.Errorf(msg)
return fmt.Errorf(msg)
}
} else {
msg := "either user or vmc access token must be set"
klog.Errorf(msg)
return fmt.Errorf(msg)
}
if lbc.Host == "" {
msg := "host is empty"
klog.Errorf(msg)
return fmt.Errorf(msg)
}
return nil
}

// CompleteAndValidate sets default values, overrides by env and validates the resulting config
func (lbc *LBConfigYAML) CompleteAndValidate() error {
if !lbc.isEnabled() {
Expand Down
26 changes: 5 additions & 21 deletions pkg/cloudprovider/vsphere/loadbalancer/config/types_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@

package config

import (
nsxtcfg "k8s.io/cloud-provider-vsphere/pkg/nsxt/config"
)

// LBConfig is used to read and store information from the cloud configuration file
type LBConfig struct {
LoadBalancer LoadBalancerConfig
LoadBalancerClass map[string]*LoadBalancerClassConfig
NSXT NsxtConfig
NSXT nsxtcfg.NsxtConfig
}

// LoadBalancerConfig contains the configuration for the load balancer itself
Expand All @@ -41,23 +45,3 @@ type LoadBalancerClassConfig struct {
UDPAppProfileName string
UDPAppProfilePath string
}

// NsxtConfig contains the NSX-T specific configuration
type NsxtConfig struct {
// NSX-T username.
User string
// NSX-T password in clear text.
Password string
// NSX-T host.
Host string
// InsecureFlag is to be set to true if NSX-T uses self-signed cert.
InsecureFlag bool
// RemoteAuth is to be set to true if NSX-T uses remote authentication (authentication done through the vIDM).
RemoteAuth bool

VMCAccessToken string
VMCAuthHost string
ClientAuthCertFile string
ClientAuthKeyFile string
CAFile string
}
26 changes: 5 additions & 21 deletions pkg/cloudprovider/vsphere/loadbalancer/config/types_ini_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@

package config

import (
nsxtcfg "k8s.io/cloud-provider-vsphere/pkg/nsxt/config"
)

// LBConfigINI is used to read and store information from the cloud configuration file
type LBConfigINI struct {
LoadBalancer LoadBalancerConfigINI `gcfg:"loadbalancer"`
LoadBalancerClass map[string]*LoadBalancerClassConfigINI `gcfg:"loadbalancerclass"`
NSXT NsxtConfigINI `gcfg:"nsxt"`
NSXT nsxtcfg.NsxtConfigINI `gcfg:"nsxt"`
}

// LoadBalancerConfigINI contains the configuration for the load balancer itself
Expand All @@ -42,23 +46,3 @@ type LoadBalancerClassConfigINI struct {
UDPAppProfileName string `gcfg:"udp-app-profile-name"`
UDPAppProfilePath string `gcfg:"udp-app-profile-path"`
}

// NsxtConfigINI contains the NSX-T specific configuration
type NsxtConfigINI struct {
// NSX-T username.
User string `gcfg:"user"`
// NSX-T password in clear text.
Password string `gcfg:"password"`
// NSX-T host.
Host string `gcfg:"host"`
// InsecureFlag is to be set to true if NSX-T uses self-signed cert.
InsecureFlag bool `gcfg:"insecure-flag"`
// RemoteAuth is to be set to true if NSX-T uses remote authentication (authentication done through the vIDM).
RemoteAuth bool `gcfg:"remote-auth"`

VMCAccessToken string `gcfg:"vmc-access-token"`
VMCAuthHost string `gcfg:"vmc-auth-host"`
ClientAuthCertFile string `gcfg:"client-auth-cert-file"`
ClientAuthKeyFile string `gcfg:"client-auth-key-file"`
CAFile string `gcfg:"ca-file"`
}
26 changes: 5 additions & 21 deletions pkg/cloudprovider/vsphere/loadbalancer/config/types_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package config

import (
nsxtcfg "k8s.io/cloud-provider-vsphere/pkg/nsxt/config"
)

/*
TODO:
When the INI based cloud-config is deprecated, this file should be renamed
Expand All @@ -31,7 +35,7 @@ package config
type LBConfigYAML struct {
LoadBalancer LoadBalancerConfigYAML `yaml:"loadBalancer"`
LoadBalancerClass map[string]*LoadBalancerClassConfigYAML `yaml:"loadBalancerClass"`
NSXT NsxtConfigYAML `yaml:"nsxt"`
NSXT nsxtcfg.NsxtConfigYAML `yaml:"nsxt"`
}

// LoadBalancerConfigYAML contains the configuration for the load balancer itself
Expand Down Expand Up @@ -60,23 +64,3 @@ type LoadBalancerClassConfigYAML struct {
UDPAppProfileName string `yaml:"udpAppProfileName"`
UDPAppProfilePath string `yaml:"udpAppProfilePath"`
}

// NsxtConfigYAML contains the NSX-T specific configuration
type NsxtConfigYAML struct {
// NSX-T username.
User string `yaml:"user"`
// NSX-T password in clear text.
Password string `yaml:"password"`
// NSX-T host.
Host string `yaml:"host"`
// InsecureFlag is to be set to true if NSX-T uses self-signed cert.
InsecureFlag bool `yaml:"insecureFlag"`
// RemoteAuth is to be set to true if NSX-T uses remote authentication (authentication done through the vIDM).
RemoteAuth bool `yaml:"remoteAuth"`

VMCAccessToken string `yaml:"vmcAccessToken"`
VMCAuthHost string `yaml:"vmcAuthHost"`
ClientAuthCertFile string `yaml:"clientAuthCertFile"`
ClientAuthKeyFile string `yaml:"clientAuthKeyFile"`
CAFile string `yaml:"caFile"`
}
Loading

0 comments on commit de7c878

Please sign in to comment.