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 27, 2023
1 parent 1712b73 commit 85c93a7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ ifneq ($(TAG),latest)
BUNDLE_VERSION ?= --version=$(shell sed s/^v// <<< $(TAG))
endif

# To get the GIT commit id
GIT_COMMIT ?= $(shell git rev-list -1 HEAD)

# Fetch the git tag
GIT_TAG ?= $(shell git describe --tags HEAD 2>/dev/null || echo $(GIT_COMMIT))

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

LDFLAGS ?=
LDFLAGS += -X $(GO_PROJECT)/internal/version.GitCommit=$(GIT_COMMIT)
LDFLAGS += -X $(GO_PROJECT)/internal/version.Version=$(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 @@ -158,8 +170,8 @@ 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/manager cmd/manager/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
8 changes: 8 additions & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
replicationController "github.com/csi-addons/kubernetes-csi-addons/controllers/replication.storage"
"github.com/csi-addons/kubernetes-csi-addons/internal/connection"
"github.com/csi-addons/kubernetes-csi-addons/internal/util"
"github.com/csi-addons/kubernetes-csi-addons/internal/version"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
Expand Down Expand Up @@ -68,6 +69,7 @@ func main() {
probeAddr string
enableLeaderElection bool
enableAdmissionWebhooks bool
showVersion bool
ctx = context.Background()
cfg = util.NewConfig()
)
Expand All @@ -80,13 +82,19 @@ func main() {
flag.IntVar(&cfg.MaxConcurrentReconciles, "max-concurrent-reconciles", cfg.MaxConcurrentReconciles, "Maximum number of concurrent reconciles")
flag.StringVar(&cfg.Namespace, "namespace", cfg.Namespace, "Namespace where the CSIAddons pod is deployed")
flag.BoolVar(&enableAdmissionWebhooks, "enable-admission-webhooks", true, "Enable the admission webhooks")
flag.BoolVar(&showVersion, "version", false, "Print Version details")
opts := zap.Options{
Development: true,
TimeEncoder: zapcore.ISO8601TimeEncoder,
}
opts.BindFlags(flag.CommandLine)
flag.Parse()

if showVersion {
version.PrintVersion()
return
}

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

kubeConfig := ctrl.GetConfigOrDie()
Expand Down
37 changes: 37 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2023 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.
Version string
)

func PrintVersion() {
fmt.Println("Version:", Version)
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)
}
12 changes: 10 additions & 2 deletions sidecar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package main

import (
"flag"
"time"

"time"
"github.com/csi-addons/kubernetes-csi-addons/internal/sidecar/service"
"github.com/csi-addons/kubernetes-csi-addons/internal/version"
"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"
Expand All @@ -46,13 +46,21 @@ func main() {
podName = flag.String("pod", "", "name of the Pod that contains this sidecar")
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")
showVersion = flag.Bool("version", false, "Print Version details")
)
klog.InitFlags(nil)

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

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 85c93a7

Please sign in to comment.