Skip to content

Commit

Permalink
Merge branch 'master' into issue763_e2e_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilien authored Mar 27, 2020
2 parents df3334c + 521a0b4 commit 322850c
Show file tree
Hide file tree
Showing 60 changed files with 1,904 additions and 393 deletions.
26 changes: 25 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,40 @@
| https://github.com/knative/client/pull/[#]
////

## v0.14.0 (2020-XX-XX)
## v0.14.0 (unreleased)

[cols="1,10,3", options="header", width="100%"]
|===
| | Description | PR
|===

| 🐣
| Refactor `e2e` common code into `lib\test\integration`
| https://github.com/knative/client/pull/764[#764]

## v0.13.1 (2020-03-25)

[cols="1,10,3", options="header", width="100%"]
|===
| | Description | PR

| 🐛
| Fix filter delete for trigger update command
| https://github.com/knative/client/pull/746[#746]

| 🐛
| Fix trigger create --filter flag to be optional
| https://github.com/knative/client/pull/745[#745]

| 🐛
| Fix plugin execution for Windows.
| https://github.com/knative/client/pull/738[#738]

| 🐛
| Fix default config path on Windows
| https://github.com/knative/client/pull/751[#751]
|===

## v0.13.0 (2020-03-11)

[cols="1,10,3", options="header", width="100%"]
Expand Down
2 changes: 1 addition & 1 deletion docs/cmd/kn_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ kn service [flags]
* [kn service create](kn_service_create.md) - Create a service.
* [kn service delete](kn_service_delete.md) - Delete a service.
* [kn service describe](kn_service_describe.md) - Show details of a service
* [kn service export](kn_service_export.md) - export a service
* [kn service export](kn_service_export.md) - Export a service.
* [kn service list](kn_service_list.md) - List available services.
* [kn service update](kn_service_update.md) - Update a service.

4 changes: 2 additions & 2 deletions docs/cmd/kn_service_export.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## kn service export

export a service
Export a service.

### Synopsis

export a service
Export a service.

```
kn service export NAME [flags]
Expand Down
7 changes: 5 additions & 2 deletions docs/cmd/kn_trigger_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ Create a trigger
Create a trigger

```
kn trigger create NAME --broker BROKER --filter KEY=VALUE --sink SINK [flags]
kn trigger create NAME --broker BROKER --sink SINK [flags]
```

### Examples

```
# Create a trigger 'mytrigger' to declare a subscription to events with attribute 'type=dev.knative.foo' from default broker. The subscriber is service 'mysvc'
# Create a trigger 'mytrigger' to declare a subscription to events from default broker. The subscriber is service 'mysvc'
kn trigger create mytrigger --broker default --sink svc:mysvc
# Create a trigger to filter events with attribute 'type=dev.knative.foo'
kn trigger create mytrigger --broker default --filter type=dev.knative.foo --sink svc:mysvc
```

Expand Down
2 changes: 1 addition & 1 deletion docs/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Plugins follow a similar architecture to
with some small differences. One key difference is that `kn` plugins can either
live in your `PATH` or in a chosen and specified directory.
[Kn plugins](https://github.com/knative/client/tree/master/docs/cmd/kn_plugin.md)
shows how to install and create new plugins as well as gives some examples and
show how to install and create new plugins as well as gives some examples and
best practices.

To see what plugins are installed on your machine, you can use the
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ require (
k8s.io/apimachinery v0.17.0
k8s.io/cli-runtime v0.17.0
k8s.io/client-go v0.17.0
knative.dev/eventing v0.13.1
knative.dev/pkg v0.0.0-20200304185554-312b1be35ceb
knative.dev/serving v0.13.0
knative.dev/test-infra v0.0.0-20200229011351-4dac123b9a3d
knative.dev/eventing v0.13.4
knative.dev/pkg v0.0.0-20200323231609-0840da9555a3
knative.dev/serving v0.13.1-0.20200324164309-ce10070bb7ef
knative.dev/test-infra v0.0.0-20200324183109-d81c66eea4e6
sigs.k8s.io/yaml v1.1.0
)

Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -592,14 +592,14 @@ k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKf
k8s.io/legacy-cloud-providers v0.17.0/go.mod h1:DdzaepJ3RtRy+e5YhNtrCYwlgyK87j/5+Yfp0L9Syp8=
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f h1:GiPwtSzdP43eI1hpPCbROQCCIgCuiMMNF8YUVLF3vJo=
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
knative.dev/eventing v0.13.1 h1:2jnxea7XtqFX8dMFu9cZ7ocMuQV5ZnXX+6tLF6AbYGo=
knative.dev/eventing v0.13.1/go.mod h1:UxweNv8yXhsdHJitcb9R6rmfNaUD2DFi9GWwNRyIs58=
knative.dev/pkg v0.0.0-20200304185554-312b1be35ceb h1:cgpFaVF0jb7z+zJGzq30HMfxMmWwX5WEnkMZ9EHli7I=
knative.dev/pkg v0.0.0-20200304185554-312b1be35ceb/go.mod h1:pgODObA1dTyhNoFxPZTTjNWfx6F0aKsKzn+vaT9XO/Q=
knative.dev/serving v0.13.0 h1:HkkTVBi6EWoFJcgjXgAVUFdKdxZRulb38dnfnkBYCrQ=
knative.dev/serving v0.13.0/go.mod h1:x2n255JS2XBI39tmjZ8CwTxIf9EKNMCrkVuiOttLRm0=
knative.dev/test-infra v0.0.0-20200229011351-4dac123b9a3d h1:YlscBzPOL3Rfyl8844/wHhJNL5uiHDdyaRn6IEVvv64=
knative.dev/test-infra v0.0.0-20200229011351-4dac123b9a3d/go.mod h1:xcdUkMJrLlBswIZqL5zCuBFOC22WIPMQoVX1L35i0vQ=
knative.dev/eventing v0.13.4 h1:UqTsfNza4BX5W0+KDoCjPOa+mkU4idE+HolqG7SdN0w=
knative.dev/eventing v0.13.4/go.mod h1:UxweNv8yXhsdHJitcb9R6rmfNaUD2DFi9GWwNRyIs58=
knative.dev/pkg v0.0.0-20200323231609-0840da9555a3 h1:lox+XrjDaw+aJxl5LZ7e+NO9Hj1OWm/ZWyyu8a2rKVI=
knative.dev/pkg v0.0.0-20200323231609-0840da9555a3/go.mod h1:pgODObA1dTyhNoFxPZTTjNWfx6F0aKsKzn+vaT9XO/Q=
knative.dev/serving v0.13.1-0.20200324164309-ce10070bb7ef h1:4CWRxXBbhEFS8kw26awitohUBZ5ao4iNWqMUdu/uf98=
knative.dev/serving v0.13.1-0.20200324164309-ce10070bb7ef/go.mod h1:x2n255JS2XBI39tmjZ8CwTxIf9EKNMCrkVuiOttLRm0=
knative.dev/test-infra v0.0.0-20200324183109-d81c66eea4e6 h1:cttACHBnpN7b509UJnQV1tCD/ssIIGJhHSdHzpPeMzE=
knative.dev/test-infra v0.0.0-20200324183109-d81c66eea4e6/go.mod h1:xcdUkMJrLlBswIZqL5zCuBFOC22WIPMQoVX1L35i0vQ=
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
Expand Down
12 changes: 6 additions & 6 deletions pkg/eventing/v1alpha1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,18 @@ func (b *TriggerBuilder) InjectBroker(inject bool) *TriggerBuilder {
}

func (b *TriggerBuilder) Filters(filters map[string]string) *TriggerBuilder {
if len(filters) == 0 {
b.trigger.Spec.Filter = &v1alpha1.TriggerFilter{}
return b
}
filter := b.trigger.Spec.Filter
if filter == nil {
filter = &v1alpha1.TriggerFilter{}
b.trigger.Spec.Filter = filter
}
attributes := filter.Attributes
if attributes == nil {
attributes = &v1alpha1.TriggerFilterAttributes{}
filter.Attributes = attributes
}
filter.Attributes = &v1alpha1.TriggerFilterAttributes{}
for k, v := range filters {
(*attributes)[k] = v
(*filter.Attributes)[k] = v
}
return b
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/eventing/v1alpha1/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ func TestTriggerBuilder(t *testing.T) {
assert.DeepEqual(t, expected, b.Build().Spec.Filter)
})

t.Run("update filters to remove filters", func(t *testing.T) {
b := NewTriggerBuilderFromExisting(a.Build())
assert.DeepEqual(t, b.Build(), a.Build())
b.Filters(nil)
expected := &v1alpha1.TriggerFilter{}
assert.DeepEqual(t, expected, b.Build().Spec.Filter)

b.Filters((make(map[string]string)))
assert.DeepEqual(t, expected, b.Build().Spec.Filter)
})

t.Run("add and remove inject annotation", func(t *testing.T) {
b := NewTriggerBuilder("broker-trigger")
b.InjectBroker(true)
Expand Down
13 changes: 13 additions & 0 deletions pkg/kn/commands/plugin/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"syscall"

Expand Down Expand Up @@ -93,6 +94,18 @@ func (h *DefaultPluginHandler) Lookup(name string) (string, bool) {

// Execute implements PluginHandler
func (h *DefaultPluginHandler) Execute(executablePath string, cmdArgs, environment []string) error {
if runtime.GOOS == "windows" {
cmd := exec.Command(executablePath, cmdArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
cmd.Env = environment
err := cmd.Run()
if err == nil {
os.Exit(0)
}
return err
}
return syscall.Exec(executablePath, cmdArgs, environment)
}

Expand Down
12 changes: 12 additions & 0 deletions pkg/kn/commands/plugin/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"

"gotest.tools/assert"
Expand All @@ -45,6 +46,9 @@ func TestPluginHandler(t *testing.T) {

beforeEach := func(t *testing.T) {
pluginName = "fake"
if runtime.GOOS == "windows" {
pluginName += ".bat"
}
pluginPath = CreateTestPluginInPath(t, "kn-"+pluginName, KnTestPluginScript, FileModeExecutable, tmpPathDir)
assert.Assert(t, pluginPath != "")

Expand Down Expand Up @@ -134,6 +138,14 @@ func TestPluginHandler(t *testing.T) {
err = pluginHandler.Execute(bogusPath, []string{bogusPath}, os.Environ())
assert.Assert(t, err != nil, fmt.Sprintf("bogus plugin in path %s unexpectedly executed OK", bogusPath))
})
t.Run("executing fake plugin successfully", func(t *testing.T) {
setup(t)
defer cleanup(t)
beforeEach(t)

err = pluginHandler.Execute(pluginPath, []string{}, os.Environ())
assert.Assert(t, err == nil, fmt.Sprintf("fail to execute fake plugin in path %s ", pluginPath))
})
})

t.Run("HandlePluginCommand", func(t *testing.T) {
Expand Down
7 changes: 1 addition & 6 deletions pkg/kn/commands/plugin/plugin_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -58,13 +57,9 @@ func CreateTestPlugin(t *testing.T, name, script string, fileMode os.FileMode) s
// CreateTestPluginInPath with name, path, script, and fileMode and return the tmp random path
func CreateTestPluginInPath(t *testing.T, name, script string, fileMode os.FileMode, path string) string {
fullPath := filepath.Join(path, name)
if runtime.GOOS == "windows" {
fullPath += ".bat"
}
err := ioutil.WriteFile(fullPath, []byte(script), fileMode)
assert.NilError(t, err)

return filepath.Join(path, name)
return fullPath
}

// DeleteTestPlugin with path
Expand Down
16 changes: 8 additions & 8 deletions pkg/kn/commands/revision/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

"knative.dev/client/pkg/kn/commands"
"knative.dev/client/pkg/kn/commands/flags"
clientservingv1alpha "knative.dev/client/pkg/serving/v1"
clientservingv1 "knative.dev/client/pkg/serving/v1"
)

// Service name filter, used with "-s"
Expand Down Expand Up @@ -64,7 +64,7 @@ func NewRevisionListCommand(p *commands.KnParams) *cobra.Command {
}

// Create list filters
var params []clientservingv1alpha.ListConfig
var params []clientservingv1.ListConfig
params, err = appendServiceFilter(params, client, cmd)
if err != nil {
return err
Expand Down Expand Up @@ -119,7 +119,7 @@ func NewRevisionListCommand(p *commands.KnParams) *cobra.Command {
}

// If a service option is given append a filter to the list of filters
func appendServiceFilter(lConfig []clientservingv1alpha.ListConfig, client clientservingv1alpha.KnServingClient, cmd *cobra.Command) ([]clientservingv1alpha.ListConfig, error) {
func appendServiceFilter(lConfig []clientservingv1.ListConfig, client clientservingv1.KnServingClient, cmd *cobra.Command) ([]clientservingv1.ListConfig, error) {
if !cmd.Flags().Changed("service") {
return lConfig, nil
}
Expand All @@ -131,19 +131,19 @@ func appendServiceFilter(lConfig []clientservingv1alpha.ListConfig, client clien
if err != nil {
return nil, err
}
return append(lConfig, clientservingv1alpha.WithService(serviceName)), nil
return append(lConfig, clientservingv1.WithService(serviceName)), nil
}

// If an additional name is given append this as a revision name filter to the given list
func appendRevisionNameFilter(lConfigs []clientservingv1alpha.ListConfig, client clientservingv1alpha.KnServingClient, args []string) ([]clientservingv1alpha.ListConfig, error) {
func appendRevisionNameFilter(lConfigs []clientservingv1.ListConfig, client clientservingv1.KnServingClient, args []string) ([]clientservingv1.ListConfig, error) {

switch len(args) {
case 0:
// No revision name given
return lConfigs, nil
case 1:
// Exactly one name given
return append(lConfigs, clientservingv1alpha.WithName(args[0])), nil
return append(lConfigs, clientservingv1.WithName(args[0])), nil
default:
return nil, fmt.Errorf("'kn revision list' accepts maximum 1 argument, not %d arguments as given", len(args))
}
Expand Down Expand Up @@ -195,7 +195,7 @@ func revisionListSortFunc(revisionList *servingv1.RevisionList) func(i int, j in
}

// Service factory function for a namespace
type serviceFactoryFunc func(namespace string) (clientservingv1alpha.KnServingClient, error)
type serviceFactoryFunc func(namespace string) (clientservingv1.KnServingClient, error)

// A function which looks up a service by name
type serviceGetFunc func(namespace, serviceName string) (*servingv1.Service, error)
Expand Down Expand Up @@ -231,7 +231,7 @@ func serviceLookup(serviceFactory serviceFactoryFunc) serviceGetFunc {

// Two caches: For service & clients (clients might not be necessary though)
serviceCache := make(map[string]*servingv1.Service)
clientCache := make(map[string]clientservingv1alpha.KnServingClient)
clientCache := make(map[string]clientservingv1.KnServingClient)

return func(namespace, serviceName string) (*servingv1.Service, error) {
if service, exists := serviceCache[serviceName]; exists {
Expand Down
10 changes: 6 additions & 4 deletions pkg/kn/commands/service/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewServiceExportCommand(p *commands.KnParams) *cobra.Command {

command := &cobra.Command{
Use: "export NAME",
Short: "export a service",
Short: "Export a service.",
Example: `
# Export a service in yaml format
kn service export foo -n bar -o yaml
Expand Down Expand Up @@ -125,7 +125,7 @@ func constructServicefromRevision(latestSvc *servingv1.Service, revision serving
TypeMeta: latestSvc.TypeMeta,
}

exportedSvc.Spec.Template = servingv1.RevisionTemplateSpec{
exportedSvc.Spec.ConfigurationSpec.Template = servingv1.RevisionTemplateSpec{
Spec: revision.Spec,
ObjectMeta: latestSvc.Spec.ConfigurationSpec.Template.ObjectMeta,
}
Expand Down Expand Up @@ -164,8 +164,10 @@ func exportServiceWithActiveRevisions(latestSvc *servingv1.Service, client clien
return nil, fmt.Errorf("no revisions found for service %s", latestSvc.ObjectMeta.Name)
}

//set traffic in the latest revision
exportedSvcItems[len(exportedSvcItems)-1] = setTrafficSplit(latestSvc, exportedSvcItems[len(exportedSvcItems)-1])
//set traffic in the latest revision on if there is traffic split
if len(latestSvc.Spec.RouteSpec.Traffic) > 1 {
exportedSvcItems[len(exportedSvcItems)-1] = setTrafficSplit(latestSvc, exportedSvcItems[len(exportedSvcItems)-1])
}

typeMeta := metav1.TypeMeta{
APIVersion: "v1",
Expand Down
Loading

0 comments on commit 322850c

Please sign in to comment.