github.com/danielqsj/helm@v2.0.0-alpha.4.0.20160908204436-976e0ba5199b+incompatible/cmd/helm/status.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 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 "fmt" 21 "io" 22 23 "github.com/spf13/cobra" 24 25 "k8s.io/helm/pkg/helm" 26 "k8s.io/helm/pkg/proto/hapi/services" 27 "k8s.io/helm/pkg/timeconv" 28 ) 29 30 var statusHelp = ` 31 This command shows the status of a named release. 32 ` 33 34 type statusCmd struct { 35 release string 36 out io.Writer 37 client helm.Interface 38 } 39 40 func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command { 41 status := &statusCmd{ 42 out: out, 43 client: client, 44 } 45 cmd := &cobra.Command{ 46 Use: "status [flags] RELEASE_NAME", 47 Short: "displays the status of the named release", 48 Long: statusHelp, 49 PersistentPreRunE: setupConnection, 50 RunE: func(cmd *cobra.Command, args []string) error { 51 if len(args) == 0 { 52 return errReleaseRequired 53 } 54 status.release = args[0] 55 if status.client == nil { 56 status.client = helm.NewClient(helm.Host(tillerHost)) 57 } 58 return status.run() 59 }, 60 } 61 return cmd 62 } 63 64 func (s *statusCmd) run() error { 65 res, err := s.client.ReleaseStatus(s.release) 66 if err != nil { 67 return prettyError(err) 68 } 69 70 PrintStatus(s.out, res) 71 return nil 72 } 73 74 // PrintStatus prints out the status of a release. Shared because also used by 75 // install / upgrade 76 func PrintStatus(out io.Writer, res *services.GetReleaseStatusResponse) { 77 if res.Info.LastDeployed != nil { 78 fmt.Fprintf(out, "Last Deployed: %s\n", timeconv.String(res.Info.LastDeployed)) 79 } 80 fmt.Fprintf(out, "Namespace: %s\n", res.Namespace) 81 fmt.Fprintf(out, "Status: %s\n", res.Info.Status.Code) 82 if res.Info.Status.Details != nil { 83 fmt.Fprintf(out, "Details: %s\n", res.Info.Status.Details) 84 } 85 fmt.Fprintf(out, "\n") 86 if len(res.Info.Status.Resources) > 0 { 87 fmt.Fprintf(out, "Resources:\n%s\n", res.Info.Status.Resources) 88 } 89 if len(res.Info.Status.Notes) > 0 { 90 fmt.Fprintf(out, "Notes:\n%s\n", res.Info.Status.Notes) 91 } 92 }