-
Notifications
You must be signed in to change notification settings - Fork 5
Run preflights in manager UI / API #2234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 37 commits
3af8ff1
088dcdd
f4dd47a
86ac03e
548468b
1d964e6
e4035b6
d90cd90
b82dbfc
f0dca98
a15bd63
c77250a
d2d10d2
45643ba
2d1b7eb
3825c4e
56ce746
3db1168
a8c01e1
b04f5fc
e932601
c617d9c
6ca3f08
5bc987c
11d558b
5810a7e
cd592a4
cb8f113
c91c351
5763381
4adddd9
34fbd09
9acd699
3b78a3e
464411d
b23c198
d5d92e6
87ad72c
39b45fe
4d77b19
4204e58
ff2d783
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ name: CI | |
|
||
on: | ||
pull_request: {} | ||
|
||
push: | ||
branches: | ||
- main | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,12 @@ import ( | |
"github.com/replicatedhq/embedded-cluster/api/controllers/console" | ||
"github.com/replicatedhq/embedded-cluster/api/controllers/install" | ||
"github.com/replicatedhq/embedded-cluster/api/docs" | ||
"github.com/replicatedhq/embedded-cluster/api/pkg/logger" | ||
"github.com/replicatedhq/embedded-cluster/api/types" | ||
"github.com/replicatedhq/embedded-cluster/pkg-new/hostutils" | ||
"github.com/replicatedhq/embedded-cluster/pkg/metrics" | ||
"github.com/replicatedhq/embedded-cluster/pkg/release" | ||
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig" | ||
"github.com/sirupsen/logrus" | ||
httpSwagger "github.com/swaggo/http-swagger/v2" | ||
) | ||
|
@@ -38,8 +43,14 @@ type API struct { | |
authController auth.Controller | ||
consoleController console.Controller | ||
installController install.Controller | ||
rc runtimeconfig.RuntimeConfig | ||
releaseData *release.ReleaseData | ||
licenseFile string | ||
airgapBundle string | ||
configChan chan<- *types.InstallationConfig | ||
logger logrus.FieldLogger | ||
hostUtils hostutils.HostUtilsInterface | ||
metricsReporter metrics.ReporterInterface | ||
} | ||
|
||
type APIOption func(*API) | ||
|
@@ -62,24 +73,79 @@ func WithInstallController(installController install.Controller) APIOption { | |
} | ||
} | ||
|
||
func WithRuntimeConfig(rc runtimeconfig.RuntimeConfig) APIOption { | ||
return func(a *API) { | ||
a.rc = rc | ||
} | ||
} | ||
|
||
func WithLogger(logger logrus.FieldLogger) APIOption { | ||
return func(a *API) { | ||
a.logger = logger | ||
} | ||
} | ||
|
||
func WithHostUtils(hostUtils hostutils.HostUtilsInterface) APIOption { | ||
return func(a *API) { | ||
a.hostUtils = hostUtils | ||
} | ||
} | ||
|
||
func WithMetricsReporter(metricsReporter metrics.ReporterInterface) APIOption { | ||
return func(a *API) { | ||
a.metricsReporter = metricsReporter | ||
} | ||
} | ||
|
||
func WithReleaseData(releaseData *release.ReleaseData) APIOption { | ||
return func(a *API) { | ||
a.releaseData = releaseData | ||
} | ||
} | ||
|
||
func WithConfigChan(configChan chan<- *types.InstallationConfig) APIOption { | ||
return func(a *API) { | ||
a.configChan = configChan | ||
} | ||
} | ||
|
||
func WithLicenseFile(licenseFile string) APIOption { | ||
return func(a *API) { | ||
a.licenseFile = licenseFile | ||
} | ||
} | ||
|
||
func WithAirgapBundle(airgapBundle string) APIOption { | ||
return func(a *API) { | ||
a.airgapBundle = airgapBundle | ||
} | ||
} | ||
|
||
func New(password string, opts ...APIOption) (*API, error) { | ||
api := &API{} | ||
|
||
for _, opt := range opts { | ||
opt(api) | ||
} | ||
|
||
if api.rc == nil { | ||
api.rc = runtimeconfig.New(nil) | ||
} | ||
|
||
if api.logger == nil { | ||
l, err := logger.NewLogger() | ||
if err != nil { | ||
return nil, fmt.Errorf("create logger: %w", err) | ||
} | ||
api.logger = l | ||
} | ||
|
||
if api.hostUtils == nil { | ||
api.hostUtils = hostutils.New( | ||
hostutils.WithLogger(api.logger), | ||
) | ||
} | ||
|
||
if api.authController == nil { | ||
authController, err := auth.NewAuthController(password) | ||
if err != nil { | ||
|
@@ -97,17 +163,21 @@ func New(password string, opts ...APIOption) (*API, error) { | |
} | ||
|
||
if api.installController == nil { | ||
installController, err := install.NewInstallController() | ||
installController, err := install.NewInstallController( | ||
install.WithRuntimeConfig(api.rc), | ||
install.WithLogger(api.logger), | ||
install.WithHostUtils(api.hostUtils), | ||
install.WithMetricsReporter(api.metricsReporter), | ||
install.WithReleaseData(api.releaseData), | ||
install.WithLicenseFile(api.licenseFile), | ||
install.WithAirgapBundle(api.airgapBundle), | ||
) | ||
Comment on lines
+166
to
+174
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should likely review some of these struct properties to understand if they need to be pointers to structs and we're making that choice deliberately or not. Right now I'm worried that we receive pointers to structs that we then pass to the controllers (and maybe these can even end up being used by things such as managers). If some end up unintentionally mutating state we can be in trouble trying to debug a particularly airy bug. |
||
if err != nil { | ||
return nil, fmt.Errorf("new install controller: %w", err) | ||
} | ||
api.installController = installController | ||
} | ||
|
||
if api.logger == nil { | ||
api.logger = NewDiscardLogger() | ||
} | ||
|
||
return api, nil | ||
} | ||
|
||
|
@@ -129,10 +199,19 @@ func (a *API) RegisterRoutes(router *mux.Router) { | |
authenticatedRouter.Use(a.authMiddleware) | ||
|
||
installRouter := authenticatedRouter.PathPrefix("/install").Subrouter() | ||
installRouter.HandleFunc("", a.getInstall).Methods("GET") | ||
installRouter.HandleFunc("/config", a.setInstallConfig).Methods("POST") | ||
installRouter.HandleFunc("/status", a.setInstallStatus).Methods("POST") | ||
installRouter.HandleFunc("/installation/config", a.getInstallInstallationConfig).Methods("GET") | ||
installRouter.HandleFunc("/installation/status", a.getInstallInstallationStatus).Methods("GET") | ||
installRouter.HandleFunc("/installation/configure", a.postInstallConfigureInstallation).Methods("POST") | ||
|
||
installRouter.HandleFunc("/host-preflights/status", a.getInstallHostPreflightsStatus).Methods("GET") | ||
installRouter.HandleFunc("/host-preflights/run", a.postInstallRunHostPreflights).Methods("POST") | ||
|
||
installRouter.HandleFunc("/node/setup", a.postInstallSetupNode).Methods("POST") | ||
|
||
// TODO (@salah): remove this once the cli isn't responsible for setting the install status | ||
// and the ui isn't polling for it to know if the entire install is complete | ||
installRouter.HandleFunc("/status", a.getInstallStatus).Methods("GET") | ||
installRouter.HandleFunc("/status", a.setInstallStatus).Methods("POST") | ||
|
||
consoleRouter := authenticatedRouter.PathPrefix("/console").Subrouter() | ||
consoleRouter.HandleFunc("/available-network-interfaces", a.getListAvailableNetworkInterfaces).Methods("GET") | ||
|
Uh oh!
There was an error while loading. Please reload this page.