Skip to content

Commit 5d1e4e6

Browse files
committed
Merge remote-tracking branch 'origin/master' into namespace
2 parents fd6bf0d + 87b65c0 commit 5d1e4e6

File tree

27 files changed

+2972
-14
lines changed

27 files changed

+2972
-14
lines changed

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ require (
1818
github.com/libopenstorage/secrets v0.0.0-20210908194121-a1d19aa9713a
1919
github.com/oracle/oci-go-sdk/v65 v65.13.1
2020
github.com/pborman/uuid v1.2.0
21-
github.com/portworx/sched-ops v1.20.4-rc1.0.20230322190949-ae08ccbf9093
21+
github.com/portworx/kvdb v0.0.0-20230326003017-21a38cf82d4b
22+
github.com/portworx/sched-ops v1.20.4-rc1.0.20211217234328-ead591c0f22d
2223
github.com/prometheus/client_golang v1.9.0
2324
github.com/sirupsen/logrus v1.8.1
2425
github.com/stretchr/testify v1.7.0
2526
github.com/vmware/govmomi v0.22.2
27+
go.etcd.io/etcd v0.5.0-alpha.5.0.20211015134708-72d3e382e73c
2628
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
2729
google.golang.org/api v0.30.0
2830
gopkg.in/yaml.v2 v2.4.0
@@ -101,7 +103,7 @@ replace (
101103
github.com/kubernetes-incubator/external-storage => github.com/libopenstorage/external-storage v5.1.1-0.20190919185747-9394ee8dd536+incompatible
102104
github.com/prometheus/prometheus v2.9.2+incompatible => github.com/prometheus/prometheus v1.8.2-0.20190424153033-d3245f150225
103105
github.com/vmware/govmomi => github.com/libopenstorage/govmomi v0.22.3-0.20200619175019-4b44cc8cf4d1
104-
k8s.io/api => k8s.io/api v0.25.4
106+
k8s.io/api => k8s.io/api v0.20.4
105107
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.20.4
106108
k8s.io/apimachinery => k8s.io/apimachinery v0.20.4
107109
k8s.io/apiserver => k8s.io/apiserver v0.20.4

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma
340340
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
341341
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
342342
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
343+
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
343344
github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4=
344345
github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
345346
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -573,6 +574,8 @@ github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP
573574
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
574575
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
575576
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A=
577+
github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c=
578+
github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
576579
github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
577580
github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
578581
github.com/golang-jwt/jwt/v4 v4.4.3 h1:Hxl6lhQFj4AnOX6MLrsCb/+7tCj7DxP7VA+2rDIq5AU=
@@ -1240,6 +1243,8 @@ github.com/portworx/kvdb v0.0.0-20191223203141-f42097b1fcd8/go.mod h1:Q8YyrNDvPp
12401243
github.com/portworx/kvdb v0.0.0-20200311180812-b2c72382d652/go.mod h1:Q8YyrNDvPp3DVF96BDcQuaC7fAYUCuUX+l58S7OnD2M=
12411244
github.com/portworx/kvdb v0.0.0-20200723230726-2734b7f40194/go.mod h1:Q8YyrNDvPp3DVF96BDcQuaC7fAYUCuUX+l58S7OnD2M=
12421245
github.com/portworx/kvdb v0.0.0-20200929023115-b312c7519467/go.mod h1:Q8YyrNDvPp3DVF96BDcQuaC7fAYUCuUX+l58S7OnD2M=
1246+
github.com/portworx/kvdb v0.0.0-20230326003017-21a38cf82d4b h1:nP+m9tYQv2cWbN9wAwjlhJU9FZRs7GaYszhLJBLAg/I=
1247+
github.com/portworx/kvdb v0.0.0-20230326003017-21a38cf82d4b/go.mod h1:Q8YyrNDvPp3DVF96BDcQuaC7fAYUCuUX+l58S7OnD2M=
12431248
github.com/portworx/px-backup-api v1.0.1-0.20200915150042-274508e876ef/go.mod h1:puy7YVXeb6glot1vVCIePIiRLSwB//+rFtN2ZjvXeEw=
12441249
github.com/portworx/pxc v0.33.0/go.mod h1:Tl7hf4K2CDr0XtxzM08sr9H/KsMhscjf9ydb+MnT0U4=
12451250
github.com/portworx/sched-ops v0.0.0-20200123020607-b0799c4686f5/go.mod h1:yb1ypNIiZQAmM7xAWGzO6dydwl/+vNC0WjUm5IvHUEY=
@@ -1429,6 +1434,7 @@ github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhV
14291434
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
14301435
github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
14311436
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
1437+
github.com/tmc/grpc-websocket-proxy v0.0.0-20200427203606-3cfed13b9966/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
14321438
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
14331439
github.com/ugorji/go v1.1.1/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
14341440
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
@@ -1466,6 +1472,8 @@ go.etcd.io/etcd v0.0.0-20181031231232-83304cfc808c/go.mod h1:weASp41xM3dk0YHg1s/
14661472
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
14671473
go.etcd.io/etcd v0.5.0-alpha.5.0.20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
14681474
go.etcd.io/etcd v0.5.0-alpha.5.0.20200910180754-dd1b699fc489/go.mod h1:yVHk9ub3CSBatqGNg7GRmsnfLWtoW60w4eDYfh7vHDg=
1475+
go.etcd.io/etcd v0.5.0-alpha.5.0.20211015134708-72d3e382e73c h1:AntSYpWALzcqs1D6ZpSPIxhpob2hFnwAfEmfr9tEhSg=
1476+
go.etcd.io/etcd v0.5.0-alpha.5.0.20211015134708-72d3e382e73c/go.mod h1:t1cqOhpjW3SEYhH7Wzlg51xzyIM2c5HMB9kvPO5k4gY=
14691477
go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
14701478
go.mongodb.org/mongo-driver v1.1.1/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
14711479
go.mongodb.org/mongo-driver v1.1.2/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=

store/store.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package store
2+
3+
import (
4+
"fmt"
5+
"github.com/portworx/kvdb"
6+
"time"
7+
)
8+
9+
// PX specific scheduler constants
10+
const (
11+
// Kubernetes identifies kubernetes as the scheduler
12+
Kubernetes = "kubernetes"
13+
)
14+
15+
// Params is the parameters to use for the Store object
16+
type Params struct {
17+
// Kv is the bootstrap kvdb instance
18+
Kv kvdb.Kvdb
19+
// InternalKvdb indicates if PX is using internal kvdb or not
20+
InternalKvdb bool
21+
// SchedulerType indicates the platform pods are running on. e.g Kubernetes
22+
SchedulerType string
23+
}
24+
25+
// Lock identifies a lock taken over CloudDrive store
26+
type Lock struct {
27+
// Key is the name on which the lock is acquired.
28+
// This is used by the callers for logging purpose. Hence public
29+
Key string
30+
// Name of the owner who acquired the lock
31+
owner string
32+
// true if this lock was acquired using LockWithKey() interface
33+
lockedWithKey bool
34+
// lock structure as returned from the KVDB interface
35+
internalLock interface{}
36+
}
37+
38+
// KeyDoesNotExist is error type when the key does not exist
39+
type KeyDoesNotExist struct {
40+
Key string
41+
}
42+
43+
func (e *KeyDoesNotExist) Error() string {
44+
return fmt.Sprintf("key %s does not exist", e.Key)
45+
}
46+
47+
// KeyExists is error type when the key already exist in store
48+
type KeyExists struct {
49+
// Key that exists
50+
Key string
51+
// Message is an optional message to the user
52+
Message string
53+
}
54+
55+
func (e *KeyExists) Error() string {
56+
errMsg := fmt.Sprintf("key %s already exists in store", e.Key)
57+
if len(e.Message) > 0 {
58+
errMsg += " " + e.Message
59+
}
60+
return errMsg
61+
}
62+
63+
// Store provides a set of APIs to CloudDrive to store its metadata
64+
// in a persistent store
65+
type Store interface {
66+
// Lock locks the cloud drive store for a node to perform operations
67+
Lock(owner string) (*Lock, error)
68+
// Unlock unlocks the cloud drive store
69+
Unlock(storeLock *Lock) error
70+
// LockWithKey locks the cloud drive store with an arbitrary key
71+
LockWithKey(owner, key string) (*Lock, error)
72+
// IsKeyLocked checks if the specified key is currently locked
73+
IsKeyLocked(key string) (bool, string, error)
74+
// CreateKey creates the given key with the value
75+
CreateKey(key string, value []byte) error
76+
// PutKey updates the given key with the value
77+
PutKey(key string, value []byte) error
78+
// GetKey returns the value for the given key
79+
GetKey(key string) ([]byte, error)
80+
// DeleteKey deletes the given key
81+
DeleteKey(key string) error
82+
// EnumerateWithKeyPrefix enumerates all keys in the store that begin with the given key
83+
EnumerateWithKeyPrefix(key string) ([]string, error)
84+
}
85+
86+
// GetStoreWithParams returns instance for Store
87+
// kv: bootstrap kvdb
88+
// schedulerType: node scheduler type e.g Kubernetes
89+
// internalKvdb: If the cluster is configured to have internal kvdb
90+
// name: Name for the store
91+
// lockTryDuration: Total time to try acquiring the lock for
92+
// lockHoldTimeout: Once a lock is acquired, if it's held beyond this time, there will be panic
93+
func GetStoreWithParams(
94+
kv kvdb.Kvdb,
95+
schedulerType string,
96+
internalKvdb bool,
97+
name string,
98+
lockTryDuration time.Duration,
99+
lockHoldTimeout time.Duration,
100+
) (Store, error) {
101+
if len(name) == 0 {
102+
return nil, fmt.Errorf("name required to create Store")
103+
}
104+
var (
105+
s Store
106+
err error
107+
)
108+
109+
if internalKvdb && schedulerType == Kubernetes {
110+
s, _, err = newK8sStoreWithParams(name, lockTryDuration, lockHoldTimeout)
111+
} else if internalKvdb && kv == nil {
112+
return nil, fmt.Errorf("bootstrap kvdb cannot be empty")
113+
} else {
114+
// Two cases:
115+
// internal kvdb && kv is not nil
116+
// external kvdb
117+
if !internalKvdb {
118+
if kvdb.Instance() == nil {
119+
return nil, fmt.Errorf("kvdb is not initialized")
120+
}
121+
kv = kvdb.Instance()
122+
}
123+
s, err = newKVStoreWithParams(kv, name, lockTryDuration, lockHoldTimeout)
124+
}
125+
return s, err
126+
}

0 commit comments

Comments
 (0)