diff --git a/source/custom/custom.go b/source/custom/custom.go index 83827395c2..87204112e6 100644 --- a/source/custom/custom.go +++ b/source/custom/custom.go @@ -25,6 +25,7 @@ import ( "sigs.k8s.io/node-feature-discovery/source" "sigs.k8s.io/node-feature-discovery/source/cpu" "sigs.k8s.io/node-feature-discovery/source/kernel" + "sigs.k8s.io/node-feature-discovery/source/local" "sigs.k8s.io/node-feature-discovery/source/pci" "sigs.k8s.io/node-feature-discovery/source/system" "sigs.k8s.io/node-feature-discovery/source/usb" @@ -40,6 +41,7 @@ type MatchRule struct { Nodename *system.NodenameRule `json:"nodename,omitempty"` CPU *cpu.CustomRule `json:"cpu,omitempty"` Kernel *kernel.CustomRule `json:"kernel,omitempty"` + Local *local.CustomRule `json:"local,omitempty"` System *system.CustomRule `json:"system,omitempty"` } @@ -128,6 +130,7 @@ func (s *customSource) discoverFeature(feature FeatureSpec) (bool, error) { matchRules.Nodename, matchRules.CPU, matchRules.Kernel, + matchRules.Local, matchRules.System, } diff --git a/source/local/custom_rule.go b/source/local/custom_rule.go new file mode 100644 index 0000000000..1310f26610 --- /dev/null +++ b/source/local/custom_rule.go @@ -0,0 +1,36 @@ +/* +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. +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 local + +import ( + "k8s.io/klog/v2" + + "sigs.k8s.io/node-feature-discovery/source" +) + +// CustomRule implements the source.CustomRule interface +type CustomRule struct { + Labels source.MatchExpressionSet +} + +func (r *CustomRule) Match() (bool, error) { + if m, err := r.Labels.MatchValues(src.features.Labels); err != nil || m == false { + klog.V(2).Infof("local CustomRule: failed to match labels") + return m, err + } + return true, nil +}