From c6fdae931a4ec3c9dcca04481174e1c5b592bc9d Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Fri, 14 Jun 2019 12:19:39 -0700 Subject: [PATCH] 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. --- Makefile | 2 +- cmd/virtual-kubelet/commands/root/node.go | 11 ++--------- cmd/virtual-kubelet/commands/root/opts.go | 2 ++ cmd/virtual-kubelet/commands/root/root.go | 2 +- cmd/virtual-kubelet/commands/version/version.go | 5 ++--- cmd/virtual-kubelet/main.go | 10 +++++++++- version/version.go | 8 -------- 7 files changed, 17 insertions(+), 23 deletions(-) delete mode 100644 version/version.go diff --git a/Makefile b/Makefile index 3b0eb9548..f1268218b 100644 --- a/Makefile +++ b/Makefile @@ -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 ./...) diff --git a/cmd/virtual-kubelet/commands/root/node.go b/cmd/virtual-kubelet/commands/root/node.go index 728575688..74227a63c 100644 --- a/cmd/virtual-kubelet/commands/root/node.go +++ b/cmd/virtual-kubelet/commands/root/node.go @@ -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), diff --git a/cmd/virtual-kubelet/commands/root/opts.go b/cmd/virtual-kubelet/commands/root/opts.go index 7b3c46da0..e0829706f 100644 --- a/cmd/virtual-kubelet/commands/root/opts.go +++ b/cmd/virtual-kubelet/commands/root/opts.go @@ -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. diff --git a/cmd/virtual-kubelet/commands/root/root.go b/cmd/virtual-kubelet/commands/root/root.go index 037cb3421..ab4186948 100644 --- a/cmd/virtual-kubelet/commands/root/root.go +++ b/cmd/virtual-kubelet/commands/root/root.go @@ -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, diff --git a/cmd/virtual-kubelet/commands/version/version.go b/cmd/virtual-kubelet/commands/version/version.go index 73f3e3967..88e0bcf7b 100644 --- a/cmd/virtual-kubelet/commands/version/version.go +++ b/cmd/virtual-kubelet/commands/version/version.go @@ -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) }, } } diff --git a/cmd/virtual-kubelet/main.go b/cmd/virtual-kubelet/main.go index e3f462cad..e96b5dc89 100644 --- a/cmd/virtual-kubelet/main.go +++ b/cmd/virtual-kubelet/main.go @@ -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 diff --git a/version/version.go b/version/version.go deleted file mode 100644 index 350712c08..000000000 --- a/version/version.go +++ /dev/null @@ -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" -)