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

Commit

Permalink
cli/cmd/cluster: move Backend interface definition to only consumer
Browse files Browse the repository at this point in the history
No other packages really need backend.Backend interface, so we can move
it to cli/cmd/cluster package where it is actually consumed, which is an
recommendation in Go. This way we can further reduce exported API of the
codebase.

Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
  • Loading branch information
invidian committed Nov 30, 2020
1 parent 4ca0ae7 commit 09412bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 1 addition & 2 deletions cli/cmd/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"helm.sh/helm/v3/pkg/chart"
"sigs.k8s.io/yaml"

"github.com/kinvolk/lokomotive/pkg/backend"
"github.com/kinvolk/lokomotive/pkg/backend/local"
"github.com/kinvolk/lokomotive/pkg/components/util"
"github.com/kinvolk/lokomotive/pkg/config"
Expand Down Expand Up @@ -106,7 +105,7 @@ func (cc clusterConfig) initialize(contextLogger *log.Entry) (*cluster, error) {

// initializeTerraform initialized Terraform directory using given backend and platform
// and returns configured executor.
func (cc clusterConfig) initializeTerraform(p platform.Platform, b backend.Backend) (*terraform.Executor, error) {
func (cc clusterConfig) initializeTerraform(p platform.Platform, b backend) (*terraform.Executor, error) {
assetDir, err := homedir.Expand(p.Meta().AssetDir)
if err != nil {
return nil, fmt.Errorf("expanding path %q: %w", p.Meta().AssetDir, err)
Expand Down
15 changes: 12 additions & 3 deletions cli/cmd/cluster/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/mitchellh/go-homedir"
log "github.com/sirupsen/logrus"

"github.com/kinvolk/lokomotive/pkg/backend"
"github.com/kinvolk/lokomotive/pkg/backend/local"
"github.com/kinvolk/lokomotive/pkg/backend/s3"
"github.com/kinvolk/lokomotive/pkg/config"
Expand All @@ -41,14 +40,24 @@ const (
kubeconfigTerraformOutputKey = "kubeconfig"
)

// backend describes the Terraform state storage location.
type backend interface {
// LoadConfig loads the backend config provided by the user.
LoadConfig(*hcl.Body, *hcl.EvalContext) hcl.Diagnostics
// Render renders the backend template with user backend configuration.
Render() (string, error)
// Validate validates backend configuration.
Validate() error
}

// getConfiguredBackend loads a backend from the given configuration file.
func getConfiguredBackend(lokoConfig *config.Config) (backend.Backend, hcl.Diagnostics) {
func getConfiguredBackend(lokoConfig *config.Config) (backend, hcl.Diagnostics) {
if lokoConfig.RootConfig.Backend == nil {
// No backend defined and no configuration error
return nil, hcl.Diagnostics{}
}

backends := map[string]backend.Backend{
backends := map[string]backend{
s3.Name: s3.NewConfig(),
local.Name: local.NewConfig(),
}
Expand Down

0 comments on commit 09412bd

Please sign in to comment.