Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
Log appset version during controller startup log (#241)
Browse files Browse the repository at this point in the history
Signed-off-by: Chetan Banavikalmutt <chetanrns1997@gmail.com>
  • Loading branch information
chetan-rns authored Jun 18, 2021
1 parent 4e7a2ca commit 8d3fa24
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ COPY go.sum .
RUN go mod download

# Copy the go source
COPY main.go .
COPY api/ api/
COPY pkg/ pkg/
COPY . .
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -a -o applicationset-controller main.go
RUN make build

FROM ubuntu:20.10

Expand All @@ -41,4 +39,4 @@ RUN mkdir -p /app/config/gpg/source && \
# chmod 0700 /app/config/gpg/keys

WORKDIR /
COPY --from=builder /workspace/applicationset-controller /usr/local/bin/
COPY --from=builder /workspace/dist/argocd-applicationset /usr/local/bin/applicationset-controller
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
VERSION_PACKAGE=github.com/argoproj-labs/applicationset/common
VERSION?=$(shell cat VERSION)
IMAGE_NAMESPACE?=argoproj
IMAGE_NAME?=argocd-applicationset
IMAGE_TAG?=latest
CONTAINER_REGISTRY?=quay.io
GIT_COMMIT = $(shell git rev-parse HEAD)
LDFLAGS = -w -s -X ${VERSION_PACKAGE}.version=${VERSION} \
-X ${VERSION_PACKAGE}.gitCommit=${GIT_COMMIT}

MKDOCS_DOCKER_IMAGE?=squidfunk/mkdocs-material:4.1.1
MKDOCS_RUN_ARGS?=
Expand Down Expand Up @@ -34,7 +38,7 @@ endif

.PHONY: build
build: manifests fmt vet
CGO_ENABLED=0 go build -ldflags="-w -s" -o ./dist/argocd-applicationset .
CGO_ENABLED=0 go build -ldflags="${LDFLAGS}" -o ./dist/argocd-applicationset .

.PHONY: test
test: generate fmt vet manifests
Expand Down
21 changes: 21 additions & 0 deletions common/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package common

// version information populated during build time
var (
version = "" // value from VERSION file
gitCommit = "" // output of git rev-parse HEAD
)

// Version of the applicationset controller
type Version struct {
Version string
GitCommit string
}

// GetVersion returns the version of the applicationset controller
func GetVersion() Version {
return Version{
Version: "v" + version,
GitCommit: gitCommit,
}
}
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/argoproj-labs/applicationset/pkg/services"
"github.com/argoproj-labs/applicationset/pkg/utils"

"github.com/argoproj-labs/applicationset/common"
argov1alpha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/util/db"
argosettings "github.com/argoproj/argo-cd/util/settings"
Expand Down Expand Up @@ -110,7 +111,8 @@ func main() {
namespace = "argocd"
}

setupLog.Info(fmt.Sprintf("ApplicationSet controller using namespace '%s'", namespace), "namespace", namespace)
version := common.GetVersion()
setupLog.Info(fmt.Sprintf("ApplicationSet controller %s using namespace '%s'", version.Version, namespace), "namespace", namespace, "COMMIT_ID", version.GitCommit)

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Expand Down

0 comments on commit 8d3fa24

Please sign in to comment.