Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
cli/cmd: only import cli/cmd/cluster package from Lokomotive
Browse files Browse the repository at this point in the history
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 <mateusz@kinvolk.io>
  • Loading branch information
invidian committed Oct 22, 2020
1 parent d444d6c commit b8b5df2
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 41 deletions.
10 changes: 10 additions & 0 deletions cli/cmd/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions cli/cmd/cluster/component.go
Original file line number Diff line number Diff line change
@@ -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()
}
24 changes: 24 additions & 0 deletions cli/cmd/cluster/version.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 1 addition & 2 deletions cli/cmd/component-apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
},
}

Expand Down
3 changes: 1 addition & 2 deletions cli/cmd/component-delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
},
}

Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/component-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
Expand Down
23 changes: 0 additions & 23 deletions cli/cmd/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
10 changes: 0 additions & 10 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/spf13/cobra"

"github.com/kinvolk/lokomotive/pkg/version"
"github.com/kinvolk/lokomotive/cli/cmd/cluster"
)

func init() {
Expand All @@ -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())
},
}

0 comments on commit b8b5df2

Please sign in to comment.