mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 18:43:34 +00:00
build: move e2e dependencies into e2e/go.mod
Several packages are only used while running the e2e suite. These packages are less important to update, as the they can not influence the final executable that is part of the Ceph-CSI container-image. By moving these dependencies out of the main Ceph-CSI go.mod, it is easier to identify if a reported CVE affects Ceph-CSI, or only the testing (like most of the Kubernetes CVEs). Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
committed by
mergify[bot]
parent
15da101b1b
commit
bec6090996
109
e2e/vendor/k8s.io/controller-manager/pkg/leadermigration/config/config.go
generated
vendored
Normal file
109
e2e/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"
|
||||
v1 "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, serializer.EnableStrict).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
|
||||
}
|
40
e2e/vendor/k8s.io/controller-manager/pkg/leadermigration/config/default.go
generated
vendored
Normal file
40
e2e/vendor/k8s.io/controller-manager/pkg/leadermigration/config/default.go
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
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-controller",
|
||||
Component: "*",
|
||||
}, {
|
||||
Name: "service-controller",
|
||||
Component: "*",
|
||||
}, {
|
||||
Name: "cloud-node-lifecycle-controller",
|
||||
Component: "*",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
85
e2e/vendor/k8s.io/controller-manager/pkg/leadermigration/options/options.go
generated
vendored
Normal file
85
e2e/vendor/k8s.io/controller-manager/pkg/leadermigration/options/options.go
generated
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
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"
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user