Skip to content

Commit

Permalink
[*/env] improve get releases performance
Browse files Browse the repository at this point in the history
  • Loading branch information
maorfr committed Dec 24, 2018
1 parent ca24763 commit aff2d86
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/utils/helm3.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ type GetInstalledReleasesOptions struct {
func GetInstalledReleases(o GetInstalledReleasesOptions) ([]ReleaseSpec, error) {

tillerNamespace := "kube-system"
tillerResourceLabel := "OWNER=TILLER"
labels := "OWNER=TILLER,STATUS in (DEPLOYED,FAILED)"
if !o.IncludeFailed {
labels = strings.Replace(labels, "FAILED", "", -1)
}
storage, err := getTillerStorage(o.KubeContext, tillerNamespace)
if err != nil {
return nil, err
}

var releaseSpecs []ReleaseSpec
list, err := listReleases(o.KubeContext, o.Namespace, storage, tillerNamespace, tillerResourceLabel)
list, err := listReleases(o.KubeContext, o.Namespace, storage, tillerNamespace, labels)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -127,7 +130,7 @@ type releaseData struct {
time time.Time
}

func listReleases(kubeContext, namespace, storage, tillerNamespace, label string) ([]releaseData, error) {
func listReleases(kubeContext, namespace, storage, tillerNamespace, labels string) ([]releaseData, error) {
clientset, err := getClientSet(kubeContext)
if err != nil {
return nil, err
Expand All @@ -137,7 +140,7 @@ func listReleases(kubeContext, namespace, storage, tillerNamespace, label string
switch storage {
case "secrets":
secrets, err := coreV1.Secrets(tillerNamespace).List(metav1.ListOptions{
LabelSelector: label,
LabelSelector: labels,
})
if err != nil {
return nil, err
Expand All @@ -151,7 +154,7 @@ func listReleases(kubeContext, namespace, storage, tillerNamespace, label string
}
case "cfgmaps":
configMaps, err := coreV1.ConfigMaps(tillerNamespace).List(metav1.ListOptions{
LabelSelector: label,
LabelSelector: labels,
})
if err != nil {
return nil, err
Expand All @@ -174,10 +177,10 @@ func listReleases(kubeContext, namespace, storage, tillerNamespace, label string

func getReleaseData(namespace, itemReleaseData string) *releaseData {
data, _ := decodeRelease(itemReleaseData)

if namespace != "" && data.Namespace != namespace {
return nil
}

deployTime := time.Unix(data.Info.LastDeployed.Seconds, 0)
chartMeta := data.GetChart().Metadata
releaseData := releaseData{
Expand Down

0 comments on commit aff2d86

Please sign in to comment.