mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 13:55:41 +00:00
Introduce thumbprints per vcenter
This commit is contained in:
parent
795e4c4254
commit
b83028325c
@ -43,6 +43,7 @@ type VSphereConnection struct {
|
|||||||
Hostname string
|
Hostname string
|
||||||
Port string
|
Port string
|
||||||
CACert string
|
CACert string
|
||||||
|
Thumbprint string
|
||||||
Insecure bool
|
Insecure bool
|
||||||
RoundTripperCount uint
|
RoundTripperCount uint
|
||||||
credentialsLock sync.Mutex
|
credentialsLock sync.Mutex
|
||||||
|
@ -103,6 +103,8 @@ type VirtualCenterConfig struct {
|
|||||||
Datacenters string `gcfg:"datacenters"`
|
Datacenters string `gcfg:"datacenters"`
|
||||||
// Soap round tripper count (retries = RoundTripper - 1)
|
// Soap round tripper count (retries = RoundTripper - 1)
|
||||||
RoundTripperCount uint `gcfg:"soap-roundtrip-count"`
|
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.
|
// 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
|
// Specifies the path to a CA certificate in PEM format. Optional; if not
|
||||||
// configured, the system's CA certificates will be used.
|
// configured, the system's CA certificates will be used.
|
||||||
CAFile string `gcfg:"ca-file"`
|
CAFile string `gcfg:"ca-file"`
|
||||||
|
// Thumbprint of the VCenter's certificate thumbprint
|
||||||
|
Thumbprint string `gcfg:"thumbprint"`
|
||||||
// Datacenter in which VMs are located.
|
// Datacenter in which VMs are located.
|
||||||
// Deprecated. Use "datacenters" instead.
|
// Deprecated. Use "datacenters" instead.
|
||||||
Datacenter string `gcfg:"datacenter"`
|
Datacenter string `gcfg:"datacenter"`
|
||||||
@ -337,6 +341,7 @@ func populateVsphereInstanceMap(cfg *VSphereConfig) (map[string]*VSphereInstance
|
|||||||
VCenterPort: cfg.Global.VCenterPort,
|
VCenterPort: cfg.Global.VCenterPort,
|
||||||
Datacenters: cfg.Global.Datacenter,
|
Datacenters: cfg.Global.Datacenter,
|
||||||
RoundTripperCount: cfg.Global.RoundTripperCount,
|
RoundTripperCount: cfg.Global.RoundTripperCount,
|
||||||
|
Thumbprint: cfg.Global.Thumbprint,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: If secrets info is provided username and password will be populated
|
// 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,
|
RoundTripperCount: vcConfig.RoundTripperCount,
|
||||||
Port: vcConfig.VCenterPort,
|
Port: vcConfig.VCenterPort,
|
||||||
CACert: cfg.Global.CAFile,
|
CACert: cfg.Global.CAFile,
|
||||||
|
Thumbprint: cfg.Global.Thumbprint,
|
||||||
}
|
}
|
||||||
|
|
||||||
vsphereIns := VSphereInstance{
|
vsphereIns := VSphereInstance{
|
||||||
@ -422,6 +428,7 @@ func populateVsphereInstanceMap(cfg *VSphereConfig) (map[string]*VSphereInstance
|
|||||||
Insecure: cfg.Global.InsecureFlag,
|
Insecure: cfg.Global.InsecureFlag,
|
||||||
RoundTripperCount: vcConfig.RoundTripperCount,
|
RoundTripperCount: vcConfig.RoundTripperCount,
|
||||||
Port: vcConfig.VCenterPort,
|
Port: vcConfig.VCenterPort,
|
||||||
|
Thumbprint: vcConfig.Thumbprint,
|
||||||
}
|
}
|
||||||
vsphereIns := VSphereInstance{
|
vsphereIns := VSphereInstance{
|
||||||
conn: &vSphereConn,
|
conn: &vSphereConn,
|
||||||
|
@ -430,6 +430,7 @@ func TestSecretVSphereConfig(t *testing.T) {
|
|||||||
expectedUsername string
|
expectedUsername string
|
||||||
expectedPassword string
|
expectedPassword string
|
||||||
expectedError error
|
expectedError error
|
||||||
|
expectedThumbprints map[string]string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
testName: "Username and password with old configuration",
|
testName: "Username and password with old configuration",
|
||||||
@ -599,6 +600,47 @@ func TestSecretVSphereConfig(t *testing.T) {
|
|||||||
expectedIsSecretProvided: true,
|
expectedIsSecretProvided: true,
|
||||||
expectedError: nil,
|
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 {
|
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",
|
t.Fatalf("Expected password %s doesn't match actual password %s in config %s. error: %s",
|
||||||
testcase.expectedPassword, vsInstance.conn.Password, testcase.conf, err)
|
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