Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot update snapshot metadata #149

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions cmd/csi-snapshotter/create_crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must not use delete crd method, when we delete the crd, all the CR will also be deleted. we should compare the crd spec and update the crd if the spec changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, if the spec not changes, no need to delete the crd

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @wackxu for your comments!
Hi @zhucan Can you try @wackxu's suggestion? Check if the spec has changed first, and then use the Update method, not the Delete, to update the CRD.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not install crd with the snapshotter and instead make it admin operation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wackxu @xing-yang Thanks, it's a good suggestion

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msau42 What you mean is to put 'install crd' step in admin operation, for example, create from yaml instead of install crd from snapshotter?

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) {
Expand All @@ -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) {
Expand Down