Skip to content
Open
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
12 changes: 11 additions & 1 deletion api/controllers/app/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
"github.com/sirupsen/logrus"
helmcli "helm.sh/helm/v3/pkg/cli"
"k8s.io/client-go/metadata"
"sigs.k8s.io/controller-runtime/pkg/client"
kyaml "sigs.k8s.io/yaml"
)
Expand All @@ -32,7 +33,7 @@ type Controller interface {
GetAppPreflightStatus(ctx context.Context) (types.Status, error)
GetAppPreflightOutput(ctx context.Context) (*types.PreflightsOutput, error)
GetAppPreflightTitles(ctx context.Context) ([]string, error)
InstallApp(ctx context.Context, ignoreAppPreflights bool) error
InstallApp(ctx context.Context, opts InstallAppOptions) error
GetAppInstallStatus(ctx context.Context) (types.AppInstall, error)
UpgradeApp(ctx context.Context, ignoreAppPreflights bool) error
GetAppUpgradeStatus(ctx context.Context) (types.AppUpgrade, error)
Expand All @@ -52,6 +53,7 @@ type AppController struct {
releaseData *release.ReleaseData
hcli helm.Client
kcli client.Client
mcli metadata.Interface
preflightRunner preflights.PreflightRunnerInterface
kubernetesEnvSettings *helmcli.EnvSettings
store store.Store
Expand Down Expand Up @@ -129,6 +131,12 @@ func WithKubeClient(kcli client.Client) AppControllerOption {
}
}

func WithMetadataClient(mcli metadata.Interface) AppControllerOption {
return func(c *AppController) {
c.mcli = mcli
}
}

func WithKubernetesEnvSettings(envSettings *helmcli.EnvSettings) AppControllerOption {
return func(c *AppController) {
c.kubernetesEnvSettings = envSettings
Expand Down Expand Up @@ -262,7 +270,9 @@ func NewAppController(opts ...AppControllerOption) (*AppController, error) {
appinstallmanager.WithAirgapBundle(controller.airgapBundle),
appinstallmanager.WithAppInstallStore(controller.store.AppInstallStore()),
appinstallmanager.WithKubeClient(controller.kcli),
appinstallmanager.WithMetadataClient(controller.mcli),
appinstallmanager.WithKubernetesEnvSettings(controller.kubernetesEnvSettings),
appinstallmanager.WithHelmClient(controller.hcli),
)
if err != nil {
return nil, fmt.Errorf("create app install manager: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/app/controller_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func (m *MockController) GetAppPreflightTitles(ctx context.Context) ([]string, e
}

// InstallApp mocks the InstallApp method
func (m *MockController) InstallApp(ctx context.Context, ignoreAppPreflights bool) error {
args := m.Called(ctx, ignoreAppPreflights)
func (m *MockController) InstallApp(ctx context.Context, opts InstallAppOptions) error {
args := m.Called(ctx, opts)
return args.Error(0)
}

Expand Down
27 changes: 20 additions & 7 deletions api/controllers/app/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ import (

"github.com/replicatedhq/embedded-cluster/api/internal/states"
"github.com/replicatedhq/embedded-cluster/api/types"
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
)

var (
ErrAppPreflightChecksFailed = errors.New("app preflight checks failed")
)

type InstallAppOptions struct {
IgnoreAppPreflights bool
ProxySpec *ecv1beta1.ProxySpec
RegistrySettings *types.RegistrySettings
HostCABundlePath string
}

// InstallApp triggers app installation with proper state transitions and panic handling
func (c *AppController) InstallApp(ctx context.Context, ignoreAppPreflights bool) (finalErr error) {
func (c *AppController) InstallApp(ctx context.Context, opts InstallAppOptions) (finalErr error) {
logger := c.logger.WithField("operation", "install-app")

lock, err := c.stateMachine.AcquireLock()
Expand Down Expand Up @@ -45,7 +53,7 @@ func (c *AppController) InstallApp(ctx context.Context, ignoreAppPreflights bool
}

allowIgnoreAppPreflights := true // TODO: implement if we decide to support a ignore-app-preflights CLI flag for V3
if !ignoreAppPreflights || !allowIgnoreAppPreflights {
if !opts.IgnoreAppPreflights || !allowIgnoreAppPreflights {
return types.NewBadRequestError(ErrAppPreflightChecksFailed)
}

Expand All @@ -60,9 +68,15 @@ func (c *AppController) InstallApp(ctx context.Context, ignoreAppPreflights bool
}

// Get config values for app installation
configValues, err := c.appConfigManager.GetKotsadmConfigValues()
appConfigValues, err := c.GetAppConfigValues(ctx)
if err != nil {
return fmt.Errorf("get app config values for app install: %w", err)
}

// Extract installable Helm charts from release manager
installableCharts, err := c.appReleaseManager.ExtractInstallableHelmCharts(ctx, appConfigValues, opts.ProxySpec, opts.RegistrySettings)
if err != nil {
return fmt.Errorf("get kotsadm config values for app install: %w", err)
return fmt.Errorf("extract installable helm charts: %w", err)
}

err = c.stateMachine.Transition(lock, states.StateAppInstalling, nil)
Expand Down Expand Up @@ -97,9 +111,8 @@ func (c *AppController) InstallApp(ctx context.Context, ignoreAppPreflights bool
return fmt.Errorf("set status to running: %w", err)
}

// Install the app
err := c.appInstallManager.Install(ctx, configValues)
if err != nil {
// Install the app with installable charts
if err := c.appInstallManager.Install(ctx, installableCharts, appConfigValues, opts.RegistrySettings, opts.HostCABundlePath); err != nil {
return fmt.Errorf("install app: %w", err)
}

Expand Down
Loading
Loading