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

push build: initial migration to krel #941

Merged
merged 1 commit into from
Dec 11, 2019

Conversation

hasheddan
Copy link
Contributor

Initial steps to move push-build.sh to krel push. Steps to still be completed include:

  • Implement remainder of push logic (do we feel the need to use bazel to push the build? If not then we can likely do it in a cleaner fashion using gcloud sdk rather than executing bazel using os.Exec.)
  • Add unit tests for new pkg functions

Please feel free to review and give any immediate thoughts or feedback!

/cc @saschagrunert @justaugustus

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. 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 Nov 25, 2019
Copy link
Member

@saschagrunert saschagrunert left a 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 {
Copy link
Member

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? 🙃

Copy link
Contributor Author

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 :)

Copy link
Member

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) {
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor Author

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

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
Copy link
Member

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.")
Copy link
Member

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) {
Copy link
Member

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.

Copy link
Contributor Author

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!

Copy link
Member

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. :)

Copy link
Contributor Author

@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.

Thanks for the review @saschagrunert! Any thoughts on the bazel question in the PR body?

@saschagrunert
Copy link
Member

saschagrunert commented Nov 27, 2019

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. 🤷‍♂️

@justaugustus
Copy link
Member

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.
Can you open up an issue to discuss that?

--

I'll come around for a review sweep on this once you take care of Sascha's initial feedback.

@hasheddan
Copy link
Contributor Author

@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:

@justaugustus
Copy link
Member

@hasheddan -- Mentioned on the SIG Release call this week, but also dropping here...
Yes, I think it's fine for us to proceed with a non-bazel push for both scenarios.

(Sending this for a retest to see if our newly-enabled linters pick up something.)
/retest

@justaugustus justaugustus added this to the v1.18 milestone Dec 4, 2019
@justaugustus
Copy link
Member

/retest

@justaugustus
Copy link
Member

(Apparently the /retest behavior may have changed?)
/test all

@justaugustus
Copy link
Member

/priority important-longterm
/kind feature

@k8s-ci-robot k8s-ci-robot added priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. kind/feature Categorizes issue or PR as related to a new feature. labels Dec 4, 2019
// Check if latest build uses bazel
dir, err := os.Getwd()
if err != nil {
log.Fatal(err)
Copy link
Contributor

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)?

Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Contributor

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)?

Copy link
Contributor Author

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) {
Copy link
Contributor

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

@justaugustus
Copy link
Member

Let's get this in.
@hasheddan -- please address PR feedback in a follow-up.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 11, 2019
@cpanato
Copy link
Member

cpanato commented Dec 11, 2019

/lgtm

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit e7cfb62 into kubernetes:master Dec 11, 2019
@saschagrunert
Copy link
Member

Awesome, it is great to see that this is merged!

@hasheddan
Copy link
Contributor Author

@justaugustus I'll get the follow-up PR in ASAP, thanks! :)

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/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-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. sig/release Categorizes an issue or PR as relevant to SIG Release. 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