From 4dca7aea3834b91cd4fc430d600fc16951241b98 Mon Sep 17 00:00:00 2001 From: zhucan Date: Tue, 23 Jul 2019 14:33:45 +0800 Subject: [PATCH] bugfix-147 cannot update snapshot metadata --- cmd/csi-snapshotter/create_crd.go | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/cmd/csi-snapshotter/create_crd.go b/cmd/csi-snapshotter/create_crd.go index 0460f691f..295e778c4 100644 --- a/cmd/csi-snapshotter/create_crd.go +++ b/cmd/csi-snapshotter/create_crd.go @@ -44,6 +44,21 @@ func CreateCRD(clientset apiextensionsclient.Interface) error { }, } + rep, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Get(crd.Name, metav1.GetOptions{}) + if err != nil { + if !apierrors.IsNotFound(err) { + klog.Fatalf("failed to get VolumeSnapshotResource: %#v, err: %#v", + rep, err) + } else { + klog.Infof("can not find VolumeSnapshotResource: %s, err: %#v", crd.Name, err) + } + } else { + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete(crd.Name, &metav1.DeleteOptions{}) + if err != nil && !apierrors.IsNotFound(err) { + klog.Fatalf("failed to delete VolumeSnapshotResource: %s, err: %#v", + crd.Name, err) + } + } res, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) if err != nil && !apierrors.IsAlreadyExists(err) { @@ -65,6 +80,22 @@ func CreateCRD(clientset apiextensionsclient.Interface) error { }, }, } + + rep, err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Get(crd.Name, metav1.GetOptions{}) + if err != nil { + if !apierrors.IsNotFound(err) { + klog.Fatalf("failed to get VolumeSnapshotResource: %#v, err: %#v", + rep, err) + } else { + klog.Infof("can not find VolumeSnapshotResource: %s, err: %#v", crd.Name, err) + } + } else { + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete(crd.Name, &metav1.DeleteOptions{}) + if err != nil && !apierrors.IsNotFound(err) { + klog.Fatalf("failed to delete VolumeSnapshotResource: %s, err: %#v", + crd.Name, err) + } + } res, err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) if err != nil && !apierrors.IsAlreadyExists(err) { @@ -89,6 +120,22 @@ func CreateCRD(clientset apiextensionsclient.Interface) error { }, }, } + + rep, err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Get(crd.Name, metav1.GetOptions{}) + if err != nil { + if !apierrors.IsNotFound(err) { + klog.Fatalf("failed to get VolumeSnapshotResource: %#v, err: %#v", + rep, err) + } else { + klog.Infof("can not find VolumeSnapshotResource: %s, err: %#v", crd.Name, err) + } + } else { + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete(crd.Name, &metav1.DeleteOptions{}) + if err != nil && !apierrors.IsNotFound(err) { + klog.Fatalf("failed to delete VolumeSnapshotResource: %s, err: %#v", + crd.Name, err) + } + } res, err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) if err != nil && !apierrors.IsAlreadyExists(err) {