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

Unify common build functionality between gce and gke #80

Merged
merged 8 commits into from
Jan 29, 2021

Conversation

amwat
Copy link
Contributor

@amwat amwat commented Jan 13, 2021

Also extend make build support for both and start staging with the new krel API.

/cc @MushuEE @BenTheElder @spiffxp

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 13, 2021
@@ -0,0 +1,40 @@
/*
Copyright 2020 The Kubernetes Authors.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Copyright 2020 The Kubernetes Authors.
Copyright 2021 The Kubernetes Authors.

if err != nil {
return "", fmt.Errorf("failed to get version: %v", err)
}
cmd := exec.Command("make", "-C", src, target)
cmd := exec.Command("make", "-C", m.RepoRoot, target)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking, the Make file exists at Root?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

it's actually a symlink, but yes 🙃
the real file is in ./build/root/Makefile

if mat == nil || len(mat) < 4 {
return fmt.Errorf("invalid stage location: %v. Use gs://bucket/ci/optional-suffix", rpb.Location)
return fmt.Errorf("invalid stage location: %v. Use gs://bucket/ci/optional-suffix", rpb.StageLocation)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("invalid stage location: %v. Use gs://bucket/ci/optional-suffix", rpb.StageLocation)
return fmt.Errorf("invalid stage location: %v. Use form gs://<bucket>/<ci>/<optional-suffix>", rpb.StageLocation)

return fmt.Errorf("invalid stage location: %v. Use gs://bucket/ci/optional-suffix", rpb.StageLocation)
}

// force indicate staging of extra gce configuration files
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// force indicate staging of extra gce configuration files
// Force indicate staging of extra gce configuration files

}

var _ build.Builder = &BuildOptions{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious what the propose of this pattern is? Just type enforcement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, this essentially is a compile time type assertion

Copy link
Member

Choose a reason for hiding this comment

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

adding: this is a common enough pattern in go, I'm not sure if it's strictly compile time or not though.

technically I bet at minimum it also ensures that the package defining the interface is valid to import even if it otherwise wouldn't be, and importing a package can have side effects (namely packages have init() / globals in a binary IFF they are imported somewhere).

@amwat amwat force-pushed the gce_build branch 2 times, most recently from 184de2a to 9f67607 Compare January 14, 2021 03:27
Copy link
Member

@spiffxp spiffxp left a comment

Choose a reason for hiding this comment

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

tiny suggestions otherwise LGTM

exec.InheritOutput(cmd)
cmd.SetDir(d.RepoRoot)
err := cmd.Run()
klog.V(2).Info("starting the legacy k/k build")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
klog.V(2).Info("starting the legacy k/k build")
klog.V(2).Info("starting the legacy kubernetes/kubernetes build")

Comment on lines 43 to 45
version += "+" + d.commonOptions.RunID()
if d.BuildOptions.CommonBuildOptions.StageLocation != "" {
Copy link
Member

Choose a reason for hiding this comment

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

nit

Suggested change
version += "+" + d.commonOptions.RunID()
if d.BuildOptions.CommonBuildOptions.StageLocation != "" {
version += "+" + d.commonOptions.RunID()
// stage build if requested
if d.BuildOptions.CommonBuildOptions.StageLocation != "" {

I'm a little curious why stage needs to be done here, seems like a side effect unrelated to building, but won't block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah stage is optional here for gce, it's not needed if running build and up together. but needed if we want to build and then up a cluster later.

@@ -55,7 +67,7 @@ func (d *deployer) Build() error {
}
// append the kubetest2 run id
version += "+" + d.commonOptions.RunID()
if d.BuildOptions.StageLocation != "" {
if d.BuildOptions.CommonBuildOptions.StageLocation != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if d.BuildOptions.CommonBuildOptions.StageLocation != "" {
// stage build if requested
if d.BuildOptions.CommonBuildOptions.StageLocation != "" {

Copy link
Member

Choose a reason for hiding this comment

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

done, I think?

)

type Options struct {
Strategy string `flag:"~strategy" desc:"Determines the build strategy to use either make or bazel."`
Copy link
Member

Choose a reason for hiding this comment

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

nit: seems like this could be its own type, but won't block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are separate types:

type MakeBuilder struct {
RepoRoot string
}

type Bazel struct {
RepoRoot string
StageLocation string
ImageLocation string
}

the string here is to expose the available strategies as a flag.

Copy link
Member

Choose a reason for hiding this comment

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

most flag libraries allow you to use the real type instead of a string /shrug

Copy link
Member

Choose a reason for hiding this comment

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

the upside to doing so is that you can then pass around this struct as the real parsed values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we are using the real type which is BuildOptions and has the actual options like RepoRoot , but at some point you need to specify whether it's bazel or make :)

exposing the individual implementation directly would mean weirdly exposing individual flags like --make-repo-root and --bazel-repo-root which looks worse /shrug

Copy link
Member

Choose a reason for hiding this comment

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

I guess I could have been clearer and suggested a string-as-enum approach (type BuildStrategy string etc.) but as-is is fine, like I said, won't block.

@@ -55,7 +67,7 @@ func (d *deployer) Build() error {
}
// append the kubetest2 run id
version += "+" + d.commonOptions.RunID()
if d.BuildOptions.StageLocation != "" {
if d.BuildOptions.CommonBuildOptions.StageLocation != "" {
Copy link
Member

Choose a reason for hiding this comment

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

done, I think?

}

var _ build.Builder = &BuildOptions{}
Copy link
Member

Choose a reason for hiding this comment

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

adding: this is a common enough pattern in go, I'm not sure if it's strictly compile time or not though.

technically I bet at minimum it also ensures that the package defining the interface is valid to import even if it otherwise wouldn't be, and importing a package can have side effects (namely packages have init() / globals in a binary IFF they are imported somewhere).

func (bo *BuildOptions) Validate() error {
return bo.implementationFromStrategy()
// force extra GCP files to be staged
Copy link
Member

Choose a reason for hiding this comment

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

nit: if we're always going to force this, IMHO this should be in Build() or really anywhere other than here, Validate should normally be only reading data, not writing; this fails the principle of least surprise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. also added a check to ensure stage is used with build and up since that's required for gke.

)

type Options struct {
Strategy string `flag:"~strategy" desc:"Determines the build strategy to use either make or bazel."`
Copy link
Member

Choose a reason for hiding this comment

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

most flag libraries allow you to use the real type instead of a string /shrug

)

type Options struct {
Strategy string `flag:"~strategy" desc:"Determines the build strategy to use either make or bazel."`
Copy link
Member

Choose a reason for hiding this comment

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

the upside to doing so is that you can then pass around this struct as the real parsed values

@amwat
Copy link
Contributor Author

amwat commented Jan 28, 2021

ping

Copy link
Member

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

@@ -39,9 +40,20 @@ var (
// $1 == prefix
// $2 == suffix
buildPrefix = regexp.MustCompile(`^(\d\.\d+\.\d+)([+-].*)?$`)

defaultImageTag = "gke.gcr.io"
Copy link
Member

Choose a reason for hiding this comment

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

nit (can be done as followup), seems like defaultImageRegistry would be a better name

}

klog.V(2).Infof("setting KUBE_DOCKER_REGISTRY to %s for tagging images", imageTag)
if err := os.Setenv("KUBE_DOCKER_REGISTRY", imageTag); 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.

ditto for imageRegistry instead

)

type Options struct {
Strategy string `flag:"~strategy" desc:"Determines the build strategy to use either make or bazel."`
Copy link
Member

Choose a reason for hiding this comment

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

I guess I could have been clearer and suggested a string-as-enum approach (type BuildStrategy string etc.) but as-is is fine, like I said, won't block.

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: amwat, spiffxp

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

@spiffxp
Copy link
Member

spiffxp commented Jan 29, 2021

/test gce-build-up-down

 - The zone 'projects/k8s-e2e-gce-alpha1-5/zones/us-central1-b' does not have enough resources available to fulfill the request.  Try a different zone, or try again later.

Neat.

@spiffxp
Copy link
Member

spiffxp commented Jan 29, 2021

/retest

@k8s-ci-robot k8s-ci-robot merged commit da7b071 into kubernetes-sigs:master Jan 29, 2021
@amwat amwat deleted the gce_build branch January 29, 2021 19:12
return err
}
// append the kubetest2 run id
version += "+" + d.commonOptions.RunID()
Copy link
Contributor

Choose a reason for hiding this comment

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

if version already contains "+", this should append "+" + d.commonOptions.RunID(), otherwise we end up with invalid docker tags

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 the GCE deployer not GKE, we might want similar changes here too though. yet to test this out for upstream jobs.

Copy link
Contributor

Choose a reason for hiding this comment

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

the double-plus version results in an invalid docker tag regardless of deployer

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/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