Skip to content

Commit

Permalink
chore: Report git version/tag/hash in the startup logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rg0now committed May 10, 2024
1 parent 75c89bb commit 721c9b0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
21 changes: 14 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# VERSION defines the project version for the bundle.
# Update this value when you upgrade the version of your project.
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= 0.0.1
# Build variables
PACKAGE = github.com/l7mp/stunner
BUILD_DIR ?= bin/
VERSION ?= $(shell (git describe --tags --abbrev=8 --always --long) | tr "/" "-")
COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null)
BUILD_DATE ?= $(shell date +%FT%T%z)
LDFLAGS += -X main.version=${VERSION} -X main.commitHash=${COMMIT_HASH} -X main.buildDate=${BUILD_DATE}

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
Expand Down Expand Up @@ -62,6 +63,12 @@ else
GOBIN=$(shell go env GOBIN)
endif

ifeq (${VERBOSE}, 1)
ifeq ($(filter -v,${GOARGS}),)
GOARGS += -v
endif
endif

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
Expand Down Expand Up @@ -115,7 +122,7 @@ test: manifests generate fmt vet envtest ## Run tests.

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
go build ${GOARGS} -ldflags "${LDFLAGS}" -o ${BUILD_DIR}/manager main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/go-logr/logr v1.4.1
github.com/go-logr/zapr v1.3.0
github.com/l7mp/stunner v0.18.0
github.com/l7mp/stunner v0.18.1
github.com/onsi/ginkgo/v2 v2.15.0
github.com/onsi/gomega v1.30.0
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/l7mp/stunner v0.18.0 h1:vsSVtkNX6pBNX7or3nZM8objm4ykZ1S6QhqYFUJfv50=
github.com/l7mp/stunner v0.18.0/go.mod h1:coyJ/CrOcM4B6z+zoYUxfVPPOXZhd4NnbjiAQ093Uq0=
github.com/l7mp/stunner v0.18.1 h1:KT5QN5o98fe9/UI1sb25HtpH+zQ3nfKZwoKA6KLmvNM=
github.com/l7mp/stunner v0.18.1/go.mod h1:coyJ/CrOcM4B6z+zoYUxfVPPOXZhd4NnbjiAQ093Uq0=
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0=
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
Expand Down
9 changes: 6 additions & 3 deletions internal/updater/client_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,20 @@ func (u *Updater) upsertDeployment(dp *appv1.Deployment, gen int) (ctrlutil.Oper

// affinity
if dpspec.Affinity != nil {
currentspec.Affinity = dpspec.Affinity
dpspec.Affinity.DeepCopyInto(currentspec.Affinity)
}

// tolerations
if dpspec.Tolerations != nil {
currentspec.Tolerations = dpspec.Tolerations
currentspec.Tolerations = make([]corev1.Toleration, len(dpspec.Containers))
for i := range dpspec.Tolerations {
dpspec.Tolerations[i].DeepCopyInto(&currentspec.Tolerations[i])
}
}

// security context
if dpspec.SecurityContext != nil {
currentspec.SecurityContext = dpspec.SecurityContext
dpspec.SecurityContext.DeepCopyInto(currentspec.SecurityContext)
}

// u.log.Info("after", "cm", fmt.Sprintf("%#v\n", current))
Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

stnrv1 "github.com/l7mp/stunner/pkg/apis/v1"
"github.com/l7mp/stunner/pkg/buildinfo"

"github.com/l7mp/stunner-gateway-operator/internal/config"
"github.com/l7mp/stunner-gateway-operator/internal/operator"
Expand All @@ -57,7 +58,10 @@ const (
)

var (
scheme = runtime.NewScheme()
scheme = runtime.NewScheme()
version = "dev"
commitHash = "n/a"
buildDate = "<unknown>"
)

func init() {
Expand Down Expand Up @@ -99,6 +103,9 @@ func main() {
ctrl.SetLogger(logger.WithName("ctrl-runtime"))
setupLog := logger.WithName("setup")

buildInfo := buildinfo.BuildInfo{Version: version, CommitHash: commitHash, BuildDate: buildDate}
setupLog.Info(fmt.Sprintf("starting STUNner gateway operator %s", buildInfo.String()))

config.EnableEndpointDiscovery = enableEDS
setupLog.Info("endpoint discovery", "state", enableEDS)

Expand Down

0 comments on commit 721c9b0

Please sign in to comment.