diff --git a/_proto/hapi/release/status.proto b/_proto/hapi/release/status.proto index 999f7bea7..9fc8eb49a 100644 --- a/_proto/hapi/release/status.proto +++ b/_proto/hapi/release/status.proto @@ -38,4 +38,5 @@ message Status { Code code = 1; google.protobuf.Any details = 2; + string cluster_status = 3; } diff --git a/cmd/helm/status.go b/cmd/helm/status.go index 3b522644f..cf407bbb6 100644 --- a/cmd/helm/status.go +++ b/cmd/helm/status.go @@ -68,6 +68,7 @@ func (s *statusCmd) run() error { fmt.Fprintf(s.out, "Last Deployed: %s\n", timeconv.String(res.Info.LastDeployed)) fmt.Fprintf(s.out, "Status: %s\n", res.Info.Status.Code) + fmt.Fprintf(s.out, "Cluster Status:\n%s\n", res.Info.Status.ClusterStatus) if res.Info.Status.Details != nil { fmt.Fprintf(s.out, "Details: %s\n", res.Info.Status.Details) } diff --git a/cmd/tiller/environment/environment.go b/cmd/tiller/environment/environment.go index 2a9d85370..609a1d113 100644 --- a/cmd/tiller/environment/environment.go +++ b/cmd/tiller/environment/environment.go @@ -147,6 +147,14 @@ type KubeClient interface { // by "\n---\n"). Create(namespace string, reader io.Reader) error + // Get gets one or more resources. + // + // namespace must contain a valid existing namespace. + // + // reader must contain a YAML stream (one or more YAML documents separated + // by "\n---\n"). + Get(namespace string, reader io.Reader) (string, error) + // Delete destroys one or more resources. // // namespace must contain a valid existing namespace. diff --git a/cmd/tiller/release_server.go b/cmd/tiller/release_server.go index 061a76c4b..f924cecf7 100644 --- a/cmd/tiller/release_server.go +++ b/cmd/tiller/release_server.go @@ -159,6 +159,17 @@ func (s *releaseServer) GetReleaseStatus(c ctx.Context, req *services.GetRelease if rel.Info == nil { return nil, errors.New("release info is missing") } + + // Ok, we got the status of the release as we had jotted down, now we need to match the + // manifest we stashed away with reality from the cluster. + kubeCli := s.env.KubeClient + resp, err := kubeCli.Get(rel.Namespace, bytes.NewBufferString(rel.Manifest)) + if err != nil { + log.Printf("warning: COULDN'T FETCH %q failed: %s", rel.Name, err) + return nil, err + } + rel.Info.Status.ClusterStatus = resp + return &services.GetReleaseStatusResponse{Info: rel.Info}, nil } diff --git a/pkg/kube/client.go b/pkg/kube/client.go index da073d173..66acd3ce2 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -17,6 +17,7 @@ limitations under the License. package kube // import "k8s.io/helm/pkg/kube" import ( + "bytes" "fmt" "io" "log" @@ -50,7 +51,7 @@ func New(config clientcmd.ClientConfig) *Client { } } -// ResourceActorFunc performs an action on a signle resource. +// ResourceActorFunc performs an action on a single resource. type ResourceActorFunc func(*resource.Info) error // Create creates kubernetes resources from an io.reader @@ -63,6 +64,54 @@ func (c *Client) Create(namespace string, reader io.Reader) error { return perform(c, namespace, reader, createResource) } +// Get gets kubernetes resources as pretty printed string +// +// Namespace will set the namespace +func (c *Client) Get(namespace string, reader io.Reader) (string, error) { + // Since we don't know what order the objects come in, let's group them by the types, so + // that when we print them, they come looking good (headers apply to subgroups, etc.) + objs := make(map[string][]runtime.Object) + err := perform(c, namespace, reader, func(info *resource.Info) error { + log.Printf("Doing get for: '%s'", info.Name) + obj, err := resource.NewHelper(info.Client, info.Mapping).Get(info.Namespace, info.Name, info.Export) + if err != nil { + return err + } + // We need to fetch the + or, err := api.GetReference(obj) + if err != nil { + log.Printf("FAILED GetReference for: %#v\n%v", obj, err) + return err + } + + // Use APIVersion/Kind as grouping mechanism + objType := or.APIVersion + "/" + or.Kind + objs[objType] = append(objs[objType], obj) + return nil + }) + + // Ok, now we have all the objects grouped by types (say, by v1/Pod, v1/Service, etc.), so + // spin through them and print them. Printer is cool since it prints the header only when + // an object type changes, so we can just rely on that. Problem is it doesn't seem to keep + // track of tab widths + buf := new(bytes.Buffer) + p := kubectl.NewHumanReadablePrinter(false, false, false, false, false, false, []string{}) + for t, ot := range objs { + for _, o := range ot { + err = p.PrintObj(o, buf) + if err != nil { + log.Printf("failed to print object type '%s', object: '%s' :\n %v", t, o, err) + return "", err + } + } + _, err := buf.WriteString("\n") + if err != nil { + return "", err + } + } + return buf.String(), err +} + // Update reads in the current configuration and a modified configuration from io.reader // and creates resources that don't already exists, updates resources that have been modified // and deletes resources from the current configuration that are not present in the diff --git a/pkg/proto/hapi/release/status.pb.go b/pkg/proto/hapi/release/status.pb.go index 1c7f161ef..66a4345f5 100644 --- a/pkg/proto/hapi/release/status.pb.go +++ b/pkg/proto/hapi/release/status.pb.go @@ -51,8 +51,9 @@ func (Status_Code) EnumDescriptor() ([]byte, []int) { return fileDescriptor3, [] // Status defines the status of a release. type Status struct { - Code Status_Code `protobuf:"varint,1,opt,name=code,enum=hapi.release.Status_Code" json:"code,omitempty"` - Details *google_protobuf1.Any `protobuf:"bytes,2,opt,name=details" json:"details,omitempty"` + Code Status_Code `protobuf:"varint,1,opt,name=code,enum=hapi.release.Status_Code" json:"code,omitempty"` + Details *google_protobuf1.Any `protobuf:"bytes,2,opt,name=details" json:"details,omitempty"` + ClusterStatus string `protobuf:"bytes,3,opt,name=cluster_status,json=clusterStatus" json:"cluster_status,omitempty"` } func (m *Status) Reset() { *m = Status{} } @@ -73,20 +74,21 @@ func init() { } var fileDescriptor3 = []byte{ - // 226 bytes of a gzipped FileDescriptorProto + // 251 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x92, 0xcc, 0x48, 0x2c, 0xc8, 0xd4, 0x2f, 0x4a, 0xcd, 0x49, 0x4d, 0x2c, 0x4e, 0xd5, 0x2f, 0x2e, 0x49, 0x2c, 0x29, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x01, 0x49, 0xe9, 0x41, 0xa5, 0xa4, 0x24, 0xd3, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0xc1, 0x72, 0x49, 0xa5, 0x69, 0xfa, 0x89, 0x79, 0x95, 0x10, 0x85, - 0x4a, 0x9b, 0x19, 0xb9, 0xd8, 0x82, 0xc1, 0x3a, 0x85, 0x74, 0xb9, 0x58, 0x92, 0xf3, 0x53, 0x52, + 0x4a, 0xb7, 0x18, 0xb9, 0xd8, 0x82, 0xc1, 0x3a, 0x85, 0x74, 0xb9, 0x58, 0x92, 0xf3, 0x53, 0x52, 0x25, 0x18, 0x15, 0x18, 0x35, 0xf8, 0x8c, 0x24, 0xf5, 0x90, 0x8d, 0xd0, 0x83, 0xa8, 0xd1, 0x73, 0x06, 0x2a, 0x08, 0x02, 0x2b, 0x13, 0xd2, 0xe3, 0x62, 0x4f, 0x49, 0x2d, 0x49, 0xcc, 0xcc, 0x29, 0x96, 0x60, 0x02, 0xea, 0xe0, 0x36, 0x12, 0xd1, 0x83, 0x58, 0xa3, 0x07, 0xb3, 0x46, 0xcf, 0x31, - 0xaf, 0x32, 0x08, 0xa6, 0x48, 0xc9, 0x8b, 0x8b, 0x05, 0xa4, 0x5b, 0x88, 0x9b, 0x8b, 0x3d, 0xd4, - 0xcf, 0xdb, 0xcf, 0x3f, 0xdc, 0x4f, 0x80, 0x41, 0x88, 0x87, 0x8b, 0xc3, 0xc5, 0x35, 0xc0, 0xc7, - 0x3f, 0xd2, 0xd5, 0x45, 0x80, 0x11, 0x24, 0xe5, 0xe2, 0xea, 0xe3, 0x1a, 0x02, 0xe4, 0x30, 0x09, - 0xf1, 0x71, 0x71, 0x05, 0x87, 0x06, 0xb8, 0x06, 0x05, 0xbb, 0xba, 0x00, 0xf9, 0xcc, 0x42, 0x5c, - 0x5c, 0x6c, 0x6e, 0x8e, 0x9e, 0x3e, 0x40, 0x36, 0x8b, 0x13, 0x67, 0x14, 0x3b, 0xd4, 0x61, 0x49, - 0x6c, 0x60, 0xdb, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x8c, 0x99, 0x9a, 0x3b, 0x0d, 0x01, - 0x00, 0x00, + 0xaf, 0x32, 0x08, 0xa6, 0x48, 0x48, 0x95, 0x8b, 0x2f, 0x39, 0xa7, 0xb4, 0xb8, 0x24, 0xb5, 0x28, + 0x1e, 0xe2, 0x54, 0x09, 0x66, 0xa0, 0x36, 0xce, 0x20, 0x5e, 0xa8, 0x28, 0xc4, 0x06, 0x25, 0x2f, + 0x2e, 0x16, 0x90, 0x25, 0x42, 0xdc, 0x5c, 0xec, 0xa1, 0x7e, 0xde, 0x7e, 0xfe, 0xe1, 0x7e, 0x02, + 0x0c, 0x42, 0x3c, 0x5c, 0x1c, 0x2e, 0xae, 0x01, 0x3e, 0xfe, 0x91, 0xae, 0x2e, 0x02, 0x8c, 0x20, + 0x29, 0x17, 0x57, 0x1f, 0xd7, 0x10, 0x20, 0x87, 0x49, 0x88, 0x8f, 0x8b, 0x2b, 0x38, 0x34, 0xc0, + 0x35, 0x28, 0xd8, 0xd5, 0x05, 0xc8, 0x67, 0x16, 0xe2, 0xe2, 0x62, 0x73, 0x73, 0xf4, 0xf4, 0x01, + 0xb2, 0x59, 0x9c, 0x38, 0xa3, 0xd8, 0xa1, 0xee, 0x4f, 0x62, 0x03, 0x3b, 0xca, 0x18, 0x10, 0x00, + 0x00, 0xff, 0xff, 0xa0, 0xaf, 0xd3, 0x6a, 0x34, 0x01, 0x00, 0x00, }