Skip to content

Commit

Permalink
Add NodeFeatureGroup API
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
  • Loading branch information
ArangoGutierrez committed Dec 4, 2023
1 parent bdfef6d commit 5f43f6c
Show file tree
Hide file tree
Showing 45 changed files with 2,765 additions and 104 deletions.
2 changes: 2 additions & 0 deletions cmd/nfd-master/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ func initFlags(flagset *flag.FlagSet) (*master.Args, *master.ConfigOverrideArgs)
flagset.BoolVar(&args.EnableNodeFeatureApi, "enable-nodefeature-api", true,
"Enable the NodeFeature CRD API for receiving node features. This will automatically disable the gRPC communication."+
" DEPRECATED: will be removed in a future release along with the deprecated gRPC API.")
flagset.BoolVar(&args.EnableNodeFeatureGroupApi, "enable-nodefeaturegroup-api", false,
"Enable the NodeFeatureGroup CRD API for receiving cluster feature rules.")
flagset.BoolVar(&args.CrdController, "featurerules-controller", true,
"Enable NFD CRD API controller. DEPRECATED: use -crd-controller instead")
flagset.BoolVar(&args.CrdController, "crd-controller", true,
Expand Down
321 changes: 321 additions & 0 deletions deployment/base/nfd-crds/nfd-api-crds.yaml

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions deployment/base/rbac/master-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ rules:
- get
- list
- watch
- apiGroups:
- nfd.k8s-sigs.io
resources:
- nodefeaturegroups
- nodefeaturegrouprules
verbs:
- get
- list
- watch
- update
- create
- apiGroups:
- coordination.k8s.io
resources:
Expand Down
321 changes: 321 additions & 0 deletions deployment/helm/node-feature-discovery/crds/nfd-api-crds.yaml

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions deployment/helm/node-feature-discovery/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ rules:
- get
- list
- watch
- apiGroups:
- nfd.k8s-sigs.io
resources:
- nodefeaturegroups
- nodefeaturegrouprules
verbs:
- get
- list
- watch
- update
- create
- apiGroups:
- coordination.k8s.io
resources:
Expand Down
3 changes: 3 additions & 0 deletions deployment/helm/node-feature-discovery/templates/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ spec:
{{- if .Values.master.instance | empty | not }}
- "-instance={{ .Values.master.instance }}"
{{- end }}
{{- if .Values.enableNodeFeatureGroupApi }}
- "-enable-nodefeaturegroup-api=true"
{{- end }}
{{- if not .Values.enableNodeFeatureApi }}
- "-port={{ .Values.master.port | default "8080" }}"
- "-enable-nodefeature-api=false"
Expand Down
1 change: 1 addition & 0 deletions deployment/helm/node-feature-discovery/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fullnameOverride: ""
namespaceOverride: ""

enableNodeFeatureApi: true
enableNodeFeatureGroupApi: false

master:
enable: true
Expand Down
16 changes: 16 additions & 0 deletions docs/reference/master-commandline-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,22 @@ Example:
nfd-master -enable-nodefeature-api=false
```

### -enable-nodefeaturegroup-api

> **NOTE:** This feature is experimental and may change in the future.
The `-enable-nodefeaturegroup-api` flag enables/disables the
[NodeFeatureGroup](../usage/custom-resources.md#nodefeaturegroup) CRD API for
working with NodeFeatureGroups.

Default: false

Example:

```bash
nfd-master -enable-nodefeaturegroup-api=true
```

### -enable-leader-election

The `-enable-leader-election` flag enables leader election for NFD-Master.
Expand Down
52 changes: 52 additions & 0 deletions docs/usage/custom-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,58 @@ See the
[Customization guide](customization-guide.md#node-feature-rule-custom-resource)
for full documentation of the NodeFeatureRule resource and its usage.
## NodeFeatureGroup
> **NOTE:** This feature is experimental and may change in the future.
NodeFeatureGroup is an NFD-specific custom resource that is designed for
grouping Nodes by matching features rules. NFD-Master watches for
NodeFeatureGroupRules objects in the cluster and creates a NodeFeatureGroup
object for each NodeFeatureGroupRule. The NodeFeatureGroup object contains a
list of nodes that match the NodeFeatureGroupRule.
```yaml
apiVersion: nfd.k8s-sigs.io/v1alpha1
kind: NodeFeatureGroup
metadata:
name: my-sample-group-resource
namespace: node-feature-discovery
spec:
FeatureGroup:
name: my-sample-group-resource
nodes:
- node-1
- node-2
- node-3
```
## NodeFeatureGroupRule
> **NOTE:** This feature is experimental and may change in the future.
NodeFeatureGroupRule is an NFD-specific custom resource that is designed for
grouping Nodes by matching features rules. NFD-Master watches for
NodeFeatureGroupRules objects in the cluster and creates a NodeFeatureGroup
object for each NodeFeatureGroupRule.
NodeFeatureGroupRule is similar to NodeFeatureRule, but instead of labeling
nodes, it creates a NodeFeatureGroup object that contains a list of nodes that
match the NodeFeatureGroupRule.
```yaml
apiVersion: nfd.k8s-sigs.io/v1alpha1
kind: NodeFeatureGroupRule
metadata:
name: my-sample-group-resource
spec:
featureGroupRules:
- name: dummy-rule
matchFeatures:
- feature: kernel.version
matchExpressions:
major: {op: Exists}
```
## NodeResourceTopology
When run with NFD-Topology-Updater, NFD creates NodeResourceTopology objects
Expand Down
12 changes: 12 additions & 0 deletions examples/nodefeaturerule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ spec:
- feature: kernel.version
matchExpressions:
major: {op: Exists}
---
apiVersion: nfd.k8s-sigs.io/v1alpha1
kind: NodeFeatureGroupRule
metadata:
name: my-sample-group-resource
spec:
featureGroupRules:
- name: dummy-rule
matchFeatures:
- feature: kernel.version
matchExpressions:
major: {op: Exists}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Kubernetes Authors.
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@ limitations under the License.

package v1alpha1

// Default values for annotations and labels.
const (
// FeatureLabelNs is the (default) namespace for feature labels.
FeatureLabelNs = "feature.node.kubernetes.io"
Expand Down Expand Up @@ -69,9 +70,62 @@ const (
// label for filtering features designated for a certain node.
NodeFeatureObjNodeNameLabel = "nfd.node.kubernetes.io/node-name"

// FeatureGroupObjLabel is the label that specifies current cluster name
FeatureGroupObjLabel = "nfd.node.kubernetes.io/feature-group"

// FeatureAnnotationNs is the (default) namespace for feature annotations.
FeatureAnnotationNs = "feature.node.kubernetes.io"

// FeatureAnnotationSubNsSuffix is the suffix for allowed feature annotation sub-namespaces.
FeatureAnnotationSubNsSuffix = "." + FeatureAnnotationNs
)

const (
// MatchAny returns always true.
MatchAny MatchOp = ""
// MatchIn returns true if any of the values stored in the expression is
// equal to the input.
MatchIn MatchOp = "In"
// MatchNotIn returns true if none of the values in the expression are
// equal to the input.
MatchNotIn MatchOp = "NotIn"
// MatchInRegexp treats values of the expression as regular expressions and
// returns true if any of them matches the input.
MatchInRegexp MatchOp = "InRegexp"
// MatchExists returns true if the input is valid. The expression must not
// have any values.
MatchExists MatchOp = "Exists"
// MatchDoesNotExist returns true if the input is not valid. The expression
// must not have any values.
MatchDoesNotExist MatchOp = "DoesNotExist"
// MatchGt returns true if the input is greater than the value of the
// expression (number of values in the expression must be exactly one).
// Both the input and value must be integer numbers, otherwise an error is
// returned.
MatchGt MatchOp = "Gt"
// MatchLt returns true if the input is less than the value of the
// expression (number of values in the expression must be exactly one).
// Both the input and value must be integer numbers, otherwise an error is
// returned.
MatchLt MatchOp = "Lt"
// MatchGtLt returns true if the input is between two values, i.e. greater
// than the first value and less than the second value of the expression
// (number of values in the expression must be exactly two). Both the input
// and values must be integer numbers, otherwise an error is returned.
MatchGtLt MatchOp = "GtLt"
// MatchIsTrue returns true if the input holds the value "true". The
// expression must not have any values.
MatchIsTrue MatchOp = "IsTrue"
// MatchIsFalse returns true if the input holds the value "false". The
// expression must not have any values.
MatchIsFalse MatchOp = "IsFalse"
)

const (
// RuleBackrefDomain is the special feature domain for backreferencing
// output of preceding rules.
RuleBackrefDomain = "rule"
// RuleBackrefFeature is the special feature name for backreferencing
// output of preceding rules.
RuleBackrefFeature = "matched"
)
2 changes: 1 addition & 1 deletion pkg/apis/nfd/v1alpha1/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,53 +238,3 @@ type MatchOp string

// MatchValue is the list of values associated with a MatchExpression.
type MatchValue []string

const (
// MatchAny returns always true.
MatchAny MatchOp = ""
// MatchIn returns true if any of the values stored in the expression is
// equal to the input.
MatchIn MatchOp = "In"
// MatchNotIn returns true if none of the values in the expression are
// equal to the input.
MatchNotIn MatchOp = "NotIn"
// MatchInRegexp treats values of the expression as regular expressions and
// returns true if any of them matches the input.
MatchInRegexp MatchOp = "InRegexp"
// MatchExists returns true if the input is valid. The expression must not
// have any values.
MatchExists MatchOp = "Exists"
// MatchDoesNotExist returns true if the input is not valid. The expression
// must not have any values.
MatchDoesNotExist MatchOp = "DoesNotExist"
// MatchGt returns true if the input is greater than the value of the
// expression (number of values in the expression must be exactly one).
// Both the input and value must be integer numbers, otherwise an error is
// returned.
MatchGt MatchOp = "Gt"
// MatchLt returns true if the input is less than the value of the
// expression (number of values in the expression must be exactly one).
// Both the input and value must be integer numbers, otherwise an error is
// returned.
MatchLt MatchOp = "Lt"
// MatchGtLt returns true if the input is between two values, i.e. greater
// than the first value and less than the second value of the expression
// (number of values in the expression must be exactly two). Both the input
// and values must be integer numbers, otherwise an error is returned.
MatchGtLt MatchOp = "GtLt"
// MatchIsTrue returns true if the input holds the value "true". The
// expression must not have any values.
MatchIsTrue MatchOp = "IsTrue"
// MatchIsFalse returns true if the input holds the value "false". The
// expression must not have any values.
MatchIsFalse MatchOp = "IsFalse"
)

const (
// RuleBackrefDomain is the special feature domain for backreferencing
// output of preceding rules.
RuleBackrefDomain = "rule"
// RuleBackrefFeature is the special feature name for backreferencing
// output of preceding rules.
RuleBackrefFeature = "matched"
)
91 changes: 91 additions & 0 deletions pkg/apis/nfd/v1alpha1/nodefeaturegroup_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NodeFeatureGroup resource holds Node pools by featureGroup
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Namespaced,shortName=nfg
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +genclient
type NodeFeatureGroup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NodeFeatureGroupSpec `json:"spec"`
}

// NodeFeatureGroupSpec describes a NodeFeatureGroup object.
type NodeFeatureGroupSpec struct {
// FeatureGroupRules is a list of feature group rules.
// Feature group rules are used to group nodes into feature groups.
// +optional
FeatureGroup `json:"featureGroup"`
// Features is the set of features that are shared by all nodes in the feature group
// +optional
Features map[string]string `json:"features"`
}

type FeatureGroup struct {
// Name is the name of the feature group
Name string `json:"name"`
// Nodes is the list of nodes in the cluster that belong to this feature group
// +optional
Nodes []string `json:"nodes"`
}

// NodeFeatureGroupList contains a list of NodeFeatureGroup objects.
// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type NodeFeatureGroupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []NodeFeatureGroup `json:"spec"`
}

// NodeFeatureGroupRule resource specifies a configuration for feature-based
// node grouping.
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=nfgr
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +genclient
// +genclient:nonNamespaced
type NodeFeatureGroupRule struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NodeFeatureGroupRuleSpec `json:"spec"`
}

// NodeFeatureGroupRuleSpec describes a NodeFeatureGroupRule.
type NodeFeatureGroupRuleSpec struct {
FeatureGroupRules []Rule `json:"featureGroupRules"`
}

// NodeFeatureGroupRuleList contains a list of NodeFeatureGroupRule objects.
// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type NodeFeatureGroupRuleList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []NodeFeatureGroupRule `json:"spec"`
}
Loading

0 comments on commit 5f43f6c

Please sign in to comment.