From d6896fa45a17f86cc3a3dbb30c25908d01f87a84 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Tue, 19 Apr 2016 09:35:32 +0200 Subject: [PATCH] Allow setting content-type in binaries --- .../app/controllermanager.go | 1 + cmd/kube-controller-manager/app/options/options.go | 1 + cmd/kube-proxy/app/options/options.go | 2 ++ cmd/kube-proxy/app/server.go | 1 + cmd/kubelet/app/options/options.go | 1 + cmd/kubelet/app/server.go | 1 + cmd/kubemark/hollow-node.go | 13 ++++++++----- pkg/apis/componentconfig/types.go | 8 +++++++- pkg/apis/componentconfig/v1alpha1/types.go | 2 ++ plugin/cmd/kube-scheduler/app/options/options.go | 1 + plugin/cmd/kube-scheduler/app/server.go | 1 + 11 files changed, 26 insertions(+), 6 deletions(-) diff --git a/cmd/kube-controller-manager/app/controllermanager.go b/cmd/kube-controller-manager/app/controllermanager.go index eac87640ca6..2feb17825dd 100644 --- a/cmd/kube-controller-manager/app/controllermanager.go +++ b/cmd/kube-controller-manager/app/controllermanager.go @@ -123,6 +123,7 @@ func Run(s *options.CMServer) error { return err } + kubeconfig.ContentConfig.ContentType = s.ContentType // Override kubeconfig qps/burst settings from flags kubeconfig.QPS = s.KubeAPIQPS kubeconfig.Burst = s.KubeAPIBurst diff --git a/cmd/kube-controller-manager/app/options/options.go b/cmd/kube-controller-manager/app/options/options.go index 764dc2afe26..7204deba36f 100644 --- a/cmd/kube-controller-manager/app/options/options.go +++ b/cmd/kube-controller-manager/app/options/options.go @@ -145,6 +145,7 @@ func (s *CMServer) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&s.Master, "master", s.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig)") fs.StringVar(&s.Kubeconfig, "kubeconfig", s.Kubeconfig, "Path to kubeconfig file with authorization and master location information.") fs.StringVar(&s.RootCAFile, "root-ca-file", s.RootCAFile, "If set, this root certificate authority will be included in service account's token secret. This must be a valid PEM-encoded CA bundle.") + fs.StringVar(&s.ContentType, "kube-api-content-type", s.ContentType, "ContentType of requests sent to apiserver. Passing application/vnd.kubernetes.protobuf is an experimental feature now.") fs.Float32Var(&s.KubeAPIQPS, "kube-api-qps", s.KubeAPIQPS, "QPS to use while talking with kubernetes apiserver") fs.IntVar(&s.KubeAPIBurst, "kube-api-burst", s.KubeAPIBurst, "Burst to use while talking with kubernetes apiserver") fs.DurationVar(&s.ControllerStartInterval.Duration, "controller-start-interval", s.ControllerStartInterval.Duration, "Interval between starting controller managers.") diff --git a/cmd/kube-proxy/app/options/options.go b/cmd/kube-proxy/app/options/options.go index 425b1ae744f..388ccb859f0 100644 --- a/cmd/kube-proxy/app/options/options.go +++ b/cmd/kube-proxy/app/options/options.go @@ -38,6 +38,7 @@ const ( type ProxyServerConfig struct { componentconfig.KubeProxyConfiguration ResourceContainer string + ContentType string KubeAPIQPS float32 KubeAPIBurst int ConfigSyncPeriod time.Duration @@ -77,6 +78,7 @@ func (s *ProxyServerConfig) AddFlags(fs *pflag.FlagSet) { fs.BoolVar(&s.MasqueradeAll, "masquerade-all", s.MasqueradeAll, "If using the pure iptables proxy, SNAT everything") fs.StringVar(&s.ClusterCIDR, "cluster-cidr", s.ClusterCIDR, "The CIDR range of pods in the cluster. It is used to bridge traffic coming from outside of the cluster. If not provided, no off-cluster bridging will be performed.") fs.BoolVar(&s.CleanupAndExit, "cleanup-iptables", s.CleanupAndExit, "If true cleanup iptables rules and exit.") + fs.StringVar(&s.ContentType, "kube-api-content-type", s.ContentType, "ContentType of requests sent to apiserver. Passing application/vnd.kubernetes.protobuf is an experimental feature now.") fs.Float32Var(&s.KubeAPIQPS, "kube-api-qps", s.KubeAPIQPS, "QPS to use while talking with kubernetes apiserver") fs.IntVar(&s.KubeAPIBurst, "kube-api-burst", s.KubeAPIBurst, "Burst to use while talking with kubernetes apiserver") fs.DurationVar(&s.UDPIdleTimeout.Duration, "udp-timeout", s.UDPIdleTimeout.Duration, "How long an idle UDP connection will be kept open (e.g. '250ms', '2s'). Must be greater than 0. Only applicable for proxy-mode=userspace") diff --git a/cmd/kube-proxy/app/server.go b/cmd/kube-proxy/app/server.go index e97fdd0badb..256c5764bf6 100644 --- a/cmd/kube-proxy/app/server.go +++ b/cmd/kube-proxy/app/server.go @@ -178,6 +178,7 @@ func NewProxyServerDefault(config *options.ProxyServerConfig) (*ProxyServer, err return nil, err } + kubeconfig.ContentType = config.ContentType // Override kubeconfig qps/burst settings from flags kubeconfig.QPS = config.KubeAPIQPS kubeconfig.Burst = config.KubeAPIBurst diff --git a/cmd/kubelet/app/options/options.go b/cmd/kubelet/app/options/options.go index f4b61cd9eb3..30a1060c18b 100644 --- a/cmd/kubelet/app/options/options.go +++ b/cmd/kubelet/app/options/options.go @@ -245,6 +245,7 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) { fs.Var(&s.SystemReserved, "system-reserved", "A set of ResourceName=ResourceQuantity (e.g. cpu=200m,memory=150G) pairs that describe resources reserved for non-kubernetes components. Currently only cpu and memory are supported. See http://releases.k8s.io/HEAD/docs/user-guide/compute-resources.md for more detail. [default=none]") fs.Var(&s.KubeReserved, "kube-reserved", "A set of ResourceName=ResourceQuantity (e.g. cpu=200m,memory=150G) pairs that describe resources reserved for kubernetes system components. Currently only cpu and memory are supported. See http://releases.k8s.io/HEAD/docs/user-guide/compute-resources.md for more detail. [default=none]") fs.BoolVar(&s.RegisterSchedulable, "register-schedulable", s.RegisterSchedulable, "Register the node as schedulable. No-op if register-node is false. [default=true]") + fs.StringVar(&s.ContentType, "kube-api-content-type", s.ContentType, "ContentType of requests sent to apiserver. Passing application/vnd.kubernetes.protobuf is an experimental feature now.") fs.Float32Var(&s.KubeAPIQPS, "kube-api-qps", s.KubeAPIQPS, "QPS to use while talking with kubernetes apiserver") fs.IntVar(&s.KubeAPIBurst, "kube-api-burst", s.KubeAPIBurst, "Burst to use while talking with kubernetes apiserver") fs.BoolVar(&s.SerializeImagePulls, "serialize-image-pulls", s.SerializeImagePulls, "Pull images one at a time. We recommend *not* changing the default value on nodes that run docker daemon with version < 1.9 or an Aufs storage backend. Issue #10959 has more details. [default=true]") diff --git a/cmd/kubelet/app/server.go b/cmd/kubelet/app/server.go index 258244aff57..8f45875b931 100644 --- a/cmd/kubelet/app/server.go +++ b/cmd/kubelet/app/server.go @@ -470,6 +470,7 @@ func CreateAPIServerClientConfig(s *options.KubeletServer) (*restclient.Config, return nil, err } + clientConfig.ContentType = s.ContentType // Override kubeconfig qps/burst settings from flags clientConfig.QPS = s.KubeAPIQPS clientConfig.Burst = s.KubeAPIBurst diff --git a/cmd/kubemark/hollow-node.go b/cmd/kubemark/hollow-node.go index bc3a0b95c43..bfac4bb03b0 100644 --- a/cmd/kubemark/hollow-node.go +++ b/cmd/kubemark/hollow-node.go @@ -45,6 +45,7 @@ type HollowNodeConfig struct { Morph string NodeName string ServerPort int + ContentType string } const ( @@ -60,17 +61,19 @@ func (c *HollowNodeConfig) addFlags(fs *pflag.FlagSet) { fs.StringVar(&c.NodeName, "name", "fake-node", "Name of this Hollow Node.") fs.IntVar(&c.ServerPort, "api-server-port", 443, "Port on which API server is listening.") fs.StringVar(&c.Morph, "morph", "", fmt.Sprintf("Specifies into which Hollow component this binary should morph. Allowed values: %v", knownMorphs.List())) + fs.StringVar(&c.ContentType, "kube-api-content-type", "application/json", "ContentType of requests sent to apiserver. Passing application/vnd.kubernetes.protobuf is an experimental feature now.") } -func createClientFromFile(path string) (*client.Client, error) { - c, err := clientcmd.LoadFromFile(path) +func (c *HollowNodeConfig) createClientFromFile() (*client.Client, error) { + clientConfig, err := clientcmd.LoadFromFile(c.KubeconfigPath) if err != nil { - return nil, fmt.Errorf("error while loading kubeconfig from file %v: %v", path, err) + return nil, fmt.Errorf("error while loading kubeconfig from file %v: %v", c.KubeconfigPath, err) } - config, err := clientcmd.NewDefaultClientConfig(*c, &clientcmd.ConfigOverrides{}).ClientConfig() + config, err := clientcmd.NewDefaultClientConfig(*clientConfig, &clientcmd.ConfigOverrides{}).ClientConfig() if err != nil { return nil, fmt.Errorf("error while creating kubeconfig: %v", err) } + config.ContentType = c.ContentType client, err := client.New(config) if err != nil { return nil, fmt.Errorf("error while creating client: %v", err) @@ -90,7 +93,7 @@ func main() { } // create a client to communicate with API server. - cl, err := createClientFromFile(config.KubeconfigPath) + cl, err := config.createClientFromFile() clientset := clientset.FromUnversionedClient(cl) if err != nil { glog.Fatal("Failed to create a Client. Exiting.") diff --git a/pkg/apis/componentconfig/types.go b/pkg/apis/componentconfig/types.go index f6ca7edb2e0..05d5685045c 100644 --- a/pkg/apis/componentconfig/types.go +++ b/pkg/apis/componentconfig/types.go @@ -313,6 +313,8 @@ type KubeletConfiguration struct { // registerSchedulable tells the kubelet to register the node as // schedulable. No-op if register-node is false. RegisterSchedulable bool `json:"registerSchedulable"` + // contentType is contentType of requests sent to apiserver. + ContentType string `json:"contentType"` // kubeAPIQPS is the QPS to use while talking with kubernetes apiserver KubeAPIQPS float32 `json:"kubeAPIQPS"` // kubeAPIBurst is the burst to allow while talking with kubernetes @@ -354,6 +356,8 @@ type KubeSchedulerConfiguration struct { PolicyConfigFile string `json:"policyConfigFile"` // enableProfiling enables profiling via web interface. EnableProfiling bool `json:"enableProfiling"` + // contentType is contentType of requests sent to apiserver. + ContentType string `json:"contentType"` // kubeAPIQPS is the QPS to use while talking with kubernetes apiserver. KubeAPIQPS float32 `json:"kubeAPIQPS"` // kubeAPIBurst is the QPS burst to use while talking with kubernetes apiserver. @@ -506,13 +510,15 @@ type KubeControllerManagerConfiguration struct { // rootCAFile is the root certificate authority will be included in service // account's token secret. This must be a valid PEM-encoded CA bundle. RootCAFile string `json:"rootCAFile"` + // contentType is contentType of requests sent to apiserver. + ContentType string `json:"contentType"` // kubeAPIQPS is the QPS to use while talking with kubernetes apiserver. KubeAPIQPS float32 `json:"kubeAPIQPS"` // kubeAPIBurst is the burst to use while talking with kubernetes apiserver. KubeAPIBurst int `json:"kubeAPIBurst"` // leaderElection defines the configuration of leader election client. LeaderElection LeaderElectionConfiguration `json:"leaderElection"` - // vloumeConfiguration holds configuration for volume related features. + // volumeConfiguration holds configuration for volume related features. VolumeConfiguration VolumeConfiguration `json:"volumeConfiguration"` // How long to wait between starting controller managers ControllerStartInterval unversioned.Duration `json:"controllerStartInterval"` diff --git a/pkg/apis/componentconfig/v1alpha1/types.go b/pkg/apis/componentconfig/v1alpha1/types.go index 307999a4b66..abffc15d42f 100644 --- a/pkg/apis/componentconfig/v1alpha1/types.go +++ b/pkg/apis/componentconfig/v1alpha1/types.go @@ -95,6 +95,8 @@ type KubeSchedulerConfiguration struct { PolicyConfigFile string `json:"policyConfigFile"` // enableProfiling enables profiling via web interface. EnableProfiling *bool `json:"enableProfiling"` + // contentType is contentType of requests sent to apiserver. + ContentType string `json:"contentType"` // kubeAPIQPS is the QPS to use while talking with kubernetes apiserver. KubeAPIQPS float32 `json:"kubeAPIQPS"` // kubeAPIBurst is the QPS burst to use while talking with kubernetes apiserver. diff --git a/plugin/cmd/kube-scheduler/app/options/options.go b/plugin/cmd/kube-scheduler/app/options/options.go index 9696fe03bd8..69cd54945c4 100644 --- a/plugin/cmd/kube-scheduler/app/options/options.go +++ b/plugin/cmd/kube-scheduler/app/options/options.go @@ -63,6 +63,7 @@ func (s *SchedulerServer) AddFlags(fs *pflag.FlagSet) { var unusedBindPodsBurst int fs.IntVar(&unusedBindPodsBurst, "bind-pods-burst", 0, "unused, use --kube-api-burst") fs.MarkDeprecated("bind-pods-burst", "flag is unused and will be removed. Use kube-api-burst instead.") + fs.StringVar(&s.ContentType, "kube-api-content-type", s.ContentType, "ContentType of requests sent to apiserver. Passing application/vnd.kubernetes.protobuf is an experimental feature now.") fs.Float32Var(&s.KubeAPIQPS, "kube-api-qps", s.KubeAPIQPS, "QPS to use while talking with kubernetes apiserver") fs.IntVar(&s.KubeAPIBurst, "kube-api-burst", s.KubeAPIBurst, "Burst to use while talking with kubernetes apiserver") fs.StringVar(&s.SchedulerName, "scheduler-name", s.SchedulerName, "Name of the scheduler, used to select which pods will be processed by this scheduler, based on pod's annotation with key 'scheduler.alpha.kubernetes.io/name'") diff --git a/plugin/cmd/kube-scheduler/app/server.go b/plugin/cmd/kube-scheduler/app/server.go index bb00fa1c1c9..6fe2eb176fa 100644 --- a/plugin/cmd/kube-scheduler/app/server.go +++ b/plugin/cmd/kube-scheduler/app/server.go @@ -79,6 +79,7 @@ func Run(s *options.SchedulerServer) error { return err } + kubeconfig.ContentType = s.ContentType // Override kubeconfig qps/burst settings from flags kubeconfig.QPS = s.KubeAPIQPS kubeconfig.Burst = s.KubeAPIBurst