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

refactor(cli): Introduce v1.Interface for CLI. Closes #2107 #2048

Merged
merged 46 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0e9231e
refactor(cli): Introduce v1.Interface for CLI
alexec Jan 24, 2020
a3cf4dd
Merge branch 'master' into cli-if
alexec Jan 24, 2020
3c89e7a
Merge branch 'master' into cli-if
alexec Jan 24, 2020
ba81475
add missing env vars
alexec Jan 25, 2020
61fcc65
namespace
alexec Jan 25, 2020
1a75fdd
removed files
alexec Jan 25, 2020
c630a8e
Merge branch 'master' into cli-if
alexec Jan 26, 2020
860076b
test: fatal if no argo-e2e label
alexec Jan 27, 2020
f502a5c
test: change archive assertion to ignore the status
alexec Jan 27, 2020
33e96fe
Merge branch 'master' into cli-if
alexec Jan 27, 2020
41f6030
refactor: Move server code (cmd/server/ -> server/) (#2071)
simster7 Jan 27, 2020
941fc06
lint
alexec Jan 27, 2020
1b5c321
Merge branch 'master' into cli-if
alexec Jan 27, 2020
e0b672a
move code around
alexec Jan 28, 2020
6a2ad93
moved files
alexec Jan 28, 2020
e4cd1bd
moved workflow files
alexec Jan 28, 2020
59f0d14
moved workflow archive files
alexec Jan 28, 2020
02c6193
moved workflow template files
alexec Jan 28, 2020
7bd8619
tweak readinessProbe
alexec Jan 28, 2020
4ffd703
build: make cli before cli tests
alexec Jan 28, 2020
9135b3c
build: make cli before tests
alexec Jan 28, 2020
f9707ed
feat: introduce various components
alexec Jan 28, 2020
b27e305
tweak readinessProbe
alexec Jan 28, 2020
96504d1
Merge branch 'master' into cli-if
alexec Jan 28, 2020
b8bab0b
docs: updated docs
alexec Jan 28, 2020
4437153
renamed API classic
alexec Jan 28, 2020
22be4a1
log warning
alexec Jan 29, 2020
fbb2f8b
Merge branch 'master' into cli-if
alexec Jan 29, 2020
4268930
Update docs/argo-server.md
alexec Jan 30, 2020
9d62b7e
Update docs/cli.md
alexec Jan 30, 2020
acd97d8
Update docs/argo-server.md
alexec Jan 30, 2020
560b775
Merge branch 'master' into cli-if
alexec Jan 30, 2020
9d6a295
Merge branch 'cli-if' of github.com:alexec/argo into cli-if
alexec Jan 30, 2020
707b6c7
Merge branch 'master' into cli-if
alexec Jan 30, 2020
3bd37f4
renamed to CLISuite
alexec Jan 30, 2020
1246586
fix: deal with missing bearer token
alexec Jan 30, 2020
443b2bd
feat: no longer query live workflows if we do not need to
alexec Jan 30, 2020
89b3ab5
Merge branch 'master' into cli-if
alexec Jan 30, 2020
4fd883e
Merge branch 'master' into cli-if
alexec Jan 30, 2020
2d013fb
merge
alexec Jan 30, 2020
ce50880
fix tests
alexec Jan 31, 2020
d2510e4
remove loggig
alexec Jan 31, 2020
d940ecb
find empty url bug
alexec Jan 31, 2020
bee619d
ci: re-order
alexec Jan 31, 2020
405f776
diagnostics
alexec Jan 31, 2020
8a6d5ad
add pod GC
alexec Jan 31, 2020
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
1 change: 0 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ mysql-cli:
kubectl exec -ti `kubectl get pod -l app=mysql -o name|cut -c 5-` -- mysql -u mysql -ppassword argo

.PHONY: test-e2e
test-e2e: test-images
test-e2e: test-images cli
# Run E2E tests
go test -timeout 20m -v -count 1 -p 1 ./test/e2e/...

Expand All @@ -381,9 +381,10 @@ test-api: test-images
go test -timeout 3m -v -count 1 -p 1 -run ArgoServerSuite ./test/e2e

.PHONY: test-cli
test-cli: test-images
test-cli: test-images cli
# Run CLI tests
go test -timeout 1m -v -count 1 -p 1 -run CliSuite ./test/e2e
go test -timeout 1m -v -count 1 -p 1 -run CLIWithServerSuite ./test/e2e
alexec marked this conversation as resolved.
Show resolved Hide resolved

# clean

Expand Down
20 changes: 8 additions & 12 deletions cmd/argo/commands/archive/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@ package archive

import (
"fmt"
"log"

"github.com/argoproj/pkg/errors"
"github.com/spf13/cobra"

"github.com/argoproj/argo/cmd/argo/commands/client"
"github.com/argoproj/argo/server/workflowarchive"
client "github.com/argoproj/argo/cmd/argo/commands/client"
workflowarchivepkg "github.com/argoproj/argo/pkg/apiclient/workflowarchive"
)

func NewDeleteCommand() *cobra.Command {
var command = &cobra.Command{
Use: "delete UID...",
Run: func(cmd *cobra.Command, args []string) {
ctx, apiClient := client.NewAPIClient()
serviceClient, err := apiClient.NewArchivedWorkflowServiceClient()
errors.CheckError(err)
for _, uid := range args {
conn := client.GetClientConn()
ctx := client.GetContext()
client := workflowarchive.NewArchivedWorkflowServiceClient(conn)
_, err := client.DeleteArchivedWorkflow(ctx, &workflowarchive.DeleteArchivedWorkflowRequest{
Uid: uid,
})
if err != nil {
log.Fatal(err)
}
_, err = serviceClient.DeleteArchivedWorkflow(ctx, &workflowarchivepkg.DeleteArchivedWorkflowRequest{Uid: uid})
errors.CheckError(err)
fmt.Printf("Archived workflow '%s' deleted\n", uid)
}
},
Expand Down
18 changes: 8 additions & 10 deletions cmd/argo/commands/archive/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"log"
"os"

"github.com/argoproj/pkg/errors"
"github.com/argoproj/pkg/humanize"
"github.com/spf13/cobra"
"sigs.k8s.io/yaml"

"github.com/argoproj/argo/cmd/argo/commands/client"
"github.com/argoproj/argo/server/workflowarchive"
workflowarchivepkg "github.com/argoproj/argo/pkg/apiclient/workflowarchive"
)

func NewGetCommand() *cobra.Command {
Expand All @@ -26,15 +27,12 @@ func NewGetCommand() *cobra.Command {
os.Exit(1)
}
uid := args[0]
conn := client.GetClientConn()
ctx := client.GetContext()
client := workflowarchive.NewArchivedWorkflowServiceClient(conn)
wf, err := client.GetArchivedWorkflow(ctx, &workflowarchive.GetArchivedWorkflowRequest{
Uid: uid,
})
if err != nil {
log.Fatal(err)
}

ctx, apiClient := client.NewAPIClient()
serviceClient, err := apiClient.NewArchivedWorkflowServiceClient()
errors.CheckError(err)
wf, err := serviceClient.GetArchivedWorkflow(ctx, &workflowarchivepkg.GetArchivedWorkflowRequest{Uid: uid})
errors.CheckError(err)
switch output {
case "json":
output, err := json.Marshal(wf)
Expand Down
24 changes: 12 additions & 12 deletions cmd/argo/commands/archive/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,32 @@ import (
"os"
"text/tabwriter"

"github.com/argoproj/pkg/errors"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"

"github.com/argoproj/argo/cmd/argo/commands/client"
"github.com/argoproj/argo/server/workflowarchive"
workflowarchivepkg "github.com/argoproj/argo/pkg/apiclient/workflowarchive"
)

func NewListCommand() *cobra.Command {
var (
output string
namespace string
output string
)
var command = &cobra.Command{
Use: "list",
Run: func(cmd *cobra.Command, args []string) {
conn := client.GetClientConn()
ctx := client.GetContext()
client := workflowarchive.NewArchivedWorkflowServiceClient(conn)
resp, err := client.ListArchivedWorkflows(ctx, &workflowarchive.ListArchivedWorkflowsRequest{
ListOptions: &metav1.ListOptions{FieldSelector: "metadata.namespace=" + namespace},
ctx, apiClient := client.NewAPIClient()
serviceClient, err := apiClient.NewArchivedWorkflowServiceClient()
errors.CheckError(err)
namespace := client.Namespace()
resp, err := serviceClient.ListArchivedWorkflows(ctx, &workflowarchivepkg.ListArchivedWorkflowsRequest{
ListOptions: &metav1.ListOptions{
FieldSelector: "metadata.namespace=" + namespace,
},
})
if err != nil {
log.Fatal(err)
}
errors.CheckError(err)
switch output {
case "json":
output, err := json.Marshal(resp.Items)
Expand All @@ -56,6 +57,5 @@ func NewListCommand() *cobra.Command {
},
}
command.Flags().StringVarP(&output, "output", "o", "wide", "Output format. One of: json|yaml|wide")
command.Flags().StringVarP(&namespace, "namespace", "n", "", "The namespace")
return command
}
31 changes: 24 additions & 7 deletions cmd/argo/commands/client/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"k8s.io/client-go/tools/clientcmd"

"github.com/argoproj/argo/pkg/apiclient"
"github.com/argoproj/argo/util/kubeconfig"
)

// DEPRECATED
var ArgoServer string

// DEPRECATED
var Config clientcmd.ClientConfig

func AddKubectlFlagsToCmd(cmd *cobra.Command) {
Expand All @@ -31,20 +34,34 @@ func AddArgoServerFlagsToCmd(cmd *cobra.Command) {
cmd.PersistentFlags().StringVar(&ArgoServer, "argo-server", os.Getenv("ARGO_SERVER"), "API server `host:port`. e.g. localhost:2746. Defaults to the ARGO_SERVER environment variable.")
}

// DEPRECATED
func GetClientConn() *grpc.ClientConn {
conn, err := grpc.Dial(ArgoServer, grpc.WithInsecure())
conn, err := apiclient.NewClientConn(ArgoServer)
if err != nil {
log.Fatal(err)
}
return conn
}

func GetContext() context.Context {
token := GetBearerToken()
if token == "" {
return context.Background()
func NewAPIClient() (context.Context, apiclient.Client) {
ctx, client, err := apiclient.NewClient(ArgoServer, GetBearerToken(), Config)
if err != nil {
log.Fatal(err)
}
return ctx, client
}

func Namespace() string {
namespace, _, err := Config.Namespace()
if err != nil {
log.Fatal(err)
}
return metadata.NewOutgoingContext(context.Background(), metadata.Pairs("authorization", "Bearer "+GetBearerToken()))
return namespace
}

// DEPRECATED should only be used by client/v1 package
func GetContext() context.Context {
return apiclient.NewContext(GetBearerToken())
}

func GetBearerToken() string {
Expand Down
29 changes: 19 additions & 10 deletions cmd/argo/commands/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,31 @@ import (
"k8s.io/client-go/rest"

"github.com/argoproj/argo/cmd/argo/commands/client"
"github.com/argoproj/argo/pkg/apiclient/workflow"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo/pkg/client/clientset/versioned"
"github.com/argoproj/argo/pkg/client/clientset/versioned/typed/workflow/v1alpha1"
wfApiServer "github.com/argoproj/argo/server/workflow"
"github.com/argoproj/argo/workflow/templateresolution"
)

// Global variables
var (
restConfig *rest.Config
clientset *kubernetes.Clientset
wfClientset *versioned.Clientset
wfClient v1alpha1.WorkflowInterface
// DEPRECATED
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't these just be deleted? AFAIK, people don't import our CLI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our CLI uses these methods - this is really more to make it easy for us to identify methods to remove

restConfig *rest.Config
// DEPRECATED
clientset *kubernetes.Clientset
// DEPRECATED
wfClientset *versioned.Clientset
// DEPRECATED
wfClient v1alpha1.WorkflowInterface
// DEPRECATED
wftmplClient v1alpha1.WorkflowTemplateInterface
jobStatusIconMap map[wfv1.NodePhase]string
noColor bool
namespace string
// DEPRECATED
namespace string
)

const ARGO_SERVER_ENV = "ARGO_SERVER"

func init() {
cobra.OnInitialize(initializeSession)
}
Expand Down Expand Up @@ -69,6 +73,7 @@ func initializeSession() {
}
}

// DEPRECATED
func InitKubeClient() *kubernetes.Clientset {
if clientset != nil {
return clientset
Expand All @@ -88,6 +93,7 @@ func InitKubeClient() *kubernetes.Clientset {
}

// InitWorkflowClient creates a new client for the Kubernetes Workflow CRD.
// DEPRECATED
func InitWorkflowClient(ns ...string) v1alpha1.WorkflowInterface {
if wfClient != nil && (len(ns) == 0 || ns[0] == namespace) {
return wfClient
Expand Down Expand Up @@ -129,9 +135,11 @@ func ansiFormat(s string, codes ...int) string {

// LazyWorkflowTemplateGetter is a wrapper of v1alpha1.WorkflowTemplateInterface which
// supports lazy initialization.
// DEPRECATED
type LazyWorkflowTemplateGetter struct{}

// Get initializes it just before it's actually used and returns a retrieved workflow template.
// DEPRECATED
func (c LazyWorkflowTemplateGetter) Get(name string) (*wfv1.WorkflowTemplate, error) {
if wftmplClient == nil {
_ = InitWorkflowClient()
Expand All @@ -141,6 +149,7 @@ func (c LazyWorkflowTemplateGetter) Get(name string) (*wfv1.WorkflowTemplate, er

var _ templateresolution.WorkflowTemplateNamespacedGetter = &LazyWorkflowTemplateGetter{}

func GetWFApiServerGRPCClient(conn *grpc.ClientConn) (wfApiServer.WorkflowServiceClient, context.Context) {
return wfApiServer.NewWorkflowServiceClient(conn), client.GetContext()
// DEPRECATED
func GetWFApiServerGRPCClient(conn *grpc.ClientConn) (workflow.WorkflowServiceClient, context.Context) {
return workflow.NewWorkflowServiceClient(conn), client.GetContext()
}
14 changes: 7 additions & 7 deletions cmd/argo/commands/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"os"
"time"

"github.com/argoproj/argo/cmd/argo/commands/client"
"github.com/argoproj/argo/server/workflow"

argotime "github.com/argoproj/pkg/time"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/argoproj/argo/cmd/argo/commands/client"
workflowpkg "github.com/argoproj/argo/pkg/apiclient/workflow"

"github.com/argoproj/argo/workflow/common"
)

Expand Down Expand Up @@ -107,8 +107,8 @@ func apiServerDeleteWorkflows(allWFs bool, older string, completed bool, wfNames
}
}

func getWFList(client workflow.WorkflowServiceClient, ctx context.Context, ns string, opts *metav1.ListOptions, older *time.Time) ([]string, error) {
wfReq := workflow.WorkflowListRequest{
func getWFList(client workflowpkg.WorkflowServiceClient, ctx context.Context, ns string, opts *metav1.ListOptions, older *time.Time) ([]string, error) {
wfReq := workflowpkg.WorkflowListRequest{
ListOptions: opts,
Namespace: ns,
}
Expand All @@ -128,8 +128,8 @@ func getWFList(client workflow.WorkflowServiceClient, ctx context.Context, ns st
return wfNames, nil
}

func apiServerDeleteWorkflow(client workflow.WorkflowServiceClient, ctx context.Context, wfName, ns string) {
wfReq := workflow.WorkflowDeleteRequest{
func apiServerDeleteWorkflow(client workflowpkg.WorkflowServiceClient, ctx context.Context, wfName, ns string) {
wfReq := workflowpkg.WorkflowDeleteRequest{
Name: wfName,
Namespace: ns,
}
Expand Down
Loading