-
Notifications
You must be signed in to change notification settings - Fork 114
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
Conversation
@@ -0,0 +1,40 @@ | |||
/* | |||
Copyright 2020 The Kubernetes Authors. |
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.
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) |
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.
Just checking, the Make file exists at Root?
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.
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.
it's actually a symlink, but yes 🙃
the real file is in ./build/root/Makefile
pkg/build/release_push_build.go
Outdated
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) |
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.
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) |
pkg/build/release_push_build.go
Outdated
return fmt.Errorf("invalid stage location: %v. Use gs://bucket/ci/optional-suffix", rpb.StageLocation) | ||
} | ||
|
||
// force indicate staging of extra gce configuration files |
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.
// force indicate staging of extra gce configuration files | |
// Force indicate staging of extra gce configuration files |
} | ||
|
||
var _ build.Builder = &BuildOptions{} |
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.
Curious what the propose of this pattern is? Just type enforcement?
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.
yes, this essentially is a compile time type assertion
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.
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).
184de2a
to
9f67607
Compare
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.
tiny suggestions otherwise LGTM
kubetest2-gce/deployer/build.go
Outdated
exec.InheritOutput(cmd) | ||
cmd.SetDir(d.RepoRoot) | ||
err := cmd.Run() | ||
klog.V(2).Info("starting the legacy k/k build") |
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.
klog.V(2).Info("starting the legacy k/k build") | |
klog.V(2).Info("starting the legacy kubernetes/kubernetes build") |
kubetest2-gce/deployer/build.go
Outdated
version += "+" + d.commonOptions.RunID() | ||
if d.BuildOptions.CommonBuildOptions.StageLocation != "" { |
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.
nit
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
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.
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 != "" { |
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.
if d.BuildOptions.CommonBuildOptions.StageLocation != "" { | |
// stage build if requested | |
if d.BuildOptions.CommonBuildOptions.StageLocation != "" { |
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.
done, I think?
) | ||
|
||
type Options struct { | ||
Strategy string `flag:"~strategy" desc:"Determines the build strategy to use either make or bazel."` |
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.
nit: seems like this could be its own type, but won't block
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.
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.
most flag libraries allow you to use the real type instead of a string /shrug
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 upside to doing so is that you can then pass around this struct as the real parsed values
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 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
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 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 != "" { |
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.
done, I think?
} | ||
|
||
var _ build.Builder = &BuildOptions{} |
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.
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 |
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.
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.
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.
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."` |
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.
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."` |
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 upside to doing so is that you can then pass around this struct as the real parsed values
ping |
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.
/approve
/lgtm
@@ -39,9 +40,20 @@ var ( | |||
// $1 == prefix | |||
// $2 == suffix | |||
buildPrefix = regexp.MustCompile(`^(\d\.\d+\.\d+)([+-].*)?$`) | |||
|
|||
defaultImageTag = "gke.gcr.io" |
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.
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 { |
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.
ditto for imageRegistry
instead
) | ||
|
||
type Options struct { | ||
Strategy string `flag:"~strategy" desc:"Determines the build strategy to use either make or bazel."` |
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 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.
[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 |
/test gce-build-up-down
Neat. |
/retest |
return err | ||
} | ||
// append the kubetest2 run id | ||
version += "+" + d.commonOptions.RunID() |
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.
if version already contains "+", this should append "+" + d.commonOptions.RunID()
, otherwise we end up with invalid docker tags
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 the GCE deployer not GKE, we might want similar changes here too though. yet to test this out for upstream jobs.
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 double-plus version results in an invalid docker tag regardless of deployer
Also extend make build support for both and start staging with the new krel API.
/cc @MushuEE @BenTheElder @spiffxp