diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 7bf0c0a073c9..fae466187a85 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -848,6 +848,12 @@ "description": "The continue option should be set when retrieving more results from the server. Since this value is\nserver defined, clients may only use the continue value from a previous query result with identical\nquery parameters (except for the value of continue) and the server may reject a continue value it\ndoes not recognize. If the specified continue value is no longer valid whether due to expiration\n(generally five to fifteen minutes) or a configuration change on the server, the server will\nrespond with a 410 ResourceExpired error together with a continue token. If the client needs a\nconsistent list, it must restart their list without the continue field. Otherwise, the client may\nsend another list request with the token received with the 410 error, the server will respond with\na list starting from the next key, but from the latest snapshot, which is inconsistent from the\nprevious list results - objects that are created, modified, or deleted after the first list request\nwill be included in the response, as long as their keys are after the \"next key\".\n\nThis field is not supported when watch is true. Clients may start a watch from the last\nresourceVersion value returned by the server and not miss any modifications.", "name": "listOptions.continue", "in": "query" + }, + { + "type": "string", + "description": "Fields to be included or excluded in the response. e.g. \"items.spec,items.status.phase\", \"-items.status.nodes\".", + "name": "fields", + "in": "query" } ], "responses": { @@ -946,6 +952,12 @@ "description": "When specified:\n- if unset, then the result is returned from remote storage based on quorum-read flag;\n- if it's 0, then we simply return what we currently have in cache, no guarantee;\n- if set to non zero, then the result is at least as fresh as given rv.", "name": "getOptions.resourceVersion", "in": "query" + }, + { + "type": "string", + "description": "Fields to be included or excluded in the response. e.g. \"spec,status.phase\", \"-status.nodes\".", + "name": "fields", + "in": "query" } ], "responses": { diff --git a/go.mod b/go.mod index f4b609a76dbb..5e890611ce3a 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( cloud.google.com/go v0.51.0 // indirect github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible github.com/ajg/form v1.5.1 // indirect - github.com/argoproj/pkg v0.0.0-20200102163130-2dd1f3f6b4de + github.com/argoproj/pkg v0.0.0-20200226231057-d69f0b04da65 github.com/aws/aws-sdk-go v1.27.1 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/colinmarc/hdfs v1.1.4-0.20180805212432-9746310a4d31 diff --git a/go.sum b/go.sum index ba4baacd5679..de0c6872c64f 100644 --- a/go.sum +++ b/go.sum @@ -35,6 +35,8 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYU github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q= github.com/argoproj/pkg v0.0.0-20200102163130-2dd1f3f6b4de h1:i19Yd0ERYAHtR84jnB8vmTuizk2q4Qw4NuayfRja5/A= github.com/argoproj/pkg v0.0.0-20200102163130-2dd1f3f6b4de/go.mod h1:2EZ44RG/CcgtPTwrRR0apOc7oU6UIw8GjCUJWZ8X3bM= +github.com/argoproj/pkg v0.0.0-20200226231057-d69f0b04da65 h1:bBC9exkuWvqhyDDhoNr66BpE6B4f+vxxKIXKxg6E6us= +github.com/argoproj/pkg v0.0.0-20200226231057-d69f0b04da65/go.mod h1:2EZ44RG/CcgtPTwrRR0apOc7oU6UIw8GjCUJWZ8X3bM= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/aws/aws-sdk-go v1.27.1 h1:MXnqY6SlWySaZAqNnXThOvjRFdiiOuKtC6i7baFdNdU= diff --git a/pkg/apiclient/workflow/forwarder_overwrite.go b/pkg/apiclient/workflow/forwarder_overwrite.go index 98750c4c74c5..b9d097522d76 100644 --- a/pkg/apiclient/workflow/forwarder_overwrite.go +++ b/pkg/apiclient/workflow/forwarder_overwrite.go @@ -1,10 +1,12 @@ package workflow import ( - "github.com/argoproj/argo/util/http" + "github.com/argoproj/pkg/grpc/http" ) func init() { forward_WorkflowService_WatchWorkflows_0 = http.StreamForwarder forward_WorkflowService_PodLogs_0 = http.StreamForwarder + forward_WorkflowService_ListWorkflows_0 = http.UnaryForwarder + forward_WorkflowService_GetWorkflow_0 = http.UnaryForwarder } diff --git a/pkg/apiclient/workflow/workflow.proto b/pkg/apiclient/workflow/workflow.proto index 781f795e30fc..c7c4d000161a 100644 --- a/pkg/apiclient/workflow/workflow.proto +++ b/pkg/apiclient/workflow/workflow.proto @@ -24,11 +24,15 @@ message WorkflowGetRequest { string name = 1; string namespace = 2; k8s.io.apimachinery.pkg.apis.meta.v1.GetOptions getOptions = 3; + // Fields to be included or excluded in the response. e.g. "spec,status.phase", "-status.nodes" + string fields = 4; } message WorkflowListRequest { string namespace = 1; k8s.io.apimachinery.pkg.apis.meta.v1.ListOptions listOptions = 2; + // Fields to be included or excluded in the response. e.g. "items.spec,items.status.phase", "-items.status.nodes" + string fields = 3; } message WorkflowResubmitRequest { diff --git a/pkg/apiclient/workflow/workflow.swagger.json b/pkg/apiclient/workflow/workflow.swagger.json index 4f4861ae5b6b..dc917dd9444b 100644 --- a/pkg/apiclient/workflow/workflow.swagger.json +++ b/pkg/apiclient/workflow/workflow.swagger.json @@ -173,6 +173,13 @@ "in": "query", "required": false, "type": "string" + }, + { + "name": "fields", + "description": "Fields to be included or excluded in the response. e.g. \"items.spec,items.status.phase\", \"-items.status.nodes\".", + "in": "query", + "required": false, + "type": "string" } ], "tags": [ @@ -272,6 +279,13 @@ "in": "query", "required": false, "type": "string" + }, + { + "name": "fields", + "description": "Fields to be included or excluded in the response. e.g. \"spec,status.phase\", \"-status.nodes\".", + "in": "query", + "required": false, + "type": "string" } ], "tags": [ diff --git a/test/e2e/argo_server_test.go b/test/e2e/argo_server_test.go index 241bc6e53b83..a5dd9f6c0686 100644 --- a/test/e2e/argo_server_test.go +++ b/test/e2e/argo_server_test.go @@ -462,6 +462,21 @@ func (s *ArgoServerSuite) TestWorkflowService() { NotNull() }) + s.Run("ListWithFields", func() { + j := s.e(s.T()).GET("/api/v1/workflows/argo"). + WithQuery("listOptions.labelSelector", "argo-e2e=subject"). + WithQuery("fields", "-items.status.nodes,items.status.finishedAt,items.status.startedAt"). + Expect(). + Status(200). + JSON() + j. + Path("$.items"). + Array(). + Length(). + Equal(1) + j.Path("$.items[0].status").Object().ContainsKey("phase").NotContainsKey("nodes") + }) + s.Run("Get", func() { j := s.e(s.T()).GET("/api/v1/workflows/argo/test"). Expect(). @@ -480,6 +495,15 @@ func (s *ArgoServerSuite) TestWorkflowService() { Status(404) }) + s.Run("GetWithFields", func() { + j := s.e(s.T()).GET("/api/v1/workflows/argo/test"). + WithQuery("fields", "status.phase"). + Expect(). + Status(200). + JSON() + j.Path("$.status").Object().ContainsKey("phase").NotContainsKey("nodes") + }) + s.Run("Suspend", func() { s.e(s.T()).PUT("/api/v1/workflows/argo/test/suspend"). Expect(). diff --git a/util/http/forwarders.go b/util/http/forwarders.go deleted file mode 100644 index 0ab0b3e4725e..000000000000 --- a/util/http/forwarders.go +++ /dev/null @@ -1,48 +0,0 @@ -package http - -import ( - "encoding/json" - "fmt" - "net/http" - - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "golang.org/x/net/context" -) - -type sseMarshaller struct { - runtime.Marshaler -} - -func (m *sseMarshaller) ContentType() string { - return "text/event-stream" -} - -func (m *sseMarshaller) Marshal(v interface{}) ([]byte, error) { - dataBytes, err := json.Marshal(v) - if err != nil { - return nil, err - } - return []byte(fmt.Sprintf("data: %s \n\n", string(dataBytes))), nil -} - -var ( - StreamForwarder = func( - ctx context.Context, - mux *runtime.ServeMux, - marshaler runtime.Marshaler, - w http.ResponseWriter, - req *http.Request, - recv func() (proto.Message, error), - opts ...func(context.Context, http.ResponseWriter, proto.Message) error, - ) { - if req.Header.Get("Accept") == "text/event-stream" { - w.Header().Set("Content-Type", "text/event-stream") - w.Header().Set("Transfer-Encoding", "chunked") - w.Header().Set("X-Content-Type-Options", "nosniff") - runtime.ForwardResponseStream(ctx, mux, &sseMarshaller{marshaler}, w, req, recv, opts...) - } else { - runtime.ForwardResponseStream(ctx, mux, marshaler, w, req, recv, opts...) - } - } -)