Skip to content

Commit

Permalink
Add version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny-Wei committed Dec 12, 2024
1 parent 4c724e2 commit 1be3b7c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmd/varmor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ RUN apt-get update
RUN apt-get install -y libseccomp2 libseccomp-dev
RUN GOOS=$(echo ${TARGETPLATFORM} | cut -d / -f1) && \
GOARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) && \
ClientGoPath="k8s.io/client-go/pkg" && \
GOVERSION=$(go version | awk '{print $3}') && \
go build -o /output/vArmor -v \
-ldflags "-w -X '${ClientGoPath}/version.gitVersion=${GITVERSION}' \
-X '${ClientGoPath}/version.gitCommit=${GITCOMMIT}' \
-X '${ClientGoPath}/version.buildDate=${BUILDDATE}'" \
-ldflags "-w -X 'k8s.io/client-go/pkg/version.gitVersion=${GITVERSION}' \
-X 'k8s.io/client-go/pkg/version.gitCommit=${GITCOMMIT}' \
-X 'k8s.io/client-go/pkg/version.buildDate=${BUILDDATE}' \
-X 'main.gitVersion=${GITVERSION}' \
-X 'main.gitCommit=${GITCOMMIT}' \
-X 'main.buildDate=${BUILDDATE}' \
-X 'main.goVersion=${GOVERSION}'" \
./cmd/varmor/


Expand Down
11 changes: 11 additions & 0 deletions cmd/varmor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ const (
)

var (
versionFlag bool
gitVersion string
gitCommit string
buildDate string
goVersion string
kubeconfig string
agent bool
enableBpfEnforcer bool
Expand All @@ -78,6 +83,7 @@ func main() {
c.AddFlags(flag.CommandLine)
log.SetLogger(textlogger.NewLogger(c))

flag.BoolVar(&versionFlag, "version", false, "Print the version information.")
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
flag.BoolVar(&agent, "agent", false, "Set this flag to run vArmor agent. Run vArmor manager default if true.")
flag.BoolVar(&enableBpfEnforcer, "enableBpfEnforcer", false, "Set this flag to enable BPF enforcer.")
Expand All @@ -97,6 +103,11 @@ func main() {
//flag.IntVar(&syncMetricsSecond, "syncMetricsSecond", 10, "Configure the profile metric update seconds")
flag.Parse()

if versionFlag {
fmt.Printf("GitVersion: %s\nGitCommit: %s\nBuildDate: %s\nGoVersion: %s\n", gitVersion, gitCommit, buildDate, goVersion)
return
}

// Set the webhook matchLabels configuration.
if webhookMatchLabel != "" {
labelKvs := strings.Split(webhookMatchLabel, "=")
Expand Down

0 comments on commit 1be3b7c

Please sign in to comment.