Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #214 from ibuildthecloud/master
Browse files Browse the repository at this point in the history
Fix drone build
  • Loading branch information
ibuildthecloud authored May 20, 2019
2 parents e8a4cf0 + d1eb5dc commit 2cc7681
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 49 deletions.
1 change: 0 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ steps:
event:
- tag

steps:
- name: manifest-cert-checker
image: plugins/manifest:1.0.2
settings:
Expand Down
58 changes: 56 additions & 2 deletions cli/cmd/ps/ps_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"github.com/rancher/rio/cli/pkg/tables"
"github.com/rancher/rio/cli/pkg/types"
riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
"github.com/rancher/rio/pkg/services"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

type ServiceData struct {
Expand All @@ -16,10 +19,61 @@ type ServiceData struct {
}

func (p *Ps) apps(ctx *clicontext.CLIContext) error {
objs, err := ctx.List(types.AppType)
var appDataList []runtime.Object
appDatas := map[string]tables.AppData{}

appObjs, err := ctx.List(types.AppType)
if err != nil {
return err
}

for _, v := range appObjs {
app := v.(*riov1.App)
appDatas[app.Namespace+"/"+app.Name] = tables.AppData{
App: app,
Revisions: map[string]*riov1.Service{},
}
}

svcObjs, err := ctx.List(types.ServiceType)
if err != nil {
return err
}

for _, v := range svcObjs {
svc := v.(*riov1.Service)
appName, version := services.AppAndVersion(svc)
key := svc.Namespace + "/" + appName
app, ok := appDatas[key]
if !ok {
app = tables.AppData{
App: riov1.NewApp(svc.Namespace, appName, riov1.App{
ObjectMeta: v1.ObjectMeta{
CreationTimestamp: svc.CreationTimestamp,
},
Spec: riov1.AppSpec{
Revisions: []riov1.Revision{
{
Scale: svc.Spec.Scale,
Version: version,
},
},
},
}),
Revisions: map[string]*riov1.Service{},
}
appDatas[key] = app
}
app.Revisions[version] = svc
}

for _, v := range appDatas {
copy := v
copy.Namespace = v.App.Namespace
copy.Name = v.App.Name
appDataList = append(appDataList, &copy)
}

writer := tables.NewApp(ctx)
return writer.Write(objs)
return writer.Write(appDataList)
}
34 changes: 17 additions & 17 deletions cli/cmd/tui/refreshers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package tui
import (
"bytes"
"os"
"os/exec"
"strings"

"github.com/docker/docker/pkg/reexec"
"github.com/pkg/errors"
)

Expand All @@ -19,9 +19,9 @@ var (
if showSystem {
args = append([]string{"--system"}, args...)
}
cmd := exec.Command("rio", args...)
cmd := reexec.Command(append([]string{"rio"}, args...)...)
errBuffer := &strings.Builder{}
cmd.Env = append(os.Environ(), "TUI_HACK=true")
cmd.Env = append(os.Environ(), "FORMAT=raw")
cmd.Stdout = b
cmd.Stderr = errBuffer
if err := cmd.Run(); err != nil {
Expand All @@ -35,9 +35,9 @@ var (
if showSystem {
args = append([]string{"--system"}, args...)
}
cmd := exec.Command("rio", args...)
cmd := reexec.Command(append([]string{"rio"}, args...)...)
errBuffer := &strings.Builder{}
cmd.Env = append(os.Environ(), "TUI_HACK=true")
cmd.Env = append(os.Environ(), "FORMAT=raw")
cmd.Stdout = b
cmd.Stderr = errBuffer
if err := cmd.Run(); err != nil {
Expand All @@ -51,9 +51,9 @@ var (
if showSystem {
args = append([]string{"--system"}, args...)
}
cmd := exec.Command("rio", args...)
cmd := reexec.Command(append([]string{"rio"}, args...)...)
errBuffer := &strings.Builder{}
cmd.Env = append(os.Environ(), "TUI_HACK=true")
cmd.Env = append(os.Environ(), "FORMAT=raw")
cmd.Stdout = b
cmd.Stderr = errBuffer
if err := cmd.Run(); err != nil {
Expand All @@ -67,9 +67,9 @@ var (
if showSystem {
args = append([]string{"--system"}, args...)
}
cmd := exec.Command("rio", args...)
cmd := reexec.Command(append([]string{"rio"}, args...)...)
errBuffer := &strings.Builder{}
cmd.Env = append(os.Environ(), "TUI_HACK=true")
cmd.Env = append(os.Environ(), "FORMAT=raw")
cmd.Stdout = b
cmd.Stderr = errBuffer
if err := cmd.Run(); err != nil {
Expand All @@ -83,9 +83,9 @@ var (
if showSystem {
args = append([]string{"--system"}, args...)
}
cmd := exec.Command("rio", args...)
cmd := reexec.Command(append([]string{"rio"}, args...)...)
errBuffer := &strings.Builder{}
cmd.Env = append(os.Environ(), "TUI_HACK=true")
cmd.Env = append(os.Environ(), "FORMAT=raw")
cmd.Stdout = b
cmd.Stderr = errBuffer
if err := cmd.Run(); err != nil {
Expand All @@ -102,9 +102,9 @@ var (
if showSystem {
args = append([]string{"--system"}, args...)
}
cmd := exec.Command("rio", args...)
cmd := reexec.Command(append([]string{"rio"}, args...)...)
errBuffer := &strings.Builder{}
cmd.Env = append(os.Environ(), "TUI_HACK=true")
cmd.Env = append(os.Environ(), "FORMAT=raw")
cmd.Stdout = b
cmd.Stderr = errBuffer
if err := cmd.Run(); err != nil {
Expand All @@ -121,9 +121,9 @@ var (
if showSystem {
args = append([]string{"--system"}, args...)
}
cmd := exec.Command("rio", args...)
cmd := reexec.Command(append([]string{"rio"}, args...)...)
errBuffer := &strings.Builder{}
cmd.Env = append(os.Environ(), "TUI_HACK=true")
cmd.Env = append(os.Environ(), "FORMAT=raw")
cmd.Stdout = b
cmd.Stderr = errBuffer
if err := cmd.Run(); err != nil {
Expand All @@ -134,9 +134,9 @@ var (

BuildRefresher = func(b *bytes.Buffer) error {
args := []string{"build"}
cmd := exec.Command("rio", args...)
cmd := reexec.Command(append([]string{"rio"}, args...)...)
errBuffer := &strings.Builder{}
cmd.Env = append(os.Environ(), "TUI_HACK=true")
cmd.Env = append(os.Environ(), "FORMAT=raw")
cmd.Stdout = b
cmd.Stderr = errBuffer
if err := cmd.Run(); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions cli/pkg/table/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ var stackLsFlags = []cli.Flag{
Usage: "Only display IDs",
},
cli.StringFlag{
Name: "format",
Usage: "'json' or 'yaml' or Custom format: '{{.ID}} {{.Stack.ServiceName}}'",
Name: "format",
EnvVar: "FORMAT",
Usage: "'json' or 'yaml' or Custom format: '{{.ID}} {{.Stack.ServiceName}}'",
},
}

Expand Down
8 changes: 4 additions & 4 deletions cli/pkg/table/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"os"
"strings"
"text/tabwriter"
"text/template"
Expand All @@ -16,9 +15,9 @@ import (

"github.com/Masterminds/sprig"
"github.com/davecgh/go-spew/spew"
units "github.com/docker/go-units"
"github.com/docker/go-units"
"github.com/rancher/mapper/convert"
yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -85,7 +84,7 @@ func NewWriter(values [][]string, config WriterConfig) Writer {
funcMap: funcMap,
}

if os.Getenv("TUI_HACK") == "true" {
if config.Format() == "raw" {
t.Writer = config.Writer()
} else {
t.Writer = tabwriter.NewWriter(config.Writer(), 10, 1, 3, ' ', 0)
Expand All @@ -108,6 +107,7 @@ func NewWriter(values [][]string, config WriterConfig) Writer {
} else if customFormat == "yaml" {
t.HeaderFormat = ""
t.ValueFormat = "yaml"
} else if customFormat == "raw" {
} else if customFormat != "" {
t.ValueFormat = customFormat + "\n"
t.HeaderFormat = ""
Expand Down
75 changes: 70 additions & 5 deletions cli/pkg/tables/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,51 @@ import (
"sort"
"strings"

"k8s.io/apimachinery/pkg/runtime"

"github.com/rancher/rio/cli/pkg/table"
riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type AppData struct {
metav1.TypeMeta
metav1.ObjectMeta

App *riov1.App
Revisions map[string]*riov1.Service
}

func (a *AppData) DeepCopyObject() runtime.Object {
ad := &AppData{
TypeMeta: a.TypeMeta,
ObjectMeta: *a.ObjectMeta.DeepCopy(),
App: a.App.DeepCopy(),
Revisions: map[string]*riov1.Service{},
}

for k, v := range a.Revisions {
ad.Revisions[k] = v.DeepCopy()
}

return ad
}

func NewApp(cfg Config) TableWriter {
writer := table.NewWriter([][]string{
{"NAME", "{{stackScopedName .Obj.Namespace .Obj.Name ``}}"},
{"ENDPOINT", "{{.Obj.Status.Endpoints | array}}"},
{"REVISIONS", "{{revisions .Obj.Spec.Revisions}}"},
{"SCALE", "{{appScale .Obj.Spec.Revisions}}"},
{"WEIGHT", "{{weightVersioned .Obj}}"},
{"NAME", "{{stackScopedName .Obj.App.Namespace .Obj.App.Name ``}}"},
{"CREATED", "{{.Obj.App.CreationTimestamp | ago}}"},
{"ENDPOINT", "{{.Obj.App.Status.Endpoints | array}}"},
{"REVISIONS", "{{revisions .Obj.App.Spec.Revisions}}"},
{"SCALE", "{{appScale .Obj.App.Spec.Revisions}}"},
{"WEIGHT", "{{weightVersioned .Obj.App}}"},
{"DETAIL", "{{detail .Obj}}"},
}, cfg)

writer.AddFormatFunc("revisions", formatRevisions)
writer.AddFormatFunc("appScale", formatAppScale)
writer.AddFormatFunc("weightVersioned", formatWeightGraph)
writer.AddFormatFunc("detail", formatAppDetail)
writer.AddFormatFunc("stackScopedName", table.FormatStackScopedName(cfg.GetSetNamespace()))

return &tableWriter{
Expand Down Expand Up @@ -82,3 +111,39 @@ func formatWeightGraph(obj interface{}) (string, error) {
}
return strings.Join(result, ","), nil
}

func formatAppDetail(obj interface{}) (string, error) {
appData := obj.(*AppData)
buffer := strings.Builder{}

versions := revisionsByVersion(appData.App.Spec.Revisions)
for _, name := range revisions(appData.App.Spec.Revisions) {
rev := versions[name]
if !rev.DeploymentReady {
if buffer.Len() > 0 {
buffer.WriteString("; ")
}
buffer.WriteString(name)
buffer.WriteString(" NotReady")
}

svc, ok := appData.Revisions[name]
if ok && svc.Spec.Image == "" {
if riov1.ServiceConditionImageReady.IsFalse(svc) {
if buffer.Len() > 0 {
buffer.WriteString("; ")
}
buffer.WriteString(name)
buffer.WriteString(" build failed: ")
buffer.WriteString(riov1.ServiceConditionImageReady.GetMessage(svc))
} else if !riov1.ServiceConditionImageReady.IsTrue(svc) {
if buffer.Len() > 0 {
buffer.WriteString("; ")
}
buffer.WriteString(name)
buffer.WriteString(" waiting on build")
}
}
}
return buffer.String(), nil
}
6 changes: 5 additions & 1 deletion cli/pkg/tables/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ func FormatScale(data, data2, data3 interface{}) (string, error) {
scaleStr := strconv.Itoa(scale)

scaleStatus, ok := data2.(*v1.ScaleStatus)
if !ok || scaleStatus == nil {
if !ok {
return scaleStr, nil
}

if scaleStatus == nil {
scaleStatus = &v1.ScaleStatus{}
}

if scaleStatus.Available == 0 && scaleStatus.Unavailable == 0 && scaleStatus.Ready == scale {
return scaleStr, nil
}
Expand Down
Loading

0 comments on commit 2cc7681

Please sign in to comment.