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

⚠️ ImageFilter - add exclusive validation -> pointers #1939

Merged
merged 2 commits into from
Mar 15, 2024

Conversation

dulek
Copy link
Contributor

@dulek dulek commented Mar 12, 2024

What this PR does / why we need it:
This commit changes ID and Name of ImageFilter to pointers which should only affect go marshalling.

Other than that it adds CEL validation of the ImageFilter, so that Name or Tags can only be set when ID is unset. Conversions are updated accordingly to make sure we only set Name when ID is unset.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

  1. Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

TODOs:

  • squashed commits
  • if necessary:
    • includes documentation
    • adds unit tests

/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 12, 2024
Copy link

netlify bot commented Mar 12, 2024

Deploy Preview for kubernetes-sigs-cluster-api-openstack ready!

Name Link
🔨 Latest commit dc3959e
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-openstack/deploys/65f2de403df8320009748c6e
😎 Deploy Preview https://deploy-preview-1939--kubernetes-sigs-cluster-api-openstack.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.

@dulek dulek force-pushed the filters-pointers branch 4 times, most recently from b94518a to f7ccaaa Compare March 12, 2024 15:39
@huxcrux
Copy link
Contributor

huxcrux commented Mar 13, 2024

/lgtm

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

@mdbooth mdbooth left a comment

Choose a reason for hiding this comment

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

Nice! Approved, but I'd appreciate it if you could add the additional requested test and fix the nit.

api/v1beta1/types.go Show resolved Hide resolved
// The ID of the desired image. If this is provided, the other filters will be ignored.
ID string `json:"id,omitempty"`
// The ID of the desired image. If ID is provided, the other filters cannot be provided.
// +kubebuilder:validation:Format:=uuid
Copy link
Contributor

Choose a reason for hiding this comment

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

Please can you also add a test for uuid format validation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Please can you add one more test that an invalid uuid is rejected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -43,7 +43,7 @@ type OpenStackMachineSpec struct {

// The image to use for your server instance.
// If the rootVolume is specified, this will be used when creating the root volume.
Image ImageFilter `json:"image,omitempty"`
Image ImageFilter `json:"image"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Please can you add an explicit // +optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't exactly sure if the image is optional. Is it? Should I make it Image *ImageFilter then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can't make ImageFilter optional, code requires that the exactly one image will be found. An empty ImageFilter might be possible and resolvable if you have just one image in that tenant.

Copy link
Contributor

Choose a reason for hiding this comment

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

D'oh. Of course this should not be optional. Yep, lets make it explicitly required.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dulek, mdbooth

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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 13, 2024
api/v1beta1/types.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 13, 2024
@dulek
Copy link
Contributor Author

dulek commented Mar 13, 2024

@mdbooth: I fixed a comment, but I'm still unsure about ImageFilter being optional. Digging into that now.

@EmilienM
Copy link
Contributor

/test pull-cluster-api-provider-openstack-e2e-full-test
/lgtm

I think all comments were addressed (nice work!) but I'll let Matt hold cancel.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 14, 2024
@dulek
Copy link
Contributor Author

dulek commented Mar 14, 2024

So we still wanted to add validation that when ID is not set, the filter has at least one other option set. Now I started working on Bastion to fix this, because this means we're unable to create an empty machine, but maybe it's an overkill. Technically an empty filter is still valid if you have just one image.

This commit changes `ID` and `Name` of `ImageFilter` to pointers which
should only affect go marshalling.

Other than that it adds CEL validation of the ImageFilter, so that Name
or Tags can only be set when ID is unset. Conversions are updated
accordingly to make sure we only set Name when ID is unset.

Moreover validation is added that ID has to be UUID. It's not enforced
in conversions, as non-UUID IDs would produce clusters or machines that
would not work properly.
This adds tests related to kubebuilder validations of ImageFilter.
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 14, 2024
@dulek
Copy link
Contributor Author

dulek commented Mar 14, 2024

I added the explicit +required on the ImageFilter. I guess this is good to go, I can expand the filter in the Bastion patch.

@dulek
Copy link
Contributor Author

dulek commented Mar 14, 2024

/retest

@EmilienM
Copy link
Contributor

/test pull-cluster-api-provider-openstack-e2e-full-test
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 15, 2024
@dulek
Copy link
Contributor Author

dulek commented Mar 15, 2024

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 15, 2024
@k8s-ci-robot k8s-ci-robot merged commit e7d0e19 into kubernetes-sigs:main Mar 15, 2024
10 checks passed
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants