-
Notifications
You must be signed in to change notification settings - Fork 505
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
Conversation
There was a problem hiding this 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?
Signed-off-by: Stephen Augustus <saugustus@vmware.com>
3210d48
to
8c0cec7
Compare
@justaugustus: Adding label: 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. |
48780f7
to
97c2806
Compare
Signed-off-by: Stephen Augustus <saugustus@vmware.com>
Signed-off-by: Stephen Augustus <saugustus@vmware.com>
97c2806
to
f2cc7cd
Compare
/assign @hasheddan @saschagrunert @hoegaarden @tpepper |
Thanks! I've moved that portion of the PR to #1115, which has already merged. |
There was a problem hiding this 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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
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) { |
There was a problem hiding this comment.
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>
Added these two bits:
|
pkg/release/release.go
Outdated
|
||
func GetLatestCIKubeVersion() (string, error) { | ||
logrus.Info("Retrieving Kubernetes latest build version...") | ||
return GetKubeVersion("https://dl.k8s.io/ci/latest.txt") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[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 |
What type of PR is this?
/kind feature cleanup
What this PR does / why we need it:
Signed-off-by: Stephen Augustus saugustus@vmware.com
Special notes for your reviewer:
Does this PR introduce a user-facing change?: