Skip to content

Commit 6f6f5d6

Browse files
authored
Merge pull request #2087 from marquiz/devel/compat-api-types
compat/api: use GroupRule type
2 parents a2600b9 + fba7fb6 commit 6f6f5d6

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

api/image-compatibility/v1alpha1/spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Spec struct {
3838
// that describe the image requirements for the host and OS.
3939
type Compatibility struct {
4040
// Rules represents a list of Node Feature Rules.
41-
Rules []nfdv1alpha1.Rule `json:"rules"`
41+
Rules []nfdv1alpha1.GroupRule `json:"rules"`
4242
// Weight indicates the priority of the compatibility set.
4343
Weight int `json:"weight,omitempty"`
4444
// Tag enables grouping or distinguishing between compatibility sets.

docs/usage/image-compatibility.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ sort: 11
2020
**Image Compatibility is in the experimental `v1alpha1` version.**
2121

2222
Image compatibility metadata enables container image authors to define their
23-
image requirements using [Node Feature Rules](./custom-resources.md#nodefeaturerule).
23+
image requirements using a spec similar to
24+
[Node Feature Groups](./custom-resources.md#nodefeaturegroup).
2425
This complementary solution allows features discovered on nodes to be matched
2526
directly from images. As a result, container requirements become discoverable
2627
and programmable, supporting various consumers and use cases where applications
@@ -29,9 +30,9 @@ need a specific compatible environment.
2930
### Compatibility Specification
3031

3132
The compatibility specification is a list of compatibility objects that contain
32-
[Node Feature Rules](./custom-resources.md#nodefeaturerule), along with
33-
additional fields to control the execution of validation between the image and
34-
the host.
33+
rules similar to [Node Feature Groups](./custom-resources.md#nodefeaturegroup),
34+
along with additional fields to control the execution of validation between the
35+
image and the host.
3536

3637
### Schema
3738

@@ -42,9 +43,9 @@ the host.
4243
This REQUIRED property is a list of compatibility sets.
4344

4445
- **rules** - *object*
45-
This REQUIRED property is a reference to the spec of the [NodeFeatureRule API](./custom-resources.md#nodefeaturerule).
46+
This REQUIRED property is a reference to the spec of the [NodeFeatureGroup API](./custom-resources.md#nodefeaturegroup).
4647
The spec allows image requirements to be described using the features
47-
discovered from NFD sources. For more details, please refer to [the documentation](./custom-resources.md#nodefeaturerule).
48+
discovered from NFD sources. For more details, please refer to [the documentation](./custom-resources.md#nodefeaturegroup).
4849

4950
- **weight** - *int*
5051
This OPTIONAL property specifies the [node affinity weight](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity-weight).

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,13 @@ func (nv *nodeValidator) Execute(ctx context.Context) ([]*CompatibilityStatus, e
8181
compat := newCompatibilityStatus(&c)
8282

8383
for _, r := range c.Rules {
84-
ruleOut, err := nodefeaturerule.Execute(&r, features, false)
84+
ruleOut, err := nodefeaturerule.ExecuteGroupRule(&r, features, false)
8585
if err != nil {
8686
return nil, err
8787
}
8888
compat.Rules = append(compat.Rules, nv.evaluateRuleStatus(&r, ruleOut.MatchStatus))
8989

9090
// Add the 'rule.matched' feature for backreference functionality
91-
features.InsertAttributeFeatures(nfdv1alpha1.RuleBackrefDomain, nfdv1alpha1.RuleBackrefFeature, ruleOut.Labels)
9291
features.InsertAttributeFeatures(nfdv1alpha1.RuleBackrefDomain, nfdv1alpha1.RuleBackrefFeature, ruleOut.Vars)
9392
}
9493
compats = append(compats, &compat)
@@ -97,7 +96,7 @@ func (nv *nodeValidator) Execute(ctx context.Context) ([]*CompatibilityStatus, e
9796
return compats, nil
9897
}
9998

100-
func (nv *nodeValidator) evaluateRuleStatus(rule *nfdv1alpha1.Rule, matchStatus *nodefeaturerule.MatchStatus) ProcessedRuleStatus {
99+
func (nv *nodeValidator) evaluateRuleStatus(rule *nfdv1alpha1.GroupRule, matchStatus *nodefeaturerule.MatchStatus) ProcessedRuleStatus {
101100
out := ProcessedRuleStatus{Name: rule.Name, IsMatch: matchStatus.IsMatch}
102101

103102
matchedFeatureTerms := nfdv1alpha1.FeatureMatcher{}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func init() {
3434
fs.SetConfig(fs.NewConfig())
3535
}
3636

37-
func buildDefaultSpec(rules []v1alpha1.Rule) *compatv1alpha1.Spec {
37+
func buildDefaultSpec(rules []v1alpha1.GroupRule) *compatv1alpha1.Spec {
3838
return &compatv1alpha1.Spec{
3939
Version: compatv1alpha1.Version,
4040
Compatibilties: []compatv1alpha1.Compatibility{
@@ -73,7 +73,7 @@ func TestNodeValidator(t *testing.T) {
7373
Convey("With a single compatibility set", t, func() {
7474

7575
Convey("That contains flag which results in match", func() {
76-
spec := buildDefaultSpec([]v1alpha1.Rule{
76+
spec := buildDefaultSpec([]v1alpha1.GroupRule{
7777
{
7878
Name: "fake_1",
7979
MatchFeatures: v1alpha1.FeatureMatcher{
@@ -105,7 +105,7 @@ func TestNodeValidator(t *testing.T) {
105105
})
106106

107107
Convey("That contains flags and attribute which result in mismatch", func() {
108-
spec := buildDefaultSpec([]v1alpha1.Rule{
108+
spec := buildDefaultSpec([]v1alpha1.GroupRule{
109109
{
110110
Name: "fake_2",
111111
MatchFeatures: v1alpha1.FeatureMatcher{
@@ -152,7 +152,7 @@ func TestNodeValidator(t *testing.T) {
152152
})
153153

154154
Convey("That contains instances which results in mismatch", func() {
155-
spec := buildDefaultSpec([]v1alpha1.Rule{
155+
spec := buildDefaultSpec([]v1alpha1.GroupRule{
156156
{
157157
Name: "fake_3",
158158
MatchFeatures: v1alpha1.FeatureMatcher{
@@ -215,7 +215,7 @@ func TestNodeValidator(t *testing.T) {
215215
})
216216

217217
Convey("That contains instances which results in match", func() {
218-
spec := buildDefaultSpec([]v1alpha1.Rule{
218+
spec := buildDefaultSpec([]v1alpha1.GroupRule{
219219
{
220220
Name: "fake_4",
221221
MatchAny: []v1alpha1.MatchAnyElem{
@@ -278,7 +278,7 @@ func TestNodeValidator(t *testing.T) {
278278
})
279279

280280
Convey("That contains spec with zero matches which results in mismatch", func() {
281-
spec := buildDefaultSpec([]v1alpha1.Rule{
281+
spec := buildDefaultSpec([]v1alpha1.GroupRule{
282282
{
283283
Name: "fake_5",
284284
MatchFeatures: v1alpha1.FeatureMatcher{
@@ -312,7 +312,7 @@ func TestNodeValidator(t *testing.T) {
312312
})
313313

314314
Convey("That contains matchAny and matchFeatures in one spec", func() {
315-
spec := buildDefaultSpec([]v1alpha1.Rule{
315+
spec := buildDefaultSpec([]v1alpha1.GroupRule{
316316
{
317317
Name: "fake_6",
318318
MatchAny: []v1alpha1.MatchAnyElem{
@@ -401,7 +401,7 @@ func TestNodeValidator(t *testing.T) {
401401
Tag: "prefered",
402402
Weight: 90,
403403
Description: "Fake compatibility 1",
404-
Rules: []v1alpha1.Rule{
404+
Rules: []v1alpha1.GroupRule{
405405
{
406406
Name: "fake_1",
407407
MatchFeatures: v1alpha1.FeatureMatcher{
@@ -419,7 +419,7 @@ func TestNodeValidator(t *testing.T) {
419419
Tag: "fallback",
420420
Weight: 40,
421421
Description: "Fake compatibility 2",
422-
Rules: []v1alpha1.Rule{
422+
Rules: []v1alpha1.GroupRule{
423423
{
424424
Name: "fake_1",
425425
MatchFeatures: v1alpha1.FeatureMatcher{
@@ -498,7 +498,7 @@ func TestNodeValidator(t *testing.T) {
498498
Tag: "prefered",
499499
Weight: 90,
500500
Description: "Fake compatibility 1",
501-
Rules: []v1alpha1.Rule{
501+
Rules: []v1alpha1.GroupRule{
502502
{
503503
Name: "fake_1",
504504
MatchFeatures: v1alpha1.FeatureMatcher{
@@ -516,7 +516,7 @@ func TestNodeValidator(t *testing.T) {
516516
Tag: "fallback",
517517
Weight: 40,
518518
Description: "Fake compatibility 2",
519-
Rules: []v1alpha1.Rule{
519+
Rules: []v1alpha1.GroupRule{
520520
{
521521
Name: "fake_1",
522522
MatchFeatures: v1alpha1.FeatureMatcher{

0 commit comments

Comments
 (0)