Skip to content

Commit 28b40c9

Browse files
TessaIOAhmedThresh
authored andcommitted
deploy: add CR restrictions to the helm config
Signed-off-by: AhmedGrati <[email protected]> Signed-off-by: AhmedThresh <[email protected]> Signed-off-by: AhmedGrati <[email protected]> Signed-off-by: AhmedThresh <[email protected]> Signed-off-by: AhmedGrati <[email protected]> Signed-off-by: AhmedThresh <[email protected]>
1 parent 925a071 commit 28b40c9

File tree

16 files changed

+582
-467
lines changed

16 files changed

+582
-467
lines changed

deployment/base/rbac/master-clusterrole.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ kind: ClusterRole
33
metadata:
44
name: nfd-master
55
rules:
6+
- apiGroups:
7+
- ""
8+
resources:
9+
- namespaces
10+
verbs:
11+
- watch
12+
- list
613
- apiGroups:
714
- ""
815
resources:

deployment/components/master-config/nfd-master.conf.example

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66
# enableTaints: false
77
# labelWhiteList: "foo"
88
# resyncPeriod: "2h"
9+
# restrictions:
10+
# disableLabels: true
11+
# disableTaints: true
12+
# disableExtendedResources: true
13+
# disableAnnotations: true
14+
# allowOverwrite: false
15+
# denyNodeFeatureLabels: true
16+
# nodeFeatureNamespaceSelector:
17+
# matchLabels:
18+
# kubernetes.io/metadata.name: "node-feature-discovery"
19+
# matchExpressions:
20+
# - key: "kubernetes.io/metadata.name"
21+
# operator: "In"
22+
# values:
23+
# - "node-feature-discovery"
924
# klog:
1025
# addDirHeader: false
1126
# alsologtostderr: false

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ metadata:
66
labels:
77
{{- include "node-feature-discovery.labels" . | nindent 4 }}
88
rules:
9+
- apiGroups:
10+
- ""
11+
resources:
12+
- namespaces
13+
verbs:
14+
- watch
15+
- list
916
- apiGroups:
1017
- ""
1118
resources:

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ master:
2828
# enableTaints: false
2929
# labelWhiteList: "foo"
3030
# resyncPeriod: "2h"
31+
# restrictions:
32+
# disableLabels: true
33+
# disableTaints: true
34+
# disableExtendedResources: true
35+
# disableAnnotations: true
36+
# allowOverwrite: false
37+
# denyNodeFeatureLabels: true
38+
# nodeFeatureNamespaceSelector:
39+
# matchLabels:
40+
# kubernetes.io/metadata.name: "node-feature-discovery"
41+
# matchExpressions:
42+
# - key: "kubernetes.io/metadata.name"
43+
# operator: "In"
44+
# values:
45+
# - "node-feature-discovery"
3146
# klog:
3247
# addDirHeader: false
3348
# alsologtostderr: false

docs/reference/master-configuration-reference.md

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -339,25 +339,24 @@ Default: *empty*
339339

340340
Run-time configurable: yes
341341

342+
## restrictions (EXPERIMENTAL)
342343

343-
## restrictions
344+
The following options specify the restrictions that can be applied by the
345+
nfd-master on the deployed Custom Resources in the cluster.
344346

345-
The following options specify the restrictions that can be applied by nfd-master
346-
on the deployed Custom Resources in the cluster.
347+
### restrictions.nodeFeatureNamespaceSelector
347348

348-
### restrictions.allowedNamespaces
349+
The `nodeFeatureNamespaceSelector` option specifies the NodeFeatures namespaces
350+
to watch, which can be selected by using `metav1.LabelSelector` as a type for
351+
this option. An empty value selects all namespaces to be watched.
349352

350-
The `allowedNamespaces` option specifies the NodeFeatures namespaces to watch.
351-
To select the appropriate namespaces to watch, you can use the `metav1.LabelSelector`
352-
as a type for this option.
353-
354-
Default: all namespaces are allowed to be watched.
353+
Default: *empty*
355354

356355
Example:
357356

358357
```yaml
359358
restrictions:
360-
allowedNamespaces:
359+
nodeFeatureNamespaceSelector:
361360
matchLabels:
362361
kubernetes.io/metadata.name: "node-feature-discovery"
363362
matchExpressions:
@@ -367,80 +366,70 @@ restrictions:
367366
- "node-feature-discovery"
368367
```
369368

370-
### restrictions.maxLabelsPerCR
371-
372-
The `maxLabelsPerCR` option specifies the maximum number of labels that can
373-
be generated by a single CustomResource.
374-
375-
Default: no limit
376-
377-
Example:
378-
379-
```yaml
380-
restrictions:
381-
maxLabelsPerCR: 20
382-
```
383-
384-
### restrictions.maxTaintsPerCR
369+
### restrictions.disableLabels
385370

386-
The `maxTaintsPerCR` option specifies the maximum number of taints that can
387-
be generated by a single CustomResource.
371+
The `disableLabels` option controls whether to allow creation of node labels
372+
from NodeFeature and NodeFeatureRule CRs or not.
388373

389-
Default: no limit
374+
Default: false
390375

391376
Example:
392377

393378
```yaml
394379
restrictions:
395-
maxTaintsPerCR: 10
380+
disableLabels: true
396381
```
397382

398-
### restrictions.maxExtendedResourcesPerCR
383+
### restrictions.disableExtendedResources
399384

400-
The `maxExtendedResourcesPerCR` option specifies the maximum number of extended
401-
resources that can be generated by a single CustomResource.
385+
The `disableExtendedResources` option controls whether to allow creation of
386+
node extended resources from NodeFeatureRule CR or not.
402387

403-
Default: no limit
388+
Default: false
404389

405390
Example:
406391

407392
```yaml
408393
restrictions:
409-
maxExtendedResourcesPerCR: 15
394+
disableExtendedResources: true
410395
```
411396

412-
### restrictions.maxExtendedResourcesPerCR
397+
### restrictions.disableAnnotations
413398

414-
The `maxExtendedResourcesPerCR` option specifies the maximum number of extended
415-
resources that can be generated by a single CustomResource.
399+
he `disableAnnotations` option controls whether to allow creation of node annotations
400+
from NodeFeatureRule CR or not.
416401

417-
Default: no limit
402+
Default: false
418403

419404
Example:
420405

421406
```yaml
422407
restrictions:
423-
maxExtendedResourcesPerCR: 15
408+
disableAnnotations: true
424409
```
425410

426-
### restrictions.overwriteLabels
411+
### restrictions.allowOverwrite
427412

428-
The `overwriteLabels` option specifies whether to overwrite existing
429-
labels, if there's an overlap, or not.
413+
The `allowOverwrite` option controls whether NFD is allowed to overwrite and
414+
take over management of existing node labels, annotations, and extended resources.
415+
Labels, annotations and extended resources created by NFD itself are not affected
416+
(overwrite cannot be disabled). NFD tracks the labels, annotations and extended
417+
resources that it manages with specific
418+
[node annotations](../get-started/introduction.md#node-annotations).
430419

431420
Default: true
432421

433422
Example:
434423

435424
```yaml
436425
restrictions:
437-
overwriteLabels: false
426+
allowOverwrite: false
438427
```
439428

440429
### restrictions.denyNodeFeatureLabels
441430

442-
The `denyNodeFeatureLabels` option specifies whether to deny labels from NodeFeature
443-
objects or not.
431+
The `denyNodeFeatureLabels` option specifies whether to deny labels from 3rd party
432+
NodeFeature objects or not. NodeFeature objects created by nfd-worker are not affected.
444433

445434
Default: false
446435

examples/nodefeature.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apiVersion: nfd.k8s-sigs.io/v1alpha1
44
kind: NodeFeature
55
metadata:
66
labels:
7-
nfd.node.kubernetes.io/node-name: nfd-control-plane
7+
nfd.node.kubernetes.io/node-name: example-node
88
name: example-node
99
namespace: node-feature-discovery
1010
spec:

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module sigs.k8s.io/node-feature-discovery
22

33
go 1.22.2
44

5-
toolchain go1.22.0
6-
75
require (
86
github.com/fsnotify/fsnotify v1.7.0
97
github.com/golang/protobuf v1.5.4

nfd-master.conf

Lines changed: 0 additions & 35 deletions
This file was deleted.

pkg/nfd-master/namespace-lister.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package nfdmaster
17+
18+
import (
19+
"time"
20+
21+
corev1 "k8s.io/api/core/v1"
22+
"k8s.io/apimachinery/pkg/labels"
23+
"k8s.io/client-go/informers"
24+
k8sclient "k8s.io/client-go/kubernetes"
25+
v1lister "k8s.io/client-go/listers/core/v1"
26+
)
27+
28+
// NamespaceLister lists kubernetes namespaces.
29+
type NamespaceLister struct {
30+
namespaceLister v1lister.NamespaceLister
31+
labelsSelector labels.Selector
32+
stopChan chan struct{}
33+
}
34+
35+
func newNamespaceLister(k8sClient k8sclient.Interface, labelsSelector labels.Selector) *NamespaceLister {
36+
factory := informers.NewSharedInformerFactory(k8sClient, time.Hour)
37+
namespaceLister := factory.Core().V1().Namespaces().Lister()
38+
39+
stopChan := make(chan struct{})
40+
factory.Start(stopChan) // runs in background
41+
factory.WaitForCacheSync(stopChan)
42+
43+
return &NamespaceLister{
44+
namespaceLister: namespaceLister,
45+
labelsSelector: labelsSelector,
46+
stopChan: stopChan,
47+
}
48+
}
49+
50+
// list returns all kubernetes namespaces.
51+
func (lister *NamespaceLister) list() ([]*corev1.Namespace, error) {
52+
return lister.namespaceLister.List(lister.labelsSelector)
53+
}
54+
55+
// stop closes the channel used by the lister
56+
func (lister *NamespaceLister) stop() {
57+
close(lister.stopChan)
58+
}

0 commit comments

Comments
 (0)