Move workflow to plugins

This commit is contained in:
Ian Howell
2019-05-09 12:46:34 -05:00
parent 5b1060842c
commit 35ed575fbc
6 changed files with 67 additions and 28 deletions

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -1,63 +0,0 @@
package cmd
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"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
func NewWorkflowListCommand(out io.Writer) *cobra.Command {
config, err := clientcmd.BuildConfigFromFlags("", settings.KubeConfigFilePath)
if err != nil {
log.Fatal(err.Error())
}
v1alpha1.AddToScheme(scheme.Scheme)
crdConfig := *config
crdConfig.ContentConfig.GroupVersion = &v1alpha1.SchemeGroupVersion
crdConfig.APIPath = "/apis"
crdConfig.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: scheme.Codecs}
crdConfig.UserAgent = rest.DefaultKubernetesUserAgent()
exampleRestClient, err := rest.UnversionedRESTClientFor(&crdConfig)
if err != nil {
panic(err)
}
workflowRootCmd := &cobra.Command{
Use: "list",
Short: "list workflows",
Aliases: []string{"ls"},
Run: func(cmd *cobra.Command, args []string) {
wflist := v1alpha1.WorkflowList{}
err := exampleRestClient.
Get().
Resource("workflows").
Do().
Into(&wflist)
if err != nil {
panic(err.Error())
}
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) {
fmt.Fprintf(w, "%s\t%s\n", wf.Name, wf.Status.Phase)
}
},
}
return workflowRootCmd
}