From ad5dd2b45d629ce274ced1c8a48eeeef94ce443b Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 2 Nov 2018 16:51:41 +0800 Subject: [PATCH 1/7] 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/7] 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 From dd61cbe22198adc7083aaa516de293e09ba63437 Mon Sep 17 00:00:00 2001 From: zhucan Date: Wed, 8 May 2019 11:36:18 +0800 Subject: [PATCH 3/7] restart external-snapshotter failed --- cmd/csi-snapshotter/create_crd.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/cmd/csi-snapshotter/create_crd.go b/cmd/csi-snapshotter/create_crd.go index 29c3a79d0..bb21679f6 100644 --- a/cmd/csi-snapshotter/create_crd.go +++ b/cmd/csi-snapshotter/create_crd.go @@ -44,18 +44,11 @@ func CreateCRD(clientset apiextensionsclient.Interface) error { }, } - _, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Get(crd.Name, metav1.GetOptions{}) - if err == nil { - if res, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Update(crd); err != nil { - klog.Fatalf("failed to update VolumeSnapshotResource: %#v, err: %#v", - res, err) - } - } else { - res, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) - if err != nil && !apierrors.IsAlreadyExists(err) { - klog.Fatalf("failed to create VolumeSnapshotResource: %#v, err: %#v", - res, err) - } + res, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) + + if err != nil && !apierrors.IsAlreadyExists(err) { + klog.Fatalf("failed to create VolumeSnapshotResource: %#v, err: %#v", + res, err) } crd = &apiextensionsv1beta1.CustomResourceDefinition{ @@ -72,7 +65,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) { klog.Fatalf("failed to create VolumeSnapshotContentResource: %#v, err: %#v", From 95fc4bc56f651decfe05afc83c7ade12ec4e9bb8 Mon Sep 17 00:00:00 2001 From: zhucan Date: Tue, 14 May 2019 18:18:59 +0800 Subject: [PATCH 4/7] update snapshot yaml --- examples/kubernetes/snapshot.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/kubernetes/snapshot.yaml b/examples/kubernetes/snapshot.yaml index b7a913f9c..602021f11 100644 --- a/examples/kubernetes/snapshot.yaml +++ b/examples/kubernetes/snapshot.yaml @@ -7,3 +7,5 @@ spec: source: name: hpvc kind: PersistentVolumeClaim + subresources: + status: {} From 4f8220979c5d11e70d455185a775bcfefa12b931 Mon Sep 17 00:00:00 2001 From: zhucan Date: Tue, 14 May 2019 18:41:19 +0800 Subject: [PATCH 5/7] run 'make -k all test' failed --- pkg/controller/snapshot_controller.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/controller/snapshot_controller.go b/pkg/controller/snapshot_controller.go index fa65366e2..5333c63f4 100644 --- a/pkg/controller/snapshot_controller.go +++ b/pkg/controller/snapshot_controller.go @@ -423,7 +423,7 @@ func (ctrl *csiSnapshotController) updateSnapshotErrorStatusWithEvent(snapshot * } snapshotClone.Status.Error = statusError snapshotClone.Status.ReadyToUse = false - newSnapshot, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshots(snapshotClone.Namespace).UpdateStatus(snapshotClone) + newSnapshot, err := ctrl.clientset.SnapshotV1alpha1().VolumeSnapshots(snapshotClone.Namespace).UpdateStatus(snapshotClone) if err != nil { klog.V(4).Infof("updating VolumeSnapshot[%s] error status failed %v", snapshotKey(snapshot), err) @@ -848,7 +848,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).UpdateStatus(snapshotClone) + newSnapshotObj, err := ctrl.clientset.SnapshotV1alpha1().VolumeSnapshots(snapshotClone.Namespace).UpdateStatus(snapshotClone) if err != nil { return nil, newControllerUpdateError(snapshotKey(snapshot), err.Error()) } From 2db3a1e8708ef53aa8154f719e3642c83f289395 Mon Sep 17 00:00:00 2001 From: zhucan Date: Fri, 17 May 2019 17:20:39 +0800 Subject: [PATCH 6/7] use 'UpdateStatus' failed --- cmd/csi-snapshotter/create_crd.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/csi-snapshotter/create_crd.go b/cmd/csi-snapshotter/create_crd.go index bb21679f6..0460f691f 100644 --- a/cmd/csi-snapshotter/create_crd.go +++ b/cmd/csi-snapshotter/create_crd.go @@ -84,6 +84,9 @@ func CreateCRD(clientset apiextensionsclient.Interface) error { Plural: crdv1.VolumeSnapshotResourcePlural, Kind: reflect.TypeOf(crdv1.VolumeSnapshot{}).Name(), }, + Subresources: &apiextensionsv1beta1.CustomResourceSubresources{ + Status: &apiextensionsv1beta1.CustomResourceSubresourceStatus{}, + }, }, } res, err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) From a23be2d944ed404d5b4b00042b86c7f6c5937fba Mon Sep 17 00:00:00 2001 From: zhucan Date: Fri, 31 May 2019 23:37:28 +0800 Subject: [PATCH 7/7] clean useless key 'subresources' in snapshot yaml --- examples/kubernetes/snapshot.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/kubernetes/snapshot.yaml b/examples/kubernetes/snapshot.yaml index 602021f11..b7a913f9c 100644 --- a/examples/kubernetes/snapshot.yaml +++ b/examples/kubernetes/snapshot.yaml @@ -7,5 +7,3 @@ spec: source: name: hpvc kind: PersistentVolumeClaim - subresources: - status: {}