From 656a6e9b1eae8a8b132ba22839b02ba3052ea0bd Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 2 Nov 2018 16:51:41 +0800 Subject: [PATCH] add status Subresources for volumeSnapshot --- cmd/csi-snapshotter/create_crd.go | 21 ++++++++++++++++----- pkg/controller/snapshot_controller.go | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cmd/csi-snapshotter/create_crd.go b/cmd/csi-snapshotter/create_crd.go index 99f9cf57f..2720df9ac 100644 --- a/cmd/csi-snapshotter/create_crd.go +++ b/cmd/csi-snapshotter/create_crd.go @@ -38,13 +38,24 @@ func CreateCRD(clientset apiextensionsclient.Interface) error { Plural: crdv1.VolumeSnapshotClassResourcePlural, Kind: reflect.TypeOf(crdv1.VolumeSnapshotClass{}).Name(), }, + Subresources: &apiextensionsv1beta1.CustomResourceSubresources{ + Status: &apiextensionsv1beta1.CustomResourceSubresourceStatus{}, + }, }, } - res, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) - if err != nil && !apierrors.IsAlreadyExists(err) { - glog.Fatalf("failed to create VolumeSnapshotResource: %#v, err: %#v", - res, err) + _, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Get(crd.Name, metav1.GetOptions{}) + if err == nil { + if res, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Update(crd); err != nil { + glog.Fatalf("failed to update VolumeSnapshotResource: %#v, err: %#v", + res, err) + } + } else { + res, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) + if err != nil && !apierrors.IsAlreadyExists(err) { + glog.Fatalf("failed to create VolumeSnapshotResource: %#v, err: %#v", + res, err) + } } crd = &apiextensionsv1beta1.CustomResourceDefinition{ @@ -61,7 +72,7 @@ func CreateCRD(clientset apiextensionsclient.Interface) error { }, }, } - res, err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) + res, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) if err != nil && !apierrors.IsAlreadyExists(err) { glog.Fatalf("failed to create VolumeSnapshotContentResource: %#v, err: %#v", diff --git a/pkg/controller/snapshot_controller.go b/pkg/controller/snapshot_controller.go index 8aac0e320..f9d69cfa6 100644 --- a/pkg/controller/snapshot_controller.go +++ b/pkg/controller/snapshot_controller.go @@ -366,7 +366,7 @@ func (ctrl *csiSnapshotController) updateSnapshotErrorStatusWithEvent(snapshot * snapshotClone.Status.Error = statusError snapshotClone.Status.Ready = false - newSnapshot, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshots(snapshotClone.Namespace).Update(snapshotClone) + newSnapshot, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshots(snapshotClone.Namespace).UpdateStatus(snapshotClone) if err != nil { glog.V(4).Infof("updating VolumeSnapshot[%s] error status failed %v", snapshotKey(snapshot), err) return err @@ -709,7 +709,7 @@ func (ctrl *csiSnapshotController) updateSnapshotStatus(snapshot *crdv1.VolumeSn status.RestoreSize = resource.NewQuantity(size, resource.BinarySI) } snapshotClone.Status = status - newSnapshotObj, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshots(snapshotClone.Namespace).Update(snapshotClone) + newSnapshotObj, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshots(snapshotClone.Namespace).UpdateStatus(snapshotClone) if err != nil { return nil, newControllerUpdateError(snapshotKey(snapshot), err.Error()) } else {