...
1
16
17 package options
18
19 import (
20 "fmt"
21
22 "github.com/spf13/pflag"
23 utilfeature "k8s.io/apiserver/pkg/util/feature"
24 cloudprovider "k8s.io/cloud-provider"
25 "k8s.io/kubernetes/pkg/features"
26 )
27
28
29 type CloudProviderOptions struct {
30 CloudConfigFile string
31 CloudProvider string
32 }
33
34
35 func NewCloudProviderOptions() *CloudProviderOptions {
36 return &CloudProviderOptions{}
37 }
38
39
40 func (opts *CloudProviderOptions) Validate() []error {
41 var errs []error
42
43 switch {
44 case opts.CloudProvider == "":
45 case opts.CloudProvider == "external":
46 if !utilfeature.DefaultFeatureGate.Enabled(features.DisableCloudProviders) {
47 errs = append(errs, fmt.Errorf("when using --cloud-provider set to '%s', "+
48 "please set DisableCloudProviders feature to true", opts.CloudProvider))
49 }
50 if !utilfeature.DefaultFeatureGate.Enabled(features.DisableKubeletCloudCredentialProviders) {
51 errs = append(errs, fmt.Errorf("when using --cloud-provider set to '%s', "+
52 "please set DisableKubeletCloudCredentialProviders feature to true", opts.CloudProvider))
53 }
54 case cloudprovider.IsDeprecatedInternal(opts.CloudProvider):
55 if utilfeature.DefaultFeatureGate.Enabled(features.DisableCloudProviders) {
56 errs = append(errs, fmt.Errorf("when using --cloud-provider set to '%s', "+
57 "please set DisableCloudProviders feature to false", opts.CloudProvider))
58 }
59 if utilfeature.DefaultFeatureGate.Enabled(features.DisableKubeletCloudCredentialProviders) {
60 errs = append(errs, fmt.Errorf("when using --cloud-provider set to '%s', "+
61 "please set DisableKubeletCloudCredentialProviders feature to false", opts.CloudProvider))
62 }
63 default:
64 errs = append(errs, fmt.Errorf("unknown --cloud-provider: %s", opts.CloudProvider))
65 }
66
67 return errs
68 }
69
70
71 func (s *CloudProviderOptions) AddFlags(fs *pflag.FlagSet) {
72 fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider,
73 "The provider for cloud services. Empty string for no provider.")
74 fs.MarkDeprecated("cloud-provider", "will be removed in a future version")
75 fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile,
76 "The path to the cloud provider configuration file. Empty string for no configuration file.")
77 fs.MarkDeprecated("cloud-config", "will be removed in a future version")
78 }
79
View as plain text