Skip to content

Commit

Permalink
fix(crds): update snapshot CRDs version to use v1 apis
Browse files Browse the repository at this point in the history
Signed-off-by: prateekpandey14 <[email protected]>
  • Loading branch information
prateekpandey14 authored and kmova committed Aug 21, 2021
1 parent 5028422 commit c0e37b3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- os: linux
arch: amd64
env:
- RELEASE_TAG_DOWNSTREAM=1
- RELEASE_TAG_DOWNSTREAM=0

before_install:
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
Expand Down
Binary file removed _output/bin/snapshot-controller
Binary file not shown.
Binary file removed _output/bin/snapshot-provisioner
Binary file not shown.
56 changes: 41 additions & 15 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import (

"github.com/golang/glog"
crdv1 "github.com/openebs/openebs-k8s-provisioner/pkg/apis/crd/v1"
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/rest"
utilpointer "k8s.io/utils/pointer"
)

const (
Expand Down Expand Up @@ -62,52 +63,77 @@ func NewClient(cfg *rest.Config) (*rest.RESTClient, *runtime.Scheme, error) {

// CreateCRD creates CustomResourceDefinition
func CreateCRD(clientset apiextensionsclient.Interface) error {
crd := &apiextensionsv1beta1.CustomResourceDefinition{
crd := &apiextensionsv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdv1.VolumeSnapshotDataResourcePlural + "." + crdv1.GroupName,
Annotations: map[string]string{
"api-approved.kubernetes.io": "https://github.com/kubernetes-csi/external-snapshotter/pull/419",
},
},
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
Group: crdv1.GroupName,
Version: crdv1.SchemeGroupVersion.Version,
Scope: apiextensionsv1beta1.ClusterScoped,
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Group: crdv1.GroupName,
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
{
Name: "v1",
Served: true,
Storage: true,
Schema: &apiextensionsv1.CustomResourceValidation{
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
XPreserveUnknownFields: utilpointer.BoolPtr(true),
},
},
},
},
Scope: apiextensionsv1.ClusterScoped,
Names: apiextensionsv1.CustomResourceDefinitionNames{
Plural: crdv1.VolumeSnapshotDataResourcePlural,
Kind: reflect.TypeOf(crdv1.VolumeSnapshotData{}).Name(),
},
},
}
res, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(context.TODO(), crd, metav1.CreateOptions{})
res, err := clientset.ApiextensionsV1().CustomResourceDefinitions().Create(context.TODO(), crd, metav1.CreateOptions{})

if err != nil && !apierrors.IsAlreadyExists(err) {
glog.Fatalf("failed to create VolumeSnapshotDataResource: %#v, err: %#v",
res, err)
}

crd = &apiextensionsv1beta1.CustomResourceDefinition{
crd = &apiextensionsv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdv1.VolumeSnapshotResourcePlural + "." + crdv1.GroupName,
Annotations: map[string]string{
"api-approved.kubernetes.io": "https://github.com/kubernetes-csi/external-snapshotter/pull/419",
},
},
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
Group: crdv1.GroupName,
Version: crdv1.SchemeGroupVersion.Version,
Scope: apiextensionsv1beta1.NamespaceScoped,
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Group: crdv1.GroupName,
// Versions: crdv1.SchemeGroupVersion.Version,
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
{
Name: "v1",
Served: true,
Storage: true,
Schema: &apiextensionsv1.CustomResourceValidation{
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
XPreserveUnknownFields: utilpointer.BoolPtr(true),
},
},
},
},
Scope: apiextensionsv1.NamespaceScoped,
Names: apiextensionsv1.CustomResourceDefinitionNames{
Plural: crdv1.VolumeSnapshotResourcePlural,
Kind: reflect.TypeOf(crdv1.VolumeSnapshot{}).Name(),
},
},
}
res, err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(context.TODO(), crd, metav1.CreateOptions{})
res, err = clientset.ApiextensionsV1().CustomResourceDefinitions().Create(context.TODO(), crd, metav1.CreateOptions{})
if err != nil && !apierrors.IsAlreadyExists(err) {
glog.Fatalf("failed to create VolumeSnapshotResource: %#v, err: %#v",
res, err)
}

glog.Infof("successfully created VolumeSnapshotResource")
return nil
}

Expand Down

0 comments on commit c0e37b3

Please sign in to comment.