mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 01:40:13 +00:00
kubectl version should include bundled kustomize version
This commit is contained in:
parent
af059a0731
commit
44e63e8ff8
@ -55,10 +55,20 @@ fi
|
||||
./hack/update-internal-modules.sh
|
||||
./hack/lint-dependencies.sh
|
||||
|
||||
sed -i '' -e "s/const kustomizeVersion.*$/const kustomizeVersion = \"${LATEST_KUSTOMIZE}\"/" staging/src/k8s.io/kubectl/pkg/cmd/version/version.go
|
||||
|
||||
echo -e "\n${color_blue}Committing changes${color_norm}"
|
||||
git add .
|
||||
git commit -a -m "Update kubectl kustomize to kyaml/$LATEST_KYAML, cmd/config/$LATEST_CONFIG, api/$LATEST_API, kustomize/$LATEST_KUSTOMIZE"
|
||||
|
||||
echo -e "\n${color_blue:?}Verifying kubectl kustomize version${color_norm:?}"
|
||||
make WHAT=cmd/kubectl
|
||||
|
||||
if [[ $(_output/bin/kubectl version --client -o json | jq -r '.kustomizeVersion') != "$LATEST_KUSTOMIZE" ]]; then
|
||||
echo -e "${color_red:?}Unexpected kubectl kustomize version${color_norm:?}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "\n${color_green:?}Update successful${color_norm:?}"
|
||||
echo "Note: If any of the integration points changed, you may need to update them manually."
|
||||
echo "See https://github.com/kubernetes-sigs/kustomize/tree/master/releasing#update-kustomize-in-kubectl for more information"
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/yaml"
|
||||
@ -34,10 +35,14 @@ import (
|
||||
"k8s.io/kubectl/pkg/util/templates"
|
||||
)
|
||||
|
||||
// TODO(knverey): remove this hardcoding once kubectl being built with module support makes BuildInfo available.
|
||||
const kustomizeVersion = "v4.4.1"
|
||||
|
||||
// Version is a struct for version information
|
||||
type Version struct {
|
||||
ClientVersion *apimachineryversion.Info `json:"clientVersion,omitempty" yaml:"clientVersion,omitempty"`
|
||||
ServerVersion *apimachineryversion.Info `json:"serverVersion,omitempty" yaml:"serverVersion,omitempty"`
|
||||
ClientVersion *apimachineryversion.Info `json:"clientVersion,omitempty" yaml:"clientVersion,omitempty"`
|
||||
KustomizeVersion string `json:"kustomizeVersion,omitempty" yaml:"kustomizeVersion,omitempty"`
|
||||
ServerVersion *apimachineryversion.Info `json:"serverVersion,omitempty" yaml:"serverVersion,omitempty"`
|
||||
}
|
||||
|
||||
var (
|
||||
@ -116,32 +121,32 @@ func (o *Options) Validate(args []string) error {
|
||||
// Run executes version command
|
||||
func (o *Options) Run() error {
|
||||
var (
|
||||
serverVersion *apimachineryversion.Info
|
||||
serverErr error
|
||||
versionInfo Version
|
||||
serverErr error
|
||||
versionInfo Version
|
||||
)
|
||||
|
||||
clientVersion := version.Get()
|
||||
versionInfo.ClientVersion = &clientVersion
|
||||
versionInfo.ClientVersion = func() *apimachineryversion.Info { v := version.Get(); return &v }()
|
||||
versionInfo.KustomizeVersion = getKustomizeVersion()
|
||||
|
||||
if !o.ClientOnly && o.discoveryClient != nil {
|
||||
// Always request fresh data from the server
|
||||
o.discoveryClient.Invalidate()
|
||||
serverVersion, serverErr = o.discoveryClient.ServerVersion()
|
||||
versionInfo.ServerVersion = serverVersion
|
||||
versionInfo.ServerVersion, serverErr = o.discoveryClient.ServerVersion()
|
||||
}
|
||||
|
||||
switch o.Output {
|
||||
case "":
|
||||
if o.Short {
|
||||
fmt.Fprintf(o.Out, "Client Version: %s\n", clientVersion.GitVersion)
|
||||
if serverVersion != nil {
|
||||
fmt.Fprintf(o.Out, "Server Version: %s\n", serverVersion.GitVersion)
|
||||
fmt.Fprintf(o.Out, "Client Version: %s\n", versionInfo.ClientVersion.GitVersion)
|
||||
fmt.Fprintf(o.Out, "Kustomize Version: %s\n", versionInfo.KustomizeVersion)
|
||||
if versionInfo.ServerVersion != nil {
|
||||
fmt.Fprintf(o.Out, "Server Version: %s\n", versionInfo.ServerVersion.GitVersion)
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(o.Out, "Client Version: %#v\n", clientVersion)
|
||||
if serverVersion != nil {
|
||||
fmt.Fprintf(o.Out, "Server Version: %#v\n", *serverVersion)
|
||||
fmt.Fprintf(o.Out, "Client Version: %#v\n", *versionInfo.ClientVersion)
|
||||
fmt.Fprintf(o.Out, "Kustomize Version: %s\n", versionInfo.KustomizeVersion)
|
||||
if versionInfo.ServerVersion != nil {
|
||||
fmt.Fprintf(o.Out, "Server Version: %#v\n", *versionInfo.ServerVersion)
|
||||
}
|
||||
}
|
||||
case "yaml":
|
||||
@ -162,11 +167,24 @@ func (o *Options) Run() error {
|
||||
return fmt.Errorf("VersionOptions were not validated: --output=%q should have been rejected", o.Output)
|
||||
}
|
||||
|
||||
if serverVersion != nil {
|
||||
if err := printVersionSkewWarning(o.ErrOut, clientVersion, *serverVersion); err != nil {
|
||||
if versionInfo.ServerVersion != nil {
|
||||
if err := printVersionSkewWarning(o.ErrOut, *versionInfo.ClientVersion, *versionInfo.ServerVersion); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return serverErr
|
||||
}
|
||||
|
||||
func getKustomizeVersion() string {
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return kustomizeVersion
|
||||
}
|
||||
for _, dep := range info.Deps {
|
||||
if dep.Path == "sigs.k8s.io/kustomize/kustomize/v4" {
|
||||
return dep.Version
|
||||
}
|
||||
}
|
||||
return kustomizeVersion
|
||||
}
|
||||
|
@ -66,6 +66,21 @@ run_kubectl_version_tests() {
|
||||
kube::test::version::yaml_object_to_file "" "${TEMP}/client_server_yaml_version_test"
|
||||
kube::test::version::diff_assert "${TEMP}/client_server_json_version_test" "eq" "${TEMP}/client_server_yaml_version_test" "--output json/yaml has identical information"
|
||||
|
||||
kube::log::status "Testing kubectl version: contains semantic version of embedded kustomize"
|
||||
output_message=$(kubectl version)
|
||||
kube::test::if_has_not_string "${output_message}" "Kustomize Version\: unknown" "kustomize version should not be unknown"
|
||||
kube::test::if_has_string "${output_message}" "Kustomize Version\: v[[:digit:]][[:digit:]]*\.[[:digit:]][[:digit:]]*\.[[:digit:]][[:digit:]]*" "kubectl kustomize version should have a reasonable value"
|
||||
|
||||
kube::log::status "Testing kubectl version: all output formats include kustomize version"
|
||||
output_message=$(kubectl version --client)
|
||||
kube::test::if_has_string "${output_message}" "Kustomize Version" "kustomize version should be printed when --client is specified"
|
||||
output_message=$(kubectl version --short)
|
||||
kube::test::if_has_string "${output_message}" "Kustomize Version" "kustomize version should be printed when --short is specified"
|
||||
output_message=$(kubectl version -o yaml)
|
||||
kube::test::if_has_string "${output_message}" "kustomizeVersion" "kustomize version should be printed when -o yaml is used"
|
||||
output_message=$(kubectl version -o json)
|
||||
kube::test::if_has_string "${output_message}" "kustomizeVersion" "kustomize version should be printed when -o json is used"
|
||||
|
||||
set +o nounset
|
||||
set +o errexit
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user