github.com/sri09kanth/helm@v3.0.0-beta.3+incompatible/pkg/action/printer.go (about)

     1  /*
     2  Copyright The Helm Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package action
    18  
    19  import (
    20  	"fmt"
    21  	"io"
    22  	"strings"
    23  
    24  	"helm.sh/helm/pkg/release"
    25  )
    26  
    27  // PrintRelease prints info about a release
    28  func PrintRelease(out io.Writer, rel *release.Release) {
    29  	if rel == nil {
    30  		return
    31  	}
    32  	fmt.Fprintf(out, "NAME: %s\n", rel.Name)
    33  	if !rel.Info.LastDeployed.IsZero() {
    34  		fmt.Fprintf(out, "LAST DEPLOYED: %s\n", rel.Info.LastDeployed)
    35  	}
    36  	fmt.Fprintf(out, "NAMESPACE: %s\n", rel.Namespace)
    37  	fmt.Fprintf(out, "STATUS: %s\n", rel.Info.Status.String())
    38  
    39  	executions := executionsByHookEvent(rel)
    40  	if tests, ok := executions[release.HookTest]; ok {
    41  		for _, h := range tests {
    42  			// Don't print anything if hook has not been initiated
    43  			if h.LastRun.StartedAt.IsZero() {
    44  				continue
    45  			}
    46  			fmt.Fprintf(out, "TEST SUITE:     %s\n%s\n%s\n%s\n\n",
    47  				h.Name,
    48  				fmt.Sprintf("Last Started:   %s", h.LastRun.StartedAt),
    49  				fmt.Sprintf("Last Completed: %s", h.LastRun.CompletedAt),
    50  				fmt.Sprintf("Phase:          %s", h.LastRun.Phase),
    51  			)
    52  		}
    53  	}
    54  
    55  	if strings.EqualFold(rel.Info.Description, "Dry run complete") {
    56  		fmt.Fprintf(out, "MANIFEST:\n%s\n", rel.Manifest)
    57  	}
    58  
    59  	if len(rel.Info.Notes) > 0 {
    60  		fmt.Fprintf(out, "NOTES:\n%s\n", strings.TrimSpace(rel.Info.Notes))
    61  	}
    62  }
    63  
    64  func executionsByHookEvent(rel *release.Release) map[release.HookEvent][]*release.Hook {
    65  	result := make(map[release.HookEvent][]*release.Hook)
    66  	for _, h := range rel.Hooks {
    67  		for _, e := range h.Events {
    68  			executions, ok := result[e]
    69  			if !ok {
    70  				executions = []*release.Hook{}
    71  			}
    72  			result[e] = append(executions, h)
    73  		}
    74  	}
    75  	return result
    76  }