-
Notifications
You must be signed in to change notification settings - Fork 502
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
push build: initial migration to krel #941
Conversation
Signed-off-by: hasheddan <[email protected]>
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 love it! I just have a couple of comments and nits 👇
@@ -104,7 +108,7 @@ func FakeGOPATH(srcDir string) (string, error) { | |||
log.Printf("GOPATH: %s", os.Getenv("GOPATH")) | |||
|
|||
gitRoot := fmt.Sprintf("%s/src/k8s.io", baseDir) | |||
if err := os.MkdirAll(gitRoot, 0o755); err != nil { | |||
if err := os.MkdirAll(gitRoot, os.FileMode(int(0755))); err != nil { |
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.
Hm, what is the benefit of doing it like this? 🙃
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 was getting a compiler error on my local, but I think my config was just wrong. I'll change back :)
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.
Okay, maybe you have no go 1.13 on your local machine?
@@ -122,3 +126,47 @@ func FakeGOPATH(srcDir string) (string, error) { | |||
|
|||
return gitRoot, nil | |||
} | |||
|
|||
// UntarAndRead opens a tarball and reads contents of a file inside. | |||
func UntarAndRead(tarPath, filePath string) (string, 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.
Do we wanna write some tests for this function and MoreRecent
?
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.
Definitely! In my check list above
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.
nits:
- Do we maybe want to return the
io.Reader
instead of a string? That way it- would be more ideomatic
- a caller could wrap a LimitedReader around it or do whatever
- Is a name like
ReadFileFromGzippedTar(...)
a "truer" name. Would it be a better name? Not really ... 🤔#namingThings
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.
Agree to both of these points :) This structure was mostly a result of trying to mimic the exact behavior of
Line 131 in 471139d
LATEST=$(tar -O -xzf $KUBE_ROOT/_output/release-tars/$FLAGS_release_kind.tar.gz $FLAGS_release_kind/version) |
|
||
// BuiltWithBazel determines whether the most recent release was built with Bazel. | ||
func BuiltWithBazel(path string, releaseKind string) (bool, error) { | ||
bazelBuild := path + bazelBuildPath + releaseKind + tarballExtension |
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 suggest using filepath.Join
for concatenating paths.
} | ||
|
||
if isBazel { | ||
log.Println("Using Bazel build version.") |
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.
Its a nitty nit, but we could remove the dot at the end of a log to have a uniform logging layout. :)
} | ||
|
||
// IsValidReleaseBuild checks if build version is valid for release. | ||
func IsValidReleaseBuild(build 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.
I'd suggest in returning either a bool
or an error
here to make its usage simpler.
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 was initially thinking that as well, but I didn't know if there would be a use case for this function in the future where it might be valid to know if there was not a match or if the comparison failed altogether. If we don't think this is necessary, I think a good fix would be to use regexp.MustCompile
in init()
then just returning MatchString()
here!
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.
Hm I see your point, so I guess we can also keep the current approach. :)
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.
Thanks for the review @saschagrunert! Any thoughts on the bazel question in the PR body?
You're welcome. No, I'm definitely not sure if we need the bazel build in first place. 🤷♂️ |
@saschagrunert @hasheddan -- We'll need to support bazel and non-bazel builds. -- I'll come around for a review sweep on this once you take care of Sascha's initial feedback. |
@justaugustus @saschagrunert definitely agree that we want to support both bazel and non-bazel builds (both are in this current iteration), but do we need to use bazel to actually push the build? References:
|
@hasheddan -- Mentioned on the SIG Release call this week, but also dropping here... (Sending this for a retest to see if our newly-enabled linters pick up something.) |
/retest |
(Apparently the |
/priority important-longterm |
// Check if latest build uses bazel | ||
dir, err := os.Getwd() | ||
if err != nil { | ||
log.Fatal(err) |
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.
Should we let the errors bubble up instead of exiting via log.Fatal
here (and at the other places)?
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.
Do you mean that we should keep executing? I think it depends on the error. This one I think we should exit immediately because we will be unable to reliably push a build if we cannot get the working dir.
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.
What I meant is:
- return an error here instead of
log.Fatal(...)
- this error should bubble up all the way to be either handled or results in an
os.Exit(...)
or such somewhere centrally.
I would not expect a function that returns an error also to shut down the whole process. If nothing else, that is IMHO not really intuitive and hard stupid to test.
|
||
if h.Name == filePath { | ||
file, err := ioutil.ReadAll(tr) | ||
return strings.TrimSuffix(string(file), "\n"), err |
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.
Is this (trimming of a newline) a general thing we need to do when extracting a file from a tarball, or is this specific to our case (reading that version file)?
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 more of a specific use-case thing, which, if this function is made more general as suggested above, should probably be deferred to the user of the function (i.e. the push build cmd). Thanks for pointing this out!
@@ -122,3 +126,47 @@ func FakeGOPATH(srcDir string) (string, error) { | |||
|
|||
return gitRoot, nil | |||
} | |||
|
|||
// UntarAndRead opens a tarball and reads contents of a file inside. | |||
func UntarAndRead(tarPath, filePath string) (string, 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.
nits:
- Do we maybe want to return the
io.Reader
instead of a string? That way it- would be more ideomatic
- a caller could wrap a LimitedReader around it or do whatever
- Is a name like
ReadFileFromGzippedTar(...)
a "truer" name. Would it be a better name? Not really ... 🤔#namingThings
Let's get this in. /lgtm |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cpanato, 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 |
Awesome, it is great to see that this is merged! |
@justaugustus I'll get the follow-up PR in ASAP, thanks! :) |
Initial steps to move
push-build.sh
tokrel push
. Steps to still be completed include:bazel
to push the build? If not then we can likely do it in a cleaner fashion using gcloud sdk rather than executing bazel usingos.Exec
.)Please feel free to review and give any immediate thoughts or feedback!
/cc @saschagrunert @justaugustus