Skip to content

Commit

Permalink
fix: Remove kubectl binary from argo image(argoproj#5005) (argoproj#5101
Browse files Browse the repository at this point in the history
)

Signed-off-by: iam-veeramalla <[email protected]>
  • Loading branch information
iam-veeramalla authored Jan 21, 2021
1 parent 1ee7997 commit eaf9887
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 75 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
45 changes: 24 additions & 21 deletions common/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
}
9 changes: 0 additions & 9 deletions hack/installers/install-kubectl-linux.sh

This file was deleted.

40 changes: 0 additions & 40 deletions server/version/version.go
Original file line number Diff line number Diff line change
@@ -1,55 +1,24 @@
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"
"github.com/argoproj/argo-cd/pkg/apiclient/version"
"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()
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion test/container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down

0 comments on commit eaf9887

Please sign in to comment.