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

Commit 73136f9

Browse files
omar-nahhasdavidmccormick
authored andcommitted
Adding the ability to add feature gates to controller components (#1544)
Ensure PodPriority is not enabled unless explicitly enabled on cluster.yaml
1 parent 625c8d4 commit 73136f9

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
@@ -354,6 +354,20 @@ func (c *Cluster) Load() error {
354354
return nil
355355
}
356356

357+
func (c *Cluster) ControllerFeatureGates() model.FeatureGates {
358+
gates := c.Controller.NodeSettings.FeatureGates
359+
//From kube 1.11 PodPriority and ExpandPersistentVolumes have become enabled by default,
360+
//so making sure it is not enabled if user has explicitly set them to false
361+
//https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.11.md#changelog-since-v1110
362+
if !c.Experimental.Admission.Priority.Enabled {
363+
gates["PodPriority"] = "false"
364+
}
365+
if !c.Experimental.Admission.PersistentVolumeClaimResize.Enabled {
366+
gates["ExpandPersistentVolumes"] = "false"
367+
}
368+
return gates
369+
}
370+
357371
func (c *Cluster) ConsumeDeprecatedKeys() {
358372
// TODO Remove in v0.9.9-rc.1
359373
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
@@ -335,8 +335,8 @@ coreos:
335335
{{ else }}--cluster-dns={{.DNSServiceIP}} \
336336
{{ end }}--cluster-domain=cluster.local \
337337
--cloud-provider=aws \
338-
{{if or (.Experimental.Admission.Priority.Enabled) (.Experimental.Admission.PersistentVolumeClaimResize.Enabled) -}}
339-
--feature-gates=PodPriority={{.Experimental.Admission.Priority.Enabled}},ExpandPersistentVolumes={{.Experimental.Admission.PersistentVolumeClaimResize.Enabled}} \
338+
{{if .ControllerFeatureGates.Enabled -}}
339+
--feature-gates={{.ControllerFeatureGates.String}} \
340340
{{end -}}\
341341
{{- if .Kubelet.SystemReservedResources }}
342342
--system-reserved={{ .Kubelet.SystemReservedResources }} \
@@ -3040,9 +3040,9 @@ write_files:
30403040
- --client-ca-file=/etc/kubernetes/ssl/ca.pem
30413041
- --service-account-key-file=/etc/kubernetes/ssl/service-account-key.pem
30423042
- --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}}
3043-
{{if or (.Experimental.Admission.Priority.Enabled) (.Experimental.Admission.PersistentVolumeClaimResize.Enabled)}}
3044-
- --feature-gates=PodPriority={{.Experimental.Admission.Priority.Enabled}},ExpandPersistentVolumes={{.Experimental.Admission.PersistentVolumeClaimResize.Enabled}}
3045-
{{end}}
3043+
{{- if .ControllerFeatureGates.Enabled }}
3044+
- --feature-gates={{.ControllerFeatureGates.String}}
3045+
{{- end }}
30463046
- --cloud-provider=aws
30473047
{{ if .Addons.APIServerAggregator.Enabled -}}
30483048
- --requestheader-client-ca-file=/etc/kubernetes/ssl/ca.pem
@@ -3195,6 +3195,9 @@ write_files:
31953195
{{range $f := .ControllerFlags -}}
31963196
- --{{$f.Name}}={{$f.Value}}
31973197
{{ end -}}
3198+
{{ if .ControllerFeatureGates.Enabled -}}
3199+
- --feature-gates={{.ControllerFeatureGates.String}}
3200+
{{ end -}}
31983201
resources:
31993202
requests:
32003203
cpu: {{ if .Kubernetes.ControllerManager.ComputeResources.Requests.Cpu }}{{ .Kubernetes.ControllerManager.ComputeResources.Requests.Cpu }}{{ else }}100m{{ end }}
@@ -3260,9 +3263,9 @@ write_files:
32603263
- scheduler
32613264
- --kubeconfig=/etc/kubernetes/kubeconfig/kube-scheduler.yaml
32623265
- --leader-elect=true
3263-
{{if or (.Experimental.Admission.Priority.Enabled) (.Experimental.Admission.PersistentVolumeClaimResize.Enabled)}}
3264-
- --feature-gates=PodPriority={{.Experimental.Admission.Priority.Enabled}},ExpandPersistentVolumes={{.Experimental.Admission.PersistentVolumeClaimResize.Enabled}}
3265-
{{end}}
3266+
{{- if .ControllerFeatureGates.Enabled }}
3267+
- --feature-gates={{.ControllerFeatureGates.String}}
3268+
{{- end }}
32663269
resources:
32673270
requests:
32683271
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)