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

Add a DashboardURL row to svcat describe instances #2262

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
})
}
}