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): 2x simplify migration to API client. See #2116 #2290

Merged
merged 6 commits into from
Feb 22, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion 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": "latest"
"version": "kube-client"
alexec marked this conversation as resolved.
Show resolved Hide resolved
},
"paths": {
"/api/v1/archived-workflows": {
Expand Down
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 newClassicClient(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")
}
42 changes: 0 additions & 42 deletions pkg/apiclient/classic-client.go

This file was deleted.

40 changes: 0 additions & 40 deletions pkg/apiclient/classic-cron-workflow-service-client.go

This file was deleted.

Loading