diff --git a/cmd/commands.go b/cmd/commands.go index db67807..9ff2362 100644 --- a/cmd/commands.go +++ b/cmd/commands.go @@ -273,7 +273,7 @@ func Commands() []*cli.Command { Usage: "Destroy releases", Aliases: []string{"d"}, Before: readInputSourceWithContext(gitSpec, conf, flags["releaseHelmfile"]), - Flags: flags["releaseHelmfileWithOutput"], + Flags: flags["releaseHelmfile"], Category: "release", BashComplete: util.ShellCompleteCustomOutput, Action: releaseHelmfileAction(conf), diff --git a/cmd/k3d.go b/cmd/k3d.go index f7e9528..83df182 100644 --- a/cmd/k3d.go +++ b/cmd/k3d.go @@ -1,6 +1,7 @@ package cmd import ( + "fmt" "os" "github.com/urfave/cli/v2" @@ -41,7 +42,7 @@ func (k *K3DCommands) prepareK3D(args ...string) error { switch { case k.APICluster: - k.SpecCMD.Envs = append(k.SpecCMD.Envs, "K3D_NAME=capi") + k.SpecCMD.Envs = append(k.SpecCMD.Envs, "K3D_NAME="+util.CAPI) case k.K3DCluster: k.SpecCMD.Envs = append(k.SpecCMD.Envs, "K3D_NAME="+k.Conf.Name) } @@ -58,9 +59,9 @@ func (k *K3DCommands) prepareK3D(args ...string) error { func (k *K3DCommands) createDeleteK3DCluster() error { switch k.Ctx.Command.Category { - case "capi": + case util.CAPI: k.APICluster = true - case "k3d": + case util.K3DPrefix: k.K3DCluster = true } @@ -68,10 +69,11 @@ func (k *K3DCommands) createDeleteK3DCluster() error { return err } - k.SpecCMD = k.prepareHelmfile("-l", "app="+k.Ctx.Command.Category+"-cluster", "template") + k.SpecCMD = k.prepareHelmfile("--log-level", "error", "-l", "cluster="+k.Ctx.Command.Category, "template") k.SpecCMD.DisableStdOut = true if err := runner(k).runCMD(); err != nil { - return err + return fmt.Errorf("Helmfile failed to render template by label release: cluster=%s\n%s", + k.Ctx.Command.Category, k.SpecCMD.StderrBuf.String()) } k3dConfig, err := util.CreateTempYAMLFile("/tmp", k.Ctx.Command.Category+"-config", k.SpecCMD.StdoutBuf.Bytes()) diff --git a/cmd/release.go b/cmd/release.go index 245ad88..bb9605d 100644 --- a/cmd/release.go +++ b/cmd/release.go @@ -166,6 +166,8 @@ func (rc *ReleaseCommands) nestedHelmfiles(envs ...string) []string { } func (rc *ReleaseCommands) prepareHelmfile(args ...string) *util.SpecCMD { + defaultArgs := []string{"--environment", rc.Conf.Environment} + envs := append([]string{}, "NAME="+rc.Conf.Name, "TENANT="+rc.Conf.Tenant, @@ -193,9 +195,12 @@ func (rc *ReleaseCommands) prepareHelmfile(args ...string) *util.SpecCMD { envs = append(envs, "K3D_CLUSTER="+strconv.FormatBool(rc.K3DCluster)) } + if len(rc.Ctx.String("helmfile-log-level")) > 0 { + defaultArgs = append(defaultArgs, "--log-level", rc.Ctx.String("helmfile-log-level")) + } + return &util.SpecCMD{ - Args: append([]string{"--environment", rc.Conf.Environment, "--log-level", - rc.Ctx.String("helmfile-log-level")}, args...), + Args: append(defaultArgs, args...), Command: "helmfile", Ctx: rc.Ctx.Context, Dir: rc.WorkDir, @@ -230,8 +235,11 @@ func (rc *ReleaseCommands) releaseMiddleware() error { if _, currentContext, err := rc.getKubeContext(); err != nil { return err } else { - if strings.Contains(currentContext, util.K3DConfigPrefix) { + switch { + case strings.Contains(currentContext, util.K3DPrefix) && !strings.Contains(currentContext, util.CAPI): rc.K3DCluster = true + case currentContext == util.K3DPrefix+"-"+util.CAPI: + rc.APICluster = true } } @@ -288,7 +296,7 @@ func (rc *ReleaseCommands) getKubeContext() (string, string, error) { contextName = "" } - if rc.K3DCluster && len(contextName) > 0 && !strings.Contains(contextName, util.K3DConfigPrefix) { + if rc.K3DCluster && len(contextName) > 0 && !strings.Contains(contextName, util.K3DPrefix) { return "", "", fmt.Errorf("remote Kubernetes context already exists %s for this branch", contextName) } @@ -312,16 +320,10 @@ func (rc *ReleaseCommands) releaseKubeContext() error { return nil } - if strings.Contains(contextName, util.K3DConfigPrefix) && rc.UpdateContext { + if strings.Contains(contextName, util.K3DPrefix) && rc.UpdateContext { return fmt.Errorf("current context %s already used for K3D cluster, --force flag cannot be used", contextName) } - //cc := &ClusterCommands{ - // Conf: rc.Conf, - // Ctx: rc.Ctx, - // WorkDir: util.GetPwdPath(""), - //} - if err := newClusterCommands(rc.Conf, rc.Ctx, util.GetPwdPath("")).awsClusterContext(); err != nil { return err } diff --git a/util/dictionary.go b/util/dictionary.go index baf086a..58cc221 100644 --- a/util/dictionary.go +++ b/util/dictionary.go @@ -3,13 +3,14 @@ package util const ( AWSClusterProvider = "aws" AzureClusterProvider = "azure" + CAPI = "capi" GitSSHPrivateKey = ".ssh/id_rsa" GlobalsFileName = "globals.yaml.gotmpl" HelmfileFileName = "helmfile.yaml" HelmfileGoTmplName = HelmfileFileName + ".gotmpl" HelpFlagFull = "--help" - K3DConfigPrefix = "k3d" - LocalClusterProvider = K3DConfigPrefix + K3DPrefix = "k3d" + LocalClusterProvider = K3DPrefix RMKBin = "rmk" RMKBucketName = "edenlabllc-rmk" RMKBucketRegion = "eu-north-1"