Skip to content

Commit 0132544

Browse files
authored
Merge pull request #1623 from ArangoGutierrez/featuregate
Add FeatureGate framework to handle new features
2 parents fbc9a78 + 06c4733 commit 0132544

File tree

24 files changed

+902
-91
lines changed

24 files changed

+902
-91
lines changed

cmd/nfd-master/main.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ import (
2323
"time"
2424

2525
"k8s.io/klog/v2"
26-
klogutils "sigs.k8s.io/node-feature-discovery/pkg/utils/klog"
2726

27+
"sigs.k8s.io/node-feature-discovery/pkg/features"
2828
master "sigs.k8s.io/node-feature-discovery/pkg/nfd-master"
2929
"sigs.k8s.io/node-feature-discovery/pkg/utils"
30+
klogutils "sigs.k8s.io/node-feature-discovery/pkg/utils/klog"
3031
"sigs.k8s.io/node-feature-discovery/pkg/version"
3132
)
3233

@@ -42,6 +43,12 @@ func main() {
4243
printVersion := flags.Bool("version", false, "Print version and exit.")
4344

4445
args, overrides := initFlags(flags)
46+
// Add FeatureGates flag
47+
if err := features.NFDMutableFeatureGate.Add(features.DefaultNFDFeatureGates); err != nil {
48+
klog.ErrorS(err, "failed to add default feature gates")
49+
os.Exit(1)
50+
}
51+
features.NFDMutableFeatureGate.AddFlag(flags)
4552

4653
_ = flags.Parse(os.Args[1:])
4754
if len(flags.Args()) > 0 {
@@ -74,8 +81,6 @@ func main() {
7481
args.Overrides.ResyncPeriod = overrides.ResyncPeriod
7582
case "nfd-api-parallelism":
7683
args.Overrides.NfdApiParallelism = overrides.NfdApiParallelism
77-
case "enable-nodefeature-api":
78-
klog.InfoS("-enable-nodefeature-api is deprecated, will be removed in a future release along with the deprecated gRPC API")
7984
case "ca-file":
8085
klog.InfoS("-ca-file is deprecated, will be removed in a future release along with the deprecated gRPC API")
8186
case "cert-file":
@@ -134,9 +139,6 @@ func initFlags(flagset *flag.FlagSet) (*master.Args, *master.ConfigOverrideArgs)
134139
"Config file to use.")
135140
flagset.StringVar(&args.Kubeconfig, "kubeconfig", "",
136141
"Kubeconfig to use")
137-
flagset.BoolVar(&args.EnableNodeFeatureApi, "enable-nodefeature-api", true,
138-
"Enable the NodeFeature CRD API for receiving node features. This will automatically disable the gRPC communication."+
139-
" DEPRECATED: will be removed in a future release along with the deprecated gRPC API.")
140142
flagset.BoolVar(&args.CrdController, "featurerules-controller", true,
141143
"Enable NFD CRD API controller. DEPRECATED: use -crd-controller instead")
142144
flagset.BoolVar(&args.CrdController, "crd-controller", true,

cmd/nfd-worker/main.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import (
2222
"os"
2323

2424
"k8s.io/klog/v2"
25-
klogutils "sigs.k8s.io/node-feature-discovery/pkg/utils/klog"
2625

26+
"sigs.k8s.io/node-feature-discovery/pkg/features"
2727
worker "sigs.k8s.io/node-feature-discovery/pkg/nfd-worker"
2828
"sigs.k8s.io/node-feature-discovery/pkg/utils"
29+
klogutils "sigs.k8s.io/node-feature-discovery/pkg/utils/klog"
2930
"sigs.k8s.io/node-feature-discovery/pkg/version"
3031
)
3132

@@ -39,6 +40,13 @@ func main() {
3940

4041
printVersion := flags.Bool("version", false, "Print version and exit.")
4142

43+
// Add FeatureGates flag
44+
if err := features.NFDMutableFeatureGate.Add(features.DefaultNFDFeatureGates); err != nil {
45+
klog.ErrorS(err, "failed to add default feature gates")
46+
os.Exit(1)
47+
}
48+
features.NFDMutableFeatureGate.AddFlag(flags)
49+
4250
args := parseArgs(flags, os.Args[1:]...)
4351

4452
if *printVersion {
@@ -124,9 +132,6 @@ func initFlags(flagset *flag.FlagSet) (*worker.Args, *worker.ConfigOverrideArgs)
124132
flagset.StringVar(&args.KeyFile, "key-file", "",
125133
"Private key matching -cert-file."+
126134
" DEPRECATED: will be removed in a future release along with the deprecated gRPC API.")
127-
flagset.BoolVar(&args.EnableNodeFeatureApi, "enable-nodefeature-api", true,
128-
"Enable the NodeFeature CRD API for communicating with nfd-master. This will automatically disable the gRPC communication."+
129-
" DEPRECATED: will be removed in a future release along with the deprecated gRPC API.")
130135
flagset.StringVar(&args.Kubeconfig, "kubeconfig", "",
131136
"Kubeconfig to use")
132137
flagset.BoolVar(&args.Oneshot, "oneshot", false,

deployment/helm/node-feature-discovery/templates/clusterrole.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ rules:
8080
- update
8181
{{- end }}
8282

83-
{{- if and .Values.gc.enable .Values.gc.rbac.create (or .Values.enableNodeFeatureApi .Values.topologyUpdater.enable) }}
83+
{{- if and .Values.gc.enable .Values.gc.rbac.create (or .Values.featureGates.NodeFeatureAPI .Values.topologyUpdater.enable) }}
8484
---
8585
apiVersion: rbac.authorization.k8s.io/v1
8686
kind: ClusterRole

deployment/helm/node-feature-discovery/templates/clusterrolebinding.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ subjects:
3333
namespace: {{ include "node-feature-discovery.namespace" . }}
3434
{{- end }}
3535

36-
{{- if and .Values.gc.enable .Values.gc.rbac.create (or .Values.enableNodeFeatureApi .Values.topologyUpdater.enable) }}
36+
{{- if and .Values.gc.enable .Values.gc.rbac.create (or .Values.featureGates.NodeFeatureAPI .Values.topologyUpdater.enable) }}
3737
---
3838
apiVersion: rbac.authorization.k8s.io/v1
3939
kind: ClusterRoleBinding

deployment/helm/node-feature-discovery/templates/master.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ spec:
7373
{{- if .Values.master.instance | empty | not }}
7474
- "-instance={{ .Values.master.instance }}"
7575
{{- end }}
76-
{{- if not .Values.enableNodeFeatureApi }}
76+
{{- if not .Values.featureGates.NodeFeatureAPI }}
7777
- "-port={{ .Values.master.port | default "8080" }}"
78-
- "-enable-nodefeature-api=false"
7978
{{- else if gt (int .Values.master.replicaCount) 1 }}
8079
- "-enable-leader-election"
8180
{{- end }}
@@ -111,6 +110,10 @@ spec:
111110
- "-key-file=/etc/kubernetes/node-feature-discovery/certs/tls.key"
112111
- "-cert-file=/etc/kubernetes/node-feature-discovery/certs/tls.crt"
113112
{{- end }}
113+
# Go over featureGates and add the feature-gate flag
114+
{{- range $key, $value := .Values.featureGates }}
115+
- "-feature-gates={{ $key }}={{ $value }}"
116+
{{- end }}
114117
- "-metrics={{ .Values.master.metricsPort | default "8081" }}"
115118
volumeMounts:
116119
{{- if .Values.tls.enable }}

deployment/helm/node-feature-discovery/templates/nfd-gc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and .Values.gc.enable (or .Values.enableNodeFeatureApi .Values.topologyUpdater.enable) -}}
1+
{{- if and .Values.gc.enable (or .Values.featureGates.NodeFeatureAPI .Values.topologyUpdater.enable) -}}
22
apiVersion: apps/v1
33
kind: Deployment
44
metadata:

deployment/helm/node-feature-discovery/templates/service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and (not .Values.enableNodeFeatureApi) .Values.master.enable }}
1+
{{- if and (not .Values.featureGates.NodeFeatureAPI) .Values.master.enable }}
22
apiVersion: v1
33
kind: Service
44
metadata:

deployment/helm/node-feature-discovery/templates/serviceaccount.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ metadata:
2727
{{- end }}
2828
{{- end }}
2929

30-
{{- if and .Values.gc.enable .Values.gc.serviceAccount.create (or .Values.enableNodeFeatureApi .Values.topologyUpdater.enable) }}
30+
{{- if and .Values.gc.enable .Values.gc.serviceAccount.create (or .Values.featureGates.NodeFeatureAPI .Values.topologyUpdater.enable) }}
3131
---
3232
apiVersion: v1
3333
kind: ServiceAccount

deployment/helm/node-feature-discovery/templates/worker.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,17 @@ spec:
6161
command:
6262
- "nfd-worker"
6363
args:
64-
{{- if not .Values.enableNodeFeatureApi }}
64+
{{- if not .Values.featureGates.NodeFeatureAPI }}
6565
- "-server={{ include "node-feature-discovery.fullname" . }}-master:{{ .Values.master.service.port }}"
66-
- "-enable-nodefeature-api=false"
67-
{{- end }}
66+
{{- end }}
6867
{{- if .Values.tls.enable }}
6968
- "-ca-file=/etc/kubernetes/node-feature-discovery/certs/ca.crt"
7069
- "-key-file=/etc/kubernetes/node-feature-discovery/certs/tls.key"
7170
- "-cert-file=/etc/kubernetes/node-feature-discovery/certs/tls.crt"
71+
{{- end }}
72+
# Go over featureGate and add the feature-gate flag
73+
{{- range $key, $value := .Values.featureGates }}
74+
- "-feature-gates={{ $key }}={{ $value }}"
7275
{{- end }}
7376
- "-metrics={{ .Values.worker.metricsPort | default "8081"}}"
7477
ports:

deployment/helm/node-feature-discovery/values.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ nameOverride: ""
1010
fullnameOverride: ""
1111
namespaceOverride: ""
1212

13-
enableNodeFeatureApi: true
13+
featureGates:
14+
NodeFeatureAPI: true
1415

1516
priorityClassName: ""
1617

0 commit comments

Comments
 (0)