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

chore(cli): Migrate argo logs to use API client. See #2116 #2177

Merged
merged 33 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
cc26a3b
chore: Migrate `argo logs` to use API client. See #2116
alexec Feb 5, 2020
664e33a
changes
alexec Feb 5, 2020
b52d20a
fix: Correctly create code from changed protos.
alexec Feb 5, 2020
12eb78e
Merge branch 'codegen' into cli-logs
alexec Feb 5, 2020
587e36d
lint
alexec Feb 5, 2020
b4d49dc
Merge branch 'master' into cli-logs
alexec Feb 6, 2020
75504ed
codegen
alexec Feb 6, 2020
a4b92a0
make codegen
alexec Feb 6, 2020
e379903
logs
alexec Feb 6, 2020
2ab5dde
changes
alexec Feb 6, 2020
0d40d96
oddloading
alexec Feb 6, 2020
cab847e
correct diagnostic output
alexec Feb 6, 2020
271eb45
hopefully the final changes
alexec Feb 6, 2020
7ed136f
changes
alexec Feb 6, 2020
7168d34
Merge branch 'master' into cli-logs
alexec Feb 7, 2020
52e85da
Merge branch 'master' into cli-logs
alexec Feb 10, 2020
88fd4ad
feat(cli-logs): fix merge + make lint
alexec Feb 10, 2020
9420827
lint
alexec Feb 10, 2020
b589a73
Merge branch 'master' into cli-logs
alexec Feb 11, 2020
1f416ff
tidy up
alexec Feb 11, 2020
8078538
Merge branch 'master' into cli-logs
alexec Feb 20, 2020
67e4f53
codegen
alexec Feb 20, 2020
1c23aa4
test(cli): fix test
alexec Feb 20, 2020
50d67aa
Merge branch 'master' into cli-logs
alexec Feb 20, 2020
ecaf440
logs
alexec Feb 21, 2020
5fed826
reinstate vendor
alexec Feb 21, 2020
1ed093a
Merge branch 'master' into cli-logs
alexec Feb 22, 2020
78eeb15
changes
alexec Feb 22, 2020
802c290
Merge branch 'master' into cli-logs
alexec Feb 24, 2020
d868351
interm-2
alexec Feb 24, 2020
67c4ff9
copylocks lint
alexec Feb 24, 2020
0594ddd
Merge branch 'master' into cli-logs
alexec Feb 25, 2020
0ec7417
Merge branch 'master' into cli-logs
alexec Feb 25, 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
Prev Previous commit
Next Next commit
Merge branch 'master' into cli-logs
  • Loading branch information
alexec committed Feb 22, 2020
commit 1ed093acc1d190ba7e4751f33bcc4710c844e28b
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ $(HOME)/go/bin/swagger:
go get github.com/go-swagger/go-swagger/cmd/swagger

api/argo-server/swagger.json: $(HOME)/go/bin/swagger $(SWAGGER_FILES)
swagger mixin -c 412 pkg/apiclient/primary.swagger.json $(SWAGGER_FILES) | sed 's/VERSION/$(VERSION)/' > api/argo-server/swagger.json
swagger mixin -c 412 pkg/apiclient/primary.swagger.json $(SWAGGER_FILES) | sed 's/VERSION/$(MANIFESTS_VERSION)/' > api/argo-server/swagger.json

# pre-push

Expand Down
28 changes: 1 addition & 27 deletions api/argo-server/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"info": {
"description": "Argo Server",
"title": "Argo Server",
"version": "cli-logs"
"version": "latest"
},
"paths": {
"/api/v1/archived-workflows": {
Expand Down Expand Up @@ -5519,31 +5519,5 @@
}
}
}
},
"x-stream-definitions": {
"workflowLogEntry": {
"properties": {
"error": {
"$ref": "#/definitions/runtimeStreamError"
},
"result": {
"$ref": "#/definitions/workflowLogEntry"
}
},
"title": "Stream result of workflowLogEntry",
"type": "object"
},
"workflowWorkflowWatchEvent": {
"properties": {
"error": {
"$ref": "#/definitions/runtimeStreamError"
},
"result": {
"$ref": "#/definitions/workflowWorkflowWatchEvent"
}
},
"title": "Stream result of workflowWorkflowWatchEvent",
"type": "object"
}
}
}
43 changes: 13 additions & 30 deletions cmd/argo/commands/resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,32 @@ package commands
import (
"fmt"
"log"
"os"

"github.com/spf13/cobra"

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

func NewResumeCommand() *cobra.Command {
var command = &cobra.Command{
Use: "resume WORKFLOW1 WORKFLOW2...",
Short: "resume a workflow",
Short: "resume zero or more workflows",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.HelpFunc()(cmd, args)
os.Exit(1)
}
namespace, _, _ := client.Config.Namespace()
if client.ArgoServer != "" {
conn := client.GetClientConn()
apiGRPCClient, ctx := GetWFApiServerGRPCClient(conn)
for _, wfName := range args {
wfUptReq := workflowpkg.WorkflowResumeRequest{
Name: wfName,
Namespace: namespace,
}
wf, err := apiGRPCClient.ResumeWorkflow(ctx, &wfUptReq)
if err != nil {
log.Fatalf("Failed to resume %s: %+v", wfName, err)
}
fmt.Printf("workflow %s resumed\n", wf.Name)
}
} else {
InitWorkflowClient()
for _, wfName := range args {
err := util.ResumeWorkflow(wfClient, wfName)
if err != nil {
log.Fatalf("Failed to resume %s: %+v", wfName, err)
}
fmt.Printf("workflow %s resumed\n", wfName)
ctx, apiClient := client.NewAPIClient()
serviceClient := apiClient.NewWorkflowServiceClient()
namespace := client.Namespace()
for _, wfName := range args {
_, err := serviceClient.ResumeWorkflow(ctx, &workflowpkg.WorkflowResumeRequest{
Name: wfName,
Namespace: namespace,
})
if err != nil {
log.Fatalf("Failed to resume %s: %+v", wfName, err)
}
fmt.Printf("workflow %s resumed\n", wfName)
}

},
}
return command
Expand Down
1 change: 1 addition & 0 deletions cmd/argo/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ If you're using the Argo Server (e.g. because you need large workflow support or
command.AddCommand(NewSubmitCommand())
command.AddCommand(NewSuspendCommand())
command.AddCommand(auth.NewAuthCommand())
command.AddCommand(NewWaitCommand())
command.AddCommand(NewWatchCommand())
command.AddCommand(NewTerminateCommand())
command.AddCommand(archive.NewArchiveCommand())
Expand Down
42 changes: 12 additions & 30 deletions cmd/argo/commands/suspend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,30 @@ package commands
import (
"fmt"
"log"
"os"

"github.com/spf13/cobra"

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

func NewSuspendCommand() *cobra.Command {
var command = &cobra.Command{
Use: "suspend WORKFLOW1 WORKFLOW2...",
Short: "suspend a workflow",
Short: "suspend zero or more workflow",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.HelpFunc()(cmd, args)
os.Exit(1)
}
namespace, _, _ := client.Config.Namespace()
if client.ArgoServer != "" {
conn := client.GetClientConn()
apiGRPCClient, ctx := GetWFApiServerGRPCClient(conn)
for _, wfName := range args {
wfUptReq := workflowpkg.WorkflowSuspendRequest{
Name: wfName,
Namespace: namespace,
}
wf, err := apiGRPCClient.SuspendWorkflow(ctx, &wfUptReq)
if err != nil {
log.Fatalf("Failed to suspended %s: %+v", wfName, err)
}
fmt.Printf("workflow %s suspended\n", wf.Name)
}
} else {
InitWorkflowClient()
for _, wfName := range args {
err := util.SuspendWorkflow(wfClient, wfName)
if err != nil {
log.Fatalf("Failed to suspend %s: %v", wfName, err)
}
fmt.Printf("workflow %s suspended\n", wfName)
ctx, apiClient := client.NewAPIClient()
serviceClient := apiClient.NewWorkflowServiceClient()
namespace := client.Namespace()
for _, wfName := range args {
_, err := serviceClient.SuspendWorkflow(ctx, &workflowpkg.WorkflowSuspendRequest{
Name: wfName,
Namespace: namespace,
})
if err != nil {
log.Fatalf("Failed to suspended %s: %+v", wfName, err)
}
fmt.Printf("workflow %s suspended\n", wfName)
}
},
}
Expand Down
20 changes: 18 additions & 2 deletions docs/managed-namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@

> v2.5 and after

You can install Argo in either cluster scoped or namespace scope configurations. This dictates if you must set-up cluster roles or normal roles.
You can install Argo in either cluster scoped or namespace scope configurations.
This dictates if you must set-up cluster roles or normal roles.

In namespace scope configuration, you must run both the Workflow Controller and Argo Server using `--namespaced`.
In namespace scope configuration, you must run both the Workflow Controller and
Argo Server using `--namespaced`. If you would like to have the workflows
running in a separated namespace, add `--managed-namespace` as well.

For example:

```
- args:
- --configmap
- workflow-controller-configmap
- --executor-image
- argoproj/workflow-controller:v2.5.1
- --namespaced
- --managed-namespace
- default
```
4 changes: 0 additions & 4 deletions docs/workflow-controller-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ data:
# controller watches workflows and pods that *are not* labeled with an instance id.
instanceID: my-ci-controller

# namespace limits the controller's watch/queries to a specific namespace. This allows the
# controller to run with namespace scope (Role), instead of cluster scope (ClusterRole).
namespace: argo

# Parallelism limits the max total parallel workflows that can execute at the same time
# (available since Argo v2.3)
parallelism: 10
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiclient/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ func NewClient(argoServer string, authSupplier func() string, clientConfig clien
if argoServer != "" {
return newArgoServerClient(argoServer, authSupplier())
} else {
return newClassicClient(clientConfig)
return newArgoKubeClient(clientConfig)
}
}
55 changes: 55 additions & 0 deletions pkg/apiclient/argo-kube-client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package apiclient

import (
"context"
"fmt"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"

"github.com/argoproj/argo/persist/sqldb"
"github.com/argoproj/argo/pkg/apiclient/cronworkflow"
workflowpkg "github.com/argoproj/argo/pkg/apiclient/workflow"
workflowarchivepkg "github.com/argoproj/argo/pkg/apiclient/workflowarchive"
"github.com/argoproj/argo/pkg/client/clientset/versioned"
"github.com/argoproj/argo/server/auth"
cronworkflowserver "github.com/argoproj/argo/server/cronworkflow"
workflowserver "github.com/argoproj/argo/server/workflow"
"github.com/argoproj/argo/util/help"
)

type argoKubeClient struct {
}

func newArgoKubeClient(clientConfig clientcmd.ClientConfig) (context.Context, Client, error) {
restConfig, err := clientConfig.ClientConfig()
if err != nil {
return nil, nil, err
}
wfClient, err := versioned.NewForConfig(restConfig)
if err != nil {
return nil, nil, err
}
kubeClient, err := kubernetes.NewForConfig(restConfig)
if err != nil {
return nil, nil, err
}
gatekeeper := auth.NewGatekeeper(auth.Server, wfClient, kubeClient, restConfig)
ctx, err := gatekeeper.Context(context.Background())
if err != nil {
return nil, nil, err
}
return ctx, &argoKubeClient{}, nil
}

func (a *argoKubeClient) NewWorkflowServiceClient() workflowpkg.WorkflowServiceClient {
return &argoKubeWorkflowServiceClient{workflowserver.NewWorkflowServer(sqldb.ExplosiveOffloadNodeStatusRepo)}
}

func (a *argoKubeClient) NewCronWorkflowServiceClient() cronworkflow.CronWorkflowServiceClient {
return &argoKubeCronWorkflowServiceClient{cronworkflowserver.NewCronWorkflowServer()}
}

func (a *argoKubeClient) NewArchivedWorkflowServiceClient() (workflowarchivepkg.ArchivedWorkflowServiceClient, error) {
return nil, fmt.Errorf("it is impossible to interact with the workflow archive if you are not using the Argo Server, see " + help.CLI)
}
34 changes: 34 additions & 0 deletions pkg/apiclient/argo-kube-cron-workflow-service-client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package apiclient

import (
"context"

"google.golang.org/grpc"

cronworkflowpkg "github.com/argoproj/argo/pkg/apiclient/cronworkflow"
"github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
)

type argoKubeCronWorkflowServiceClient struct {
delegate cronworkflowpkg.CronWorkflowServiceServer
}

func (c argoKubeCronWorkflowServiceClient) CreateCronWorkflow(ctx context.Context, req *cronworkflowpkg.CreateCronWorkflowRequest, _ ...grpc.CallOption) (*v1alpha1.CronWorkflow, error) {
return c.delegate.CreateCronWorkflow(ctx, req)
}

func (c argoKubeCronWorkflowServiceClient) ListCronWorkflows(ctx context.Context, req *cronworkflowpkg.ListCronWorkflowsRequest, _ ...grpc.CallOption) (*v1alpha1.CronWorkflowList, error) {
return c.delegate.ListCronWorkflows(ctx, req)
}

func (c argoKubeCronWorkflowServiceClient) GetCronWorkflow(ctx context.Context, req *cronworkflowpkg.GetCronWorkflowRequest, _ ...grpc.CallOption) (*v1alpha1.CronWorkflow, error) {
return c.delegate.GetCronWorkflow(ctx, req)
}

func (c argoKubeCronWorkflowServiceClient) UpdateCronWorkflow(ctx context.Context, req *cronworkflowpkg.UpdateCronWorkflowRequest, _ ...grpc.CallOption) (*v1alpha1.CronWorkflow, error) {
return c.delegate.UpdateCronWorkflow(ctx, req)
}

func (c argoKubeCronWorkflowServiceClient) DeleteCronWorkflow(ctx context.Context, req *cronworkflowpkg.DeleteCronWorkflowRequest, _ ...grpc.CallOption) (*cronworkflowpkg.CronWorkflowDeletedResponse, error) {
return c.delegate.DeleteCronWorkflow(ctx, req)
}
62 changes: 62 additions & 0 deletions pkg/apiclient/argo-kube-workflow-service-client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package apiclient

import (
"context"

"google.golang.org/grpc"

workflowpkg "github.com/argoproj/argo/pkg/apiclient/workflow"
"github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
)

type argoKubeWorkflowServiceClient struct {
delegate workflowpkg.WorkflowServiceServer
}

func (c argoKubeWorkflowServiceClient) CreateWorkflow(ctx context.Context, req *workflowpkg.WorkflowCreateRequest, _ ...grpc.CallOption) (*v1alpha1.Workflow, error) {
return c.delegate.CreateWorkflow(ctx, req)
}

func (c argoKubeWorkflowServiceClient) GetWorkflow(ctx context.Context, req *workflowpkg.WorkflowGetRequest, _ ...grpc.CallOption) (*v1alpha1.Workflow, error) {
return c.delegate.GetWorkflow(ctx, req)
}

func (c argoKubeWorkflowServiceClient) ListWorkflows(ctx context.Context, req *workflowpkg.WorkflowListRequest, _ ...grpc.CallOption) (*v1alpha1.WorkflowList, error) {
return c.delegate.ListWorkflows(ctx, req)
}

func (c argoKubeWorkflowServiceClient) WatchWorkflows(ctx context.Context, req *workflowpkg.WatchWorkflowsRequest, _ ...grpc.CallOption) (workflowpkg.WorkflowService_WatchWorkflowsClient, error) {
panic("not implemented")
}

func (c argoKubeWorkflowServiceClient) DeleteWorkflow(ctx context.Context, req *workflowpkg.WorkflowDeleteRequest, _ ...grpc.CallOption) (*workflowpkg.WorkflowDeleteResponse, error) {
return c.delegate.DeleteWorkflow(ctx, req)
}

func (c argoKubeWorkflowServiceClient) RetryWorkflow(ctx context.Context, req *workflowpkg.WorkflowRetryRequest, _ ...grpc.CallOption) (*v1alpha1.Workflow, error) {
return c.delegate.RetryWorkflow(ctx, req)
}

func (c argoKubeWorkflowServiceClient) ResubmitWorkflow(ctx context.Context, req *workflowpkg.WorkflowResubmitRequest, _ ...grpc.CallOption) (*v1alpha1.Workflow, error) {
return c.delegate.ResubmitWorkflow(ctx, req)
}

func (c argoKubeWorkflowServiceClient) ResumeWorkflow(ctx context.Context, req *workflowpkg.WorkflowResumeRequest, _ ...grpc.CallOption) (*v1alpha1.Workflow, error) {
return c.delegate.ResumeWorkflow(ctx, req)
}

func (c argoKubeWorkflowServiceClient) SuspendWorkflow(ctx context.Context, req *workflowpkg.WorkflowSuspendRequest, _ ...grpc.CallOption) (*v1alpha1.Workflow, error) {
return c.delegate.SuspendWorkflow(ctx, req)
}

func (c argoKubeWorkflowServiceClient) TerminateWorkflow(ctx context.Context, req *workflowpkg.WorkflowTerminateRequest, _ ...grpc.CallOption) (*v1alpha1.Workflow, error) {
return c.delegate.TerminateWorkflow(ctx, req)
}

func (c argoKubeWorkflowServiceClient) LintWorkflow(ctx context.Context, req *workflowpkg.WorkflowLintRequest, _ ...grpc.CallOption) (*v1alpha1.Workflow, error) {
return c.delegate.LintWorkflow(ctx, req)
}

func (c argoKubeWorkflowServiceClient) PodLogs(ctx context.Context, req *workflowpkg.WorkflowLogRequest, _ ...grpc.CallOption) (workflowpkg.WorkflowService_PodLogsClient, error) {
panic("not implemented")
}
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.