|
| 1 | +package v1beta3 |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "time" |
| 6 | + |
| 7 | + "github.com/openebs/openebs-e2e/common" |
| 8 | + "github.com/openebs/openebs-e2e/common/e2e_config" |
| 9 | + |
| 10 | + v1beta3 "github.com/openebs/openebs-e2e/common/custom_resources/api/types/v1beta3" |
| 11 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 12 | + "k8s.io/apimachinery/pkg/watch" |
| 13 | + "k8s.io/client-go/kubernetes/scheme" |
| 14 | + "k8s.io/client-go/rest" |
| 15 | +) |
| 16 | + |
| 17 | +// DiskPoolInterface has methods to work with Mayastor pool resources. |
| 18 | +type DiskPoolInterface interface { |
| 19 | + Create(ctxt context.Context, diskpool *v1beta3.DiskPool, opts metav1.CreateOptions) (*v1beta3.DiskPool, error) |
| 20 | + Get(ctxt context.Context, name string, opts metav1.GetOptions) (*v1beta3.DiskPool, error) |
| 21 | + List(ctxt context.Context, opts metav1.ListOptions) (*v1beta3.DiskPoolList, error) |
| 22 | + Update(ctxt context.Context, diskpool *v1beta3.DiskPool, opts metav1.UpdateOptions) (*v1beta3.DiskPool, error) |
| 23 | + Delete(ctxt context.Context, name string, opts metav1.DeleteOptions) error |
| 24 | + Watch(ctxt context.Context, opts metav1.ListOptions) (watch.Interface, error) |
| 25 | + // ... |
| 26 | +} |
| 27 | + |
| 28 | +// dspClient implements DiskPoolInterface |
| 29 | +type dspClient struct { |
| 30 | + restClient rest.Interface |
| 31 | +} |
| 32 | + |
| 33 | +// Create takes the representation of a Mayastor pool and creates it. Returns the server's representation of the pool, and an error if one occurred. |
| 34 | +func (c *dspClient) Create(ctxt context.Context, diskpool *v1beta3.DiskPool, opts metav1.CreateOptions) (*v1beta3.DiskPool, error) { |
| 35 | + result := v1beta3.DiskPool{} |
| 36 | + err := c.restClient. |
| 37 | + Post(). |
| 38 | + Namespace(common.NSMayastor()). |
| 39 | + Resource(e2e_config.GetConfig().Product.CrdPoolsResourceName). |
| 40 | + VersionedParams(&opts, scheme.ParameterCodec). |
| 41 | + Body(diskpool). |
| 42 | + Do(ctxt). |
| 43 | + Into(&result) |
| 44 | + |
| 45 | + return &result, err |
| 46 | +} |
| 47 | + |
| 48 | +// Get takes the name of the Mayastor pool and returns the server's representation of it, and an error if one occurred. |
| 49 | +func (c *dspClient) Get(ctxt context.Context, name string, opts metav1.GetOptions) (*v1beta3.DiskPool, error) { |
| 50 | + result := v1beta3.DiskPool{} |
| 51 | + err := c.restClient. |
| 52 | + Get(). |
| 53 | + Namespace(common.NSMayastor()). |
| 54 | + Resource(e2e_config.GetConfig().Product.CrdPoolsResourceName). |
| 55 | + Name(name). |
| 56 | + VersionedParams(&opts, scheme.ParameterCodec). |
| 57 | + Do(ctxt). |
| 58 | + Into(&result) |
| 59 | + |
| 60 | + return &result, err |
| 61 | +} |
| 62 | + |
| 63 | +// List takes the label and field selectors, and returns a list matching Mayastor Pool, and an error if one occurred. |
| 64 | +func (c *dspClient) List(ctxt context.Context, opts metav1.ListOptions) (*v1beta3.DiskPoolList, error) { |
| 65 | + result := v1beta3.DiskPoolList{} |
| 66 | + err := c.restClient. |
| 67 | + Get(). |
| 68 | + Namespace(common.NSMayastor()). |
| 69 | + Resource(e2e_config.GetConfig().Product.CrdPoolsResourceName). |
| 70 | + VersionedParams(&opts, scheme.ParameterCodec). |
| 71 | + Do(ctxt). |
| 72 | + Into(&result) |
| 73 | + |
| 74 | + return &result, err |
| 75 | +} |
| 76 | + |
| 77 | +// Update takes the representation of a Mayastor pool and updates it. Returns the server's representation of the pool, and an error if one occurred. |
| 78 | +func (c *dspClient) Update(ctxt context.Context, diskpool *v1beta3.DiskPool, opts metav1.UpdateOptions) (*v1beta3.DiskPool, error) { |
| 79 | + result := v1beta3.DiskPool{} |
| 80 | + err := c.restClient. |
| 81 | + Put(). |
| 82 | + Namespace(common.NSMayastor()). |
| 83 | + Resource(e2e_config.GetConfig().Product.CrdPoolsResourceName). |
| 84 | + Name(diskpool.Name). |
| 85 | + VersionedParams(&opts, scheme.ParameterCodec). |
| 86 | + Body(diskpool). |
| 87 | + Do(ctxt). |
| 88 | + Into(&result) |
| 89 | + |
| 90 | + return &result, err |
| 91 | +} |
| 92 | + |
| 93 | +// Delete takes the name of the Mayastor pool and deletes it. Returns error if one occurred. |
| 94 | +func (c *dspClient) Delete(ctxt context.Context, name string, opts metav1.DeleteOptions) error { |
| 95 | + return c.restClient. |
| 96 | + Delete(). |
| 97 | + Namespace(common.NSMayastor()). |
| 98 | + Resource(e2e_config.GetConfig().Product.CrdPoolsResourceName). |
| 99 | + Name(name). |
| 100 | + Body(&opts). |
| 101 | + Do(ctxt). |
| 102 | + Error() |
| 103 | +} |
| 104 | + |
| 105 | +// Watch takes the label and field selectors, and returns a watch.Interface the watches matching Mayastor pools, and an error if one occurred. |
| 106 | +func (c *dspClient) Watch(ctxt context.Context, opts metav1.ListOptions) (watch.Interface, error) { |
| 107 | + var timeout time.Duration |
| 108 | + if opts.TimeoutSeconds != nil { |
| 109 | + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second |
| 110 | + } |
| 111 | + opts.Watch = true |
| 112 | + return c.restClient. |
| 113 | + Get(). |
| 114 | + Namespace(common.NSMayastor()). |
| 115 | + Resource(e2e_config.GetConfig().Product.CrdPoolsResourceName). |
| 116 | + VersionedParams(&opts, scheme.ParameterCodec). |
| 117 | + Timeout(timeout). |
| 118 | + Watch(ctxt) |
| 119 | +} |
0 commit comments