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

Add validation for ClusterRepo #306

Open
wants to merge 3 commits into
base: release/v0.4
Choose a base branch
from

Conversation

rohitsakala
Copy link
Member

@rohitsakala rohitsakala commented Oct 27, 2023

Github Issue - https://github.com/rancherlabs/rancher-security/issues/1258

Add validation and mutation for ClusterRepo

New validations:

Both GitRepo and URl cannot exist simultaneously

Testing

Added unit tests

@rohitsakala rohitsakala requested a review from a team October 27, 2023 00:41
@rohitsakala rohitsakala changed the title Release/v0.4 Add validation for ClusterRepo Oct 27, 2023
pjbgf
pjbgf previously approved these changes Nov 1, 2023
Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

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

Small nit, otherwise LGTM.

return admission.ResponseAllowed(), nil
}

func (a *admitter) validateFields(newClusterrepo *catalogv1.ClusterRepo) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit

Suggested change
func (a *admitter) validateFields(newClusterrepo *catalogv1.ClusterRepo) error {
func (a *admitter) validateFields(repo *catalogv1.ClusterRepo) error {

Copy link
Member Author

@rohitsakala rohitsakala Nov 3, 2023

Choose a reason for hiding this comment

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

why should I change it from newClusterRepo to repo? The resource name is ClusterRepo not just repo. Also,the new signifies it is the latest one.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's up to you, hence I marked it as a nit. At a minimum, you might want to make the casing look better, so newClusterRepo instead of newClusterrepo.
But you sort of repeat this composite name after the type name, which reads strangely. And it doesn't matter whether the repo is the latest one, you simply validate its fields. But it's all up to you.

pkg/server/handlers.go Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants