Skip to content

Commit fe56bf8

Browse files
authored
Bootstrap app manager and store (#2419)
1 parent 5b2c894 commit fe56bf8

File tree

8 files changed

+218
-0
lines changed

8 files changed

+218
-0
lines changed

api/controllers/kubernetes/install/controller.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"sync"
66

7+
appconfig "github.com/replicatedhq/embedded-cluster/api/internal/managers/app/config"
78
"github.com/replicatedhq/embedded-cluster/api/internal/managers/kubernetes/infra"
89
"github.com/replicatedhq/embedded-cluster/api/internal/managers/kubernetes/installation"
910
"github.com/replicatedhq/embedded-cluster/api/internal/statemachine"
@@ -31,6 +32,7 @@ var _ Controller = (*InstallController)(nil)
3132
type InstallController struct {
3233
installationManager installation.InstallationManager
3334
infraManager infra.InfraManager
35+
appConfigManager appconfig.AppConfigManager
3436
metricsReporter metrics.ReporterInterface
3537
restClientGetterFactory func(namespace string) genericclioptions.RESTClientGetter
3638
releaseData *release.ReleaseData
@@ -127,6 +129,12 @@ func WithInfraManager(infraManager infra.InfraManager) InstallControllerOption {
127129
}
128130
}
129131

132+
func WithAppConfigManager(appConfigManager appconfig.AppConfigManager) InstallControllerOption {
133+
return func(c *InstallController) {
134+
c.appConfigManager = appConfigManager
135+
}
136+
}
137+
130138
func WithStateMachine(stateMachine statemachine.Interface) InstallControllerOption {
131139
return func(c *InstallController) {
132140
c.stateMachine = stateMachine
@@ -172,5 +180,12 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
172180
)
173181
}
174182

183+
if controller.appConfigManager == nil {
184+
controller.appConfigManager = appconfig.NewAppConfigManager(
185+
appconfig.WithLogger(controller.logger),
186+
appconfig.WithAppConfigStore(controller.store.AppConfigStore()),
187+
)
188+
}
189+
175190
return controller, nil
176191
}

api/controllers/linux/install/controller.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"sync"
66

7+
appconfig "github.com/replicatedhq/embedded-cluster/api/internal/managers/app/config"
78
"github.com/replicatedhq/embedded-cluster/api/internal/managers/linux/infra"
89
"github.com/replicatedhq/embedded-cluster/api/internal/managers/linux/installation"
910
"github.com/replicatedhq/embedded-cluster/api/internal/managers/linux/preflight"
@@ -42,6 +43,7 @@ type InstallController struct {
4243
installationManager installation.InstallationManager
4344
hostPreflightManager preflight.HostPreflightManager
4445
infraManager infra.InfraManager
46+
appConfigManager appconfig.AppConfigManager
4547
hostUtils hostutils.HostUtilsInterface
4648
netUtils utils.NetUtils
4749
metricsReporter metrics.ReporterInterface
@@ -165,6 +167,12 @@ func WithInfraManager(infraManager infra.InfraManager) InstallControllerOption {
165167
}
166168
}
167169

170+
func WithAppConfigManager(appConfigManager appconfig.AppConfigManager) InstallControllerOption {
171+
return func(c *InstallController) {
172+
c.appConfigManager = appConfigManager
173+
}
174+
}
175+
168176
func WithStateMachine(stateMachine statemachine.Interface) InstallControllerOption {
169177
return func(c *InstallController) {
170178
c.stateMachine = stateMachine
@@ -236,6 +244,13 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
236244
)
237245
}
238246

247+
if controller.appConfigManager == nil {
248+
controller.appConfigManager = appconfig.NewAppConfigManager(
249+
appconfig.WithLogger(controller.logger),
250+
appconfig.WithAppConfigStore(controller.store.AppConfigStore()),
251+
)
252+
}
253+
239254
controller.registerReportingHandlers()
240255

241256
return controller, nil
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package config
2+
3+
import (
4+
"context"
5+
6+
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
7+
)
8+
9+
func (m *appConfigManager) Get() (kotsv1beta1.Config, error) {
10+
return m.appConfigStore.Get()
11+
}
12+
13+
func (m *appConfigManager) Set(ctx context.Context) error {
14+
return nil
15+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package config
2+
3+
import (
4+
"context"
5+
"sync"
6+
7+
configstore "github.com/replicatedhq/embedded-cluster/api/internal/store/app/config"
8+
"github.com/replicatedhq/embedded-cluster/api/pkg/logger"
9+
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
10+
"github.com/sirupsen/logrus"
11+
)
12+
13+
var _ AppConfigManager = &appConfigManager{}
14+
15+
// AppConfigManager provides methods for managing appConfigstructure setup
16+
type AppConfigManager interface {
17+
Get() (kotsv1beta1.Config, error)
18+
Set(ctx context.Context) error
19+
}
20+
21+
// appConfigManager is an implementation of the AppConfigManager interface
22+
type appConfigManager struct {
23+
appConfigStore configstore.Store
24+
logger logrus.FieldLogger
25+
mu sync.RWMutex
26+
}
27+
28+
type AppConfigManagerOption func(*appConfigManager)
29+
30+
func WithLogger(logger logrus.FieldLogger) AppConfigManagerOption {
31+
return func(c *appConfigManager) {
32+
c.logger = logger
33+
}
34+
}
35+
36+
func WithAppConfigStore(store configstore.Store) AppConfigManagerOption {
37+
return func(c *appConfigManager) {
38+
c.appConfigStore = store
39+
}
40+
}
41+
42+
// NewAppConfigManager creates a new AppConfigManager with the provided options
43+
func NewAppConfigManager(opts ...AppConfigManagerOption) *appConfigManager {
44+
manager := &appConfigManager{}
45+
46+
for _, opt := range opts {
47+
opt(manager)
48+
}
49+
50+
if manager.logger == nil {
51+
manager.logger = logger.NewDiscardLogger()
52+
}
53+
54+
if manager.appConfigStore == nil {
55+
manager.appConfigStore = configstore.NewMemoryStore()
56+
}
57+
58+
return manager
59+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package config
2+
3+
import (
4+
"sync"
5+
6+
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
7+
"github.com/tiendc/go-deepcopy"
8+
)
9+
10+
var _ Store = &memoryStore{}
11+
12+
type Store interface {
13+
Get() (kotsv1beta1.Config, error)
14+
Set(config kotsv1beta1.Config) error
15+
}
16+
17+
type memoryStore struct {
18+
mu sync.RWMutex
19+
config kotsv1beta1.Config
20+
}
21+
22+
type StoreOption func(*memoryStore)
23+
24+
func WithConfig(config kotsv1beta1.Config) StoreOption {
25+
return func(s *memoryStore) {
26+
s.config = config
27+
}
28+
}
29+
30+
func NewMemoryStore(opts ...StoreOption) Store {
31+
s := &memoryStore{}
32+
33+
for _, opt := range opts {
34+
opt(s)
35+
}
36+
37+
return s
38+
}
39+
40+
func (s *memoryStore) Get() (kotsv1beta1.Config, error) {
41+
s.mu.RLock()
42+
defer s.mu.RUnlock()
43+
44+
var config kotsv1beta1.Config
45+
if err := deepcopy.Copy(&config, &s.config); err != nil {
46+
return kotsv1beta1.Config{}, err
47+
}
48+
49+
return config, nil
50+
}
51+
52+
func (s *memoryStore) Set(config kotsv1beta1.Config) error {
53+
s.mu.Lock()
54+
defer s.mu.Unlock()
55+
56+
s.config = config
57+
return nil
58+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package config
2+
3+
import (
4+
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
5+
"github.com/stretchr/testify/mock"
6+
)
7+
8+
var _ Store = (*MockStore)(nil)
9+
10+
// MockStore is a mock implementation of the Store interface
11+
type MockStore struct {
12+
mock.Mock
13+
}
14+
15+
// Get mocks the Get method
16+
func (m *MockStore) Get() (kotsv1beta1.Config, error) {
17+
args := m.Called()
18+
if args.Get(0) == nil {
19+
return kotsv1beta1.Config{}, args.Error(1)
20+
}
21+
return args.Get(0).(kotsv1beta1.Config), args.Error(1)
22+
}
23+
24+
// Set mocks the Set method
25+
func (m *MockStore) Set(config kotsv1beta1.Config) error {
26+
args := m.Called(config)
27+
return args.Error(0)
28+
}

api/internal/store/store.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package store
22

33
import (
4+
appconfig "github.com/replicatedhq/embedded-cluster/api/internal/store/app/config"
45
"github.com/replicatedhq/embedded-cluster/api/internal/store/infra"
56
kubernetesinstallation "github.com/replicatedhq/embedded-cluster/api/internal/store/kubernetes/installation"
67
linuxinstallation "github.com/replicatedhq/embedded-cluster/api/internal/store/linux/installation"
@@ -25,6 +26,9 @@ type Store interface {
2526

2627
// KubernetesInfraStore provides access to kubernetes infrastructure operations
2728
KubernetesInfraStore() infra.Store
29+
30+
// AppConfigStore provides access to app config operations
31+
AppConfigStore() appconfig.Store
2832
}
2933

3034
// StoreOption is a function that configures a store
@@ -58,6 +62,13 @@ func WithKubernetesInstallationStore(store kubernetesinstallation.Store) StoreOp
5862
}
5963
}
6064

65+
// WithAppConfigStore sets the app config store
66+
func WithAppConfigStore(store appconfig.Store) StoreOption {
67+
return func(s *memoryStore) {
68+
s.appConfigStore = store
69+
}
70+
}
71+
6172
// memoryStore is an in-memory implementation of the global Store interface
6273
type memoryStore struct {
6374
linuxPreflightStore linuxpreflight.Store
@@ -66,6 +77,8 @@ type memoryStore struct {
6677

6778
kubernetesInstallationStore kubernetesinstallation.Store
6879
kubernetesInfraStore infra.Store
80+
81+
appConfigStore appconfig.Store
6982
}
7083

7184
// NewMemoryStore creates a new memory store with the given options
@@ -96,6 +109,10 @@ func NewMemoryStore(opts ...StoreOption) Store {
96109
s.kubernetesInfraStore = infra.NewMemoryStore()
97110
}
98111

112+
if s.appConfigStore == nil {
113+
s.appConfigStore = appconfig.NewMemoryStore()
114+
}
115+
99116
return s
100117
}
101118

@@ -118,3 +135,7 @@ func (s *memoryStore) KubernetesInstallationStore() kubernetesinstallation.Store
118135
func (s *memoryStore) KubernetesInfraStore() infra.Store {
119136
return s.kubernetesInfraStore
120137
}
138+
139+
func (s *memoryStore) AppConfigStore() appconfig.Store {
140+
return s.appConfigStore
141+
}

api/internal/store/store_mock.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package store
22

33
import (
4+
appconfig "github.com/replicatedhq/embedded-cluster/api/internal/store/app/config"
45
"github.com/replicatedhq/embedded-cluster/api/internal/store/infra"
56
kubernetesinstallation "github.com/replicatedhq/embedded-cluster/api/internal/store/kubernetes/installation"
67
linuxinstallation "github.com/replicatedhq/embedded-cluster/api/internal/store/linux/installation"
@@ -16,6 +17,7 @@ type MockStore struct {
1617
LinuxInfraMockStore infra.MockStore
1718
KubernetesInstallationMockStore kubernetesinstallation.MockStore
1819
KubernetesInfraMockStore infra.MockStore
20+
AppConfigMockStore appconfig.MockStore
1921
}
2022

2123
// LinuxPreflightStore returns the mock linux preflight store
@@ -42,3 +44,8 @@ func (m *MockStore) KubernetesInstallationStore() kubernetesinstallation.Store {
4244
func (m *MockStore) KubernetesInfraStore() infra.Store {
4345
return &m.KubernetesInfraMockStore
4446
}
47+
48+
// AppConfigStore returns the mock app config store
49+
func (m *MockStore) AppConfigStore() appconfig.Store {
50+
return &m.AppConfigMockStore
51+
}

0 commit comments

Comments
 (0)