diff --git a/cmd/workflow/testdata/TestWorkflowInitGoldenOutput/workflow-init.golden b/cmd/workflow/testdata/TestWorkflowInitGoldenOutput/workflow-init.golden new file mode 100644 index 000000000..039deaabf --- /dev/null +++ b/cmd/workflow/testdata/TestWorkflowInitGoldenOutput/workflow-init.golden @@ -0,0 +1,10 @@ +Creating namespace "argo" +Registering Workflow CRD +Creating argo ServiceAccount +Creating argo admin ClusterRole +Creating argo edit ClusterRole +Creating argo view ClusterRole +Creating argo ClusterRole +Creating argo ClusterRoleBinding +Creating argo ConfigMap +Creating argo Deployment diff --git a/cmd/workflow/workflow_init.go b/cmd/workflow/workflow_init.go index 0d9dcb714..6f4683482 100644 --- a/cmd/workflow/workflow_init.go +++ b/cmd/workflow/workflow_init.go @@ -14,8 +14,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" - wfenv "github.com/ian-howell/airshipctl/pkg/workflow/environment" "github.com/ian-howell/airshipctl/pkg/environment" + wfenv "github.com/ian-howell/airshipctl/pkg/workflow/environment" ) const ( @@ -48,7 +48,7 @@ func NewWorkflowInitCommand(out io.Writer, rootSettings *environment.AirshipCTLS workflowInit := &workflowInitCmd{ out: out, kubeclient: wfSettings.KubeClient, - crdclient: wfSettings.CRDClient, + crdclient: wfSettings.CRDClient.ApiextensionsV1beta1(), } fmt.Fprintf(out, "Creating namespace \"%s\"\n", argoNamespace) diff --git a/cmd/workflow/workflow_init_test.go b/cmd/workflow/workflow_init_test.go new file mode 100644 index 000000000..4595e114b --- /dev/null +++ b/cmd/workflow/workflow_init_test.go @@ -0,0 +1,44 @@ +package workflow_test + +import ( + "bytes" + "os" + "testing" + + apixv1beta1fake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake" + kubefake "k8s.io/client-go/kubernetes/fake" + + "github.com/ian-howell/airshipctl/cmd" + "github.com/ian-howell/airshipctl/cmd/workflow" + argofake "github.com/ian-howell/airshipctl/pkg/client/clientset/versioned/fake" + wfenv "github.com/ian-howell/airshipctl/pkg/workflow/environment" + "github.com/ian-howell/airshipctl/test" +) + +func TestWorkflowInit(t *testing.T) { + actual := &bytes.Buffer{} + rootCmd, settings, err := cmd.NewRootCmd(actual) + if err != nil { + t.Fatalf("Could not create root command: %s", err.Error()) + } + workflowRoot := workflow.NewWorkflowCommand(actual, settings) + workflowRoot.AddCommand(workflow.NewWorkflowInitCommand(actual, settings)) + argoClient := argofake.NewSimpleClientset() + crdClient := apixv1beta1fake.NewSimpleClientset() + kubeClient := kubefake.NewSimpleClientset() + settings.PluginSettings[workflow.PluginSettingsID] = &wfenv.Settings{ + ArgoClient: argoClient, + CRDClient: crdClient, + KubeClient: kubeClient, + } + rootCmd.AddCommand(workflowRoot) + rootCmd.PersistentFlags().Parse(os.Args[1:]) + + var tt test.CmdTest + tt = test.CmdTest{ + Name: "workflow-init", + CmdLine: "workflow init", + } + + test.RunTest(t, tt, rootCmd, actual) +} diff --git a/cmd/workflow/workflow_list.go b/cmd/workflow/workflow_list.go index 4230ce11c..cc5a7ad81 100644 --- a/cmd/workflow/workflow_list.go +++ b/cmd/workflow/workflow_list.go @@ -7,8 +7,8 @@ import ( "github.com/spf13/cobra" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/ian-howell/airshipctl/pkg/util" "github.com/ian-howell/airshipctl/pkg/environment" + "github.com/ian-howell/airshipctl/pkg/util" wfenv "github.com/ian-howell/airshipctl/pkg/workflow/environment" ) diff --git a/pkg/apis/workflow/register.go b/pkg/apis/workflow/register.go index 53e410498..978bae77c 100644 --- a/pkg/apis/workflow/register.go +++ b/pkg/apis/workflow/register.go @@ -9,4 +9,3 @@ const ( ShortName string = "wf" FullName string = Plural + "." + Group ) - diff --git a/pkg/workflow/environment/settings.go b/pkg/workflow/environment/settings.go index 38bfee974..0427ebc9b 100644 --- a/pkg/workflow/environment/settings.go +++ b/pkg/workflow/environment/settings.go @@ -2,11 +2,11 @@ package environment import ( "github.com/spf13/cobra" + apixv1beta1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" - argo "github.com/ian-howell/airshipctl/pkg/client/clientset/versioned" - apixv1beta1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1" + argo "github.com/ian-howell/airshipctl/pkg/client/clientset/versioned" ) // Settings is a container for all of the settings needed by workflows @@ -26,7 +26,7 @@ type Settings struct { ArgoClient argo.Interface // CRDClient is an instrument for interacting with CRDs - CRDClient apixv1beta1.ApiextensionsV1beta1Interface + CRDClient apixv1beta1.Interface } // InitFlags adds the default settings flags to cmd diff --git a/tools/tools.go b/tools/tools.go index f892254b1..476e03fe1 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -7,4 +7,3 @@ import ( // _ "github.com/golangci/golangci-lint/cmd/golangci-lint" _ "k8s.io/code-generator" ) -