Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from epinio/add-predelete-to-uninstall
Browse files Browse the repository at this point in the history
Add preDelete action for uninstall
  • Loading branch information
Mario Manno authored Dec 2, 2021
2 parents f97f688 + 0fadd98 commit 78035bc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cmd/internal/installer/cli/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/spf13/viper"

"github.com/epinio/epinio/helpers/tracelog"
"github.com/epinio/installer/internal/duration"
"github.com/epinio/installer/internal/installer"
"github.com/epinio/installer/internal/kubernetes"
)
Expand Down Expand Up @@ -44,7 +45,8 @@ func uninstall(cmd *cobra.Command, args []string) error {

log.Info("plan", "components", p.String())

act := installer.NewUninstall(cluster, log)
ca := installer.NewComponentActions(cluster, log, duration.ToDeployment())
act := installer.NewUninstall(cluster, log, ca)

installer.ReverseWalk(ctx, m.Components, act)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/installer/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type Component struct {
// Type is 'helm' or 'yaml'
Type ComponentType `json:"type" yaml:"type"`

// PreDelete checks make sure the component can be uninstalled
PreDelete []ComponentAction `json:"pre_delete_check,omitempty" yaml:"preDelete"`

// PreDeploy checks make sure the component can be installed
PreDeploy []ComponentAction `json:"pre_deploy_check,omitempty" yaml:"preDeploy"`

Expand Down
11 changes: 10 additions & 1 deletion internal/installer/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import (
type Uninstall struct {
cluster *kubernetes.Cluster
log logr.Logger
ca *ComponentActions
}

var _ Action = &Uninstall{}

func NewUninstall(cluster *kubernetes.Cluster, log logr.Logger) *Uninstall {
func NewUninstall(cluster *kubernetes.Cluster, log logr.Logger, ca *ComponentActions) *Uninstall {
return &Uninstall{
ca: ca,
cluster: cluster,
log: log,
}
Expand All @@ -27,6 +29,13 @@ func (u Uninstall) Apply(ctx context.Context, c Component) error {
log := u.log.WithValues("component", c.ID, "type", c.Type)
log.Info("apply uninstall")

for _, chk := range c.PreDelete {
log.V(2).Info("pre deploy", "checkType", string(chk.Type))
if err := u.ca.Run(ctx, c, chk); err != nil {
return err
}
}

switch c.Type {
case Helm:
{
Expand Down
8 changes: 8 additions & 0 deletions internal/installer/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ import (
)

func yamlApply(log logr.Logger, c Component) error {
if c.Source.URL != "" {
return errors.New("URL not supported by YAML component")
}

if c.Source.Path == "" {
return errors.New("Empty path for YAML component")
}

path := c.Source.Path
if len(c.Values) > 0 {
var err error
Expand Down

0 comments on commit 78035bc

Please sign in to comment.