mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
rebase: bump k8s.io/kubernetes from 1.26.2 to 1.27.2
Bumps [k8s.io/kubernetes](https://github.com/kubernetes/kubernetes) from 1.26.2 to 1.27.2. - [Release notes](https://github.com/kubernetes/kubernetes/releases) - [Commits](https://github.com/kubernetes/kubernetes/compare/v1.26.2...v1.27.2) --- updated-dependencies: - dependency-name: k8s.io/kubernetes dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
committed by
mergify[bot]
parent
0e79135419
commit
07b05616a0
109
vendor/k8s.io/controller-manager/pkg/leadermigration/config/config.go
generated
vendored
Normal file
109
vendor/k8s.io/controller-manager/pkg/leadermigration/config/config.go
generated
vendored
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
Copyright 2020 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 config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||
util "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
internal "k8s.io/controller-manager/config"
|
||||
"k8s.io/controller-manager/config/v1"
|
||||
"k8s.io/controller-manager/config/v1alpha1"
|
||||
"k8s.io/controller-manager/config/v1beta1"
|
||||
)
|
||||
|
||||
// ResourceLockLeases is the resourceLock value for 'leases' API
|
||||
const ResourceLockLeases = "leases"
|
||||
|
||||
// ResourceLockEndpoints is the resourceLock value for 'endpoints' API
|
||||
const ResourceLockEndpoints = "endpoints"
|
||||
|
||||
var cfgScheme = runtime.NewScheme()
|
||||
|
||||
func init() {
|
||||
// internal
|
||||
util.Must(internal.AddToScheme(cfgScheme))
|
||||
|
||||
// v1alpha1
|
||||
util.Must(v1alpha1.AddToScheme(cfgScheme))
|
||||
util.Must(cfgScheme.SetVersionPriority(v1alpha1.SchemeGroupVersion))
|
||||
|
||||
// v1beta1
|
||||
util.Must(v1beta1.AddToScheme(cfgScheme))
|
||||
util.Must(cfgScheme.SetVersionPriority(v1beta1.SchemeGroupVersion))
|
||||
|
||||
// v1
|
||||
util.Must(v1.AddToScheme(cfgScheme))
|
||||
util.Must(cfgScheme.SetVersionPriority(v1.SchemeGroupVersion))
|
||||
}
|
||||
|
||||
// ReadLeaderMigrationConfiguration reads LeaderMigrationConfiguration from a YAML file at the given path.
|
||||
// The parsed LeaderMigrationConfiguration may be invalid.
|
||||
// It returns an error if the file did not exist.
|
||||
func ReadLeaderMigrationConfiguration(configFilePath string) (*internal.LeaderMigrationConfiguration, error) {
|
||||
data, err := os.ReadFile(configFilePath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read leader migration configuration from %q: %w", configFilePath, err)
|
||||
}
|
||||
config, gvk, err := serializer.NewCodecFactory(cfgScheme).UniversalDecoder().Decode(data, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
internalConfig, ok := config.(*internal.LeaderMigrationConfiguration)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected config type: %v", gvk)
|
||||
}
|
||||
return internalConfig, nil
|
||||
}
|
||||
|
||||
// ValidateLeaderMigrationConfiguration validates the LeaderMigrationConfiguration against common errors.
|
||||
// It checks required names and whether resourceLock is either 'leases' or 'endpoints'.
|
||||
// It will return nil if it does not find anything wrong.
|
||||
func ValidateLeaderMigrationConfiguration(config *internal.LeaderMigrationConfiguration) (allErrs field.ErrorList) {
|
||||
if config.LeaderName == "" {
|
||||
allErrs = append(allErrs, field.Required(field.NewPath("leaderName"),
|
||||
"leaderName must be set for LeaderMigrationConfiguration"))
|
||||
}
|
||||
if config.ResourceLock != ResourceLockLeases && config.ResourceLock != ResourceLockEndpoints {
|
||||
allErrs = append(allErrs, field.Invalid(field.NewPath("resourceLock"), config.ResourceLock,
|
||||
"resource Lock must be one of 'leases' or 'endpoints'"))
|
||||
}
|
||||
// validate controllerLeaders
|
||||
fldPath := field.NewPath("controllerLeaders")
|
||||
for i, controllerLeader := range config.ControllerLeaders {
|
||||
path := fldPath.Index(i)
|
||||
allErrs = append(allErrs, validateControllerLeaderConfiguration(path, &controllerLeader)...)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func validateControllerLeaderConfiguration(path *field.Path, config *internal.ControllerLeaderConfiguration) (allErrs field.ErrorList) {
|
||||
if config == nil {
|
||||
return
|
||||
}
|
||||
if config.Component == "" {
|
||||
allErrs = append(allErrs, field.Required(path.Child("component"), "component must be set"))
|
||||
}
|
||||
if config.Name == "" {
|
||||
allErrs = append(allErrs, field.Required(path.Child("name"), "name must be set"))
|
||||
}
|
||||
return
|
||||
}
|
41
vendor/k8s.io/controller-manager/pkg/leadermigration/config/default.go
generated
vendored
Normal file
41
vendor/k8s.io/controller-manager/pkg/leadermigration/config/default.go
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright 2021 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 config
|
||||
|
||||
import internal "k8s.io/controller-manager/config"
|
||||
|
||||
// DefaultLeaderMigrationConfiguration returns the default LeaderMigrationConfiguration
|
||||
//
|
||||
// that is valid for this release of Kubernetes.
|
||||
func DefaultLeaderMigrationConfiguration() *internal.LeaderMigrationConfiguration {
|
||||
return &internal.LeaderMigrationConfiguration{
|
||||
LeaderName: "cloud-provider-extraction-migration",
|
||||
ResourceLock: ResourceLockLeases,
|
||||
ControllerLeaders: []internal.ControllerLeaderConfiguration{
|
||||
{
|
||||
Name: "route",
|
||||
Component: "*",
|
||||
}, {
|
||||
Name: "service",
|
||||
Component: "*",
|
||||
}, {
|
||||
Name: "cloud-node-lifecycle",
|
||||
Component: "*",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
28
vendor/k8s.io/controller-manager/pkg/leadermigration/feature.go
generated
vendored
Normal file
28
vendor/k8s.io/controller-manager/pkg/leadermigration/feature.go
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
Copyright 2021 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 leadermigration
|
||||
|
||||
import (
|
||||
"k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/controller-manager/pkg/features"
|
||||
_ "k8s.io/controller-manager/pkg/features/register"
|
||||
)
|
||||
|
||||
// FeatureEnabled tells if leader migration is enabled through the feature gate.
|
||||
func FeatureEnabled() bool {
|
||||
return feature.DefaultMutableFeatureGate.Enabled(features.ControllerManagerLeaderMigration)
|
||||
}
|
35
vendor/k8s.io/controller-manager/pkg/leadermigration/filter.go
generated
vendored
Normal file
35
vendor/k8s.io/controller-manager/pkg/leadermigration/filter.go
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright 2021 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 leadermigration
|
||||
|
||||
// FilterResult indicates whether and how the controller manager should start the controller.
|
||||
type FilterResult int32
|
||||
|
||||
const (
|
||||
// ControllerUnowned indicates that the controller is owned by another controller manager
|
||||
// and thus should NOT be started by this controller manager.
|
||||
ControllerUnowned = iota
|
||||
// ControllerMigrated indicates that the controller manager should start this controller
|
||||
// with the migration lock.
|
||||
ControllerMigrated
|
||||
// ControllerNonMigrated indicates that the controller manager should start this controller
|
||||
// with the main lock.
|
||||
ControllerNonMigrated
|
||||
)
|
||||
|
||||
// FilterFunc takes a name of controller, returning a FilterResult indicating how to start controller.
|
||||
type FilterFunc func(controllerName string) FilterResult
|
62
vendor/k8s.io/controller-manager/pkg/leadermigration/migrator.go
generated
vendored
Normal file
62
vendor/k8s.io/controller-manager/pkg/leadermigration/migrator.go
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright 2021 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 leadermigration
|
||||
|
||||
import (
|
||||
internal "k8s.io/controller-manager/config"
|
||||
)
|
||||
|
||||
// LeaderMigrator holds information required by the leader migration process.
|
||||
type LeaderMigrator struct {
|
||||
// MigrationReady is closed after the controller manager finishes preparing for the migration lock.
|
||||
// After this point, the leader migration process will proceed to acquire the migration lock.
|
||||
MigrationReady chan struct{}
|
||||
|
||||
// FilterFunc returns a FilterResult telling the controller manager what to do with the controller.
|
||||
FilterFunc FilterFunc
|
||||
}
|
||||
|
||||
// NewLeaderMigrator creates a LeaderMigrator with given config for the given component. component
|
||||
//
|
||||
// indicates which controller manager is requesting this leader migration, and it should be consistent
|
||||
// with the component field of ControllerLeaderConfiguration.
|
||||
func NewLeaderMigrator(config *internal.LeaderMigrationConfiguration, component string) *LeaderMigrator {
|
||||
migratedControllers := make(map[string]bool)
|
||||
for _, leader := range config.ControllerLeaders {
|
||||
migratedControllers[leader.Name] = leader.Component == component || leader.Component == "*"
|
||||
}
|
||||
return &LeaderMigrator{
|
||||
MigrationReady: make(chan struct{}),
|
||||
FilterFunc: func(controllerName string) FilterResult {
|
||||
shouldRun, ok := migratedControllers[controllerName]
|
||||
if ok {
|
||||
// The controller is included in the migration
|
||||
if shouldRun {
|
||||
// If the controller manager should run the controller,
|
||||
// start it in the migration lock.
|
||||
return ControllerMigrated
|
||||
}
|
||||
// Otherwise, the controller should be started by
|
||||
// some other controller manager.
|
||||
return ControllerUnowned
|
||||
}
|
||||
// The controller is not included in the migration,
|
||||
// and should be started in the main lock.
|
||||
return ControllerNonMigrated
|
||||
},
|
||||
}
|
||||
}
|
89
vendor/k8s.io/controller-manager/pkg/leadermigration/options/options.go
generated
vendored
Normal file
89
vendor/k8s.io/controller-manager/pkg/leadermigration/options/options.go
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
Copyright 2021 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"
|
||||
"k8s.io/controller-manager/config"
|
||||
"k8s.io/controller-manager/pkg/leadermigration"
|
||||
migrationconfig "k8s.io/controller-manager/pkg/leadermigration/config"
|
||||
)
|
||||
|
||||
// LeaderMigrationOptions is the set of options for Leader Migration,
|
||||
// which is given to the controller manager through flags
|
||||
type LeaderMigrationOptions struct {
|
||||
// Enabled indicates whether leader migration is enabled through the --enabled-leader-migration flag.
|
||||
Enabled bool
|
||||
|
||||
// ControllerMigrationConfig is the path to the file of LeaderMigrationConfiguration type.
|
||||
// It can be set with --leader-migration-config flag
|
||||
// If the path is "" (default vaule), the default vaule will be used.
|
||||
ControllerMigrationConfig string
|
||||
}
|
||||
|
||||
// DefaultLeaderMigrationOptions returns a LeaderMigrationOptions with default values.
|
||||
func DefaultLeaderMigrationOptions() *LeaderMigrationOptions {
|
||||
return &LeaderMigrationOptions{
|
||||
Enabled: false,
|
||||
ControllerMigrationConfig: "",
|
||||
}
|
||||
}
|
||||
|
||||
// AddFlags adds all flags related to leader migration to given flag set.
|
||||
func (o *LeaderMigrationOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
if o == nil {
|
||||
return
|
||||
}
|
||||
fs.BoolVar(&o.Enabled, "enable-leader-migration", false, "Whether to enable controller leader migration.")
|
||||
fs.StringVar(&o.ControllerMigrationConfig, "leader-migration-config", "",
|
||||
"Path to the config file for controller leader migration, "+
|
||||
"or empty to use the value that reflects default configuration of the controller manager. "+
|
||||
"The config file should be of type LeaderMigrationConfiguration, group controllermanager.config.k8s.io, version v1alpha1.")
|
||||
}
|
||||
|
||||
// ApplyTo applies the options of leader migration to generic configuration.
|
||||
func (o *LeaderMigrationOptions) ApplyTo(cfg *config.GenericControllerManagerConfiguration) error {
|
||||
if o == nil {
|
||||
// an nil LeaderMigrationOptions indicates that default options should be used
|
||||
// in which case leader migration will be disabled
|
||||
cfg.LeaderMigrationEnabled = false
|
||||
return nil
|
||||
}
|
||||
if o.Enabled && !leadermigration.FeatureEnabled() {
|
||||
return fmt.Errorf("Leader Migration is not enabled through feature gate")
|
||||
}
|
||||
cfg.LeaderMigrationEnabled = o.Enabled
|
||||
if !cfg.LeaderMigrationEnabled {
|
||||
return nil
|
||||
}
|
||||
if o.ControllerMigrationConfig == "" {
|
||||
cfg.LeaderMigration = *migrationconfig.DefaultLeaderMigrationConfiguration()
|
||||
return nil
|
||||
}
|
||||
leaderMigrationConfig, err := migrationconfig.ReadLeaderMigrationConfiguration(o.ControllerMigrationConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
errs := migrationconfig.ValidateLeaderMigrationConfiguration(leaderMigrationConfig)
|
||||
if len(errs) != 0 {
|
||||
return fmt.Errorf("failed to parse leader migration configuration: %v", errs)
|
||||
}
|
||||
cfg.LeaderMigration = *leaderMigrationConfig
|
||||
return nil
|
||||
}
|
25
vendor/k8s.io/controller-manager/pkg/leadermigration/util.go
generated
vendored
Normal file
25
vendor/k8s.io/controller-manager/pkg/leadermigration/util.go
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
Copyright 2021 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 leadermigration
|
||||
|
||||
import config "k8s.io/controller-manager/config"
|
||||
|
||||
// Enabled checks whether Leader Migration should be enabled, given the GenericControllerManagerConfiguration.
|
||||
// It considers the feature gate first, and will always return false if the feature gate is not enabled.
|
||||
func Enabled(genericConfig *config.GenericControllerManagerConfiguration) bool {
|
||||
return FeatureEnabled() && genericConfig.LeaderElection.LeaderElect && genericConfig.LeaderMigrationEnabled
|
||||
}
|
Reference in New Issue
Block a user