Skip to content

Commit

Permalink
Adding version details to sidecar
Browse files Browse the repository at this point in the history
Signed-off-by: saranyareddy24 <[email protected]>
  • Loading branch information
saranyareddy24 committed Jun 25, 2023
1 parent 1712b73 commit 43ebc4b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
23 changes: 20 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ TOOLS_IMG ?= quay.io/csiaddons/tools

# set TAG to a release for consumption in the bundle
TAG ?= latest

# In case the *_IMG variables can contain a full qualified container-image
# resource (includes a ":"), the container-images should not use the TAG
# valued. The :TAG option will only be added if no predefined version is
Expand Down Expand Up @@ -56,6 +55,24 @@ ifneq ($(TAG),latest)
BUNDLE_VERSION ?= --version=$(shell sed s/^v// <<< $(TAG))
endif

ifndef GIT_COMMIT
GIT_COMMIT=$(shell git rev-list -1 HEAD)
endif

ifndef GIT_TAG
GIT_TAG=$(shell git describe --tags --exact-match --abbrev=0 2>/dev/null)
endif

ifeq ($(GIT_TAG),)
GIT_TAG=$(shell git rev-parse --short HEAD)
endif

GO_PROJECT=github.com/csi-addons/kubernetes-csi-addons

LDFLAGS ?=
LDFLAGS += -X $(GO_PROJECT)/sidecar/internal/version.GitCommit=$(GIT_COMMIT)
LDFLAGS += -X $(GO_PROJECT)/sidecar/internal/version.SidecarVersion=$(GIT_TAG)

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.23

Expand Down Expand Up @@ -159,7 +176,7 @@ bundle-validate: container-cmd operator-sdk
.PHONY: build
build: generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/manager/main.go
go build -o bin/sidecar sidecar/main.go
go build -ldflags '$(LDFLAGS)' -o bin/sidecar sidecar/main.go
go build -o bin/csi-addons ./cmd/csi-addons

.PHONY: run
Expand Down Expand Up @@ -192,7 +209,7 @@ docker-push-bundle: container-cmd

.PHONY: docker-build-tools
docker-generate-protobuf: container-cmd ./build/Containerfile.tools
$(CONTAINER_CMD) build -f ./build/Containerfile.tools -t ${TOOLS_IMG} .
$(CONTAINER_CMD) build -f $^ -t ${TOOLS_IMG} .
$(CONTAINER_CMD) run --rm -ti --volume=${PWD}:/go/src/github.com/csi-addons/kubernetes-csi-addons:Z ${TOOLS_IMG} make generate-protobuf

##@ Deployment
Expand Down
37 changes: 37 additions & 0 deletions sidecar/internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2021 The Kubernetes-CSI-Addons Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package version

import (
"fmt"
"runtime"
)

var (
// GitCommit tell the latest git commit image is built from.
GitCommit string
// SidecarVersion which will be sidecar release version.
SidecarVersion string
)

func PrintVersion() {
fmt.Println("Version:", SidecarVersion)
fmt.Println("Git Commit:", GitCommit)
fmt.Println("Go Version:", runtime.Version())
fmt.Println("Compiler:", runtime.Compiler)
fmt.Printf("Platform: %s/%s\n", runtime.GOOS, runtime.GOARCH)
}
13 changes: 11 additions & 2 deletions sidecar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package main

import (
"flag"
"time"

"github.com/csi-addons/kubernetes-csi-addons/internal/sidecar/service"
"github.com/csi-addons/kubernetes-csi-addons/sidecar/internal/client"
"github.com/csi-addons/kubernetes-csi-addons/sidecar/internal/csiaddonsnode"
"github.com/csi-addons/kubernetes-csi-addons/sidecar/internal/server"
"github.com/csi-addons/kubernetes-csi-addons/sidecar/internal/util"
"github.com/csi-addons/kubernetes-csi-addons/sidecar/internal/version"
"time"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand All @@ -47,12 +47,21 @@ func main() {
podNamespace = flag.String("namespace", "", "namespace of the Pod that contains this sidecar")
podUID = flag.String("pod-uid", "", "UID of the Pod that contains this sidecar")
)
var showVersion bool
klog.InitFlags(nil)

if err := flag.Set("logtostderr", "true"); err != nil {
klog.Exitf("failed to set logtostderr flag: %v", err)
}

flag.BoolVar(&showVersion, "version", false, "Print Version details")
flag.Parse()

if showVersion {
version.PrintVersion()
return
}

controllerEndpoint, err := util.BuildEndpointURL(*controllerIP, *controllerPort, *podName, *podNamespace)
if err != nil {
klog.Fatalf("Failed to validate controller endpoint: %w", err)
Expand Down

0 comments on commit 43ebc4b

Please sign in to comment.