Skip to content

Commit

Permalink
Allow switching to shorter label namespace nfd.k8s.io
Browse files Browse the repository at this point in the history
Signed-off-by: Feruzjon Muyassarov <[email protected]>
  • Loading branch information
fmuyassarov committed Oct 18, 2022
1 parent 14ad323 commit d8ca4f3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/nfd-master/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func initFlags(flagset *flag.FlagSet) *master.Args {
flagset.BoolVar(&args.VerifyNodeName, "verify-node-name", false,
"Verify worker node name against the worker's TLS certificate. "+
"Only takes effect when TLS authentication has been enabled.")
flagset.StringVar(&args.NsFormat, "label-ns", "legacy",
"Feature label namespace format. By default set to legacy.")

return args
}
33 changes: 33 additions & 0 deletions pkg/nfd-master/nfd-master.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ import (
"sigs.k8s.io/node-feature-discovery/pkg/version"
)

var (
// FeatureLabelNs is the namespace for feature labels
FeatureLabelNs = "feature.node.kubernetes.io"
// FeatureLabelSubNsSuffix is the suffix for allowed feature label sub-namespaces
FeatureLabelSubNsSuffix = "." + FeatureLabelNs
)

const (
// ProfileLabelNs is the namespace for profile labels
ProfileLabelNs = "profile.node.kubernetes.io"

// ProfileLabelSubNsSuffix is the suffix for allowed profile label sub-namespaces
ProfileLabelSubNsSuffix = "." + ProfileLabelNs

// AnnotationNsBase namespace for all NFD-related annotations
AnnotationNsBase = "nfd.node.kubernetes.io"
)

// Labels are a Kubernetes representation of discovered features.
type Labels map[string]string

Expand All @@ -72,6 +90,7 @@ type Args struct {
LabelWhiteList utils.RegexpVal
FeatureRulesController bool
NoPublish bool
NsFormat string
Port int
Prune bool
VerifyNodeName bool
Expand Down Expand Up @@ -104,6 +123,13 @@ func NewNfdMaster(args *Args) (NfdMaster, error) {
stop: make(chan struct{}, 1),
}

if args.NsFormat != "legacy" {
// FeatureLabelNs is the namespace for feature labels
FeatureLabelNs = "nfd.k8s.io"
// FeatureLabelSubNsSuffix is the suffix for allowed feature label sub-namespaces
FeatureLabelSubNsSuffix = "." + FeatureLabelNs
}

if args.Instance != "" {
if ok, _ := regexp.MatchString(`^([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$`, args.Instance); !ok {
return nfd, fmt.Errorf("invalid -instance %q: instance name "+
Expand Down Expand Up @@ -141,6 +167,12 @@ func NewNfdMaster(args *Args) (NfdMaster, error) {
// is called.
func (m *nfdMaster) Run() error {
klog.Infof("Node Feature Discovery Master %s", version.Get())

// TODO(fmuyassarov): Remove this logging when short label namespace becomes default option.
if m.args.NsFormat != "legacy" {
klog.Infof("Using short label namespace %q instead of legacy namespace", FeatureLabelNs)
}

if m.args.Instance != "" {
klog.Infof("Master instance: %q", m.args.Instance)
}
Expand Down Expand Up @@ -344,6 +376,7 @@ func filterFeatureLabels(labels Labels, extraLabelNs map[string]struct{}, labelW
outLabels := Labels{}

for label, value := range labels {

// Add possibly missing default ns
label := addNs(label, nfdv1alpha1.FeatureLabelNs)

Expand Down

0 comments on commit d8ca4f3

Please sign in to comment.