diff --git a/api/v1/nodefeaturediscovery_types.go b/api/v1/nodefeaturediscovery_types.go index a5ae1cf3..8d675dd0 100644 --- a/api/v1/nodefeaturediscovery_types.go +++ b/api/v1/nodefeaturediscovery_types.go @@ -32,6 +32,25 @@ type NodeFeatureDiscoverySpec struct { // +optional Instance string `json:"instance"` + // ExtraLabelNs defines the list of of allowed extra label namespaces + // By default, only allow labels in the default `feature.node.kubernetes.io` label namespace + // +nullable + // +kubebuilder:validation:Optional + ExtraLabelNs []string `json:"extraLabelNs,omitempty"` + + // ResourceLabels defines the list of features + // to be advertised as extended resources instead of labels. + // +nullable + // +kubebuilder:validation:Optional + ResourceLabels []string `json:"resourceLabels,omitempty"` + + // LabelWhiteList defines a regular expression + // for filtering feature labels based on their name. + // Each label must match against the given reqular expression in order to be published. + // +nullable + // +kubebuilder:validation:Optional + LabelWhiteList string `json:"labelWhiteList,omitempty"` + // WorkerConfig describes configuration options for the NFD // worker. // +optional diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 033b8599..e40680f7 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -45,7 +45,7 @@ func (in *NodeFeatureDiscovery) DeepCopyInto(out *NodeFeatureDiscovery) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec + in.Spec.DeepCopyInto(&out.Spec) in.Status.DeepCopyInto(&out.Status) } @@ -103,6 +103,16 @@ func (in *NodeFeatureDiscoveryList) DeepCopyObject() runtime.Object { func (in *NodeFeatureDiscoverySpec) DeepCopyInto(out *NodeFeatureDiscoverySpec) { *out = *in out.Operand = in.Operand + if in.ExtraLabelNs != nil { + in, out := &in.ExtraLabelNs, &out.ExtraLabelNs + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.ResourceLabels != nil { + in, out := &in.ResourceLabels, &out.ResourceLabels + *out = make([]string, len(*in)) + copy(*out, *in) + } out.WorkerConfig = in.WorkerConfig } diff --git a/config/crd/bases/nfd.kubernetes.io_nodefeaturediscoveries.yaml b/config/crd/bases/nfd.kubernetes.io_nodefeaturediscoveries.yaml index 7ca42539..bb7a2412 100644 --- a/config/crd/bases/nfd.kubernetes.io_nodefeaturediscoveries.yaml +++ b/config/crd/bases/nfd.kubernetes.io_nodefeaturediscoveries.yaml @@ -37,10 +37,24 @@ spec: spec: description: NodeFeatureDiscoverySpec defines the desired state of NodeFeatureDiscovery properties: + extraLabelNs: + description: ExtraLabelNs defines the list of of allowed extra label + namespaces By default, only allow labels in the default `feature.node.kubernetes.io` + label namespace + items: + type: string + nullable: true + type: array instance: description: Instance name. Used to separate annotation namespaces for multiple parallel deployments. type: string + labelWhiteList: + description: LabelWhiteList defines a regular expression for filtering + feature labels based on their name. Each label must match against + the given reqular expression in order to be published. + nullable: true + type: string operand: description: OperandSpec describes configuration options for the operand properties: @@ -63,6 +77,13 @@ spec: listens for incoming requests. type: integer type: object + resourceLabels: + description: ResourceLabels defines the list of features to be advertised + as extended resources instead of labels. + items: + type: string + nullable: true + type: array workerConfig: description: WorkerConfig describes configuration options for the NFD worker. diff --git a/config/samples/nfd.kubernetes.io_v1_nodefeaturediscovery.yaml b/config/samples/nfd.kubernetes.io_v1_nodefeaturediscovery.yaml index e1121bb4..a27c16ed 100644 --- a/config/samples/nfd.kubernetes.io_v1_nodefeaturediscovery.yaml +++ b/config/samples/nfd.kubernetes.io_v1_nodefeaturediscovery.yaml @@ -5,6 +5,11 @@ metadata: namespace: node-feature-discovery-operator spec: instance: "" # instance is empty by default + #labelWhiteList: "" + #extraLabelNs: + # - "example.com" + #resourceLabels: + # - "example.com/resource" operand: namespace: node-feature-discovery-operator image: gcr.io/k8s-staging-nfd/node-feature-discovery:master diff --git a/controllers/nodefeaturediscovery_controls.go b/controllers/nodefeaturediscovery_controls.go index 1e102cfc..c903a7be 100644 --- a/controllers/nodefeaturediscovery_controls.go +++ b/controllers/nodefeaturediscovery_controls.go @@ -19,6 +19,7 @@ package controllers import ( "context" "fmt" + "strings" secv1 "github.com/openshift/api/security/v1" appsv1 "k8s.io/api/apps/v1" @@ -324,6 +325,18 @@ func DaemonSet(n NFD) (ResourceStatus, error) { args = append(args, fmt.Sprintf("--instance=%s", n.ins.Spec.Instance)) } + if len(n.ins.Spec.ExtraLabelNs) != 0 { + args = append(args, fmt.Sprintf("--extra-label-ns=%s", strings.Join(n.ins.Spec.ExtraLabelNs, ","))) + } + + if len(n.ins.Spec.ResourceLabels) != 0 { + args = append(args, fmt.Sprintf("--resource-labels=%s", strings.Join(n.ins.Spec.ResourceLabels, ","))) + } + + if strings.TrimSpace(n.ins.Spec.LabelWhiteList) != "" { + args = append(args, fmt.Sprintf("--label-whitelist=%s", n.ins.Spec.LabelWhiteList)) + } + obj.Spec.Template.Spec.Containers[0].Args = args }