Skip to content

Conversation

@estroz
Copy link
Contributor

@estroz estroz commented Feb 21, 2020

This PR implements plugin version format enforcement. See the plugins design doc and #1290 for more details.

Changes:

  • pkg/cli: validate cli struct's fields
  • pkg/plugin: validation for plugin version strings
  • pkg/internal/validation: project-wide validation logic; move pkg/model/resource/validation.go functions here

/cc @DirectXMan12 @mengqiy @hasbro17 @Adirio

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

@estroz: GitHub didn't allow me to request PR reviews from the following users: Adirio.

Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

This PR implements plugin version format enforcement. See the plugins design doc and #1290 for more details.

Changes:

  • pkg/cli: validate cli struct's fields
  • pkg/plugin: validation for plugin version strings
  • pkg/model/validation: project-wide validation logic; move pkg/model/resource/validation.go functions here

/cc @DirectXMan12 @mengqiy @hasbro17 @Adirio

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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 21, 2020
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Hi @estroz,

Great 👍 . Just an optional nit and I think would be nice add some tests.
Otherwise, it shows

/lgtm

For me.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 21, 2020
@estroz estroz force-pushed the feature/plugins-enforce-version-format branch from bcb985d to d7aaa06 Compare February 21, 2020 18:59
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 21, 2020
@estroz estroz force-pushed the feature/plugins-enforce-version-format branch from d7aaa06 to ffa2875 Compare February 21, 2020 18:59
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/lgtm when pass in the lint.

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

@Adirio Adirio 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
Contributor

@Adirio Adirio left a comment

Choose a reason for hiding this comment

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

LGTM

@estroz estroz force-pushed the feature/plugins-enforce-version-format branch from ffa2875 to 9485888 Compare February 22, 2020 21:29
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 22, 2020
@camilamacedo86
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Feb 23, 2020
@estroz estroz force-pushed the feature/plugins-enforce-version-format branch from 9485888 to 5215a49 Compare February 25, 2020 18:49
@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Feb 25, 2020
dns1035LabelFmt string = "[a-z]([-a-z0-9]*[a-z0-9])?"
)

type dnsValidationConfig struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Adirio @camilamacedo86 refactored these for convenience after rebasing onto the feature branch, PTAL.

Copy link
Contributor

@Adirio Adirio Feb 26, 2020

Choose a reason for hiding this comment

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

I do like the refactor you did, avoiding code duplications through the use of the dnsValidationConfig struct and its check method. A couple of considerations:

  • When I read IsDNS1XXXLabel I instantly imagine a func (string) bool signature. As the different errors need to be differentiate, we can not change the function signature to that one, so what about changing the name? Maybe around MustBe... or ConformsTo.... I guess we could check how the standard library
  • Returning a []string containing the errors doesn't seem very idiomatic in Go. Maybe we should just return an error and have the user solve the problem in two steps in case he encounters two errors, as the second one will not be reported until the first one is solved.
  • Would it make sense to group functions for the same specification? Something in the line of validation.DNS1XXX.ConformsToLabel(myString). You would have either to export the struct instance or an interface to it:
type DNSValidator interface {
	ConformsToLabel(string) error
	ConformsToSubdomain(string) error
}

var (
	DNS1023 DNSValidator = dns1023Config
	DNS1135 DNSValidator = dns1135Config
)

They can slo be left for further PRs if you prefer, they are just ideas.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The naming and return values could use some work. Doing this in a follow-up sounds good to me.

pkg/plugin: validation for plugin version strings

pkg/internal/validation: project-wide validation logic; move
pkg/model/resource/validation.go functions here
@estroz estroz force-pushed the feature/plugins-enforce-version-format branch from 5215a49 to b3d7e23 Compare February 26, 2020 00:20

var dns1123LabelConfig = dnsValidationConfig{
format: dns1123LabelFmt,
maxLen: 56, // = 63 - len("-system")
Copy link
Contributor

@Adirio Adirio Feb 26, 2020

Choose a reason for hiding this comment

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

Non-blocking: I think the validation package should not know about the "-system" prefix, the method should be called with that already prefixed and the maxLen field should be left to 63.

Copy link
Member

@camilamacedo86 camilamacedo86 Feb 26, 2020

Choose a reason for hiding this comment

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

Just to clarifies: The project name will be used as part of the namespace added in the files.
So, it will be <projectname-system>. In this way, when we scaffold the project we cannot allow a projectName with more than 56 characters. However, I agree that how it will be implemented as a hall for improvements like you described.

However, it may not part of the context of this PR as well.

@DirectXMan12
Copy link
Contributor

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DirectXMan12, estroz

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 Feb 26, 2020
@Adirio
Copy link
Contributor

Adirio commented Feb 26, 2020

An ok-to-test should be applied for prow tests, right?

@mengqiy
Copy link
Member

mengqiy commented Feb 27, 2020

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Feb 27, 2020
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 27, 2020
@k8s-ci-robot k8s-ci-robot merged commit c1f48d0 into kubernetes-sigs:feature/plugins-part-2-electric-boogaloo Feb 27, 2020
@estroz estroz deleted the feature/plugins-enforce-version-format branch February 27, 2020 17:59
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants