Skip to content

Commit

Permalink
Add --no-taint flag opt out/in from tainting feature of NFD
Browse files Browse the repository at this point in the history
This commit adds a flag to allow users opt in/out from node
tainting feature. The flag take precedence over taints defined
in NodeFeatureRule CR. In other words, if no-taint is set to true
(disabled) and user still defines taints on the CR, NFD will ignore
those taints and skip them from setting on the node.

Signed-off-by: Feruzjon Muyassarov <[email protected]>
  • Loading branch information
fmuyassarov committed Oct 6, 2022
1 parent 2a7978e commit 20e44ec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions cmd/nfd-master/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func initFlags(flagset *flag.FlagSet) *master.Args {
"NB: the label namespace is omitted i.e. the filter is only applied to the name part after '/'.")
flagset.BoolVar(&args.NoPublish, "no-publish", false,
"Do not publish feature labels")
flagset.BoolVar(&args.NoTaint, "no-taint", true,
"Do not set node taint defined on the NodeFeatureRule CR")
flagset.BoolVar(&args.FeatureRulesController, "featurerules-controller", true,
"Enable controller for NodeFeatureRule objects. Generates node labels based on the rules in these CRs.")
flagset.IntVar(&args.Port, "port", 8080,
Expand Down
10 changes: 6 additions & 4 deletions docs/advanced/customization-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ labeling:
## NodeFeatureRule custom resource

`NodeFeatureRule` objects provide an easy way to create vendor or application
specific labels and taints (disabled by default). It uses a flexible rule-based
mechanism for creating labels/taints based on node feature.
specific labels and taints. It uses a flexible rule-based mechanism for creating
labels/taints based on node features. Tainting feature is disabled by default and
to enable it set `--no-taint` flag to `false`. If the feature gate `--no-taint`
is `true` (i.e. disabled), taints defined in the NodeFeatureRule CRD have no effect
and will be ignored by the NFD controller.

### A NodeFeatureRule example

Expand All @@ -47,7 +50,7 @@ spec:
- name: "my sample rule"
labels:
"my-sample-feature": "true"
# Using tainting feature requires the feature gate (--allowTainting) to be enabled
# Using tainting feature requires the feature gate (--no-taint) to be enabled (set to false)
taints:
- effect: PreferNoSchedule
key: bar
Expand Down Expand Up @@ -1044,4 +1047,3 @@ __In the example above:__
matches the `node-datacenter1-rack.*-server.*` pattern, e.g.
`node-datacenter1-rack2-server42`


14 changes: 8 additions & 6 deletions pkg/nfd-master/nfd-master.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type Args struct {
LabelWhiteList utils.RegexpVal
FeatureRulesController bool
NoPublish bool
NoTaint bool
Port int
Prune bool
VerifyNodeName bool
Expand Down Expand Up @@ -445,14 +446,15 @@ func (m *nfdMaster) SetLabels(c context.Context, r *pb.SetLabelsRequest) (*pb.Se
klog.Errorf("failed to advertise labels: %v", err)
return &pb.SetLabelsReply{}, err
}
// Set NodeFeatureRule provided taints
if mustTaint {
labelReply, err := m.SetTaints(c, r)
if err != nil {
return labelReply, err
if !m.args.NoTaint {
// Set NodeFeatureRule provided taints
if mustTaint {
labelReply, err := m.SetTaints(c, r)
if err != nil {
return labelReply, err
}
}
}

}
return &pb.SetLabelsReply{}, nil
}
Expand Down

0 comments on commit 20e44ec

Please sign in to comment.