-
Notifications
You must be signed in to change notification settings - Fork 4k
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
VPA: Create a build and deploy locally script #7654
base: master
Are you sure you want to change the base?
VPA: Create a build and deploy locally script #7654
Conversation
This is for easier setup of local environments to test PRs and the like. Some notes: 1. I thought it was useful to display the git commit in the version number, for debugging purposes 2. The `LD_FLAGS=-s` env-var that used to be set doesn't actually do anything, so I've moved it to the correct location 3. Most of this re-uses existing scripts 4. It doesn't handle setup of the Kubernetes cluster or teardown of the VPA
// gitCommit is the commit used to build the VPA binaries, if available. | ||
// It is injected at build time. | ||
var gitCommit = "" | ||
|
||
// VerticalPodAutoscalerVersion is the version of VPA. | ||
const VerticalPodAutoscalerVersion = "1.2.0" | ||
const versionCore = "1.2.0" | ||
|
||
func VerticalPodAutoscalerVersion() string { | ||
v := versionCore | ||
if gitCommit != "" { | ||
// NOTE: use 14 character short hash, like Kubernetes | ||
v += "+" + truncate(gitCommit, 14) | ||
} | ||
|
||
return v | ||
} | ||
|
||
func truncate(s string, maxLen int) string { | ||
if len(s) < maxLen { | ||
return s | ||
} | ||
return s[:maxLen] | ||
} |
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 of this is copied from kind: https://github.com/kubernetes-sigs/kind/blob/1c5a56b30145d98a61c0538975ca0894ad65e0d0/pkg/cmd/kind/version/version.go#L42
Ideally I'd like to copy what Kubernetes does, but it's a larger project with a more complicated build process that I'm unfamiliar with
|
||
RUN CGO_ENABLED=0 LD_FLAGS=-s GOARCH=$TARGETARCH GOOS=$TARGETOS go build -C pkg/admission-controller -o admission-controller-$TARGETARCH | ||
RUN CGO_ENABLED=0 GOARCH=$TARGETARCH GOOS=$TARGETOS go build -C pkg/admission-controller -ldflags="${BUILD_LD_FLAGS}" -o admission-controller-$TARGETARCH |
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 don't think that LD_FLAGS=-s
ever worked:
$ docker create --platform linux/amd64 --name vpa-recommender registry.k8s.io/autoscaling/vpa-recommender:1.2.1
999058e6c14330101bf0ce4e916f5dedbc4d1005d6ff9643033db0289624a7ee
$ docker cp vpa-recommender:/recommender .
Successfully copied 58.2MB to /Users/Adrian/.
$ file recommender
recommender: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=1NTySJ_TLdHBpDxDiF3X/gpLdixJiYC-YAHAH54Dt/1soeNlTu_Tj_uuiTrLyP/hqX1KbQPpE4_hW1xIaiQ, with debug_info, not stripped
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.
Before:
$ GOOS=linux go build -C pkg/admission-controller -o admission-controller-not-stripped
$ file pkg/admission-controller/admission-controller-not-stripped
pkg/admission-controller/admission-controller-not-stripped: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, Go BuildID=FdIwuV800tRp_DwpAJve/rSttx_oRFM1ycMHfuEdQ/-anDCNZimL-FExp30NhX/EBATf_tSCu-ZUkhthpUD, with debug_info, not stripped
$ ls -lh pkg/admission-controller/admission-controller-not-stripped
-rwxr-xr-x 1 adrian staff 67M Jan 4 17:22 pkg/admission-controller/admission-controller-not-stripped
After:
$ GOOS=linux go build -C pkg/admission-controller -ldflags="-s" -o admission-controller-stripped
$ file pkg/admission-controller/admission-controller-stripped
pkg/admission-controller/admission-controller-stripped: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, Go BuildID=MBFlhlA4r-VBNuUueZHw/jA8qtsf8vlLZF32hl2vw/-anDCNZimL-FExp30NhX/HIDLyY7TlMNMbxcIptrl, stripped
$ ls -lh pkg/admission-controller/admission-controller-stripped
-rwxr-xr-x 1 adrian staff 46M Jan 4 17:22 pkg/admission-controller/admission-controller-stripped
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 a small nit, but I tested it and it works so lgtm from me.
@@ -0,0 +1,70 @@ | |||
#!/bin/bash | |||
|
|||
# Copyright 2023 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.
We are in 2025 :)
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.
Fixed in 40f0c9b
echo " ** Deploying building and deploying all VPA components" | ||
${SCRIPT_ROOT}/hack/deploy-for-e2e-locally.sh full-vpa | ||
|
||
echo " ** Restarting all VPA components" |
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.
Why do we have to restart all VPA components? Just curious
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 made the script add the latest git commit as a tag, which will cause the pods to restart if a new commit is added.
But, if local changes were made without being committed, then the tag won't change, and pods won't restart
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.
Understood. It makes sense.
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 may be other ways to handle that, such as hashing all uncommitted files and adding that to the tag. After a quick google it seemed to be more effort than it's worth
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, I agree. good job :)
/lgtm |
New changes are detected. LGTM label has been removed. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: adrianmoisey The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This is for easier setup of local environments to test PRs and the like.
Some notes:
LD_FLAGS=-s
env-var that used to be set doesn't actually do anything, so I've moved it to the correct locationWhat type of PR is this?
/kind cleanup
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #7653
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: