Move workflow to plugins
This commit is contained in:
parent
5b1060842c
commit
35ed575fbc
10
Makefile
10
Makefile
@ -5,6 +5,10 @@ EXECUTABLE_CLI := airshipctl
|
||||
|
||||
SCRIPTS_DIR := scripts
|
||||
|
||||
PLUGIN_DIR := plugins
|
||||
PLUGIN_SOURCES := $(wildcard $(PLUGIN_DIR)/*/*.go)
|
||||
PLUGIN_OBJECTS := $(PLUGIN_SOURCES:%.go=%.so)
|
||||
|
||||
# linting
|
||||
LINTER_CMD := "github.com/golangci/golangci-lint/cmd/golangci-lint" run
|
||||
ADDTL_LINTERS := goconst,gofmt,lll,unparam
|
||||
@ -61,3 +65,9 @@ update-golden: TESTFLAGS += -update -v
|
||||
update-golden: PKG = github.com/ian-howell/airshipctl/cmd
|
||||
update-golden:
|
||||
@go test $(PKG) $(TESTFLAGS)
|
||||
|
||||
.PHONY: plugin
|
||||
plugin: $(PLUGIN_OBJECTS)
|
||||
|
||||
%.so: %.go
|
||||
@go build -buildmode=plugin -o $@ $<
|
||||
|
@ -9,6 +9,8 @@ import (
|
||||
"github.com/ian-howell/airshipctl/pkg/environment"
|
||||
"github.com/ian-howell/airshipctl/pkg/kube"
|
||||
"github.com/ian-howell/airshipctl/pkg/log"
|
||||
"github.com/ian-howell/airshipctl/pkg/plugin"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -34,8 +36,11 @@ func NewRootCmd(out io.Writer, client *kube.Client, args []string) (*cobra.Comma
|
||||
|
||||
rootCmd.AddCommand(NewVersionCommand(out, client))
|
||||
|
||||
// Compound commands
|
||||
rootCmd.AddCommand(NewWorkflowCommand(out))
|
||||
workflowPlugin := "plugins/internal/workflow.so"
|
||||
if _, err := os.Stat(workflowPlugin); err == nil {
|
||||
rootCmd.AddCommand(plugin.CreateCommandFromPlugin(workflowPlugin, out, settings.KubeConfigFilePath))
|
||||
}
|
||||
|
||||
return rootCmd, nil
|
||||
}
|
||||
|
||||
|
@ -1,19 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func NewWorkflowCommand(out io.Writer) *cobra.Command {
|
||||
workflowRootCmd := &cobra.Command{
|
||||
Use: "workflow",
|
||||
Short: "access to workflows",
|
||||
Aliases: []string{"workflows", "wf"},
|
||||
}
|
||||
|
||||
workflowRootCmd.AddCommand(NewWorkflowListCommand(out))
|
||||
|
||||
return workflowRootCmd
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
package environment
|
||||
|
||||
import (
|
||||
restclient "k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
// AirshipCTLSettings is a container for all of the settings needed by airshipctl
|
||||
type AirshipCTLSettings struct {
|
||||
// KubeConfigFilePath is the path to the kubernetes configuration file.
|
||||
@ -7,6 +11,10 @@ type AirshipCTLSettings struct {
|
||||
// out-of-cluster
|
||||
KubeConfigFilePath string
|
||||
|
||||
// KubeConfig contains the configuration details needed for interacting
|
||||
// with the cluster
|
||||
KubeConfig *restclient.Config
|
||||
|
||||
// Debug is used for verbose output
|
||||
Debug bool
|
||||
}
|
||||
|
25
pkg/plugin/plugin.go
Normal file
25
pkg/plugin/plugin.go
Normal file
@ -0,0 +1,25 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"io"
|
||||
"plugin"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func CreateCommandFromPlugin(pluginPath string, out io.Writer, configPath string) *cobra.Command {
|
||||
//TODO(howell): Remove these panics
|
||||
plug, err := plugin.Open(pluginPath)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
cmdSym, err := plug.Lookup("NewCommand")
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
command, ok := cmdSym.(func(io.Writer, string) *cobra.Command)
|
||||
if !ok {
|
||||
panic("NewCommand does not meet the interface.")
|
||||
}
|
||||
return command(out, configPath)
|
||||
}
|
@ -1,12 +1,10 @@
|
||||
package cmd
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/ian-howell/airshipctl/pkg/log"
|
||||
|
||||
"github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||
@ -15,11 +13,23 @@ import (
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
func NewWorkflowListCommand(out io.Writer) *cobra.Command {
|
||||
func NewCommand(out io.Writer, configPath string) *cobra.Command {
|
||||
workflowRootCmd := &cobra.Command{
|
||||
Use: "workflow",
|
||||
Short: "access to workflows",
|
||||
Aliases: []string{"workflows", "wf"},
|
||||
}
|
||||
|
||||
config, err := clientcmd.BuildConfigFromFlags("", settings.KubeConfigFilePath)
|
||||
workflowRootCmd.AddCommand(NewWorkflowListCommand(out, configPath))
|
||||
|
||||
return workflowRootCmd
|
||||
}
|
||||
|
||||
func NewWorkflowListCommand(out io.Writer, configPath string) *cobra.Command {
|
||||
|
||||
config, err := clientcmd.BuildConfigFromFlags("", configPath)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
v1alpha1.AddToScheme(scheme.Scheme)
|
||||
@ -53,7 +63,7 @@ func NewWorkflowListCommand(out io.Writer) *cobra.Command {
|
||||
w := tabwriter.NewWriter(out, 0, 0, 5, ' ', 0)
|
||||
defer w.Flush()
|
||||
fmt.Fprintf(w, "%s\t%s\n", "NAME", "PHASE")
|
||||
for _, wf := range(wflist.Items) {
|
||||
for _, wf := range wflist.Items {
|
||||
fmt.Fprintf(w, "%s\t%s\n", wf.Name, wf.Status.Phase)
|
||||
}
|
||||
},
|
Loading…
x
Reference in New Issue
Block a user