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

Expose the version of Kustomize that Kubectl embeds #108817

Merged
merged 2 commits into from
Mar 24, 2022

Conversation

KnVerey
Copy link
Contributor

@KnVerey KnVerey commented Mar 18, 2022

What type of PR is this?

/kind feature

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes kubernetes-sigs/kustomize#1424. This is the top feature request on Kustomize by upvotes and has also been requested directly on the kubectl and oc repos.

/cc @natasha41575

Special notes for your reviewer:

Updated to match the implementation agreed to at the Mar 23 SIG CLI meeting

This PR extracts the current Kustomize version from the root go.mod and sets an ldflag that embeds the version into Kustomize's Provenance code (the same code that drives standalone kustomize version). It then uses that information to expose Kustomize version info in kubectl version. It also adds a sanity check to the Kustomize update script, ensuring that the version output matches what the update executor intended.

Alternatives considered:

  • Embedding the Kustomize version inside the client section of kubectl version: [ALTERNATIVE] Expose the version of Kustomize that Kubectl embeds #108947
  • Introduce kubectl version --kustomize to expose this info specifically. Would be clean to implement, but not consistent with anything else I'm aware of, and probably unintuitive.
  • Having the Kustomize release process directly embed the version, or having the kubectl update process embed it in the kubectl integration code (3dba87f). Both of those would cause potentially inaccurate output for other CLIs importing kustomize and kubectl CLI code respectively.
  • kubectl kustomize version (1e7c1db). It was pointed out at today's SIG meeting that the version also applies to kubectl apply -k, not just kubectl kustomize.

Output

Expand to show output samples
༶ _output/bin/kubectl version
Client Version: version.Info{Major:"1", Minor:"24+", GitVersion:"v1.24.0-alpha.4.14+b85880aac7a987-dirty", GitCommit:"b85880aac7a9879f70b4d124e0f92826a00eeb0a", GitTreeState:"dirty", BuildDate:"2022-03-23T22:57:37Z", GoVersion:"go1.17.6", Compiler:"gc", Platform:"darwin/arm64"}
Kustomize Version: v4.4.1
Server Version: # not relevant / unchanged

༶ _output/bin/kubectl version --client
Client Version: version.Info{Major:"1", Minor:"24+", GitVersion:"v1.24.0-alpha.4.14+b85880aac7a987-dirty", GitCommit:"b85880aac7a9879f70b4d124e0f92826a00eeb0a", GitTreeState:"dirty", BuildDate:"2022-03-23T22:57:37Z", GoVersion:"go1.17.6", Compiler:"gc", Platform:"darwin/arm64"}
Kustomize Version: v4.4.1

༶ _output/bin/kubectl version --client -o yaml
clientVersion:
  buildDate: "2022-03-23T22:57:37Z"
  compiler: gc
  gitCommit: b85880aac7a9879f70b4d124e0f92826a00eeb0a
  gitTreeState: dirty
  gitVersion: v1.24.0-alpha.4.14+b85880aac7a987-dirty
  goVersion: go1.17.6
  major: "1"
  minor: 24+
  platform: darwin/arm64
kustomizeVersion: v4.4.1

༶ _output/bin/kubectl version --client -o json
{
  "clientVersion": {
    "major": "1",
    "minor": "24+",
    "gitVersion": "v1.24.0-alpha.4.14+b85880aac7a987-dirty",
    "gitCommit": "b85880aac7a9879f70b4d124e0f92826a00eeb0a",
    "gitTreeState": "dirty",
    "buildDate": "2022-03-23T22:57:37Z",
    "goVersion": "go1.17.6",
    "compiler": "gc",
    "platform": "darwin/arm64"
  },
  "kustomizeVersion": "v4.4.1"
}

༶ _output/bin/kubectl version --short
Client Version: v1.24.0-alpha.4.14+b85880aac7a987-dirty
Kustomize Version: v4.4.1
Server Version: v1.22.4

Does this PR introduce a user-facing change?

`kubectl version` now includes information on the embedded version of Kustomize

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Mar 18, 2022
@k8s-ci-robot
Copy link
Contributor

@KnVerey: This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Mar 18, 2022
Copy link
Contributor

@natasha41575 natasha41575 left a comment

Choose a reason for hiding this comment

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

/lgtm

hack/update-kustomize.sh Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 21, 2022
@natasha41575
Copy link
Contributor

/retest

@KnVerey
Copy link
Contributor Author

KnVerey commented Mar 21, 2022

/hold

I think this approach might be problematic for CLIs that embed kubectl (and by extension kubectl kustomize). At minimum, I think kubectl kustomize version should print "unknown" by default and give those tools a hook to set the version they're using. And the version k/k is pinned to should probably be injected by the release pipeline (which needs to be informed of it somehow) instead of straight into the code during the dep update.

(Note: I tried debug/ReadBuildInfo#Deps, but it doesn't seem to be available, at least to local builds.)

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 21, 2022
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/test sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 22, 2022
@KnVerey KnVerey changed the title kubectl kustomize version [WIP] kubectl kustomize version Mar 22, 2022
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 22, 2022
@k8s-ci-robot k8s-ci-robot added the area/dependency Issues or PRs related to dependency changes label Mar 22, 2022
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 22, 2022
@KnVerey
Copy link
Contributor Author

KnVerey commented Mar 22, 2022

/test pull-kubernetes-node-e2e-containerd

1 similar comment
@KnVerey
Copy link
Contributor Author

KnVerey commented Mar 22, 2022

/test pull-kubernetes-node-e2e-containerd

@natasha41575
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 23, 2022
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed 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. labels Mar 23, 2022
@KnVerey KnVerey changed the title kubectl kustomize version Expose the version of Kustomize that Kubectl embeds Mar 23, 2022
@@ -328,12 +328,16 @@ kube::test::if_has_string() {
local match=$2

if grep -q "${match}" <<< "${message}"; then
echo -n "${green}"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When running the version tests, I noticed that some of the helpers it uses had nice colorization and others did not. This is in a separate commit, and I can easily remove it from the PR if it is unwanted.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch, those are usually handy :) Thank you!

)

clientVersion := version.Get()
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 got rid of the separate serverVersion and clientVersion variables in favour of having all usages rely on the same copy of the data, i.e. the one in versionInfo

@KnVerey
Copy link
Contributor Author

KnVerey commented Mar 24, 2022

@soltysh I've updated this PR to match the implementation agreed to at the meeting earlier today. I've also created yet another option for consideration at #108947. LMK what you think.

@@ -26,6 +26,7 @@
# KUBE_GIT_VERSION - "vX.Y" used to indicate the last release version.
# KUBE_GIT_MAJOR - The major part of the version
# KUBE_GIT_MINOR - The minor component of the version
# KUSTOMIZE_VERSION - The semantic version of kustomize embedded in kubectl
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 really like to avoid this plumbing here, since the compiled in module info is in reach with go 1.18 and this build script services many binaries, not just kubectl

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@@ -328,12 +328,16 @@ kube::test::if_has_string() {
local match=$2

if grep -q "${match}" <<< "${message}"; then
echo -n "${green}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch, those are usually handy :) Thank you!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: KnVerey, soltysh

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 24, 2022
@mikebz
Copy link

mikebz commented Mar 24, 2022

great to see this in the version output. It is a frequently asked question.

@k8s-ci-robot k8s-ci-robot merged commit bd1e7dc into kubernetes:master Mar 24, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Mar 24, 2022
@KnVerey KnVerey deleted the kustomize_version branch November 8, 2022 19:03
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/dependency Issues or PRs related to dependency changes area/kubectl area/test 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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Add kustomize --version and kubectl kustomize --version
6 participants