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

Defaulting to the latest tag if no tag was specified. #826

Closed
wants to merge 2 commits into from

Conversation

ybettan
Copy link
Contributor

@ybettan ybettan commented Jun 3, 2024

Defaulting to the latest tag if no tag was specified.

In the current code, we handle differently build/sign and deploying a
pre-built kmod.

This is the current behavior:

  • If a build/sign section is set in the module, and the image tag
    isn't specified, then we will return an error.
  • If there are no build/sign section, and the image tag isn't
    specified, then we will default to the latest tag.

This change is adjusting the behavior of both workflow to always defaul
to the latest image tag if it is not specified in the
Module/ManagedClusterModule.

This is achieved by adding a new mutating-webhook for the
Module&ManangedClusterModule objects.

This change is also adding the nullable attributes to some API fields
in order for it to work.


/cc @qbarrand @yevgeny-shnaidman

The +nullable kubebuilder annotation is required until this PR is merged.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 3, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ybettan

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:

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

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 3, 2024
Copy link

netlify bot commented Jun 3, 2024

Deploy Preview for kubernetes-sigs-kmm ready!

Name Link
🔨 Latest commit 0a2b042
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-kmm/deploys/66844a1e09167b0008dfb043
😎 Deploy Preview https://deploy-preview-826--kubernetes-sigs-kmm.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.

@ybettan
Copy link
Contributor Author

ybettan commented Jun 3, 2024

/hols
The webhook isn't popping the warning for some reason.

@codecov-commenter
Copy link

codecov-commenter commented Jun 3, 2024

Codecov Report

Attention: Patch coverage is 69.56522% with 14 lines in your changes missing coverage. Please review.

Project coverage is 71.63%. Comparing base (fa23a9b) to head (0a2b042).
Report is 76 commits behind head on main.

Files Patch % Lines
...ternal/webhook/hub/managedclustermodule_mutator.go 70.58% 5 Missing ⚠️
internal/webhook/module_mutator.go 80.00% 5 Missing ⚠️
cmd/webhook-server/main.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #826      +/-   ##
==========================================
- Coverage   79.09%   71.63%   -7.47%     
==========================================
  Files          51       68      +17     
  Lines        5109     4519     -590     
==========================================
- Hits         4041     3237     -804     
- Misses        882     1087     +205     
- Partials      186      195       +9     

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

if km.ContainerImage != "" {
imgToCheck = km.ContainerImage
}
if !strings.ContainsRune(imgToCheck, '@') && !strings.ContainsRune(imgToCheck, ':') {
Copy link
Contributor

Choose a reason for hiding this comment

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

why can't we just return ImageHashOrTagNotSet from here? Why do we have to wait for the loop to finish?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we return directly then we will only warn about a single potential missing tag in a single kernelMapping instead of appending them all to 1 warning.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need a warning in the webhook? Container image is either valid or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should have a new mutating webhook that sets the latest tag instead of returning warnings.

if km.ContainerImage != "" {
imgToCheck = km.ContainerImage
}
if !strings.ContainsRune(imgToCheck, '@') && !strings.ContainsRune(imgToCheck, ':') {
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think about using NewTag and NewDigest to verify the correctness of the image? Those functions are part of the go-containerregistry/pkg/name package, and they make a little bit more verifications than just the presence of @ or :


"github.com/go-logr/logr"
multierror "github.com/hashicorp/go-multierror"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use errors.Join from the standard library instead.

if km.ContainerImage != "" {
imgToCheck = km.ContainerImage
}
if !strings.ContainsRune(imgToCheck, '@') && !strings.ContainsRune(imgToCheck, ':') {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should have a new mutating webhook that sets the latest tag instead of returning warnings.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 27, 2024
@ybettan ybettan force-pushed the latest-tag branch 8 times, most recently from 4227a87 to 9acd668 Compare July 2, 2024 08:33
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 2, 2024
@ybettan ybettan force-pushed the latest-tag branch 4 times, most recently from 5711d0f to f001c8d Compare July 2, 2024 13:59
In the current code, we handle differently build/sign and deploying a
pre-built kmod.

This is the current behavior:
* If a `build`/`sign` section is set in the module, and the image tag
  isn't specified, then we will return an error.
* If there are no `build`/`sign` section, and the image tag isn't
  specified, then we will default to the `latest` tag.

This change is adjusting the behavior of both workflow to always default
to the `latest` image tag if it is not specified in the
`Module`/`ManagedClusterModule`.

This is achieved by adding a new mutating-webhook for the
`Module`&`ManangedClusterModule` objects.

This change is also adding the `nullable` attributes to some API fields
in order for it to work.

Signed-off-by: Yoni Bettan <yonibettan@gmail.com>
Signed-off-by: Yoni Bettan <yonibettan@gmail.com>
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 2, 2024
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jul 2, 2024

@ybettan: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kernel-module-management-check-commits-count 0a2b042 link true /test pull-kernel-module-management-check-commits-count

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@ybettan
Copy link
Contributor Author

ybettan commented Jul 2, 2024

/hold
This fix will fail for any field in the CR that is an optional pointer/slice and was not initiated because of this issue unless the +nullable kubebuilder annotation is added to it.

This is very fragile and will require an API bump for each field that we forgot to check.

@yevgeny-shnaidman @TomerNewman How about we just add a validation-webhook rule to refuse Module/ManagedClusterModule in which an image with no has or tag was specified?

We can proceed with this mutating webhook without the +nullable annotation once the PR fixing the issue is merged in https://github.com/kubernetes-sigs/structured-merge-diff.

@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 Jul 2, 2024
@ybettan
Copy link
Contributor Author

ybettan commented Jul 3, 2024

/close
Closing in favor of #853

@k8s-ci-robot
Copy link
Contributor

@ybettan: Closed this PR.

In response to this:

/close
Closing in favor of #853

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

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. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants