Skip to content
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

Use concrete types with destroyCmd.Run() #365

Merged
merged 2 commits into from
Aug 23, 2023
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
3 changes: 1 addition & 2 deletions cmd/up/space/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"k8s.io/client-go/kubernetes"

"github.com/upbound/up/internal/input"
"github.com/upbound/up/internal/install"
"github.com/upbound/up/internal/install/helm"
"github.com/upbound/up/internal/upterm"
)
Expand Down Expand Up @@ -113,7 +112,7 @@ func (c *destroyCmd) AfterApply(kongCtx *kong.Context) error {
}

// Run executes the uninstall command.
func (c *destroyCmd) Run(kClient kubernetes.Interface, mgr install.Manager) error {
func (c *destroyCmd) Run(kClient *kubernetes.Clientset, mgr *helm.Installer) error {
if err := mgr.Uninstall(); err != nil {
return err
}
Expand Down
40 changes: 20 additions & 20 deletions internal/install/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type LoaderFn func(name string) (*chart.Chart, error)
// HomeDirFn indicates the location of a user's home directory.
type HomeDirFn func() (string, error)

type installer struct {
type Installer struct {
repoURL *url.URL
chartFile *os.File
chartName string
Expand Down Expand Up @@ -144,89 +144,89 @@ type installer struct {
}

// InstallerModifierFn modifies the installer.
type InstallerModifierFn func(*installer)
type InstallerModifierFn func(*Installer)

// WithNamespace sets the namespace for the helm installer.
func WithNamespace(ns string) InstallerModifierFn {
return func(h *installer) {
return func(h *Installer) {
h.namespace = ns
}
}

// WithAlternateChart sets an alternate chart that is compatible to upgrade from if installed.
func WithAlternateChart(chartName string) InstallerModifierFn {
return func(h *installer) {
return func(h *Installer) {
h.alternateChart = chartName
}
}

// WithBasicAuth sets the username and password for the helm installer.
func WithBasicAuth(username, password string) InstallerModifierFn {
return func(h *installer) {
return func(h *Installer) {
h.username = username
h.password = password
}
}

// IsOCI indicates that the chart is an OCI image.
func IsOCI() InstallerModifierFn {
return func(h *installer) {
return func(h *Installer) {
h.oci = true
}
}

// WithLogger sets the logger for the helm installer.
func WithLogger(l logging.Logger) InstallerModifierFn {
return func(h *installer) {
return func(h *Installer) {
h.log = l
}
}

// WithCacheDir sets the cache directory for the helm installer.
func WithCacheDir(c string) InstallerModifierFn {
return func(h *installer) {
return func(h *Installer) {
h.cacheDir = c
}
}

// WithChart sets the chart to be installed/upgraded
func WithChart(chartFile *os.File) InstallerModifierFn {
return func(h *installer) {
return func(h *Installer) {
h.chartFile = chartFile
}
}

// RollbackOnError will cause installer to rollback on failed upgrade.
func RollbackOnError(r bool) InstallerModifierFn {
return func(h *installer) {
return func(h *Installer) {
h.rollbackOnError = r
}
}

// Force will force operations when possible.
func Force(f bool) InstallerModifierFn {
return func(h *installer) {
return func(h *Installer) {
h.force = f
}
}

// Wait will wait operations till they are completed.
func Wait() InstallerModifierFn {
return func(h *installer) {
return func(h *Installer) {
h.wait = true
}
}

// WithNoHooks will disable uninstall hooks
func WithNoHooks() InstallerModifierFn {
return func(h *installer) {
return func(h *Installer) {
h.noHooks = true
}
}

// NewManager builds a helm install manager for UXP.
func NewManager(config *rest.Config, chartName string, repoURL *url.URL, modifiers ...InstallerModifierFn) (install.Manager, error) { // nolint:gocyclo
h := &installer{
h := &Installer{
repoURL: repoURL,
chartName: chartName,
releaseName: chartName,
Expand Down Expand Up @@ -323,7 +323,7 @@ func NewManager(config *rest.Config, chartName string, repoURL *url.URL, modifie
}

// GetCurrentVersion gets the current UXP version in the cluster.
func (h *installer) GetCurrentVersion() (string, error) {
func (h *Installer) GetCurrentVersion() (string, error) {
var release *release.Release
var err error
release, err = h.getClient.Run(h.chartName)
Expand All @@ -348,7 +348,7 @@ func (h *installer) GetCurrentVersion() (string, error) {
}

// Install installs in the cluster.
func (h *installer) Install(version string, parameters map[string]any) error {
func (h *Installer) Install(version string, parameters map[string]any) error {
// make sure no version is already installed
current, err := h.GetCurrentVersion()
if err == nil {
Expand Down Expand Up @@ -378,7 +378,7 @@ func (h *installer) Install(version string, parameters map[string]any) error {
}

// Upgrade upgrades an existing installation to a new version.
func (h *installer) Upgrade(version string, parameters map[string]any) error {
func (h *Installer) Upgrade(version string, parameters map[string]any) error {
// check if version exists
current, err := h.GetCurrentVersion()
if err != nil {
Expand Down Expand Up @@ -413,13 +413,13 @@ func (h *installer) Upgrade(version string, parameters map[string]any) error {
}

// Uninstall uninstalls an installation.
func (h *installer) Uninstall() error {
func (h *Installer) Uninstall() error {
_, err := h.uninstallClient.Run(h.chartName)
return err
}

// pullAndLoad pulls and loads a chart or fetches it from the cache.
func (h *installer) pullAndLoad(version string) (*chart.Chart, error) { //nolint:gocyclo
func (h *Installer) pullAndLoad(version string) (*chart.Chart, error) { //nolint:gocyclo
// check to see if version is cached
if version != "" {
// helm strips versions with leading v, which can cause issues when fetching
Expand Down Expand Up @@ -469,7 +469,7 @@ func (h *installer) pullAndLoad(version string) (*chart.Chart, error) { //nolint
return c, nil
}

func (h *installer) pullChart(version string) error {
func (h *Installer) pullChart(version string) error {
// NOTE(hasheddan): Because UXP uses different Helm repos for stable and
// development versions, we are safe to set version to latest in repo
// regardless of whether stable or unstable is specified.
Expand Down
Loading
Loading