From b8b5df25306f4eb2b1a2c95cdffd7806ba6de4e3 Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 19 Oct 2020 13:17:28 +0200 Subject: [PATCH] cli/cmd: only import cli/cmd/cluster package from Lokomotive To finish isolation of CLI code, we move anonymouse imports from cli/cmd package to cluster package and we make cmd/cli rely only on cli/cmd/cluster package for Lokomotive interactions. This is a required step if we decide to implement #312 using Go modules. Signed-off-by: Mateusz Gozdek --- cli/cmd/cluster/cluster.go | 10 ++++++++ cli/cmd/cluster/component.go | 47 ++++++++++++++++++++++++++++++++++++ cli/cmd/cluster/version.go | 24 ++++++++++++++++++ cli/cmd/component-apply.go | 3 +-- cli/cmd/component-delete.go | 3 +-- cli/cmd/component-list.go | 4 +-- cli/cmd/component.go | 23 ------------------ cli/cmd/root.go | 10 -------- cli/cmd/version.go | 4 +-- 9 files changed, 87 insertions(+), 41 deletions(-) create mode 100644 cli/cmd/cluster/component.go create mode 100644 cli/cmd/cluster/version.go diff --git a/cli/cmd/cluster/cluster.go b/cli/cmd/cluster/cluster.go index 709474636..a9de63590 100644 --- a/cli/cmd/cluster/cluster.go +++ b/cli/cmd/cluster/cluster.go @@ -29,6 +29,16 @@ import ( "github.com/kinvolk/lokomotive/pkg/config" "github.com/kinvolk/lokomotive/pkg/platform" "github.com/kinvolk/lokomotive/pkg/terraform" + + // Register platforms by adding an anonymous import. + _ "github.com/kinvolk/lokomotive/pkg/platform/aks" + _ "github.com/kinvolk/lokomotive/pkg/platform/aws" + _ "github.com/kinvolk/lokomotive/pkg/platform/baremetal" + _ "github.com/kinvolk/lokomotive/pkg/platform/packet" + + // Register backends by adding an anonymous import. + _ "github.com/kinvolk/lokomotive/pkg/backend/local" + _ "github.com/kinvolk/lokomotive/pkg/backend/s3" ) // cluster is a temporary helper struct to aggregate objects which are used diff --git a/cli/cmd/cluster/component.go b/cli/cmd/cluster/component.go new file mode 100644 index 000000000..c262b880d --- /dev/null +++ b/cli/cmd/cluster/component.go @@ -0,0 +1,47 @@ +// Copyright 2020 The Lokomotive Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cluster + +import ( + // Register a component by adding an anonymous import + _ "github.com/kinvolk/lokomotive/pkg/components/aws-ebs-csi-driver" + _ "github.com/kinvolk/lokomotive/pkg/components/cert-manager" + _ "github.com/kinvolk/lokomotive/pkg/components/cluster-autoscaler" + _ "github.com/kinvolk/lokomotive/pkg/components/contour" + _ "github.com/kinvolk/lokomotive/pkg/components/dex" + _ "github.com/kinvolk/lokomotive/pkg/components/external-dns" + _ "github.com/kinvolk/lokomotive/pkg/components/flatcar-linux-update-operator" + _ "github.com/kinvolk/lokomotive/pkg/components/gangway" + _ "github.com/kinvolk/lokomotive/pkg/components/httpbin" + _ "github.com/kinvolk/lokomotive/pkg/components/inspektor-gadget" + _ "github.com/kinvolk/lokomotive/pkg/components/istio-operator" + _ "github.com/kinvolk/lokomotive/pkg/components/linkerd" + _ "github.com/kinvolk/lokomotive/pkg/components/metallb" + _ "github.com/kinvolk/lokomotive/pkg/components/metrics-server" + _ "github.com/kinvolk/lokomotive/pkg/components/openebs-operator" + _ "github.com/kinvolk/lokomotive/pkg/components/openebs-storage-class" + _ "github.com/kinvolk/lokomotive/pkg/components/prometheus-operator" + _ "github.com/kinvolk/lokomotive/pkg/components/rook" + _ "github.com/kinvolk/lokomotive/pkg/components/rook-ceph" + _ "github.com/kinvolk/lokomotive/pkg/components/velero" + _ "github.com/kinvolk/lokomotive/pkg/components/web-ui" + + "github.com/kinvolk/lokomotive/pkg/components" +) + +// AvailableComponents returns list of valid component names. +func AvailableComponents() []string { + return components.ListNames() +} diff --git a/cli/cmd/cluster/version.go b/cli/cmd/cluster/version.go new file mode 100644 index 000000000..8323641cf --- /dev/null +++ b/cli/cmd/cluster/version.go @@ -0,0 +1,24 @@ +// Copyright 2020 The Lokomotive Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cluster + +import ( + "github.com/kinvolk/lokomotive/pkg/version" +) + +// Version returns current Lokomotive version. +func Version() string { + return version.Version +} diff --git a/cli/cmd/component-apply.go b/cli/cmd/component-apply.go index fb3260be2..0cff5e927 100644 --- a/cli/cmd/component-apply.go +++ b/cli/cmd/component-apply.go @@ -20,7 +20,6 @@ import ( "github.com/spf13/viper" "github.com/kinvolk/lokomotive/cli/cmd/cluster" - "github.com/kinvolk/lokomotive/pkg/components" ) var componentApplyCmd = &cobra.Command{ @@ -35,7 +34,7 @@ When run with no arguments, all components listed in the configuration are appli return nil, cobra.ShellCompDirectiveNoFileComp } - return components.ListNames(), cobra.ShellCompDirectiveNoFileComp + return cluster.AvailableComponents(), cobra.ShellCompDirectiveNoFileComp }, } diff --git a/cli/cmd/component-delete.go b/cli/cmd/component-delete.go index 7d5c256ea..3049a6ce3 100644 --- a/cli/cmd/component-delete.go +++ b/cli/cmd/component-delete.go @@ -20,7 +20,6 @@ import ( "github.com/spf13/viper" "github.com/kinvolk/lokomotive/cli/cmd/cluster" - "github.com/kinvolk/lokomotive/pkg/components" ) var componentDeleteCmd = &cobra.Command{ @@ -34,7 +33,7 @@ When run with no arguments, all components listed in the configuration are delet return nil, cobra.ShellCompDirectiveNoFileComp } - return components.ListNames(), cobra.ShellCompDirectiveNoFileComp + return cluster.AvailableComponents(), cobra.ShellCompDirectiveNoFileComp }, } diff --git a/cli/cmd/component-list.go b/cli/cmd/component-list.go index d15e2c218..9f3b8b6c9 100644 --- a/cli/cmd/component-list.go +++ b/cli/cmd/component-list.go @@ -21,7 +21,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "github.com/kinvolk/lokomotive/pkg/components" + "github.com/kinvolk/lokomotive/cli/cmd/cluster" ) var listCmd = &cobra.Command{ @@ -44,7 +44,7 @@ func runList(cmd *cobra.Command, args []string) { } fmt.Println("Available components:") - comps := components.ListNames() + comps := cluster.AvailableComponents() sort.Strings(comps) for _, name := range comps { fmt.Println("\t", name) diff --git a/cli/cmd/component.go b/cli/cmd/component.go index dc2b6a507..c694ccf17 100644 --- a/cli/cmd/component.go +++ b/cli/cmd/component.go @@ -16,29 +16,6 @@ package cmd import ( "github.com/spf13/cobra" - - // Register a component by adding an anonymous import - _ "github.com/kinvolk/lokomotive/pkg/components/aws-ebs-csi-driver" - _ "github.com/kinvolk/lokomotive/pkg/components/cert-manager" - _ "github.com/kinvolk/lokomotive/pkg/components/cluster-autoscaler" - _ "github.com/kinvolk/lokomotive/pkg/components/contour" - _ "github.com/kinvolk/lokomotive/pkg/components/dex" - _ "github.com/kinvolk/lokomotive/pkg/components/external-dns" - _ "github.com/kinvolk/lokomotive/pkg/components/flatcar-linux-update-operator" - _ "github.com/kinvolk/lokomotive/pkg/components/gangway" - _ "github.com/kinvolk/lokomotive/pkg/components/httpbin" - _ "github.com/kinvolk/lokomotive/pkg/components/inspektor-gadget" - _ "github.com/kinvolk/lokomotive/pkg/components/istio-operator" - _ "github.com/kinvolk/lokomotive/pkg/components/linkerd" - _ "github.com/kinvolk/lokomotive/pkg/components/metallb" - _ "github.com/kinvolk/lokomotive/pkg/components/metrics-server" - _ "github.com/kinvolk/lokomotive/pkg/components/openebs-operator" - _ "github.com/kinvolk/lokomotive/pkg/components/openebs-storage-class" - _ "github.com/kinvolk/lokomotive/pkg/components/prometheus-operator" - _ "github.com/kinvolk/lokomotive/pkg/components/rook" - _ "github.com/kinvolk/lokomotive/pkg/components/rook-ceph" - _ "github.com/kinvolk/lokomotive/pkg/components/velero" - _ "github.com/kinvolk/lokomotive/pkg/components/web-ui" ) var componentCmd = &cobra.Command{ diff --git a/cli/cmd/root.go b/cli/cmd/root.go index 08e1dd2b4..58322ee5f 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -21,16 +21,6 @@ import ( "github.com/spf13/cobra" flag "github.com/spf13/pflag" "github.com/spf13/viper" - - // Register platforms by adding an anonymous import. - _ "github.com/kinvolk/lokomotive/pkg/platform/aks" - _ "github.com/kinvolk/lokomotive/pkg/platform/aws" - _ "github.com/kinvolk/lokomotive/pkg/platform/baremetal" - _ "github.com/kinvolk/lokomotive/pkg/platform/packet" - - // Register backends by adding an anonymous import. - _ "github.com/kinvolk/lokomotive/pkg/backend/local" - _ "github.com/kinvolk/lokomotive/pkg/backend/s3" ) var RootCmd = &cobra.Command{ diff --git a/cli/cmd/version.go b/cli/cmd/version.go index e0b119062..1dbe24979 100644 --- a/cli/cmd/version.go +++ b/cli/cmd/version.go @@ -19,7 +19,7 @@ import ( "github.com/spf13/cobra" - "github.com/kinvolk/lokomotive/pkg/version" + "github.com/kinvolk/lokomotive/cli/cmd/cluster" ) func init() { @@ -30,6 +30,6 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "Print version information", Run: func(cmd *cobra.Command, args []string) { - fmt.Println(version.Version) + fmt.Println(cluster.Version()) }, }