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

Commit

Permalink
Remove pkg/backend package
Browse files Browse the repository at this point in the history
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 <mateusz@kinvolk.io>
  • Loading branch information
invidian committed Dec 2, 2020
1 parent 6649e28 commit 297530c
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 39 deletions.
27 changes: 0 additions & 27 deletions pkg/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package backend

import (
"fmt"

"github.com/hashicorp/hcl/v2"
)

Expand All @@ -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
}
6 changes: 0 additions & 6 deletions pkg/backend/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions pkg/backend/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 297530c

Please sign in to comment.