github.com/aaronmell/helm@v3.0.0-beta.2+incompatible/cmd/helm/status.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 main
    18  
    19  import (
    20  	"io"
    21  
    22  	"github.com/pkg/errors"
    23  	"github.com/spf13/cobra"
    24  
    25  	"helm.sh/helm/cmd/helm/require"
    26  	"helm.sh/helm/pkg/action"
    27  )
    28  
    29  var statusHelp = `
    30  This command shows the status of a named release.
    31  The status consists of:
    32  - last deployment time
    33  - k8s namespace in which the release lives
    34  - state of the release (can be: unknown, deployed, deleted, superseded, failed or deleting)
    35  - list of resources that this release consists of, sorted by kind
    36  - details on last test suite run, if applicable
    37  - additional notes provided by the chart
    38  `
    39  
    40  func newStatusCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
    41  	client := action.NewStatus(cfg)
    42  
    43  	cmd := &cobra.Command{
    44  		Use:   "status RELEASE_NAME",
    45  		Short: "displays the status of the named release",
    46  		Long:  statusHelp,
    47  		Args:  require.ExactArgs(1),
    48  		RunE: func(cmd *cobra.Command, args []string) error {
    49  			rel, err := client.Run(args[0])
    50  			if err != nil {
    51  				return err
    52  			}
    53  
    54  			// strip chart metadata from the output
    55  			rel.Chart = nil
    56  
    57  			outfmt, err := action.ParseOutputFormat(client.OutputFormat)
    58  			// We treat an invalid format type as the default
    59  			if err != nil && err != action.ErrInvalidFormatType {
    60  				return err
    61  			}
    62  
    63  			switch outfmt {
    64  			case "":
    65  				action.PrintRelease(out, rel)
    66  				return nil
    67  			case action.JSON, action.YAML:
    68  				data, err := outfmt.Marshal(rel)
    69  				if err != nil {
    70  					return errors.Wrap(err, "failed to Marshal output")
    71  				}
    72  				out.Write(data)
    73  				return nil
    74  			default:
    75  				return errors.Errorf("unknown output format %q", outfmt)
    76  			}
    77  		},
    78  	}
    79  
    80  	f := cmd.PersistentFlags()
    81  	f.IntVar(&client.Version, "revision", 0, "if set, display the status of the named release with revision")
    82  	f.StringVarP(&client.OutputFormat, "output", "o", "", "output the status in the specified format (json or yaml)")
    83  
    84  	return cmd
    85  }