Skip to content

Commit 7f3cb9c

Browse files
authored
chore: install state machine with final states (#2334)
* chore: install state machine with final states
1 parent d3131d9 commit 7f3cb9c

32 files changed

+1338
-495
lines changed

api/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ The root directory contains the main API setup files and request handlers.
1212
#### `/controllers`
1313
Contains the business logic for different API endpoints. Each controller package focuses on a specific domain of functionality or workflow (e.g., authentication, console, install, upgrade, join, etc.) and implements the core business logic for that domain or workflow. Controllers can utilize multiple managers with each manager handling a specific subdomain of functionality.
1414

15+
#### `/internal`
16+
Contains shared utilities and helper packages that provide common functionality used across different parts of the API. This includes both general-purpose utilities and domain-specific helpers.
17+
1518
#### `/internal/managers`
1619
Each manager is responsible for a specific subdomain of functionality and provides a clean, thread-safe interface for controllers to interact with. For example, the Preflight Manager manages system requirement checks and validation.
1720

21+
#### `/internal/statemachine`
22+
The statemachine is used by controllers to capture workflow state and enforce valid transitions.
23+
1824
#### `/types`
1925
Defines the core data structures and types used throughout the API. This includes:
2026
- Request and response types
@@ -30,7 +36,7 @@ Contains Swagger-generated API documentation. This includes:
3036
- API operation descriptions
3137

3238
#### `/pkg`
33-
Contains shared utilities and helper packages that provide common functionality used across different parts of the API. This includes both general-purpose utilities and domain-specific helpers.
39+
Contains helper packages that can be used by packages external to the API.
3440

3541
#### `/client`
3642
Provides a client library for interacting with the API. The client package implements a clean interface for making API calls and handling responses, making it easy to integrate with the API from other parts of the system.

api/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type API struct {
4848
rc runtimeconfig.RuntimeConfig
4949
releaseData *release.ReleaseData
5050
tlsConfig types.TLSConfig
51-
licenseFile string
51+
license []byte
5252
airgapBundle string
5353
configValues string
5454
endUserConfig *ecv1beta1.Config
@@ -113,9 +113,9 @@ func WithTLSConfig(tlsConfig types.TLSConfig) APIOption {
113113
}
114114
}
115115

116-
func WithLicenseFile(licenseFile string) APIOption {
116+
func WithLicense(license []byte) APIOption {
117117
return func(a *API) {
118-
a.licenseFile = licenseFile
118+
a.license = license
119119
}
120120
}
121121

@@ -188,7 +188,7 @@ func New(password string, opts ...APIOption) (*API, error) {
188188
install.WithReleaseData(api.releaseData),
189189
install.WithPassword(password),
190190
install.WithTLSConfig(api.tlsConfig),
191-
install.WithLicenseFile(api.licenseFile),
191+
install.WithLicense(api.license),
192192
install.WithAirgapBundle(api.airgapBundle),
193193
install.WithConfigValues(api.configValues),
194194
install.WithEndUserConfig(api.endUserConfig),

api/controllers/install/controller.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/replicatedhq/embedded-cluster/api/internal/managers/infra"
88
"github.com/replicatedhq/embedded-cluster/api/internal/managers/installation"
99
"github.com/replicatedhq/embedded-cluster/api/internal/managers/preflight"
10+
"github.com/replicatedhq/embedded-cluster/api/internal/statemachine"
1011
"github.com/replicatedhq/embedded-cluster/api/internal/store"
1112
"github.com/replicatedhq/embedded-cluster/api/pkg/logger"
1213
"github.com/replicatedhq/embedded-cluster/api/pkg/utils"
@@ -40,24 +41,26 @@ type RunHostPreflightsOptions struct {
4041
var _ Controller = (*InstallController)(nil)
4142

4243
type InstallController struct {
43-
install types.Install
44-
store store.Store
4544
installationManager installation.InstallationManager
4645
hostPreflightManager preflight.HostPreflightManager
4746
infraManager infra.InfraManager
48-
rc runtimeconfig.RuntimeConfig
49-
logger logrus.FieldLogger
5047
hostUtils hostutils.HostUtilsInterface
5148
netUtils utils.NetUtils
5249
metricsReporter metrics.ReporterInterface
5350
releaseData *release.ReleaseData
5451
password string
5552
tlsConfig types.TLSConfig
56-
licenseFile string
53+
license []byte
5754
airgapBundle string
5855
configValues string
5956
endUserConfig *ecv1beta1.Config
60-
mu sync.RWMutex
57+
58+
install types.Install
59+
store store.Store
60+
rc runtimeconfig.RuntimeConfig
61+
stateMachine statemachine.Interface
62+
logger logrus.FieldLogger
63+
mu sync.RWMutex
6164
}
6265

6366
type InstallControllerOption func(*InstallController)
@@ -110,9 +113,9 @@ func WithTLSConfig(tlsConfig types.TLSConfig) InstallControllerOption {
110113
}
111114
}
112115

113-
func WithLicenseFile(licenseFile string) InstallControllerOption {
116+
func WithLicense(license []byte) InstallControllerOption {
114117
return func(c *InstallController) {
115-
c.licenseFile = licenseFile
118+
c.license = license
116119
}
117120
}
118121

@@ -152,19 +155,22 @@ func WithInfraManager(infraManager infra.InfraManager) InstallControllerOption {
152155
}
153156
}
154157

155-
func NewInstallController(opts ...InstallControllerOption) (*InstallController, error) {
156-
controller := &InstallController{}
157-
158-
for _, opt := range opts {
159-
opt(controller)
158+
func WithStateMachine(stateMachine statemachine.Interface) InstallControllerOption {
159+
return func(c *InstallController) {
160+
c.stateMachine = stateMachine
160161
}
162+
}
161163

162-
if controller.rc == nil {
163-
controller.rc = runtimeconfig.New(nil)
164+
func NewInstallController(opts ...InstallControllerOption) (*InstallController, error) {
165+
controller := &InstallController{
166+
store: store.NewMemoryStore(),
167+
rc: runtimeconfig.New(nil),
168+
logger: logger.NewDiscardLogger(),
169+
stateMachine: NewStateMachine(),
164170
}
165171

166-
if controller.logger == nil {
167-
controller.logger = logger.NewDiscardLogger()
172+
for _, opt := range opts {
173+
opt(controller)
168174
}
169175

170176
if controller.hostUtils == nil {
@@ -177,15 +183,11 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
177183
controller.netUtils = utils.NewNetUtils()
178184
}
179185

180-
if controller.store == nil {
181-
controller.store = store.NewMemoryStore()
182-
}
183-
184186
if controller.installationManager == nil {
185187
controller.installationManager = installation.NewInstallationManager(
186188
installation.WithLogger(controller.logger),
187189
installation.WithInstallationStore(controller.store.InstallationStore()),
188-
installation.WithLicenseFile(controller.licenseFile),
190+
installation.WithLicense(controller.license),
189191
installation.WithAirgapBundle(controller.airgapBundle),
190192
installation.WithHostUtils(controller.hostUtils),
191193
installation.WithNetUtils(controller.netUtils),
@@ -207,7 +209,7 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
207209
infra.WithInfraStore(controller.store.InfraStore()),
208210
infra.WithPassword(controller.password),
209211
infra.WithTLSConfig(controller.tlsConfig),
210-
infra.WithLicenseFile(controller.licenseFile),
212+
infra.WithLicense(controller.license),
211213
infra.WithAirgapBundle(controller.airgapBundle),
212214
infra.WithConfigValues(controller.configValues),
213215
infra.WithReleaseData(controller.releaseData),

0 commit comments

Comments
 (0)