From 28b4eb57db7fe6ae4cbe2b79ae199dcfc592fea3 Mon Sep 17 00:00:00 2001 From: Dominic Gunn Date: Tue, 26 May 2020 11:27:55 +0100 Subject: [PATCH] Enable the use of autoscaler rest-client without metrics-api server addon --- builtin/files/cluster.yaml.tmpl | 4 ++ .../files/userdata/cloud-config-controller | 2 +- pkg/api/kubernetes.go | 19 +++--- pkg/api/types.go | 4 ++ pkg/model/cluster_test.go | 67 +++++++++++++++++++ 5 files changed, 86 insertions(+), 10 deletions(-) diff --git a/builtin/files/cluster.yaml.tmpl b/builtin/files/cluster.yaml.tmpl index 369099041..692860e7d 100644 --- a/builtin/files/cluster.yaml.tmpl +++ b/builtin/files/cluster.yaml.tmpl @@ -1166,6 +1166,10 @@ kubernetes: encryptionAtRest: enabled: false + # Tells Kubernetes to enable the autoscaler rest client (not using heapster) without the requirement to use metrics-server. + podAutoscalerUseRestClient: + enabled: false + # controllerManager: # resources: # requests: diff --git a/builtin/files/userdata/cloud-config-controller b/builtin/files/userdata/cloud-config-controller index 17becfd33..ff675338e 100644 --- a/builtin/files/userdata/cloud-config-controller +++ b/builtin/files/userdata/cloud-config-controller @@ -3569,7 +3569,7 @@ write_files: - --configure-cloud-routes=false {{ end -}} - --service-cluster-ip-range={{.ServiceCIDR}} {{/* removes the service CIDR range from the cluster CIDR if it intersects */}} - {{ if not .Addons.MetricsServer.Enabled -}} + {{ if and (not .Addons.MetricsServer.Enabled) (not .Kubernetes.PodAutoscalerUseRestClient.Enabled) -}} - --horizontal-pod-autoscaler-use-rest-clients=false {{end}} {{range $f := .ControllerFlags -}} diff --git a/pkg/api/kubernetes.go b/pkg/api/kubernetes.go index e2357fb1f..a3e6aa429 100644 --- a/pkg/api/kubernetes.go +++ b/pkg/api/kubernetes.go @@ -1,15 +1,16 @@ package api type Kubernetes struct { - Authentication KubernetesAuthentication `yaml:"authentication"` - EncryptionAtRest EncryptionAtRest `yaml:"encryptionAtRest"` - Networking Networking `yaml:"networking,omitempty"` - ControllerManager ControllerManager `yaml:"controllerManager,omitempty"` - KubeScheduler KubeScheduler `yaml:"kubeScheduler,omitempty"` - KubeProxy KubeProxy `yaml:"kubeProxy,omitempty"` - KubeApiServer KubeApiServer `yaml:"apiServer,omitempty"` - Kubelet Kubelet `yaml:"kubelet,omitempty"` - APIServer KubernetesAPIServer `yaml:"apiserver,omitempty"` + Authentication KubernetesAuthentication `yaml:"authentication"` + EncryptionAtRest EncryptionAtRest `yaml:"encryptionAtRest"` + PodAutoscalerUseRestClient PodAutoscalerUseRestClient `yaml:"podAutoscalerUseRestClient"` + Networking Networking `yaml:"networking,omitempty"` + ControllerManager ControllerManager `yaml:"controllerManager,omitempty"` + KubeScheduler KubeScheduler `yaml:"kubeScheduler,omitempty"` + KubeProxy KubeProxy `yaml:"kubeProxy,omitempty"` + KubeApiServer KubeApiServer `yaml:"apiServer,omitempty"` + Kubelet Kubelet `yaml:"kubelet,omitempty"` + APIServer KubernetesAPIServer `yaml:"apiserver,omitempty"` // Manifests is a list of manifests to be installed to the cluster. // Note that the list is sorted by their names by kube-aws so that it won't result in unnecessarily node replacements. diff --git a/pkg/api/types.go b/pkg/api/types.go index 40152ae3c..1fee0db07 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -118,6 +118,10 @@ type EncryptionAtRest struct { Enabled bool `yaml:"enabled"` } +type PodAutoscalerUseRestClient struct { + Enabled bool `yaml:"enabled"` +} + type EphemeralImageStorage struct { Enabled bool `yaml:"enabled"` Disk string `yaml:"disk"` diff --git a/pkg/model/cluster_test.go b/pkg/model/cluster_test.go index e68c65fe8..df8698df7 100644 --- a/pkg/model/cluster_test.go +++ b/pkg/model/cluster_test.go @@ -1059,6 +1059,73 @@ encryptionAtRest: } } +func TestPodAutoscalerUseRestClientConfig(t *testing.T) { + validConfigs := []struct { + conf string + podAutoscalerUseRestClient api.PodAutoscalerUseRestClient + }{ + { + conf: ` +`, + podAutoscalerUseRestClient: api.PodAutoscalerUseRestClient{ + Enabled: false, + }, + }, + { + conf: ` +kubernetes: + podAutoscalerUseRestClient: + enabled: false +`, + podAutoscalerUseRestClient: api.PodAutoscalerUseRestClient{ + Enabled: false, + }, + }, + { + conf: ` +kubernetes: + podAutoscalerUseRestClient: + enabled: true +`, + podAutoscalerUseRestClient: api.PodAutoscalerUseRestClient{ + Enabled: true, + }, + }, + { + conf: ` +# Settings for an experimental feature must be under the "experimental" field. Ignored. +podAutoscalerUseRestClient: + enabled: true +`, + podAutoscalerUseRestClient: api.PodAutoscalerUseRestClient{ + Enabled: false, + }, + }, + } + + for _, conf := range validConfigs { + confBody := singleAzConfigYaml + conf.conf + c, err := ClusterFromBytes([]byte(confBody)) + if err != nil { + y, err2 := json.MarshalIndent(c, "", " ") + if err2 != nil { + t.Errorf("%v", err2) + t.FailNow() + } + t.Logf("%s", string(y)) + t.Errorf("failed to parse config: %v:\n%s", err, confBody) + continue + } + if !reflect.DeepEqual(c.Kubernetes.PodAutoscalerUseRestClient, conf.podAutoscalerUseRestClient) { + t.Errorf( + "parsed encryption at rest settings %+v does not match config: %s", + c.Kubernetes.PodAutoscalerUseRestClient, + confBody, + ) + } + } +} + func TestKubeletReserved(t *testing.T) { validConfigs := []struct {