Skip to content

proposal: simplify labels.Requirement creation #446

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

Conversation

filariow
Copy link
Contributor

@filariow filariow commented Jul 22, 2024

We can skip validations performed by labels.NewRequirement as operator is fixed, key is constant, and value is extracted from Custom Resources.

NewRequirement is the constructor for a Requirement. If any of these rules is violated, an error is returned:

  1. The operator can only be In, NotIn, Equals, DoubleEquals, Gt, Lt, NotEquals, Exists, or DoesNotExist.
  2. If the operator is In or NotIn, the values set must be non-empty.
  3. If the operator is Equals, DoubleEquals, or NotEquals, the values set must contain one value.
  4. If the operator is Exists or DoesNotExist, the value set must be empty.
  5. If the operator is Gt or Lt, the values set must contain only one value, which will be interpreted as an integer.
  6. The key is invalid due to its length, or sequence of characters. See validateLabelKey for more details.

The empty string is a valid value in the input values set. Returned error, if not nil, is guaranteed to be an aggregated field.ErrorList

SelectorFromSet does not perform any validation, which means the server will reject the request if the Set contains invalid values.

We can skip validations performed by
[labels.NewRequirement](https://pkg.go.dev/k8s.io/apimachinery/pkg/labels#NewRequirement)
as operator is fixed, key is constant, and value is extracted
from Custom Resources.

[SelectorFromSet](https://pkg.go.dev/k8s.io/apimachinery/pkg/labels#SelectorFromSet)
does not perform any validation, which means the server will
reject the request if the Set contains invalid values.

Signed-off-by: Francesco Ilario <filario@redhat.com>
Copy link

Copy link

codecov bot commented Jul 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.36%. Comparing base (bd75cb2) to head (1538ea5).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #446      +/-   ##
==========================================
+ Coverage   78.14%   78.36%   +0.22%     
==========================================
  Files          41       41              
  Lines        2681     2672       -9     
==========================================
- Hits         2095     2094       -1     
+ Misses        491      487       -4     
+ Partials       95       91       -4     
Flag Coverage Δ
unittests 78.36% <100.00%> (+0.22%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@mfrancisc mfrancisc left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@MatousJobanek MatousJobanek left a comment

Choose a reason for hiding this comment

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

/lgtm

Copy link

openshift-ci bot commented Jul 23, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexeykazakov, filariow, MatousJobanek, mfrancisc

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 [MatousJobanek,alexeykazakov,mfrancisc]

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

@openshift-merge-bot openshift-merge-bot bot merged commit 9ed22dc into codeready-toolchain:master Jul 23, 2024
11 checks passed
@filariow filariow deleted the simplify-labelselectors branch July 23, 2024 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants