Skip to content

Commit

Permalink
chore(service): Rebased on master
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuss committed Jul 8, 2019
1 parent ac4b85a commit e67694b
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 109 deletions.
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ github.com/evanphx/json-patch v4.2.0+incompatible h1:fUDGZCv/7iAN7u0puUVhvKCcsR6
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680 h1:ZktWZesgun21uEDrwW7iEV1zPCGQldM2atlJZ3TdvVM=
Expand Down Expand Up @@ -186,6 +188,10 @@ github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a h1:TpvdAwDAt1K4ANV
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a h1:+J2gw7Bw77w/fbK7wnNJJDKmw1IbWft2Ul5BzrG1Qm8=
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a/go.mod h1:M1qoD/MqPgTZIk0EWKB38wE28ACRfVcn+cU08jyArI0=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
Expand Down Expand Up @@ -331,6 +337,8 @@ golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a h1:1n5lsVfiQW3yfsRGu98756EH1
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
27 changes: 14 additions & 13 deletions pkg/kn/commands/service/service_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (

"github.com/fatih/color"
"github.com/knative/client/pkg/printers"
"github.com/knative/client/pkg/serving"
serving_kn_v1alpha1 "github.com/knative/client/pkg/serving/v1alpha1"

"github.com/knative/pkg/apis"
"github.com/knative/pkg/apis/duck/v1beta1"
"github.com/knative/serving/pkg/apis/serving/v1alpha1"
Expand Down Expand Up @@ -95,7 +96,7 @@ func NewServiceDescribeCommand(p *commands.KnParams) *cobra.Command {
}
serviceName := args[0]

namespace, err := GetNamespace(cmd)
namespace, err := p.GetNamespace(cmd)
if err != nil {
return err
}
Expand All @@ -116,12 +117,12 @@ func NewServiceDescribeCommand(p *commands.KnParams) *cobra.Command {
// Set color option globally
color.NoColor = !useColor

service, err := client.Service(serviceName)
service, err := client.GetService(serviceName)
if err != nil {
return err
}
// Additional revision related information
revisionDescs, err := getRevisionDescriptions(sClient, service, printAll)
revisionDescs, err := getRevisionDescriptions(client, service, printAll)

hipsterMode, err := cmd.Flags().GetBool("hipster")
if err != nil {
Expand All @@ -136,7 +137,7 @@ func NewServiceDescribeCommand(p *commands.KnParams) *cobra.Command {
},
}
flags := command.Flags()
AddNamespaceFlags(flags, false)
commands.AddNamespaceFlags(flags, false)
flags.BoolP("all", "a", false, "don't truncate long information")
flags.BoolP("color", "c", false, "use colorful output")
flags.Bool("hipster", false, "🤓")
Expand Down Expand Up @@ -378,7 +379,7 @@ func age(t time.Time) string {

// Call the backend to query revisions for the given service and build up
// the view objects used for output
func getRevisionDescriptions(client *serving.NamespacedClient, service *v1alpha1.Service, all bool) ([]*revisionDesc, error) {
func getRevisionDescriptions(client serving_kn_v1alpha1.KnClient, service *v1alpha1.Service, all bool) ([]*revisionDesc, error) {
revisionDescs := make(map[string]*revisionDesc)

trafficTargets := service.Status.Traffic
Expand Down Expand Up @@ -415,14 +416,14 @@ func orderByConfigurationGeneration(descs map[string]*revisionDesc) []*revisionD
return descsList
}

func completeWithUntargetedRevisions(client *serving.NamespacedClient, service *v1alpha1.Service, descs map[string]*revisionDesc) error {
revisions, err := client.RevisionsForService(service)
func completeWithUntargetedRevisions(client serving_kn_v1alpha1.KnClient, service *v1alpha1.Service, descs map[string]*revisionDesc) error {
revisions, err := client.ListRevisions(serving_kn_v1alpha1.WithService(service.Name))
if err != nil {
return err
}
for _, revision := range revisions {
for _, revision := range revisions.Items {
if _, ok := descs[revision.Name]; !ok {
descs[revision.Name], err = newRevisionDesc(revision, nil)
descs[revision.Name], err = newRevisionDesc(&revision, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -498,20 +499,20 @@ func extractContainer(revision *v1alpha1.Revision) *v1.Container {
return revision.Spec.DeprecatedContainer
}

func extractRevisionFromTarget(client *serving.NamespacedClient, target v1alpha1.TrafficTarget) (*v1alpha1.Revision, error) {
func extractRevisionFromTarget(client serving_kn_v1alpha1.KnClient, target v1alpha1.TrafficTarget) (*v1alpha1.Revision, error) {
var revisionName = target.RevisionName
if revisionName == "" {
configurationName := target.ConfigurationName
if configurationName == "" {
return nil, fmt.Errorf("neither RevisionName nor ConfigurationName set")
}
configuration, err := client.Configuration(configurationName)
configuration, err := client.GetConfiguration(configurationName)
if err != nil {
return nil, err
}
revisionName = configuration.Status.LatestCreatedRevisionName
}
return client.Revision(revisionName)
return client.GetRevision(revisionName)
}

func extractURL(service *v1alpha1.Service) string {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
package commands
// Copyright © 2019 The Knative 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 service

import (
"fmt"
"io"
"strconv"
"strings"

"github.com/fatih/color"
"github.com/knative/client/pkg/printers"
"github.com/knative/serving/pkg/apis/serving/v1alpha1"
"io"
v1 "k8s.io/api/core/v1"
"strconv"
"strings"
)

var emojiMap = map[string]string{
Expand Down
15 changes: 2 additions & 13 deletions pkg/kn/commands/service/service_describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,20 @@
package service

import (
"bytes"
"regexp"
"strings"
"encoding/json"
"testing"

duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
"github.com/knative/client/pkg/kn/commands"
"github.com/knative/serving/pkg/apis/serving/v1alpha1"
serving "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1"
"github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake"
"k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
clienttesting "k8s.io/client-go/testing"

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

func fakeServiceDescribe(args []string, response *v1alpha1.Service) (action clienttesting.Action, output string, err error) {
buf := new(bytes.Buffer)
fakeServing := &fake.FakeServingV1alpha1{Fake: &clienttesting.Fake{}}
cmd := NewKnCommand(KnParams{
Output: buf,
ServingFactory: func() (serving.ServingV1alpha1Interface, error) { return fakeServing, nil },
})
func fakeServiceDescribe(args []string, response *v1alpha1.Service) (action client_testing.Action, output string, err error) {
knParams := &commands.KnParams{}
cmd, fakeServing, buf := commands.CreateTestKnCommand(NewServiceCommand(knParams), knParams)
fakeServing.AddReactor("*", "*",
Expand Down
16 changes: 15 additions & 1 deletion pkg/printers/prefixwriter.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright © 2019 The Knative 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 printers

import (
Expand Down Expand Up @@ -57,7 +71,7 @@ func (pw *prefixWriter) Write(level int, format string, a ...interface{}) {

func (pw *prefixWriter) WriteCols(level int, cols ...string) {
ss := make([]string, len(cols))
for i, _ := range cols {
for i := range cols {
ss[i] = "%s"
}
format := strings.Join(ss, "\t")
Expand Down
78 changes: 0 additions & 78 deletions pkg/serving/client.go

This file was deleted.

16 changes: 16 additions & 0 deletions pkg/serving/v1alpha1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ type KnClient interface {
// Wait for a service to become ready, but not longer than provided timeout
WaitForService(name string, timeout time.Duration) error

// Get a configuration by name
GetConfiguration(name string) (*v1alpha1.Configuration, error)

// Get a revision by name
GetRevision(name string) (*v1alpha1.Revision, error)

Expand Down Expand Up @@ -192,6 +195,19 @@ func (cl *knClient) WaitForService(name string, timeout time.Duration) error {
return waitForReady.Wait(name, timeout)
}

// Get the configuration for a service
func (cl *knClient) GetConfiguration(name string) (*v1alpha1.Configuration, error) {
configuration, err := cl.client.Configurations(cl.namespace).Get(name, v1.GetOptions{})
if err != nil {
return nil, err
}
err = updateServingGvk(configuration)
if err != nil {
return nil, err
}
return configuration, nil
}

// Get a revision by name
func (cl *knClient) GetRevision(name string) (*v1alpha1.Revision, error) {
revision, err := cl.client.Revisions(cl.namespace).Get(name, v1.GetOptions{})
Expand Down

0 comments on commit e67694b

Please sign in to comment.