Remove providers (#670)
* Move all but mock provider out of tree These have all been moved to repos under github.com/virtual-kubelet. * Introduce a providers.Store This essentially moves the the old register/ handling into a first class object that can be controlled from the CLI rather than through build tags deep in the code. This actually would have made it a bit easier to build the provider repos and makes the cmd/ code more re-usable.
This commit is contained in:
@@ -19,12 +19,12 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers/register"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers"
|
||||
)
|
||||
|
||||
// NewCommand creates a new providers subcommand
|
||||
// This subcommand is used to determine which providers are registered.
|
||||
func NewCommand() *cobra.Command {
|
||||
func NewCommand(s *providers.Store) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "providers",
|
||||
Short: "Show the list of supported providers",
|
||||
@@ -33,12 +33,11 @@ func NewCommand() *cobra.Command {
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
switch len(args) {
|
||||
case 0:
|
||||
ls := register.List()
|
||||
for _, p := range ls {
|
||||
for _, p := range s.List() {
|
||||
fmt.Fprintln(cmd.OutOrStdout(), p)
|
||||
}
|
||||
case 1:
|
||||
if !register.Exists(args[0]) {
|
||||
if !s.Exists(args[0]) {
|
||||
fmt.Fprintln(cmd.OutOrStderr(), "no such provider", args[0])
|
||||
|
||||
// TODO(@cpuuy83): would be nice to not short-circuit the exit here
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"github.com/virtual-kubelet/virtual-kubelet/manager"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/node"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers/register"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -44,7 +43,7 @@ import (
|
||||
|
||||
// NewCommand creates a new top-level command.
|
||||
// This command is used to start the virtual-kubelet daemon
|
||||
func NewCommand(ctx context.Context, name string, c Opts) *cobra.Command {
|
||||
func NewCommand(ctx context.Context, name string, s *providers.Store, c Opts) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: name,
|
||||
Short: name + " provides a virtual kubelet interface for your kubernetes cluster.",
|
||||
@@ -52,7 +51,7 @@ func NewCommand(ctx context.Context, name string, c Opts) *cobra.Command {
|
||||
backend implementation allowing users to create kubernetes nodes without running the kubelet.
|
||||
This allows users to schedule kubernetes workloads on nodes that aren't running Kubernetes.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runRootCommand(ctx, c)
|
||||
return runRootCommand(ctx, s, c)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -60,7 +59,7 @@ This allows users to schedule kubernetes workloads on nodes that aren't running
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runRootCommand(ctx context.Context, c Opts) error {
|
||||
func runRootCommand(ctx context.Context, s *providers.Store, c Opts) error {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
@@ -120,7 +119,7 @@ func runRootCommand(ctx context.Context, c Opts) error {
|
||||
return err
|
||||
}
|
||||
|
||||
initConfig := register.InitConfig{
|
||||
initConfig := providers.InitConfig{
|
||||
ConfigPath: c.ProviderConfigPath,
|
||||
NodeName: c.NodeName,
|
||||
OperatingSystem: c.OperatingSystem,
|
||||
@@ -129,9 +128,14 @@ func runRootCommand(ctx context.Context, c Opts) error {
|
||||
InternalIP: os.Getenv("VKUBELET_POD_IP"),
|
||||
}
|
||||
|
||||
p, err := register.GetProvider(c.Provider, initConfig)
|
||||
pInit := s.Get(c.Provider)
|
||||
if pInit == nil {
|
||||
return errors.Errorf("provider %q not found", c.Provider)
|
||||
}
|
||||
|
||||
p, err := pInit(initConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrapf(err, "error initializing provider %s", c.Provider)
|
||||
}
|
||||
|
||||
ctx = log.WithLogger(ctx, log.G(ctx).WithFields(log.Fields{
|
||||
|
||||
@@ -25,11 +25,12 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/cmd/virtual-kubelet/commands/providers"
|
||||
cmdproviders "github.com/virtual-kubelet/virtual-kubelet/cmd/virtual-kubelet/commands/providers"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/cmd/virtual-kubelet/commands/root"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/cmd/virtual-kubelet/commands/version"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/log"
|
||||
logruslogger "github.com/virtual-kubelet/virtual-kubelet/log/logrus"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/trace"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/trace/opencensus"
|
||||
)
|
||||
@@ -56,8 +57,11 @@ func main() {
|
||||
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(buildVersion, buildTime), providers.NewCommand())
|
||||
s := providers.NewStore()
|
||||
registerMock(s)
|
||||
|
||||
rootCmd := root.NewCommand(ctx, filepath.Base(os.Args[0]), s, opts)
|
||||
rootCmd.AddCommand(version.NewCommand(buildVersion, buildTime), cmdproviders.NewCommand(s))
|
||||
preRun := rootCmd.PreRunE
|
||||
|
||||
var logLevel string
|
||||
|
||||
28
cmd/virtual-kubelet/register.go
Normal file
28
cmd/virtual-kubelet/register.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers/mock"
|
||||
)
|
||||
|
||||
func registerMock(s *providers.Store) {
|
||||
s.Register("mock", func(cfg providers.InitConfig) (providers.Provider, error) {
|
||||
return mock.NewMockProvider(
|
||||
cfg.ConfigPath,
|
||||
cfg.NodeName,
|
||||
cfg.OperatingSystem,
|
||||
cfg.InternalIP,
|
||||
cfg.DaemonPort,
|
||||
)
|
||||
})
|
||||
|
||||
s.Register("mockV0", func(cfg providers.InitConfig) (providers.Provider, error) {
|
||||
return mock.NewMockProvider(
|
||||
cfg.ConfigPath,
|
||||
cfg.NodeName,
|
||||
cfg.OperatingSystem,
|
||||
cfg.InternalIP,
|
||||
cfg.DaemonPort,
|
||||
)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user