Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(operator): Add commit hash, buildtime, buildversion to OTel resource attributes #121

Merged
merged 3 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion operator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
FROM golang:1.18 as builder

ARG ARCH
ARG GIT_HASH
ARG RELEASE_VERSION

WORKDIR /workspace

Expand All @@ -20,7 +22,7 @@ COPY controllers/ controllers/
COPY webhooks/ webhooks/

# Build
RUN make build.$ARCH
RUN make build.$ARCH HASH=${GIT_HASH} TAG=${RELEASE_VERSION}

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
21 changes: 13 additions & 8 deletions operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ IMG ?= controller:latest
# RELEASE_REGISTRY is the container registry to push
# into.
RELEASE_REGISTRY?=ghcr.io/keptn-sandbox
RELEASE_VERSION?=$(shell date +%Y%m%d%s)-v0.24.3#$(shell git describe --tags --match "v*")
RELEASE_TIME=$(shell date +%Y%m%d%s)
BUILD_TIME=$(shell date -u "+%F_%T")
RELEASE_VERSION?=$(RELEASE_TIME)-v0.24.3#$(shell git describe --tags --match "v*")
TAG?=latest
RELEASE_IMAGE:=keptn-lifecycle-operator:$(TAG)

Expand Down Expand Up @@ -32,6 +34,9 @@ endif
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

# Compute the current Git commit hash
HASH?=$(shell git rev-parse HEAD)

.PHONY: all
all: build

Expand Down Expand Up @@ -77,15 +82,15 @@ test: manifests generate fmt vet envtest ## Run tests.
##@ Build
.PHONY: build
build: generate fmt vet ## Build manager binary.
$(COMMONENVVAR) $(BUILDENVVAR) go build -ldflags '-w' -o bin/manager main.go
$(COMMONENVVAR) $(BUILDENVVAR) go build -ldflags '-w -X main.gitCommit=$(HASH) -X main.buildTime=$(BUILD_TIME) -X main.buildVersion=$(TAG)' -o bin/manager main.go

.PHONY: build.amd64
build.amd64: generate fmt vet ## Build manager binary.
$(COMMONENVVAR) $(BUILDENVVAR) GOARCH=amd64 go build -ldflags '-w' -o bin/manager main.go
$(COMMONENVVAR) $(BUILDENVVAR) GOARCH=amd64 go build -ldflags '-w -X main.gitCommit=$(HASH) -X main.buildTime=$(BUILD_TIME) -X main.buildVersion=$(TAG)' -o bin/manager main.go

.PHONY: build.arm64v8
build.arm64v8: generate fmt vet ## Build manager binary.
$(COMMONENVVAR) $(BUILDENVVAR) GOARCH=arm64 go build -ldflags '-w' -o bin/manager main.go
$(COMMONENVVAR) $(BUILDENVVAR) GOARCH=arm64 go build -ldflags '-w -X main.gitCommit=$(HASH) -X main.buildTime=$(BUILD_TIME) -X main.buildVersion=$(TAG)' -o bin/manager main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
Expand Down Expand Up @@ -162,11 +167,11 @@ release-image: release-image.amd64 release-image.arm64v8

.PHONY: release-image.amd64
release-image.amd64: clean
docker build --load --build-arg ARCH="amd64" --build-arg RELEASE_VERSION="$(RELEASE_VERSION)" -t $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-amd64 .
docker build --load --build-arg ARCH="amd64" --build-arg GIT_HASH="$(HASH)" --build-arg RELEASE_VERSION="$(TAG)" -t $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-amd64 .

.PHONY: release-image.arm64v8
release-image.arm64v8: clean
docker build --load --build-arg ARCH="arm64v8" --build-arg RELEASE_VERSION="$(RELEASE_VERSION)" -t $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-arm64 .
docker build --load --build-arg ARCH="arm64v8" --build-arg GIT_HASH="$(HASH)" --build-arg RELEASE_VERSION="$(TAG)" -t $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-arm64 .

.PHONY: push-release-images
push-release-images:
Expand Down Expand Up @@ -203,8 +208,8 @@ release-local: release-local.amd64 release-local.arm64v8

.PHONY: release-local.amd64
release-local.amd64: clean
docker build --build-arg ARCH="amd64" --build-arg RELEASE_VERSION="$(RELEASE_VERSION)" -t $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-amd64 .
docker build --build-arg ARCH="amd64" --build-arg GIT_HASH="$(HASH)" --build-arg RELEASE_VERSION="$(TAG)" -t $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-amd64 .

.PHONY: release-local.arm64v8
release-local.arm64v8: clean
docker build --build-arg ARCH="arm64v8" --build-arg RELEASE_VERSION="$(RELEASE_VERSION)" -t $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-arm64 .
docker build --build-arg ARCH="arm64v8" --build-arg GIT_HASH="$(HASH)" --build-arg RELEASE_VERSION="$(TAG)" -t $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-arm64 .
11 changes: 7 additions & 4 deletions operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ import (
)

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
gitCommit string
buildTime string
buildVersion string
)

func init() {
Expand Down Expand Up @@ -197,7 +200,6 @@ func main() {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}

}

func newExporter() (trace.SpanExporter, error) {
Expand All @@ -214,8 +216,9 @@ func newResource() *resource.Resource {
resource.Default(),
resource.NewWithAttributes(
semconv.SchemaURL,
semconv.TelemetrySDKLanguageGo,
semconv.ServiceNameKey.String("keptn-lifecycle-operator"),
semconv.ServiceVersionKey.String("v0.1.0"),
semconv.ServiceVersionKey.String(buildVersion+"-"+gitCommit+"-"+buildTime),
),
)
return r
Expand Down