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:
2
Makefile
2
Makefile
@@ -142,7 +142,7 @@ setup: goimports gocovmerge goreleaser gox clean
|
|||||||
|
|
||||||
VERSION := $(shell git describe --tags --always --dirty="-dev")
|
VERSION := $(shell git describe --tags --always --dirty="-dev")
|
||||||
DATE := $(shell date -u '+%Y-%m-%d-%H:%M UTC')
|
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!!
|
# assuming go 1.9 here!!
|
||||||
_allpackages = $(shell go list ./...)
|
_allpackages = $(shell go list ./...)
|
||||||
|
|||||||
@@ -20,21 +20,14 @@ import (
|
|||||||
|
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
|
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/providers"
|
"github.com/virtual-kubelet/virtual-kubelet/providers"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/version"
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/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
|
// 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.
|
// 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)
|
taints := make([]v1.Taint, 0)
|
||||||
|
|
||||||
if taint != nil {
|
if taint != nil {
|
||||||
@@ -59,7 +52,7 @@ func NodeFromProvider(ctx context.Context, name string, taint *v1.Taint, p provi
|
|||||||
NodeInfo: v1.NodeSystemInfo{
|
NodeInfo: v1.NodeSystemInfo{
|
||||||
OperatingSystem: p.OperatingSystem(),
|
OperatingSystem: p.OperatingSystem(),
|
||||||
Architecture: "amd64",
|
Architecture: "amd64",
|
||||||
KubeletVersion: vkVersion,
|
KubeletVersion: version,
|
||||||
},
|
},
|
||||||
Capacity: p.Capacity(ctx),
|
Capacity: p.Capacity(ctx),
|
||||||
Allocatable: p.Capacity(ctx),
|
Allocatable: p.Capacity(ctx),
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ type Opts struct {
|
|||||||
|
|
||||||
// Startup Timeout is how long to wait for the kubelet to start
|
// Startup Timeout is how long to wait for the kubelet to start
|
||||||
StartupTimeout time.Duration
|
StartupTimeout time.Duration
|
||||||
|
|
||||||
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDefaultOpts sets default options for unset values on the passed in option struct.
|
// SetDefaultOpts sets default options for unset values on the passed in option struct.
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ func runRootCommand(ctx context.Context, c Opts) error {
|
|||||||
leaseClient = client.CoordinationV1beta1().Leases(corev1.NamespaceNodeLease)
|
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(
|
nodeRunner, err := node.NewNodeController(
|
||||||
node.NaiveNodeProvider{},
|
node.NaiveNodeProvider{},
|
||||||
pNode,
|
pNode,
|
||||||
|
|||||||
@@ -18,17 +18,16 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/version"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCommand creates a new version subcommand command
|
// NewCommand creates a new version subcommand command
|
||||||
func NewCommand() *cobra.Command {
|
func NewCommand(version, buildTime string) *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Show the version of the program",
|
Short: "Show the version of the program",
|
||||||
Long: `Show the version of the program`,
|
Long: `Show the version of the program`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
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)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -33,6 +34,12 @@ import (
|
|||||||
"github.com/virtual-kubelet/virtual-kubelet/trace/opencensus"
|
"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() {
|
func main() {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
sig := make(chan os.Signal, 1)
|
sig := make(chan os.Signal, 1)
|
||||||
@@ -47,9 +54,10 @@ func main() {
|
|||||||
|
|
||||||
var opts root.Opts
|
var opts root.Opts
|
||||||
optsErr := root.SetDefaultOpts(&opts)
|
optsErr := root.SetDefaultOpts(&opts)
|
||||||
|
opts.Version = strings.Join([]string{k8sVersion, "vk", buildVersion}, "-")
|
||||||
|
|
||||||
rootCmd := root.NewCommand(ctx, filepath.Base(os.Args[0]), opts)
|
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
|
preRun := rootCmd.PreRunE
|
||||||
|
|
||||||
var logLevel string
|
var logLevel string
|
||||||
|
|||||||
@@ -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"
|
|
||||||
)
|
|
||||||
Reference in New Issue
Block a user