Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Add a DashboardURL row to svcat describe instances (#2262)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertscherbarth authored and k8s-ci-robot committed Aug 8, 2018
1 parent 3984a95 commit 7a10340
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmd/svcat/output/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io"

"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1"
"github.com/olekukonko/tablewriter"
)

func getInstanceStatusCondition(status v1beta1.ServiceInstanceStatus) v1beta1.ServiceInstanceCondition {
Expand All @@ -40,6 +41,15 @@ func getInstanceStatusShort(status v1beta1.ServiceInstanceStatus) string {
return formatStatusShort(string(lastCond.Type), lastCond.Status, lastCond.Reason)
}

func appendInstanceDashboardURL(status v1beta1.ServiceInstanceStatus, table *tablewriter.Table) {
if status.DashboardURL != nil {
dashboardURL := *status.DashboardURL
table.AppendBulk([][]string{
{"DashboardURL:", dashboardURL},
})
}
}

func writeInstanceListTable(w io.Writer, instanceList *v1beta1.ServiceInstanceList) {
t := NewListTable(w)
t.SetHeader([]string{
Expand Down Expand Up @@ -133,6 +143,9 @@ func WriteInstanceDetails(w io.Writer, instance *v1beta1.ServiceInstance) {
{"Name:", instance.Name},
{"Namespace:", instance.Namespace},
{"Status:", getInstanceStatusFull(instance.Status)},
})
appendInstanceDashboardURL(instance.Status, t)
t.AppendBulk([][]string{
{"Class:", instance.Spec.GetSpecifiedClusterServiceClass()},
{"Plan:", instance.Spec.GetSpecifiedClusterServicePlan()},
})
Expand Down
55 changes: 55 additions & 0 deletions cmd/svcat/output/instance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package output

import (
"strings"
"testing"

"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1"
"github.com/olekukonko/tablewriter"
)

func Test_appendInstanceDashboardURL(t *testing.T) {
dashboardURL := "grafana.example.com"
table := &tablewriter.Table{}

tests := []struct {
name string
status v1beta1.ServiceInstanceStatus
table *tablewriter.Table
expectedString string
}{
{"dashboardURLOK", v1beta1.ServiceInstanceStatus{
DashboardURL: &dashboardURL,
}, table, "DashboardURL: grafana.example.com"},
{"dashboardURLEmpty", v1beta1.ServiceInstanceStatus{}, table, ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var stringBuilder strings.Builder
tt.table = NewDetailsTable(&stringBuilder)
appendInstanceDashboardURL(tt.status, tt.table)
tt.table.Render()
actualString := strings.Trim(stringBuilder.String(), " \n")

if actualString != tt.expectedString {
t.Fatalf("%v failed; expected %v; got %v", tt.name, tt.expectedString, actualString)
}
})
}
}

0 comments on commit 7a10340

Please sign in to comment.