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
21 changes: 14 additions & 7 deletions pkg/kagent/install/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ type UninstallOptions struct {
Confirm func(ctx context.Context, summary string) (bool, error)
}

// Uninstall removes the releases in the reverse of install order. It keeps
// CRDs, secrets, the database volume and the namespaces unless
// opts.IncludeCRDs or opts.Purge say otherwise.
// Uninstall shows UninstallSummary to opts.Confirm, then runs
// UninstallSteps.
func (in *Installer) Uninstall(ctx context.Context, opts UninstallOptions) error {
summary, err := in.inventory(ctx, opts)
summary, err := in.UninstallSummary(ctx, opts)
if err != nil {
return err
}
Expand All @@ -70,6 +69,14 @@ func (in *Installer) Uninstall(ctx context.Context, opts UninstallOptions) error
return ErrAborted
}
}
return in.Run(ctx, in.UninstallSteps(opts))
}

// UninstallSteps returns the steps that remove the releases in the reverse of
// install order. They keep CRDs, secrets, the database volume and the
// namespaces unless opts.IncludeCRDs or opts.Purge say otherwise. They don't
// call opts.Confirm.
func (in *Installer) UninstallSteps(opts UninstallOptions) []Step {
steps := []Step{
{"Delete worker pools", in.deleteWorkerPools},
{"Uninstall Substrate", in.uninstallStep(substrateRelease)},
Expand All @@ -86,11 +93,11 @@ func (in *Installer) Uninstall(ctx context.Context, opts UninstallOptions) error
Step{"Delete namespaces", in.deleteNamespaces},
)
}
return in.Run(ctx, steps)
return steps
}

// inventory describes what Uninstall will remove, for opts.Confirm.
func (in *Installer) inventory(ctx context.Context, opts UninstallOptions) (string, error) {
// UninstallSummary describes what UninstallSteps will remove.
func (in *Installer) UninstallSummary(ctx context.Context, opts UninstallOptions) (string, error) {
var installed []string
for _, r := range allReleases {
rel, err := in.helm.get(r)
Expand Down
20 changes: 16 additions & 4 deletions pkg/kagent/install/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,20 @@ type UpgradeOptions struct {
Out io.Writer
}

// Upgrade moves every release to the charts in this binary.
// Upgrade runs UpgradeSteps.
func (in *Installer) Upgrade(ctx context.Context, opts UpgradeOptions) error {
steps, err := in.UpgradeSteps(ctx, opts)
if err != nil {
return err
}
return in.Run(ctx, steps)
}

// UpgradeSteps returns the steps that move every release to the charts in
// this binary. It reads the cluster to check for the microVM SandboxConfig.
// After it is called, the Installer's helm steps upgrade releases across
// chart versions.
func (in *Installer) UpgradeSteps(ctx context.Context, opts UpgradeOptions) ([]Step, error) {
in.upgrading = true
steps := []Step{
{"Check versions", in.checkVersions},
Expand All @@ -63,7 +75,7 @@ func (in *Installer) Upgrade(ctx context.Context, opts UpgradeOptions) error {
for _, u := range upgradeOrder {
steps = append(steps, Step{"Diff " + u.r.name, in.diffStep(u.r, in.valuesFor(u.r), opts.Out)})
}
return in.Run(ctx, steps)
return steps, nil
}
steps = append(steps,
Step{"Create pod certificate CAs", in.createPodCertCAs},
Expand All @@ -77,7 +89,7 @@ func (in *Installer) Upgrade(ctx context.Context, opts UpgradeOptions) error {
// A new release may pin new microVM assets.
microVM, err := in.hasMicroVMSandboxConfig(ctx)
if err != nil {
return err
return nil, err
}
if microVM {
steps = append(steps,
Expand All @@ -86,7 +98,7 @@ func (in *Installer) Upgrade(ctx context.Context, opts UpgradeOptions) error {
)
}
steps = append(steps, Step{"Check API", in.checkAPI})
return in.Run(ctx, steps)
return steps, nil
}

// hasMicroVMSandboxConfig reports whether the microvm SandboxConfig exists.
Expand Down
Loading