Skip to content

Commit

Permalink
etcd (v3) store: implements KV methods of storage.Interface
Browse files Browse the repository at this point in the history
This implements Get(), Create(), Delete(), GetToList(),
List(), GuaranteedUpdate().
  • Loading branch information
hongchaodeng committed Mar 30, 2016
1 parent e2ef27e commit 00ddf06
Show file tree
Hide file tree
Showing 5 changed files with 979 additions and 10 deletions.
10 changes: 10 additions & 0 deletions pkg/runtime/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,13 @@ func (m MultiObjectTyper) IsUnversioned(obj Object) (bool, bool) {
}
return false, false
}

// SetZeroValue would set the object of objPtr to zero value of its type.
func SetZeroValue(objPtr Object) error {
v, err := conversion.EnforcePtr(objPtr)
if err != nil {
return err
}
v.Set(reflect.Zero(v.Type()))
return nil
}
36 changes: 28 additions & 8 deletions pkg/storage/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ const (
ErrCodeKeyNotFound int = iota + 1
ErrCodeKeyExists
ErrCodeResourceVersionConflicts
ErrCodeInvalidObj
ErrCodeUnreachable
)

var errCodeToMessage = map[int]string{
ErrCodeKeyNotFound: "key not found",
ErrCodeKeyExists: "key exists",
ErrCodeResourceVersionConflicts: "resource version conflicts",
ErrCodeInvalidObj: "invalid object",
ErrCodeUnreachable: "server unreachable",
}

Expand Down Expand Up @@ -68,15 +70,24 @@ func NewUnreachableError(key string, rv int64) *StorageError {
}
}

func NewInvalidObjError(key, msg string) *StorageError {
return &StorageError{
Code: ErrCodeInvalidObj,
Key: key,
AdditionalErrorMsg: msg,
}
}

type StorageError struct {
Code int
Key string
ResourceVersion int64
Code int
Key string
ResourceVersion int64
AdditionalErrorMsg string
}

func (e *StorageError) Error() string {
return fmt.Sprintf("StorageError: %s, Code: %d, Key: %s, ResourceVersion: %d",
errCodeToMessage[e.Code], e.Code, e.Key, e.ResourceVersion)
return fmt.Sprintf("StorageError: %s, Code: %d, Key: %s, ResourceVersion: %d, AdditionalErrorMsg: %s",
errCodeToMessage[e.Code], e.Code, e.Key, e.ResourceVersion, e.AdditionalErrorMsg)
}

// IsNotFound returns true if and only if err is "key" not found error.
Expand All @@ -96,15 +107,24 @@ func IsUnreachable(err error) bool {

// IsTestFailed returns true if and only if err is a write conflict.
func IsTestFailed(err error) bool {
return isErrCode(err, ErrCodeResourceVersionConflicts)
return isErrCode(err, ErrCodeResourceVersionConflicts, ErrCodeInvalidObj)
}

// IsInvalidUID returns true if and only if err is invalid UID error
func IsInvalidObj(err error) bool {
return isErrCode(err, ErrCodeInvalidObj)
}

func isErrCode(err error, code int) bool {
func isErrCode(err error, codes ...int) bool {
if err == nil {
return false
}
if e, ok := err.(*StorageError); ok {
return e.Code == code
for _, code := range codes {
if e.Code == code {
return true
}
}
}
return false
}
Expand Down
Loading

1 comment on commit 00ddf06

@k8s-teamcity-mesosphere

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity OSS :: Kubernetes Mesos :: 4 - Smoke Tests Build 20223 outcome was SUCCESS
Summary: Tests passed: 1, ignored: 267 Build time: 00:05:22

Please sign in to comment.