Change scheduler ComponentConfig fields to nilable

As part of graduating the scheduler's component config to beta, we require configurable fields to be nilable pointers (see https://github.com/kubernetes/kubernetes/issues/78109). This enables the ability to distinguish between default and unset values. We are only applying this change to external types, and reacting in our defaulting logic. This also reverts existing internal component config fields which were pointers to be non-pointers, for consistency.
This commit is contained in:
Mike Dame 2019-11-04 16:43:39 -05:00
parent de56c90540
commit 9e2591f867
14 changed files with 630 additions and 172 deletions

View File

@ -277,9 +277,10 @@ pluginConfig:
Burst: 100, Burst: 100,
ContentType: "application/vnd.kubernetes.protobuf", ContentType: "application/vnd.kubernetes.protobuf",
}, },
BindTimeoutSeconds: &defaultBindTimeoutSeconds, PercentageOfNodesToScore: 50,
PodInitialBackoffSeconds: &defaultPodInitialBackoffSeconds, BindTimeoutSeconds: defaultBindTimeoutSeconds,
PodMaxBackoffSeconds: &defaultPodMaxBackoffSeconds, PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds,
PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds,
Plugins: nil, Plugins: nil,
}, },
}, },
@ -359,14 +360,20 @@ pluginConfig:
Burst: 100, Burst: 100,
ContentType: "application/vnd.kubernetes.protobuf", ContentType: "application/vnd.kubernetes.protobuf",
}, },
BindTimeoutSeconds: &defaultBindTimeoutSeconds, PercentageOfNodesToScore: 50,
PodInitialBackoffSeconds: &defaultPodInitialBackoffSeconds, BindTimeoutSeconds: defaultBindTimeoutSeconds,
PodMaxBackoffSeconds: &defaultPodMaxBackoffSeconds, PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds,
PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds,
}, },
}, },
{ {
name: "overridden master", name: "overridden master",
options: &Options{ options: &Options{
ComponentConfig: func() kubeschedulerconfig.KubeSchedulerConfiguration {
cfg, _ := newDefaultComponentConfig()
cfg.ClientConnection.Kubeconfig = flagKubeconfig
return *cfg
}(),
Master: insecureserver.URL, Master: insecureserver.URL,
SecureServing: (&apiserveroptions.SecureServingOptions{ SecureServing: (&apiserveroptions.SecureServingOptions{
ServerCert: apiserveroptions.GeneratableKeyCert{ ServerCert: apiserveroptions.GeneratableKeyCert{
@ -391,6 +398,34 @@ pluginConfig:
AlwaysAllowPaths: []string{"/healthz"}, // note: this does not match /healthz/ or /healthz/* AlwaysAllowPaths: []string{"/healthz"}, // note: this does not match /healthz/ or /healthz/*
}, },
}, },
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
SchedulerName: "default-scheduler",
AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
HardPodAffinitySymmetricWeight: 1,
HealthzBindAddress: "", // defaults empty when not running from config file
MetricsBindAddress: "", // defaults empty when not running from config file
LeaderElection: kubeschedulerconfig.KubeSchedulerLeaderElectionConfiguration{
LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
LeaderElect: 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: "kube-system",
ResourceName: "kube-scheduler",
},
},
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
Kubeconfig: flagKubeconfig,
QPS: 50,
Burst: 100,
ContentType: "application/vnd.kubernetes.protobuf",
},
PercentageOfNodesToScore: 50,
BindTimeoutSeconds: defaultBindTimeoutSeconds,
PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds,
PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds,
},
expectedUsername: "none, http", expectedUsername: "none, http",
}, },
{ {
@ -422,9 +457,10 @@ pluginConfig:
Burst: 100, Burst: 100,
ContentType: "application/vnd.kubernetes.protobuf", ContentType: "application/vnd.kubernetes.protobuf",
}, },
BindTimeoutSeconds: &defaultBindTimeoutSeconds, PercentageOfNodesToScore: 50,
PodInitialBackoffSeconds: &defaultPodInitialBackoffSeconds, BindTimeoutSeconds: defaultBindTimeoutSeconds,
PodMaxBackoffSeconds: &defaultPodMaxBackoffSeconds, PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds,
PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds,
Plugins: &kubeschedulerconfig.Plugins{ Plugins: &kubeschedulerconfig.Plugins{
Reserve: &kubeschedulerconfig.PluginSet{ Reserve: &kubeschedulerconfig.PluginSet{
Enabled: []kubeschedulerconfig.Plugin{ Enabled: []kubeschedulerconfig.Plugin{
@ -499,9 +535,10 @@ pluginConfig:
Burst: 100, Burst: 100,
ContentType: "application/vnd.kubernetes.protobuf", ContentType: "application/vnd.kubernetes.protobuf",
}, },
BindTimeoutSeconds: &defaultBindTimeoutSeconds, PercentageOfNodesToScore: 50,
PodInitialBackoffSeconds: &defaultPodInitialBackoffSeconds, BindTimeoutSeconds: defaultBindTimeoutSeconds,
PodMaxBackoffSeconds: &defaultPodMaxBackoffSeconds, PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds,
PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds,
Plugins: nil, Plugins: nil,
}, },
}, },
@ -537,9 +574,10 @@ pluginConfig:
Burst: 100, Burst: 100,
ContentType: "application/vnd.kubernetes.protobuf", ContentType: "application/vnd.kubernetes.protobuf",
}, },
BindTimeoutSeconds: &defaultBindTimeoutSeconds, PercentageOfNodesToScore: 50,
PodInitialBackoffSeconds: &defaultPodInitialBackoffSeconds, BindTimeoutSeconds: defaultBindTimeoutSeconds,
PodMaxBackoffSeconds: &defaultPodMaxBackoffSeconds, PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds,
PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds,
Plugins: nil, Plugins: nil,
}, },
}, },

View File

@ -193,12 +193,12 @@ func Run(ctx context.Context, cc schedulerserverconfig.CompletedConfig, outOfTre
scheduler.WithHardPodAffinitySymmetricWeight(cc.ComponentConfig.HardPodAffinitySymmetricWeight), scheduler.WithHardPodAffinitySymmetricWeight(cc.ComponentConfig.HardPodAffinitySymmetricWeight),
scheduler.WithPreemptionDisabled(cc.ComponentConfig.DisablePreemption), scheduler.WithPreemptionDisabled(cc.ComponentConfig.DisablePreemption),
scheduler.WithPercentageOfNodesToScore(cc.ComponentConfig.PercentageOfNodesToScore), scheduler.WithPercentageOfNodesToScore(cc.ComponentConfig.PercentageOfNodesToScore),
scheduler.WithBindTimeoutSeconds(*cc.ComponentConfig.BindTimeoutSeconds), scheduler.WithBindTimeoutSeconds(cc.ComponentConfig.BindTimeoutSeconds),
scheduler.WithFrameworkOutOfTreeRegistry(outOfTreeRegistry), scheduler.WithFrameworkOutOfTreeRegistry(outOfTreeRegistry),
scheduler.WithFrameworkPlugins(cc.ComponentConfig.Plugins), scheduler.WithFrameworkPlugins(cc.ComponentConfig.Plugins),
scheduler.WithFrameworkPluginConfig(cc.ComponentConfig.PluginConfig), scheduler.WithFrameworkPluginConfig(cc.ComponentConfig.PluginConfig),
scheduler.WithPodMaxBackoffSeconds(*cc.ComponentConfig.PodMaxBackoffSeconds), scheduler.WithPodMaxBackoffSeconds(cc.ComponentConfig.PodMaxBackoffSeconds),
scheduler.WithPodInitialBackoffSeconds(*cc.ComponentConfig.PodInitialBackoffSeconds), scheduler.WithPodInitialBackoffSeconds(cc.ComponentConfig.PodInitialBackoffSeconds),
) )
if err != nil { if err != nil {
return err return err

View File

@ -88,17 +88,17 @@ type KubeSchedulerConfiguration struct {
// Duration to wait for a binding operation to complete before timing out // Duration to wait for a binding operation to complete before timing out
// Value must be non-negative integer. The value zero indicates no waiting. // Value must be non-negative integer. The value zero indicates no waiting.
// If this value is nil, the default value will be used. // If this value is nil, the default value will be used.
BindTimeoutSeconds *int64 BindTimeoutSeconds int64
// PodInitialBackoffSeconds is the initial backoff for unschedulable pods. // 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) // If specified, it must be greater than 0. If this value is null, the default value (1s)
// will be used. // will be used.
PodInitialBackoffSeconds *int64 PodInitialBackoffSeconds int64
// PodMaxBackoffSeconds is the max backoff for unschedulable pods. // PodMaxBackoffSeconds is the max backoff for unschedulable pods.
// If specified, it must be greater than podInitialBackoffSeconds. If this value is null, // If specified, it must be greater than podInitialBackoffSeconds. If this value is null,
// the default value (10s) will be used. // the default value (10s) will be used.
PodMaxBackoffSeconds *int64 PodMaxBackoffSeconds int64
// Plugins specify the set of plugins that should be enabled or disabled. Enabled plugins are the // 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 // ones that should be enabled in addition to the default plugins. Disabled plugins are any of the

View File

@ -17,6 +17,7 @@ go_library(
"//pkg/apis/core:go_default_library", "//pkg/apis/core:go_default_library",
"//pkg/master/ports:go_default_library", "//pkg/master/ports:go_default_library",
"//pkg/scheduler/apis/config:go_default_library", "//pkg/scheduler/apis/config:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
@ -34,13 +35,12 @@ go_test(
embed = [":go_default_library"], embed = [":go_default_library"],
deps = [ deps = [
"//pkg/scheduler/apis/config:go_default_library", "//pkg/scheduler/apis/config:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/component-base/config:go_default_library", "//staging/src/k8s.io/component-base/config:go_default_library",
"//staging/src/k8s.io/component-base/config/v1alpha1:go_default_library", "//staging/src/k8s.io/component-base/config/v1alpha1:go_default_library",
"//staging/src/k8s.io/kube-scheduler/config/v1alpha1:go_default_library", "//staging/src/k8s.io/kube-scheduler/config/v1alpha1:go_default_library",
"//vendor/k8s.io/utils/pointer:go_default_library",
], ],
) )

View File

@ -27,6 +27,7 @@ import (
// this package shouldn't really depend on other k8s.io/kubernetes code // this package shouldn't really depend on other k8s.io/kubernetes code
api "k8s.io/kubernetes/pkg/apis/core" api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/master/ports" "k8s.io/kubernetes/pkg/master/ports"
"k8s.io/kubernetes/pkg/scheduler/apis/config"
) )
func addDefaultingFuncs(scheme *runtime.Scheme) error { func addDefaultingFuncs(scheme *runtime.Scheme) error {
@ -35,12 +36,14 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {
// SetDefaults_KubeSchedulerConfiguration sets additional defaults // SetDefaults_KubeSchedulerConfiguration sets additional defaults
func SetDefaults_KubeSchedulerConfiguration(obj *kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration) { func SetDefaults_KubeSchedulerConfiguration(obj *kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration) {
if len(obj.SchedulerName) == 0 { if obj.SchedulerName == nil {
obj.SchedulerName = api.DefaultSchedulerName val := api.DefaultSchedulerName
obj.SchedulerName = &val
} }
if obj.HardPodAffinitySymmetricWeight == 0 { if obj.HardPodAffinitySymmetricWeight == nil {
obj.HardPodAffinitySymmetricWeight = api.DefaultHardPodAffinitySymmetricWeight val := api.DefaultHardPodAffinitySymmetricWeight
obj.HardPodAffinitySymmetricWeight = &val
} }
if obj.AlgorithmSource.Policy == nil && if obj.AlgorithmSource.Policy == nil &&
@ -55,22 +58,64 @@ func SetDefaults_KubeSchedulerConfiguration(obj *kubeschedulerconfigv1alpha1.Kub
} }
} }
if host, port, err := net.SplitHostPort(obj.HealthzBindAddress); err == nil { // 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 { if len(host) == 0 {
host = "0.0.0.0" host = "0.0.0.0"
} }
obj.HealthzBindAddress = net.JoinHostPort(host, port) hostPort := net.JoinHostPort(host, port)
obj.HealthzBindAddress = &hostPort
} else { } else {
obj.HealthzBindAddress = net.JoinHostPort("0.0.0.0", strconv.Itoa(ports.InsecureSchedulerPort)) // 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 host, port, err := net.SplitHostPort(obj.MetricsBindAddress); err == nil { if obj.MetricsBindAddress == nil {
obj.MetricsBindAddress = &defaultBindAddress
} else {
if host, port, err := net.SplitHostPort(*obj.MetricsBindAddress); err == nil {
if len(host) == 0 { if len(host) == 0 {
host = "0.0.0.0" host = "0.0.0.0"
} }
obj.MetricsBindAddress = net.JoinHostPort(host, port) hostPort := net.JoinHostPort(host, port)
obj.MetricsBindAddress = &hostPort
} else { } else {
obj.MetricsBindAddress = net.JoinHostPort("0.0.0.0", strconv.Itoa(ports.InsecureSchedulerPort)) // 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 { if len(obj.LeaderElection.ResourceLock) == 0 {
@ -98,17 +143,17 @@ func SetDefaults_KubeSchedulerConfiguration(obj *kubeschedulerconfigv1alpha1.Kub
componentbaseconfigv1alpha1.RecommendedDefaultLeaderElectionConfiguration(&obj.LeaderElection.LeaderElectionConfiguration) componentbaseconfigv1alpha1.RecommendedDefaultLeaderElectionConfiguration(&obj.LeaderElection.LeaderElectionConfiguration)
if obj.BindTimeoutSeconds == nil { if obj.BindTimeoutSeconds == nil {
defaultBindTimeoutSeconds := int64(600) val := int64(600)
obj.BindTimeoutSeconds = &defaultBindTimeoutSeconds obj.BindTimeoutSeconds = &val
} }
if obj.PodInitialBackoffSeconds == nil { if obj.PodInitialBackoffSeconds == nil {
defaultPodInitialBackoffSeconds := int64(1) val := int64(1)
obj.PodInitialBackoffSeconds = &defaultPodInitialBackoffSeconds obj.PodInitialBackoffSeconds = &val
} }
if obj.PodMaxBackoffSeconds == nil { if obj.PodMaxBackoffSeconds == nil {
defaultPodMaxBackoffSeconds := int64(10) val := int64(10)
obj.PodMaxBackoffSeconds = &defaultPodMaxBackoffSeconds obj.PodMaxBackoffSeconds = &val
} }
} }

View File

@ -17,48 +17,140 @@ limitations under the License.
package v1alpha1 package v1alpha1
import ( import (
"encoding/json"
"reflect" "reflect"
"testing" "testing"
"time"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" componentbaseconfig "k8s.io/component-base/config/v1alpha1"
kubeschedulerconfigv1alpha1 "k8s.io/kube-scheduler/config/v1alpha1" kubeschedulerconfigv1alpha1 "k8s.io/kube-scheduler/config/v1alpha1"
"k8s.io/utils/pointer"
) )
func TestSchedulerDefaults(t *testing.T) { func TestSchedulerDefaults(t *testing.T) {
ks1 := &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{} tests := []struct {
SetDefaults_KubeSchedulerConfiguration(ks1) name string
cm, err := convertObjToConfigMap("KubeSchedulerConfiguration", ks1) config *kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration
if err != nil { expected *kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration
t.Errorf("unexpected ConvertObjToConfigMap error %v", err) }{
} {
name: "empty config",
ks2 := &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{} config: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{},
if err = json.Unmarshal([]byte(cm.Data["KubeSchedulerConfiguration"]), ks2); err != nil { expected: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{
t.Errorf("unexpected error unserializing scheduler config %v", err) SchedulerName: pointer.StringPtr("default-scheduler"),
} AlgorithmSource: kubeschedulerconfigv1alpha1.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")},
HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1),
if !reflect.DeepEqual(ks2, ks1) { HealthzBindAddress: pointer.StringPtr("0.0.0.0:10251"),
t.Errorf("Expected:\n%#v\n\nGot:\n%#v", ks1, ks2) MetricsBindAddress: pointer.StringPtr("0.0.0.0:10251"),
} LeaderElection: kubeschedulerconfigv1alpha1.KubeSchedulerLeaderElectionConfiguration{
} LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
LeaderElect: pointer.BoolPtr(true),
// ConvertObjToConfigMap converts an object to a ConfigMap. LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
// This is specifically meant for ComponentConfigs. RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
func convertObjToConfigMap(name string, obj runtime.Object) (*v1.ConfigMap, error) { RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
eJSONBytes, err := json.Marshal(obj) ResourceLock: "endpointsleases",
if err != nil { ResourceNamespace: "",
return nil, err ResourceName: "",
} },
cm := &v1.ConfigMap{ LockObjectName: "kube-scheduler",
ObjectMeta: metav1.ObjectMeta{ LockObjectNamespace: "kube-system",
Name: name, },
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
QPS: 50,
Burst: 100,
ContentType: "application/vnd.kubernetes.protobuf",
},
DisablePreemption: pointer.BoolPtr(false),
PercentageOfNodesToScore: pointer.Int32Ptr(50),
BindTimeoutSeconds: pointer.Int64Ptr(600),
PodInitialBackoffSeconds: pointer.Int64Ptr(1),
PodMaxBackoffSeconds: pointer.Int64Ptr(10),
Plugins: nil,
},
},
{
name: "metrics and healthz address with no port",
config: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{
MetricsBindAddress: pointer.StringPtr("1.2.3.4"),
HealthzBindAddress: pointer.StringPtr("1.2.3.4"),
},
expected: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{
SchedulerName: pointer.StringPtr("default-scheduler"),
AlgorithmSource: kubeschedulerconfigv1alpha1.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"),
LeaderElection: kubeschedulerconfigv1alpha1.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(50),
BindTimeoutSeconds: pointer.Int64Ptr(600),
PodInitialBackoffSeconds: pointer.Int64Ptr(1),
PodMaxBackoffSeconds: pointer.Int64Ptr(10),
Plugins: nil,
},
},
{
name: "metrics and healthz port with no address",
config: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{
MetricsBindAddress: pointer.StringPtr(":12345"),
HealthzBindAddress: pointer.StringPtr(":12345"),
},
expected: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{
SchedulerName: pointer.StringPtr("default-scheduler"),
AlgorithmSource: kubeschedulerconfigv1alpha1.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"),
LeaderElection: kubeschedulerconfigv1alpha1.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(50),
BindTimeoutSeconds: pointer.Int64Ptr(600),
PodInitialBackoffSeconds: pointer.Int64Ptr(1),
PodMaxBackoffSeconds: pointer.Int64Ptr(10),
Plugins: nil,
}, },
Data: map[string]string{
name: string(eJSONBytes[:]),
}, },
} }
return cm, 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)
}
})
}
} }

View File

@ -23,6 +23,7 @@ package v1alpha1
import ( import (
unsafe "unsafe" unsafe "unsafe"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
conversion "k8s.io/apimachinery/pkg/conversion" conversion "k8s.io/apimachinery/pkg/conversion"
runtime "k8s.io/apimachinery/pkg/runtime" runtime "k8s.io/apimachinery/pkg/runtime"
componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1" componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1"
@ -141,28 +142,54 @@ func RegisterConversions(s *runtime.Scheme) error {
} }
func autoConvert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in *v1alpha1.KubeSchedulerConfiguration, out *config.KubeSchedulerConfiguration, s conversion.Scope) error { func autoConvert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in *v1alpha1.KubeSchedulerConfiguration, out *config.KubeSchedulerConfiguration, s conversion.Scope) error {
out.SchedulerName = in.SchedulerName if err := v1.Convert_Pointer_string_To_string(&in.SchedulerName, &out.SchedulerName, s); err != nil {
return err
}
if err := Convert_v1alpha1_SchedulerAlgorithmSource_To_config_SchedulerAlgorithmSource(&in.AlgorithmSource, &out.AlgorithmSource, s); err != nil { if err := Convert_v1alpha1_SchedulerAlgorithmSource_To_config_SchedulerAlgorithmSource(&in.AlgorithmSource, &out.AlgorithmSource, s); err != nil {
return err return err
} }
out.HardPodAffinitySymmetricWeight = in.HardPodAffinitySymmetricWeight if err := v1.Convert_Pointer_int32_To_int32(&in.HardPodAffinitySymmetricWeight, &out.HardPodAffinitySymmetricWeight, s); err != nil {
return err
}
if err := Convert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil { if err := Convert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil {
return err return err
} }
if err := componentbaseconfigv1alpha1.Convert_v1alpha1_ClientConnectionConfiguration_To_config_ClientConnectionConfiguration(&in.ClientConnection, &out.ClientConnection, s); err != nil { if err := componentbaseconfigv1alpha1.Convert_v1alpha1_ClientConnectionConfiguration_To_config_ClientConnectionConfiguration(&in.ClientConnection, &out.ClientConnection, s); err != nil {
return err return err
} }
out.HealthzBindAddress = in.HealthzBindAddress if err := v1.Convert_Pointer_string_To_string(&in.HealthzBindAddress, &out.HealthzBindAddress, s); err != nil {
out.MetricsBindAddress = in.MetricsBindAddress return err
}
if err := v1.Convert_Pointer_string_To_string(&in.MetricsBindAddress, &out.MetricsBindAddress, s); err != nil {
return err
}
if err := componentbaseconfigv1alpha1.Convert_v1alpha1_DebuggingConfiguration_To_config_DebuggingConfiguration(&in.DebuggingConfiguration, &out.DebuggingConfiguration, s); err != nil { if err := componentbaseconfigv1alpha1.Convert_v1alpha1_DebuggingConfiguration_To_config_DebuggingConfiguration(&in.DebuggingConfiguration, &out.DebuggingConfiguration, s); err != nil {
return err return err
} }
out.DisablePreemption = in.DisablePreemption if err := v1.Convert_Pointer_bool_To_bool(&in.DisablePreemption, &out.DisablePreemption, s); err != nil {
out.PercentageOfNodesToScore = in.PercentageOfNodesToScore return err
out.BindTimeoutSeconds = (*int64)(unsafe.Pointer(in.BindTimeoutSeconds)) }
out.PodInitialBackoffSeconds = (*int64)(unsafe.Pointer(in.PodInitialBackoffSeconds)) if err := v1.Convert_Pointer_int32_To_int32(&in.PercentageOfNodesToScore, &out.PercentageOfNodesToScore, s); err != nil {
out.PodMaxBackoffSeconds = (*int64)(unsafe.Pointer(in.PodMaxBackoffSeconds)) return err
out.Plugins = (*config.Plugins)(unsafe.Pointer(in.Plugins)) }
if err := v1.Convert_Pointer_int64_To_int64(&in.BindTimeoutSeconds, &out.BindTimeoutSeconds, s); err != nil {
return err
}
if err := v1.Convert_Pointer_int64_To_int64(&in.PodInitialBackoffSeconds, &out.PodInitialBackoffSeconds, s); err != nil {
return err
}
if err := v1.Convert_Pointer_int64_To_int64(&in.PodMaxBackoffSeconds, &out.PodMaxBackoffSeconds, s); err != nil {
return err
}
if in.Plugins != nil {
in, out := &in.Plugins, &out.Plugins
*out = new(config.Plugins)
if err := Convert_v1alpha1_Plugins_To_config_Plugins(*in, *out, s); err != nil {
return err
}
} else {
out.Plugins = nil
}
out.PluginConfig = *(*[]config.PluginConfig)(unsafe.Pointer(&in.PluginConfig)) out.PluginConfig = *(*[]config.PluginConfig)(unsafe.Pointer(&in.PluginConfig))
return nil return nil
} }
@ -173,28 +200,54 @@ func Convert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfigur
} }
func autoConvert_config_KubeSchedulerConfiguration_To_v1alpha1_KubeSchedulerConfiguration(in *config.KubeSchedulerConfiguration, out *v1alpha1.KubeSchedulerConfiguration, s conversion.Scope) error { func autoConvert_config_KubeSchedulerConfiguration_To_v1alpha1_KubeSchedulerConfiguration(in *config.KubeSchedulerConfiguration, out *v1alpha1.KubeSchedulerConfiguration, s conversion.Scope) error {
out.SchedulerName = in.SchedulerName if err := v1.Convert_string_To_Pointer_string(&in.SchedulerName, &out.SchedulerName, s); err != nil {
return err
}
if err := Convert_config_SchedulerAlgorithmSource_To_v1alpha1_SchedulerAlgorithmSource(&in.AlgorithmSource, &out.AlgorithmSource, s); err != nil { if err := Convert_config_SchedulerAlgorithmSource_To_v1alpha1_SchedulerAlgorithmSource(&in.AlgorithmSource, &out.AlgorithmSource, s); err != nil {
return err return err
} }
out.HardPodAffinitySymmetricWeight = in.HardPodAffinitySymmetricWeight if err := v1.Convert_int32_To_Pointer_int32(&in.HardPodAffinitySymmetricWeight, &out.HardPodAffinitySymmetricWeight, s); err != nil {
return err
}
if err := Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_KubeSchedulerLeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil { if err := Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_KubeSchedulerLeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil {
return err return err
} }
if err := componentbaseconfigv1alpha1.Convert_config_ClientConnectionConfiguration_To_v1alpha1_ClientConnectionConfiguration(&in.ClientConnection, &out.ClientConnection, s); err != nil { if err := componentbaseconfigv1alpha1.Convert_config_ClientConnectionConfiguration_To_v1alpha1_ClientConnectionConfiguration(&in.ClientConnection, &out.ClientConnection, s); err != nil {
return err return err
} }
out.HealthzBindAddress = in.HealthzBindAddress if err := v1.Convert_string_To_Pointer_string(&in.HealthzBindAddress, &out.HealthzBindAddress, s); err != nil {
out.MetricsBindAddress = in.MetricsBindAddress return err
}
if err := v1.Convert_string_To_Pointer_string(&in.MetricsBindAddress, &out.MetricsBindAddress, s); err != nil {
return err
}
if err := componentbaseconfigv1alpha1.Convert_config_DebuggingConfiguration_To_v1alpha1_DebuggingConfiguration(&in.DebuggingConfiguration, &out.DebuggingConfiguration, s); err != nil { if err := componentbaseconfigv1alpha1.Convert_config_DebuggingConfiguration_To_v1alpha1_DebuggingConfiguration(&in.DebuggingConfiguration, &out.DebuggingConfiguration, s); err != nil {
return err return err
} }
out.DisablePreemption = in.DisablePreemption if err := v1.Convert_bool_To_Pointer_bool(&in.DisablePreemption, &out.DisablePreemption, s); err != nil {
out.PercentageOfNodesToScore = in.PercentageOfNodesToScore return err
out.BindTimeoutSeconds = (*int64)(unsafe.Pointer(in.BindTimeoutSeconds)) }
out.PodInitialBackoffSeconds = (*int64)(unsafe.Pointer(in.PodInitialBackoffSeconds)) if err := v1.Convert_int32_To_Pointer_int32(&in.PercentageOfNodesToScore, &out.PercentageOfNodesToScore, s); err != nil {
out.PodMaxBackoffSeconds = (*int64)(unsafe.Pointer(in.PodMaxBackoffSeconds)) return err
out.Plugins = (*v1alpha1.Plugins)(unsafe.Pointer(in.Plugins)) }
if err := v1.Convert_int64_To_Pointer_int64(&in.BindTimeoutSeconds, &out.BindTimeoutSeconds, s); err != nil {
return err
}
if err := v1.Convert_int64_To_Pointer_int64(&in.PodInitialBackoffSeconds, &out.PodInitialBackoffSeconds, s); err != nil {
return err
}
if err := v1.Convert_int64_To_Pointer_int64(&in.PodMaxBackoffSeconds, &out.PodMaxBackoffSeconds, s); err != nil {
return err
}
if in.Plugins != nil {
in, out := &in.Plugins, &out.Plugins
*out = new(v1alpha1.Plugins)
if err := Convert_config_Plugins_To_v1alpha1_Plugins(*in, *out, s); err != nil {
return err
}
} else {
out.Plugins = nil
}
out.PluginConfig = *(*[]v1alpha1.PluginConfig)(unsafe.Pointer(&in.PluginConfig)) out.PluginConfig = *(*[]v1alpha1.PluginConfig)(unsafe.Pointer(&in.PluginConfig))
return nil return nil
} }
@ -222,7 +275,9 @@ func autoConvert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_Kub
func autoConvert_v1alpha1_Plugin_To_config_Plugin(in *v1alpha1.Plugin, out *config.Plugin, s conversion.Scope) error { func autoConvert_v1alpha1_Plugin_To_config_Plugin(in *v1alpha1.Plugin, out *config.Plugin, s conversion.Scope) error {
out.Name = in.Name out.Name = in.Name
out.Weight = in.Weight if err := v1.Convert_Pointer_int32_To_int32(&in.Weight, &out.Weight, s); err != nil {
return err
}
return nil return nil
} }
@ -233,7 +288,9 @@ func Convert_v1alpha1_Plugin_To_config_Plugin(in *v1alpha1.Plugin, out *config.P
func autoConvert_config_Plugin_To_v1alpha1_Plugin(in *config.Plugin, out *v1alpha1.Plugin, s conversion.Scope) error { func autoConvert_config_Plugin_To_v1alpha1_Plugin(in *config.Plugin, out *v1alpha1.Plugin, s conversion.Scope) error {
out.Name = in.Name out.Name = in.Name
out.Weight = in.Weight if err := v1.Convert_int32_To_Pointer_int32(&in.Weight, &out.Weight, s); err != nil {
return err
}
return nil return nil
} }
@ -265,8 +322,28 @@ func Convert_config_PluginConfig_To_v1alpha1_PluginConfig(in *config.PluginConfi
} }
func autoConvert_v1alpha1_PluginSet_To_config_PluginSet(in *v1alpha1.PluginSet, out *config.PluginSet, s conversion.Scope) error { func autoConvert_v1alpha1_PluginSet_To_config_PluginSet(in *v1alpha1.PluginSet, out *config.PluginSet, s conversion.Scope) error {
out.Enabled = *(*[]config.Plugin)(unsafe.Pointer(&in.Enabled)) if in.Enabled != nil {
out.Disabled = *(*[]config.Plugin)(unsafe.Pointer(&in.Disabled)) in, out := &in.Enabled, &out.Enabled
*out = make([]config.Plugin, len(*in))
for i := range *in {
if err := Convert_v1alpha1_Plugin_To_config_Plugin(&(*in)[i], &(*out)[i], s); err != nil {
return err
}
}
} else {
out.Enabled = nil
}
if in.Disabled != nil {
in, out := &in.Disabled, &out.Disabled
*out = make([]config.Plugin, len(*in))
for i := range *in {
if err := Convert_v1alpha1_Plugin_To_config_Plugin(&(*in)[i], &(*out)[i], s); err != nil {
return err
}
}
} else {
out.Disabled = nil
}
return nil return nil
} }
@ -276,8 +353,28 @@ func Convert_v1alpha1_PluginSet_To_config_PluginSet(in *v1alpha1.PluginSet, out
} }
func autoConvert_config_PluginSet_To_v1alpha1_PluginSet(in *config.PluginSet, out *v1alpha1.PluginSet, s conversion.Scope) error { func autoConvert_config_PluginSet_To_v1alpha1_PluginSet(in *config.PluginSet, out *v1alpha1.PluginSet, s conversion.Scope) error {
out.Enabled = *(*[]v1alpha1.Plugin)(unsafe.Pointer(&in.Enabled)) if in.Enabled != nil {
out.Disabled = *(*[]v1alpha1.Plugin)(unsafe.Pointer(&in.Disabled)) in, out := &in.Enabled, &out.Enabled
*out = make([]v1alpha1.Plugin, len(*in))
for i := range *in {
if err := Convert_config_Plugin_To_v1alpha1_Plugin(&(*in)[i], &(*out)[i], s); err != nil {
return err
}
}
} else {
out.Enabled = nil
}
if in.Disabled != nil {
in, out := &in.Disabled, &out.Disabled
*out = make([]v1alpha1.Plugin, len(*in))
for i := range *in {
if err := Convert_config_Plugin_To_v1alpha1_Plugin(&(*in)[i], &(*out)[i], s); err != nil {
return err
}
}
} else {
out.Disabled = nil
}
return nil return nil
} }
@ -287,17 +384,105 @@ func Convert_config_PluginSet_To_v1alpha1_PluginSet(in *config.PluginSet, out *v
} }
func autoConvert_v1alpha1_Plugins_To_config_Plugins(in *v1alpha1.Plugins, out *config.Plugins, s conversion.Scope) error { func autoConvert_v1alpha1_Plugins_To_config_Plugins(in *v1alpha1.Plugins, out *config.Plugins, s conversion.Scope) error {
out.QueueSort = (*config.PluginSet)(unsafe.Pointer(in.QueueSort)) if in.QueueSort != nil {
out.PreFilter = (*config.PluginSet)(unsafe.Pointer(in.PreFilter)) in, out := &in.QueueSort, &out.QueueSort
out.Filter = (*config.PluginSet)(unsafe.Pointer(in.Filter)) *out = new(config.PluginSet)
out.PostFilter = (*config.PluginSet)(unsafe.Pointer(in.PostFilter)) if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil {
out.Score = (*config.PluginSet)(unsafe.Pointer(in.Score)) return err
out.Reserve = (*config.PluginSet)(unsafe.Pointer(in.Reserve)) }
out.Permit = (*config.PluginSet)(unsafe.Pointer(in.Permit)) } else {
out.PreBind = (*config.PluginSet)(unsafe.Pointer(in.PreBind)) out.QueueSort = nil
out.Bind = (*config.PluginSet)(unsafe.Pointer(in.Bind)) }
out.PostBind = (*config.PluginSet)(unsafe.Pointer(in.PostBind)) if in.PreFilter != nil {
out.Unreserve = (*config.PluginSet)(unsafe.Pointer(in.Unreserve)) in, out := &in.PreFilter, &out.PreFilter
*out = new(config.PluginSet)
if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.PreFilter = nil
}
if in.Filter != nil {
in, out := &in.Filter, &out.Filter
*out = new(config.PluginSet)
if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.Filter = nil
}
if in.PostFilter != nil {
in, out := &in.PostFilter, &out.PostFilter
*out = new(config.PluginSet)
if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.PostFilter = nil
}
if in.Score != nil {
in, out := &in.Score, &out.Score
*out = new(config.PluginSet)
if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.Score = nil
}
if in.Reserve != nil {
in, out := &in.Reserve, &out.Reserve
*out = new(config.PluginSet)
if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.Reserve = nil
}
if in.Permit != nil {
in, out := &in.Permit, &out.Permit
*out = new(config.PluginSet)
if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.Permit = nil
}
if in.PreBind != nil {
in, out := &in.PreBind, &out.PreBind
*out = new(config.PluginSet)
if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.PreBind = nil
}
if in.Bind != nil {
in, out := &in.Bind, &out.Bind
*out = new(config.PluginSet)
if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.Bind = nil
}
if in.PostBind != nil {
in, out := &in.PostBind, &out.PostBind
*out = new(config.PluginSet)
if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.PostBind = nil
}
if in.Unreserve != nil {
in, out := &in.Unreserve, &out.Unreserve
*out = new(config.PluginSet)
if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.Unreserve = nil
}
return nil return nil
} }
@ -307,17 +492,105 @@ func Convert_v1alpha1_Plugins_To_config_Plugins(in *v1alpha1.Plugins, out *confi
} }
func autoConvert_config_Plugins_To_v1alpha1_Plugins(in *config.Plugins, out *v1alpha1.Plugins, s conversion.Scope) error { func autoConvert_config_Plugins_To_v1alpha1_Plugins(in *config.Plugins, out *v1alpha1.Plugins, s conversion.Scope) error {
out.QueueSort = (*v1alpha1.PluginSet)(unsafe.Pointer(in.QueueSort)) if in.QueueSort != nil {
out.PreFilter = (*v1alpha1.PluginSet)(unsafe.Pointer(in.PreFilter)) in, out := &in.QueueSort, &out.QueueSort
out.Filter = (*v1alpha1.PluginSet)(unsafe.Pointer(in.Filter)) *out = new(v1alpha1.PluginSet)
out.PostFilter = (*v1alpha1.PluginSet)(unsafe.Pointer(in.PostFilter)) if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil {
out.Score = (*v1alpha1.PluginSet)(unsafe.Pointer(in.Score)) return err
out.Reserve = (*v1alpha1.PluginSet)(unsafe.Pointer(in.Reserve)) }
out.Permit = (*v1alpha1.PluginSet)(unsafe.Pointer(in.Permit)) } else {
out.PreBind = (*v1alpha1.PluginSet)(unsafe.Pointer(in.PreBind)) out.QueueSort = nil
out.Bind = (*v1alpha1.PluginSet)(unsafe.Pointer(in.Bind)) }
out.PostBind = (*v1alpha1.PluginSet)(unsafe.Pointer(in.PostBind)) if in.PreFilter != nil {
out.Unreserve = (*v1alpha1.PluginSet)(unsafe.Pointer(in.Unreserve)) in, out := &in.PreFilter, &out.PreFilter
*out = new(v1alpha1.PluginSet)
if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.PreFilter = nil
}
if in.Filter != nil {
in, out := &in.Filter, &out.Filter
*out = new(v1alpha1.PluginSet)
if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.Filter = nil
}
if in.PostFilter != nil {
in, out := &in.PostFilter, &out.PostFilter
*out = new(v1alpha1.PluginSet)
if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.PostFilter = nil
}
if in.Score != nil {
in, out := &in.Score, &out.Score
*out = new(v1alpha1.PluginSet)
if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.Score = nil
}
if in.Reserve != nil {
in, out := &in.Reserve, &out.Reserve
*out = new(v1alpha1.PluginSet)
if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.Reserve = nil
}
if in.Permit != nil {
in, out := &in.Permit, &out.Permit
*out = new(v1alpha1.PluginSet)
if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.Permit = nil
}
if in.PreBind != nil {
in, out := &in.PreBind, &out.PreBind
*out = new(v1alpha1.PluginSet)
if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.PreBind = nil
}
if in.Bind != nil {
in, out := &in.Bind, &out.Bind
*out = new(v1alpha1.PluginSet)
if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.Bind = nil
}
if in.PostBind != nil {
in, out := &in.PostBind, &out.PostBind
*out = new(v1alpha1.PluginSet)
if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.PostBind = nil
}
if in.Unreserve != nil {
in, out := &in.Unreserve, &out.Unreserve
*out = new(v1alpha1.PluginSet)
if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil {
return err
}
} else {
out.Unreserve = nil
}
return nil return nil
} }

View File

@ -47,22 +47,15 @@ func ValidateKubeSchedulerConfiguration(cc *config.KubeSchedulerConfiguration) f
if cc.HardPodAffinitySymmetricWeight < 0 || cc.HardPodAffinitySymmetricWeight > 100 { if cc.HardPodAffinitySymmetricWeight < 0 || cc.HardPodAffinitySymmetricWeight > 100 {
allErrs = append(allErrs, field.Invalid(field.NewPath("hardPodAffinitySymmetricWeight"), cc.HardPodAffinitySymmetricWeight, "not in valid range 0-100")) allErrs = append(allErrs, field.Invalid(field.NewPath("hardPodAffinitySymmetricWeight"), cc.HardPodAffinitySymmetricWeight, "not in valid range 0-100"))
} }
if cc.BindTimeoutSeconds == nil {
allErrs = append(allErrs, field.Required(field.NewPath("bindTimeoutSeconds"), ""))
}
if cc.PercentageOfNodesToScore < 0 || cc.PercentageOfNodesToScore > 100 { if cc.PercentageOfNodesToScore < 0 || cc.PercentageOfNodesToScore > 100 {
allErrs = append(allErrs, field.Invalid(field.NewPath("percentageOfNodesToScore"), allErrs = append(allErrs, field.Invalid(field.NewPath("percentageOfNodesToScore"),
cc.PercentageOfNodesToScore, "not in valid range 0-100")) cc.PercentageOfNodesToScore, "not in valid range 0-100"))
} }
if cc.PodInitialBackoffSeconds == nil { if cc.PodInitialBackoffSeconds <= 0 {
allErrs = append(allErrs, field.Required(field.NewPath("podInitialBackoffSeconds"), ""))
} else if *cc.PodInitialBackoffSeconds <= 0 {
allErrs = append(allErrs, field.Invalid(field.NewPath("podInitialBackoffSeconds"), allErrs = append(allErrs, field.Invalid(field.NewPath("podInitialBackoffSeconds"),
cc.PodInitialBackoffSeconds, "must be greater than 0")) cc.PodInitialBackoffSeconds, "must be greater than 0"))
} }
if cc.PodMaxBackoffSeconds == nil { if cc.PodMaxBackoffSeconds < cc.PodInitialBackoffSeconds {
allErrs = append(allErrs, field.Required(field.NewPath("podMaxBackoffSeconds"), ""))
} else if cc.PodInitialBackoffSeconds != nil && *cc.PodMaxBackoffSeconds < *cc.PodInitialBackoffSeconds {
allErrs = append(allErrs, field.Invalid(field.NewPath("podMaxBackoffSeconds"), allErrs = append(allErrs, field.Invalid(field.NewPath("podMaxBackoffSeconds"),
cc.PodMaxBackoffSeconds, "must be greater than or equal to PodInitialBackoffSeconds")) cc.PodMaxBackoffSeconds, "must be greater than or equal to PodInitialBackoffSeconds"))
} }

View File

@ -61,9 +61,9 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) {
ResourceName: "name", ResourceName: "name",
}, },
}, },
PodInitialBackoffSeconds: &podInitialBackoffSeconds, PodInitialBackoffSeconds: podInitialBackoffSeconds,
PodMaxBackoffSeconds: &podMaxBackoffSeconds, PodMaxBackoffSeconds: podMaxBackoffSeconds,
BindTimeoutSeconds: &testTimeout, BindTimeoutSeconds: testTimeout,
PercentageOfNodesToScore: 35, PercentageOfNodesToScore: 35,
} }
@ -95,9 +95,6 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) {
enableContentProfilingSetWithoutEnableProfiling.EnableProfiling = false enableContentProfilingSetWithoutEnableProfiling.EnableProfiling = false
enableContentProfilingSetWithoutEnableProfiling.EnableContentionProfiling = true enableContentProfilingSetWithoutEnableProfiling.EnableContentionProfiling = true
bindTimeoutUnset := validConfig.DeepCopy()
bindTimeoutUnset.BindTimeoutSeconds = nil
percentageOfNodesToScore101 := validConfig.DeepCopy() percentageOfNodesToScore101 := validConfig.DeepCopy()
percentageOfNodesToScore101.PercentageOfNodesToScore = int32(101) percentageOfNodesToScore101.PercentageOfNodesToScore = int32(101)
@ -141,10 +138,6 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) {
expectedToFail: true, expectedToFail: true,
config: HardPodAffinitySymmetricWeightLt0, config: HardPodAffinitySymmetricWeightLt0,
}, },
"bind-timeout-unset": {
expectedToFail: true,
config: bindTimeoutUnset,
},
"bad-percentage-of-nodes-to-score": { "bad-percentage-of-nodes-to-score": {
expectedToFail: true, expectedToFail: true,
config: percentageOfNodesToScore101, config: percentageOfNodesToScore101,

View File

@ -105,21 +105,6 @@ func (in *KubeSchedulerConfiguration) DeepCopyInto(out *KubeSchedulerConfigurati
out.LeaderElection = in.LeaderElection out.LeaderElection = in.LeaderElection
out.ClientConnection = in.ClientConnection out.ClientConnection = in.ClientConnection
out.DebuggingConfiguration = in.DebuggingConfiguration out.DebuggingConfiguration = in.DebuggingConfiguration
if in.BindTimeoutSeconds != nil {
in, out := &in.BindTimeoutSeconds, &out.BindTimeoutSeconds
*out = new(int64)
**out = **in
}
if in.PodInitialBackoffSeconds != nil {
in, out := &in.PodInitialBackoffSeconds, &out.PodInitialBackoffSeconds
*out = new(int64)
**out = **in
}
if in.PodMaxBackoffSeconds != nil {
in, out := &in.PodMaxBackoffSeconds, &out.PodMaxBackoffSeconds
*out = new(int64)
**out = **in
}
if in.Plugins != nil { if in.Plugins != nil {
in, out := &in.Plugins, &out.Plugins in, out := &in.Plugins, &out.Plugins
*out = new(Plugins) *out = new(Plugins)

View File

@ -26,6 +26,7 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go" dto "github.com/prometheus/client_model/go"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"

View File

@ -46,7 +46,6 @@ import (
"k8s.io/kubernetes/pkg/scheduler/algorithm" "k8s.io/kubernetes/pkg/scheduler/algorithm"
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates" "k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities" "k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config" schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/core" "k8s.io/kubernetes/pkg/scheduler/core"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
@ -192,7 +191,7 @@ func TestSchedulerCreation(t *testing.T) {
informerFactory, informerFactory,
NewPodInformer(client, 0), NewPodInformer(client, 0),
eventBroadcaster.NewRecorder(scheme.Scheme, "scheduler"), eventBroadcaster.NewRecorder(scheme.Scheme, "scheduler"),
kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &testSource}, schedulerapi.SchedulerAlgorithmSource{Provider: &testSource},
stopCh, stopCh,
WithPodInitialBackoffSeconds(1), WithPodInitialBackoffSeconds(1),
WithPodMaxBackoffSeconds(10), WithPodMaxBackoffSeconds(10),
@ -693,7 +692,7 @@ func setupTestScheduler(queuedPodStore *clientcache.FIFO, scache internalcache.C
} }
func setupTestSchedulerLongBindingWithRetry(queuedPodStore *clientcache.FIFO, scache internalcache.Cache, informerFactory informers.SharedInformerFactory, predicateMap map[string]predicates.FitPredicate, stop chan struct{}, bindingTime time.Duration) (*Scheduler, chan *v1.Binding) { func setupTestSchedulerLongBindingWithRetry(queuedPodStore *clientcache.FIFO, scache internalcache.Cache, informerFactory informers.SharedInformerFactory, predicateMap map[string]predicates.FitPredicate, stop chan struct{}, bindingTime time.Duration) (*Scheduler, chan *v1.Binding) {
fwk, _ := framework.NewFramework(emptyPluginRegistry, nil, []kubeschedulerconfig.PluginConfig{}) fwk, _ := framework.NewFramework(emptyPluginRegistry, nil, []schedulerapi.PluginConfig{})
algo := core.NewGenericScheduler( algo := core.NewGenericScheduler(
scache, scache,
internalqueue.NewSchedulingQueue(nil, nil), internalqueue.NewSchedulingQueue(nil, nil),

View File

@ -41,13 +41,13 @@ type KubeSchedulerConfiguration struct {
// SchedulerName is name of the scheduler, used to select which pods // SchedulerName is name of the scheduler, used to select which pods
// will be processed by this scheduler, based on pod's "spec.SchedulerName". // will be processed by this scheduler, based on pod's "spec.SchedulerName".
SchedulerName string `json:"schedulerName"` SchedulerName *string `json:"schedulerName,omitempty"`
// AlgorithmSource specifies the scheduler algorithm source. // AlgorithmSource specifies the scheduler algorithm source.
AlgorithmSource SchedulerAlgorithmSource `json:"algorithmSource"` AlgorithmSource SchedulerAlgorithmSource `json:"algorithmSource"`
// RequiredDuringScheduling affinity is not symmetric, but there is an implicit PreferredDuringScheduling affinity rule // RequiredDuringScheduling affinity is not symmetric, but there is an implicit PreferredDuringScheduling affinity rule
// corresponding to every RequiredDuringScheduling affinity rule. // corresponding to every RequiredDuringScheduling affinity rule.
// HardPodAffinitySymmetricWeight represents the weight of implicit PreferredDuringScheduling affinity rule, in the range 0-100. // HardPodAffinitySymmetricWeight represents the weight of implicit PreferredDuringScheduling affinity rule, in the range 0-100.
HardPodAffinitySymmetricWeight int32 `json:"hardPodAffinitySymmetricWeight"` HardPodAffinitySymmetricWeight *int32 `json:"hardPodAffinitySymmetricWeight,omitempty"`
// LeaderElection defines the configuration of leader election client. // LeaderElection defines the configuration of leader election client.
LeaderElection KubeSchedulerLeaderElectionConfiguration `json:"leaderElection"` LeaderElection KubeSchedulerLeaderElectionConfiguration `json:"leaderElection"`
@ -57,17 +57,17 @@ type KubeSchedulerConfiguration struct {
ClientConnection componentbaseconfigv1alpha1.ClientConnectionConfiguration `json:"clientConnection"` ClientConnection componentbaseconfigv1alpha1.ClientConnectionConfiguration `json:"clientConnection"`
// HealthzBindAddress is the IP address and port for the health check server to serve on, // HealthzBindAddress is the IP address and port for the health check server to serve on,
// defaulting to 0.0.0.0:10251 // defaulting to 0.0.0.0:10251
HealthzBindAddress string `json:"healthzBindAddress"` HealthzBindAddress *string `json:"healthzBindAddress,omitempty"`
// MetricsBindAddress is the IP address and port for the metrics server to // MetricsBindAddress is the IP address and port for the metrics server to
// serve on, defaulting to 0.0.0.0:10251. // serve on, defaulting to 0.0.0.0:10251.
MetricsBindAddress string `json:"metricsBindAddress"` MetricsBindAddress *string `json:"metricsBindAddress,omitempty"`
// DebuggingConfiguration holds configuration for Debugging related features // DebuggingConfiguration holds configuration for Debugging related features
// TODO: We might wanna make this a substruct like Debugging componentbaseconfigv1alpha1.DebuggingConfiguration // TODO: We might wanna make this a substruct like Debugging componentbaseconfigv1alpha1.DebuggingConfiguration
componentbaseconfigv1alpha1.DebuggingConfiguration `json:",inline"` componentbaseconfigv1alpha1.DebuggingConfiguration `json:",inline"`
// DisablePreemption disables the pod preemption feature. // DisablePreemption disables the pod preemption feature.
DisablePreemption bool `json:"disablePreemption"` DisablePreemption *bool `json:"disablePreemption,omitempty"`
// PercentageOfNodeToScore is the percentage of all nodes that once found feasible // 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 // for running a pod, the scheduler stops its search for more feasible nodes in
@ -77,7 +77,7 @@ type KubeSchedulerConfiguration struct {
// then scheduler stops finding further feasible nodes once it finds 150 feasible ones. // 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 // When the value is 0, default percentage (5%--50% based on the size of the cluster) of the
// nodes will be scored. // nodes will be scored.
PercentageOfNodesToScore int32 `json:"percentageOfNodesToScore"` PercentageOfNodesToScore *int32 `json:"percentageOfNodesToScore,omitempty"`
// Duration to wait for a binding operation to complete before timing out // Duration to wait for a binding operation to complete before timing out
// Value must be non-negative integer. The value zero indicates no waiting. // Value must be non-negative integer. The value zero indicates no waiting.
@ -209,7 +209,7 @@ type Plugin struct {
// Name defines the name of plugin // Name defines the name of plugin
Name string `json:"name"` Name string `json:"name"`
// Weight defines the weight of plugin, only used for Score plugins. // Weight defines the weight of plugin, only used for Score plugins.
Weight int32 `json:"weight,omitempty"` Weight *int32 `json:"weight,omitempty"`
} }
// PluginConfig specifies arguments that should be passed to a plugin at the time of initialization. // PluginConfig specifies arguments that should be passed to a plugin at the time of initialization.

View File

@ -28,10 +28,40 @@ import (
func (in *KubeSchedulerConfiguration) DeepCopyInto(out *KubeSchedulerConfiguration) { func (in *KubeSchedulerConfiguration) DeepCopyInto(out *KubeSchedulerConfiguration) {
*out = *in *out = *in
out.TypeMeta = in.TypeMeta out.TypeMeta = in.TypeMeta
if in.SchedulerName != nil {
in, out := &in.SchedulerName, &out.SchedulerName
*out = new(string)
**out = **in
}
in.AlgorithmSource.DeepCopyInto(&out.AlgorithmSource) in.AlgorithmSource.DeepCopyInto(&out.AlgorithmSource)
if in.HardPodAffinitySymmetricWeight != nil {
in, out := &in.HardPodAffinitySymmetricWeight, &out.HardPodAffinitySymmetricWeight
*out = new(int32)
**out = **in
}
in.LeaderElection.DeepCopyInto(&out.LeaderElection) in.LeaderElection.DeepCopyInto(&out.LeaderElection)
out.ClientConnection = in.ClientConnection out.ClientConnection = in.ClientConnection
if in.HealthzBindAddress != nil {
in, out := &in.HealthzBindAddress, &out.HealthzBindAddress
*out = new(string)
**out = **in
}
if in.MetricsBindAddress != nil {
in, out := &in.MetricsBindAddress, &out.MetricsBindAddress
*out = new(string)
**out = **in
}
in.DebuggingConfiguration.DeepCopyInto(&out.DebuggingConfiguration) in.DebuggingConfiguration.DeepCopyInto(&out.DebuggingConfiguration)
if in.DisablePreemption != nil {
in, out := &in.DisablePreemption, &out.DisablePreemption
*out = new(bool)
**out = **in
}
if in.PercentageOfNodesToScore != nil {
in, out := &in.PercentageOfNodesToScore, &out.PercentageOfNodesToScore
*out = new(int32)
**out = **in
}
if in.BindTimeoutSeconds != nil { if in.BindTimeoutSeconds != nil {
in, out := &in.BindTimeoutSeconds, &out.BindTimeoutSeconds in, out := &in.BindTimeoutSeconds, &out.BindTimeoutSeconds
*out = new(int64) *out = new(int64)
@ -100,6 +130,11 @@ func (in *KubeSchedulerLeaderElectionConfiguration) DeepCopy() *KubeSchedulerLea
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Plugin) DeepCopyInto(out *Plugin) { func (in *Plugin) DeepCopyInto(out *Plugin) {
*out = *in *out = *in
if in.Weight != nil {
in, out := &in.Weight, &out.Weight
*out = new(int32)
**out = **in
}
return return
} }
@ -136,12 +171,16 @@ func (in *PluginSet) DeepCopyInto(out *PluginSet) {
if in.Enabled != nil { if in.Enabled != nil {
in, out := &in.Enabled, &out.Enabled in, out := &in.Enabled, &out.Enabled
*out = make([]Plugin, len(*in)) *out = make([]Plugin, len(*in))
copy(*out, *in) for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
} }
if in.Disabled != nil { if in.Disabled != nil {
in, out := &in.Disabled, &out.Disabled in, out := &in.Disabled, &out.Disabled
*out = make([]Plugin, len(*in)) *out = make([]Plugin, len(*in))
copy(*out, *in) for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
} }
return return
} }