Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kn): Enable faas to be integrated as plugin to kn #155

Merged
merged 1 commit into from
Oct 8, 2020
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: 6 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ var root = &cobra.Command{
Create and run Functions as a Service.`,
}

// NewRootCmd is used to initialize faas as kn plugin
func NewRootCmd() *cobra.Command {
return root
}

// When the code is loaded into memory upon invocation, the cobra/viper packages
// are invoked to gather system context. This includes reading the configuration
// file, environment variables, and parsing the command flags.
func init() {
func Init() {
// read in environment variables that match
viper.AutomaticEnv()

Expand Down
42 changes: 42 additions & 0 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package plugin

import (
"github.com/boson-project/faas/cmd"
"knative.dev/client/pkg/kn/plugin"
"os"
)

func init() {
plugin.InternalPlugins = append(plugin.InternalPlugins, &faasPlugin{})
}

type faasPlugin struct {}

func (f *faasPlugin) Name() string {
return "kn-faas"
}

func (f *faasPlugin) Execute(args []string) error {
rootCmd := cmd.NewRootCmd()
cmd.Init()
oldArgs := os.Args
defer (func() {
os.Args = oldArgs
})()
os.Args = append([]string { "kn-faas" }, args...)
return rootCmd.Execute()
}

// Description for faas subcommand visible in 'kn --help'
func (f *faasPlugin) Description() (string, error) {
return "Function as a Service plugin", nil
}

func (f *faasPlugin) CommandParts() []string {
return []string{ "faas"}
}

// Path is empty because its an internal plugins
func (f *faasPlugin) Path() string {
return ""
}