Skip to content

Commit

Permalink
Add version and commit hash logging
Browse files Browse the repository at this point in the history
norseto committed Nov 3, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent feb501d commit 3fffbb6
Showing 10 changed files with 100 additions and 34 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'Tag Release'

on:
push:
branches:
- main
- 'release-*'
paths:
- version.go

jobs:
tag-release:
runs-on: ubuntu-20.04

permissions:
contents: write

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: /usr/bin/git config --global user.email [email protected]
- run: /usr/bin/git config --global user.name 'GitHub Actions Release Tagger'
- run: hack/tag-release.sh
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -12,16 +12,20 @@ COPY go.sum go.sum
RUN go mod download

# Copy the go source
COPY .git/ .git/
COPY cmd/main.go cmd/main.go
COPY version.go version.go
COPY api/ api/
COPY internal/controller/ internal/controller/
COPY internal/taints/ internal/taints/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build \
-ldflags=all="-X github.com/norseto/taint-remover.GitVersion=$(git describe --always)" -a -o manager cmd/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -4,6 +4,9 @@ IMG ?= controller:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.28.0

GITSHA := $(shell git describe --always)
LDFLAGS := -ldflags=all=

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
@@ -68,11 +71,11 @@ test: manifests generate fmt vet envtest ## Run tests.

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/main.go
go build $(LDFLAGS)"-X github.com/norseto/taint-remover.GitVersion=$(GITSHA)" -o bin/manager cmd/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/main.go
go run $(LDFLAGS)"-X github.com/norseto/taint-remover.GitVersion=$(GITSHA)" ./cmd/main.go

# If you wish to build the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
4 changes: 4 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

taintremover "github.com/norseto/taint-remover"
nodesv1alpha1 "github.com/norseto/taint-remover/api/v1alpha1"
"github.com/norseto/taint-remover/internal/controller"
//+kubebuilder:scaffold:imports
@@ -74,6 +75,9 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

ctrl.Log.Info("Starting TaintRemover", "version", taintremover.RELEASE_VERSION,
"GitVersion", taintremover.GitVersion)

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Metrics: metricsserver.Options{BindAddress: metricsAddr},
4 changes: 3 additions & 1 deletion config/samples/nodes_v1alpha1_taintremover.yaml
Original file line number Diff line number Diff line change
@@ -9,4 +9,6 @@ metadata:
app.kubernetes.io/created-by: taint-remover
name: taintremover-sample
spec:
# TODO(user): Add fields here
taints:
- key: oci.oraclecloud.com/oke-is-preemptible
effect: NoSchedule
26 changes: 26 additions & 0 deletions hack/tag-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash -xe

VERSION=$(grep 'RELEASE_VERSION\s*=' version.go | awk -F= '{print $2}' | sed -e 's_"__g' -e 's/\s//g')

if [[ ! "${VERSION}" =~ ^([0-9]+[.][0-9]+)[.]([0-9]+)(-(alpha|beta)[.]([0-9]+))?$ ]]; then
echo "Version ${VERSION} must be 'X.Y.Z', 'X.Y.Z-alpha.N', or 'X.Y.Z-beta.N'"
exit 1
fi

MINOR=${BASH_REMATCH[1]}
RELEASE_BRANCH="release-${MINOR}"

if [ "$(git tag -l "v${VERSION}")" ]; then
echo "Tag v${VERSION} already exists"
exit 0
fi

git tag -a -m "Release ${VERSION}" "v${VERSION}"
git push origin "v${VERSION}"

if [[ ! "${VERSION}" =~ .0-beta.1$ ]]; then
exit 0
fi

git branch "${RELEASE_BRANCH}"
git push origin "${RELEASE_BRANCH}"
8 changes: 0 additions & 8 deletions tr-oracle-oke.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions tr-sample-2.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions tr-sample.yaml

This file was deleted.

33 changes: 33 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
MIT License
Copyright (c) 2023 Norihiro Seto
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package taintremover

var Version = RELEASE_VERSION

const (
RELEASE_VERSION = "0.1.0-alpha.1"
)

var GitVersion = ""

0 comments on commit 3fffbb6

Please sign in to comment.