Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

source/custom: add internal rule api #1479

Merged
merged 4 commits into from
Dec 18, 2023

Conversation

marquiz
Copy link
Contributor

@marquiz marquiz commented Nov 30, 2023

  1. Add new internal "API" for the
    Add internal API for the nfd-worker custom feature source rule
    configuration. This API has already diverged from the NFD
    NodeFeatureRule API in that annotations, extended resources or taints
    are not supported. This patch basically copies the Rule type (and it's
    sub-types) from the nfdv1alpha1 package. It also adds conversion
    functions from the internal rule API to the "external" nfdv1alpha1 API.
    This is done to use the same rule matching functionality (from the
    nfdv1alpha1 package).

    One notable remark is that the feature source rule config supports some
    custom formatting (short forms, multi-type fields) that relies on
    special json/yaml unmarshalling functions that are better to nuke from
    the nfdv1alpha1 package (in another patch). These (legacy) syntax
    specialities are most probably used by nobody but let's keep them as
    they're already there. Unit tests to cover the custom json
    unmarshalling are now added.

  2. Use the new internal api for nfd-worker config parsing
    Change the custom feature source of nfd-worker to use the newly added
    internal config API for its own configuration. It now uses the internal
    types for json/yaml unmarshalling but converts them to external
    nfdv1alpha1 API to do the actual rule matching as the internal API does
    not duplicate that functionality.

  3. Drop custom unmarshaller functions from the nfdv1alpha1 API

Copy link

netlify bot commented Nov 30, 2023

Deploy Preview for kubernetes-sigs-nfd ready!

Name Link
🔨 Latest commit b28d5c1
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-nfd/deploys/658047c8804508000848ccfc
😎 Deploy Preview https://deploy-preview-1479--kubernetes-sigs-nfd.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 30, 2023
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 30, 2023
@marquiz
Copy link
Contributor Author

marquiz commented Dec 1, 2023

Let's wait for #1480 at least
/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 1, 2023
@marquiz marquiz force-pushed the devel/api-internal branch 3 times, most recently from 11553e6 to 17b2184 Compare December 1, 2023 13:14
@ArangoGutierrez
Copy link
Contributor

Let's wait for #1480 at least /hold

#1480 is merged
/unhold

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Dec 14, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 15, 2023
@marquiz
Copy link
Contributor Author

marquiz commented Dec 15, 2023

Rebased

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 15, 2023
@ArangoGutierrez ArangoGutierrez self-assigned this Dec 18, 2023
source/custom/api/types.go Outdated Show resolved Hide resolved
}

// Validate validates the expression.
func (m *MatchExpression) Validate() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we leverage the new Validate PKG?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not for this internal API.

But that could be possible further change/enhancement on top of this PR. It'd be a slightly bigger change than initially thought.

Add internal API for the nfd-worker custom feature source rule
configuration. This API has already diverged from the NFD
NodeFeatureRule API in that annotations, extended resources or taints
are not supported. This patch basically copies the Rule type (and it's
sub-types) from the nfdv1alpha1 package. It also adds conversion
functions from the internal rule API to the "external" nfdv1alpha1 API.
This is done to use the same rule matching functionality (from the
nfdv1alpha1 package).

One notable remark is that the feature source rule config supports some
custom formatting (short forms, multi-type fields) that relies on
special json/yaml unmarshalling functions that are better to nuke from
the nfdv1alpha1 package (in another patch). These (legacy) syntax
specialities are most probably used by nobody but let's keep them as
they're already there.  Unit tests to cover the custom json
unmarshalling are now added.
Change the custom feature source of nfd-worker to use the newly added
internal config API for its own configuration. It now uses the internal
types for json/yaml unmarshalling but converts them to external
nfdv1alpha1 API to do the actual rule matching as the internal API does
not duplicate that functionality.
Not needed in the external API.
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 18, 2023
Copy link
Contributor

@ArangoGutierrez ArangoGutierrez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

package api

// Rule defines a rule for node customization such as labeling.
type Rule struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't like having duplicated cope like this. but for now it's ok.
I think for v0.16 I want to work on moving Rule type outside the v1alpha1 folder/pkg to clean the api pkg and also to have all that functionality in a more centralized location

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding duplication, I cannot think of a better alternative. The two APIs (the CRD API and the custom source configuration) have diverged. In terms of typedefs the custom source config is a subset of the CRD API, but in terms of "syntax", it's a superset as it supports these int-or-string-or-bool kind of fields and some historical shortforms etc

We cannot move the typedef outside the nfdv1alpha1 package as that's part of the API (or we technically could import it from anywhere but I think that's a bad idea because that other package then essentially becomes a part of the API...). For the "functionality", i.e. the implementation of Rule evaluation/processing, I agree that we want to move it out of the API package.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 18, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: be44725c918f2f505100fec2d50b837e807443b3

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ArangoGutierrez, marquiz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [ArangoGutierrez,marquiz]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ArangoGutierrez
Copy link
Contributor

/test pull-node-feature-discovery-build-image-cross-generic

Copy link

codecov bot commented Dec 18, 2023

Codecov Report

Merging #1479 (b28d5c1) into master (884edc6) will increase coverage by 0.67%.
The diff coverage is 72.55%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1479      +/-   ##
==========================================
+ Coverage   31.27%   31.94%   +0.67%     
==========================================
  Files          59       61       +2     
  Lines        7649     7722      +73     
==========================================
+ Hits         2392     2467      +75     
+ Misses       5009     5004       -5     
- Partials      248      251       +3     
Files Coverage Δ
pkg/apis/nfd/v1alpha1/expression.go 72.31% <ø> (+5.64%) ⬆️
source/custom/api/conversion.go 75.34% <75.34%> (ø)
source/custom/api/expression.go 71.12% <71.12%> (ø)

@k8s-ci-robot k8s-ci-robot merged commit 7ae2516 into kubernetes-sigs:master Dec 18, 2023
12 checks passed
@marquiz marquiz deleted the devel/api-internal branch December 19, 2023 08:32
@marquiz marquiz mentioned this pull request Dec 20, 2023
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants