mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 02:08:13 +00:00 
			
		
		
		
	kube-apiserver: removed the deprecated the --cloud-provider and --cloud-config CLI parameters.
				
					
				
			Signed-off-by: carlory <baofa.fan@daocloud.io>
This commit is contained in:
		| @@ -28,13 +28,11 @@ import ( | ||||
|  | ||||
| 	cp "k8s.io/kubernetes/pkg/controlplane/apiserver/options" | ||||
| 	"k8s.io/kubernetes/pkg/kubeapiserver" | ||||
| 	kubeoptions "k8s.io/kubernetes/pkg/kubeapiserver/options" | ||||
| ) | ||||
|  | ||||
| // completedOptions is a private wrapper that enforces a call of Complete() before Run can be invoked. | ||||
| type completedOptions struct { | ||||
| 	cp.CompletedOptions | ||||
| 	CloudProvider *kubeoptions.CloudProviderOptions | ||||
|  | ||||
| 	Extra | ||||
| } | ||||
| @@ -64,7 +62,6 @@ func (s *ServerRunOptions) Complete(ctx context.Context) (CompletedOptions, erro | ||||
|  | ||||
| 	completed := completedOptions{ | ||||
| 		CompletedOptions: controlplane, | ||||
| 		CloudProvider:    s.CloudProvider, | ||||
|  | ||||
| 		Extra: s.Extra, | ||||
| 	} | ||||
|   | ||||
| @@ -38,7 +38,6 @@ import ( | ||||
| // ServerRunOptions runs a kubernetes api server. | ||||
| type ServerRunOptions struct { | ||||
| 	*controlplaneapiserver.Options // embedded to avoid noise in existing consumers | ||||
| 	CloudProvider                  *kubeoptions.CloudProviderOptions | ||||
|  | ||||
| 	Extra | ||||
| } | ||||
| @@ -66,8 +65,7 @@ type Extra struct { | ||||
| // NewServerRunOptions creates and returns ServerRunOptions according to the given featureGate and effectiveVersion of the server binary to run. | ||||
| func NewServerRunOptions() *ServerRunOptions { | ||||
| 	s := ServerRunOptions{ | ||||
| 		Options:       controlplaneapiserver.NewOptions(), | ||||
| 		CloudProvider: kubeoptions.NewCloudProviderOptions(), | ||||
| 		Options: controlplaneapiserver.NewOptions(), | ||||
|  | ||||
| 		Extra: Extra{ | ||||
| 			EndpointReconcilerType: string(reconcilers.LeaseEndpointReconcilerType), | ||||
| @@ -101,7 +99,6 @@ func NewServerRunOptions() *ServerRunOptions { | ||||
| // Flags returns flags for a specific APIServer by section name | ||||
| func (s *ServerRunOptions) Flags() (fss cliflag.NamedFlagSets) { | ||||
| 	s.Options.AddFlags(&fss) | ||||
| 	s.CloudProvider.AddFlags(fss.FlagSet("cloud provider")) | ||||
|  | ||||
| 	// Note: the weird ""+ in below lines seems to be the only way to get gofmt to | ||||
| 	// arrange these text blocks sensibly. Grrr. | ||||
|   | ||||
| @@ -331,10 +331,6 @@ func TestAddFlags(t *testing.T) { | ||||
| 			}, | ||||
| 			MasterCount: 5, | ||||
| 		}, | ||||
| 		CloudProvider: &kubeoptions.CloudProviderOptions{ | ||||
| 			CloudConfigFile: "/cloud-config", | ||||
| 			CloudProvider:   "azure", | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	expected.Authentication.OIDC.UsernameClaim = "sub" | ||||
|   | ||||
| @@ -132,7 +132,6 @@ func (s CompletedOptions) Validate() []error { | ||||
| 	var errs []error | ||||
|  | ||||
| 	errs = append(errs, s.CompletedOptions.Validate()...) | ||||
| 	errs = append(errs, s.CloudProvider.Validate()...) | ||||
| 	errs = append(errs, validateClusterIPFlags(s.Extra)...) | ||||
| 	errs = append(errs, validateServiceNodePort(s.Extra)...) | ||||
| 	errs = append(errs, validatePublicIPServiceClusterIPRangeIPFamilies(s.Extra, *s.GenericServerRunOptions)...) | ||||
|   | ||||
| @@ -212,9 +212,7 @@ func CreateKubeAPIServerConfig( | ||||
| 	capabilities.Setup(opts.AllowPrivileged, opts.MaxConnectionBytesPerSec) | ||||
|  | ||||
| 	// additional admission initializers | ||||
| 	kubeAdmissionConfig := &kubeapiserveradmission.Config{ | ||||
| 		CloudConfigFile: opts.CloudProvider.CloudConfigFile, | ||||
| 	} | ||||
| 	kubeAdmissionConfig := &kubeapiserveradmission.Config{} | ||||
| 	kubeInitializers, err := kubeAdmissionConfig.New() | ||||
| 	if err != nil { | ||||
| 		return nil, nil, nil, fmt.Errorf("failed to create admission plugin initializer: %w", err) | ||||
|   | ||||
| @@ -17,28 +17,13 @@ limitations under the License. | ||||
| package admission | ||||
|  | ||||
| import ( | ||||
| 	"os" | ||||
|  | ||||
| 	"k8s.io/klog/v2" | ||||
|  | ||||
| 	"k8s.io/apiserver/pkg/admission" | ||||
| ) | ||||
|  | ||||
| // Config holds the configuration needed to for initialize the admission plugins | ||||
| type Config struct { | ||||
| 	CloudConfigFile string | ||||
| } | ||||
| type Config struct{} | ||||
|  | ||||
| // New sets up the plugins and admission start hooks needed for admission | ||||
| func (c *Config) New() ([]admission.PluginInitializer, error) { | ||||
| 	var cloudConfig []byte | ||||
| 	if c.CloudConfigFile != "" { | ||||
| 		var err error | ||||
| 		cloudConfig, err = os.ReadFile(c.CloudConfigFile) | ||||
| 		if err != nil { | ||||
| 			klog.Fatalf("Error reading from cloud configuration file %s: %#v", c.CloudConfigFile, err) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return []admission.PluginInitializer{NewPluginInitializer(cloudConfig)}, nil | ||||
| 	return []admission.PluginInitializer{NewPluginInitializer()}, nil | ||||
| } | ||||
|   | ||||
| @@ -22,29 +22,17 @@ import ( | ||||
|  | ||||
| // TODO add a `WantsToRun` which takes a stopCh.  Might make it generic. | ||||
|  | ||||
| // WantsCloudConfig defines a function which sets CloudConfig for admission plugins that need it. | ||||
| type WantsCloudConfig interface { | ||||
| 	SetCloudConfig([]byte) | ||||
| } | ||||
|  | ||||
| // PluginInitializer is used for initialization of the Kubernetes specific admission plugins. | ||||
| type PluginInitializer struct { | ||||
| 	cloudConfig []byte | ||||
| } | ||||
|  | ||||
| var _ admission.PluginInitializer = &PluginInitializer{} | ||||
|  | ||||
| // NewPluginInitializer constructs new instance of PluginInitializer | ||||
| func NewPluginInitializer(cloudConfig []byte) *PluginInitializer { | ||||
| 	return &PluginInitializer{ | ||||
| 		cloudConfig: cloudConfig, | ||||
| 	} | ||||
| func NewPluginInitializer() *PluginInitializer { | ||||
| 	return &PluginInitializer{} | ||||
| } | ||||
|  | ||||
| // Initialize checks the initialization interfaces implemented by each plugin | ||||
| // and provide the appropriate initialization data | ||||
| func (i *PluginInitializer) Initialize(plugin admission.Interface) { | ||||
| 	if wants, ok := plugin.(WantsCloudConfig); ok { | ||||
| 		wants.SetCloudConfig(i.cloudConfig) | ||||
| 	} | ||||
| } | ||||
| func (i *PluginInitializer) Initialize(plugin admission.Interface) {} | ||||
|   | ||||
| @@ -1,52 +0,0 @@ | ||||
| /* | ||||
| Copyright 2016 The Kubernetes Authors. | ||||
|  | ||||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| you may not use this file except in compliance with the License. | ||||
| You may obtain a copy of the License at | ||||
|  | ||||
|     http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  | ||||
| Unless required by applicable law or agreed to in writing, software | ||||
| distributed under the License is distributed on an "AS IS" BASIS, | ||||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| See the License for the specific language governing permissions and | ||||
| limitations under the License. | ||||
| */ | ||||
|  | ||||
| package admission | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"testing" | ||||
|  | ||||
| 	"k8s.io/apiserver/pkg/admission" | ||||
| ) | ||||
|  | ||||
| type doNothingAdmission struct{} | ||||
|  | ||||
| func (doNothingAdmission) Admit(ctx context.Context, a admission.Attributes, o admission.ObjectInterfaces) error { | ||||
| 	return nil | ||||
| } | ||||
| func (doNothingAdmission) Handles(o admission.Operation) bool { return false } | ||||
| func (doNothingAdmission) Validate() error                    { return nil } | ||||
|  | ||||
| type WantsCloudConfigAdmissionPlugin struct { | ||||
| 	doNothingAdmission | ||||
| 	cloudConfig []byte | ||||
| } | ||||
|  | ||||
| func (p *WantsCloudConfigAdmissionPlugin) SetCloudConfig(cloudConfig []byte) { | ||||
| 	p.cloudConfig = cloudConfig | ||||
| } | ||||
|  | ||||
| func TestCloudConfigAdmissionPlugin(t *testing.T) { | ||||
| 	cloudConfig := []byte("cloud-configuration") | ||||
| 	initializer := NewPluginInitializer(cloudConfig) | ||||
| 	wantsCloudConfigAdmission := &WantsCloudConfigAdmissionPlugin{} | ||||
| 	initializer.Initialize(wantsCloudConfigAdmission) | ||||
|  | ||||
| 	if wantsCloudConfigAdmission.cloudConfig == nil { | ||||
| 		t.Errorf("Expected cloud config to be initialized but found nil") | ||||
| 	} | ||||
| } | ||||
| @@ -1,69 +0,0 @@ | ||||
| /* | ||||
| Copyright 2017 The Kubernetes Authors. | ||||
|  | ||||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| you may not use this file except in compliance with the License. | ||||
| You may obtain a copy of the License at | ||||
|  | ||||
|     http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  | ||||
| Unless required by applicable law or agreed to in writing, software | ||||
| distributed under the License is distributed on an "AS IS" BASIS, | ||||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| See the License for the specific language governing permissions and | ||||
| limitations under the License. | ||||
| */ | ||||
|  | ||||
| package options | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
|  | ||||
| 	"github.com/spf13/pflag" | ||||
| 	utilfeature "k8s.io/apiserver/pkg/util/feature" | ||||
| 	cloudprovider "k8s.io/cloud-provider" | ||||
| 	"k8s.io/kubernetes/pkg/features" | ||||
| ) | ||||
|  | ||||
| // CloudProviderOptions contains cloud provider config | ||||
| type CloudProviderOptions struct { | ||||
| 	CloudConfigFile string | ||||
| 	CloudProvider   string | ||||
| } | ||||
|  | ||||
| // NewCloudProviderOptions creates a default CloudProviderOptions | ||||
| func NewCloudProviderOptions() *CloudProviderOptions { | ||||
| 	return &CloudProviderOptions{} | ||||
| } | ||||
|  | ||||
| // Validate checks invalid config | ||||
| func (opts *CloudProviderOptions) Validate() []error { | ||||
| 	var errs []error | ||||
|  | ||||
| 	switch { | ||||
| 	case opts.CloudProvider == "": | ||||
| 	case cloudprovider.IsExternal(opts.CloudProvider): | ||||
| 		if !utilfeature.DefaultFeatureGate.Enabled(features.DisableCloudProviders) { | ||||
| 			errs = append(errs, fmt.Errorf("when using --cloud-provider set to '%s', "+ | ||||
| 				"please set DisableCloudProviders feature to true", opts.CloudProvider)) | ||||
| 		} | ||||
| 		if !utilfeature.DefaultFeatureGate.Enabled(features.DisableKubeletCloudCredentialProviders) { | ||||
| 			errs = append(errs, fmt.Errorf("when using --cloud-provider set to '%s', "+ | ||||
| 				"please set DisableKubeletCloudCredentialProviders feature to true", opts.CloudProvider)) | ||||
| 		} | ||||
| 	default: | ||||
| 		errs = append(errs, fmt.Errorf("unknown --cloud-provider: %s", opts.CloudProvider)) | ||||
| 	} | ||||
|  | ||||
| 	return errs | ||||
| } | ||||
|  | ||||
| // AddFlags returns flags of cloud provider for a API Server | ||||
| func (s *CloudProviderOptions) AddFlags(fs *pflag.FlagSet) { | ||||
| 	fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider, | ||||
| 		"The provider for cloud services. Empty string for no provider.") | ||||
| 	fs.MarkDeprecated("cloud-provider", "will be removed in a future version") // nolint: errcheck | ||||
| 	fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile, | ||||
| 		"The path to the cloud provider configuration file. Empty string for no configuration file.") | ||||
| 	fs.MarkDeprecated("cloud-config", "will be removed in a future version") // nolint: errcheck | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 carlory
					carlory