Skip to content

Commit

Permalink
fix(service): Pick up new field Address instead of Domain when listin…
Browse files Browse the repository at this point in the history
…g service

Starting with 0.7.0 old fields are not populated anymore. Let's switch to the new fields then.

This fix should work with 0.6.0, too as the new fields already have been populated back then.

So we can unconditionally pick status.address.url which is accordance with
our policy to support the latest release and the release before.

Fixes knative#246.
  • Loading branch information
rhuss committed Jul 10, 2019
1 parent 3eb6e41 commit e2f2374
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/kn/commands/service/human_readable_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
// ServiceListHandlers adds print handlers for service list command
func ServiceListHandlers(h hprinters.PrintHandler) {
kServiceColumnDefinitions := []metav1beta1.TableColumnDefinition{
{Name: "Name", Type: "string", Description: "Name of the knative service."},
{Name: "Domain", Type: "string", Description: "Domain name of the knative service."},
{Name: "Name", Type: "string", Description: "Name of the Knative service."},
{Name: "Address", Type: "string", Description: "Address of the Knative service."},
//{Name: "LastCreatedRevision", Type: "string", Description: "Name of last revision created."},
//{Name: "LastReadyRevision", Type: "string", Description: "Name of last ready revision."},
{Name: "Generation", Type: "integer", Description: "Sequence number of 'Generation' of the service that was last processed by the controller."},
Expand Down Expand Up @@ -57,7 +57,7 @@ func printKServiceList(kServiceList *servingv1alpha1.ServiceList, options hprint
// printKService populates the knative service table rows
func printKService(kService *servingv1alpha1.Service, options hprinters.PrintOptions) ([]metav1beta1.TableRow, error) {
name := kService.Name
domain := kService.Status.RouteStatusFields.DeprecatedDomain
url := kService.Status.RouteStatusFields.Address.URL
//lastCreatedRevision := kService.Status.LatestCreatedRevisionName
//lastReadyRevision := kService.Status.LatestReadyRevisionName
generation := kService.Status.ObservedGeneration
Expand All @@ -71,7 +71,7 @@ func printKService(kService *servingv1alpha1.Service, options hprinters.PrintOpt
}
row.Cells = append(row.Cells,
name,
domain,
url,
//lastCreatedRevision,
//lastReadyRevision,
generation,
Expand Down
12 changes: 8 additions & 4 deletions pkg/kn/commands/service/service_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ import (
"strings"
"testing"

"github.com/knative/client/pkg/kn/commands"
"github.com/knative/client/pkg/util"
"github.com/knative/pkg/apis"
duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
duckv1beta1 "github.com/knative/pkg/apis/duck/v1beta1"
"github.com/knative/serving/pkg/apis/serving/v1alpha1"
"gotest.tools/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
client_testing "k8s.io/client-go/testing"

"github.com/knative/client/pkg/kn/commands"
"github.com/knative/client/pkg/util"
)

func fakeServiceList(args []string, response *v1alpha1.ServiceList) (action client_testing.Action, output []string, err error) {
Expand Down Expand Up @@ -86,7 +89,7 @@ func TestServiceListDefaultOutput(t *testing.T) {
} else if !action.Matches("list", "services") {
t.Errorf("Bad action %v", action)
}
assert.Check(t, util.ContainsAll(output[0], "NAME", "DOMAIN", "GENERATION", "AGE", "CONDITIONS", "READY", "REASON"))
assert.Check(t, util.ContainsAll(output[0], "NAME", "ADDRESS", "GENERATION", "AGE", "CONDITIONS", "READY", "REASON"))
assert.Check(t, util.ContainsAll(output[1], "foo", "foo.default.example.com", "1"))
assert.Check(t, util.ContainsAll(output[2], "bar", "bar.default.example.com", "2"))
}
Expand Down Expand Up @@ -115,6 +118,7 @@ func TestServiceGetWithTwoSrvName(t *testing.T) {
}

func createMockServiceWithParams(name, domain string, generation int64) *v1alpha1.Service {
url, _ := apis.ParseURL(domain)
service := &v1alpha1.Service{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
Expand All @@ -131,7 +135,7 @@ func createMockServiceWithParams(name, domain string, generation int64) *v1alpha
Status: duckv1beta1.Status{
ObservedGeneration: generation},
RouteStatusFields: v1alpha1.RouteStatusFields{
DeprecatedDomain: domain,
Address: &duckv1alpha1.Addressable{Addressable: duckv1beta1.Addressable{URL: url}},
},
},
}
Expand Down

0 comments on commit e2f2374

Please sign in to comment.