diff --git a/Dockerfile b/Dockerfile index 5ff315ff0ef2d..89cb3f43b1ba0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,7 +28,6 @@ ADD hack/installers installers ADD hack/tool-versions.sh . RUN ./install.sh packr-linux -RUN ./install.sh kubectl-linux RUN ./install.sh ksonnet-linux RUN ./install.sh helm2-linux RUN ./install.sh helm-linux @@ -62,7 +61,6 @@ COPY hack/git-verify-wrapper.sh /usr/local/bin/git-verify-wrapper.sh COPY --from=builder /usr/local/bin/ks /usr/local/bin/ks COPY --from=builder /usr/local/bin/helm2 /usr/local/bin/helm2 COPY --from=builder /usr/local/bin/helm /usr/local/bin/helm -COPY --from=builder /usr/local/bin/kubectl /usr/local/bin/kubectl COPY --from=builder /usr/local/bin/kustomize /usr/local/bin/kustomize # script to add current (possibly arbitrary) user to /etc/passwd at runtime # (if it's not already there, to be openshift friendly) diff --git a/Makefile b/Makefile index 38d086a87ac1d..64faf3bd49ad0 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ GIT_TAG=$(shell if [ -z "`git status --porcelain`" ]; then git describe --exact- GIT_TREE_STATE=$(shell if [ -z "`git status --porcelain`" ]; then echo "clean" ; else echo "dirty"; fi) PACKR_CMD=$(shell if [ "`which packr`" ]; then echo "packr"; else echo "go run github.com/gobuffalo/packr/packr"; fi) VOLUME_MOUNT=$(shell if test "$(go env GOOS)" = "darwin"; then echo ":delegated"; elif test selinuxenabled; then echo ":delegated"; else echo ""; fi) +KUBECTL_VERSION=$(shell awk '/k8s.io\/client-go => k8s.io\/client-go/ { print $$4 }' go.mod | sed -e 's/v0\.\(.*\)/v1\.\1/') GOPATH?=$(shell if test -x `which go`; then go env GOPATH; else echo "$(HOME)/go"; fi) GOCACHE?=$(HOME)/.cache/go-build @@ -120,7 +121,9 @@ override LDFLAGS += \ -X ${PACKAGE}.version=${VERSION} \ -X ${PACKAGE}.buildDate=${BUILD_DATE} \ -X ${PACKAGE}.gitCommit=${GIT_COMMIT} \ - -X ${PACKAGE}.gitTreeState=${GIT_TREE_STATE} + -X ${PACKAGE}.gitTreeState=${GIT_TREE_STATE}\ + -X ${PACKAGE}.gitTreeState=${GIT_TREE_STATE}\ + -X ${PACKAGE}.kubectlVersion=${KUBECTL_VERSION} ifeq (${STATIC_BUILD}, true) override LDFLAGS += -extldflags "-static" @@ -513,7 +516,6 @@ install-tools-local: install-test-tools-local install-codegen-tools-local instal .PHONY: install-test-tools-local install-test-tools-local: sudo ./hack/install.sh packr-linux - sudo ./hack/install.sh kubectl-linux sudo ./hack/install.sh kustomize-linux sudo ./hack/install.sh ksonnet-linux sudo ./hack/install.sh helm2-linux diff --git a/common/version.go b/common/version.go index ea552100aad88..b06976877f9b2 100644 --- a/common/version.go +++ b/common/version.go @@ -8,23 +8,25 @@ import ( // Version information set by link flags during build. We fall back to these sane // default values when we build outside the Makefile context (e.g. go run, go build, or go test). var ( - version = "99.99.99" // value from VERSION file - buildDate = "1970-01-01T00:00:00Z" // output from `date -u +'%Y-%m-%dT%H:%M:%SZ'` - gitCommit = "" // output from `git rev-parse HEAD` - gitTag = "" // output from `git describe --exact-match --tags HEAD` (if clean tree state) - gitTreeState = "" // determined from `git status --porcelain`. either 'clean' or 'dirty' + version = "99.99.99" // value from VERSION file + buildDate = "1970-01-01T00:00:00Z" // output from `date -u +'%Y-%m-%dT%H:%M:%SZ'` + gitCommit = "" // output from `git rev-parse HEAD` + gitTag = "" // output from `git describe --exact-match --tags HEAD` (if clean tree state) + gitTreeState = "" // determined from `git status --porcelain`. either 'clean' or 'dirty' + kubectlVersion = "" // determined from go.mod file ) // Version contains Argo version information type Version struct { - Version string - BuildDate string - GitCommit string - GitTag string - GitTreeState string - GoVersion string - Compiler string - Platform string + Version string + BuildDate string + GitCommit string + GitTag string + GitTreeState string + GoVersion string + Compiler string + Platform string + KubectlVersion string } func (v Version) String() string { @@ -53,13 +55,14 @@ func GetVersion() Version { } } return Version{ - Version: versionStr, - BuildDate: buildDate, - GitCommit: gitCommit, - GitTag: gitTag, - GitTreeState: gitTreeState, - GoVersion: runtime.Version(), - Compiler: runtime.Compiler, - Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), + Version: versionStr, + BuildDate: buildDate, + GitCommit: gitCommit, + GitTag: gitTag, + GitTreeState: gitTreeState, + GoVersion: runtime.Version(), + Compiler: runtime.Compiler, + Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), + KubectlVersion: kubectlVersion, } } diff --git a/hack/installers/install-kubectl-linux.sh b/hack/installers/install-kubectl-linux.sh deleted file mode 100755 index c7feb9743c3e4..0000000000000 --- a/hack/installers/install-kubectl-linux.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -eux -o pipefail - -. $(dirname $0)/../tool-versions.sh - -# NOTE: keep the version synced with https://storage.googleapis.com/kubernetes-release/release/stable.txt -[ -e $DOWNLOADS/kubectl ] || curl -sLf --retry 3 -o $DOWNLOADS/kubectl https://storage.googleapis.com/kubernetes-release/release/v${kubectl_version}/bin/linux/$ARCHITECTURE/kubectl -cp $DOWNLOADS/kubectl $BIN/ -chmod +x $BIN/kubectl diff --git a/server/version/version.go b/server/version/version.go index d1ab03254b2f3..6609efc4212fb 100644 --- a/server/version/version.go +++ b/server/version/version.go @@ -1,16 +1,8 @@ package version import ( - "errors" - "fmt" - "os/exec" - "regexp" - "strings" - - "github.com/argoproj/gitops-engine/pkg/utils/tracing" "github.com/golang/protobuf/ptypes/empty" "github.com/google/go-jsonnet" - "github.com/sirupsen/logrus" "golang.org/x/net/context" "github.com/argoproj/argo-cd/common" @@ -18,38 +10,15 @@ import ( "github.com/argoproj/argo-cd/util/helm" ksutil "github.com/argoproj/argo-cd/util/ksonnet" "github.com/argoproj/argo-cd/util/kustomize" - "github.com/argoproj/argo-cd/util/log" ) type Server struct { ksonnetVersion string kustomizeVersion string helmVersion string - kubectlVersion string jsonnetVersion string } -func getVersion() (string, error) { - span := tracing.NewLoggingTracer(log.NewLogrusLogger(logrus.New())).StartSpan("Version") - defer span.Finish() - cmd := exec.Command("kubectl", "version", "--client") - out, err := cmd.CombinedOutput() - if err != nil { - return "", fmt.Errorf("could not get kubectl version: %s", err) - } - - re := regexp.MustCompile(`GitVersion:"([a-zA-Z0-9\.\-]+)"`) - matches := re.FindStringSubmatch(string(out)) - if len(matches) != 2 { - return "", errors.New("could not get kubectl version") - } - version := matches[1] - if version[0] != 'v' { - version = "v" + version - } - return strings.TrimSpace(version), nil -} - // Version returns the version of the API server func (s *Server) Version(context.Context, *empty.Empty) (*version.VersionMessage, error) { vers := common.GetVersion() @@ -77,14 +46,6 @@ func (s *Server) Version(context.Context, *empty.Empty) (*version.VersionMessage s.helmVersion = err.Error() } } - if s.kubectlVersion == "" { - kubectlVersion, err := getVersion() - if err == nil { - s.kubectlVersion = kubectlVersion - } else { - s.kubectlVersion = err.Error() - } - } s.jsonnetVersion = jsonnet.Version() return &version.VersionMessage{ Version: vers.Version, @@ -98,7 +59,6 @@ func (s *Server) Version(context.Context, *empty.Empty) (*version.VersionMessage KsonnetVersion: s.ksonnetVersion, KustomizeVersion: s.kustomizeVersion, HelmVersion: s.helmVersion, - KubectlVersion: s.kubectlVersion, JsonnetVersion: s.jsonnetVersion, }, nil } diff --git a/test/container/Dockerfile b/test/container/Dockerfile index 78773bc0ee4ba..5358359026b56 100644 --- a/test/container/Dockerfile +++ b/test/container/Dockerfile @@ -37,7 +37,6 @@ ADD ./hack/installers installers RUN ./install.sh dep-linux && \ ./install.sh packr-linux && \ - ./install.sh kubectl-linux && \ ./install.sh ksonnet-linux && \ ./install.sh helm2-linux && \ ./install.sh helm-linux && \