Skip to content

Commit

Permalink
chore: refactor condition judgement of backend and minor changes acco…
Browse files Browse the repository at this point in the history
…rding to review comments

Signed-off-by: Bird <aflybird0@gmail.com>
  • Loading branch information
aFlyBird0 committed Aug 19, 2022
1 parent 63b0674 commit 1902241
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/core-concepts/stateconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ state:
backend: k8s
options:
namespace: devstream # optional, default is "devstream", will be created if not exists
configmap: devstream-state # optional, default is "devstream-state", will be created if not exists
configmap: state # optional, default is "state", will be created if not exists
```

## S3 Backend
Expand Down
23 changes: 9 additions & 14 deletions internal/pkg/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/devstream-io/devstream/internal/pkg/configmanager"
)

// Backend is used to persist data, it can be local file/etcd/s3/k8s...
// Backend is used to persist data, it can be local file/s3/k8s...
type Backend interface {
// Read is used to read data from persistent storage.
Read() ([]byte, error)
Expand All @@ -20,20 +20,15 @@ type Backend interface {

// GetBackend will return a Backend by the given name.
func GetBackend(state configmanager.State) (Backend, error) {
typeName := types.Type(state.Backend)
switch {
case types.Local == typeName:
typeName := types.Type(strings.ToLower(state.Backend))

switch typeName {
case types.Local:
return local.NewLocal(state.Options.StateFile)
case types.S3 == typeName:
return s3.NewS3Backend(
state.Options.Bucket,
state.Options.Region,
state.Options.Key)
case strings.ToLower(state.Backend) == types.K8s.String() ||
strings.ToLower(state.Backend) == types.K8sAlis.String():
return k8s.NewBackend(
state.Options.Namespace,
state.Options.ConfigMap)
case types.S3:
return s3.NewS3Backend(state.Options.Bucket, state.Options.Region, state.Options.Key)
case types.K8s, types.K8sAlias:
return k8s.NewBackend(state.Options.Namespace, state.Options.ConfigMap)
default:
return nil, types.NewInvalidBackendErr(state.Backend)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/backend/k8s/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

const (
defaultNamespace = "devstream"
defaultConfigMapName = "devstream-state"
defaultConfigMapName = "state"
stateKey = "state"
)

Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/backend/types/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ func (t Type) String() string {
}

const (
Local Type = "local"
S3 Type = "s3"
K8s Type = "k8s"
K8sAlis Type = "kubernetes"
Local Type = "local"
S3 Type = "s3"
K8s Type = "k8s"
K8sAlias Type = "kubernetes"
)

0 comments on commit 1902241

Please sign in to comment.