in pkg/common/config/config_yaml.go [92:196]
func (ccy *CommonConfigYAML) validateConfig() error {
//Fix default global values
if ccy.Global.RoundTripperCount == 0 {
ccy.Global.RoundTripperCount = DefaultRoundTripperCount
}
if ccy.Global.VCenterPort == 0 {
ccy.Global.VCenterPort = DefaultVCenterPort
}
if ccy.Global.APIBinding == "" {
ccy.Global.APIBinding = DefaultAPIBinding
}
if len(ccy.Global.IPFamilyPriority) == 0 {
ccy.Global.IPFamilyPriority = []string{DefaultIPFamily}
}
// Create a single instance of VSphereInstance for the Global VCenterIP if the
// VirtualCenter does not already exist in the map
if ccy.Global.VCenterIP != "" && ccy.Vcenter[ccy.Global.VCenterIP] == nil {
ccy.Vcenter[ccy.Global.VCenterIP] = &VirtualCenterConfigYAML{
User: ccy.Global.User,
Password: ccy.Global.Password,
TenantRef: ccy.Global.VCenterIP,
VCenterIP: ccy.Global.VCenterIP,
VCenterPort: ccy.Global.VCenterPort,
InsecureFlag: ccy.Global.InsecureFlag,
Datacenters: ccy.Global.Datacenters,
RoundTripperCount: ccy.Global.RoundTripperCount,
CAFile: ccy.Global.CAFile,
Thumbprint: ccy.Global.Thumbprint,
SecretRef: DefaultCredentialManager,
SecretName: ccy.Global.SecretName,
SecretNamespace: ccy.Global.SecretNamespace,
IPFamilyPriority: ccy.Global.IPFamilyPriority,
}
}
// Must have at least one vCenter defined
if len(ccy.Vcenter) == 0 {
klog.Error(ErrMissingVCenter)
return ErrMissingVCenter
}
// vsphere.conf is no longer supported in the old format.
for tenantRef, vcConfig := range ccy.Vcenter {
klog.V(4).Infof("Initializing vc server %s", tenantRef)
if vcConfig.VCenterIP == "" {
klog.Error(ErrInvalidVCenterIP)
return ErrInvalidVCenterIP
}
// in the YAML-based config, the tenant ref is required in the config
vcConfig.TenantRef = tenantRef
if !ccy.isSecretInfoProvided() && !vcConfig.isSecretInfoProvided() {
if vcConfig.User == "" {
vcConfig.User = ccy.Global.User
if vcConfig.User == "" {
klog.Errorf("vcConfig.User is empty for vc %s!", tenantRef)
return ErrUsernameMissing
}
}
if vcConfig.Password == "" {
vcConfig.Password = ccy.Global.Password
if vcConfig.Password == "" {
klog.Errorf("vcConfig.Password is empty for vc %s!", tenantRef)
return ErrPasswordMissing
}
}
} else if ccy.isSecretInfoProvided() && !vcConfig.isSecretInfoProvided() {
vcConfig.SecretRef = DefaultCredentialManager
} else if vcConfig.isSecretInfoProvided() {
vcConfig.SecretRef = vcConfig.SecretNamespace + "/" + vcConfig.SecretName
}
if vcConfig.VCenterPort == 0 {
vcConfig.VCenterPort = ccy.Global.VCenterPort
}
if len(vcConfig.Datacenters) == 0 {
if len(ccy.Global.Datacenters) != 0 {
vcConfig.Datacenters = ccy.Global.Datacenters
}
}
if vcConfig.RoundTripperCount == 0 {
vcConfig.RoundTripperCount = ccy.Global.RoundTripperCount
}
if vcConfig.CAFile == "" {
vcConfig.CAFile = ccy.Global.CAFile
}
if vcConfig.Thumbprint == "" {
vcConfig.Thumbprint = ccy.Global.Thumbprint
}
if len(vcConfig.IPFamilyPriority) == 0 {
vcConfig.IPFamilyPriority = ccy.Global.IPFamilyPriority
}
insecure := vcConfig.InsecureFlag
if !insecure {
vcConfig.InsecureFlag = ccy.Global.InsecureFlag
}
}
return nil
}