Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable --version flag #131

Merged
merged 2 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ GOOS=linux
PACKAGE=sigs.k8s.io/node-feature-discovery-operator
MAIN_PACKAGE=main.go
BIN=node-feature-discovery-operator
LDFLAGS = -ldflags "-s -w -X sigs.k8s.io/node-feature-discovery-operator/pkg/version.version=$(VERSION)"

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

Expand All @@ -100,7 +101,7 @@ go_mod:

# Build binary
build: go_mod
@GOOS=$(GOOS) GO111MODULE=on CGO_ENABLED=0 $(GO_CMD) build -o $(BIN) $(MAIN_PACKAGE)
@GOOS=$(GOOS) GO111MODULE=on CGO_ENABLED=0 $(GO_CMD) build -o $(BIN) $(LDFLAGS) $(MAIN_PACKAGE)

# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"os"

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

"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -34,6 +33,7 @@ import (
nfdkubernetesiov1 "sigs.k8s.io/node-feature-discovery-operator/api/v1"
"sigs.k8s.io/node-feature-discovery-operator/controllers"
"sigs.k8s.io/node-feature-discovery-operator/pkg/utils"
"sigs.k8s.io/node-feature-discovery-operator/pkg/version"
// +kubebuilder:scaffold:imports
)

Expand Down
22 changes: 16 additions & 6 deletions version/version.go → pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
Copyright 2020 The Kubernetes Authors.
Copyright 2022 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
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,
Expand All @@ -16,7 +16,17 @@ limitations under the License.

package version

var (
// Version tracks the NFD operator release
Version = "0.0.1"
)
const undefinedVersion string = "undefined"

// Must not be const, supposed to be set using ldflags at build time
var version = undefinedVersion

// Get returns the version as a string
func Get() string {
return version
}

// Undefined returns if version is at it's default value
func Undefined() bool {
return version == undefinedVersion
}