Skip to content

Commit feea0e3

Browse files
authored
Merge pull request #2010 from mfranczy/image-compatibility-nfr
Bugfixes for image compatibility feature
2 parents 0cef90d + 8db03fe commit feea0e3

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

pkg/apis/nfd/nodefeaturerule/rule.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ func evaluateFeatureMatcher(m *nfdv1alpha1.FeatureMatcher, features *nfdv1alpha1
269269
fI, okI := features.Instances[featureName]
270270
if !okF && !okA && !okI {
271271
klog.V(2).InfoS("feature not available", "featureName", featureName)
272-
return false, nil, nil
272+
if failFast {
273+
return false, nil, nil
274+
}
275+
isMatch = false
276+
continue
273277
}
274278

275279
if term.MatchExpressions != nil {

pkg/client-nfd/compat/artifact-client/client.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"context"
2323
"encoding/json"
2424
"fmt"
25+
"slices"
26+
"time"
2527

2628
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2729
oras "oras.land/oras-go/v2"
@@ -34,6 +36,10 @@ import (
3436
compatv1alpha1 "sigs.k8s.io/node-feature-discovery/api/image-compatibility/v1alpha1"
3537
)
3638

39+
const (
40+
ArtifactCreationTimestampKey = "org.opencontainers.image.created"
41+
)
42+
3743
// ArtifactClient interface contain set of functions to manipulate compatibility artfact.
3844
type ArtifactClient interface {
3945
// FetchCompatibilitySpec downloads the compatibility specifcation associated with the image.
@@ -90,6 +96,14 @@ func (c *Client) FetchCompatibilitySpec(ctx context.Context) (*compatv1alpha1.Sp
9096
} else if len(descs) < 1 {
9197
return nil, fmt.Errorf("compatibility artifact not found")
9298
}
99+
100+
// Sort the artifacts in desc order.
101+
// If the artifact does not have creation timestamp it will be moved to the top of the slice.
102+
slices.SortFunc(descs, func(i, j ocispec.Descriptor) int {
103+
it, _ := time.Parse(time.RFC3339, i.Annotations[ArtifactCreationTimestampKey])
104+
jt, _ := time.Parse(time.RFC3339, j.Annotations[ArtifactCreationTimestampKey])
105+
return it.Compare(jt)
106+
})
93107
artifactDesc := descs[len(descs)-1]
94108

95109
_, content, err := oras.FetchBytes(ctx, repo.Manifests(), artifactDesc.Digest.String(), oras.DefaultFetchBytesOptions)

pkg/client-nfd/compat/node-validator/node-validator.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func (nv *nodeValidator) Execute(ctx context.Context) ([]*CompatibilityStatus, e
9797
}
9898

9999
func evaluateRuleStatus(rule *nfdv1alpha1.Rule, matchStatus *nodefeaturerule.MatchStatus) ProcessedRuleStatus {
100+
var matchedFeatureTerms nfdv1alpha1.FeatureMatcher
100101
out := ProcessedRuleStatus{Name: rule.Name, IsMatch: matchStatus.IsMatch}
101102

102103
evaluateFeatureMatcher := func(featureMatcher, matchedFeatureTerms nfdv1alpha1.FeatureMatcher) []MatchedExpression {
@@ -163,11 +164,17 @@ func evaluateRuleStatus(rule *nfdv1alpha1.Rule, matchStatus *nodefeaturerule.Mat
163164
}
164165

165166
if matchFeatures := rule.MatchFeatures; matchFeatures != nil {
166-
out.MatchedExpressions = evaluateFeatureMatcher(matchFeatures, matchStatus.MatchedFeaturesTerms)
167+
if matchStatus.MatchFeatureStatus != nil {
168+
matchedFeatureTerms = matchStatus.MatchFeatureStatus.MatchedFeaturesTerms
169+
}
170+
out.MatchedExpressions = evaluateFeatureMatcher(matchFeatures, matchedFeatureTerms)
167171
}
168172

169173
for i, matchAnyElem := range rule.MatchAny {
170-
matchedExpressions := evaluateFeatureMatcher(matchAnyElem.MatchFeatures, matchStatus.MatchAny[i].MatchedFeaturesTerms)
174+
if matchStatus.MatchAny[i].MatchedFeaturesTerms != nil {
175+
matchedFeatureTerms = matchStatus.MatchAny[i].MatchedFeaturesTerms
176+
}
177+
matchedExpressions := evaluateFeatureMatcher(matchAnyElem.MatchFeatures, matchedFeatureTerms)
171178
out.MatchedAny = append(out.MatchedAny, MatchAnyElem{MatchedExpressions: matchedExpressions})
172179
}
173180

pkg/client-nfd/compat/node-validator/node-validator_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ func TestNodeValidator(t *testing.T) {
114114
},
115115
},
116116
},
117+
{
118+
Name: "fake_5",
119+
MatchFeatures: v1alpha1.FeatureMatcher{
120+
{
121+
Feature: "unknown.unknown",
122+
MatchExpressions: &v1alpha1.MatchExpressionSet{
123+
"name": &v1alpha1.MatchExpression{Op: v1alpha1.MatchIn, Value: v1alpha1.MatchValue{"instance_1"}},
124+
},
125+
},
126+
},
127+
},
117128
},
118129
},
119130
},
@@ -219,6 +230,19 @@ func TestNodeValidator(t *testing.T) {
219230
},
220231
},
221232
},
233+
{
234+
Name: "fake_5",
235+
IsMatch: false,
236+
MatchedExpressions: []MatchedExpression{
237+
{
238+
Feature: "unknown.unknown",
239+
Name: "name",
240+
Expression: &v1alpha1.MatchExpression{Op: v1alpha1.MatchIn, Value: v1alpha1.MatchValue{"instance_1"}},
241+
MatcherType: MatchExpressionType,
242+
IsMatch: false,
243+
},
244+
},
245+
},
222246
},
223247
},
224248
}

0 commit comments

Comments
 (0)