Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: set default config secret name and namespace #662

Merged
merged 1 commit into from Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/cloud-controller-manager/app/options/dynamic.go
Expand Up @@ -37,7 +37,7 @@ func (o *DynamicReloadingOptions) AddFlags(fs *pflag.FlagSet) {
}

fs.BoolVar(&o.EnableDynamicReloading, "enable-dynamic-reloading", false, "Enable re-configuring cloud controller manager from secret without restarting")
fs.StringVar(&o.CloudConfigSecretName, "cloud-config-secret-name", "cloud-provider-config", "The name of the cloud config secret, default to 'cloud-provider-config'")
fs.StringVar(&o.CloudConfigSecretName, "cloud-config-secret-name", "azure-cloud-provider", "The name of the cloud config secret, default to 'cloud-provider-config'")
fs.StringVar(&o.CloudConfigSecretNamespace, "cloud-config-secret-namespace", "kube-system", "The k8s namespace of the cloud config secret, default to 'kube-system'")
fs.StringVar(&o.CloudConfigKey, "cloud-config-key", "cloud-config", "The key of the config data in the cloud config secret, default to 'cloud-config'")
}
Expand All @@ -64,8 +64,8 @@ func (o *DynamicReloadingOptions) Validate() []error {
func defaultDynamicReloadingOptions() *DynamicReloadingOptions {
return &DynamicReloadingOptions{
EnableDynamicReloading: false,
CloudConfigSecretName: "",
CloudConfigSecretNamespace: "",
CloudConfigSecretName: "azure-cloud-provider",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the code change should be in pkg/provider, otherwise how could csi driver use the default values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

CloudConfigSecretNamespace: "kube-system",
CloudConfigKey: "",
}
}
4 changes: 2 additions & 2 deletions cmd/cloud-controller-manager/app/options/options_test.go
Expand Up @@ -141,8 +141,8 @@ func TestDefaultFlags(t *testing.T) {
NodeStatusUpdateFrequency: metav1.Duration{Duration: 5 * time.Minute},
DynamicReloading: &DynamicReloadingOptions{
EnableDynamicReloading: false,
CloudConfigSecretName: "",
CloudConfigSecretNamespace: "",
CloudConfigSecretName: "azure-cloud-provider",
CloudConfigSecretNamespace: "kube-system",
CloudConfigKey: "",
},
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/consts/consts.go
Expand Up @@ -340,3 +340,10 @@ const (
RouteNameFmt = "%s____%s"
RouteNameSeparator = "____"
)

// cloud provider config secret
const (
DefaultCloudProviderConfigSecName = "azure-cloud-provider"
DefaultCloudProviderConfigSecNamespace = "kube-system"
DefaultCloudProviderConfigSecKey = "cloud-config"
)
25 changes: 20 additions & 5 deletions pkg/provider/azure.go
Expand Up @@ -372,20 +372,35 @@ func NewCloudFromConfigFile(configFilePath string, syncZones bool) (cloudprovide
return cloud, nil
}

func (az *Cloud) configSecretMetadata(secretName, secretNamespace, cloudConfigKey string) {
if secretName == "" {
secretName = consts.DefaultCloudProviderConfigSecName
}
if secretNamespace == "" {
secretNamespace = consts.DefaultCloudProviderConfigSecNamespace
}
if cloudConfigKey == "" {
cloudConfigKey = consts.DefaultCloudProviderConfigSecKey
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also add a unit test for these default values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding


az.InitSecretConfig = InitSecretConfig{
SecretName: secretName,
SecretNamespace: secretNamespace,
CloudConfigKey: cloudConfigKey,
}
}

func NewCloudFromSecret(clientBuilder cloudprovider.ControllerClientBuilder, secretName, secretNamespace, cloudConfigKey string) (cloudprovider.Interface, error) {
az := &Cloud{
nodeNames: sets.NewString(),
nodeZones: map[string]sets.String{},
nodeResourceGroups: map[string]string{},
unmanagedNodes: sets.NewString(),
routeCIDRs: map[string]string{},
InitSecretConfig: InitSecretConfig{
SecretName: secretName,
SecretNamespace: secretNamespace,
CloudConfigKey: cloudConfigKey,
},
}

az.configSecretMetadata(secretName, secretNamespace, cloudConfigKey)

az.Initialize(clientBuilder, wait.NeverStop)

err := az.InitializeCloudFromSecret()
Expand Down
35 changes: 35 additions & 0 deletions pkg/provider/azure_config_test.go
Expand Up @@ -20,6 +20,8 @@ import (
"context"
"testing"

"sigs.k8s.io/cloud-provider-azure/pkg/consts"

"github.com/golang/mock/gomock"
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/zoneclient/mockzoneclient"

Expand Down Expand Up @@ -286,3 +288,36 @@ func TestInitializeCloudFromSecret(t *testing.T) {
})
}
}

func TestConfigSecretMetadata(t *testing.T) {
for _, testCase := range []struct {
description string
secretName, secretNamespace, cloudConfigKey string
expectedsecretName, expectedSsecretNamespace, expectedClouConfigKey string
}{
{
description: "configSecretMetadata should set the secret metadata from the given parameters",
secretName: "cloud-provider-config",
secretNamespace: "123456",
cloudConfigKey: "azure.json",
expectedsecretName: "cloud-provider-config",
expectedSsecretNamespace: "123456",
expectedClouConfigKey: "azure.json",
},
{
description: "configSecretMetadata should set the secret metadata from the default values",
expectedsecretName: consts.DefaultCloudProviderConfigSecName,
expectedSsecretNamespace: consts.DefaultCloudProviderConfigSecNamespace,
expectedClouConfigKey: consts.DefaultCloudProviderConfigSecKey,
},
} {
t.Run(testCase.description, func(t *testing.T) {
az := &Cloud{}
az.configSecretMetadata(testCase.secretName, testCase.secretNamespace, testCase.cloudConfigKey)

assert.Equal(t, testCase.expectedsecretName, az.SecretName)
assert.Equal(t, testCase.expectedSsecretNamespace, az.SecretNamespace)
assert.Equal(t, testCase.expectedClouConfigKey, az.CloudConfigKey)
})
}
}