Repository: virtual-kubelet/virtual-kubelet
Pull request #697 (2019-07-03 19:40:34)

Move CLI related packages into internal
We don't want people to import these packages, so move these out into
private packages.

cpuguy83: Doing this as an alternative to #687. That PR is working, but modules is being problematic (e.g. `go mod tidy` keeps acting like it is missing modules when it's not... everything builds fine but `go mod tidy` keeps having problems with `golang.org/x/time/rate`

Patch:
diff --git a/cmd/virtual-kubelet/commands/providers/provider.go b/cmd/virtual-kubelet/internal/commands/providers/provider.go
similarity index 91%
rename from cmd/virtual-kubelet/commands/providers/provider.go
rename to cmd/virtual-kubelet/internal/commands/providers/provider.go
index 570c7a07..7d880d5c 100644
--- a/cmd/virtual-kubelet/commands/providers/provider.go
+++ b/cmd/virtual-kubelet/internal/commands/providers/provider.go
@@ -19,12 +19,12 @@ import (
 	"os"
 
 	"github.com/spf13/cobra"
-	"github.com/virtual-kubelet/virtual-kubelet/providers"
+	"github.com/virtual-kubelet/virtual-kubelet/cmd/virtual-kubelet/internal/provider"
 )
 
 // NewCommand creates a new providers subcommand
 // This subcommand is used to determine which providers are registered.
-func NewCommand(s *providers.Store) *cobra.Command {
+func NewCommand(s *provider.Store) *cobra.Command {
 	return &cobra.Command{
 		Use:   "providers",
 		Short: "Show the list of supported providers",
diff --git a/cmd/virtual-kubelet/commands/root/flag.go b/cmd/virtual-kubelet/internal/commands/root/flag.go
similarity index 100%
rename from cmd/virtual-kubelet/commands/root/flag.go
rename to cmd/virtual-kubelet/internal/commands/root/flag.go
diff --git a/cmd/virtual-kubelet/commands/root/http.go b/cmd/virtual-kubelet/internal/commands/root/http.go
similarity index 94%
rename from cmd/virtual-kubelet/commands/root/http.go
rename to cmd/virtual-kubelet/internal/commands/root/http.go
index 8ffba86f..3d02abfe 100644
--- a/cmd/virtual-kubelet/commands/root/http.go
+++ b/cmd/virtual-kubelet/internal/commands/root/http.go
@@ -24,9 +24,9 @@ import (
 	"os"
 
 	"github.com/pkg/errors"
+	"github.com/virtual-kubelet/virtual-kubelet/cmd/virtual-kubelet/internal/provider"
 	"github.com/virtual-kubelet/virtual-kubelet/log"
 	"github.com/virtual-kubelet/virtual-kubelet/node/api"
-	"github.com/virtual-kubelet/virtual-kubelet/providers"
 )
 
 // AcceptedCiphers is the list of accepted TLS ciphers, with known weak ciphers elided
@@ -57,7 +57,7 @@ func loadTLSConfig(certPath, keyPath string) (*tls.Config, error) {
 	}, nil
 }
 
-func setupHTTPServer(ctx context.Context, p providers.Provider, cfg *apiServerConfig) (_ func(), retErr error) {
+func setupHTTPServer(ctx context.Context, p provider.Provider, cfg *apiServerConfig) (_ func(), retErr error) {
 	var closers []io.Closer
 	cancel := func() {
 		for _, c := range closers {
@@ -113,7 +113,7 @@ func setupHTTPServer(ctx context.Context, p providers.Provider, cfg *apiServerCo
 		mux := http.NewServeMux()
 
 		var summaryHandlerFunc api.PodStatsSummaryHandlerFunc
-		if mp, ok := p.(providers.PodMetricsProvider); ok {
+		if mp, ok := p.(provider.PodMetricsProvider); ok {
 			summaryHandlerFunc = mp.GetStatsSummary
 		}
 		podMetricsRoutes := api.PodMetricsConfig{
diff --git a/cmd/virtual-kubelet/commands/root/node.go b/cmd/virtual-kubelet/internal/commands/root/node.go
similarity index 95%
rename from cmd/virtual-kubelet/commands/root/node.go
rename to cmd/virtual-kubelet/internal/commands/root/node.go
index d1b6c08a..876bcd7d 100644
--- a/cmd/virtual-kubelet/commands/root/node.go
+++ b/cmd/virtual-kubelet/internal/commands/root/node.go
@@ -18,8 +18,8 @@ import (
 	"context"
 	"strings"
 
+	"github.com/virtual-kubelet/virtual-kubelet/cmd/virtual-kubelet/internal/provider"
 	"github.com/virtual-kubelet/virtual-kubelet/errdefs"
-	"github.com/virtual-kubelet/virtual-kubelet/providers"
 	corev1 "k8s.io/api/core/v1"
 	v1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -29,7 +29,7 @@ const osLabel = "beta.kubernetes.io/os"
 
 // 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, version string) *v1.Node {
+func NodeFromProvider(ctx context.Context, name string, taint *v1.Taint, p provider.Provider, version string) *v1.Node {
 	taints := make([]v1.Taint, 0)
 
 	if taint != nil {
diff --git a/cmd/virtual-kubelet/commands/root/opts.go b/cmd/virtual-kubelet/internal/commands/root/opts.go
similarity index 100%
rename from cmd/virtual-kubelet/commands/root/opts.go
rename to cmd/virtual-kubelet/internal/commands/root/opts.go
diff --git a/cmd/virtual-kubelet/commands/root/root.go b/cmd/virtual-kubelet/internal/commands/root/root.go
similarity index 92%
rename from cmd/virtual-kubelet/commands/root/root.go
rename to cmd/virtual-kubelet/internal/commands/root/root.go
index 715cfd8c..c7bd555d 100644
--- a/cmd/virtual-kubelet/commands/root/root.go
+++ b/cmd/virtual-kubelet/internal/commands/root/root.go
@@ -22,11 +22,11 @@ import (
 
 	"github.com/pkg/errors"
 	"github.com/spf13/cobra"
+	"github.com/virtual-kubelet/virtual-kubelet/cmd/virtual-kubelet/internal/provider"
 	"github.com/virtual-kubelet/virtual-kubelet/errdefs"
+	"github.com/virtual-kubelet/virtual-kubelet/internal/manager"
 	"github.com/virtual-kubelet/virtual-kubelet/log"
-	"github.com/virtual-kubelet/virtual-kubelet/manager"
 	"github.com/virtual-kubelet/virtual-kubelet/node"
-	"github.com/virtual-kubelet/virtual-kubelet/providers"
 	corev1 "k8s.io/api/core/v1"
 	k8serrors "k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -43,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, s *providers.Store, c Opts) *cobra.Command {
+func NewCommand(ctx context.Context, name string, s *provider.Store, c Opts) *cobra.Command {
 	cmd := &cobra.Command{
 		Use:   name,
 		Short: name + " provides a virtual kubelet interface for your kubernetes cluster.",
@@ -59,11 +59,11 @@ This allows users to schedule kubernetes workloads on nodes that aren't running
 	return cmd
 }
 
-func runRootCommand(ctx context.Context, s *providers.Store, c Opts) error {
+func runRootCommand(ctx context.Context, s *provider.Store, c Opts) error {
 	ctx, cancel := context.WithCancel(ctx)
 	defer cancel()
 
-	if ok := providers.ValidOperatingSystems[c.OperatingSystem]; !ok {
+	if ok := provider.ValidOperatingSystems[c.OperatingSystem]; !ok {
 		return errdefs.InvalidInputf("operating system %q is not supported", c.OperatingSystem)
 	}
 
@@ -119,13 +119,13 @@ func runRootCommand(ctx context.Context, s *providers.Store, c Opts) error {
 		return err
 	}
 
-	initConfig := providers.InitConfig{
-		ConfigPath:      c.ProviderConfigPath,
-		NodeName:        c.NodeName,
-		OperatingSystem: c.OperatingSystem,
-		ResourceManager: rm,
-		DaemonPort:      int32(c.ListenPort),
-		InternalIP:      os.Getenv("VKUBELET_POD_IP"),
+	initConfig := provider.InitConfig{
+		ConfigPath:        c.ProviderConfigPath,
+		NodeName:          c.NodeName,
+		OperatingSystem:   c.OperatingSystem,
+		ResourceManager:   rm,
+		DaemonPort:        int32(c.ListenPort),
+		InternalIP:        os.Getenv("VKUBELET_POD_IP"),
 		KubeClusterDomain: c.KubeClusterDomain,
 	}
 
diff --git a/cmd/virtual-kubelet/commands/root/tracing.go b/cmd/virtual-kubelet/internal/commands/root/tracing.go
similarity index 100%
rename from cmd/virtual-kubelet/commands/root/tracing.go
rename to cmd/virtual-kubelet/internal/commands/root/tracing.go
diff --git a/cmd/virtual-kubelet/commands/root/tracing_register.go b/cmd/virtual-kubelet/internal/commands/root/tracing_register.go
similarity index 100%
rename from cmd/virtual-kubelet/commands/root/tracing_register.go
rename to cmd/virtual-kubelet/internal/commands/root/tracing_register.go
diff --git a/cmd/virtual-kubelet/commands/root/tracing_register_jaeger.go b/cmd/virtual-kubelet/internal/commands/root/tracing_register_jaeger.go
similarity index 100%
rename from cmd/virtual-kubelet/commands/root/tracing_register_jaeger.go
rename to cmd/virtual-kubelet/internal/commands/root/tracing_register_jaeger.go
diff --git a/cmd/virtual-kubelet/commands/root/tracing_register_ocagent.go b/cmd/virtual-kubelet/internal/commands/root/tracing_register_ocagent.go
similarity index 100%
rename from cmd/virtual-kubelet/commands/root/tracing_register_ocagent.go
rename to cmd/virtual-kubelet/internal/commands/root/tracing_register_ocagent.go
diff --git a/cmd/virtual-kubelet/commands/root/tracing_register_test.go b/cmd/virtual-kubelet/internal/commands/root/tracing_register_test.go
similarity index 100%
rename from cmd/virtual-kubelet/commands/root/tracing_register_test.go
rename to cmd/virtual-kubelet/internal/commands/root/tracing_register_test.go
diff --git a/cmd/virtual-kubelet/commands/version/version.go b/cmd/virtual-kubelet/internal/commands/version/version.go
similarity index 100%
rename from cmd/virtual-kubelet/commands/version/version.go
rename to cmd/virtual-kubelet/internal/commands/version/version.go
diff --git a/providers/README.md b/cmd/virtual-kubelet/internal/provider/README.md
similarity index 100%
rename from providers/README.md
rename to cmd/virtual-kubelet/internal/provider/README.md
diff --git a/providers/mock/mock.go b/cmd/virtual-kubelet/internal/provider/mock/mock.go
similarity index 100%
rename from providers/mock/mock.go
rename to cmd/virtual-kubelet/internal/provider/mock/mock.go
diff --git a/providers/mock/mock_test.go b/cmd/virtual-kubelet/internal/provider/mock/mock_test.go
similarity index 100%
rename from providers/mock/mock_test.go
rename to cmd/virtual-kubelet/internal/provider/mock/mock_test.go
diff --git a/providers/provider.go b/cmd/virtual-kubelet/internal/provider/provider.go
similarity index 98%
rename from providers/provider.go
rename to cmd/virtual-kubelet/internal/provider/provider.go
index 81d53f82..e6a654a6 100644
--- a/providers/provider.go
+++ b/cmd/virtual-kubelet/internal/provider/provider.go
@@ -1,4 +1,4 @@
-package providers
+package provider
 
 import (
 	"context"
diff --git a/providers/store.go b/cmd/virtual-kubelet/internal/provider/store.go
similarity index 94%
rename from providers/store.go
rename to cmd/virtual-kubelet/internal/provider/store.go
index 8799b12c..f711513f 100644
--- a/providers/store.go
+++ b/cmd/virtual-kubelet/internal/provider/store.go
@@ -1,10 +1,10 @@
-package providers
+package provider
 
 import (
 	"sync"
 
 	"github.com/virtual-kubelet/virtual-kubelet/errdefs"
-	"github.com/virtual-kubelet/virtual-kubelet/manager"
+	"github.com/virtual-kubelet/virtual-kubelet/internal/manager"
 )
 
 // Store is used for registering/fetching providers
diff --git a/providers/types.go b/cmd/virtual-kubelet/internal/provider/types.go
similarity index 97%
rename from providers/types.go
rename to cmd/virtual-kubelet/internal/provider/types.go
index 9c94e104..8c507840 100644
--- a/providers/types.go
+++ b/cmd/virtual-kubelet/internal/provider/types.go
@@ -1,4 +1,4 @@
-package providers
+package provider
 
 const (
 	// OperatingSystemLinux is the configuration value for defining Linux.
diff --git a/cmd/virtual-kubelet/main.go b/cmd/virtual-kubelet/main.go
index 43ae68df..749339a8 100644
--- a/cmd/virtual-kubelet/main.go
+++ b/cmd/virtual-kubelet/main.go
@@ -25,12 +25,12 @@ import (
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"
 	"github.com/spf13/cobra"
-	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/cmd/virtual-kubelet/internal/commands/providers"
+	"github.com/virtual-kubelet/virtual-kubelet/cmd/virtual-kubelet/internal/commands/root"
+	"github.com/virtual-kubelet/virtual-kubelet/cmd/virtual-kubelet/internal/commands/version"
+	"github.com/virtual-kubelet/virtual-kubelet/cmd/virtual-kubelet/internal/provider"
 	"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"
 )
@@ -57,11 +57,11 @@ func main() {
 	optsErr := root.SetDefaultOpts(&opts)
 	opts.Version = strings.Join([]string{k8sVersion, "vk", buildVersion}, "-")
 
-	s := providers.NewStore()
+	s := provider.NewStore()
 	registerMock(s)
 
 	rootCmd := root.NewCommand(ctx, filepath.Base(os.Args[0]), s, opts)
-	rootCmd.AddCommand(version.NewCommand(buildVersion, buildTime), cmdproviders.NewCommand(s))
+	rootCmd.AddCommand(version.NewCommand(buildVersion, buildTime), providers.NewCommand(s))
 	preRun := rootCmd.PreRunE
 
 	var logLevel string
diff --git a/cmd/virtual-kubelet/register.go b/cmd/virtual-kubelet/register.go
index 0f907c5f..2d1eb16e 100644
--- a/cmd/virtual-kubelet/register.go
+++ b/cmd/virtual-kubelet/register.go
@@ -1,12 +1,12 @@
 package main
 
 import (
-	"github.com/virtual-kubelet/virtual-kubelet/providers"
-	"github.com/virtual-kubelet/virtual-kubelet/providers/mock"
+	"github.com/virtual-kubelet/virtual-kubelet/cmd/virtual-kubelet/internal/provider"
+	"github.com/virtual-kubelet/virtual-kubelet/cmd/virtual-kubelet/internal/provider/mock"
 )
 
-func registerMock(s *providers.Store) {
-	s.Register("mock", func(cfg providers.InitConfig) (providers.Provider, error) {
+func registerMock(s *provider.Store) {
+	s.Register("mock", func(cfg provider.InitConfig) (provider.Provider, error) {
 		return mock.NewMockProvider(
 			cfg.ConfigPath,
 			cfg.NodeName,
@@ -16,7 +16,7 @@ func registerMock(s *providers.Store) {
 		)
 	})
 
-	s.Register("mockV0", func(cfg providers.InitConfig) (providers.Provider, error) {
+	s.Register("mockV0", func(cfg provider.InitConfig) (provider.Provider, error) {
 		return mock.NewMockProvider(
 			cfg.ConfigPath,
 			cfg.NodeName,
diff --git a/node/env.go b/node/env.go
index 29f3762b..1dff7358 100755
--- a/node/env.go
+++ b/node/env.go
@@ -32,8 +32,8 @@ import (
 	"k8s.io/kubernetes/pkg/kubelet/envvars"
 	"k8s.io/kubernetes/third_party/forked/golang/expansion"
 
+	"github.com/virtual-kubelet/virtual-kubelet/internal/manager"
 	"github.com/virtual-kubelet/virtual-kubelet/log"
-	"github.com/virtual-kubelet/virtual-kubelet/manager"
 )
 
 const (
diff --git a/node/podcontroller.go b/node/podcontroller.go
index 013470c6..cf868df3 100644
--- a/node/podcontroller.go
+++ b/node/podcontroller.go
@@ -24,8 +24,8 @@ import (
 
 	pkgerrors "github.com/pkg/errors"
 	"github.com/virtual-kubelet/virtual-kubelet/errdefs"
+	"github.com/virtual-kubelet/virtual-kubelet/internal/manager"
 	"github.com/virtual-kubelet/virtual-kubelet/log"
-	"github.com/virtual-kubelet/virtual-kubelet/manager"
 	"github.com/virtual-kubelet/virtual-kubelet/trace"
 	corev1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/api/errors"


Test patch:
diff --git a/manager/doc.go b/internal/manager/doc.go
similarity index 100%
rename from manager/doc.go
rename to internal/manager/doc.go
diff --git a/manager/resource.go b/internal/manager/resource.go
similarity index 100%
rename from manager/resource.go
rename to internal/manager/resource.go
diff --git a/manager/resource_test.go b/internal/manager/resource_test.go
similarity index 98%
rename from manager/resource_test.go
rename to internal/manager/resource_test.go
index eb454975..030a1d86 100644
--- a/manager/resource_test.go
+++ b/internal/manager/resource_test.go
@@ -22,8 +22,8 @@ import (
 	corev1listers "k8s.io/client-go/listers/core/v1"
 	"k8s.io/client-go/tools/cache"
 
+	"github.com/virtual-kubelet/virtual-kubelet/internal/manager"
 	testutil "github.com/virtual-kubelet/virtual-kubelet/internal/test/util"
-	"github.com/virtual-kubelet/virtual-kubelet/manager"
 )
 
 // TestGetPods verifies that the resource manager acts as a passthrough to a pod lister.
diff --git a/internal/test/util/resource_manager.go b/internal/test/util/resource_manager.go
index ef8544fb..c3ef2268 100644
--- a/internal/test/util/resource_manager.go
+++ b/internal/test/util/resource_manager.go
@@ -9,7 +9,7 @@ import (
 	"k8s.io/client-go/kubernetes/fake"
 	"k8s.io/client-go/tools/cache"
 
-	"github.com/virtual-kubelet/virtual-kubelet/manager"
+	"github.com/virtual-kubelet/virtual-kubelet/internal/manager"
 )
 
 // FakeResourceManager returns an instance of the resource manager that will return the specified objects when its "GetX" methods are called.