From 03c19bb68ec9a54cb5b47f909cbe2058d5ca7103 Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 2 Nov 2020 22:02:53 +0100 Subject: [PATCH] Remove pkg/backend package We no longer use registration pattern for backends, as it is using globals and init() which we want to avoid using. We also moved the interface to cli/cmd/cluster package, as it was the only consumer of it, so actually the entire package can be now removed, as it no longer has any use. Refs #992 Signed-off-by: Mateusz Gozdek --- pkg/backend/backend.go | 27 --------------------------- pkg/backend/local/local.go | 6 ------ pkg/backend/s3/s3.go | 6 ------ 3 files changed, 39 deletions(-) diff --git a/pkg/backend/backend.go b/pkg/backend/backend.go index 8df9df010..9c06fc9f0 100644 --- a/pkg/backend/backend.go +++ b/pkg/backend/backend.go @@ -15,8 +15,6 @@ package backend import ( - "fmt" - "github.com/hashicorp/hcl/v2" ) @@ -29,28 +27,3 @@ type Backend interface { // Validate validates backend configuration. Validate() error } - -// backends is a collection in which all Backends get automatically registered. -var backends map[string]Backend - -// Initialize package's global variable on import. -func init() { - backends = make(map[string]Backend) -} - -// Register registers Backend b in the internal backends map. -func Register(name string, b Backend) { - if _, exists := backends[name]; exists { - panic(fmt.Sprintf("backend with name %q registered already", name)) - } - backends[name] = b -} - -// GetBackend returns the Backend referred to by name. -func GetBackend(name string) (Backend, error) { - backend, exists := backends[name] - if !exists { - return nil, fmt.Errorf("no backend with name %q found", name) - } - return backend, nil -} diff --git a/pkg/backend/local/local.go b/pkg/backend/local/local.go index ee56f0825..ab86df339 100644 --- a/pkg/backend/local/local.go +++ b/pkg/backend/local/local.go @@ -19,7 +19,6 @@ import ( "github.com/hashicorp/hcl/v2/gohcl" "github.com/kinvolk/lokomotive/internal/template" - "github.com/kinvolk/lokomotive/pkg/backend" ) type local struct { @@ -32,11 +31,6 @@ const ( Name = "local" ) -// init registers local as a backend. -func init() { - backend.Register(Name, NewConfig()) -} - // LoadConfig loads the configuration for the local backend. func (l *local) LoadConfig(configBody *hcl.Body, evalContext *hcl.EvalContext) hcl.Diagnostics { if configBody == nil { diff --git a/pkg/backend/s3/s3.go b/pkg/backend/s3/s3.go index 65306726e..2e948ed38 100644 --- a/pkg/backend/s3/s3.go +++ b/pkg/backend/s3/s3.go @@ -22,7 +22,6 @@ import ( "github.com/hashicorp/hcl/v2/gohcl" "github.com/kinvolk/lokomotive/internal/template" - "github.com/kinvolk/lokomotive/pkg/backend" ) type s3 struct { @@ -39,11 +38,6 @@ const ( Name = "s3" ) -// init registers s3 as a backend. -func init() { - backend.Register(Name, NewConfig()) -} - // LoadConfig loads the configuration for the s3 backend. func (s *s3) LoadConfig(configBody *hcl.Body, evalContext *hcl.EvalContext) hcl.Diagnostics { if configBody == nil {