Skip to content

Commit

Permalink
Printout git commit for better debugging.
Browse files Browse the repository at this point in the history
Signed-off-by: xuezhaojun <[email protected]>
  • Loading branch information
xuezhaojun committed Oct 18, 2024
1 parent f550bbd commit e0b3da5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
IMAGE_REGISTRY_NAME ?= quay.io/open-cluster-management
Expand Down Expand Up @@ -112,9 +111,11 @@ client-gen:
--versions=open-cluster-management.io/cluster-proxy/pkg/apis/proxy/v1alpha1

images:
git_commit=$$(git rev-parse --short HEAD) && \
docker build \
-f cmd/Dockerfile \
--build-arg ADDON_AGENT_IMAGE_NAME=$(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME):$(IMAGE_TAG) \
--build-arg GIT_COMMIT=$$git_commit \
-t $(IMAGE_REGISTRY_NAME)/$(IMAGE_NAME):$(IMAGE_TAG) .

ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
Expand Down
4 changes: 3 additions & 1 deletion cmd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ WORKDIR /workspace
ARG APISERVER_NETWORK_PROXY_VERSION=0.30.2
ARG KUBECTL_VERSION=v1.30.2
ARG ADDON_AGENT_IMAGE_NAME
ARG GIT_COMMIT

# Build Apiserver-network-proxy binaries
RUN wget https://github.com/kubernetes-sigs/apiserver-network-proxy/archive/refs/tags/v${APISERVER_NETWORK_PROXY_VERSION}.tar.gz \
Expand Down Expand Up @@ -33,7 +34,8 @@ COPY pkg pkg/
# Build addons
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o agent cmd/addon-agent/main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a \
-ldflags="-X 'open-cluster-management.io/cluster-proxy/pkg/config.AgentImageName=${ADDON_AGENT_IMAGE_NAME}'" \
-ldflags="-X 'open-cluster-management.io/cluster-proxy/pkg/config.AgentImageName=${ADDON_AGENT_IMAGE_NAME}' \
-X 'main.gitCommit=${GIT_COMMIT}'" \
-o manager cmd/addon-manager/main.go

# Use distroless as minimal base image to package the manager binary
Expand Down
6 changes: 6 additions & 0 deletions cmd/addon-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"context"
"flag"
"fmt"
"os"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
Expand Down Expand Up @@ -49,6 +50,9 @@ import (
//+kubebuilder:scaffold:imports
)

var commitNumber string

Check failure on line 53 in cmd/addon-manager/main.go

View workflow job for this annotation

GitHub Actions / verify

var `commitNumber` is unused (unused)
var gitCommit string

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
Expand Down Expand Up @@ -91,6 +95,8 @@ func main() {

flag.Parse()

fmt.Printf("Starting addon-manager. Git commit: %s\n", gitCommit)

// pipe controller-runtime logs to klog
ctrl.SetLogger(logger)

Expand Down

0 comments on commit e0b3da5

Please sign in to comment.