Merge pull request #61706 from hanxiaoshuai/bugfix0326

Automatic merge from submit-queue (batch tested with PRs 60166, 61706, 61769). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

use status.Errorf instead of Deprecated func grpc.Errorf

**What this PR does / why we need it**:
```
// Deprecated; use status.Errorf instead.
func Errorf(c codes.Code, format string, a ...interface{}) error {
	return status.Errorf(c, format, a...)
}
```
func grpc.Errorf will be deprecated
**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #
use status.Errorf instead of Deprecated func grpc.Errorf
**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue
2018-03-28 10:46:08 -07:00
committed by GitHub
3 changed files with 12 additions and 10 deletions

View File

@@ -21,6 +21,7 @@ go_library(
"//vendor/github.com/emicklei/go-restful:go_default_library", "//vendor/github.com/emicklei/go-restful:go_default_library",
"//vendor/google.golang.org/grpc:go_default_library", "//vendor/google.golang.org/grpc:go_default_library",
"//vendor/google.golang.org/grpc/codes:go_default_library", "//vendor/google.golang.org/grpc/codes:go_default_library",
"//vendor/google.golang.org/grpc/status:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library", "//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/remotecommand:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/remotecommand:go_default_library",

View File

@@ -23,15 +23,16 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
) )
func ErrorStreamingDisabled(method string) error { func ErrorStreamingDisabled(method string) error {
return grpc.Errorf(codes.NotFound, fmt.Sprintf("streaming method %s disabled", method)) return status.Errorf(codes.NotFound, fmt.Sprintf("streaming method %s disabled", method))
} }
// The error returned when the maximum number of in-flight requests is exceeded. // The error returned when the maximum number of in-flight requests is exceeded.
func ErrorTooManyInFlight() error { func ErrorTooManyInFlight() error {
return grpc.Errorf(codes.ResourceExhausted, "maximum number of in-flight requests exceeded") return status.Errorf(codes.ResourceExhausted, "maximum number of in-flight requests exceeded")
} }
// Translates a CRI streaming error into an appropriate HTTP response. // Translates a CRI streaming error into an appropriate HTTP response.

View File

@@ -25,8 +25,8 @@ import (
"path" "path"
"time" "time"
"google.golang.org/grpc"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
restful "github.com/emicklei/go-restful" restful "github.com/emicklei/go-restful"
@@ -160,15 +160,15 @@ type server struct {
func validateExecRequest(req *runtimeapi.ExecRequest) error { func validateExecRequest(req *runtimeapi.ExecRequest) error {
if req.ContainerId == "" { if req.ContainerId == "" {
return grpc.Errorf(codes.InvalidArgument, "missing required container_id") return status.Errorf(codes.InvalidArgument, "missing required container_id")
} }
if req.Tty && req.Stderr { if req.Tty && req.Stderr {
// If TTY is set, stderr cannot be true because multiplexing is not // If TTY is set, stderr cannot be true because multiplexing is not
// supported. // supported.
return grpc.Errorf(codes.InvalidArgument, "tty and stderr cannot both be true") return status.Errorf(codes.InvalidArgument, "tty and stderr cannot both be true")
} }
if !req.Stdin && !req.Stdout && !req.Stderr { if !req.Stdin && !req.Stdout && !req.Stderr {
return grpc.Errorf(codes.InvalidArgument, "one of stdin, stdout, or stderr must be set") return status.Errorf(codes.InvalidArgument, "one of stdin, stdout, or stderr must be set")
} }
return nil return nil
} }
@@ -188,15 +188,15 @@ func (s *server) GetExec(req *runtimeapi.ExecRequest) (*runtimeapi.ExecResponse,
func validateAttachRequest(req *runtimeapi.AttachRequest) error { func validateAttachRequest(req *runtimeapi.AttachRequest) error {
if req.ContainerId == "" { if req.ContainerId == "" {
return grpc.Errorf(codes.InvalidArgument, "missing required container_id") return status.Errorf(codes.InvalidArgument, "missing required container_id")
} }
if req.Tty && req.Stderr { if req.Tty && req.Stderr {
// If TTY is set, stderr cannot be true because multiplexing is not // If TTY is set, stderr cannot be true because multiplexing is not
// supported. // supported.
return grpc.Errorf(codes.InvalidArgument, "tty and stderr cannot both be true") return status.Errorf(codes.InvalidArgument, "tty and stderr cannot both be true")
} }
if !req.Stdin && !req.Stdout && !req.Stderr { if !req.Stdin && !req.Stdout && !req.Stderr {
return grpc.Errorf(codes.InvalidArgument, "one of stdin, stdout, and stderr must be set") return status.Errorf(codes.InvalidArgument, "one of stdin, stdout, and stderr must be set")
} }
return nil return nil
} }
@@ -216,7 +216,7 @@ func (s *server) GetAttach(req *runtimeapi.AttachRequest) (*runtimeapi.AttachRes
func (s *server) GetPortForward(req *runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error) { func (s *server) GetPortForward(req *runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error) {
if req.PodSandboxId == "" { if req.PodSandboxId == "" {
return nil, grpc.Errorf(codes.InvalidArgument, "missing required pod_sandbox_id") return nil, status.Errorf(codes.InvalidArgument, "missing required pod_sandbox_id")
} }
token, err := s.cache.Insert(req) token, err := s.cache.Insert(req)
if err != nil { if err != nil {