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

✨ Remove spaces from machine-readable comments #1868

Merged

Conversation

Adirio
Copy link
Contributor

@Adirio Adirio commented Dec 2, 2020

Description

Machine-readable comments used for markers have spaces after the comment character (// or #), they have been removed to follow common coding practices.

Closes: #1384

Comments to reviewers

131/144 files are from the testdata directory, this PR is smaller than what it looks like by the number of files changed.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 2, 2020
@camilamacedo86
Copy link
Member

camilamacedo86 commented Dec 11, 2020

Hi @Adirio,

It is not passing in the CI. Could you please check this one for we get it merged?
Shows that it is missing run make generate only. Otherwise, the changes looks, great 👍

looking for to check it passing in the CI fr we are able to merge this one.

@Adirio
Copy link
Contributor Author

Adirio commented Dec 11, 2020

I think it is a rebase what it is needed. Will try it.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 11, 2020
@Adirio Adirio force-pushed the machine-readable-markers branch 2 times, most recently from 9f8fedd to 9f9e702 Compare December 11, 2020 23:38
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 11, 2020
Copy link
Contributor

@estroz estroz left a comment

Choose a reason for hiding this comment

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

Something like this can be done for any plugin, stable/frozen or not, since machine-readable comments with spaces are backwards compatible.

@camilamacedo86
Copy link
Member

camilamacedo86 commented Dec 12, 2020

Hi @Adirio

What was your motivation to define that #1384 (this change) would be a breaking change and that should be done only for v3? If it is backwards compatible with v2 then I agree with @estroz in #1868 (review).

However, i imagine that you saw some scenario that would be affected. so, could you please clarify?

@Adirio
Copy link
Contributor Author

Adirio commented Dec 12, 2020

If we apply this to v2, projects scaffolded with v2 before applyign this change will have spaces and further update operation by kubebuilder will not be able to find the placeholders. For example the ones in mian.go to register the controllers in the manager.

@estroz
Copy link
Contributor

estroz commented Dec 12, 2020

further update operation by kubebuilder will not be able to find the placeholders

If that’s true, it sounds like a bug in controller-tools’ comment lexer. Both forms are valid marker comments so should be parsed in the same manner.

@Adirio
Copy link
Contributor Author

Adirio commented Dec 13, 2020

I mean the comments that are meant for kubebuilder itself, for example the MainUpdater inserts code fragments to register new controllers. Those fragments are inserted just before a machine-readable comment and it does use exact match.

@estroz
Copy link
Contributor

estroz commented Dec 14, 2020

What about creating a method to compare marker comments like so

func (m Marker) EqualsLine(line string) bool {
	line = strings.TrimSpace(strings.TrimPrefix(m.comment))
	return line == m.value
}

and use it here:

		line := scanner.Text()
		for marker, codeFragments := range codeFragmentsMap {
-			if strings.TrimSpace(line) == strings.TrimSpace(marker.String()) {
+			if marker.EqualsLine(line) {
				...
			}
		}

@estroz
Copy link
Contributor

estroz commented Dec 14, 2020

The above is just a suggestion btw. Your solution also works. Feel free to unhold to merge as-is.

/lgtm
/hold

@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 Dec 14, 2020
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 14, 2020
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 15, 2020
@Adirio
Copy link
Contributor Author

Adirio commented Dec 15, 2020

/unhold

@estroz I liked your suggestion, removed the hold as the lgtm label is required again

@Adirio Adirio force-pushed the machine-readable-markers branch 2 times, most recently from bd5b718 to 3b57509 Compare December 15, 2020 14:02
@Adirio Adirio closed this Dec 15, 2020
@Adirio Adirio reopened this Dec 15, 2020
@Adirio Adirio changed the title ⚠️ (go/v3-alpha) Remove spaces from machine-readable comments ✨ Remove spaces from machine-readable comments Dec 15, 2020
@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 Dec 15, 2020
@camilamacedo86
Copy link
Member

/retest

@camilamacedo86
Copy link
Member

Hi @Adirio,

it is not passing in the CI. Maybe it is missing a rebase?

@Adirio
Copy link
Contributor Author

Adirio commented Dec 15, 2020

I don't know why but seems that one of the changes in *_webhook.go files seems to be breaking the webhooks. @estroz do you know if this should be considered a parsing error from the side of controller-tools?

Edit: Nevermind, it doesn't have to do with that. Trying to debug it further.

@Adirio Adirio force-pushed the machine-readable-markers branch 3 times, most recently from 3bbd8d2 to d501fc3 Compare December 16, 2020 07:17
@Adirio
Copy link
Contributor Author

Adirio commented Dec 16, 2020

The part that is failing is this one:

// wait for the webhook server to get ready
dialer := &net.Dialer{Timeout: time.Second}
addrPort := fmt.Sprintf("%s:%d", webhookInstallOptions.LocalServingHost, webhookInstallOptions.LocalServingPort)
Eventually(func() error {
conn, err := tls.DialWithDialer(dialer, "tcp", addrPort, &tls.Config{InsecureSkipVerify: true})
if err != nil {
return err
}
conn.Close()
return nil
}).Should(Succeed())

I'm not modifying anything that should break that check.

Copy link
Contributor

@prafull01 prafull01 left a comment

Choose a reason for hiding this comment

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

I have looked into the code and the reason for this failure is following scaffolding code is not generated by kubebuilder:

err = (&Captain{}).SetupWebhookWithManager(mgr)
	Expect(err).NotTo(HaveOccurred())

Attaching the screenshot of failure and missing piece of code from scaffold code.
Screenshot from 2020-12-17 01-31-38
Screenshot from 2020-12-17 01-31-48

Copy link
Contributor

@estroz estroz left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Adirio, estroz, prafull01

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 Dec 17, 2020
@k8s-ci-robot k8s-ci-robot merged commit 7245d41 into kubernetes-sigs:master Dec 17, 2020
@Adirio Adirio deleted the machine-readable-markers branch December 17, 2020 06:16
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/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.

[V3] Marker pattern
5 participants