-
Notifications
You must be signed in to change notification settings - Fork 14
PWX-28882: Fix Nomad support issues for vSphere provider #137
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c08974e
PWX-28882: Fix Nomad support issues for vSphere provider
nrevanna a8ac404
Vendoring packages
nrevanna f02a911
Review comments
nrevanna 272fd9b
Review comments
nrevanna d64cc89
Comment fixes
nrevanna 02735eb
Review comments
nrevanna e37c094
Review comments
nrevanna de5c04d
Merge branch 'master' into PWX-28882_master
nrevanna 3f9f10b
Improvements to store interface
nrevanna eac79cb
comment update
nrevanna 6bfc5a5
Vendoring + renaming
nrevanna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,126 @@ | ||
| package store | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "github.com/portworx/kvdb" | ||
| "time" | ||
| ) | ||
|
|
||
| // PX specific scheduler constants | ||
| const ( | ||
| // Kubernetes identifies kubernetes as the scheduler | ||
| Kubernetes = "kubernetes" | ||
| ) | ||
|
|
||
| // Params is the parameters to use for the Store object | ||
| type Params struct { | ||
| // Kv is the bootstrap kvdb instance | ||
| Kv kvdb.Kvdb | ||
| // InternalKvdb indicates if PX is using internal kvdb or not | ||
| InternalKvdb bool | ||
| // SchedulerType indicates the platform pods are running on. e.g Kubernetes | ||
| SchedulerType string | ||
| } | ||
|
|
||
| // Lock identifies a lock taken over CloudDrive store | ||
| type Lock struct { | ||
| // Key is the name on which the lock is acquired. | ||
| // This is used by the callers for logging purpose. Hence public | ||
| Key string | ||
| // Name of the owner who acquired the lock | ||
| owner string | ||
| // true if this lock was acquired using LockWithKey() interface | ||
| lockedWithKey bool | ||
| // lock structure as returned from the KVDB interface | ||
| internalLock interface{} | ||
| } | ||
|
|
||
| // KeyDoesNotExist is error type when the key does not exist | ||
| type KeyDoesNotExist struct { | ||
| Key string | ||
| } | ||
|
|
||
| func (e *KeyDoesNotExist) Error() string { | ||
| return fmt.Sprintf("key %s does not exist", e.Key) | ||
| } | ||
|
|
||
| // KeyExists is error type when the key already exist in store | ||
| type KeyExists struct { | ||
| // Key that exists | ||
| Key string | ||
| // Message is an optional message to the user | ||
| Message string | ||
| } | ||
|
|
||
| func (e *KeyExists) Error() string { | ||
| errMsg := fmt.Sprintf("key %s already exists in store", e.Key) | ||
| if len(e.Message) > 0 { | ||
| errMsg += " " + e.Message | ||
| } | ||
| return errMsg | ||
| } | ||
|
|
||
| // Store provides a set of APIs to CloudDrive to store its metadata | ||
| // in a persistent store | ||
| type Store interface { | ||
| // Lock locks the cloud drive store for a node to perform operations | ||
| Lock(owner string) (*Lock, error) | ||
| // Unlock unlocks the cloud drive store | ||
| Unlock(storeLock *Lock) error | ||
| // LockWithKey locks the cloud drive store with an arbitrary key | ||
| LockWithKey(owner, key string) (*Lock, error) | ||
| // IsKeyLocked checks if the specified key is currently locked | ||
| IsKeyLocked(key string) (bool, string, error) | ||
| // CreateKey creates the given key with the value | ||
| CreateKey(key string, value []byte) error | ||
| // PutKey updates the given key with the value | ||
| PutKey(key string, value []byte) error | ||
| // GetKey returns the value for the given key | ||
| GetKey(key string) ([]byte, error) | ||
| // DeleteKey deletes the given key | ||
| DeleteKey(key string) error | ||
| // EnumerateWithKeyPrefix enumerates all keys in the store that begin with the given key | ||
| EnumerateWithKeyPrefix(key string) ([]string, error) | ||
| } | ||
|
|
||
| // GetStoreWithParams returns instance for Store | ||
| // kv: bootstrap kvdb | ||
| // schedulerType: node scheduler type e.g Kubernetes | ||
| // internalKvdb: If the cluster is configured to have internal kvdb | ||
| // name: Name for the store | ||
| // lockTryDuration: Total time to try acquiring the lock for | ||
| // lockHoldTimeout: Once a lock is acquired, if it's held beyond this time, there will be panic | ||
| func GetStoreWithParams( | ||
| kv kvdb.Kvdb, | ||
| schedulerType string, | ||
| internalKvdb bool, | ||
| name string, | ||
| lockTryDuration time.Duration, | ||
| lockHoldTimeout time.Duration, | ||
| ) (Store, error) { | ||
| if len(name) == 0 { | ||
| return nil, fmt.Errorf("name required to create Store") | ||
| } | ||
| var ( | ||
| s Store | ||
| err error | ||
| ) | ||
|
|
||
| if internalKvdb && schedulerType == Kubernetes { | ||
| s, _, err = newK8sStoreWithParams(name, lockTryDuration, lockHoldTimeout) | ||
| } else if internalKvdb && kv == nil { | ||
| return nil, fmt.Errorf("bootstrap kvdb cannot be empty") | ||
| } else { | ||
| // Two cases: | ||
| // internal kvdb && kv is not nil | ||
| // external kvdb | ||
| if !internalKvdb { | ||
| if kvdb.Instance() == nil { | ||
| return nil, fmt.Errorf("kvdb is not initialized") | ||
| } | ||
| kv = kvdb.Instance() | ||
| } | ||
| s, err = newKVStoreWithParams(kv, name, lockTryDuration, lockHoldTimeout) | ||
| } | ||
| return s, err | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.