Skip to content

Commit

Permalink
refactor: adapter store refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
deviantony committed Aug 25, 2023
1 parent 1307367 commit 53fa157
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 25 deletions.
11 changes: 6 additions & 5 deletions internal/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (

"github.com/docker/docker/client"
"github.com/portainer/k2d/internal/adapter/converter"
"github.com/portainer/k2d/internal/adapter/filesystem"
"github.com/portainer/k2d/internal/adapter/memory"
"github.com/portainer/k2d/internal/adapter/store"
"github.com/portainer/k2d/internal/adapter/store/filesystem"
"github.com/portainer/k2d/internal/adapter/store/memory"
"github.com/portainer/k2d/internal/types"
"go.uber.org/zap"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -27,9 +28,9 @@ type (
KubeDockerAdapter struct {
cli *client.Client
converter *converter.DockerAPIConverter
configMapStore types.ConfigMapStore
secretStore types.SecretStore
registrySecretStore types.SecretStore
configMapStore store.ConfigMapStore
secretStore store.SecretStore
registrySecretStore store.SecretStore
logger *zap.SugaredLogger
conversionScheme *runtime.Scheme
startTime time.Time
Expand Down
2 changes: 1 addition & 1 deletion internal/adapter/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package converter
import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/portainer/k2d/internal/adapter/filesystem"
"github.com/portainer/k2d/internal/adapter/store/filesystem"
"github.com/portainer/k2d/internal/types"
"github.com/portainer/k2d/pkg/rand"
)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Package filesystem provides functionality to interact with the file system.
package filesystem

import (
Expand All @@ -18,6 +17,7 @@ const (
)

// FileSystemStore is a structure that represents a file system store.
// It can be used to store ConfigMaps and Secrets.
// It holds paths to the configMap and secret directories,
// and a mutex to handle concurrent access.
type (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ type secretData struct {
Type string
}

// InMemoryStore is a simple in-memory store for secrets
// InMemoryStore is a simple in-memory that can be used
// to store Secrets.
type InMemoryStore struct {
m sync.RWMutex
secretMap map[string]secretData
Expand Down
10 changes: 9 additions & 1 deletion internal/types/secret.go → internal/adapter/store/store.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package types
package store

import (
corev1 "k8s.io/api/core/v1"
Expand All @@ -13,3 +13,11 @@ type SecretStore interface {
GetSecrets(selector labels.Selector) (core.SecretList, error)
StoreSecret(secret *corev1.Secret) error
}

// ConfigMapStore is an interface for interacting with Kubernetes ConfigMaps.
type ConfigMapStore interface {
DeleteConfigMap(configMapName string) error
GetConfigMap(configMapName string) (*core.ConfigMap, error)
GetConfigMaps() (core.ConfigMapList, error)
StoreConfigMap(configMap *corev1.ConfigMap) error
}
2 changes: 1 addition & 1 deletion internal/api/core/v1/configmaps/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"

"github.com/emicklei/go-restful/v3"
"github.com/portainer/k2d/internal/adapter/filesystem"
"github.com/portainer/k2d/internal/adapter/store/filesystem"
"github.com/portainer/k2d/internal/api/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/api/core/v1/configmaps/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"

"github.com/emicklei/go-restful/v3"
"github.com/portainer/k2d/internal/adapter/filesystem"
"github.com/portainer/k2d/internal/adapter/store/filesystem"
"github.com/portainer/k2d/internal/api/utils"
"github.com/portainer/k2d/internal/controller"
"github.com/portainer/k2d/internal/types"
Expand Down
14 changes: 0 additions & 14 deletions internal/types/configmap.go

This file was deleted.

0 comments on commit 53fa157

Please sign in to comment.