Skip to content
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
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,11 @@ require (
)

require (
knative.dev/client-pkg v0.0.0-20230425201444-4f052f9ef2f2 // indirect
knative.dev/eventing-kafka v0.37.0 // indirect
github.com/hashicorp/errwrap v1.1.0
github.com/hashicorp/go-cleanhttp v0.5.2
knative.dev/client-pkg v0.0.0-20230425201444-4f052f9ef2f2
)

require knative.dev/eventing-kafka v0.37.0 // indirect

replace knative.dev/kn-plugin-event => github.com/openshift-knative/kn-plugin-event v0.33.1-0.20230821121340-be32652cdd6c
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
Expand Down
17 changes: 16 additions & 1 deletion pkg/kn/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ import (
"strings"
"text/template"

pkgplugin "knative.dev/client-pkg/pkg/kn/plugin"

homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
)

// Allow plugins to register to this slice for inlining
var InternalPlugins PluginList

var synced bool

// Interface describing a plugin
type Plugin interface {
// Get the name of the plugin (the file name without extensions)
Expand Down Expand Up @@ -104,10 +108,21 @@ func (p PluginList) Swap(i, j int) { p[i], p[j] = p[j], p[i] }

// NewManager creates a new manager for looking up plugins on the file system
func NewManager(pluginDir string, lookupInPath bool) *Manager {
return &Manager{
m := &Manager{
pluginsDir: pluginDir,
lookupInPath: lookupInPath,
}
if !synced {
for _, p := range pkgplugin.InternalPlugins {
m.AppendPlugin(p)
}
synced = true
}
return m
}

func (manager *Manager) AppendPlugin(plugin Plugin) {
InternalPlugins = append(InternalPlugins, plugin)
}

// FindPlugin checks if a plugin for the given parts exist and return it.
Expand Down
18 changes: 18 additions & 0 deletions pkg/kn/plugin/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,24 @@ func TestPluginExecute(t *testing.T) {
assert.Equal(t, out, "OK arg1 arg2\n")
}

func TestPluginAppend(t *testing.T) {
ctx := setup(t)
defer cleanup(t, ctx)

// Initialize registered plugins
defer (prepareInternalPlugins(
testPlugin{[]string{"a"}}))()

pl, err := ctx.pluginManager.ListPlugins()
assert.NilError(t, err)
assert.Assert(t, len(pl) == 1)

ctx.pluginManager.AppendPlugin(testPlugin{[]string{"another"}})
pl, err = ctx.pluginManager.ListPlugins()
assert.NilError(t, err)
assert.Assert(t, len(pl) == 2)
}

func TestPluginMixed(t *testing.T) {
ctx := setup(t)
defer cleanup(t, ctx)
Expand Down
Loading