Skip to content

Commit

Permalink
Add support for extraLabelNs, resourceLabels, labelWhiteList
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Zhang <kweizh@gmail.com>
  • Loading branch information
zwpaper committed Aug 13, 2021
1 parent b5efc6f commit 85ddce7
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
19 changes: 19 additions & 0 deletions api/v1/nodefeaturediscovery_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions config/crd/bases/nfd.kubernetes.io_nodefeaturediscoveries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions config/samples/nfd.kubernetes.io_v1_nodefeaturediscovery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions controllers/nodefeaturediscovery_controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllers
import (
"context"
"fmt"
"strings"

secv1 "github.com/openshift/api/security/v1"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 85ddce7

Please sign in to comment.