Unverified Commit 7b93d81a authored by Wojciech Tyczynski's avatar Wojciech Tyczynski Committed by GitHub

Revert "scheduler: align with ctrl-managers and apiservers, add https+auth in options"

parent 33d85b01
...@@ -30,8 +30,6 @@ import ( ...@@ -30,8 +30,6 @@ import (
type InsecureServingInfo struct { type InsecureServingInfo struct {
// Listener is the secure server network listener. // Listener is the secure server network listener.
Listener net.Listener Listener net.Listener
// optional server name for log messages
Name string
} }
// Serve starts an insecure http server with the given handler. It fails only if // Serve starts an insecure http server with the given handler. It fails only if
...@@ -43,10 +41,6 @@ func (s *InsecureServingInfo) Serve(handler http.Handler, shutdownTimeout time.D ...@@ -43,10 +41,6 @@ func (s *InsecureServingInfo) Serve(handler http.Handler, shutdownTimeout time.D
MaxHeaderBytes: 1 << 20, MaxHeaderBytes: 1 << 20,
} }
if len(s.Name) > 0 { glog.Infof("Serving insecurely on %s", s.Listener.Addr())
glog.Infof("Serving %s insecurely on %s", s.Name, s.Listener.Addr())
} else {
glog.Infof("Serving insecurely on %s", s.Listener.Addr())
}
return server.RunServer(insecureServer, s.Listener, shutdownTimeout, stopCh) return server.RunServer(insecureServer, s.Listener, shutdownTimeout, stopCh)
} }
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"github.com/spf13/pflag" "github.com/spf13/pflag"
"k8s.io/apiserver/pkg/server/options" "k8s.io/apiserver/pkg/server/options"
genericcontrollermanager "k8s.io/kubernetes/cmd/controller-manager/app" genericcontrollermanager "k8s.io/kubernetes/cmd/controller-manager/app"
"k8s.io/kubernetes/pkg/apis/componentconfig"
) )
// InsecureServingOptions are for creating an unauthenticated, unauthorized, insecure port. // InsecureServingOptions are for creating an unauthenticated, unauthorized, insecure port.
...@@ -38,20 +39,16 @@ type InsecureServingOptions struct { ...@@ -38,20 +39,16 @@ type InsecureServingOptions struct {
// either Listener or BindAddress/BindPort/BindNetwork is set, // either Listener or BindAddress/BindPort/BindNetwork is set,
// if Listener is set, use it and omit BindAddress/BindPort/BindNetwork. // if Listener is set, use it and omit BindAddress/BindPort/BindNetwork.
Listener net.Listener Listener net.Listener
// ListenFunc can be overridden to create a custom listener, e.g. for mocking in tests.
// It defaults to options.CreateListener.
ListenFunc func(network, addr string) (net.Listener, int, error)
} }
// Validate ensures that the insecure port values within the range of the port. // Validate ensures that the insecure port values within the range of the port.
func (s *InsecureServingOptions) Validate() []error { func (s *InsecureServingOptions) Validate() []error {
errors := []error{}
if s == nil { if s == nil {
return nil return nil
} }
errors := []error{}
if s.BindPort < 0 || s.BindPort > 32767 { if s.BindPort < 0 || s.BindPort > 32767 {
errors = append(errors, fmt.Errorf("--insecure-port %v must be between 0 and 32767, inclusive. 0 for turning off insecure (HTTP) port", s.BindPort)) errors = append(errors, fmt.Errorf("--insecure-port %v must be between 0 and 32767, inclusive. 0 for turning off insecure (HTTP) port", s.BindPort))
} }
...@@ -64,10 +61,20 @@ func (s *InsecureServingOptions) AddFlags(fs *pflag.FlagSet) { ...@@ -64,10 +61,20 @@ func (s *InsecureServingOptions) AddFlags(fs *pflag.FlagSet) {
if s == nil { if s == nil {
return return
} }
}
fs.IPVar(&s.BindAddress, "address", s.BindAddress, "DEPRECATED: the IP address on which to listen for the --port port (set to 0.0.0.0 for all IPv4 interfaces and :: for all IPv6 interfaces). See --bind-address instead.") // AddDeprecatedFlags adds deprecated flags related to insecure serving for controller manager to the specified FlagSet.
// TODO: remove it until kops stop using `--address`
func (s *InsecureServingOptions) AddDeprecatedFlags(fs *pflag.FlagSet) {
if s == nil {
return
}
fs.IPVar(&s.BindAddress, "address", s.BindAddress,
"DEPRECATED: the IP address on which to listen for the --port port. See --bind-address instead.")
// MarkDeprecated hides the flag from the help. We don't want that: // MarkDeprecated hides the flag from the help. We don't want that:
// fs.MarkDeprecated("address", "see --bind-address instead.") // fs.MarkDeprecated("address", "see --bind-address instead.")
fs.IntVar(&s.BindPort, "port", s.BindPort, "DEPRECATED: the port on which to serve HTTP insecurely without authentication and authorization. If 0, don't serve HTTPS at all. See --secure-port instead.") fs.IntVar(&s.BindPort, "port", s.BindPort, "DEPRECATED: the port on which to serve HTTP insecurely without authentication and authorization. If 0, don't serve HTTPS at all. See --secure-port instead.")
// MarkDeprecated hides the flag from the help. We don't want that: // MarkDeprecated hides the flag from the help. We don't want that:
// fs.MarkDeprecated("port", "see --secure-port instead.") // fs.MarkDeprecated("port", "see --secure-port instead.")
...@@ -75,7 +82,7 @@ func (s *InsecureServingOptions) AddFlags(fs *pflag.FlagSet) { ...@@ -75,7 +82,7 @@ func (s *InsecureServingOptions) AddFlags(fs *pflag.FlagSet) {
// ApplyTo adds InsecureServingOptions to the insecureserverinfo amd kube-controller manager configuration. // ApplyTo adds InsecureServingOptions to the insecureserverinfo amd kube-controller manager configuration.
// Note: the double pointer allows to set the *InsecureServingInfo to nil without referencing the struct hosting this pointer. // Note: the double pointer allows to set the *InsecureServingInfo to nil without referencing the struct hosting this pointer.
func (s *InsecureServingOptions) ApplyTo(c **genericcontrollermanager.InsecureServingInfo) error { func (s *InsecureServingOptions) ApplyTo(c **genericcontrollermanager.InsecureServingInfo, cfg *componentconfig.KubeCloudSharedConfiguration) error {
if s == nil { if s == nil {
return nil return nil
} }
...@@ -85,12 +92,8 @@ func (s *InsecureServingOptions) ApplyTo(c **genericcontrollermanager.InsecureSe ...@@ -85,12 +92,8 @@ func (s *InsecureServingOptions) ApplyTo(c **genericcontrollermanager.InsecureSe
if s.Listener == nil { if s.Listener == nil {
var err error var err error
listen := options.CreateListener
if s.ListenFunc != nil {
listen = s.ListenFunc
}
addr := net.JoinHostPort(s.BindAddress.String(), fmt.Sprintf("%d", s.BindPort)) addr := net.JoinHostPort(s.BindAddress.String(), fmt.Sprintf("%d", s.BindPort))
s.Listener, s.BindPort, err = listen(s.BindNetwork, addr) s.Listener, s.BindPort, err = options.CreateListener(s.BindNetwork, addr)
if err != nil { if err != nil {
return fmt.Errorf("failed to create listener: %v", err) return fmt.Errorf("failed to create listener: %v", err)
} }
...@@ -100,5 +103,10 @@ func (s *InsecureServingOptions) ApplyTo(c **genericcontrollermanager.InsecureSe ...@@ -100,5 +103,10 @@ func (s *InsecureServingOptions) ApplyTo(c **genericcontrollermanager.InsecureSe
Listener: s.Listener, Listener: s.Listener,
} }
// sync back to component config
// TODO: find more elegant way than synching back the values.
cfg.Port = int32(s.BindPort)
cfg.Address = s.BindAddress.String()
return nil return nil
} }
...@@ -225,6 +225,7 @@ func (o *GenericControllerManagerOptions) AddFlags(fs *pflag.FlagSet) { ...@@ -225,6 +225,7 @@ func (o *GenericControllerManagerOptions) AddFlags(fs *pflag.FlagSet) {
o.ServiceController.AddFlags(fs) o.ServiceController.AddFlags(fs)
o.SecureServing.AddFlags(fs) o.SecureServing.AddFlags(fs)
o.InsecureServing.AddFlags(fs) o.InsecureServing.AddFlags(fs)
o.InsecureServing.AddDeprecatedFlags(fs)
o.Authentication.AddFlags(fs) o.Authentication.AddFlags(fs)
o.Authorization.AddFlags(fs) o.Authorization.AddFlags(fs)
} }
...@@ -303,7 +304,7 @@ func (o *GenericControllerManagerOptions) ApplyTo(c *genericcontrollermanager.Co ...@@ -303,7 +304,7 @@ func (o *GenericControllerManagerOptions) ApplyTo(c *genericcontrollermanager.Co
if err := o.SecureServing.ApplyTo(&c.SecureServing); err != nil { if err := o.SecureServing.ApplyTo(&c.SecureServing); err != nil {
return err return err
} }
if err := o.InsecureServing.ApplyTo(&c.InsecureServing); err != nil { if err := o.InsecureServing.ApplyTo(&c.InsecureServing, &c.ComponentConfig.KubeCloudShared); err != nil {
return err return err
} }
if err := o.Authentication.ApplyTo(&c.Authentication, c.SecureServing, nil); err != nil { if err := o.Authentication.ApplyTo(&c.Authentication, c.SecureServing, nil); err != nil {
...@@ -313,11 +314,6 @@ func (o *GenericControllerManagerOptions) ApplyTo(c *genericcontrollermanager.Co ...@@ -313,11 +314,6 @@ func (o *GenericControllerManagerOptions) ApplyTo(c *genericcontrollermanager.Co
return err return err
} }
// sync back to component config
// TODO: find more elegant way than synching back the values.
c.ComponentConfig.KubeCloudShared.Port = int32(o.InsecureServing.BindPort)
c.ComponentConfig.KubeCloudShared.Address = o.InsecureServing.BindAddress.String()
var err error var err error
c.Kubeconfig, err = clientcmd.BuildConfigFromFlags(o.Master, o.Kubeconfig) c.Kubeconfig, err = clientcmd.BuildConfigFromFlags(o.Master, o.Kubeconfig)
if err != nil { if err != nil {
......
...@@ -10,12 +10,14 @@ go_library( ...@@ -10,12 +10,14 @@ go_library(
srcs = ["server.go"], srcs = ["server.go"],
importpath = "k8s.io/kubernetes/cmd/kube-scheduler/app", importpath = "k8s.io/kubernetes/cmd/kube-scheduler/app",
deps = [ deps = [
"//cmd/kube-scheduler/app/config:go_default_library",
"//cmd/kube-scheduler/app/options:go_default_library",
"//pkg/api/legacyscheme:go_default_library", "//pkg/api/legacyscheme:go_default_library",
"//pkg/apis/componentconfig:go_default_library", "//pkg/apis/componentconfig:go_default_library",
"//pkg/apis/componentconfig/v1alpha1:go_default_library",
"//pkg/client/leaderelectionconfig:go_default_library",
"//pkg/controller:go_default_library", "//pkg/controller:go_default_library",
"//pkg/features:go_default_library", "//pkg/features:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/master/ports:go_default_library",
"//pkg/scheduler:go_default_library", "//pkg/scheduler:go_default_library",
"//pkg/scheduler/algorithmprovider:go_default_library", "//pkg/scheduler/algorithmprovider:go_default_library",
"//pkg/scheduler/api:go_default_library", "//pkg/scheduler/api:go_default_library",
...@@ -28,23 +30,30 @@ go_library( ...@@ -28,23 +30,30 @@ go_library(
"//vendor/github.com/golang/glog:go_default_library", "//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library", "//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library", "//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer/json:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/apiserver/pkg/authentication/authenticator:go_default_library",
"//vendor/k8s.io/apiserver/pkg/authorization/authorizer:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/filters:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/server/filters:go_default_library",
"//vendor/k8s.io/apiserver/pkg/server/healthz:go_default_library", "//vendor/k8s.io/apiserver/pkg/server/healthz:go_default_library",
"//vendor/k8s.io/apiserver/pkg/server/mux:go_default_library", "//vendor/k8s.io/apiserver/pkg/server/mux:go_default_library",
"//vendor/k8s.io/apiserver/pkg/server/routes:go_default_library", "//vendor/k8s.io/apiserver/pkg/server/routes:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library", "//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//vendor/k8s.io/client-go/informers:go_default_library",
"//vendor/k8s.io/client-go/informers/core/v1:go_default_library",
"//vendor/k8s.io/client-go/informers/storage/v1:go_default_library", "//vendor/k8s.io/client-go/informers/storage/v1:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library", "//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd/api:go_default_library",
"//vendor/k8s.io/client-go/tools/leaderelection:go_default_library", "//vendor/k8s.io/client-go/tools/leaderelection:go_default_library",
"//vendor/k8s.io/client-go/tools/leaderelection/resourcelock:go_default_library",
"//vendor/k8s.io/client-go/tools/record:go_default_library",
], ],
) )
...@@ -57,10 +66,6 @@ filegroup( ...@@ -57,10 +66,6 @@ filegroup(
filegroup( filegroup(
name = "all-srcs", name = "all-srcs",
srcs = [ srcs = [":package-srcs"],
":package-srcs",
"//cmd/kube-scheduler/app/config:all-srcs",
"//cmd/kube-scheduler/app/options:all-srcs",
],
tags = ["automanaged"], tags = ["automanaged"],
) )
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["config.go"],
importpath = "k8s.io/kubernetes/cmd/kube-scheduler/app/config",
visibility = ["//visibility:public"],
deps = [
"//cmd/controller-manager/app:go_default_library",
"//pkg/apis/componentconfig:go_default_library",
"//vendor/k8s.io/apiserver/pkg/server:go_default_library",
"//vendor/k8s.io/client-go/informers:go_default_library",
"//vendor/k8s.io/client-go/informers/core/v1:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library",
"//vendor/k8s.io/client-go/tools/leaderelection:go_default_library",
"//vendor/k8s.io/client-go/tools/record:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package config
import (
apiserver "k8s.io/apiserver/pkg/server"
"k8s.io/client-go/informers"
coreinformers "k8s.io/client-go/informers/core/v1"
clientset "k8s.io/client-go/kubernetes"
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/record"
"k8s.io/kubernetes/cmd/controller-manager/app"
"k8s.io/kubernetes/pkg/apis/componentconfig"
)
// Config has all the context to run a Scheduler
type Config struct {
// config is the scheduler server's configuration object.
ComponentConfig componentconfig.KubeSchedulerConfiguration
InsecureServing *app.InsecureServingInfo // nil will disable serving on an insecure port
InsecureMetricsServing *app.InsecureServingInfo // non-nil if metrics should be served independently
Authentication apiserver.AuthenticationInfo
Authorization apiserver.AuthorizationInfo
SecureServing *apiserver.SecureServingInfo
Client clientset.Interface
InformerFactory informers.SharedInformerFactory
PodInformer coreinformers.PodInformer
EventClient v1core.EventsGetter
Recorder record.EventRecorder
Broadcaster record.EventBroadcaster
// LeaderElection is optional.
LeaderElection *leaderelection.LeaderElectionConfig
}
type completedConfig struct {
*Config
}
// CompletedConfig same as Config, just to swap private object.
type CompletedConfig struct {
// Embed a private pointer that cannot be instantiated outside of this package.
*completedConfig
}
// Complete fills in any fields not set that are required to have valid data. It's mutating the receiver.
func (c *Config) Complete() CompletedConfig {
cc := completedConfig{c}
if c.InsecureServing != nil {
c.InsecureServing.Name = "healthz"
}
if c.InsecureMetricsServing != nil {
c.InsecureMetricsServing.Name = "metrics"
}
return CompletedConfig{&cc}
}
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"configfile.go",
"deprecated.go",
"insecure_serving.go",
"options.go",
],
importpath = "k8s.io/kubernetes/cmd/kube-scheduler/app/options",
visibility = ["//visibility:public"],
deps = [
"//cmd/controller-manager/app/options:go_default_library",
"//cmd/kube-scheduler/app/config:go_default_library",
"//pkg/api/legacyscheme:go_default_library",
"//pkg/apis/componentconfig:go_default_library",
"//pkg/apis/componentconfig/v1alpha1:go_default_library",
"//pkg/client/leaderelectionconfig:go_default_library",
"//pkg/scheduler/factory:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer/json:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
"//vendor/k8s.io/apiserver/pkg/server/options:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//vendor/k8s.io/client-go/informers:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd/api:go_default_library",
"//vendor/k8s.io/client-go/tools/leaderelection:go_default_library",
"//vendor/k8s.io/client-go/tools/leaderelection/resourcelock:go_default_library",
"//vendor/k8s.io/client-go/tools/record:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
go_test(
name = "go_default_test",
srcs = ["insecure_serving_test.go"],
embed = [":go_default_library"],
deps = [
"//cmd/controller-manager/app/options:go_default_library",
"//cmd/kube-scheduler/app/config:go_default_library",
"//pkg/apis/componentconfig:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/rand:go_default_library",
],
)
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package options
import (
"errors"
"fmt"
"io/ioutil"
"os"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
"k8s.io/kubernetes/pkg/apis/componentconfig"
componentconfigv1alpha1 "k8s.io/kubernetes/pkg/apis/componentconfig/v1alpha1"
)
var (
configScheme = runtime.NewScheme()
configCodecs = serializer.NewCodecFactory(configScheme)
)
func init() {
componentconfig.AddToScheme(configScheme)
componentconfigv1alpha1.AddToScheme(configScheme)
}
func loadConfigFromFile(file string) (*componentconfig.KubeSchedulerConfiguration, error) {
data, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
return loadConfig(data)
}
func loadConfig(data []byte) (*componentconfig.KubeSchedulerConfiguration, error) {
configObj, gvk, err := configCodecs.UniversalDecoder().Decode(data, nil, nil)
if err != nil {
return nil, err
}
config, ok := configObj.(*componentconfig.KubeSchedulerConfiguration)
if !ok {
return nil, fmt.Errorf("got unexpected config type: %v", gvk)
}
return config, nil
}
// WriteConfigFile writes the config into the given file name as YAML.
func WriteConfigFile(fileName string, cfg *componentconfig.KubeSchedulerConfiguration) error {
var encoder runtime.Encoder
mediaTypes := configCodecs.SupportedMediaTypes()
for _, info := range mediaTypes {
if info.MediaType == "application/yaml" {
encoder = info.Serializer
break
}
}
if encoder == nil {
return errors.New("unable to locate yaml encoder")
}
encoder = json.NewYAMLSerializer(json.DefaultMetaFactory, configScheme, configScheme)
encoder = configCodecs.EncoderForVersion(encoder, componentconfigv1alpha1.SchemeGroupVersion)
configFile, err := os.Create(fileName)
if err != nil {
return err
}
defer configFile.Close()
if err := encoder.Encode(cfg, configFile); err != nil {
return err
}
return nil
}
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package options
import (
"fmt"
"github.com/spf13/pflag"
"k8s.io/kubernetes/pkg/apis/componentconfig"
"k8s.io/kubernetes/pkg/scheduler/factory"
)
// DeprecatedOptions contains deprecated options and their flags.
// TODO remove these fields once the deprecated flags are removed.
type DeprecatedOptions struct {
// The fields below here are placeholders for flags that can't be directly
// mapped into componentconfig.KubeSchedulerConfiguration.
PolicyConfigFile string
PolicyConfigMapName string
PolicyConfigMapNamespace string
UseLegacyPolicyConfig bool
AlgorithmProvider string
}
// AddFlags adds flags for the deprecated options.
func (o *DeprecatedOptions) AddFlags(fs *pflag.FlagSet, cfg *componentconfig.KubeSchedulerConfiguration) {
if o == nil {
return
}
// TODO: unify deprecation mechanism, string prefix or MarkDeprecated (the latter hides the flag. We also don't want that).
fs.StringVar(&o.AlgorithmProvider, "algorithm-provider", o.AlgorithmProvider, "DEPRECATED: the scheduling algorithm provider to use, one of: "+factory.ListAlgorithmProviders())
fs.StringVar(&o.PolicyConfigFile, "policy-config-file", o.PolicyConfigFile, "DEPRECATED: file with scheduler policy configuration. This file is used if policy ConfigMap is not provided or --use-legacy-policy-config=true")
usage := fmt.Sprintf("DEPRECATED: name of the ConfigMap object that contains scheduler's policy configuration. It must exist in the system namespace before scheduler initialization if --use-legacy-policy-config=false. The config must be provided as the value of an element in 'Data' map with the key='%v'", componentconfig.SchedulerPolicyConfigMapKey)
fs.StringVar(&o.PolicyConfigMapName, "policy-configmap", o.PolicyConfigMapName, usage)
fs.StringVar(&o.PolicyConfigMapNamespace, "policy-configmap-namespace", o.PolicyConfigMapNamespace, "DEPRECATED: the namespace where policy ConfigMap is located. The kube-system namespace will be used if this is not provided or is empty.")
fs.BoolVar(&o.UseLegacyPolicyConfig, "use-legacy-policy-config", o.UseLegacyPolicyConfig, "DEPRECATED: when set to true, scheduler will ignore policy ConfigMap and uses policy config file")
fs.BoolVar(&cfg.EnableProfiling, "profiling", cfg.EnableProfiling, "DEPRECATED: enable profiling via web interface host:port/debug/pprof/")
fs.BoolVar(&cfg.EnableContentionProfiling, "contention-profiling", cfg.EnableContentionProfiling, "DEPRECATED: enable lock contention profiling, if profiling is enabled")
fs.StringVar(&cfg.ClientConnection.KubeConfigFile, "kubeconfig", cfg.ClientConnection.KubeConfigFile, "DEPRECATED: path to kubeconfig file with authorization and master location information.")
fs.StringVar(&cfg.ClientConnection.ContentType, "kube-api-content-type", cfg.ClientConnection.ContentType, "DEPRECATED: content type of requests sent to apiserver.")
fs.Float32Var(&cfg.ClientConnection.QPS, "kube-api-qps", cfg.ClientConnection.QPS, "DEPRECATED: QPS to use while talking with kubernetes apiserver")
fs.Int32Var(&cfg.ClientConnection.Burst, "kube-api-burst", cfg.ClientConnection.Burst, "DEPRECATED: burst to use while talking with kubernetes apiserver")
fs.StringVar(&cfg.SchedulerName, "scheduler-name", cfg.SchedulerName, "DEPRECATED: name of the scheduler, used to select which pods will be processed by this scheduler, based on pod's \"spec.schedulerName\".")
fs.StringVar(&cfg.LeaderElection.LockObjectNamespace, "lock-object-namespace", cfg.LeaderElection.LockObjectNamespace, "DEPRECATED: define the namespace of the lock object.")
fs.StringVar(&cfg.LeaderElection.LockObjectName, "lock-object-name", cfg.LeaderElection.LockObjectName, "DEPRECATED: define the name of the lock object.")
fs.Int32Var(&cfg.HardPodAffinitySymmetricWeight, "hard-pod-affinity-symmetric-weight", cfg.HardPodAffinitySymmetricWeight,
"RequiredDuringScheduling affinity is not symmetric, but there is an implicit PreferredDuringScheduling affinity rule corresponding "+
"to every RequiredDuringScheduling affinity rule. --hard-pod-affinity-symmetric-weight represents the weight of implicit PreferredDuringScheduling affinity rule.")
fs.MarkDeprecated("hard-pod-affinity-symmetric-weight", "This option was moved to the policy configuration file")
fs.StringVar(&cfg.FailureDomains, "failure-domains", cfg.FailureDomains, "Indicate the \"all topologies\" set for an empty topologyKey when it's used for PreferredDuringScheduling pod anti-affinity.")
fs.MarkDeprecated("failure-domains", "Doesn't have any effect. Will be removed in future version.")
}
// Validate validates the deprecated scheduler options.
func (o *DeprecatedOptions) Validate() []error {
if o != nil {
return nil
}
return nil
}
// ApplyTo sets cfg.AlgorithmSource from flags passed on the command line in the following precedence order:
//
// 1. --use-legacy-policy-config to use a policy file.
// 2. --policy-configmap to use a policy config map value.
// 3. --algorithm-provider to use a named algorithm provider.
func (o *DeprecatedOptions) ApplyTo(cfg *componentconfig.KubeSchedulerConfiguration) error {
if o == nil {
return nil
}
switch {
case o.UseLegacyPolicyConfig || (len(o.PolicyConfigFile) > 0 && o.PolicyConfigMapName == ""):
cfg.AlgorithmSource = componentconfig.SchedulerAlgorithmSource{
Policy: &componentconfig.SchedulerPolicySource{
File: &componentconfig.SchedulerPolicyFileSource{
Path: o.PolicyConfigFile,
},
},
}
case len(o.PolicyConfigMapName) > 0:
cfg.AlgorithmSource = componentconfig.SchedulerAlgorithmSource{
Policy: &componentconfig.SchedulerPolicySource{
ConfigMap: &componentconfig.SchedulerPolicyConfigMapSource{
Name: o.PolicyConfigMapName,
Namespace: o.PolicyConfigMapNamespace,
},
},
}
case len(o.AlgorithmProvider) > 0:
cfg.AlgorithmSource = componentconfig.SchedulerAlgorithmSource{
Provider: &o.AlgorithmProvider,
}
}
return nil
}
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package options
import (
"fmt"
"net"
"strconv"
"github.com/spf13/pflag"
controlleroptions "k8s.io/kubernetes/cmd/controller-manager/app/options"
schedulerappconfig "k8s.io/kubernetes/cmd/kube-scheduler/app/config"
"k8s.io/kubernetes/pkg/apis/componentconfig"
)
// CombinedInsecureServingOptions sets up up to two insecure listeners for healthz and metrics. The flags
// override the ComponentConfig and InsecureServingOptions values for both.
type CombinedInsecureServingOptions struct {
Healthz *controlleroptions.InsecureServingOptions
Metrics *controlleroptions.InsecureServingOptions
BindPort int // overrides the structs above on ApplyTo, ignored on ApplyToFromLoadedConfig
BindAddress string // overrides the structs above on ApplyTo, ignored on ApplyToFromLoadedConfig
}
// AddFlags adds flags for the insecure serving options.
func (o *CombinedInsecureServingOptions) AddFlags(fs *pflag.FlagSet) {
if o == nil {
return
}
fs.StringVar(&o.BindAddress, "address", o.BindAddress, "DEPRECATED: the IP address on which to listen for the --port port (set to 0.0.0.0 for all IPv4 interfaces and :: for all IPv6 interfaces). See --bind-address instead.")
// MarkDeprecated hides the flag from the help. We don't want that:
// fs.MarkDeprecated("address", "see --bind-address instead.")
fs.IntVar(&o.BindPort, "port", o.BindPort, "DEPRECATED: the port on which to serve HTTP insecurely without authentication and authorization. If 0, don't serve HTTPS at all. See --secure-port instead.")
// MarkDeprecated hides the flag from the help. We don't want that:
// fs.MarkDeprecated("port", "see --secure-port instead.")
}
func (o *CombinedInsecureServingOptions) applyTo(c *schedulerappconfig.Config, componentConfig *componentconfig.KubeSchedulerConfiguration) error {
if err := updateAddressFromInsecureServingOptions(&componentConfig.HealthzBindAddress, o.Healthz); err != nil {
return err
}
if err := updateAddressFromInsecureServingOptions(&componentConfig.MetricsBindAddress, o.Metrics); err != nil {
return err
}
if err := o.Healthz.ApplyTo(&c.InsecureServing); err != nil {
return err
}
if o.Metrics != nil && (c.ComponentConfig.MetricsBindAddress != c.ComponentConfig.HealthzBindAddress || o.Healthz == nil) {
if err := o.Metrics.ApplyTo(&c.InsecureMetricsServing); err != nil {
return err
}
}
return nil
}
// ApplyTo applies the insecure serving options to the given scheduler app configuration, and updates the componentConfig.
func (o *CombinedInsecureServingOptions) ApplyTo(c *schedulerappconfig.Config, componentConfig *componentconfig.KubeSchedulerConfiguration) error {
if o == nil {
componentConfig.HealthzBindAddress = ""
componentConfig.MetricsBindAddress = ""
return nil
}
if o.Healthz != nil {
o.Healthz.BindPort = o.BindPort
o.Healthz.BindAddress = net.ParseIP(o.BindAddress)
}
if o.Metrics != nil {
o.Metrics.BindPort = o.BindPort
o.Metrics.BindAddress = net.ParseIP(o.BindAddress)
}
return o.applyTo(c, componentConfig)
}
// ApplyToFromLoadedConfig updates the insecure serving options from the component config and then appies it to the given scheduler app configuration.
func (o *CombinedInsecureServingOptions) ApplyToFromLoadedConfig(c *schedulerappconfig.Config, componentConfig *componentconfig.KubeSchedulerConfiguration) error {
if o == nil {
return nil
}
if err := updateInsecureServingOptionsFromAddress(o.Healthz, componentConfig.HealthzBindAddress); err != nil {
return fmt.Errorf("invalid healthz address: %v", err)
}
if err := updateInsecureServingOptionsFromAddress(o.Metrics, componentConfig.MetricsBindAddress); err != nil {
return fmt.Errorf("invalid metrics address: %v", err)
}
return o.applyTo(c, componentConfig)
}
func updateAddressFromInsecureServingOptions(addr *string, is *controlleroptions.InsecureServingOptions) error {
if is == nil {
*addr = ""
} else {
if is.Listener != nil {
*addr = is.Listener.Addr().String()
} else if is.BindPort == 0 {
*addr = ""
} else {
*addr = net.JoinHostPort(is.BindAddress.String(), strconv.Itoa(is.BindPort))
}
}
return nil
}
func updateInsecureServingOptionsFromAddress(is *controlleroptions.InsecureServingOptions, addr string) error {
if is == nil {
return nil
}
if len(addr) == 0 {
is.BindPort = 0
return nil
}
host, portInt, err := splitHostIntPort(addr)
if err != nil {
return fmt.Errorf("invalid address %q", addr)
}
is.BindAddress = net.ParseIP(host)
is.BindPort = portInt
return nil
}
// Validate validates the insecure serving options.
func (o *CombinedInsecureServingOptions) Validate() []error {
if o == nil {
return nil
}
errors := []error{}
if o.BindPort <= 0 || o.BindPort > 32767 {
errors = append(errors, fmt.Errorf("--insecure-port %v must be between 0 and 32767, inclusive. 0 for turning off insecure (HTTP) port", o.BindPort))
}
if len(o.BindAddress) > 0 && net.ParseIP(o.BindAddress) == nil {
errors = append(errors, fmt.Errorf("--address has no valid IP address"))
}
return errors
}
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package options
import (
"fmt"
"net"
"strconv"
"testing"
"k8s.io/apimachinery/pkg/util/rand"
"k8s.io/kubernetes/cmd/controller-manager/app/options"
schedulerappconfig "k8s.io/kubernetes/cmd/kube-scheduler/app/config"
"k8s.io/kubernetes/pkg/apis/componentconfig"
)
func TestOptions_ApplyTo(t *testing.T) {
tests := []struct {
name string
options Options
configLoaded bool
expectHealthzBindAddress, expectMetricsBindAddress string
expectInsecureServingAddress, expectInsecureMetricsServingAddress string
expectInsecureServingPort, expectInsecureMetricsServingPort int
wantErr bool
}{
{
name: "no config, zero port",
options: Options{
ComponentConfig: componentconfig.KubeSchedulerConfiguration{
HealthzBindAddress: "1.2.3.4:1234",
MetricsBindAddress: "1.2.3.4:1234",
},
CombinedInsecureServing: &CombinedInsecureServingOptions{
Healthz: &options.InsecureServingOptions{},
Metrics: &options.InsecureServingOptions{},
BindPort: 0,
},
},
configLoaded: false,
},
{
name: "config loaded, non-nil healthz",
options: Options{
ComponentConfig: componentconfig.KubeSchedulerConfiguration{
HealthzBindAddress: "1.2.3.4:1234",
MetricsBindAddress: "1.2.3.4:1234",
},
CombinedInsecureServing: &CombinedInsecureServingOptions{
Healthz: &options.InsecureServingOptions{},
BindPort: 0,
},
},
configLoaded: true,
expectHealthzBindAddress: "1.2.3.4:1234",
expectInsecureServingPort: 1234,
expectInsecureServingAddress: "1.2.3.4",
},
{
name: "config loaded, non-nil metrics",
options: Options{
ComponentConfig: componentconfig.KubeSchedulerConfiguration{
HealthzBindAddress: "1.2.3.4:1234",
MetricsBindAddress: "1.2.3.4:1234",
},
CombinedInsecureServing: &CombinedInsecureServingOptions{
Metrics: &options.InsecureServingOptions{},
BindPort: 0,
},
},
configLoaded: true,
expectMetricsBindAddress: "1.2.3.4:1234",
expectInsecureMetricsServingPort: 1234,
expectInsecureMetricsServingAddress: "1.2.3.4",
},
{
name: "config loaded, all set, zero BindPort",
options: Options{
ComponentConfig: componentconfig.KubeSchedulerConfiguration{
HealthzBindAddress: "1.2.3.4:1234",
MetricsBindAddress: "1.2.3.4:1234",
},
CombinedInsecureServing: &CombinedInsecureServingOptions{
Healthz: &options.InsecureServingOptions{},
Metrics: &options.InsecureServingOptions{},
BindPort: 0,
},
},
configLoaded: true,
expectHealthzBindAddress: "1.2.3.4:1234",
expectInsecureServingPort: 1234,
expectInsecureServingAddress: "1.2.3.4",
expectMetricsBindAddress: "1.2.3.4:1234",
},
{
name: "config loaded, all set, different addresses",
options: Options{
ComponentConfig: componentconfig.KubeSchedulerConfiguration{
HealthzBindAddress: "1.2.3.4:1234",
MetricsBindAddress: "1.2.3.4:1235",
},
CombinedInsecureServing: &CombinedInsecureServingOptions{
Healthz: &options.InsecureServingOptions{},
Metrics: &options.InsecureServingOptions{},
BindPort: 0,
},
},
configLoaded: true,
expectHealthzBindAddress: "1.2.3.4:1234",
expectInsecureServingPort: 1234,
expectInsecureServingAddress: "1.2.3.4",
expectMetricsBindAddress: "1.2.3.4:1235",
expectInsecureMetricsServingPort: 1235,
expectInsecureMetricsServingAddress: "1.2.3.4",
},
{
name: "no config, all set, port passed",
options: Options{
ComponentConfig: componentconfig.KubeSchedulerConfiguration{
HealthzBindAddress: "1.2.3.4:1234",
MetricsBindAddress: "1.2.3.4:1234",
},
CombinedInsecureServing: &CombinedInsecureServingOptions{
Healthz: &options.InsecureServingOptions{},
Metrics: &options.InsecureServingOptions{},
BindPort: 1236,
BindAddress: "1.2.3.4",
},
},
configLoaded: false,
expectHealthzBindAddress: "1.2.3.4:1236",
expectInsecureServingPort: 1236,
expectInsecureServingAddress: "1.2.3.4",
expectMetricsBindAddress: "1.2.3.4:1236",
},
{
name: "no config, all set, address passed",
options: Options{
ComponentConfig: componentconfig.KubeSchedulerConfiguration{
HealthzBindAddress: "1.2.3.4:1234",
MetricsBindAddress: "1.2.3.4:1234",
},
CombinedInsecureServing: &CombinedInsecureServingOptions{
Healthz: &options.InsecureServingOptions{},
Metrics: &options.InsecureServingOptions{},
BindAddress: "2.3.4.5",
BindPort: 1234,
},
},
configLoaded: false,
expectHealthzBindAddress: "2.3.4.5:1234",
expectInsecureServingPort: 1234,
expectInsecureServingAddress: "2.3.4.5",
expectMetricsBindAddress: "2.3.4.5:1234",
},
{
name: "no config, all set, zero port passed",
options: Options{
ComponentConfig: componentconfig.KubeSchedulerConfiguration{
HealthzBindAddress: "1.2.3.4:1234",
MetricsBindAddress: "1.2.3.4:1234",
},
CombinedInsecureServing: &CombinedInsecureServingOptions{
Healthz: &options.InsecureServingOptions{},
Metrics: &options.InsecureServingOptions{},
BindAddress: "2.3.4.5",
BindPort: 0,
},
},
configLoaded: false,
},
}
for i, tt := range tests {
t.Run(fmt.Sprintf("%d-%s", i, tt.name), func(t *testing.T) {
c := schedulerappconfig.Config{
ComponentConfig: tt.options.ComponentConfig,
}
if tt.options.CombinedInsecureServing != nil {
if tt.options.CombinedInsecureServing.Healthz != nil {
tt.options.CombinedInsecureServing.Healthz.ListenFunc = createMockListener
}
if tt.options.CombinedInsecureServing.Metrics != nil {
tt.options.CombinedInsecureServing.Metrics.ListenFunc = createMockListener
}
}
if tt.configLoaded {
if err := tt.options.CombinedInsecureServing.ApplyToFromLoadedConfig(&c, &c.ComponentConfig); (err != nil) != tt.wantErr {
t.Fatalf("%d - Options.ApplyTo() error = %v, wantErr %v", i, err, tt.wantErr)
}
} else {
if err := tt.options.CombinedInsecureServing.ApplyTo(&c, &c.ComponentConfig); (err != nil) != tt.wantErr {
t.Fatalf("%d - Options.ApplyTo() error = %v, wantErr %v", i, err, tt.wantErr)
}
}
if got, expect := c.ComponentConfig.HealthzBindAddress, tt.expectHealthzBindAddress; got != expect {
t.Errorf("%d - expected HealthzBindAddress %q, got %q", i, expect, got)
}
if got, expect := c.ComponentConfig.MetricsBindAddress, tt.expectMetricsBindAddress; got != expect {
t.Errorf("%d - expected MetricsBindAddress %q, got %q", i, expect, got)
}
if got, expect := c.InsecureServing != nil, tt.expectInsecureServingPort != 0; got != expect {
t.Errorf("%d - expected InsecureServing != nil to be %v, got %v", i, expect, got)
} else if c.InsecureServing != nil {
if got, expect := c.InsecureServing.Listener.(*mockListener).address, tt.expectInsecureServingAddress; got != expect {
t.Errorf("%d - expected healthz address %q, got %q", i, expect, got)
}
if got, expect := c.InsecureServing.Listener.(*mockListener).port, tt.expectInsecureServingPort; got != expect {
t.Errorf("%d - expected healthz port %v, got %v", i, expect, got)
}
}
if got, expect := c.InsecureMetricsServing != nil, tt.expectInsecureMetricsServingPort != 0; got != expect {
t.Errorf("%d - expected Metrics != nil to be %v, got %v", i, expect, got)
} else if c.InsecureMetricsServing != nil {
if got, expect := c.InsecureMetricsServing.Listener.(*mockListener).address, tt.expectInsecureMetricsServingAddress; got != expect {
t.Errorf("%d - expected metrics address %q, got %q", i, expect, got)
}
if got, expect := c.InsecureMetricsServing.Listener.(*mockListener).port, tt.expectInsecureMetricsServingPort; got != expect {
t.Errorf("%d - expected metrics port %v, got %v", i, expect, got)
}
}
})
}
}
type mockListener struct {
address string
port int
}
func createMockListener(network, addr string) (net.Listener, int, error) {
host, portInt, err := splitHostIntPort(addr)
if err != nil {
return nil, 0, err
}
if portInt == 0 {
portInt = rand.IntnRange(1, 32767)
}
return &mockListener{host, portInt}, portInt, nil
}
func (l *mockListener) Accept() (net.Conn, error) { return nil, nil }
func (l *mockListener) Close() error { return nil }
func (l *mockListener) Addr() net.Addr {
return mockAddr(net.JoinHostPort(l.address, strconv.Itoa(l.port)))
}
type mockAddr string
func (a mockAddr) Network() string { return "tcp" }
func (a mockAddr) String() string { return string(a) }
...@@ -51,7 +51,7 @@ go_library( ...@@ -51,7 +51,7 @@ go_library(
deps = [ deps = [
"//cmd/kube-apiserver/app/options:go_default_library", "//cmd/kube-apiserver/app/options:go_default_library",
"//cmd/kube-controller-manager/app/options:go_default_library", "//cmd/kube-controller-manager/app/options:go_default_library",
"//cmd/kube-scheduler/app/options:go_default_library", "//cmd/kube-scheduler/app:go_default_library",
"//cmd/kubeadm/app/apis/kubeadm:go_default_library", "//cmd/kubeadm/app/apis/kubeadm:go_default_library",
"//cmd/kubeadm/app/apis/kubeadm/v1alpha1:go_default_library", "//cmd/kubeadm/app/apis/kubeadm/v1alpha1:go_default_library",
"//cmd/kubeadm/app/constants:go_default_library", "//cmd/kubeadm/app/constants:go_default_library",
......
...@@ -46,7 +46,7 @@ import ( ...@@ -46,7 +46,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
apiservoptions "k8s.io/kubernetes/cmd/kube-apiserver/app/options" apiservoptions "k8s.io/kubernetes/cmd/kube-apiserver/app/options"
cmoptions "k8s.io/kubernetes/cmd/kube-controller-manager/app/options" cmoptions "k8s.io/kubernetes/cmd/kube-controller-manager/app/options"
scheduleroptions "k8s.io/kubernetes/cmd/kube-scheduler/app/options" schedulerapp "k8s.io/kubernetes/cmd/kube-scheduler/app"
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmdefaults "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha1" kubeadmdefaults "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha1"
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants" kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
...@@ -548,7 +548,7 @@ func (eac ExtraArgsCheck) Check() (warnings, errors []error) { ...@@ -548,7 +548,7 @@ func (eac ExtraArgsCheck) Check() (warnings, errors []error) {
warnings = append(warnings, argsCheck("kube-controller-manager", eac.ControllerManagerExtraArgs, flags)...) warnings = append(warnings, argsCheck("kube-controller-manager", eac.ControllerManagerExtraArgs, flags)...)
} }
if len(eac.SchedulerExtraArgs) > 0 { if len(eac.SchedulerExtraArgs) > 0 {
opts, err := scheduleroptions.NewOptions() opts, err := schedulerapp.NewOptions()
if err != nil { if err != nil {
warnings = append(warnings, err) warnings = append(warnings, err)
} }
......
...@@ -23,7 +23,6 @@ go_test( ...@@ -23,7 +23,6 @@ go_test(
tags = ["integration"], tags = ["integration"],
deps = [ deps = [
"//cmd/kube-scheduler/app:go_default_library", "//cmd/kube-scheduler/app:go_default_library",
"//cmd/kube-scheduler/app/config:go_default_library",
"//pkg/api/legacyscheme:go_default_library", "//pkg/api/legacyscheme:go_default_library",
"//pkg/api/testapi:go_default_library", "//pkg/api/testapi:go_default_library",
"//pkg/apis/componentconfig:go_default_library", "//pkg/apis/componentconfig:go_default_library",
......
...@@ -42,7 +42,6 @@ import ( ...@@ -42,7 +42,6 @@ import (
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
schedulerapp "k8s.io/kubernetes/cmd/kube-scheduler/app" schedulerapp "k8s.io/kubernetes/cmd/kube-scheduler/app"
schedulerappconfig "k8s.io/kubernetes/cmd/kube-scheduler/app/config"
"k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/testapi" "k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/apis/componentconfig" "k8s.io/kubernetes/pkg/apis/componentconfig"
...@@ -182,19 +181,17 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) { ...@@ -182,19 +181,17 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) {
eventBroadcaster := record.NewBroadcaster() eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartRecordingToSink(&clientv1core.EventSinkImpl{Interface: clientSet.CoreV1().Events("")}) eventBroadcaster.StartRecordingToSink(&clientv1core.EventSinkImpl{Interface: clientSet.CoreV1().Events("")})
ss := &schedulerappconfig.Config{ ss := &schedulerapp.SchedulerServer{
ComponentConfig: componentconfig.KubeSchedulerConfiguration{ SchedulerName: v1.DefaultSchedulerName,
HardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight, AlgorithmSource: componentconfig.SchedulerAlgorithmSource{
SchedulerName: v1.DefaultSchedulerName, Policy: &componentconfig.SchedulerPolicySource{
AlgorithmSource: componentconfig.SchedulerAlgorithmSource{ ConfigMap: &componentconfig.SchedulerPolicyConfigMapSource{
Policy: &componentconfig.SchedulerPolicySource{ Namespace: policyConfigMap.Namespace,
ConfigMap: &componentconfig.SchedulerPolicyConfigMapSource{ Name: policyConfigMap.Name,
Namespace: policyConfigMap.Namespace,
Name: policyConfigMap.Name,
},
}, },
}, },
}, },
HardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight,
Client: clientSet, Client: clientSet,
InformerFactory: informerFactory, InformerFactory: informerFactory,
PodInformer: factory.NewPodInformer(clientSet, 0), PodInformer: factory.NewPodInformer(clientSet, 0),
...@@ -203,7 +200,7 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) { ...@@ -203,7 +200,7 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) {
Broadcaster: eventBroadcaster, Broadcaster: eventBroadcaster,
} }
config, err := schedulerapp.NewSchedulerConfig(ss.Complete()) config, err := ss.SchedulerConfig()
if err != nil { if err != nil {
t.Fatalf("couldn't make scheduler config: %v", err) t.Fatalf("couldn't make scheduler config: %v", err)
} }
...@@ -243,19 +240,17 @@ func TestSchedulerCreationFromNonExistentConfigMap(t *testing.T) { ...@@ -243,19 +240,17 @@ func TestSchedulerCreationFromNonExistentConfigMap(t *testing.T) {
eventBroadcaster := record.NewBroadcaster() eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartRecordingToSink(&clientv1core.EventSinkImpl{Interface: clientSet.CoreV1().Events("")}) eventBroadcaster.StartRecordingToSink(&clientv1core.EventSinkImpl{Interface: clientSet.CoreV1().Events("")})
ss := &schedulerappconfig.Config{ ss := &schedulerapp.SchedulerServer{
ComponentConfig: componentconfig.KubeSchedulerConfiguration{ SchedulerName: v1.DefaultSchedulerName,
SchedulerName: v1.DefaultSchedulerName, AlgorithmSource: componentconfig.SchedulerAlgorithmSource{
AlgorithmSource: componentconfig.SchedulerAlgorithmSource{ Policy: &componentconfig.SchedulerPolicySource{
Policy: &componentconfig.SchedulerPolicySource{ ConfigMap: &componentconfig.SchedulerPolicyConfigMapSource{
ConfigMap: &componentconfig.SchedulerPolicyConfigMapSource{ Namespace: "non-existent-config",
Namespace: "non-existent-config", Name: "non-existent-config",
Name: "non-existent-config",
},
}, },
}, },
HardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight,
}, },
HardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight,
Client: clientSet, Client: clientSet,
InformerFactory: informerFactory, InformerFactory: informerFactory,
PodInformer: factory.NewPodInformer(clientSet, 0), PodInformer: factory.NewPodInformer(clientSet, 0),
...@@ -264,7 +259,7 @@ func TestSchedulerCreationFromNonExistentConfigMap(t *testing.T) { ...@@ -264,7 +259,7 @@ func TestSchedulerCreationFromNonExistentConfigMap(t *testing.T) {
Broadcaster: eventBroadcaster, Broadcaster: eventBroadcaster,
} }
_, err := schedulerapp.NewSchedulerConfig(ss.Complete()) _, err := ss.SchedulerConfig()
if err == nil { if err == nil {
t.Fatalf("Creation of scheduler didn't fail while the policy ConfigMap didn't exist.") t.Fatalf("Creation of scheduler didn't fail while the policy ConfigMap didn't exist.")
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment