-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Record original error code to operation_errors metric for temporary e…
…rrors
- Loading branch information
1 parent
cb041f3
commit e0054fd
Showing
7 changed files
with
179 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package common | ||
|
||
import ( | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
// TemporaryError wraps an error that needs to be returned to the CSI Provisioner | ||
// with a temporary Error code. It implements the error interface. | ||
type TemporaryError struct { | ||
err error | ||
code codes.Code | ||
} | ||
|
||
// Unwrap extracts the original error. | ||
func (te *TemporaryError) Unwrap() error { | ||
return te.err | ||
} | ||
|
||
// GRPCStatus extracts the underlying gRPC Status error. | ||
// This method is necessary to fulfill the interface | ||
// described in https://pkg.go.dev/google.golang.org/grpc/status#FromError. | ||
// FromError is used in CodeForError to get existing error codes from status errors. | ||
func (te *TemporaryError) GRPCStatus() *status.Status { | ||
if te.err == nil { | ||
return status.New(codes.OK, "") | ||
} | ||
return status.New(te.code, te.err.Error()) | ||
} | ||
|
||
func NewTemporaryError(code codes.Code, err error) *TemporaryError { | ||
return &TemporaryError{err: err, code: code} | ||
} | ||
|
||
// Error returns a readable representation of the TemporaryError. | ||
func (te *TemporaryError) Error() string { | ||
return te.err.Error() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters