Skip to content

Commit

Permalink
refactor: introduce constants for backend stores
Browse files Browse the repository at this point in the history
  • Loading branch information
deviantony committed Sep 21, 2023
1 parent 5de030b commit 0e6ea62
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/adapter/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/portainer/k2d/internal/adapter/store/filesystem"
"github.com/portainer/k2d/internal/adapter/store/memory"
"github.com/portainer/k2d/internal/adapter/store/volume"
"github.com/portainer/k2d/internal/types"
"go.uber.org/zap"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -92,15 +93,15 @@ type StoreOptions struct {
// - Returns an error if an invalid backend type is provided.
func ConfigureStore(opts StoreOptions) (ConfigMapStore, SecretStore, error) {
switch opts.Backend {
case "disk":
case types.DiskStoreBackend:
filesystemStore, err := filesystem.NewFileSystemStore(opts.Logger, opts.Filesystem)
if err != nil {
return nil, nil, fmt.Errorf("failed to create filesystem store: %w", err)
}

opts.Logger.Info("using disk store for ConfigMaps and Secrets")
return filesystemStore, filesystemStore, nil
case "volume":
case types.VolumeStoreBackend:
opts.Volume.SecretKind = volume.SecretResourceType
volumeStore, err := volume.NewVolumeStore(opts.Logger, opts.Volume)
if err != nil {
Expand Down Expand Up @@ -132,10 +133,10 @@ func ConfigureStore(opts StoreOptions) (ConfigMapStore, SecretStore, error) {
// - Returns an error if an invalid registry secret store backend is provided.
func ConfigureRegistrySecretStore(opts StoreOptions, encryptionKeyFolder string) (SecretStore, error) {
switch opts.RegistryBackend {
case "memory":
case types.MemoryRegistryStoreBackend:
opts.Logger.Info("using memory store for registry Secrets")
return memory.NewInMemoryStore(), nil
case "volume":
case types.VolumeRegistryStoreBackend:
opts.Logger.Info("using encrypted volume store for registry Secrets")

encryptionKey, err := volume.GenerateOrRetrieveEncryptionKey(opts.Logger, encryptionKeyFolder)
Expand Down
15 changes: 15 additions & 0 deletions internal/types/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package types

const (
// DiskStoreBackend is the value used to identify the disk storage backend
DiskStoreBackend = "disk"
// VolumeStoreBackend is the value used to identify the volume storage backend
VolumeStoreBackend = "volume"
)

const (
// MemoryRegistryStoreBackend is the value used to identify the memory storage backend
MemoryRegistryStoreBackend = "memory"
// VolumeRegistryStoreBackend is the value used to identify the volume storage backend
VolumeRegistryStoreBackend = "volume"
)

0 comments on commit 0e6ea62

Please sign in to comment.