From ad5dd2b45d629ce274ced1c8a48eeeef94ce443b Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 2 Nov 2018 16:51:41 +0800 Subject: [PATCH 1/2] 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 89d9e3029..563603a69 100644 --- a/pkg/controller/snapshot_controller.go +++ b/pkg/controller/snapshot_controller.go @@ -380,7 +380,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 @@ -737,7 +737,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 { From 94855066cb9ef26b1036e004b156edf01472b7e1 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Wed, 21 Nov 2018 14:50:40 +0800 Subject: [PATCH 2/2] update cluster role for snapshot status --- deploy/kubernetes/rbac.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deploy/kubernetes/rbac.yaml b/deploy/kubernetes/rbac.yaml index 7bfdb81be..889844220 100644 --- a/deploy/kubernetes/rbac.yaml +++ b/deploy/kubernetes/rbac.yaml @@ -44,9 +44,12 @@ rules: - apiGroups: ["snapshot.storage.k8s.io"] resources: ["volumesnapshots"] verbs: ["get", "list", "watch", "update"] + - apiGroups: ["snapshot.storage.k8s.io"] + resources: ["volumesnapshots/status"] + verbs: ["update"] - apiGroups: ["apiextensions.k8s.io"] resources: ["customresourcedefinitions"] - verbs: ["create", "list", "watch", "delete"] + verbs: ["create", "list", "watch", "delete", "get", "update"] --- kind: ClusterRoleBinding