Skip to content

Commit

Permalink
get env - add failed release only if it isnt already deployed
Browse files Browse the repository at this point in the history
  • Loading branch information
maorfr committed Oct 16, 2018
1 parent 9bf6c49 commit f0ee8a0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pkg/orca/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewGetEnvCmd(out io.Writer) *cobra.Command {
return nil
},
Run: func(cmd *cobra.Command, args []string) {
releases := utils.GetInstalledReleases(e.kubeContext, e.name, true)
releases := utils.GetInstalledReleases(e.kubeContext, e.name, false)

switch e.output {
case "yaml":
Expand Down
35 changes: 0 additions & 35 deletions pkg/utils/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,6 @@ import (
"time"
)

// GetInstalledReleases gets the installed Helm releases in a given namespace
func GetInstalledReleases(kubeContext, namespace string, includeFailed bool) []ReleaseSpec {

statuses := []string{"DEPLOYED"}
if includeFailed {
statuses = append(statuses, "FAILED")
}

tillerNamespace := "kube-system"
tillerResourceLabel := "OWNER=TILLER"
storage := getTillerStorage(kubeContext, tillerNamespace)

var releaseSpecs []ReleaseSpec
list, err := listReleases(kubeContext, namespace, storage, tillerNamespace, tillerResourceLabel)
if err != nil {
log.Fatal(err)
}

for _, releaseData := range list {

if !Contains(statuses, releaseData.status) {
continue
}

var releaseSpec ReleaseSpec
releaseSpec.ReleaseName = releaseData.name
releaseSpec.ChartName = releaseData.chart
releaseSpec.ChartVersion = releaseData.version

releaseSpecs = append(releaseSpecs, releaseSpec)
}

return releaseSpecs
}

// DeployChartsFromRepository deploys a list of Helm charts from a repository in parallel
func DeployChartsFromRepository(releasesToInstall []ReleaseSpec, kubeContext, namespace, repo, helmTLSStore string, tls bool, packedValues, set []string, inject bool) {

Expand Down
58 changes: 58 additions & 0 deletions pkg/utils/helm3.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,64 @@ type releaseData struct {
time time.Time
}

// GetInstalledReleases gets the installed Helm releases in a given namespace
func GetInstalledReleases(kubeContext, namespace string, includeFailed bool) []ReleaseSpec {

tillerNamespace := "kube-system"
tillerResourceLabel := "OWNER=TILLER"
storage := getTillerStorage(kubeContext, tillerNamespace)

var releaseSpecs []ReleaseSpec
list, err := listReleases(kubeContext, namespace, storage, tillerNamespace, tillerResourceLabel)
if err != nil {
log.Fatal(err)
}

for _, releaseData := range list {

if releaseData.status != "DEPLOYED" {
continue
}

var releaseSpec ReleaseSpec
releaseSpec.ReleaseName = releaseData.name
releaseSpec.ChartName = releaseData.chart
releaseSpec.ChartVersion = releaseData.version

releaseSpecs = append(releaseSpecs, releaseSpec)
}

if !includeFailed {
return releaseSpecs
}

for _, releaseData := range list {
if releaseData.status != "FAILED" {
continue
}

exists := false
for _, rs := range releaseSpecs {
if releaseData.name == rs.ReleaseName {
exists = true
break
}
}
if exists {
continue
}

var releaseSpec ReleaseSpec
releaseSpec.ReleaseName = releaseData.name
releaseSpec.ChartName = releaseData.chart
releaseSpec.ChartVersion = releaseData.version

releaseSpecs = append(releaseSpecs, releaseSpec)
}

return releaseSpecs
}

func getTillerStorage(kubeContext, tillerNamespace string) string {
clientset := getClientSet(kubeContext)
coreV1 := clientset.CoreV1()
Expand Down

0 comments on commit f0ee8a0

Please sign in to comment.