mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Rename new configs to cloudConfigType and cloudConfigScope
This commit is contained in:
parent
be3eeb296f
commit
5461d48fa5
@ -160,10 +160,10 @@ type Config struct {
|
|||||||
// Maximum allowed LoadBalancer Rule Count is the limit enforced by Azure Load balancer
|
// Maximum allowed LoadBalancer Rule Count is the limit enforced by Azure Load balancer
|
||||||
MaximumLoadBalancerRuleCount int `json:"maximumLoadBalancerRuleCount,omitempty" yaml:"maximumLoadBalancerRuleCount,omitempty"`
|
MaximumLoadBalancerRuleCount int `json:"maximumLoadBalancerRuleCount,omitempty" yaml:"maximumLoadBalancerRuleCount,omitempty"`
|
||||||
|
|
||||||
// The configure type for Azure cloud provider secret.
|
// The cloud configure type for Azure cloud provider. Supported values are file, secret and merge.
|
||||||
ConfigType secretConfigureType `json:"configType,omitempty" yaml:"configType,omitempty"`
|
CloudConfigType cloudConfigType `json:"cloudConfigType,omitempty" yaml:"cloudConfigType,omitempty"`
|
||||||
// The override type for Azure cloud provider secret.
|
// The cloud config scope for Azure cloud provider. Supported values are all, node and control-plane.
|
||||||
OverrideType secretOverrideType `json:"overrideType,omitempty" yaml:"overrideType,omitempty"`
|
CloudConfigScope cloudConfigScope `json:"cloudConfigScope,omitempty" yaml:"cloudConfigScope,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ cloudprovider.Interface = (*Cloud)(nil)
|
var _ cloudprovider.Interface = (*Cloud)(nil)
|
||||||
@ -273,29 +273,29 @@ func (az *Cloud) InitializeCloudFromConfig(config *Config, fromSecret bool) erro
|
|||||||
config.VMType = vmTypeStandard
|
config.VMType = vmTypeStandard
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.OverrideType == "" {
|
if config.CloudConfigType == "" {
|
||||||
// The default override type is secretOverrideTypeCan.
|
// The default cloud config type is cloudConfigTypeMerge.
|
||||||
config.OverrideType = secretOverrideTypeCan
|
config.CloudConfigType = cloudConfigTypeMerge
|
||||||
} else {
|
} else {
|
||||||
supportedOverrideTypes := sets.NewString(
|
supportedCloudConfigTypes := sets.NewString(
|
||||||
string(secretOverrideTypeCan),
|
string(cloudConfigTypeMerge),
|
||||||
string(secretOverrideTypeMust),
|
string(cloudConfigTypeFile),
|
||||||
string(secretOverrideTypeNo))
|
string(cloudConfigTypeSecret))
|
||||||
if !supportedOverrideTypes.Has(string(config.OverrideType)) {
|
if !supportedCloudConfigTypes.Has(string(config.CloudConfigType)) {
|
||||||
return fmt.Errorf("overrideType %v is not supported, supported values are %v", config.OverrideType, supportedOverrideTypes.List())
|
return fmt.Errorf("cloudConfigType %v is not supported, supported values are %v", config.CloudConfigType, supportedCloudConfigTypes.List())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.ConfigType == "" {
|
if config.CloudConfigScope == "" {
|
||||||
// The default config type is secretConfigureAll.
|
// The default config scope is cloudConfigScopeAll.
|
||||||
config.ConfigType = secretConfigureAll
|
config.CloudConfigScope = cloudConfigScopeAll
|
||||||
} else {
|
} else {
|
||||||
supportedConfigTypes := sets.NewString(
|
supportedCloudConfigScopes := sets.NewString(
|
||||||
string(secretConfigureAll),
|
string(cloudConfigScopeAll),
|
||||||
string(secretConfigureNode),
|
string(cloudConfigScopeNode),
|
||||||
string(secretConfigureControlPlane))
|
string(cloudConfigScopeControlPlane))
|
||||||
if !supportedConfigTypes.Has(string(config.ConfigType)) {
|
if !supportedCloudConfigScopes.Has(string(config.CloudConfigScope)) {
|
||||||
return fmt.Errorf("configType %v is not supported, supported values are %v", config.ConfigType, supportedConfigTypes.List())
|
return fmt.Errorf("cloudConfigScope %v is not supported, supported values are %v", config.CloudConfigScope, supportedCloudConfigScopes.List())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,13 +324,13 @@ func (az *Cloud) InitializeCloudFromConfig(config *Config, fromSecret bool) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Credentials are required if override type is "no".
|
// Credentials are required if cloud config type is "file".
|
||||||
if az.Config.OverrideType == secretOverrideTypeNo {
|
if az.Config.CloudConfigType == cloudConfigTypeFile {
|
||||||
return fmt.Errorf("no credentials provided for Azure cloud provider")
|
return fmt.Errorf("no credentials provided for Azure cloud provider")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Controller manager could be initialized from secret.
|
// Controller manager could be initialized from secret.
|
||||||
klog.V(2).Infof("No credentials provided, lazy initialize from secret %s", getConfigSecretName(az.Config.ConfigType))
|
klog.V(2).Infof("No credentials provided, lazy initialize from secret %s", getConfigSecretName(az.Config.CloudConfigScope))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,37 +25,37 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
secretNamespace = "kube-system"
|
cloudConfigNamespace = "kube-system"
|
||||||
secretCloudConfigKey = "cloud-config"
|
cloudConfigKey = "cloud-config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The configure type for Azure cloud provider secret. Supported values are:
|
// The configure scope for Azure cloud provider secret. Supported values are:
|
||||||
// * all : configure applied for components (kubelet and controller-manager). This is the default value.
|
// * all : configure applied for components (kubelet and controller-manager). This is the default value.
|
||||||
// * node : configure applied for nodes (kubelet).
|
// * node : configure applied for nodes (kubelet).
|
||||||
// * control-plane : configure applied for control plane components (controller-manager).
|
// * control-plane : configure applied for control plane components (controller-manager).
|
||||||
//
|
//
|
||||||
// For different configure types, the secret name would also be different:
|
// For different configure scope, the secret name would also be different:
|
||||||
// * all : secret name would be azure-cloud-provider.
|
// * all : secret name would be azure-cloud-provider.
|
||||||
// * node : secret name would azure-cloud-provider-node.
|
// * node : secret name would azure-cloud-provider-node.
|
||||||
// * control-plane : secret name would be azure-cloud-provider-control-plane.
|
// * control-plane : secret name would be azure-cloud-provider-control-plane.
|
||||||
type secretConfigureType string
|
type cloudConfigScope string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
secretConfigureAll secretConfigureType = "all"
|
cloudConfigScopeAll cloudConfigScope = "all"
|
||||||
secretConfigureNode secretConfigureType = "node"
|
cloudConfigScopeNode cloudConfigScope = "node"
|
||||||
secretConfigureControlPlane secretConfigureType = "control-plane"
|
cloudConfigScopeControlPlane cloudConfigScope = "control-plane"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The override type for Azure cloud provider secret. Supported values are:
|
// The config type for Azure cloud provider secret. Supported values are:
|
||||||
// * no : The values from secret won't override any configures from local cloud-config file.
|
// * file : The values are read from local cloud-config file.
|
||||||
// * must : The values from secret would override all configures from local cloud-config file.
|
// * secret : The values from secret would override all configures from local cloud-config file.
|
||||||
// * can : The values from secret would override only configurations that are explicitly set in the secret. This is the default value.
|
// * merge : The values from secret would override only configurations that are explicitly set in the secret. This is the default value.
|
||||||
type secretOverrideType string
|
type cloudConfigType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
secretOverrideTypeNo secretOverrideType = "no"
|
cloudConfigTypeFile cloudConfigType = "file"
|
||||||
secretOverrideTypeMust secretOverrideType = "must"
|
cloudConfigTypeSecret cloudConfigType = "secret"
|
||||||
secretOverrideTypeCan secretOverrideType = "can"
|
cloudConfigTypeMerge cloudConfigType = "merge"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InitializeCloudFromSecret initializes Azure cloud provider from Kubernetes secret.
|
// InitializeCloudFromSecret initializes Azure cloud provider from Kubernetes secret.
|
||||||
@ -77,25 +77,25 @@ func (az *Cloud) InitializeCloudFromSecret() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (az *Cloud) getConfigFromSecret() (*Config, error) {
|
func (az *Cloud) getConfigFromSecret() (*Config, error) {
|
||||||
// No override, return nil.
|
// Read config from file and no override, return nil.
|
||||||
if az.Config.OverrideType == secretOverrideTypeNo {
|
if az.Config.CloudConfigType == cloudConfigTypeFile {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
secretName := getConfigSecretName(az.Config.ConfigType)
|
secretName := getConfigSecretName(az.Config.CloudConfigScope)
|
||||||
secret, err := az.kubeClient.CoreV1().Secrets(secretNamespace).Get(secretName, metav1.GetOptions{})
|
secret, err := az.kubeClient.CoreV1().Secrets(cloudConfigNamespace).Get(secretName, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to get secret %s: %v", secretName, err)
|
return nil, fmt.Errorf("Failed to get secret %s: %v", secretName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cloudConfigData, ok := secret.Data[secretCloudConfigKey]
|
cloudConfigData, ok := secret.Data[cloudConfigKey]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("cloud-config is not set in the secret (%s)", secretName)
|
return nil, fmt.Errorf("cloud-config is not set in the secret (%s)", secretName)
|
||||||
}
|
}
|
||||||
|
|
||||||
config := Config{}
|
config := Config{}
|
||||||
if az.Config.OverrideType == "" || az.Config.OverrideType == secretOverrideTypeCan {
|
if az.Config.CloudConfigType == "" || az.Config.CloudConfigType == cloudConfigTypeMerge {
|
||||||
// "can" override, set default value to existing config.
|
// Merge cloud config, set default value to existing config.
|
||||||
config = az.Config
|
config = az.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,13 +107,13 @@ func (az *Cloud) getConfigFromSecret() (*Config, error) {
|
|||||||
return &config, nil
|
return &config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConfigSecretName(configType secretConfigureType) string {
|
func getConfigSecretName(scope cloudConfigScope) string {
|
||||||
switch configType {
|
switch scope {
|
||||||
case secretConfigureAll:
|
case cloudConfigScopeAll:
|
||||||
return azureSecretNamePrefix
|
return azureSecretNamePrefix
|
||||||
case secretConfigureNode:
|
case cloudConfigScopeNode:
|
||||||
return fmt.Sprintf("%s-node", azureSecretNamePrefix)
|
return fmt.Sprintf("%s-node", azureSecretNamePrefix)
|
||||||
case secretConfigureControlPlane:
|
case cloudConfigScopeControlPlane:
|
||||||
return fmt.Sprintf("%s-control-plane", azureSecretNamePrefix)
|
return fmt.Sprintf("%s-control-plane", azureSecretNamePrefix)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -50,7 +50,7 @@ func getTestConfig() *Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTestMustOverrideConfig() *Config {
|
func getTestCloudConfigTypeSecretConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
AzureAuthConfig: auth.AzureAuthConfig{
|
AzureAuthConfig: auth.AzureAuthConfig{
|
||||||
TenantID: "TenantID",
|
TenantID: "TenantID",
|
||||||
@ -60,11 +60,11 @@ func getTestMustOverrideConfig() *Config {
|
|||||||
RouteTableName: "RouteTableName",
|
RouteTableName: "RouteTableName",
|
||||||
RouteTableResourceGroup: "RouteTableResourceGroup",
|
RouteTableResourceGroup: "RouteTableResourceGroup",
|
||||||
SecurityGroupName: "SecurityGroupName",
|
SecurityGroupName: "SecurityGroupName",
|
||||||
OverrideType: secretOverrideTypeMust,
|
CloudConfigType: cloudConfigTypeSecret,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTestCanOverrideConfig() *Config {
|
func getTestCloudConfigTypeMergeConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
AzureAuthConfig: auth.AzureAuthConfig{
|
AzureAuthConfig: auth.AzureAuthConfig{
|
||||||
TenantID: "TenantID",
|
TenantID: "TenantID",
|
||||||
@ -74,14 +74,14 @@ func getTestCanOverrideConfig() *Config {
|
|||||||
RouteTableName: "RouteTableName",
|
RouteTableName: "RouteTableName",
|
||||||
RouteTableResourceGroup: "RouteTableResourceGroup",
|
RouteTableResourceGroup: "RouteTableResourceGroup",
|
||||||
SecurityGroupName: "SecurityGroupName",
|
SecurityGroupName: "SecurityGroupName",
|
||||||
OverrideType: secretOverrideTypeCan,
|
CloudConfigType: cloudConfigTypeMerge,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTestCanOverrideConfigExpected() *Config {
|
func getTestCloudConfigTypeMergeConfigExpected() *Config {
|
||||||
config := getTestConfig()
|
config := getTestConfig()
|
||||||
config.SecurityGroupName = "SecurityGroupName"
|
config.SecurityGroupName = "SecurityGroupName"
|
||||||
config.OverrideType = secretOverrideTypeCan
|
config.CloudConfigType = cloudConfigTypeMerge
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,34 +95,34 @@ func TestGetConfigFromSecret(t *testing.T) {
|
|||||||
expectErr bool
|
expectErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Azure config shouldn't be override when override type is no",
|
name: "Azure config shouldn't be override when cloud config type is file",
|
||||||
existingConfig: &Config{
|
existingConfig: &Config{
|
||||||
ResourceGroup: "ResourceGroup1",
|
ResourceGroup: "ResourceGroup1",
|
||||||
OverrideType: secretOverrideTypeNo,
|
CloudConfigType: cloudConfigTypeFile,
|
||||||
},
|
},
|
||||||
secretConfig: getTestConfig(),
|
secretConfig: getTestConfig(),
|
||||||
expected: nil,
|
expected: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Azure config should be override when override type is must",
|
name: "Azure config should be override when cloud config type is secret",
|
||||||
existingConfig: getTestMustOverrideConfig(),
|
existingConfig: getTestCloudConfigTypeSecretConfig(),
|
||||||
secretConfig: getTestConfig(),
|
secretConfig: getTestConfig(),
|
||||||
expected: getTestConfig(),
|
expected: getTestConfig(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Azure config should be override when override type is can",
|
name: "Azure config should be override when cloud config type is merge",
|
||||||
existingConfig: getTestCanOverrideConfig(),
|
existingConfig: getTestCloudConfigTypeMergeConfig(),
|
||||||
secretConfig: getTestConfig(),
|
secretConfig: getTestConfig(),
|
||||||
expected: getTestCanOverrideConfigExpected(),
|
expected: getTestCloudConfigTypeMergeConfigExpected(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Error should be reported when secret doesn't exists",
|
name: "Error should be reported when secret doesn't exists",
|
||||||
existingConfig: getTestCanOverrideConfig(),
|
existingConfig: getTestCloudConfigTypeMergeConfig(),
|
||||||
expectErr: true,
|
expectErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Error should be reported when secret exists but cloud-config data is not provided",
|
name: "Error should be reported when secret exists but cloud-config data is not provided",
|
||||||
existingConfig: getTestCanOverrideConfig(),
|
existingConfig: getTestCloudConfigTypeMergeConfig(),
|
||||||
secretConfig: emptyConfig,
|
secretConfig: emptyConfig,
|
||||||
expectErr: true,
|
expectErr: true,
|
||||||
},
|
},
|
||||||
@ -150,7 +150,7 @@ func TestGetConfigFromSecret(t *testing.T) {
|
|||||||
"cloud-config": secretData,
|
"cloud-config": secretData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, err := az.kubeClient.CoreV1().Secrets(secretNamespace).Create(secret)
|
_, err := az.kubeClient.CoreV1().Secrets(cloudConfigNamespace).Create(secret)
|
||||||
assert.NoError(t, err, test.name)
|
assert.NoError(t, err, test.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user