Skip to content

Commit

Permalink
add support for missing wait and skip flags (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz authored Mar 20, 2023
1 parent 3d53a9c commit 67275ea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
10 changes: 3 additions & 7 deletions cmd/plural/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,15 @@ func (p *Plural) bounceHelm(c *cli.Context) error {
return err
}

args := []string{}
if c.IsSet("wait") {
args = append(args, "--wait")
}
skipArgs := []string{}
if c.IsSet("skip") {
for _, skipChart := range c.StringSlice("skip") {
skipString := fmt.Sprintf("%s.enabled=false", skipChart)
skip := []string{"--set", skipString}
args = append(args, skip...)
skipArgs = append(skipArgs, skipString)
}
}

return minimal.BounceHelm(args...)
return minimal.BounceHelm(c.IsSet("wait"), skipArgs...)
}

func (p *Plural) diffHelm(c *cli.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/wkspace/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (w *Workspace) DestroyHelm() error {
}

func (w *Workspace) Bounce() error {
return w.ToMinimal().BounceHelm()
return w.ToMinimal().BounceHelm(false)
}

func (w *Workspace) HelmDiff() error {
Expand Down
16 changes: 13 additions & 3 deletions pkg/wkspace/minimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"text/template"
"time"

Expand All @@ -27,6 +26,7 @@ import (
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/storage/driver"
"helm.sh/helm/v3/pkg/strvals"
"sigs.k8s.io/yaml"
)

Expand Down Expand Up @@ -70,7 +70,7 @@ func FormatValues(w io.Writer, vals string, output *output.Output) (err error) {
return
}

func (m *MinimalWorkspace) BounceHelm(extraArgs ...string) error {
func (m *MinimalWorkspace) BounceHelm(wait bool, skipArgs ...string) error {
path, err := filepath.Abs(pathing.SanitizeFilepath(filepath.Join("helm", m.Name)))
if err != nil {
return err
Expand All @@ -79,6 +79,13 @@ func (m *MinimalWorkspace) BounceHelm(extraArgs ...string) error {
if err != nil {
return err
}

for _, arg := range skipArgs {
if err := strvals.ParseInto(arg, defaultVals); err != nil {
return err
}
}

namespace := m.Config.Namespace(m.Name)
if m.HelmConfig == nil {
m.HelmConfig, err = helm.GetActionConfig(namespace)
Expand All @@ -87,7 +94,7 @@ func (m *MinimalWorkspace) BounceHelm(extraArgs ...string) error {
}
}

utils.Warn("helm upgrade --install --skip-crds --namespace %s %s %s %s\n", namespace, m.Name, path, strings.Join(extraArgs, " "))
utils.Warn("helm upgrade --install --skip-crds --namespace %s %s %s\n", namespace, m.Name, path)
chart, err := loader.Load(path)
if err != nil {
return err
Expand All @@ -100,6 +107,8 @@ func (m *MinimalWorkspace) BounceHelm(extraArgs ...string) error {
instClient.Namespace = namespace
instClient.ReleaseName = m.Name
instClient.SkipCRDs = true
instClient.Timeout = time.Minute * 10
instClient.Wait = wait

if req := chart.Metadata.Dependencies; req != nil {
if err := action.CheckDependencies(chart, req); err != nil {
Expand All @@ -113,6 +122,7 @@ func (m *MinimalWorkspace) BounceHelm(extraArgs ...string) error {
client.Namespace = namespace
client.SkipCRDs = true
client.Timeout = time.Minute * 10
client.Wait = wait
_, err = client.Run(m.Name, chart, defaultVals)
return err
}
Expand Down

0 comments on commit 67275ea

Please sign in to comment.