Skip to content

Commit a7b9628

Browse files
authored
Merge pull request #131 from ArangoGutierrez/devel/123
Enable --version flag
2 parents 48f50b3 + a06710a commit a7b9628

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ GOOS=linux
8484
PACKAGE=sigs.k8s.io/node-feature-discovery-operator
8585
MAIN_PACKAGE=main.go
8686
BIN=node-feature-discovery-operator
87+
LDFLAGS = -ldflags "-s -w -X sigs.k8s.io/node-feature-discovery-operator/pkg/version.version=$(VERSION)"
8788

8889
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
8990

@@ -100,7 +101,7 @@ go_mod:
100101

101102
# Build binary
102103
build: go_mod
103-
@GOOS=$(GOOS) GO111MODULE=on CGO_ENABLED=0 $(GO_CMD) build -o $(BIN) $(MAIN_PACKAGE)
104+
@GOOS=$(GOOS) GO111MODULE=on CGO_ENABLED=0 $(GO_CMD) build -o $(BIN) $(LDFLAGS) $(MAIN_PACKAGE)
104105

105106
# Run against the configured Kubernetes cluster in ~/.kube/config
106107
run: generate fmt vet manifests

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"os"
2323

2424
_ "k8s.io/client-go/plugin/pkg/client/auth"
25-
"k8s.io/component-base/version"
2625
"k8s.io/klog/v2"
2726

2827
"k8s.io/apimachinery/pkg/runtime"
@@ -34,6 +33,7 @@ import (
3433
nfdkubernetesiov1 "sigs.k8s.io/node-feature-discovery-operator/api/v1"
3534
"sigs.k8s.io/node-feature-discovery-operator/controllers"
3635
"sigs.k8s.io/node-feature-discovery-operator/pkg/utils"
36+
"sigs.k8s.io/node-feature-discovery-operator/pkg/version"
3737
// +kubebuilder:scaffold:imports
3838
)
3939

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
Copyright 2020 The Kubernetes Authors.
2+
Copyright 2022 The Kubernetes Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
77
8-
http://www.apache.org/licenses/LICENSE-2.0
8+
http://www.apache.org/licenses/LICENSE-2.0
99
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,7 +16,17 @@ limitations under the License.
1616

1717
package version
1818

19-
var (
20-
// Version tracks the NFD operator release
21-
Version = "0.0.1"
22-
)
19+
const undefinedVersion string = "undefined"
20+
21+
// Must not be const, supposed to be set using ldflags at build time
22+
var version = undefinedVersion
23+
24+
// Get returns the version as a string
25+
func Get() string {
26+
return version
27+
}
28+
29+
// Undefined returns if version is at it's default value
30+
func Undefined() bool {
31+
return version == undefinedVersion
32+
}

0 commit comments

Comments
 (0)