Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-bhatia committed Mar 28, 2023
2 parents fd6bf0d + 87b65c0 commit 5d1e4e6
Show file tree
Hide file tree
Showing 27 changed files with 2,972 additions and 14 deletions.
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ require (
github.com/libopenstorage/secrets v0.0.0-20210908194121-a1d19aa9713a
github.com/oracle/oci-go-sdk/v65 v65.13.1
github.com/pborman/uuid v1.2.0
github.com/portworx/sched-ops v1.20.4-rc1.0.20230322190949-ae08ccbf9093
github.com/portworx/kvdb v0.0.0-20230326003017-21a38cf82d4b
github.com/portworx/sched-ops v1.20.4-rc1.0.20211217234328-ead591c0f22d
github.com/prometheus/client_golang v1.9.0
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
github.com/vmware/govmomi v0.22.2
go.etcd.io/etcd v0.5.0-alpha.5.0.20211015134708-72d3e382e73c
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
google.golang.org/api v0.30.0
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -101,7 +103,7 @@ replace (
github.com/kubernetes-incubator/external-storage => github.com/libopenstorage/external-storage v5.1.1-0.20190919185747-9394ee8dd536+incompatible
github.com/prometheus/prometheus v2.9.2+incompatible => github.com/prometheus/prometheus v1.8.2-0.20190424153033-d3245f150225
github.com/vmware/govmomi => github.com/libopenstorage/govmomi v0.22.3-0.20200619175019-4b44cc8cf4d1
k8s.io/api => k8s.io/api v0.25.4
k8s.io/api => k8s.io/api v0.20.4
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.20.4
k8s.io/apimachinery => k8s.io/apimachinery v0.20.4
k8s.io/apiserver => k8s.io/apiserver v0.20.4
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4=
github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -573,6 +574,8 @@ github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A=
github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c=
github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
github.com/golang-jwt/jwt/v4 v4.4.3 h1:Hxl6lhQFj4AnOX6MLrsCb/+7tCj7DxP7VA+2rDIq5AU=
Expand Down Expand Up @@ -1240,6 +1243,8 @@ github.com/portworx/kvdb v0.0.0-20191223203141-f42097b1fcd8/go.mod h1:Q8YyrNDvPp
github.com/portworx/kvdb v0.0.0-20200311180812-b2c72382d652/go.mod h1:Q8YyrNDvPp3DVF96BDcQuaC7fAYUCuUX+l58S7OnD2M=
github.com/portworx/kvdb v0.0.0-20200723230726-2734b7f40194/go.mod h1:Q8YyrNDvPp3DVF96BDcQuaC7fAYUCuUX+l58S7OnD2M=
github.com/portworx/kvdb v0.0.0-20200929023115-b312c7519467/go.mod h1:Q8YyrNDvPp3DVF96BDcQuaC7fAYUCuUX+l58S7OnD2M=
github.com/portworx/kvdb v0.0.0-20230326003017-21a38cf82d4b h1:nP+m9tYQv2cWbN9wAwjlhJU9FZRs7GaYszhLJBLAg/I=
github.com/portworx/kvdb v0.0.0-20230326003017-21a38cf82d4b/go.mod h1:Q8YyrNDvPp3DVF96BDcQuaC7fAYUCuUX+l58S7OnD2M=
github.com/portworx/px-backup-api v1.0.1-0.20200915150042-274508e876ef/go.mod h1:puy7YVXeb6glot1vVCIePIiRLSwB//+rFtN2ZjvXeEw=
github.com/portworx/pxc v0.33.0/go.mod h1:Tl7hf4K2CDr0XtxzM08sr9H/KsMhscjf9ydb+MnT0U4=
github.com/portworx/sched-ops v0.0.0-20200123020607-b0799c4686f5/go.mod h1:yb1ypNIiZQAmM7xAWGzO6dydwl/+vNC0WjUm5IvHUEY=
Expand Down Expand Up @@ -1429,6 +1434,7 @@ github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhV
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20200427203606-3cfed13b9966/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/ugorji/go v1.1.1/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
Expand Down Expand Up @@ -1466,6 +1472,8 @@ go.etcd.io/etcd v0.0.0-20181031231232-83304cfc808c/go.mod h1:weASp41xM3dk0YHg1s/
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
go.etcd.io/etcd v0.5.0-alpha.5.0.20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
go.etcd.io/etcd v0.5.0-alpha.5.0.20200910180754-dd1b699fc489/go.mod h1:yVHk9ub3CSBatqGNg7GRmsnfLWtoW60w4eDYfh7vHDg=
go.etcd.io/etcd v0.5.0-alpha.5.0.20211015134708-72d3e382e73c h1:AntSYpWALzcqs1D6ZpSPIxhpob2hFnwAfEmfr9tEhSg=
go.etcd.io/etcd v0.5.0-alpha.5.0.20211015134708-72d3e382e73c/go.mod h1:t1cqOhpjW3SEYhH7Wzlg51xzyIM2c5HMB9kvPO5k4gY=
go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
go.mongodb.org/mongo-driver v1.1.1/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
go.mongodb.org/mongo-driver v1.1.2/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
Expand Down
126 changes: 126 additions & 0 deletions store/store.go
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
}
Loading

0 comments on commit 5d1e4e6

Please sign in to comment.