Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

Commit 31612ee

Browse files
omar-nahhasdavidmccormick
authored andcommitted
Adding the ability to add feature gates to controller components (#1545)
Ensure PodPriority is disabled if specified in the config
1 parent 68c79e2 commit 31612ee

File tree

6 files changed

+64
-12
lines changed

6 files changed

+64
-12
lines changed

core/controlplane/config/config.go

+14
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,20 @@ func (c *Cluster) Load() error {
357357
return nil
358358
}
359359

360+
func (c *Cluster) ControllerFeatureGates() model.FeatureGates {
361+
gates := c.Controller.NodeSettings.FeatureGates
362+
//From kube 1.11 PodPriority and ExpandPersistentVolumes have become enabled by default,
363+
//so making sure it is not enabled if user has explicitly set them to false
364+
//https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.11.md#changelog-since-v1110
365+
if !c.Experimental.Admission.Priority.Enabled {
366+
gates["PodPriority"] = "false"
367+
}
368+
if !c.Experimental.Admission.PersistentVolumeClaimResize.Enabled {
369+
gates["ExpandPersistentVolumes"] = "false"
370+
}
371+
return gates
372+
}
373+
360374
func (c *Cluster) ConsumeDeprecatedKeys() {
361375
// TODO Remove in v0.9.9-rc.1
362376
if c.DeprecatedVPCID != "" {

core/controlplane/config/config_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,28 @@ apiEndpoints:
235235
`,
236236
}
237237

238+
var featureGates = `
239+
controller:
240+
featureGates:
241+
feature1: "true"
242+
feature2: "false"
243+
`
244+
245+
func TestFeatureFlags(t *testing.T) {
246+
var c *Cluster
247+
var err error
248+
if c, err = ClusterFromBytes([]byte(singleAzConfigYaml + featureGates)); err != nil {
249+
t.Errorf("Incorrect config for controller feature gates: %s\n%s", err, featureGates)
250+
}
251+
if c.ControllerFeatureGates().Enabled() != true {
252+
t.Errorf("Incorrect config for controller feature gates: %s\n%s", err, featureGates)
253+
}
254+
if !(c.ControllerFeatureGates()["feature1"] == "true" &&
255+
c.ControllerFeatureGates()["feature2"] == "false") {
256+
t.Errorf("Incorrect config for controller feature gates: %s\n%s", err, featureGates)
257+
}
258+
}
259+
238260
func TestNetworkValidation(t *testing.T) {
239261
for _, networkConfig := range goodNetworkingConfigs {
240262
configBody := singleAzConfigYaml + networkConfig

core/controlplane/config/templates/cloud-config-controller

+11-8
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,8 @@ coreos:
442442
{{ else }}--cluster-dns={{.DNSServiceIP}} \
443443
{{ end }}--cluster-domain=cluster.local \
444444
--cloud-provider=aws \
445-
{{if or (.Experimental.Admission.Priority.Enabled) (.Experimental.Admission.PersistentVolumeClaimResize.Enabled) -}}
446-
--feature-gates=PodPriority={{.Experimental.Admission.Priority.Enabled}},ExpandPersistentVolumes={{.Experimental.Admission.PersistentVolumeClaimResize.Enabled}} \
445+
{{if .ControllerFeatureGates.Enabled -}}
446+
--feature-gates={{.ControllerFeatureGates.String}} \
447447
{{end -}}\
448448
{{- if .Kubelet.SystemReservedResources }}
449449
--system-reserved={{ .Kubelet.SystemReservedResources }} \
@@ -3485,9 +3485,9 @@ write_files:
34853485
- --client-ca-file=/etc/kubernetes/ssl/ca.pem
34863486
- --service-account-key-file=/etc/kubernetes/ssl/service-account-key.pem
34873487
- --runtime-config=extensions/v1beta1/networkpolicies=true{{if .Experimental.Admission.PodSecurityPolicy.Enabled}},extensions/v1beta1/podsecuritypolicy=true{{ end }}{{if .Experimental.Admission.Initializers.Enabled}},admissionregistration.k8s.io/v1alpha1{{end}}{{if .Experimental.Admission.Priority.Enabled}},scheduling.k8s.io/v1alpha1=true{{end}}
3488-
{{if or (.Experimental.Admission.Priority.Enabled) (.Experimental.Admission.PersistentVolumeClaimResize.Enabled)}}
3489-
- --feature-gates=PodPriority={{.Experimental.Admission.Priority.Enabled}},ExpandPersistentVolumes={{.Experimental.Admission.PersistentVolumeClaimResize.Enabled}}
3490-
{{end}}
3488+
{{- if .ControllerFeatureGates.Enabled }}
3489+
- --feature-gates={{.ControllerFeatureGates.String}}
3490+
{{- end }}
34913491
- --cloud-provider=aws
34923492
{{ if .Addons.APIServerAggregator.Enabled -}}
34933493
- --requestheader-client-ca-file=/etc/kubernetes/ssl/ca.pem
@@ -3637,6 +3637,9 @@ write_files:
36373637
{{ if not .Addons.MetricsServer.Enabled -}}
36383638
- --horizontal-pod-autoscaler-use-rest-clients=false
36393639
{{end}}
3640+
{{ if .ControllerFeatureGates.Enabled -}}
3641+
- --feature-gates={{.ControllerFeatureGates.String}}
3642+
{{ end -}}
36403643
resources:
36413644
requests:
36423645
cpu: {{ if .Kubernetes.ControllerManager.ComputeResources.Requests.Cpu }}{{ .Kubernetes.ControllerManager.ComputeResources.Requests.Cpu }}{{ else }}100m{{ end }}
@@ -3703,9 +3706,9 @@ write_files:
37033706
- scheduler
37043707
- --kubeconfig=/etc/kubernetes/kubeconfig/kube-scheduler.yaml
37053708
- --leader-elect=true
3706-
{{if or (.Experimental.Admission.Priority.Enabled) (.Experimental.Admission.PersistentVolumeClaimResize.Enabled)}}
3707-
- --feature-gates=PodPriority={{.Experimental.Admission.Priority.Enabled}},ExpandPersistentVolumes={{.Experimental.Admission.PersistentVolumeClaimResize.Enabled}}
3708-
{{end}}
3709+
{{- if .ControllerFeatureGates.Enabled }}
3710+
- --feature-gates={{.ControllerFeatureGates.String}}
3711+
{{- end }}
37093712
resources:
37103713
requests:
37113714
cpu: 100m

core/nodepool/config/config.go

+12
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ func (c ProvidedConfig) NodeLabels() model.NodeLabels {
285285

286286
func (c ProvidedConfig) FeatureGates() model.FeatureGates {
287287
gates := c.NodeSettings.FeatureGates
288+
if gates == nil {
289+
gates = model.FeatureGates{}
290+
}
288291
if c.Gpu.Nvidia.IsEnabledOn(c.InstanceType) {
289292
gates["Accelerators"] = "true"
290293
}
@@ -294,6 +297,15 @@ func (c ProvidedConfig) FeatureGates() model.FeatureGates {
294297
if c.Kubelet.RotateCerts.Enabled {
295298
gates["RotateKubeletClientCertificate"] = "true"
296299
}
300+
//From kube 1.11 PodPriority and ExpandPersistentVolumes have become enabled by default,
301+
//so making sure it is not enabled if user has explicitly set them to false
302+
//https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.11.md#changelog-since-v1110
303+
if !c.Experimental.Admission.Priority.Enabled {
304+
gates["PodPriority"] = "false"
305+
}
306+
if !c.Experimental.Admission.PersistentVolumeClaimResize.Enabled {
307+
gates["ExpandPersistentVolumes"] = "false"
308+
}
297309
return gates
298310
}
299311

test/integration/maincluster_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ experimental:
13171317
validatingAdmissionWebhook:
13181318
enabled: true
13191319
persistentVolumeClaimResize:
1320-
enabled: true
1320+
enabled: false
13211321
auditLog:
13221322
enabled: true
13231323
logPath: "/var/log/audit.log"
@@ -1402,7 +1402,7 @@ worker:
14021402
Enabled: true,
14031403
},
14041404
PersistentVolumeClaimResize: controlplane_config.PersistentVolumeClaimResize{
1405-
Enabled: true,
1405+
Enabled: false,
14061406
},
14071407
},
14081408
AuditLog: controlplane_config.AuditLog{
@@ -1496,7 +1496,7 @@ worker:
14961496
func(c root.Cluster, t *testing.T) {
14971497
cp := c.ControlPlane()
14981498
controllerUserdataS3Part := cp.UserDataController.Parts[model.USERDATA_S3].Asset.Content
1499-
if !strings.Contains(controllerUserdataS3Part, `--feature-gates=PodPriority=true`) {
1499+
if match, _ := regexp.MatchString(`--feature-gates=.*ExpandPersistentVolumes=false`, controllerUserdataS3Part); !match {
15001500
t.Error("missing controller feature gate: PodPriority=true")
15011501
}
15021502

test/integration/plugin_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package integration
33
import (
44
"os"
55
"reflect"
6+
"regexp"
67
"strings"
78
"testing"
89

@@ -458,7 +459,7 @@ spec:
458459
}
459460

460461
// A kube-aws plugin can activate feature gates
461-
if !strings.Contains(workerUserdataS3Part, `--feature-gates="Accelerators=true"`) {
462+
if match, _ := regexp.MatchString(`--feature-gates=.*Accelerators=true`, workerUserdataS3Part); !match {
462463
t.Error("missing worker feature gate: Accelerators=true")
463464
}
464465

0 commit comments

Comments
 (0)