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

VPA: Create a build and deploy locally script #7654

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

adrianmoisey
Copy link
Member

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

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


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
@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 4, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: adrianmoisey
Once this PR has been reviewed and has the lgtm label, please assign raywainman for approval. For more information see the Kubernetes Code Review Process.

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

@k8s-ci-robot k8s-ci-robot requested a review from jbartosik January 4, 2025 15:15
@k8s-ci-robot k8s-ci-robot requested a review from voelzmo January 4, 2025 15:15
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 4, 2025
Comment on lines 19 to 41
// 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]
}
Copy link
Member Author

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

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

Copy link
Member Author

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

Copy link
Member

@omerap12 omerap12 left a 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.
Copy link
Member

Choose a reason for hiding this comment

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

We are in 2025 :)

Copy link
Member Author

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

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

Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Understood. It makes sense.

Copy link
Member Author

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

Copy link
Member

@omerap12 omerap12 Jan 5, 2025

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

@omerap12
Copy link
Member

omerap12 commented Jan 4, 2025

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/vertical-pod-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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.

Add development script to quickly test VPA in kind cluster
3 participants