From b1b30617382b76c02a05e52e966e3433329c60f0 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Wed, 6 Sep 2023 14:26:53 +0300 Subject: [PATCH] sources/custom: convert static rules to new format Also add a log message warning about legacy rule format. --- source/custom/custom.go | 1 + source/custom/static_features.go | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/source/custom/custom.go b/source/custom/custom.go index 90ccdea4e..769e7b440 100644 --- a/source/custom/custom.go +++ b/source/custom/custom.go @@ -134,6 +134,7 @@ func (s *customSource) GetLabels() (source.FeatureLabels, error) { func (r *CustomRule) execute(features *nfdv1alpha1.Features) (nfdv1alpha1.RuleOutput, error) { if r.LegacyRule != nil { + klog.InfoS("legacy 'matchOn' rule format is deprecated, please convert to the new 'matchFeatures' rule format", "ruleName", r.LegacyRule.Name) ruleOut, err := r.LegacyRule.execute() if err != nil { return nfdv1alpha1.RuleOutput{}, fmt.Errorf("failed to execute legacy rule %s: %w", r.LegacyRule.Name, err) diff --git a/source/custom/static_features.go b/source/custom/static_features.go index fed8a22c5..3f44df99e 100644 --- a/source/custom/static_features.go +++ b/source/custom/static_features.go @@ -18,7 +18,6 @@ package custom import ( nfdv1alpha1 "sigs.k8s.io/node-feature-discovery/pkg/apis/nfd/v1alpha1" - "sigs.k8s.io/node-feature-discovery/source/custom/rules" ) // getStaticFeatures returns statically configured custom features to discover @@ -26,12 +25,14 @@ import ( func getStaticFeatureConfig() []CustomRule { return []CustomRule{ { - LegacyRule: &LegacyRule{ - Name: "rdma.capable", - MatchOn: []LegacyMatcher{ - { - PciID: &rules.PciIDRule{ - MatchExpressionSet: nfdv1alpha1.MatchExpressionSet{ + Rule: &Rule{ + nfdv1alpha1.Rule{ + Name: "RDMA capable static rule", + Labels: map[string]string{"rdma.capable": "true"}, + MatchFeatures: nfdv1alpha1.FeatureMatcher{ + nfdv1alpha1.FeatureMatcherTerm{ + Feature: "pci.device", + MatchExpressions: nfdv1alpha1.MatchExpressionSet{ "vendor": nfdv1alpha1.MustCreateMatchExpression(nfdv1alpha1.MatchIn, "15b3"), }, }, @@ -40,12 +41,14 @@ func getStaticFeatureConfig() []CustomRule { }, }, { - LegacyRule: &LegacyRule{ - Name: "rdma.available", - MatchOn: []LegacyMatcher{ - { - LoadedKMod: &rules.LoadedKModRule{ - MatchExpressionSet: nfdv1alpha1.MatchExpressionSet{ + Rule: &Rule{ + nfdv1alpha1.Rule{ + Name: "RDMA available static rule", + Labels: map[string]string{"rdma.available": "true"}, + MatchFeatures: nfdv1alpha1.FeatureMatcher{ + nfdv1alpha1.FeatureMatcherTerm{ + Feature: "kernel.loadedmodule", + MatchExpressions: nfdv1alpha1.MatchExpressionSet{ "ib_uverbs": nfdv1alpha1.MustCreateMatchExpression(nfdv1alpha1.MatchExists), "rdma_ucm": nfdv1alpha1.MustCreateMatchExpression(nfdv1alpha1.MatchExists), }, @@ -55,4 +58,5 @@ func getStaticFeatureConfig() []CustomRule { }, }, } + }