Skip to content

Commit 2b3104d

Browse files
authored
Merge pull request #127 from openebs/v1beta3-dsp-crd
feat(v1beta3): add support for latest v1beta3 dsp crd version
2 parents 2f3208d + 653445d commit 2b3104d

File tree

7 files changed

+512
-1
lines changed

7 files changed

+512
-1
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package v1beta3
2+
3+
import (
4+
runtime "k8s.io/apimachinery/pkg/runtime"
5+
)
6+
7+
func (in *DiskPool) DeepCopyInto(out *DiskPool) {
8+
*out = *in
9+
out.TypeMeta = in.TypeMeta
10+
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
11+
out.Spec = in.Spec
12+
}
13+
14+
func (in *DiskPool) DeepCopy() *DiskPool {
15+
if in == nil {
16+
return nil
17+
}
18+
out := new(DiskPool)
19+
in.DeepCopyInto(out)
20+
return out
21+
}
22+
23+
func (in *DiskPool) DeepCopyObject() runtime.Object {
24+
if c := in.DeepCopy(); c != nil {
25+
return c
26+
}
27+
return nil
28+
}
29+
30+
func (in *DiskPoolList) DeepCopyInto(out *DiskPoolList) {
31+
*out = *in
32+
out.TypeMeta = in.TypeMeta
33+
in.ListMeta.DeepCopyInto(&out.ListMeta)
34+
if in.Items != nil {
35+
in, out := &in.Items, &out.Items
36+
*out = make([]DiskPool, len(*in))
37+
for i := range *in {
38+
(*in)[i].DeepCopyInto(&(*out)[i])
39+
}
40+
}
41+
}
42+
43+
func (in *DiskPoolList) DeepCopy() *DiskPoolList {
44+
if in == nil {
45+
return nil
46+
}
47+
out := new(DiskPoolList)
48+
in.DeepCopyInto(out)
49+
return out
50+
}
51+
52+
func (in *DiskPoolList) DeepCopyObject() runtime.Object {
53+
if c := in.DeepCopy(); c != nil {
54+
return c
55+
}
56+
return nil
57+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package v1beta3
2+
3+
import metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4+
5+
type Topology struct {
6+
Labelled map[string]string `json:"labelled,omitempty"`
7+
}
8+
9+
type DiskPoolSpec struct {
10+
Disks []string `json:"disks"`
11+
Node string `json:"node"`
12+
Topology *Topology `json:"topology,omitempty"`
13+
}
14+
15+
type DiskPoolStatus struct {
16+
Available uint64 `json:"available"`
17+
Capacity uint64 `json:"capacity"`
18+
Used uint64 `json:"used"`
19+
CRStatus string `json:"cr_state"`
20+
PoolStatus string `json:"pool_status"`
21+
}
22+
23+
type DiskPool struct {
24+
metaV1.TypeMeta `json:",inline"`
25+
metaV1.ObjectMeta `json:"metadata,omitempty"`
26+
27+
Spec DiskPoolSpec `json:"spec"`
28+
Status DiskPoolStatus `json:"status"`
29+
}
30+
31+
type DiskPoolList struct {
32+
metaV1.TypeMeta `json:",inline"`
33+
metaV1.ListMeta `json:"metadata,omitempty"`
34+
35+
Items []DiskPool `json:"items"`
36+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package v1beta3
2+
3+
import (
4+
"github.com/openebs/openebs-e2e/common/e2e_config"
5+
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6+
"k8s.io/apimachinery/pkg/runtime"
7+
"k8s.io/apimachinery/pkg/runtime/schema"
8+
)
9+
10+
var (
11+
PoolSchemeBuilder = runtime.NewSchemeBuilder(poolAddKnownTypes)
12+
PoolAddToScheme = PoolSchemeBuilder.AddToScheme
13+
)
14+
15+
func poolAddKnownTypes(scheme *runtime.Scheme) error {
16+
var PoolSchemeGroupVersion = schema.GroupVersion{Group: e2e_config.GetConfig().Product.CrdGroupName,
17+
Version: "v1beta3"}
18+
19+
scheme.AddKnownTypes(PoolSchemeGroupVersion,
20+
&DiskPool{},
21+
&DiskPoolList{},
22+
)
23+
24+
metaV1.AddToGroupVersion(scheme, PoolSchemeGroupVersion)
25+
return nil
26+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package v1beta3
2+
3+
import (
4+
"github.com/openebs/openebs-e2e/common/e2e_config"
5+
"k8s.io/apimachinery/pkg/runtime/schema"
6+
"k8s.io/client-go/kubernetes/scheme"
7+
"k8s.io/client-go/rest"
8+
)
9+
10+
// Pool APIx
11+
12+
type DiskPoolV1Beta3Interface interface {
13+
DiskPools() DiskPoolInterface
14+
}
15+
16+
type DiskPoolV1Beta3Client struct {
17+
restClient rest.Interface
18+
}
19+
20+
func DspNewForConfig(c *rest.Config) (*DiskPoolV1Beta3Client, error) {
21+
config := *c
22+
config.ContentConfig.GroupVersion = &schema.GroupVersion{Group: e2e_config.GetConfig().Product.CrdGroupName,
23+
Version: "v1beta3"}
24+
config.APIPath = "/apis"
25+
config.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
26+
config.UserAgent = rest.DefaultKubernetesUserAgent()
27+
28+
client, err := rest.RESTClientFor(&config)
29+
if err != nil {
30+
return nil, err
31+
}
32+
33+
return &DiskPoolV1Beta3Client{restClient: client}, nil
34+
}
35+
36+
func (c *DiskPoolV1Beta3Client) DiskPools() DiskPoolInterface {
37+
return &dspClient{
38+
restClient: c.restClient,
39+
}
40+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
}

common/custom_resources/util.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ func initialise() {
126126
version extCRDVersion
127127
fnInitialise func(*rest.Config, bool) (crtypes.DiskPoolFunctions, error)
128128
}{
129+
{
130+
description: "v1beta3",
131+
version: extCRDVersion{
132+
"v1beta3", false, "v1beta3",
133+
},
134+
fnInitialise: v1beta2Ifc.Initialise,
135+
},
129136
{
130137
description: "v1beta2",
131138
version: extCRDVersion{
@@ -169,7 +176,7 @@ func initialise() {
169176
)
170177
}
171178

172-
var crdVersionOrder = []string{"v1beta2", "v1beta1", "v1alpha1Ext", "v1alpha1"}
179+
var crdVersionOrder = []string{"v1beta3", "v1beta2", "v1beta1", "v1alpha1Ext", "v1alpha1"}
173180

174181
func getDspFuncs() crtypes.DiskPoolFunctions {
175182
if selectedDspFuncs != nil {

0 commit comments

Comments
 (0)