mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-14 11:57:51 +00:00
Move version information into a separate module
This commit is contained in:
parent
2bf4d6f1f4
commit
c1377589b3
4 changed files with 33 additions and 11 deletions
|
@ -10,7 +10,7 @@ ARG NFD_VERSION
|
|||
RUN go get github.com/golang/dep/cmd/dep
|
||||
RUN dep ensure
|
||||
RUN go install \
|
||||
-ldflags "-s -w -X main.version=$NFD_VERSION" \
|
||||
-ldflags "-s -w -X sigs.k8s.io/node-feature-discovery/pkg/version.version=$NFD_VERSION" \
|
||||
sigs.k8s.io/node-feature-discovery
|
||||
RUN install -D -m644 node-feature-discovery.conf.example /etc/kubernetes/node-feature-discovery/node-feature-discovery.conf
|
||||
|
||||
|
|
15
main.go
15
main.go
|
@ -17,6 +17,7 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/validation"
|
||||
k8sclient "k8s.io/client-go/kubernetes"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"sigs.k8s.io/node-feature-discovery/pkg/version"
|
||||
"sigs.k8s.io/node-feature-discovery/source"
|
||||
"sigs.k8s.io/node-feature-discovery/source/cpu"
|
||||
"sigs.k8s.io/node-feature-discovery/source/cpuid"
|
||||
|
@ -48,10 +49,6 @@ const (
|
|||
NodeNameEnv = "NODE_NAME"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "" // Must not be const, set using ldflags at build time
|
||||
)
|
||||
|
||||
// package loggers
|
||||
var (
|
||||
stdoutLogger = log.New(os.Stdout, "", log.LstdFlags)
|
||||
|
@ -115,10 +112,10 @@ type Args struct {
|
|||
|
||||
func main() {
|
||||
// Assert that the version is known
|
||||
if version == "" {
|
||||
stderrLogger.Fatalf("main.version not set! Set -ldflags \"-X main.version `git describe --tags --dirty --always`\" during build or run.")
|
||||
if version.Get() == "undefined" {
|
||||
stderrLogger.Fatalf("version not set! Set -ldflags \"-X sigs.k8s.io/node-feature-discovery/pkg/version.version=`git describe --tags --dirty --always`\" during build or run.")
|
||||
}
|
||||
stdoutLogger.Printf("Node Feature Discovery %s", version)
|
||||
stdoutLogger.Printf("Node Feature Discovery %s", version.Get())
|
||||
|
||||
// Parse command-line arguments.
|
||||
args := argsParse(nil)
|
||||
|
@ -199,7 +196,7 @@ func argsParse(argv []string) (args Args) {
|
|||
)
|
||||
|
||||
arguments, _ := docopt.Parse(usage, argv, true,
|
||||
fmt.Sprintf("%s %s", ProgramName, version), false)
|
||||
fmt.Sprintf("%s %s", ProgramName, version.Get()), false)
|
||||
|
||||
// Parse argument values as usable types.
|
||||
var err error
|
||||
|
@ -332,7 +329,7 @@ func updateNodeWithFeatureLabels(helper APIHelpers, noPublish bool, labels Label
|
|||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
annotations := Annotations{"version": version,
|
||||
annotations := Annotations{"version": version.Get(),
|
||||
"feature-labels": strings.Join(keys, ",")}
|
||||
|
||||
err := advertiseFeatureLabels(helper, labels, annotations)
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
"sigs.k8s.io/node-feature-discovery/source"
|
||||
"sigs.k8s.io/node-feature-discovery/source/fake"
|
||||
"sigs.k8s.io/node-feature-discovery/source/panic_fake"
|
||||
"sigs.k8s.io/node-feature-discovery/pkg/version"
|
||||
)
|
||||
|
||||
func TestDiscoveryWithMockSources(t *testing.T) {
|
||||
|
@ -26,7 +27,7 @@ func TestDiscoveryWithMockSources(t *testing.T) {
|
|||
fakeFeatureNames := []string{"testfeature1", "testfeature2", "testfeature3"}
|
||||
fakeFeatures := source.Features{}
|
||||
fakeFeatureLabels := Labels{}
|
||||
fakeAnnotations := Annotations{"version": version,
|
||||
fakeAnnotations := Annotations{"version": version.Get(),
|
||||
"feature-labels": "testSource-testfeature1,testSource-testfeature2,testSource-testfeature3"}
|
||||
fakeFeatureLabelNames := make([]string, 0, len(fakeFeatureNames))
|
||||
for _, f := range fakeFeatureNames {
|
||||
|
|
24
pkg/version/version.go
Normal file
24
pkg/version/version.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
Copyright 2019 The Kubernetes 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
|
||||
|
||||
// Must not be const, supposed to be set using ldflags at build time
|
||||
var version = "undefined"
|
||||
|
||||
func Get() string {
|
||||
return version
|
||||
}
|
Loading…
Reference in a new issue