mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 04:27:54 +00:00
Introduce thumbprints per vcenter
This commit is contained in:
parent
795e4c4254
commit
b83028325c
@ -43,6 +43,7 @@ type VSphereConnection struct {
|
||||
Hostname string
|
||||
Port string
|
||||
CACert string
|
||||
Thumbprint string
|
||||
Insecure bool
|
||||
RoundTripperCount uint
|
||||
credentialsLock sync.Mutex
|
||||
|
@ -103,6 +103,8 @@ type VirtualCenterConfig struct {
|
||||
Datacenters string `gcfg:"datacenters"`
|
||||
// Soap round tripper count (retries = RoundTripper - 1)
|
||||
RoundTripperCount uint `gcfg:"soap-roundtrip-count"`
|
||||
// Thumbprint of the VCenter's certificate thumbprint
|
||||
Thumbprint string `gcfg:"thumbprint"`
|
||||
}
|
||||
|
||||
// Structure that represents the content of vsphere.conf file.
|
||||
@ -124,6 +126,8 @@ type VSphereConfig struct {
|
||||
// Specifies the path to a CA certificate in PEM format. Optional; if not
|
||||
// configured, the system's CA certificates will be used.
|
||||
CAFile string `gcfg:"ca-file"`
|
||||
// Thumbprint of the VCenter's certificate thumbprint
|
||||
Thumbprint string `gcfg:"thumbprint"`
|
||||
// Datacenter in which VMs are located.
|
||||
// Deprecated. Use "datacenters" instead.
|
||||
Datacenter string `gcfg:"datacenter"`
|
||||
@ -337,6 +341,7 @@ func populateVsphereInstanceMap(cfg *VSphereConfig) (map[string]*VSphereInstance
|
||||
VCenterPort: cfg.Global.VCenterPort,
|
||||
Datacenters: cfg.Global.Datacenter,
|
||||
RoundTripperCount: cfg.Global.RoundTripperCount,
|
||||
Thumbprint: cfg.Global.Thumbprint,
|
||||
}
|
||||
|
||||
// Note: If secrets info is provided username and password will be populated
|
||||
@ -349,6 +354,7 @@ func populateVsphereInstanceMap(cfg *VSphereConfig) (map[string]*VSphereInstance
|
||||
RoundTripperCount: vcConfig.RoundTripperCount,
|
||||
Port: vcConfig.VCenterPort,
|
||||
CACert: cfg.Global.CAFile,
|
||||
Thumbprint: cfg.Global.Thumbprint,
|
||||
}
|
||||
|
||||
vsphereIns := VSphereInstance{
|
||||
@ -422,6 +428,7 @@ func populateVsphereInstanceMap(cfg *VSphereConfig) (map[string]*VSphereInstance
|
||||
Insecure: cfg.Global.InsecureFlag,
|
||||
RoundTripperCount: vcConfig.RoundTripperCount,
|
||||
Port: vcConfig.VCenterPort,
|
||||
Thumbprint: vcConfig.Thumbprint,
|
||||
}
|
||||
vsphereIns := VSphereInstance{
|
||||
conn: &vSphereConn,
|
||||
|
@ -430,6 +430,7 @@ func TestSecretVSphereConfig(t *testing.T) {
|
||||
expectedUsername string
|
||||
expectedPassword string
|
||||
expectedError error
|
||||
expectedThumbprints map[string]string
|
||||
}{
|
||||
{
|
||||
testName: "Username and password with old configuration",
|
||||
@ -599,6 +600,47 @@ func TestSecretVSphereConfig(t *testing.T) {
|
||||
expectedIsSecretProvided: true,
|
||||
expectedError: nil,
|
||||
},
|
||||
{
|
||||
testName: "virtual centers with a thumbprint",
|
||||
conf: `[Global]
|
||||
server = global
|
||||
user = user
|
||||
password = password
|
||||
datacenter = us-west
|
||||
thumbprint = "thumbprint:global"
|
||||
working-dir = kubernetes
|
||||
`,
|
||||
expectedUsername: username,
|
||||
expectedPassword: password,
|
||||
expectedError: nil,
|
||||
expectedThumbprints: map[string]string{
|
||||
"global": "thumbprint:global",
|
||||
},
|
||||
},
|
||||
{
|
||||
testName: "Multiple virtual centers with different thumbprints",
|
||||
conf: `[Global]
|
||||
user = user
|
||||
password = password
|
||||
datacenter = us-west
|
||||
[VirtualCenter "0.0.0.0"]
|
||||
thumbprint = thumbprint:0
|
||||
[VirtualCenter "no_thumbprint"]
|
||||
[VirtualCenter "1.1.1.1"]
|
||||
thumbprint = thumbprint:1
|
||||
[Workspace]
|
||||
server = 0.0.0.0
|
||||
datacenter = us-west
|
||||
folder = kubernetes
|
||||
`,
|
||||
expectedUsername: username,
|
||||
expectedPassword: password,
|
||||
expectedError: nil,
|
||||
expectedThumbprints: map[string]string{
|
||||
"0.0.0.0": "thumbprint:0",
|
||||
"1.1.1.1": "thumbprint:1",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testcase := range testcases {
|
||||
@ -628,9 +670,19 @@ func TestSecretVSphereConfig(t *testing.T) {
|
||||
t.Fatalf("Expected password %s doesn't match actual password %s in config %s. error: %s",
|
||||
testcase.expectedPassword, vsInstance.conn.Password, testcase.conf, err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for instanceName, expectedThumbprint := range testcase.expectedThumbprints {
|
||||
instanceConfig, ok := vs.vsphereInstanceMap[instanceName]
|
||||
if !ok {
|
||||
t.Fatalf("Could not find configuration for instance %s", instanceName)
|
||||
}
|
||||
if actualThumbprint := instanceConfig.conn.Thumbprint; actualThumbprint != expectedThumbprint {
|
||||
t.Fatalf(
|
||||
"Expected thumbprint for instance '%s' to be '%s', got '%s'",
|
||||
instanceName, expectedThumbprint, actualThumbprint,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user