Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func WithMetricsReporter(metricsReporter metrics.ReporterInterface) Option {

// New creates a new API instance.
func New(cfg types.APIConfig, opts ...Option) (*API, error) {
if cfg.InstallTarget == "" {
return nil, fmt.Errorf("target is required")
}

api := &API{
cfg: cfg,
}
Expand Down
9 changes: 9 additions & 0 deletions api/controllers/app/install/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type InstallController struct {
clusterID string
airgapBundle string
privateCACertConfigMapName string
k8sVersion string
restClientGetter genericclioptions.RESTClientGetter
kubeConfigPath string
}
Expand Down Expand Up @@ -132,6 +133,12 @@ func WithPrivateCACertConfigMapName(configMapName string) InstallControllerOptio
}
}

func WithK8sVersion(k8sVersion string) InstallControllerOption {
return func(c *InstallController) {
c.k8sVersion = k8sVersion
}
}

func WithRESTClientGetter(restClientGetter genericclioptions.RESTClientGetter) InstallControllerOption {
return func(c *InstallController) {
c.restClientGetter = restClientGetter
Expand Down Expand Up @@ -205,6 +212,7 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
appreleasemanager.WithReleaseData(controller.releaseData),
appreleasemanager.WithLicense(license),
appreleasemanager.WithPrivateCACertConfigMapName(controller.privateCACertConfigMapName),
appreleasemanager.WithK8sVersion(controller.k8sVersion),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only passing the version to the release manager, not the install manager. is that correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm does the install manager assume a linux target and uses the k0s version? If so then it should be fixed to follow the pattern in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated so they both use it

)
if err != nil {
return nil, fmt.Errorf("create app release manager: %w", err)
Expand All @@ -220,6 +228,7 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
appinstallmanager.WithClusterID(controller.clusterID),
appinstallmanager.WithAirgapBundle(controller.airgapBundle),
appinstallmanager.WithAppInstallStore(controller.store.AppInstallStore()),
appinstallmanager.WithK8sVersion(controller.k8sVersion),
appinstallmanager.WithRESTClientGetter(controller.restClientGetter),
appinstallmanager.WithKubeConfigPath(controller.kubeConfigPath),
)
Expand Down
4 changes: 4 additions & 0 deletions api/controllers/app/install/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func (s *AppInstallControllerTestSuite) TestPatchAppConfigValues() {
WithAppInstallManager(appInstallManager),
WithStore(&store.MockStore{}),
WithReleaseData(&release.ReleaseData{}),
WithK8sVersion("v1.33.0"),
)
require.NoError(t, err, "failed to create install controller")

Expand Down Expand Up @@ -409,6 +410,7 @@ func (s *AppInstallControllerTestSuite) TestRunAppPreflights() {
WithAppReleaseManager(appReleaseManager),
WithStore(&store.MockStore{}),
WithReleaseData(&release.ReleaseData{}),
WithK8sVersion("v1.33.0"),
)
require.NoError(t, err, "failed to create install controller")

Expand Down Expand Up @@ -481,6 +483,7 @@ func (s *AppInstallControllerTestSuite) TestGetAppInstallStatus() {
WithAppInstallManager(appInstallManager),
WithStore(&store.MockStore{}),
WithReleaseData(&release.ReleaseData{}),
WithK8sVersion("v1.33.0"),
)
require.NoError(t, err, "failed to create install controller")

Expand Down Expand Up @@ -692,6 +695,7 @@ func (s *AppInstallControllerTestSuite) TestInstallApp() {
WithAppInstallManager(appInstallManager),
WithStore(&store.MockStore{}),
WithReleaseData(&release.ReleaseData{}),
WithK8sVersion("v1.33.0"),
)
require.NoError(t, err, "failed to create install controller")

Expand Down
10 changes: 9 additions & 1 deletion api/controllers/kubernetes/install/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type InstallController struct {
installationManager installation.InstallationManager
infraManager infra.InfraManager
metricsReporter metrics.ReporterInterface
k8sVersion string
restClientGetter genericclioptions.RESTClientGetter
releaseData *release.ReleaseData
password string
Expand Down Expand Up @@ -73,6 +74,12 @@ func WithMetricsReporter(metricsReporter metrics.ReporterInterface) InstallContr
}
}

func WithK8sVersion(k8sVersion string) InstallControllerOption {
return func(c *InstallController) {
c.k8sVersion = k8sVersion
}
}

func WithRESTClientGetter(restClientGetter genericclioptions.RESTClientGetter) InstallControllerOption {
return func(c *InstallController) {
c.restClientGetter = restClientGetter
Expand Down Expand Up @@ -191,7 +198,8 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
appcontroller.WithReleaseData(controller.releaseData),
appcontroller.WithConfigValues(controller.configValues),
appcontroller.WithAirgapBundle(controller.airgapBundle),
appcontroller.WithPrivateCACertConfigMapName(""), // Private CA ConfigMap functionality not yet implemented for Kubernetes installations
appcontroller.WithPrivateCACertConfigMapName(""), // Private CA ConfigMap functionality not yet implemented for Kubernetes installations
appcontroller.WithK8sVersion(controller.k8sVersion), // Used to determine the kubernetes version for the helm client
appcontroller.WithRESTClientGetter(controller.restClientGetter),
)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions api/controllers/kubernetes/install/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func TestGetInstallationConfig(t *testing.T) {
WithInstallation(ki),
WithInstallationManager(mockManager),
WithReleaseData(getTestReleaseData(&kotsv1beta1.Config{})),
WithK8sVersion("v1.33.0"),
)
require.NoError(t, err)

Expand Down Expand Up @@ -219,6 +220,7 @@ func TestConfigureInstallation(t *testing.T) {
WithStore(mockStore),
WithMetricsReporter(metricsReporter),
WithReleaseData(getTestReleaseData(&kotsv1beta1.Config{})),
WithK8sVersion("v1.33.0"),
)
require.NoError(t, err)

Expand Down Expand Up @@ -282,6 +284,7 @@ func TestGetInstallationStatus(t *testing.T) {
controller, err := NewInstallController(
WithInstallationManager(mockManager),
WithReleaseData(getTestReleaseData(&kotsv1beta1.Config{})),
WithK8sVersion("v1.33.0"),
)
require.NoError(t, err)

Expand Down Expand Up @@ -408,6 +411,7 @@ func TestSetupInfra(t *testing.T) {
appcontroller.WithStore(mockStore),
appcontroller.WithReleaseData(getTestReleaseData(&appConfig)),
appcontroller.WithAppConfigManager(mockAppConfigManager),
appcontroller.WithK8sVersion("v1.33.0"),
)
require.NoError(t, err)

Expand All @@ -420,6 +424,7 @@ func TestSetupInfra(t *testing.T) {
WithMetricsReporter(mockMetricsReporter),
WithReleaseData(getTestReleaseData(&appConfig)),
WithStore(mockStore),
WithK8sVersion("v1.33.0"),
)
require.NoError(t, err)

Expand Down Expand Up @@ -514,6 +519,7 @@ func TestGetInfra(t *testing.T) {
controller, err := NewInstallController(
WithInfraManager(mockManager),
WithReleaseData(getTestReleaseData(&kotsv1beta1.Config{})),
WithK8sVersion("v1.33.0"),
)
require.NoError(t, err)

Expand Down
2 changes: 2 additions & 0 deletions api/controllers/linux/install/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/replicatedhq/embedded-cluster/pkg/metrics"
"github.com/replicatedhq/embedded-cluster/pkg/release"
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
"github.com/replicatedhq/embedded-cluster/pkg/versions"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -266,6 +267,7 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
appcontroller.WithClusterID(controller.clusterID),
appcontroller.WithAirgapBundle(controller.airgapBundle),
appcontroller.WithPrivateCACertConfigMapName(adminconsole.PrivateCASConfigMapName), // Linux installations use the ConfigMap
appcontroller.WithK8sVersion(versions.K0sVersion), // Used to determine the kubernetes version for the helm client
appcontroller.WithKubeConfigPath(controller.rc.PathToKubeConfig()),
)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions api/controllers/linux/install/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,7 @@ func TestSetupInfra(t *testing.T) {
appcontroller.WithStateMachine(sm),
appcontroller.WithStore(mockStore),
appcontroller.WithReleaseData(getTestReleaseData(&appConfig)),
appcontroller.WithK8sVersion("v1.33.0"),
appcontroller.WithLicense([]byte("spec:\n licenseID: test-license\n")),
appcontroller.WithAppConfigManager(mockAppConfigManager),
appcontroller.WithAppPreflightManager(mockAppPreflightManager),
Expand Down
43 changes: 23 additions & 20 deletions api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
healthhandler "github.com/replicatedhq/embedded-cluster/api/internal/handlers/health"
kuberneteshandler "github.com/replicatedhq/embedded-cluster/api/internal/handlers/kubernetes"
linuxhandler "github.com/replicatedhq/embedded-cluster/api/internal/handlers/linux"
apitypes "github.com/replicatedhq/embedded-cluster/api/types"
)

type handlers struct {
Expand Down Expand Up @@ -49,28 +50,30 @@ func (a *API) initHandlers() error {
}
a.handlers.health = healthHandler

// Linux handler
linuxHandler, err := linuxhandler.New(
a.cfg,
linuxhandler.WithLogger(a.logger),
linuxhandler.WithMetricsReporter(a.metricsReporter),
linuxhandler.WithInstallController(a.linuxInstallController),
)
if err != nil {
return fmt.Errorf("new linux handler: %w", err)
}
a.handlers.linux = linuxHandler
switch a.cfg.InstallTarget {
case apitypes.InstallTargetLinux:
linuxHandler, err := linuxhandler.New(
a.cfg,
linuxhandler.WithLogger(a.logger),
linuxhandler.WithMetricsReporter(a.metricsReporter),
linuxhandler.WithInstallController(a.linuxInstallController),
)
if err != nil {
return fmt.Errorf("new linux handler: %w", err)
}
a.handlers.linux = linuxHandler

// Kubernetes handler
kubernetesHandler, err := kuberneteshandler.New(
a.cfg,
kuberneteshandler.WithLogger(a.logger),
kuberneteshandler.WithInstallController(a.kubernetesInstallController),
)
if err != nil {
return fmt.Errorf("new kubernetes handler: %w", err)
case apitypes.InstallTargetKubernetes:
kubernetesHandler, err := kuberneteshandler.New(
a.cfg,
kuberneteshandler.WithLogger(a.logger),
kuberneteshandler.WithInstallController(a.kubernetesInstallController),
)
if err != nil {
return fmt.Errorf("new kubernetes handler: %w", err)
}
a.handlers.kubernetes = kubernetesHandler
}
a.handlers.kubernetes = kubernetesHandler

return nil
}
5 changes: 3 additions & 2 deletions api/integration/app/install/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ func TestAppInstallSuite(t *testing.T) {
)
require.NoError(t, err)
// Create the API with the install controller
return integration.NewAPIWithReleaseData(t,
return integration.NewTargetLinuxAPIWithReleaseData(t,
api.WithLinuxInstallController(controller),
api.WithAuthController(auth.NewStaticAuthController("TOKEN")),
api.WithLogger(logger.NewDiscardLogger()),
Expand All @@ -1068,10 +1068,11 @@ func TestAppInstallSuite(t *testing.T) {
kubernetesinstall.WithReleaseData(rd),
kubernetesinstall.WithLicense([]byte("spec:\n licenseID: test-license\n")),
kubernetesinstall.WithConfigValues(configValues),
kubernetesinstall.WithK8sVersion("v1.33.0"),
)
require.NoError(t, err)
// Create the API with the install controller
return integration.NewAPIWithReleaseData(t,
return integration.NewTargetKubernetesAPIWithReleaseData(t,
api.WithKubernetesInstallController(controller),
api.WithAuthController(auth.NewStaticAuthController("TOKEN")),
api.WithLogger(logger.NewDiscardLogger()),
Expand Down
10 changes: 5 additions & 5 deletions api/integration/auth/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/replicatedhq/embedded-cluster/api/controllers/auth"
linuxinstall "github.com/replicatedhq/embedded-cluster/api/controllers/linux/install"
"github.com/replicatedhq/embedded-cluster/api/integration"
"github.com/replicatedhq/embedded-cluster/api/internal/managers/linux/installation"
linuxinstallation "github.com/replicatedhq/embedded-cluster/api/internal/managers/linux/installation"
"github.com/replicatedhq/embedded-cluster/api/internal/utils"
"github.com/replicatedhq/embedded-cluster/api/pkg/logger"
"github.com/replicatedhq/embedded-cluster/api/types"
Expand All @@ -28,15 +28,15 @@ func TestAuthLoginAndTokenValidation(t *testing.T) {

// Create an install controller
installController, err := linuxinstall.NewInstallController(
linuxinstall.WithInstallationManager(installation.NewInstallationManager(
installation.WithNetUtils(&utils.MockNetUtils{}),
linuxinstall.WithInstallationManager(linuxinstallation.NewInstallationManager(
linuxinstallation.WithNetUtils(&utils.MockNetUtils{}),
)),
linuxinstall.WithReleaseData(integration.DefaultReleaseData()),
)
require.NoError(t, err)

// Create the API with the auth controller
apiInstance := integration.NewAPIWithReleaseData(t,
apiInstance := integration.NewTargetLinuxAPIWithReleaseData(t,
api.WithAuthController(authController),
api.WithLinuxInstallController(installController),
api.WithLogger(logger.NewDiscardLogger()),
Expand Down Expand Up @@ -134,7 +134,7 @@ func TestAuthLoginAndTokenValidation(t *testing.T) {

func TestAPIClientLogin(t *testing.T) {
// Create the API with the auth controller
apiInstance := integration.NewAPIWithReleaseData(t,
apiInstance := integration.NewTargetLinuxAPIWithReleaseData(t,
api.WithLogger(logger.NewDiscardLogger()),
)

Expand Down
6 changes: 3 additions & 3 deletions api/integration/console/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestConsoleListAvailableNetworkInterfaces(t *testing.T) {
require.NoError(t, err)

// Create the API with the install controller
apiInstance := integration.NewAPIWithReleaseData(t,
apiInstance := integration.NewTargetLinuxAPIWithReleaseData(t,
api.WithConsoleController(consoleController),
api.WithAuthController(auth.NewStaticAuthController("TOKEN")),
api.WithLogger(logger.NewDiscardLogger()),
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestConsoleListAvailableNetworkInterfacesUnauthorized(t *testing.T) {
require.NoError(t, err)

// Create the API with the install controller
apiInstance := integration.NewAPIWithReleaseData(t,
apiInstance := integration.NewTargetLinuxAPIWithReleaseData(t,
api.WithConsoleController(consoleController),
api.WithAuthController(auth.NewStaticAuthController("VALID_TOKEN")),
api.WithLogger(logger.NewDiscardLogger()),
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestConsoleListAvailableNetworkInterfacesError(t *testing.T) {
require.NoError(t, err)

// Create the API with the install controller
apiInstance := integration.NewAPIWithReleaseData(t,
apiInstance := integration.NewTargetLinuxAPIWithReleaseData(t,
api.WithConsoleController(consoleController),
api.WithAuthController(auth.NewStaticAuthController("TOKEN")),
api.WithLogger(logger.NewDiscardLogger()),
Expand Down
9 changes: 6 additions & 3 deletions api/integration/kubernetes/install/appconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ func TestInstallController_PatchAppConfigValuesWithAPIClient(t *testing.T) {
kubernetesinstall.WithReleaseData(&release.ReleaseData{
AppConfig: &appConfig,
}),
kubernetesinstall.WithK8sVersion("v1.33.0"),
)
require.NoError(t, err)

// Create the API with the install controller
apiInstance := integration.NewAPIWithReleaseData(t,
apiInstance := integration.NewTargetKubernetesAPIWithReleaseData(t,
api.WithKubernetesInstallController(installController),
api.WithAuthController(auth.NewStaticAuthController("TOKEN")),
api.WithLogger(logger.NewDiscardLogger()),
Expand Down Expand Up @@ -116,11 +117,12 @@ func TestInstallController_PatchAppConfigValuesWithAPIClient(t *testing.T) {
kubernetesinstall.WithReleaseData(&release.ReleaseData{
AppConfig: &appConfig,
}),
kubernetesinstall.WithK8sVersion("v1.33.0"),
)
require.NoError(t, err)

// Create the API with the completed install controller
completedAPIInstance := integration.NewAPIWithReleaseData(t,
completedAPIInstance := integration.NewTargetKubernetesAPIWithReleaseData(t,
api.WithKubernetesInstallController(completedInstallController),
api.WithAuthController(auth.NewStaticAuthController("TOKEN")),
api.WithLogger(logger.NewDiscardLogger()),
Expand Down Expand Up @@ -219,11 +221,12 @@ func TestInstallController_GetAppConfigValuesWithAPIClient(t *testing.T) {
kubernetesinstall.WithReleaseData(&release.ReleaseData{
AppConfig: &appConfig,
}),
kubernetesinstall.WithK8sVersion("v1.33.0"),
)
require.NoError(t, err)

// Create the API with the install controller
apiInstance := integration.NewAPIWithReleaseData(t,
apiInstance := integration.NewTargetKubernetesAPIWithReleaseData(t,
api.WithKubernetesInstallController(installController),
api.WithAuthController(auth.NewStaticAuthController("TOKEN")),
api.WithLogger(logger.NewDiscardLogger()),
Expand Down
Loading
Loading