Skip to content

Commit 0a21feb

Browse files
authored
Merge pull request #327842 from cafkafk/kubernetes-feature-gate-refactor
nixos/kubernetes: refactor feature gates to attrsOf bool, making it possible to disable featureGates
2 parents ad192af + 32ca66f commit 0a21feb

File tree

8 files changed

+43
-21
lines changed

8 files changed

+43
-21
lines changed

nixos/doc/manual/release-notes/rl-2411.section.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,24 @@
147147
nvimpager settings: user commands in `-c` and `--cmd` now override the
148148
respective default settings because they are executed later.
149149

150+
- Kubernetes `featureGates` have changed from a `listOf str` to `attrsOf bool`.
151+
This refactor makes it possible to also disable feature gates, without having
152+
to use `extraOpts` flags.
153+
154+
A previous configuration may have looked like this:
155+
```nix
156+
featureGates = [ "EphemeralContainers" ];
157+
extraOpts = pkgs.lib.concatStringsSep " " (
158+
[
159+
''--feature-gates="CSIMigration=false"''
160+
});
161+
```
162+
163+
Using an AttrSet instead, the new configuration would be:
164+
```nix
165+
featureGates = {EphemeralContainers = true; CSIMigration=false;};
166+
```
167+
150168
- `pkgs.nextcloud27` has been removed since it's EOL.
151169

152170
- `services.forgejo.mailerPasswordFile` has been deprecated by the drop-in replacement `services.forgejo.secrets.mailer.PASSWD`,

nixos/modules/services/cluster/kubernetes/apiserver.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ in
159159
};
160160

161161
featureGates = mkOption {
162-
description = "List set of feature gates";
162+
description = "Attribute set of feature gates.";
163163
default = top.featureGates;
164164
defaultText = literalExpression "config.${otop.featureGates}";
165-
type = listOf str;
165+
type = attrsOf bool;
166166
};
167167

168168
kubeletClientCaFile = mkOption {
@@ -349,8 +349,8 @@ in
349349
"--etcd-certfile=${cfg.etcd.certFile}"} \
350350
${optionalString (cfg.etcd.keyFile != null)
351351
"--etcd-keyfile=${cfg.etcd.keyFile}"} \
352-
${optionalString (cfg.featureGates != [])
353-
"--feature-gates=${concatMapStringsSep "," (feature: "${feature}=true") cfg.featureGates}"} \
352+
${optionalString (cfg.featureGates != {})
353+
"--feature-gates=${(concatStringsSep "," (builtins.attrValues (mapAttrs (n: v: "${n}=${trivial.boolToString v}") cfg.featureGates)))}"} \
354354
${optionalString (cfg.basicAuthFile != null)
355355
"--basic-auth-file=${cfg.basicAuthFile}"} \
356356
${optionalString (cfg.kubeletClientCaFile != null)

nixos/modules/services/cluster/kubernetes/controller-manager.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ in
4444
};
4545

4646
featureGates = mkOption {
47-
description = "List set of feature gates";
47+
description = "Attribute set of feature gates.";
4848
default = top.featureGates;
4949
defaultText = literalExpression "config.${otop.featureGates}";
50-
type = listOf str;
50+
type = attrsOf bool;
5151
};
5252

5353
kubeconfig = top.lib.mkKubeConfigOptions "Kubernetes controller manager";
@@ -121,8 +121,8 @@ in
121121
--bind-address=${cfg.bindAddress} \
122122
${optionalString (cfg.clusterCidr!=null)
123123
"--cluster-cidr=${cfg.clusterCidr}"} \
124-
${optionalString (cfg.featureGates != [])
125-
"--feature-gates=${concatMapStringsSep "," (feature: "${feature}=true") cfg.featureGates}"} \
124+
${optionalString (cfg.featureGates != {})
125+
"--feature-gates=${concatStringsSep "," (builtins.attrValues (mapAttrs (n: v: "${n}=${trivial.boolToString v}") cfg.featureGates))}"} \
126126
--kubeconfig=${top.lib.mkKubeConfig "kube-controller-manager" cfg.kubeconfig} \
127127
--leader-elect=${boolToString cfg.leaderElect} \
128128
${optionalString (cfg.rootCaFile!=null)

nixos/modules/services/cluster/kubernetes/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ in {
155155

156156
featureGates = mkOption {
157157
description = "List set of feature gates.";
158-
default = [];
159-
type = types.listOf types.str;
158+
default = {};
159+
type = types.attrsOf types.bool;
160160
};
161161

162162
masterAddress = mkOption {

nixos/modules/services/cluster/kubernetes/kubelet.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ let
6565
// lib.optionalAttrs (cfg.tlsKeyFile != null) { tlsPrivateKeyFile = cfg.tlsKeyFile; }
6666
// lib.optionalAttrs (cfg.clusterDomain != "") { clusterDomain = cfg.clusterDomain; }
6767
// lib.optionalAttrs (cfg.clusterDns != "") { clusterDNS = [ cfg.clusterDns ] ; }
68-
// lib.optionalAttrs (cfg.featureGates != []) { featureGates = cfg.featureGates; }
68+
// lib.optionalAttrs (cfg.featureGates != {}) { featureGates = cfg.featureGates; }
6969
));
7070

7171
manifestPath = "kubernetes/manifests";
@@ -185,10 +185,10 @@ in
185185
};
186186

187187
featureGates = mkOption {
188-
description = "List set of feature gates";
188+
description = "Attribute set of feature gate";
189189
default = top.featureGates;
190190
defaultText = literalExpression "config.${otop.featureGates}";
191-
type = listOf str;
191+
type = attrsOf bool;
192192
};
193193

194194
healthz = {

nixos/modules/services/cluster/kubernetes/proxy.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ in
3030
};
3131

3232
featureGates = mkOption {
33-
description = "List set of feature gates";
33+
description = "Attribute set of feature gates.";
3434
default = top.featureGates;
3535
defaultText = literalExpression "config.${otop.featureGates}";
36-
type = listOf str;
36+
type = attrsOf bool;
3737
};
3838

3939
hostname = mkOption {
@@ -69,8 +69,8 @@ in
6969
--bind-address=${cfg.bindAddress} \
7070
${optionalString (top.clusterCidr!=null)
7171
"--cluster-cidr=${top.clusterCidr}"} \
72-
${optionalString (cfg.featureGates != [])
73-
"--feature-gates=${concatMapStringsSep "," (feature: "${feature}=true") cfg.featureGates}"} \
72+
${optionalString (cfg.featureGates != {})
73+
"--feature-gates=${concatStringsSep "," (builtins.attrValues (mapAttrs (n: v: "${n}=${trivial.boolToString v}") cfg.featureGates))}"} \
7474
--hostname-override=${cfg.hostname} \
7575
--kubeconfig=${top.lib.mkKubeConfig "kube-proxy" cfg.kubeconfig} \
7676
${optionalString (cfg.verbosity != null) "--v=${toString cfg.verbosity}"} \

nixos/modules/services/cluster/kubernetes/scheduler.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ in
2626
};
2727

2828
featureGates = mkOption {
29-
description = "List set of feature gates";
29+
description = "Attribute set of feature gates.";
3030
default = top.featureGates;
3131
defaultText = literalExpression "config.${otop.featureGates}";
32-
type = listOf str;
32+
type = attrsOf bool;
3333
};
3434

3535
kubeconfig = top.lib.mkKubeConfigOptions "Kubernetes scheduler";
@@ -67,8 +67,8 @@ in
6767
Slice = "kubernetes.slice";
6868
ExecStart = ''${top.package}/bin/kube-scheduler \
6969
--bind-address=${cfg.address} \
70-
${optionalString (cfg.featureGates != [])
71-
"--feature-gates=${concatMapStringsSep "," (feature: "${feature}=true") cfg.featureGates}"} \
70+
${optionalString (cfg.featureGates != {})
71+
"--feature-gates=${concatStringsSep "," (builtins.attrValues (mapAttrs (n: v: "${n}=${trivial.boolToString v}") cfg.featureGates))}"} \
7272
--kubeconfig=${top.lib.mkKubeConfig "kube-scheduler" cfg.kubeconfig} \
7373
--leader-elect=${boolToString cfg.leaderElect} \
7474
--secure-port=${toString cfg.port} \

nixos/tests/kubernetes/base.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ let
5959
securePort = 443;
6060
advertiseAddress = master.ip;
6161
};
62+
# NOTE: what featureGates are useful for testing might change in
63+
# the future, see link below to find new ones
64+
# https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/
65+
featureGates = {CPUManager = true; AppArmor= false;};
6266
masterAddress = "${masterName}.${config.networking.domain}";
6367
};
6468
}

0 commit comments

Comments
 (0)