Remove version package (#667)

This moves version declaration into cmd/virtual-kubelet/main.go
From here values are passed down into the things that need it.
This commit is contained in:
Brian Goff
2019-06-14 12:19:39 -07:00
committed by Pires
parent cacce3b288
commit c6fdae931a
7 changed files with 17 additions and 23 deletions

View File

@@ -142,7 +142,7 @@ setup: goimports gocovmerge goreleaser gox clean
VERSION := $(shell git describe --tags --always --dirty="-dev")
DATE := $(shell date -u '+%Y-%m-%d-%H:%M UTC')
VERSION_FLAGS := -ldflags='-X "github.com/virtual-kubelet/virtual-kubelet/version.Version=$(VERSION)" -X "github.com/virtual-kubelet/virtual-kubelet/version.BuildTime=$(DATE)"'
VERSION_FLAGS := -ldflags='-X "main.buildVersion=$(VERSION)" -X "main.buildTime=$(DATE)"'
# assuming go 1.9 here!!
_allpackages = $(shell go list ./...)

View File

@@ -20,21 +20,14 @@ import (
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
"github.com/virtual-kubelet/virtual-kubelet/providers"
"github.com/virtual-kubelet/virtual-kubelet/version"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var (
// vkVersion is a concatenation of the Kubernetes version the VK is built against, the string "vk" and the VK release version.
// TODO @pires revisit after VK 1.0 is released as agreed in https://github.com/virtual-kubelet/virtual-kubelet/pull/446#issuecomment-448423176.
vkVersion = strings.Join([]string{"v1.13.1", "vk", version.Version}, "-")
)
// NodeFromProvider builds a kubernetes node object from a provider
// This is a temporary solution until node stuff actually split off from the provider interface itself.
func NodeFromProvider(ctx context.Context, name string, taint *v1.Taint, p providers.Provider) *v1.Node {
func NodeFromProvider(ctx context.Context, name string, taint *v1.Taint, p providers.Provider, version string) *v1.Node {
taints := make([]v1.Taint, 0)
if taint != nil {
@@ -59,7 +52,7 @@ func NodeFromProvider(ctx context.Context, name string, taint *v1.Taint, p provi
NodeInfo: v1.NodeSystemInfo{
OperatingSystem: p.OperatingSystem(),
Architecture: "amd64",
KubeletVersion: vkVersion,
KubeletVersion: version,
},
Capacity: p.Capacity(ctx),
Allocatable: p.Capacity(ctx),

View File

@@ -80,6 +80,8 @@ type Opts struct {
// Startup Timeout is how long to wait for the kubelet to start
StartupTimeout time.Duration
Version string
}
// SetDefaultOpts sets default options for unset values on the passed in option struct.

View File

@@ -146,7 +146,7 @@ func runRootCommand(ctx context.Context, c Opts) error {
leaseClient = client.CoordinationV1beta1().Leases(corev1.NamespaceNodeLease)
}
pNode := NodeFromProvider(ctx, c.NodeName, taint, p)
pNode := NodeFromProvider(ctx, c.NodeName, taint, p, c.Version)
nodeRunner, err := node.NewNodeController(
node.NaiveNodeProvider{},
pNode,

View File

@@ -18,17 +18,16 @@ import (
"fmt"
"github.com/spf13/cobra"
"github.com/virtual-kubelet/virtual-kubelet/version"
)
// NewCommand creates a new version subcommand command
func NewCommand() *cobra.Command {
func NewCommand(version, buildTime string) *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Show the version of the program",
Long: `Show the version of the program`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Version: %s, Built: %s\n", version.Version, version.BuildTime)
fmt.Printf("Version: %s, Built: %s\n", version, buildTime)
},
}
}

View File

@@ -19,6 +19,7 @@ import (
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"github.com/pkg/errors"
@@ -33,6 +34,12 @@ import (
"github.com/virtual-kubelet/virtual-kubelet/trace/opencensus"
)
var (
buildVersion = "N/A"
buildTime = "N/A"
k8sVersion = "v1.13.1" // This should follow the version of k8s.io/kubernetes we are importing
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
sig := make(chan os.Signal, 1)
@@ -47,9 +54,10 @@ func main() {
var opts root.Opts
optsErr := root.SetDefaultOpts(&opts)
opts.Version = strings.Join([]string{k8sVersion, "vk", buildVersion}, "-")
rootCmd := root.NewCommand(ctx, filepath.Base(os.Args[0]), opts)
rootCmd.AddCommand(version.NewCommand(), providers.NewCommand())
rootCmd.AddCommand(version.NewCommand(buildVersion, buildTime), providers.NewCommand())
preRun := rootCmd.PreRunE
var logLevel string

View File

@@ -1,8 +0,0 @@
package version
var (
// Version holds the value for the binary version. It is a compile time variable.
Version = "N/A"
// BuildTime is a compile time variable for the binary build time.
BuildTime = "N/A"
)