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

[krel] gcbmgr: Dynamically retrieve build version from CI markers #1114

Merged
merged 5 commits into from
Feb 20, 2020

Conversation

justaugustus
Copy link
Member

@justaugustus justaugustus commented Feb 19, 2020

What type of PR is this?
/kind feature cleanup

What this PR does / why we need it:

  • pkg/release: Add getters for tools GitHub url, org, repo, and branch
  • pkg/release: Refactor version marker getters
  • [krel] gcbmgr: Dynamically retrieve build version from CI markers
  • pkg/util: Check HTTP status code before return in GetURLResponse()
  • pkg/release: Allow version getters to return [non-]SemVer-compliant

Signed-off-by: Stephen Augustus saugustus@vmware.com

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

[krel] gcbmgr: Dynamically retrieve build version from CI markers

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-priority size/M Denotes a PR that changes 30-99 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Feb 19, 2020
@k8s-ci-robot k8s-ci-robot added area/release-eng Issues or PRs related to the Release Engineering subproject sig/release Categorizes an issue or PR as relevant to SIG Release. labels Feb 19, 2020
Copy link
Contributor

@hasheddan hasheddan left a comment

Choose a reason for hiding this comment

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

@justaugustus this is a nice improvement here 👍 could we add some comments to each of the exported funcs as well?

@justaugustus justaugustus changed the title [WIP] pkg/git: Add getters for GitHub URLs [WIP] [krel] gcbmgr: Add additional checks Feb 19, 2020
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 19, 2020
Signed-off-by: Stephen Augustus <saugustus@vmware.com>
@k8s-ci-robot
Copy link
Contributor

@justaugustus: Adding label: do-not-merge/blocked-paths because PR changes a protected file.

Reasons for blocking this PR:

[Changes to certain release tools can affect our ability to test, build, and release Kubernetes. This PR must be explicitly approved by SIG Release repo admins.]

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 do-not-merge/blocked-paths Indicates that a PR should not merge because it touches files in blocked paths. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 19, 2020
@justaugustus justaugustus force-pushed the krel-gcbmgr branch 2 times, most recently from 48780f7 to 97c2806 Compare February 20, 2020 00:12
Signed-off-by: Stephen Augustus <saugustus@vmware.com>
Signed-off-by: Stephen Augustus <saugustus@vmware.com>
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Feb 20, 2020
@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Feb 20, 2020
@justaugustus justaugustus changed the title [WIP] [krel] gcbmgr: Add additional checks [krel] gcbmgr: Dynamically retrieve build version from CI markers Feb 20, 2020
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 20, 2020
@justaugustus
Copy link
Member Author

/assign @hasheddan @saschagrunert @hoegaarden @tpepper
/priority important-soon

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority labels Feb 20, 2020
@justaugustus
Copy link
Member Author

@justaugustus this is a nice improvement here could we add some comments to each of the exported funcs as well?

Thanks! I've moved that portion of the PR to #1115, which has already merged.

Copy link
Contributor

@hasheddan hasheddan left a comment

Choose a reason for hiding this comment

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

This is looking good @justaugustus :) One small change proposed that I would like to get your thoughts on 👍

// GetToolRepo checks if the 'TOOL_REPO' environment variable is set.
// If 'TOOL_REPO' is non-empty, it returns the value. Otherwise, it returns DefaultToolRepo.
func GetToolRepo() string {
toolRepo := os.Getenv("TOOL_REPO")
Copy link
Contributor

Choose a reason for hiding this comment

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

I generally try to steer away from using env variables if possible. However, if we do want to use them, I would prefer for it to be exposed at the command level and then either checked, or passed as a parameter to a library function like this. The latter case could look something like this in gcbmgr or any other command:

toolRepo := release.GetToolRepo(os.Getenv("TOOL_REPO"))

How would you feel about that?

Choose a reason for hiding this comment

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

Big +1 from me about steering awat from using env vars directly in functions. The good advice I read some time ago is to use the env vars just in the main function and then pass them around as function parameters.

Copy link
Member Author

@justaugustus justaugustus Feb 20, 2020

Choose a reason for hiding this comment

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

@hasheddan -- I would prefer to keep this one as-is.
The idea being that we want to make it a little difficult to run the tool in a non-k/release@master manner.

If you used some flags, it's possible maybe you copy/pasted something.
If you set three environment variables, there's some intent behind overriding the default tools org, repo, and branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

I definitely see your point, but I could also see someone copy pasting setting env vars just like the command with flags. In addition, a flag must always be set explicitly on each command run, while an env var could be lurking from a previous operation in the same session. All of that being said, I think this is mostly a stylistic preference (rather than a right / wrong thing) so I am comfortable moving forward if you feel strongly :)

Choose a reason for hiding this comment

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

The case is, it's not about making it harder for people to not use the flags itself, but it's much easier to maintain the thing in the future if logic related to env-vars is stored in the main/root place. These are just good practices and makes code more futureproof.

Copy link
Member Author

Choose a reason for hiding this comment

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

@bartsmykla -- That's essentially what's being done here.
By putting the logic for these env vars in the release package, instead of the command, I'm trying to ensure that anyone who needs to use them has a consistent experience.

As a note, this is one of the first few passes on this tool rewrite.
In this first phase, I'm primarily concerned w/ replicating the logic of the existing tool, which uses env vars:

release/gcbmgr

Lines 152 to 154 in c13fa28

readonly TOOL_ORG="${TOOL_ORG:-kubernetes}"
readonly TOOL_REPO="${TOOL_REPO:-release}"
readonly TOOL_BRANCH="${TOOL_BRANCH:-master}"

There are some pieces that no longer make sense to carry over, but this isn't one of them just yet.

// BuiltWithBazel determines whether the most recent release was built with Bazel.
func BuiltWithBazel(path, releaseKind string) (bool, error) {
func BuiltWithBazel(workDir, releaseKind string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for these updates, much better param name :)

Signed-off-by: Stephen Augustus <saugustus@vmware.com>
Signed-off-by: Stephen Augustus <saugustus@vmware.com>
@justaugustus
Copy link
Member Author

Added these two bits:

  • pkg/util: Check HTTP status code before return in GetURLResponse()
  • pkg/release: Allow version getters to return [non-]SemVer-compliant


func GetLatestCIKubeVersion() (string, error) {
logrus.Info("Retrieving Kubernetes latest build version...")
return GetKubeVersion("https://dl.k8s.io/ci/latest.txt")

Choose a reason for hiding this comment

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

We have three different urls here. I think it will be better to put them as const at the beginning of the file. It will be more future proof if the links will be used somewhere else, and also more consise.

versionMarkerFile := fmt.Sprintf("%s.txt", versionMarker)
logrus.Infof("Version marker file: %s", versionMarkerFile)

u, parseErr := url.Parse("https://dl.k8s.io/ci")

Choose a reason for hiding this comment

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

The same comment with putting the url at the top of the file applies here too.

Copy link
Member Author

Choose a reason for hiding this comment

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

@bartsmykla -- Hehe. I was actually planning on doing that for a follow-up.
I want to think a little more about version markers before parameterizing them.

// GetToolRepo checks if the 'TOOL_REPO' environment variable is set.
// If 'TOOL_REPO' is non-empty, it returns the value. Otherwise, it returns DefaultToolRepo.
func GetToolRepo() string {
toolRepo := os.Getenv("TOOL_REPO")

Choose a reason for hiding this comment

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

Big +1 from me about steering awat from using env vars directly in functions. The good advice I read some time ago is to use the env vars just in the main function and then pass them around as function parameters.

@justaugustus justaugustus removed the do-not-merge/blocked-paths Indicates that a PR should not merge because it touches files in blocked paths. label Feb 20, 2020
Copy link
Contributor

@hasheddan hasheddan 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 20, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hasheddan, justaugustus

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 merged commit 11f0f14 into kubernetes:master Feb 20, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.18 milestone Feb 20, 2020
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. area/release-eng Issues or PRs related to the Release Engineering subproject cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/release Categorizes an issue or PR as relevant to SIG Release. 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.

7 participants