Copy kubescheduler.config.k8s.io/v1alpha1 files onto v1alpha2
Signed-off-by: Aldo Culquicondor <acondor@google.com>
This commit is contained in:
parent
8daa761757
commit
11c4bcd9dd
@ -28,6 +28,7 @@ import (
|
|||||||
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
kubeschedulerscheme "k8s.io/kubernetes/pkg/scheduler/apis/config/scheme"
|
kubeschedulerscheme "k8s.io/kubernetes/pkg/scheduler/apis/config/scheme"
|
||||||
kubeschedulerconfigv1alpha1 "k8s.io/kubernetes/pkg/scheduler/apis/config/v1alpha1"
|
kubeschedulerconfigv1alpha1 "k8s.io/kubernetes/pkg/scheduler/apis/config/v1alpha1"
|
||||||
|
kubeschedulerconfigv1alpha2 "k8s.io/kubernetes/pkg/scheduler/apis/config/v1alpha2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func loadConfigFromFile(file string) (*kubeschedulerconfig.KubeSchedulerConfiguration, error) {
|
func loadConfigFromFile(file string) (*kubeschedulerconfig.KubeSchedulerConfiguration, error) {
|
||||||
@ -55,6 +56,7 @@ func loadConfig(data []byte) (*kubeschedulerconfig.KubeSchedulerConfiguration, e
|
|||||||
_, lenientCodecs, lenientErr := codec.NewLenientSchemeAndCodecs(
|
_, lenientCodecs, lenientErr := codec.NewLenientSchemeAndCodecs(
|
||||||
kubeschedulerconfig.AddToScheme,
|
kubeschedulerconfig.AddToScheme,
|
||||||
kubeschedulerconfigv1alpha1.AddToScheme,
|
kubeschedulerconfigv1alpha1.AddToScheme,
|
||||||
|
kubeschedulerconfigv1alpha2.AddToScheme,
|
||||||
)
|
)
|
||||||
if lenientErr != nil {
|
if lenientErr != nil {
|
||||||
return nil, lenientErr
|
return nil, lenientErr
|
||||||
@ -76,7 +78,7 @@ func WriteConfigFile(fileName string, cfg *kubeschedulerconfig.KubeSchedulerConf
|
|||||||
return fmt.Errorf("unable to locate encoder -- %q is not a supported media type", mediaType)
|
return fmt.Errorf("unable to locate encoder -- %q is not a supported media type", mediaType)
|
||||||
}
|
}
|
||||||
|
|
||||||
encoder := kubeschedulerscheme.Codecs.EncoderForVersion(info.Serializer, kubeschedulerconfigv1alpha1.SchemeGroupVersion)
|
encoder := kubeschedulerscheme.Codecs.EncoderForVersion(info.Serializer, kubeschedulerconfigv1alpha2.SchemeGroupVersion)
|
||||||
|
|
||||||
configFile, err := os.Create(fileName)
|
configFile, err := os.Create(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
kubeschedulerconfigv1 "k8s.io/kubernetes/pkg/scheduler/apis/config/v1"
|
kubeschedulerconfigv1 "k8s.io/kubernetes/pkg/scheduler/apis/config/v1"
|
||||||
kubeschedulerconfigv1alpha1 "k8s.io/kubernetes/pkg/scheduler/apis/config/v1alpha1"
|
kubeschedulerconfigv1alpha1 "k8s.io/kubernetes/pkg/scheduler/apis/config/v1alpha1"
|
||||||
|
kubeschedulerconfigv1alpha2 "k8s.io/kubernetes/pkg/scheduler/apis/config/v1alpha2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -42,5 +43,6 @@ func AddToScheme(scheme *runtime.Scheme) {
|
|||||||
utilruntime.Must(kubeschedulerconfig.AddToScheme(Scheme))
|
utilruntime.Must(kubeschedulerconfig.AddToScheme(Scheme))
|
||||||
utilruntime.Must(kubeschedulerconfigv1.AddToScheme(Scheme))
|
utilruntime.Must(kubeschedulerconfigv1.AddToScheme(Scheme))
|
||||||
utilruntime.Must(kubeschedulerconfigv1alpha1.AddToScheme(Scheme))
|
utilruntime.Must(kubeschedulerconfigv1alpha1.AddToScheme(Scheme))
|
||||||
|
utilruntime.Must(kubeschedulerconfigv1alpha2.AddToScheme(Scheme))
|
||||||
utilruntime.Must(scheme.SetVersionPriority(kubeschedulerconfigv1alpha1.SchemeGroupVersion))
|
utilruntime.Must(scheme.SetVersionPriority(kubeschedulerconfigv1alpha1.SchemeGroupVersion))
|
||||||
}
|
}
|
||||||
|
68
pkg/scheduler/apis/config/v1alpha2/conversion.go
Normal file
68
pkg/scheduler/apis/config/v1alpha2/conversion.go
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
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 v1alpha2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/conversion"
|
||||||
|
"k8s.io/kube-scheduler/config/v1alpha2"
|
||||||
|
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Convert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration is an autogenerated conversion function.
|
||||||
|
func Convert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(in *v1alpha2.KubeSchedulerLeaderElectionConfiguration, out *config.KubeSchedulerLeaderElectionConfiguration, s conversion.Scope) error {
|
||||||
|
if err := autoConvert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(in, out, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(in.ResourceNamespace) > 0 && len(in.LockObjectNamespace) == 0 {
|
||||||
|
out.ResourceNamespace = in.ResourceNamespace
|
||||||
|
} else if len(in.ResourceNamespace) == 0 && len(in.LockObjectNamespace) > 0 {
|
||||||
|
out.ResourceNamespace = in.LockObjectNamespace
|
||||||
|
} else if len(in.ResourceNamespace) > 0 && len(in.LockObjectNamespace) > 0 {
|
||||||
|
if in.ResourceNamespace == in.LockObjectNamespace {
|
||||||
|
out.ResourceNamespace = in.ResourceNamespace
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("ResourceNamespace and LockObjectNamespace are both set and do not match, ResourceNamespace: %s, LockObjectNamespace: %s", in.ResourceNamespace, in.LockObjectNamespace)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(in.ResourceName) > 0 && len(in.LockObjectName) == 0 {
|
||||||
|
out.ResourceName = in.ResourceName
|
||||||
|
} else if len(in.ResourceName) == 0 && len(in.LockObjectName) > 0 {
|
||||||
|
out.ResourceName = in.LockObjectName
|
||||||
|
} else if len(in.ResourceName) > 0 && len(in.LockObjectName) > 0 {
|
||||||
|
if in.ResourceName == in.LockObjectName {
|
||||||
|
out.ResourceName = in.ResourceName
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("ResourceName and LockObjectName are both set and do not match, ResourceName: %s, LockObjectName: %s", in.ResourceName, in.LockObjectName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_KubeSchedulerLeaderElectionConfiguration is an autogenerated conversion function.
|
||||||
|
func Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_KubeSchedulerLeaderElectionConfiguration(in *config.KubeSchedulerLeaderElectionConfiguration, out *v1alpha2.KubeSchedulerLeaderElectionConfiguration, s conversion.Scope) error {
|
||||||
|
if err := autoConvert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_KubeSchedulerLeaderElectionConfiguration(in, out, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out.ResourceNamespace = in.ResourceNamespace
|
||||||
|
out.LockObjectNamespace = in.ResourceNamespace
|
||||||
|
out.ResourceName = in.ResourceName
|
||||||
|
out.LockObjectName = in.ResourceName
|
||||||
|
return nil
|
||||||
|
}
|
193
pkg/scheduler/apis/config/v1alpha2/conversion_test.go
Normal file
193
pkg/scheduler/apis/config/v1alpha2/conversion_test.go
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
/*
|
||||||
|
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 v1alpha2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/conversion"
|
||||||
|
componentbaseconfig "k8s.io/component-base/config"
|
||||||
|
componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1"
|
||||||
|
"k8s.io/kube-scheduler/config/v1alpha2"
|
||||||
|
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestV1alpha1ToConfigKubeSchedulerLeaderElectionConfiguration(t *testing.T) {
|
||||||
|
configuration := &v1alpha2.KubeSchedulerLeaderElectionConfiguration{
|
||||||
|
LockObjectName: "name",
|
||||||
|
LockObjectNamespace: "namespace",
|
||||||
|
LeaderElectionConfiguration: componentbaseconfigv1alpha1.LeaderElectionConfiguration{
|
||||||
|
ResourceName: "name",
|
||||||
|
ResourceNamespace: "namespace",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
emptyLockObjectNameConfig := configuration.DeepCopy()
|
||||||
|
emptyLockObjectNameConfig.LockObjectName = ""
|
||||||
|
|
||||||
|
emptyLockObjectNamespaceConfig := configuration.DeepCopy()
|
||||||
|
emptyLockObjectNamespaceConfig.LockObjectNamespace = ""
|
||||||
|
|
||||||
|
emptyResourceNameConfig := configuration.DeepCopy()
|
||||||
|
emptyResourceNameConfig.ResourceName = ""
|
||||||
|
|
||||||
|
emptyResourceNamespaceConfig := configuration.DeepCopy()
|
||||||
|
emptyResourceNamespaceConfig.ResourceNamespace = ""
|
||||||
|
|
||||||
|
differentNameConfig := configuration.DeepCopy()
|
||||||
|
differentNameConfig.LockObjectName = "name1"
|
||||||
|
|
||||||
|
differentNamespaceConfig := configuration.DeepCopy()
|
||||||
|
differentNamespaceConfig.LockObjectNamespace = "namespace1"
|
||||||
|
|
||||||
|
emptyconfig := &v1alpha2.KubeSchedulerLeaderElectionConfiguration{}
|
||||||
|
|
||||||
|
scenarios := map[string]struct {
|
||||||
|
expectedResourceNamespace string
|
||||||
|
expectedResourceName string
|
||||||
|
expectedToFailed bool
|
||||||
|
config *v1alpha2.KubeSchedulerLeaderElectionConfiguration
|
||||||
|
}{
|
||||||
|
"both-set-same-name-and-namespace": {
|
||||||
|
expectedResourceNamespace: "namespace",
|
||||||
|
expectedResourceName: "name",
|
||||||
|
expectedToFailed: false,
|
||||||
|
config: configuration,
|
||||||
|
},
|
||||||
|
"not-set-lock-object-name": {
|
||||||
|
expectedResourceNamespace: "namespace",
|
||||||
|
expectedResourceName: "name",
|
||||||
|
expectedToFailed: false,
|
||||||
|
config: emptyLockObjectNameConfig,
|
||||||
|
},
|
||||||
|
"not-set-lock-object-namespace": {
|
||||||
|
expectedResourceNamespace: "namespace",
|
||||||
|
expectedResourceName: "name",
|
||||||
|
expectedToFailed: false,
|
||||||
|
config: emptyLockObjectNamespaceConfig,
|
||||||
|
},
|
||||||
|
"not-set-resource-name": {
|
||||||
|
expectedResourceNamespace: "namespace",
|
||||||
|
expectedResourceName: "name",
|
||||||
|
expectedToFailed: false,
|
||||||
|
config: emptyResourceNameConfig,
|
||||||
|
},
|
||||||
|
"not-set-resource-namespace": {
|
||||||
|
expectedResourceNamespace: "namespace",
|
||||||
|
expectedResourceName: "name",
|
||||||
|
expectedToFailed: false,
|
||||||
|
config: emptyResourceNamespaceConfig,
|
||||||
|
},
|
||||||
|
"set-different-name": {
|
||||||
|
expectedResourceNamespace: "",
|
||||||
|
expectedResourceName: "",
|
||||||
|
expectedToFailed: true,
|
||||||
|
config: differentNameConfig,
|
||||||
|
},
|
||||||
|
"set-different-namespace": {
|
||||||
|
expectedResourceNamespace: "",
|
||||||
|
expectedResourceName: "",
|
||||||
|
expectedToFailed: true,
|
||||||
|
config: differentNamespaceConfig,
|
||||||
|
},
|
||||||
|
"set-empty-name-and-namespace": {
|
||||||
|
expectedResourceNamespace: "",
|
||||||
|
expectedResourceName: "",
|
||||||
|
expectedToFailed: false,
|
||||||
|
config: emptyconfig,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for name, scenario := range scenarios {
|
||||||
|
out := &config.KubeSchedulerLeaderElectionConfiguration{}
|
||||||
|
s := conversion.Scope(nil)
|
||||||
|
err := Convert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(scenario.config, out, s)
|
||||||
|
if err == nil && scenario.expectedToFailed {
|
||||||
|
t.Errorf("Unexpected success for scenario: %s", name)
|
||||||
|
}
|
||||||
|
if err == nil && !scenario.expectedToFailed {
|
||||||
|
if out.ResourceName != scenario.expectedResourceName {
|
||||||
|
t.Errorf("Unexpected success for scenario: %s, out.ResourceName: %s, expectedResourceName: %s", name, out.ResourceName, scenario.expectedResourceName)
|
||||||
|
}
|
||||||
|
if out.ResourceNamespace != scenario.expectedResourceNamespace {
|
||||||
|
t.Errorf("Unexpected success for scenario: %s, out.ResourceNamespace: %s, expectedResourceNamespace: %s", name, out.ResourceNamespace, scenario.expectedResourceNamespace)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil && !scenario.expectedToFailed {
|
||||||
|
t.Errorf("Unexpected failure for scenario: %s - %+v", name, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConfigToV1alpha1KubeSchedulerLeaderElectionConfiguration(t *testing.T) {
|
||||||
|
configuration := &config.KubeSchedulerLeaderElectionConfiguration{
|
||||||
|
LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
|
||||||
|
ResourceName: "name",
|
||||||
|
ResourceNamespace: "namespace",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
emptyconfig := &config.KubeSchedulerLeaderElectionConfiguration{}
|
||||||
|
|
||||||
|
scenarios := map[string]struct {
|
||||||
|
expectedResourceNamespace string
|
||||||
|
expectedResourceName string
|
||||||
|
expectedLockObjectNamespace string
|
||||||
|
expectedLockObjectName string
|
||||||
|
expectedToFailed bool
|
||||||
|
config *config.KubeSchedulerLeaderElectionConfiguration
|
||||||
|
}{
|
||||||
|
"both-set-name-and-namespace": {
|
||||||
|
expectedResourceNamespace: "namespace",
|
||||||
|
expectedResourceName: "name",
|
||||||
|
expectedLockObjectNamespace: "namespace",
|
||||||
|
expectedLockObjectName: "name",
|
||||||
|
expectedToFailed: false,
|
||||||
|
config: configuration,
|
||||||
|
},
|
||||||
|
"set-empty-name-and-namespace": {
|
||||||
|
expectedResourceNamespace: "",
|
||||||
|
expectedResourceName: "",
|
||||||
|
expectedLockObjectNamespace: "",
|
||||||
|
expectedLockObjectName: "",
|
||||||
|
expectedToFailed: false,
|
||||||
|
config: emptyconfig,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for name, scenario := range scenarios {
|
||||||
|
out := &v1alpha2.KubeSchedulerLeaderElectionConfiguration{}
|
||||||
|
s := conversion.Scope(nil)
|
||||||
|
err := Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_KubeSchedulerLeaderElectionConfiguration(scenario.config, out, s)
|
||||||
|
if err == nil && scenario.expectedToFailed {
|
||||||
|
t.Errorf("Unexpected success for scenario: %s", name)
|
||||||
|
}
|
||||||
|
if err == nil && !scenario.expectedToFailed {
|
||||||
|
if out.ResourceName != scenario.expectedResourceName {
|
||||||
|
t.Errorf("Unexpected success for scenario: %s, out.ResourceName: %s, expectedResourceName: %s", name, out.ResourceName, scenario.expectedResourceName)
|
||||||
|
}
|
||||||
|
if out.LockObjectName != scenario.expectedLockObjectName {
|
||||||
|
t.Errorf("Unexpected success for scenario: %s, out.LockObjectName: %s, expectedLockObjectName: %s", name, out.LockObjectName, scenario.expectedLockObjectName)
|
||||||
|
}
|
||||||
|
if out.ResourceNamespace != scenario.expectedResourceNamespace {
|
||||||
|
t.Errorf("Unexpected success for scenario: %s, out.ResourceNamespace: %s, expectedResourceNamespace: %s", name, out.ResourceNamespace, scenario.expectedResourceNamespace)
|
||||||
|
}
|
||||||
|
if out.LockObjectNamespace != scenario.expectedLockObjectNamespace {
|
||||||
|
t.Errorf("Unexpected success for scenario: %s, out.LockObjectNamespace: %s, expectedLockObjectNamespace: %s", name, out.LockObjectNamespace, scenario.expectedLockObjectNamespace)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil && !scenario.expectedToFailed {
|
||||||
|
t.Errorf("Unexpected failure for scenario: %s - %+v", name, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
171
pkg/scheduler/apis/config/v1alpha2/defaults.go
Normal file
171
pkg/scheduler/apis/config/v1alpha2/defaults.go
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
/*
|
||||||
|
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 v1alpha2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1"
|
||||||
|
"k8s.io/kube-scheduler/config/v1alpha2"
|
||||||
|
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
|
|
||||||
|
// this package shouldn't really depend on other k8s.io/kubernetes code
|
||||||
|
api "k8s.io/kubernetes/pkg/apis/core"
|
||||||
|
"k8s.io/kubernetes/pkg/master/ports"
|
||||||
|
)
|
||||||
|
|
||||||
|
func addDefaultingFuncs(scheme *runtime.Scheme) error {
|
||||||
|
return RegisterDefaults(scheme)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDefaults_KubeSchedulerConfiguration sets additional defaults
|
||||||
|
func SetDefaults_KubeSchedulerConfiguration(obj *v1alpha2.KubeSchedulerConfiguration) {
|
||||||
|
if obj.SchedulerName == nil {
|
||||||
|
val := api.DefaultSchedulerName
|
||||||
|
obj.SchedulerName = &val
|
||||||
|
}
|
||||||
|
|
||||||
|
if obj.HardPodAffinitySymmetricWeight == nil {
|
||||||
|
val := api.DefaultHardPodAffinitySymmetricWeight
|
||||||
|
obj.HardPodAffinitySymmetricWeight = &val
|
||||||
|
}
|
||||||
|
|
||||||
|
if obj.AlgorithmSource.Policy == nil &&
|
||||||
|
(obj.AlgorithmSource.Provider == nil || len(*obj.AlgorithmSource.Provider) == 0) {
|
||||||
|
val := v1alpha2.SchedulerDefaultProviderName
|
||||||
|
obj.AlgorithmSource.Provider = &val
|
||||||
|
}
|
||||||
|
|
||||||
|
if policy := obj.AlgorithmSource.Policy; policy != nil {
|
||||||
|
if policy.ConfigMap != nil && len(policy.ConfigMap.Namespace) == 0 {
|
||||||
|
obj.AlgorithmSource.Policy.ConfigMap.Namespace = api.NamespaceSystem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For Healthz and Metrics bind addresses, we want to check:
|
||||||
|
// 1. If the value is nil, default to 0.0.0.0 and default scheduler port
|
||||||
|
// 2. If there is a value set, attempt to split it. If it's just a port (ie, ":1234"), default to 0.0.0.0 with that port
|
||||||
|
// 3. If splitting the value fails, check if the value is even a valid IP. If so, use that with the default port.
|
||||||
|
// Otherwise use the default bind address
|
||||||
|
defaultBindAddress := net.JoinHostPort("0.0.0.0", strconv.Itoa(ports.InsecureSchedulerPort))
|
||||||
|
if obj.HealthzBindAddress == nil {
|
||||||
|
obj.HealthzBindAddress = &defaultBindAddress
|
||||||
|
} else {
|
||||||
|
if host, port, err := net.SplitHostPort(*obj.HealthzBindAddress); err == nil {
|
||||||
|
if len(host) == 0 {
|
||||||
|
host = "0.0.0.0"
|
||||||
|
}
|
||||||
|
hostPort := net.JoinHostPort(host, port)
|
||||||
|
obj.HealthzBindAddress = &hostPort
|
||||||
|
} else {
|
||||||
|
// Something went wrong splitting the host/port, could just be a missing port so check if the
|
||||||
|
// existing value is a valid IP address. If so, use that with the default scheduler port
|
||||||
|
if host := net.ParseIP(*obj.HealthzBindAddress); host != nil {
|
||||||
|
hostPort := net.JoinHostPort(*obj.HealthzBindAddress, strconv.Itoa(ports.InsecureSchedulerPort))
|
||||||
|
obj.HealthzBindAddress = &hostPort
|
||||||
|
} else {
|
||||||
|
// TODO: in v1beta1 we should let this error instead of stomping with a default value
|
||||||
|
obj.HealthzBindAddress = &defaultBindAddress
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if obj.MetricsBindAddress == nil {
|
||||||
|
obj.MetricsBindAddress = &defaultBindAddress
|
||||||
|
} else {
|
||||||
|
if host, port, err := net.SplitHostPort(*obj.MetricsBindAddress); err == nil {
|
||||||
|
if len(host) == 0 {
|
||||||
|
host = "0.0.0.0"
|
||||||
|
}
|
||||||
|
hostPort := net.JoinHostPort(host, port)
|
||||||
|
obj.MetricsBindAddress = &hostPort
|
||||||
|
} else {
|
||||||
|
// Something went wrong splitting the host/port, could just be a missing port so check if the
|
||||||
|
// existing value is a valid IP address. If so, use that with the default scheduler port
|
||||||
|
if host := net.ParseIP(*obj.MetricsBindAddress); host != nil {
|
||||||
|
hostPort := net.JoinHostPort(*obj.MetricsBindAddress, strconv.Itoa(ports.InsecureSchedulerPort))
|
||||||
|
obj.MetricsBindAddress = &hostPort
|
||||||
|
} else {
|
||||||
|
// TODO: in v1beta1 we should let this error instead of stomping with a default value
|
||||||
|
obj.MetricsBindAddress = &defaultBindAddress
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if obj.DisablePreemption == nil {
|
||||||
|
disablePreemption := false
|
||||||
|
obj.DisablePreemption = &disablePreemption
|
||||||
|
}
|
||||||
|
|
||||||
|
if obj.PercentageOfNodesToScore == nil {
|
||||||
|
percentageOfNodesToScore := int32(config.DefaultPercentageOfNodesToScore)
|
||||||
|
obj.PercentageOfNodesToScore = &percentageOfNodesToScore
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(obj.LeaderElection.ResourceLock) == 0 {
|
||||||
|
obj.LeaderElection.ResourceLock = "endpointsleases"
|
||||||
|
}
|
||||||
|
if len(obj.LeaderElection.LockObjectNamespace) == 0 && len(obj.LeaderElection.ResourceNamespace) == 0 {
|
||||||
|
obj.LeaderElection.LockObjectNamespace = v1alpha2.SchedulerDefaultLockObjectNamespace
|
||||||
|
}
|
||||||
|
if len(obj.LeaderElection.LockObjectName) == 0 && len(obj.LeaderElection.ResourceName) == 0 {
|
||||||
|
obj.LeaderElection.LockObjectName = v1alpha2.SchedulerDefaultLockObjectName
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(obj.ClientConnection.ContentType) == 0 {
|
||||||
|
obj.ClientConnection.ContentType = "application/vnd.kubernetes.protobuf"
|
||||||
|
}
|
||||||
|
// Scheduler has an opinion about QPS/Burst, setting specific defaults for itself, instead of generic settings.
|
||||||
|
if obj.ClientConnection.QPS == 0.0 {
|
||||||
|
obj.ClientConnection.QPS = 50.0
|
||||||
|
}
|
||||||
|
if obj.ClientConnection.Burst == 0 {
|
||||||
|
obj.ClientConnection.Burst = 100
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the default LeaderElectionConfiguration options
|
||||||
|
componentbaseconfigv1alpha1.RecommendedDefaultLeaderElectionConfiguration(&obj.LeaderElection.LeaderElectionConfiguration)
|
||||||
|
|
||||||
|
if obj.BindTimeoutSeconds == nil {
|
||||||
|
val := int64(600)
|
||||||
|
obj.BindTimeoutSeconds = &val
|
||||||
|
}
|
||||||
|
|
||||||
|
if obj.PodInitialBackoffSeconds == nil {
|
||||||
|
val := int64(1)
|
||||||
|
obj.PodInitialBackoffSeconds = &val
|
||||||
|
}
|
||||||
|
|
||||||
|
if obj.PodMaxBackoffSeconds == nil {
|
||||||
|
val := int64(10)
|
||||||
|
obj.PodMaxBackoffSeconds = &val
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable profiling by default in the scheduler
|
||||||
|
if obj.EnableProfiling == nil {
|
||||||
|
enableProfiling := true
|
||||||
|
obj.EnableProfiling = &enableProfiling
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable contention profiling by default if profiling is enabled
|
||||||
|
if *obj.EnableProfiling && obj.EnableContentionProfiling == nil {
|
||||||
|
enableContentionProfiling := true
|
||||||
|
obj.EnableContentionProfiling = &enableContentionProfiling
|
||||||
|
}
|
||||||
|
}
|
169
pkg/scheduler/apis/config/v1alpha2/defaults_test.go
Normal file
169
pkg/scheduler/apis/config/v1alpha2/defaults_test.go
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
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 v1alpha2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
componentbaseconfig "k8s.io/component-base/config/v1alpha1"
|
||||||
|
"k8s.io/kube-scheduler/config/v1alpha2"
|
||||||
|
"k8s.io/utils/pointer"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSchedulerDefaults(t *testing.T) {
|
||||||
|
enable := true
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
config *v1alpha2.KubeSchedulerConfiguration
|
||||||
|
expected *v1alpha2.KubeSchedulerConfiguration
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty config",
|
||||||
|
config: &v1alpha2.KubeSchedulerConfiguration{},
|
||||||
|
expected: &v1alpha2.KubeSchedulerConfiguration{
|
||||||
|
SchedulerName: pointer.StringPtr("default-scheduler"),
|
||||||
|
AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")},
|
||||||
|
HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1),
|
||||||
|
HealthzBindAddress: pointer.StringPtr("0.0.0.0:10251"),
|
||||||
|
MetricsBindAddress: pointer.StringPtr("0.0.0.0:10251"),
|
||||||
|
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||||
|
EnableProfiling: &enable,
|
||||||
|
EnableContentionProfiling: &enable,
|
||||||
|
},
|
||||||
|
LeaderElection: v1alpha2.KubeSchedulerLeaderElectionConfiguration{
|
||||||
|
LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
|
||||||
|
LeaderElect: pointer.BoolPtr(true),
|
||||||
|
LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
|
||||||
|
RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
|
||||||
|
RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
|
||||||
|
ResourceLock: "endpointsleases",
|
||||||
|
ResourceNamespace: "",
|
||||||
|
ResourceName: "",
|
||||||
|
},
|
||||||
|
LockObjectName: "kube-scheduler",
|
||||||
|
LockObjectNamespace: "kube-system",
|
||||||
|
},
|
||||||
|
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
|
||||||
|
QPS: 50,
|
||||||
|
Burst: 100,
|
||||||
|
ContentType: "application/vnd.kubernetes.protobuf",
|
||||||
|
},
|
||||||
|
DisablePreemption: pointer.BoolPtr(false),
|
||||||
|
PercentageOfNodesToScore: pointer.Int32Ptr(0),
|
||||||
|
BindTimeoutSeconds: pointer.Int64Ptr(600),
|
||||||
|
PodInitialBackoffSeconds: pointer.Int64Ptr(1),
|
||||||
|
PodMaxBackoffSeconds: pointer.Int64Ptr(10),
|
||||||
|
Plugins: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "metrics and healthz address with no port",
|
||||||
|
config: &v1alpha2.KubeSchedulerConfiguration{
|
||||||
|
MetricsBindAddress: pointer.StringPtr("1.2.3.4"),
|
||||||
|
HealthzBindAddress: pointer.StringPtr("1.2.3.4"),
|
||||||
|
},
|
||||||
|
expected: &v1alpha2.KubeSchedulerConfiguration{
|
||||||
|
SchedulerName: pointer.StringPtr("default-scheduler"),
|
||||||
|
AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")},
|
||||||
|
HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1),
|
||||||
|
HealthzBindAddress: pointer.StringPtr("1.2.3.4:10251"),
|
||||||
|
MetricsBindAddress: pointer.StringPtr("1.2.3.4:10251"),
|
||||||
|
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||||
|
EnableProfiling: &enable,
|
||||||
|
EnableContentionProfiling: &enable,
|
||||||
|
},
|
||||||
|
LeaderElection: v1alpha2.KubeSchedulerLeaderElectionConfiguration{
|
||||||
|
LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
|
||||||
|
LeaderElect: pointer.BoolPtr(true),
|
||||||
|
LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
|
||||||
|
RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
|
||||||
|
RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
|
||||||
|
ResourceLock: "endpointsleases",
|
||||||
|
ResourceNamespace: "",
|
||||||
|
ResourceName: "",
|
||||||
|
},
|
||||||
|
LockObjectName: "kube-scheduler",
|
||||||
|
LockObjectNamespace: "kube-system",
|
||||||
|
},
|
||||||
|
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
|
||||||
|
QPS: 50,
|
||||||
|
Burst: 100,
|
||||||
|
ContentType: "application/vnd.kubernetes.protobuf",
|
||||||
|
},
|
||||||
|
DisablePreemption: pointer.BoolPtr(false),
|
||||||
|
PercentageOfNodesToScore: pointer.Int32Ptr(0),
|
||||||
|
BindTimeoutSeconds: pointer.Int64Ptr(600),
|
||||||
|
PodInitialBackoffSeconds: pointer.Int64Ptr(1),
|
||||||
|
PodMaxBackoffSeconds: pointer.Int64Ptr(10),
|
||||||
|
Plugins: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "metrics and healthz port with no address",
|
||||||
|
config: &v1alpha2.KubeSchedulerConfiguration{
|
||||||
|
MetricsBindAddress: pointer.StringPtr(":12345"),
|
||||||
|
HealthzBindAddress: pointer.StringPtr(":12345"),
|
||||||
|
},
|
||||||
|
expected: &v1alpha2.KubeSchedulerConfiguration{
|
||||||
|
SchedulerName: pointer.StringPtr("default-scheduler"),
|
||||||
|
AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")},
|
||||||
|
HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1),
|
||||||
|
HealthzBindAddress: pointer.StringPtr("0.0.0.0:12345"),
|
||||||
|
MetricsBindAddress: pointer.StringPtr("0.0.0.0:12345"),
|
||||||
|
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||||
|
EnableProfiling: &enable,
|
||||||
|
EnableContentionProfiling: &enable,
|
||||||
|
},
|
||||||
|
LeaderElection: v1alpha2.KubeSchedulerLeaderElectionConfiguration{
|
||||||
|
LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
|
||||||
|
LeaderElect: pointer.BoolPtr(true),
|
||||||
|
LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
|
||||||
|
RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
|
||||||
|
RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
|
||||||
|
ResourceLock: "endpointsleases",
|
||||||
|
ResourceNamespace: "",
|
||||||
|
ResourceName: "",
|
||||||
|
},
|
||||||
|
LockObjectName: "kube-scheduler",
|
||||||
|
LockObjectNamespace: "kube-system",
|
||||||
|
},
|
||||||
|
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
|
||||||
|
QPS: 50,
|
||||||
|
Burst: 100,
|
||||||
|
ContentType: "application/vnd.kubernetes.protobuf",
|
||||||
|
},
|
||||||
|
DisablePreemption: pointer.BoolPtr(false),
|
||||||
|
PercentageOfNodesToScore: pointer.Int32Ptr(0),
|
||||||
|
BindTimeoutSeconds: pointer.Int64Ptr(600),
|
||||||
|
PodInitialBackoffSeconds: pointer.Int64Ptr(1),
|
||||||
|
PodMaxBackoffSeconds: pointer.Int64Ptr(10),
|
||||||
|
Plugins: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
SetDefaults_KubeSchedulerConfiguration(tc.config)
|
||||||
|
if !reflect.DeepEqual(tc.expected, tc.config) {
|
||||||
|
t.Errorf("Expected:\n%#v\n\nGot:\n%#v", tc.expected, tc.config)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
24
pkg/scheduler/apis/config/v1alpha2/doc.go
Normal file
24
pkg/scheduler/apis/config/v1alpha2/doc.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen=package
|
||||||
|
// +k8s:conversion-gen=k8s.io/kubernetes/pkg/scheduler/apis/config
|
||||||
|
// +k8s:conversion-gen-external-types=k8s.io/kube-scheduler/config/v1alpha2
|
||||||
|
// +k8s:defaulter-gen=TypeMeta
|
||||||
|
// +k8s:defaulter-gen-input=../../../../../vendor/k8s.io/kube-scheduler/config/v1alpha2
|
||||||
|
// +groupName=kubescheduler.config.k8s.io
|
||||||
|
|
||||||
|
package v1alpha2 // import "k8s.io/kubernetes/pkg/scheduler/apis/config/v1alpha2"
|
42
pkg/scheduler/apis/config/v1alpha2/register.go
Normal file
42
pkg/scheduler/apis/config/v1alpha2/register.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
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 v1alpha2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/kube-scheduler/config/v1alpha2"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GroupName is the group name used in this package
|
||||||
|
const GroupName = v1alpha2.GroupName
|
||||||
|
|
||||||
|
// SchemeGroupVersion is group version used to register these objects
|
||||||
|
var SchemeGroupVersion = v1alpha2.SchemeGroupVersion
|
||||||
|
|
||||||
|
var (
|
||||||
|
// localSchemeBuilder extends the SchemeBuilder instance with the external types. In this package,
|
||||||
|
// defaulting and conversion init funcs are registered as well.
|
||||||
|
localSchemeBuilder = &v1alpha2.SchemeBuilder
|
||||||
|
// AddToScheme is a global function that registers this API group & version to a scheme
|
||||||
|
AddToScheme = localSchemeBuilder.AddToScheme
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// We only register manually written functions here. The registration of the
|
||||||
|
// generated functions takes place in the generated files. The separation
|
||||||
|
// makes the code compile even when the generated files are missing.
|
||||||
|
localSchemeBuilder.Register(addDefaultingFuncs)
|
||||||
|
}
|
21
staging/src/k8s.io/kube-scheduler/config/v1alpha2/doc.go
Normal file
21
staging/src/k8s.io/kube-scheduler/config/v1alpha2/doc.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen=package
|
||||||
|
// +k8s:openapi-gen=true
|
||||||
|
// +groupName=kubescheduler.config.k8s.io
|
||||||
|
|
||||||
|
package v1alpha2 // import "k8s.io/kube-scheduler/config/v1alpha2"
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
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 v1alpha2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GroupName is the group name used in this package
|
||||||
|
const GroupName = "kubescheduler.config.k8s.io"
|
||||||
|
|
||||||
|
// SchemeGroupVersion is group version used to register these objects
|
||||||
|
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// SchemeBuilder is the scheme builder with scheme init functions to run for this API package
|
||||||
|
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
|
||||||
|
// AddToScheme is a global function that registers this API group & version to a scheme
|
||||||
|
AddToScheme = SchemeBuilder.AddToScheme
|
||||||
|
)
|
||||||
|
|
||||||
|
// addKnownTypes registers known types to the given scheme
|
||||||
|
func addKnownTypes(scheme *runtime.Scheme) error {
|
||||||
|
scheme.AddKnownTypes(SchemeGroupVersion,
|
||||||
|
&KubeSchedulerConfiguration{},
|
||||||
|
)
|
||||||
|
return nil
|
||||||
|
}
|
228
staging/src/k8s.io/kube-scheduler/config/v1alpha2/types.go
Normal file
228
staging/src/k8s.io/kube-scheduler/config/v1alpha2/types.go
Normal file
@ -0,0 +1,228 @@
|
|||||||
|
/*
|
||||||
|
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 v1alpha2
|
||||||
|
|
||||||
|
import (
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// SchedulerDefaultLockObjectNamespace defines default scheduler lock object namespace ("kube-system")
|
||||||
|
SchedulerDefaultLockObjectNamespace string = metav1.NamespaceSystem
|
||||||
|
|
||||||
|
// SchedulerDefaultLockObjectName defines default scheduler lock object name ("kube-scheduler")
|
||||||
|
SchedulerDefaultLockObjectName = "kube-scheduler"
|
||||||
|
|
||||||
|
// SchedulerDefaultProviderName defines the default provider names
|
||||||
|
SchedulerDefaultProviderName = "DefaultProvider"
|
||||||
|
)
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||||
|
|
||||||
|
// KubeSchedulerConfiguration configures a scheduler
|
||||||
|
type KubeSchedulerConfiguration struct {
|
||||||
|
metav1.TypeMeta `json:",inline"`
|
||||||
|
|
||||||
|
// SchedulerName is name of the scheduler, used to select which pods
|
||||||
|
// will be processed by this scheduler, based on pod's "spec.SchedulerName".
|
||||||
|
SchedulerName *string `json:"schedulerName,omitempty"`
|
||||||
|
// AlgorithmSource specifies the scheduler algorithm source.
|
||||||
|
AlgorithmSource SchedulerAlgorithmSource `json:"algorithmSource"`
|
||||||
|
// RequiredDuringScheduling affinity is not symmetric, but there is an implicit PreferredDuringScheduling affinity rule
|
||||||
|
// corresponding to every RequiredDuringScheduling affinity rule.
|
||||||
|
// HardPodAffinitySymmetricWeight represents the weight of implicit PreferredDuringScheduling affinity rule, in the range 0-100.
|
||||||
|
HardPodAffinitySymmetricWeight *int32 `json:"hardPodAffinitySymmetricWeight,omitempty"`
|
||||||
|
|
||||||
|
// LeaderElection defines the configuration of leader election client.
|
||||||
|
LeaderElection KubeSchedulerLeaderElectionConfiguration `json:"leaderElection"`
|
||||||
|
|
||||||
|
// ClientConnection specifies the kubeconfig file and client connection
|
||||||
|
// settings for the proxy server to use when communicating with the apiserver.
|
||||||
|
ClientConnection componentbaseconfigv1alpha1.ClientConnectionConfiguration `json:"clientConnection"`
|
||||||
|
// HealthzBindAddress is the IP address and port for the health check server to serve on,
|
||||||
|
// defaulting to 0.0.0.0:10251
|
||||||
|
HealthzBindAddress *string `json:"healthzBindAddress,omitempty"`
|
||||||
|
// MetricsBindAddress is the IP address and port for the metrics server to
|
||||||
|
// serve on, defaulting to 0.0.0.0:10251.
|
||||||
|
MetricsBindAddress *string `json:"metricsBindAddress,omitempty"`
|
||||||
|
|
||||||
|
// DebuggingConfiguration holds configuration for Debugging related features
|
||||||
|
// TODO: We might wanna make this a substruct like Debugging componentbaseconfigv1alpha1.DebuggingConfiguration
|
||||||
|
componentbaseconfigv1alpha1.DebuggingConfiguration `json:",inline"`
|
||||||
|
|
||||||
|
// DisablePreemption disables the pod preemption feature.
|
||||||
|
DisablePreemption *bool `json:"disablePreemption,omitempty"`
|
||||||
|
|
||||||
|
// PercentageOfNodeToScore is the percentage of all nodes that once found feasible
|
||||||
|
// for running a pod, the scheduler stops its search for more feasible nodes in
|
||||||
|
// the cluster. This helps improve scheduler's performance. Scheduler always tries to find
|
||||||
|
// at least "minFeasibleNodesToFind" feasible nodes no matter what the value of this flag is.
|
||||||
|
// Example: if the cluster size is 500 nodes and the value of this flag is 30,
|
||||||
|
// then scheduler stops finding further feasible nodes once it finds 150 feasible ones.
|
||||||
|
// When the value is 0, default percentage (5%--50% based on the size of the cluster) of the
|
||||||
|
// nodes will be scored.
|
||||||
|
PercentageOfNodesToScore *int32 `json:"percentageOfNodesToScore,omitempty"`
|
||||||
|
|
||||||
|
// Duration to wait for a binding operation to complete before timing out
|
||||||
|
// Value must be non-negative integer. The value zero indicates no waiting.
|
||||||
|
// If this value is nil, the default value will be used.
|
||||||
|
BindTimeoutSeconds *int64 `json:"bindTimeoutSeconds"`
|
||||||
|
|
||||||
|
// PodInitialBackoffSeconds is the initial backoff for unschedulable pods.
|
||||||
|
// If specified, it must be greater than 0. If this value is null, the default value (1s)
|
||||||
|
// will be used.
|
||||||
|
PodInitialBackoffSeconds *int64 `json:"podInitialBackoffSeconds"`
|
||||||
|
|
||||||
|
// PodMaxBackoffSeconds is the max backoff for unschedulable pods.
|
||||||
|
// If specified, it must be greater than podInitialBackoffSeconds. If this value is null,
|
||||||
|
// the default value (10s) will be used.
|
||||||
|
PodMaxBackoffSeconds *int64 `json:"podMaxBackoffSeconds"`
|
||||||
|
|
||||||
|
// Plugins specify the set of plugins that should be enabled or disabled. Enabled plugins are the
|
||||||
|
// ones that should be enabled in addition to the default plugins. Disabled plugins are any of the
|
||||||
|
// default plugins that should be disabled.
|
||||||
|
// When no enabled or disabled plugin is specified for an extension point, default plugins for
|
||||||
|
// that extension point will be used if there is any.
|
||||||
|
Plugins *Plugins `json:"plugins,omitempty"`
|
||||||
|
|
||||||
|
// PluginConfig is an optional set of custom plugin arguments for each plugin.
|
||||||
|
// Omitting config args for a plugin is equivalent to using the default config for that plugin.
|
||||||
|
// +listType=map
|
||||||
|
// +listMapKey=name
|
||||||
|
PluginConfig []PluginConfig `json:"pluginConfig,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SchedulerAlgorithmSource is the source of a scheduler algorithm. One source
|
||||||
|
// field must be specified, and source fields are mutually exclusive.
|
||||||
|
type SchedulerAlgorithmSource struct {
|
||||||
|
// Policy is a policy based algorithm source.
|
||||||
|
Policy *SchedulerPolicySource `json:"policy,omitempty"`
|
||||||
|
// Provider is the name of a scheduling algorithm provider to use.
|
||||||
|
Provider *string `json:"provider,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SchedulerPolicySource configures a means to obtain a scheduler Policy. One
|
||||||
|
// source field must be specified, and source fields are mutually exclusive.
|
||||||
|
type SchedulerPolicySource struct {
|
||||||
|
// File is a file policy source.
|
||||||
|
File *SchedulerPolicyFileSource `json:"file,omitempty"`
|
||||||
|
// ConfigMap is a config map policy source.
|
||||||
|
ConfigMap *SchedulerPolicyConfigMapSource `json:"configMap,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SchedulerPolicyFileSource is a policy serialized to disk and accessed via
|
||||||
|
// path.
|
||||||
|
type SchedulerPolicyFileSource struct {
|
||||||
|
// Path is the location of a serialized policy.
|
||||||
|
Path string `json:"path"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SchedulerPolicyConfigMapSource is a policy serialized into a config map value
|
||||||
|
// under the SchedulerPolicyConfigMapKey key.
|
||||||
|
type SchedulerPolicyConfigMapSource struct {
|
||||||
|
// Namespace is the namespace of the policy config map.
|
||||||
|
Namespace string `json:"namespace"`
|
||||||
|
// Name is the name of hte policy config map.
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// KubeSchedulerLeaderElectionConfiguration expands LeaderElectionConfiguration
|
||||||
|
// to include scheduler specific configuration.
|
||||||
|
type KubeSchedulerLeaderElectionConfiguration struct {
|
||||||
|
componentbaseconfigv1alpha1.LeaderElectionConfiguration `json:",inline"`
|
||||||
|
// LockObjectNamespace defines the namespace of the lock object
|
||||||
|
// DEPRECATED: will be removed in favor of resourceNamespace
|
||||||
|
LockObjectNamespace string `json:"lockObjectNamespace"`
|
||||||
|
// LockObjectName defines the lock object name
|
||||||
|
// DEPRECATED: will be removed in favor of resourceName
|
||||||
|
LockObjectName string `json:"lockObjectName"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Plugins include multiple extension points. When specified, the list of plugins for
|
||||||
|
// a particular extension point are the only ones enabled. If an extension point is
|
||||||
|
// omitted from the config, then the default set of plugins is used for that extension point.
|
||||||
|
// Enabled plugins are called in the order specified here, after default plugins. If they need to
|
||||||
|
// be invoked before default plugins, default plugins must be disabled and re-enabled here in desired order.
|
||||||
|
type Plugins struct {
|
||||||
|
// QueueSort is a list of plugins that should be invoked when sorting pods in the scheduling queue.
|
||||||
|
QueueSort *PluginSet `json:"queueSort,omitempty"`
|
||||||
|
|
||||||
|
// PreFilter is a list of plugins that should be invoked at "PreFilter" extension point of the scheduling framework.
|
||||||
|
PreFilter *PluginSet `json:"preFilter,omitempty"`
|
||||||
|
|
||||||
|
// Filter is a list of plugins that should be invoked when filtering out nodes that cannot run the Pod.
|
||||||
|
Filter *PluginSet `json:"filter,omitempty"`
|
||||||
|
|
||||||
|
// PostFilter is a list of plugins that are invoked after filtering out infeasible nodes.
|
||||||
|
PostFilter *PluginSet `json:"postFilter,omitempty"`
|
||||||
|
|
||||||
|
// Score is a list of plugins that should be invoked when ranking nodes that have passed the filtering phase.
|
||||||
|
Score *PluginSet `json:"score,omitempty"`
|
||||||
|
|
||||||
|
// Reserve is a list of plugins invoked when reserving a node to run the pod.
|
||||||
|
Reserve *PluginSet `json:"reserve,omitempty"`
|
||||||
|
|
||||||
|
// Permit is a list of plugins that control binding of a Pod. These plugins can prevent or delay binding of a Pod.
|
||||||
|
Permit *PluginSet `json:"permit,omitempty"`
|
||||||
|
|
||||||
|
// PreBind is a list of plugins that should be invoked before a pod is bound.
|
||||||
|
PreBind *PluginSet `json:"preBind,omitempty"`
|
||||||
|
|
||||||
|
// Bind is a list of plugins that should be invoked at "Bind" extension point of the scheduling framework.
|
||||||
|
// The scheduler call these plugins in order. Scheduler skips the rest of these plugins as soon as one returns success.
|
||||||
|
Bind *PluginSet `json:"bind,omitempty"`
|
||||||
|
|
||||||
|
// PostBind is a list of plugins that should be invoked after a pod is successfully bound.
|
||||||
|
PostBind *PluginSet `json:"postBind,omitempty"`
|
||||||
|
|
||||||
|
// Unreserve is a list of plugins invoked when a pod that was previously reserved is rejected in a later phase.
|
||||||
|
Unreserve *PluginSet `json:"unreserve,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PluginSet specifies enabled and disabled plugins for an extension point.
|
||||||
|
// If an array is empty, missing, or nil, default plugins at that extension point will be used.
|
||||||
|
type PluginSet struct {
|
||||||
|
// Enabled specifies plugins that should be enabled in addition to default plugins.
|
||||||
|
// These are called after default plugins and in the same order specified here.
|
||||||
|
// +listType=atomic
|
||||||
|
Enabled []Plugin `json:"enabled,omitempty"`
|
||||||
|
// Disabled specifies default plugins that should be disabled.
|
||||||
|
// When all default plugins need to be disabled, an array containing only one "*" should be provided.
|
||||||
|
// +listType=map
|
||||||
|
// +listMapKey=name
|
||||||
|
Disabled []Plugin `json:"disabled,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Plugin specifies a plugin name and its weight when applicable. Weight is used only for Score plugins.
|
||||||
|
type Plugin struct {
|
||||||
|
// Name defines the name of plugin
|
||||||
|
Name string `json:"name"`
|
||||||
|
// Weight defines the weight of plugin, only used for Score plugins.
|
||||||
|
Weight *int32 `json:"weight,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PluginConfig specifies arguments that should be passed to a plugin at the time of initialization.
|
||||||
|
// A plugin that is invoked at multiple extension points is initialized once. Args can have arbitrary structure.
|
||||||
|
// It is up to the plugin to process these Args.
|
||||||
|
type PluginConfig struct {
|
||||||
|
// Name defines the name of plugin being configured
|
||||||
|
Name string `json:"name"`
|
||||||
|
// Args defines the arguments passed to the plugins at the time of initialization. Args can have arbitrary structure.
|
||||||
|
Args runtime.Unknown `json:"args,omitempty"`
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user