From 76c098ad37910ad25a3dcddea900a26aad0b22b1 Mon Sep 17 00:00:00 2001 From: Leonardo Cecchi Date: Wed, 10 Apr 2024 23:09:29 +0200 Subject: [PATCH 1/6] API change to improve VolumeGroupSnapshot restore Change `VolumeSnapshotRefList` in `VolumeGroupSnapshotStatus` to `PVCVolumeSnapshotRefList`, allowing users to map a `VolumeSnapshot` to a specific `PersistentVolumeClaim`. Change `VolumeSnapshotContentRefList` in `VolumeGroupSnapshotContentStatus` to `PVVolumeSnapshotContentRefList`, allowing users to map a `VolumeSnapshotContent` to a specific `PersistentVolume`. This two changes allow users to map each `VolumeSnapshot` back to the original PVC it was taken from. --- .../volumegroupsnapshot/v1alpha1/types.go | 31 +++- .../v1alpha1/zz_generated.deepcopy.go | 47 +++++- ...ge.k8s.io_volumegroupsnapshotcontents.yaml | 86 +++------- ...t.storage.k8s.io_volumegroupsnapshots.yaml | 156 ++++++++++-------- .../volumegroupsnapshot/v1alpha1/types.go | 31 +++- .../v1alpha1/zz_generated.deepcopy.go | 47 +++++- 6 files changed, 238 insertions(+), 160 deletions(-) diff --git a/client/apis/volumegroupsnapshot/v1alpha1/types.go b/client/apis/volumegroupsnapshot/v1alpha1/types.go index b8de64948..5aa14d272 100644 --- a/client/apis/volumegroupsnapshot/v1alpha1/types.go +++ b/client/apis/volumegroupsnapshot/v1alpha1/types.go @@ -103,11 +103,20 @@ type VolumeGroupSnapshotStatus struct { // +optional Error *snapshotv1.VolumeSnapshotError `json:"error,omitempty" protobuf:"bytes,4,opt,name=error,casttype=VolumeSnapshotError"` - // VolumeSnapshotRefList is the list of volume snapshot references for this - // group snapshot. + // VolumeSnapshotRefList is the list of PVC and VolumeSnapshot pair that + // is part of this group snapshot. // The maximum number of allowed snapshots in the group is 100. // +optional - VolumeSnapshotRefList []core_v1.ObjectReference `json:"volumeSnapshotRefList,omitempty" protobuf:"bytes,5,opt,name=volumeSnapshotRefList"` + PVCVolumeSnapshotRefList []PVCVolumeSnapshotPair `json:"pvcVolumeSnapshotRefList,omitempty" protobuf:"bytes,6,opt,name=pvcVolumeSnapshotRefList"` +} + +// PVCVolumeSnapshotPair defines a pair of a PVC reference and a Volume Snapshot +type PVCVolumeSnapshotPair struct { + // PersistentVolumeClaimRef is a reference to the PVC this pair is referring to + PersistentVolumeClaimRef core_v1.ObjectReference `json:"persistentVolumeClaimRef,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeClaimRef"` + + // VolumeSnapshotRef is a reference to the VolumeSnapshot this pair is referring to + VolumeSnapshotRef core_v1.ObjectReference `json:"volumeSnapshotRef,omitempty" protobuf:"bytes,1,opt,name=volumeSnapshotRef"` } //+genclient @@ -337,11 +346,21 @@ type VolumeGroupSnapshotContentStatus struct { // +optional Error *snapshotv1.VolumeSnapshotError `json:"error,omitempty" protobuf:"bytes,4,opt,name=error,casttype=VolumeSnapshotError"` - // VolumeSnapshotContentRefList is the list of volume snapshot content references - // for this group snapshot. + // PVVolumeSnapshotContentRefList is the list of pairs of PV and + // VolumeSnapshotCOntent for this group snapshot // The maximum number of allowed snapshots in the group is 100. // +optional - VolumeSnapshotContentRefList []core_v1.ObjectReference `json:"volumeSnapshotContentRefList,omitempty" protobuf:"bytes,5,opt,name=volumeSnapshotContentRefList"` + PVVolumeSnapshotContentRefList []PVVolumeSnapshotContentPair `json:"pvVolumeSnapshotContentRefList,omitempty" protobuf:"bytes,6,opt,name=pvVolumeSnapshotContentRefList"` +} + +// PVVolumeSnapshotContentPair represent a pair of PV names and +// VolumeSnapshotContent names +type PVVolumeSnapshotContentPair struct { + // PersistentVolumeName is the name of the persistent volume + PersistentVolumeName string `json:"persistentVolumeName,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeName"` + + // VolumeSnapshotContentName is the name of the volume snapshot content resource + VolumeSnapshotContentName string `json:"volumeSnapshotContentName,omitempty" protobuf:"bytes,1,opt,name=volumeSnapshotContentName"` } // VolumeGroupSnapshotContentSource represents the CSI source of a group snapshot. diff --git a/client/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go b/client/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go index 820cbb91a..47277fd40 100644 --- a/client/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go +++ b/client/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go @@ -23,7 +23,6 @@ package v1alpha1 import ( v1 "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -49,6 +48,40 @@ func (in *GroupSnapshotHandles) DeepCopy() *GroupSnapshotHandles { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PVCVolumeSnapshotPair) DeepCopyInto(out *PVCVolumeSnapshotPair) { + *out = *in + out.PersistentVolumeClaimRef = in.PersistentVolumeClaimRef + out.VolumeSnapshotRef = in.VolumeSnapshotRef + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PVCVolumeSnapshotPair. +func (in *PVCVolumeSnapshotPair) DeepCopy() *PVCVolumeSnapshotPair { + if in == nil { + return nil + } + out := new(PVCVolumeSnapshotPair) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PVVolumeSnapshotContentPair) DeepCopyInto(out *PVVolumeSnapshotContentPair) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PVVolumeSnapshotContentPair. +func (in *PVVolumeSnapshotContentPair) DeepCopy() *PVVolumeSnapshotContentPair { + if in == nil { + return nil + } + out := new(PVVolumeSnapshotContentPair) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VolumeGroupSnapshot) DeepCopyInto(out *VolumeGroupSnapshot) { *out = *in @@ -284,9 +317,9 @@ func (in *VolumeGroupSnapshotContentStatus) DeepCopyInto(out *VolumeGroupSnapsho *out = new(v1.VolumeSnapshotError) (*in).DeepCopyInto(*out) } - if in.VolumeSnapshotContentRefList != nil { - in, out := &in.VolumeSnapshotContentRefList, &out.VolumeSnapshotContentRefList - *out = make([]corev1.ObjectReference, len(*in)) + if in.PVVolumeSnapshotContentRefList != nil { + in, out := &in.PVVolumeSnapshotContentRefList, &out.PVVolumeSnapshotContentRefList + *out = make([]PVVolumeSnapshotContentPair, len(*in)) copy(*out, *in) } return @@ -405,9 +438,9 @@ func (in *VolumeGroupSnapshotStatus) DeepCopyInto(out *VolumeGroupSnapshotStatus *out = new(v1.VolumeSnapshotError) (*in).DeepCopyInto(*out) } - if in.VolumeSnapshotRefList != nil { - in, out := &in.VolumeSnapshotRefList, &out.VolumeSnapshotRefList - *out = make([]corev1.ObjectReference, len(*in)) + if in.PVCVolumeSnapshotRefList != nil { + in, out := &in.PVCVolumeSnapshotRefList, &out.PVCVolumeSnapshotRefList + *out = make([]PVCVolumeSnapshotPair, len(*in)) copy(*out, *in) } return diff --git a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml index c150705a0..ca154b704 100644 --- a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml +++ b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - api-approved.kubernetes.io: "https://github.com/kubernetes-csi/external-snapshotter/pull/971" + api-approved.kubernetes.io: "https://github.com/kubernetes-csi/external-snapshotter/pull/1068" controller-gen.kubebuilder.io/version: v0.12.0 creationTimestamp: null name: volumegroupsnapshotcontents.groupsnapshot.storage.k8s.io @@ -227,6 +227,24 @@ spec: format: date-time type: string type: object + pvVolumeSnapshotContentRefList: + description: PVVolumeSnapshotContentRefList is the list of pairs of + PV and VolumeSnapshotCOntent for this group snapshot The maximum + number of allowed snapshots in the group is 100. + items: + description: PVVolumeSnapshotContentPair represent a pair of PV + names and VolumeSnapshotContent names + properties: + persistentVolumeName: + description: PersistentVolumeName is the name of the persistent + volume + type: string + volumeSnapshotContentName: + description: VolumeSnapshotContentName is the name of the volume + snapshot content resource + type: string + type: object + type: array readyToUse: description: ReadyToUse indicates if all the individual snapshots in the group are ready to be used to restore a group of volumes. @@ -239,72 +257,6 @@ spec: system. If a storage system does not provide such an id, the CSI driver can choose to return the VolumeGroupSnapshot name. type: string - volumeSnapshotContentRefList: - description: VolumeSnapshotContentRefList is the list of volume snapshot - content references for this group snapshot. The maximum number of - allowed snapshots in the group is 100. - items: - description: "ObjectReference contains enough information to let - you inspect or modify the referred object. --- New uses of this - type are discouraged because of difficulty describing its usage - when embedded in APIs. 1. Ignored fields. It includes many fields - which are not generally honored. For instance, ResourceVersion - and FieldPath are both very rarely valid in actual usage. 2. Invalid - usage help. It is impossible to add specific help for individual - usage. In most embedded usages, there are particular restrictions - like, \"must refer only to types A and B\" or \"UID not honored\" - or \"name must be restricted\". Those cannot be well described - when embedded. 3. Inconsistent validation. Because the usages - are different, the validation rules are different by usage, which - makes it hard for users to predict what will happen. 4. The fields - are both imprecise and overly precise. Kind is not a precise - mapping to a URL. This can produce ambiguity during interpretation - and require a REST mapping. In most cases, the dependency is - on the group,resource tuple and the version of the actual struct - is irrelevant. 5. We cannot easily change it. Because this type - is embedded in many locations, updates to this type will affect - numerous schemas. Don't make new APIs embed an underspecified - API type they do not control. \n Instead of using this type, create - a locally provided and used type that is well-focused on your - reference. For example, ServiceReferences for admission registration: - https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 - ." - properties: - apiVersion: - description: API version of the referent. - type: string - fieldPath: - description: 'If referring to a piece of an object instead of - an entire object, this string should contain a valid JSON/Go - field access statement, such as desiredState.manifest.containers[2]. - For example, if the object reference is to a container within - a pod, this would take on a value like: "spec.containers{name}" - (where "name" refers to the name of the container that triggered - the event) or if no container name is specified "spec.containers[2]" - (container with index 2 in this pod). This syntax is chosen - only to have some well-defined way of referencing a part of - an object. TODO: this design is not final and this field is - subject to change in the future.' - type: string - kind: - description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' - type: string - namespace: - description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/' - type: string - resourceVersion: - description: 'Specific resourceVersion to which this reference - is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency' - type: string - uid: - description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids' - type: string - type: object - x-kubernetes-map-type: atomic - type: array type: object required: - spec diff --git a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml index b8bf6366e..cb62d1685 100644 --- a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml +++ b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - api-approved.kubernetes.io: "https://github.com/kubernetes-csi/external-snapshotter/pull/995" + api-approved.kubernetes.io: "https://github.com/kubernetes-csi/external-snapshotter/pull/1068" controller-gen.kubebuilder.io/version: v0.12.0 creationTimestamp: null name: volumegroupsnapshots.groupsnapshot.storage.k8s.io @@ -183,6 +183,94 @@ spec: format: date-time type: string type: object + pvcVolumeSnapshotRefList: + description: VolumeSnapshotRefList is the list of PVC and VolumeSnapshot + pair that is part of this group snapshot. The maximum number of + allowed snapshots in the group is 100. + items: + description: PVCVolumeSnapshotPair defines a pair of a PVC reference + and a Volume Snapshot + properties: + persistentVolumeClaimRef: + description: PersistentVolumeClaimRef is a reference to the + PVC this pair is referring to + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: 'If referring to a piece of an object instead + of an entire object, this string should contain a valid + JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container + within a pod, this would take on a value like: "spec.containers{name}" + (where "name" refers to the name of the container that + triggered the event) or if no container name is specified + "spec.containers[2]" (container with index 2 in this pod). + This syntax is chosen only to have some well-defined way + of referencing a part of an object. TODO: this design + is not final and this field is subject to change in the + future.' + type: string + kind: + description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' + type: string + namespace: + description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/' + type: string + resourceVersion: + description: 'Specific resourceVersion to which this reference + is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency' + type: string + uid: + description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids' + type: string + type: object + x-kubernetes-map-type: atomic + volumeSnapshotRef: + description: VolumeSnapshotRef is a reference to the VolumeSnapshot + this pair is referring to + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: 'If referring to a piece of an object instead + of an entire object, this string should contain a valid + JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container + within a pod, this would take on a value like: "spec.containers{name}" + (where "name" refers to the name of the container that + triggered the event) or if no container name is specified + "spec.containers[2]" (container with index 2 in this pod). + This syntax is chosen only to have some well-defined way + of referencing a part of an object. TODO: this design + is not final and this field is subject to change in the + future.' + type: string + kind: + description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' + type: string + namespace: + description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/' + type: string + resourceVersion: + description: 'Specific resourceVersion to which this reference + is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency' + type: string + uid: + description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids' + type: string + type: object + x-kubernetes-map-type: atomic + type: object + type: array readyToUse: description: ReadyToUse indicates if all the individual snapshots in the group are ready to be used to restore a group of volumes. @@ -190,72 +278,6 @@ spec: become true. If not specified, it means the readiness of a group snapshot is unknown. type: boolean - volumeSnapshotRefList: - description: VolumeSnapshotRefList is the list of volume snapshot - references for this group snapshot. The maximum number of allowed - snapshots in the group is 100. - items: - description: "ObjectReference contains enough information to let - you inspect or modify the referred object. --- New uses of this - type are discouraged because of difficulty describing its usage - when embedded in APIs. 1. Ignored fields. It includes many fields - which are not generally honored. For instance, ResourceVersion - and FieldPath are both very rarely valid in actual usage. 2. Invalid - usage help. It is impossible to add specific help for individual - usage. In most embedded usages, there are particular restrictions - like, \"must refer only to types A and B\" or \"UID not honored\" - or \"name must be restricted\". Those cannot be well described - when embedded. 3. Inconsistent validation. Because the usages - are different, the validation rules are different by usage, which - makes it hard for users to predict what will happen. 4. The fields - are both imprecise and overly precise. Kind is not a precise - mapping to a URL. This can produce ambiguity during interpretation - and require a REST mapping. In most cases, the dependency is - on the group,resource tuple and the version of the actual struct - is irrelevant. 5. We cannot easily change it. Because this type - is embedded in many locations, updates to this type will affect - numerous schemas. Don't make new APIs embed an underspecified - API type they do not control. \n Instead of using this type, create - a locally provided and used type that is well-focused on your - reference. For example, ServiceReferences for admission registration: - https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 - ." - properties: - apiVersion: - description: API version of the referent. - type: string - fieldPath: - description: 'If referring to a piece of an object instead of - an entire object, this string should contain a valid JSON/Go - field access statement, such as desiredState.manifest.containers[2]. - For example, if the object reference is to a container within - a pod, this would take on a value like: "spec.containers{name}" - (where "name" refers to the name of the container that triggered - the event) or if no container name is specified "spec.containers[2]" - (container with index 2 in this pod). This syntax is chosen - only to have some well-defined way of referencing a part of - an object. TODO: this design is not final and this field is - subject to change in the future.' - type: string - kind: - description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' - type: string - namespace: - description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/' - type: string - resourceVersion: - description: 'Specific resourceVersion to which this reference - is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency' - type: string - uid: - description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids' - type: string - type: object - x-kubernetes-map-type: atomic - type: array type: object required: - spec diff --git a/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go b/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go index b8de64948..5aa14d272 100644 --- a/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go +++ b/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go @@ -103,11 +103,20 @@ type VolumeGroupSnapshotStatus struct { // +optional Error *snapshotv1.VolumeSnapshotError `json:"error,omitempty" protobuf:"bytes,4,opt,name=error,casttype=VolumeSnapshotError"` - // VolumeSnapshotRefList is the list of volume snapshot references for this - // group snapshot. + // VolumeSnapshotRefList is the list of PVC and VolumeSnapshot pair that + // is part of this group snapshot. // The maximum number of allowed snapshots in the group is 100. // +optional - VolumeSnapshotRefList []core_v1.ObjectReference `json:"volumeSnapshotRefList,omitempty" protobuf:"bytes,5,opt,name=volumeSnapshotRefList"` + PVCVolumeSnapshotRefList []PVCVolumeSnapshotPair `json:"pvcVolumeSnapshotRefList,omitempty" protobuf:"bytes,6,opt,name=pvcVolumeSnapshotRefList"` +} + +// PVCVolumeSnapshotPair defines a pair of a PVC reference and a Volume Snapshot +type PVCVolumeSnapshotPair struct { + // PersistentVolumeClaimRef is a reference to the PVC this pair is referring to + PersistentVolumeClaimRef core_v1.ObjectReference `json:"persistentVolumeClaimRef,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeClaimRef"` + + // VolumeSnapshotRef is a reference to the VolumeSnapshot this pair is referring to + VolumeSnapshotRef core_v1.ObjectReference `json:"volumeSnapshotRef,omitempty" protobuf:"bytes,1,opt,name=volumeSnapshotRef"` } //+genclient @@ -337,11 +346,21 @@ type VolumeGroupSnapshotContentStatus struct { // +optional Error *snapshotv1.VolumeSnapshotError `json:"error,omitempty" protobuf:"bytes,4,opt,name=error,casttype=VolumeSnapshotError"` - // VolumeSnapshotContentRefList is the list of volume snapshot content references - // for this group snapshot. + // PVVolumeSnapshotContentRefList is the list of pairs of PV and + // VolumeSnapshotCOntent for this group snapshot // The maximum number of allowed snapshots in the group is 100. // +optional - VolumeSnapshotContentRefList []core_v1.ObjectReference `json:"volumeSnapshotContentRefList,omitempty" protobuf:"bytes,5,opt,name=volumeSnapshotContentRefList"` + PVVolumeSnapshotContentRefList []PVVolumeSnapshotContentPair `json:"pvVolumeSnapshotContentRefList,omitempty" protobuf:"bytes,6,opt,name=pvVolumeSnapshotContentRefList"` +} + +// PVVolumeSnapshotContentPair represent a pair of PV names and +// VolumeSnapshotContent names +type PVVolumeSnapshotContentPair struct { + // PersistentVolumeName is the name of the persistent volume + PersistentVolumeName string `json:"persistentVolumeName,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeName"` + + // VolumeSnapshotContentName is the name of the volume snapshot content resource + VolumeSnapshotContentName string `json:"volumeSnapshotContentName,omitempty" protobuf:"bytes,1,opt,name=volumeSnapshotContentName"` } // VolumeGroupSnapshotContentSource represents the CSI source of a group snapshot. diff --git a/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go b/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go index 820cbb91a..47277fd40 100644 --- a/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go +++ b/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go @@ -23,7 +23,6 @@ package v1alpha1 import ( v1 "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -49,6 +48,40 @@ func (in *GroupSnapshotHandles) DeepCopy() *GroupSnapshotHandles { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PVCVolumeSnapshotPair) DeepCopyInto(out *PVCVolumeSnapshotPair) { + *out = *in + out.PersistentVolumeClaimRef = in.PersistentVolumeClaimRef + out.VolumeSnapshotRef = in.VolumeSnapshotRef + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PVCVolumeSnapshotPair. +func (in *PVCVolumeSnapshotPair) DeepCopy() *PVCVolumeSnapshotPair { + if in == nil { + return nil + } + out := new(PVCVolumeSnapshotPair) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PVVolumeSnapshotContentPair) DeepCopyInto(out *PVVolumeSnapshotContentPair) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PVVolumeSnapshotContentPair. +func (in *PVVolumeSnapshotContentPair) DeepCopy() *PVVolumeSnapshotContentPair { + if in == nil { + return nil + } + out := new(PVVolumeSnapshotContentPair) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VolumeGroupSnapshot) DeepCopyInto(out *VolumeGroupSnapshot) { *out = *in @@ -284,9 +317,9 @@ func (in *VolumeGroupSnapshotContentStatus) DeepCopyInto(out *VolumeGroupSnapsho *out = new(v1.VolumeSnapshotError) (*in).DeepCopyInto(*out) } - if in.VolumeSnapshotContentRefList != nil { - in, out := &in.VolumeSnapshotContentRefList, &out.VolumeSnapshotContentRefList - *out = make([]corev1.ObjectReference, len(*in)) + if in.PVVolumeSnapshotContentRefList != nil { + in, out := &in.PVVolumeSnapshotContentRefList, &out.PVVolumeSnapshotContentRefList + *out = make([]PVVolumeSnapshotContentPair, len(*in)) copy(*out, *in) } return @@ -405,9 +438,9 @@ func (in *VolumeGroupSnapshotStatus) DeepCopyInto(out *VolumeGroupSnapshotStatus *out = new(v1.VolumeSnapshotError) (*in).DeepCopyInto(*out) } - if in.VolumeSnapshotRefList != nil { - in, out := &in.VolumeSnapshotRefList, &out.VolumeSnapshotRefList - *out = make([]corev1.ObjectReference, len(*in)) + if in.PVCVolumeSnapshotRefList != nil { + in, out := &in.PVCVolumeSnapshotRefList, &out.PVCVolumeSnapshotRefList + *out = make([]PVCVolumeSnapshotPair, len(*in)) copy(*out, *in) } return From 7c8516f9af477608ad98ab9bde94e36f86603088 Mon Sep 17 00:00:00 2001 From: Leonardo Cecchi Date: Mon, 15 Apr 2024 18:18:42 +0200 Subject: [PATCH 2/6] Minimal changes to get the controller working with the updated API This commit won't set any value in the new fields, but only change the logic to reproduce the behavior we already had. --- .../groupsnapshot_controller_helper.go | 34 ++++++++++--------- .../groupsnapshot_helper.go | 22 ++++++------ pkg/utils/util.go | 4 +-- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/pkg/common-controller/groupsnapshot_controller_helper.go b/pkg/common-controller/groupsnapshot_controller_helper.go index 81e56fc0e..c29dc1155 100644 --- a/pkg/common-controller/groupsnapshot_controller_helper.go +++ b/pkg/common-controller/groupsnapshot_controller_helper.go @@ -315,7 +315,7 @@ func (ctrl *csiSnapshotCommonController) syncGroupSnapshot(groupSnapshot *crdv1a // 2) groupSnapshot.Status.ReadyToUse is false // 3) groupSnapshot.Status.IsBoundVolumeGroupSnapshotContentNameSet is not set // 4) groupSnapshot.Status.IsVolumeSnapshotRefListSet is not set - if !utils.IsGroupSnapshotReady(groupSnapshot) || !utils.IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot) || !utils.IsVolumeSnapshotRefListSet(groupSnapshot) { + if !utils.IsGroupSnapshotReady(groupSnapshot) || !utils.IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot) || !utils.IsPVCVolumeSnapshotRefListSet(groupSnapshot) { return ctrl.syncUnreadyGroupSnapshot(groupSnapshot) } return ctrl.syncReadyGroupSnapshot(groupSnapshot) @@ -564,14 +564,16 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot volumeSnapshotErr = groupSnapshotContent.Status.Error.DeepCopy() } - var volumeSnapshotRefList []v1.ObjectReference - if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.VolumeSnapshotContentRefList) != 0 { - for _, contentRef := range groupSnapshotContent.Status.VolumeSnapshotContentRefList { - groupSnapshotContent, err := ctrl.contentLister.Get(contentRef.Name) + var pvcVolumeSnapshotRefList []crdv1alpha1.PVCVolumeSnapshotPair + if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.PVVolumeSnapshotContentRefList) != 0 { + for _, contentRef := range groupSnapshotContent.Status.PVVolumeSnapshotContentRefList { + groupSnapshotContent, err := ctrl.contentLister.Get(contentRef.VolumeSnapshotContentName) if err != nil { - return nil, fmt.Errorf("failed to get group snapshot content %s from group snapshot content store: %v", contentRef.Name, err) + return nil, fmt.Errorf("failed to get group snapshot content %s from group snapshot content store: %v", contentRef.VolumeSnapshotContentName, err) } - volumeSnapshotRefList = append(volumeSnapshotRefList, groupSnapshotContent.Spec.VolumeSnapshotRef) + pvcVolumeSnapshotRefList = append(pvcVolumeSnapshotRefList, crdv1alpha1.PVCVolumeSnapshotPair{ + VolumeSnapshotRef: groupSnapshotContent.Spec.VolumeSnapshotRef, + }) } } @@ -595,8 +597,8 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot if volumeSnapshotErr != nil { newStatus.Error = volumeSnapshotErr } - if len(volumeSnapshotRefList) == 0 { - newStatus.VolumeSnapshotRefList = volumeSnapshotRefList + if len(pvcVolumeSnapshotRefList) == 0 { + newStatus.PVCVolumeSnapshotRefList = pvcVolumeSnapshotRefList } updated = true @@ -621,8 +623,8 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot newStatus.Error = volumeSnapshotErr updated = true } - if len(newStatus.VolumeSnapshotRefList) == 0 { - newStatus.VolumeSnapshotRefList = volumeSnapshotRefList + if len(newStatus.PVCVolumeSnapshotRefList) == 0 { + newStatus.PVCVolumeSnapshotRefList = pvcVolumeSnapshotRefList updated = true } } @@ -1137,8 +1139,8 @@ func (ctrl *csiSnapshotCommonController) processGroupSnapshotWithDeletionTimesta // check if an individual snapshot belonging to the group snapshot is being // used for restore a PVC // If yes, do nothing and wait until PVC restoration finishes - for _, snapshotRef := range groupSnapshot.Status.VolumeSnapshotRefList { - snapshot, err := ctrl.snapshotLister.VolumeSnapshots(snapshotRef.Namespace).Get(snapshotRef.Name) + for _, snapshotRef := range groupSnapshot.Status.PVCVolumeSnapshotRefList { + snapshot, err := ctrl.snapshotLister.VolumeSnapshots(snapshotRef.VolumeSnapshotRef.Namespace).Get(snapshotRef.VolumeSnapshotRef.Name) if err != nil { if apierrs.IsNotFound(err) { continue @@ -1185,10 +1187,10 @@ func (ctrl *csiSnapshotCommonController) processGroupSnapshotWithDeletionTimesta klog.V(5).Infof("processGroupSnapshotWithDeletionTimestamp[%s]: Delete individual snapshots that are part of the group snapshot", utils.GroupSnapshotKey(groupSnapshot)) // Delete the individual snapshots part of the group snapshot - for _, snapshot := range groupSnapshot.Status.VolumeSnapshotRefList { - err := ctrl.clientset.SnapshotV1().VolumeSnapshots(snapshot.Namespace).Delete(context.TODO(), snapshot.Name, metav1.DeleteOptions{}) + for _, snapshot := range groupSnapshot.Status.PVCVolumeSnapshotRefList { + err := ctrl.clientset.SnapshotV1().VolumeSnapshots(snapshot.VolumeSnapshotRef.Namespace).Delete(context.TODO(), snapshot.VolumeSnapshotRef.Name, metav1.DeleteOptions{}) if err != nil && !apierrs.IsNotFound(err) { - msg := fmt.Sprintf("failed to delete snapshot API object %s/%s part of group snapshot %s: %v", snapshot.Namespace, snapshot.Name, utils.GroupSnapshotKey(groupSnapshot), err) + msg := fmt.Sprintf("failed to delete snapshot API object %s/%s part of group snapshot %s: %v", snapshot.VolumeSnapshotRef.Namespace, snapshot.VolumeSnapshotRef.Name, utils.GroupSnapshotKey(groupSnapshot), err) klog.Error(msg) ctrl.eventRecorder.Event(groupSnapshot, v1.EventTypeWarning, "SnapshotDeleteError", msg) return fmt.Errorf(msg) diff --git a/pkg/sidecar-controller/groupsnapshot_helper.go b/pkg/sidecar-controller/groupsnapshot_helper.go index 0414de902..f2376a8cb 100644 --- a/pkg/sidecar-controller/groupsnapshot_helper.go +++ b/pkg/sidecar-controller/groupsnapshot_helper.go @@ -240,11 +240,11 @@ func (ctrl *csiSnapshotSideCarController) deleteCSIGroupSnapshotOperation(groupS } var snapshotIDs []string - if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.VolumeSnapshotContentRefList) != 0 { - for _, contentRef := range groupSnapshotContent.Status.VolumeSnapshotContentRefList { - snapshotContent, err := ctrl.contentLister.Get(contentRef.Name) + if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.PVVolumeSnapshotContentRefList) != 0 { + for _, contentRef := range groupSnapshotContent.Status.PVVolumeSnapshotContentRefList { + snapshotContent, err := ctrl.contentLister.Get(contentRef.VolumeSnapshotContentName) if err != nil { - return fmt.Errorf("failed to get snapshot content %s from snapshot content store: %v", contentRef.Name, err) + return fmt.Errorf("failed to get snapshot content %s from snapshot content store: %v", contentRef.VolumeSnapshotContentName, err) } snapshotIDs = append(snapshotIDs, *snapshotContent.Status.SnapshotHandle) } @@ -283,7 +283,7 @@ func (ctrl *csiSnapshotSideCarController) clearGroupSnapshotContentStatus( groupSnapshotContent.Status.ReadyToUse = nil groupSnapshotContent.Status.CreationTime = nil groupSnapshotContent.Status.Error = nil - groupSnapshotContent.Status.VolumeSnapshotContentRefList = nil + groupSnapshotContent.Status.PVVolumeSnapshotContentRefList = nil } newContent, err := ctrl.clientset.GroupsnapshotV1alpha1().VolumeGroupSnapshotContents().UpdateStatus(context.TODO(), groupSnapshotContent, metav1.UpdateOptions{}) if err != nil { @@ -650,9 +650,8 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus( CreationTime: &createdAt, } for _, name := range snapshotContentNames { - newStatus.VolumeSnapshotContentRefList = append(newStatus.VolumeSnapshotContentRefList, v1.ObjectReference{ - Kind: "VolumeSnapshotContent", - Name: name, + newStatus.PVVolumeSnapshotContentRefList = append(newStatus.PVVolumeSnapshotContentRefList, crdv1alpha1.PVVolumeSnapshotContentPair{ + VolumeSnapshotContentName: name, }) } updated = true @@ -673,11 +672,10 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus( newStatus.CreationTime = &createdAt updated = true } - if len(newStatus.VolumeSnapshotContentRefList) == 0 { + if len(newStatus.PVVolumeSnapshotContentRefList) == 0 { for _, name := range snapshotContentNames { - newStatus.VolumeSnapshotContentRefList = append(newStatus.VolumeSnapshotContentRefList, v1.ObjectReference{ - Kind: "VolumeSnapshotContent", - Name: name, + newStatus.PVVolumeSnapshotContentRefList = append(newStatus.PVVolumeSnapshotContentRefList, crdv1alpha1.PVVolumeSnapshotContentPair{ + VolumeSnapshotContentName: name, }) } updated = true diff --git a/pkg/utils/util.go b/pkg/utils/util.go index bea90871e..d893ec983 100644 --- a/pkg/utils/util.go +++ b/pkg/utils/util.go @@ -638,8 +638,8 @@ func IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot *crdv1alpha1.VolumeG return true } -func IsVolumeSnapshotRefListSet(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) bool { - if groupSnapshot.Status == nil || len(groupSnapshot.Status.VolumeSnapshotRefList) == 0 { +func IsPVCVolumeSnapshotRefListSet(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) bool { + if groupSnapshot.Status == nil || len(groupSnapshot.Status.PVCVolumeSnapshotRefList) == 0 { return false } return true From 519eacf00ff6ee91d31636c3774b18f96449c440 Mon Sep 17 00:00:00 2001 From: Leonardo Cecchi Date: Sat, 20 Apr 2024 09:15:20 +0200 Subject: [PATCH 3/6] Address review comments --- client/apis/volumegroupsnapshot/v1alpha1/types.go | 14 +++++++------- .../v1alpha1/zz_generated.deepcopy.go | 4 ++-- ...storage.k8s.io_volumegroupsnapshotcontents.yaml | 8 ++++---- ...apshot.storage.k8s.io_volumegroupsnapshots.yaml | 2 +- .../groupsnapshot_controller_helper.go | 4 ++-- pkg/sidecar-controller/groupsnapshot_helper.go | 12 ++++++------ .../v7/apis/volumegroupsnapshot/v1alpha1/types.go | 14 +++++++------- .../v1alpha1/zz_generated.deepcopy.go | 4 ++-- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/client/apis/volumegroupsnapshot/v1alpha1/types.go b/client/apis/volumegroupsnapshot/v1alpha1/types.go index 5aa14d272..f55051f91 100644 --- a/client/apis/volumegroupsnapshot/v1alpha1/types.go +++ b/client/apis/volumegroupsnapshot/v1alpha1/types.go @@ -107,16 +107,16 @@ type VolumeGroupSnapshotStatus struct { // is part of this group snapshot. // The maximum number of allowed snapshots in the group is 100. // +optional - PVCVolumeSnapshotRefList []PVCVolumeSnapshotPair `json:"pvcVolumeSnapshotRefList,omitempty" protobuf:"bytes,6,opt,name=pvcVolumeSnapshotRefList"` + PVCVolumeSnapshotRefList []PVCVolumeSnapshotPair `json:"pvcVolumeSnapshotRefList,omitempty" protobuf:"bytes,5,opt,name=pvcVolumeSnapshotRefList"` } -// PVCVolumeSnapshotPair defines a pair of a PVC reference and a Volume Snapshot +// PVCVolumeSnapshotPair defines a pair of a PVC reference and a Volume Snapshot Reference type PVCVolumeSnapshotPair struct { // PersistentVolumeClaimRef is a reference to the PVC this pair is referring to PersistentVolumeClaimRef core_v1.ObjectReference `json:"persistentVolumeClaimRef,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeClaimRef"` // VolumeSnapshotRef is a reference to the VolumeSnapshot this pair is referring to - VolumeSnapshotRef core_v1.ObjectReference `json:"volumeSnapshotRef,omitempty" protobuf:"bytes,1,opt,name=volumeSnapshotRef"` + VolumeSnapshotRef core_v1.ObjectReference `json:"volumeSnapshotRef,omitempty" protobuf:"bytes,2,opt,name=volumeSnapshotRef"` } //+genclient @@ -346,11 +346,11 @@ type VolumeGroupSnapshotContentStatus struct { // +optional Error *snapshotv1.VolumeSnapshotError `json:"error,omitempty" protobuf:"bytes,4,opt,name=error,casttype=VolumeSnapshotError"` - // PVVolumeSnapshotContentRefList is the list of pairs of PV and - // VolumeSnapshotCOntent for this group snapshot + // PVVolumeSnapshotContentList is the list of pairs of PV and + // VolumeSnapshotContent for this group snapshot // The maximum number of allowed snapshots in the group is 100. // +optional - PVVolumeSnapshotContentRefList []PVVolumeSnapshotContentPair `json:"pvVolumeSnapshotContentRefList,omitempty" protobuf:"bytes,6,opt,name=pvVolumeSnapshotContentRefList"` + PVVolumeSnapshotContentList []PVVolumeSnapshotContentPair `json:"pvVolumeSnapshotContentList,omitempty" protobuf:"bytes,5,opt,name=pvVolumeSnapshotContentRefList"` } // PVVolumeSnapshotContentPair represent a pair of PV names and @@ -360,7 +360,7 @@ type PVVolumeSnapshotContentPair struct { PersistentVolumeName string `json:"persistentVolumeName,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeName"` // VolumeSnapshotContentName is the name of the volume snapshot content resource - VolumeSnapshotContentName string `json:"volumeSnapshotContentName,omitempty" protobuf:"bytes,1,opt,name=volumeSnapshotContentName"` + VolumeSnapshotContentName string `json:"volumeSnapshotContentName,omitempty" protobuf:"bytes,2,opt,name=volumeSnapshotContentName"` } // VolumeGroupSnapshotContentSource represents the CSI source of a group snapshot. diff --git a/client/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go b/client/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go index 47277fd40..a1a484569 100644 --- a/client/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go +++ b/client/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go @@ -317,8 +317,8 @@ func (in *VolumeGroupSnapshotContentStatus) DeepCopyInto(out *VolumeGroupSnapsho *out = new(v1.VolumeSnapshotError) (*in).DeepCopyInto(*out) } - if in.PVVolumeSnapshotContentRefList != nil { - in, out := &in.PVVolumeSnapshotContentRefList, &out.PVVolumeSnapshotContentRefList + if in.PVVolumeSnapshotContentList != nil { + in, out := &in.PVVolumeSnapshotContentList, &out.PVVolumeSnapshotContentList *out = make([]PVVolumeSnapshotContentPair, len(*in)) copy(*out, *in) } diff --git a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml index ca154b704..f9182782e 100644 --- a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml +++ b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml @@ -227,10 +227,10 @@ spec: format: date-time type: string type: object - pvVolumeSnapshotContentRefList: - description: PVVolumeSnapshotContentRefList is the list of pairs of - PV and VolumeSnapshotCOntent for this group snapshot The maximum - number of allowed snapshots in the group is 100. + pvVolumeSnapshotContentList: + description: PVVolumeSnapshotContentList is the list of pairs of PV + and VolumeSnapshotContent for this group snapshot The maximum number + of allowed snapshots in the group is 100. items: description: PVVolumeSnapshotContentPair represent a pair of PV names and VolumeSnapshotContent names diff --git a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml index cb62d1685..68805adbb 100644 --- a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml +++ b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml @@ -189,7 +189,7 @@ spec: allowed snapshots in the group is 100. items: description: PVCVolumeSnapshotPair defines a pair of a PVC reference - and a Volume Snapshot + and a Volume Snapshot Reference properties: persistentVolumeClaimRef: description: PersistentVolumeClaimRef is a reference to the diff --git a/pkg/common-controller/groupsnapshot_controller_helper.go b/pkg/common-controller/groupsnapshot_controller_helper.go index c29dc1155..9dd5142cf 100644 --- a/pkg/common-controller/groupsnapshot_controller_helper.go +++ b/pkg/common-controller/groupsnapshot_controller_helper.go @@ -565,8 +565,8 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot } var pvcVolumeSnapshotRefList []crdv1alpha1.PVCVolumeSnapshotPair - if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.PVVolumeSnapshotContentRefList) != 0 { - for _, contentRef := range groupSnapshotContent.Status.PVVolumeSnapshotContentRefList { + if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.PVVolumeSnapshotContentList) != 0 { + for _, contentRef := range groupSnapshotContent.Status.PVVolumeSnapshotContentList { groupSnapshotContent, err := ctrl.contentLister.Get(contentRef.VolumeSnapshotContentName) if err != nil { return nil, fmt.Errorf("failed to get group snapshot content %s from group snapshot content store: %v", contentRef.VolumeSnapshotContentName, err) diff --git a/pkg/sidecar-controller/groupsnapshot_helper.go b/pkg/sidecar-controller/groupsnapshot_helper.go index f2376a8cb..a275c2fc4 100644 --- a/pkg/sidecar-controller/groupsnapshot_helper.go +++ b/pkg/sidecar-controller/groupsnapshot_helper.go @@ -240,8 +240,8 @@ func (ctrl *csiSnapshotSideCarController) deleteCSIGroupSnapshotOperation(groupS } var snapshotIDs []string - if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.PVVolumeSnapshotContentRefList) != 0 { - for _, contentRef := range groupSnapshotContent.Status.PVVolumeSnapshotContentRefList { + if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.PVVolumeSnapshotContentList) != 0 { + for _, contentRef := range groupSnapshotContent.Status.PVVolumeSnapshotContentList { snapshotContent, err := ctrl.contentLister.Get(contentRef.VolumeSnapshotContentName) if err != nil { return fmt.Errorf("failed to get snapshot content %s from snapshot content store: %v", contentRef.VolumeSnapshotContentName, err) @@ -283,7 +283,7 @@ func (ctrl *csiSnapshotSideCarController) clearGroupSnapshotContentStatus( groupSnapshotContent.Status.ReadyToUse = nil groupSnapshotContent.Status.CreationTime = nil groupSnapshotContent.Status.Error = nil - groupSnapshotContent.Status.PVVolumeSnapshotContentRefList = nil + groupSnapshotContent.Status.PVVolumeSnapshotContentList = nil } newContent, err := ctrl.clientset.GroupsnapshotV1alpha1().VolumeGroupSnapshotContents().UpdateStatus(context.TODO(), groupSnapshotContent, metav1.UpdateOptions{}) if err != nil { @@ -650,7 +650,7 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus( CreationTime: &createdAt, } for _, name := range snapshotContentNames { - newStatus.PVVolumeSnapshotContentRefList = append(newStatus.PVVolumeSnapshotContentRefList, crdv1alpha1.PVVolumeSnapshotContentPair{ + newStatus.PVVolumeSnapshotContentList = append(newStatus.PVVolumeSnapshotContentList, crdv1alpha1.PVVolumeSnapshotContentPair{ VolumeSnapshotContentName: name, }) } @@ -672,9 +672,9 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus( newStatus.CreationTime = &createdAt updated = true } - if len(newStatus.PVVolumeSnapshotContentRefList) == 0 { + if len(newStatus.PVVolumeSnapshotContentList) == 0 { for _, name := range snapshotContentNames { - newStatus.PVVolumeSnapshotContentRefList = append(newStatus.PVVolumeSnapshotContentRefList, crdv1alpha1.PVVolumeSnapshotContentPair{ + newStatus.PVVolumeSnapshotContentList = append(newStatus.PVVolumeSnapshotContentList, crdv1alpha1.PVVolumeSnapshotContentPair{ VolumeSnapshotContentName: name, }) } diff --git a/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go b/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go index 5aa14d272..f55051f91 100644 --- a/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go +++ b/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go @@ -107,16 +107,16 @@ type VolumeGroupSnapshotStatus struct { // is part of this group snapshot. // The maximum number of allowed snapshots in the group is 100. // +optional - PVCVolumeSnapshotRefList []PVCVolumeSnapshotPair `json:"pvcVolumeSnapshotRefList,omitempty" protobuf:"bytes,6,opt,name=pvcVolumeSnapshotRefList"` + PVCVolumeSnapshotRefList []PVCVolumeSnapshotPair `json:"pvcVolumeSnapshotRefList,omitempty" protobuf:"bytes,5,opt,name=pvcVolumeSnapshotRefList"` } -// PVCVolumeSnapshotPair defines a pair of a PVC reference and a Volume Snapshot +// PVCVolumeSnapshotPair defines a pair of a PVC reference and a Volume Snapshot Reference type PVCVolumeSnapshotPair struct { // PersistentVolumeClaimRef is a reference to the PVC this pair is referring to PersistentVolumeClaimRef core_v1.ObjectReference `json:"persistentVolumeClaimRef,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeClaimRef"` // VolumeSnapshotRef is a reference to the VolumeSnapshot this pair is referring to - VolumeSnapshotRef core_v1.ObjectReference `json:"volumeSnapshotRef,omitempty" protobuf:"bytes,1,opt,name=volumeSnapshotRef"` + VolumeSnapshotRef core_v1.ObjectReference `json:"volumeSnapshotRef,omitempty" protobuf:"bytes,2,opt,name=volumeSnapshotRef"` } //+genclient @@ -346,11 +346,11 @@ type VolumeGroupSnapshotContentStatus struct { // +optional Error *snapshotv1.VolumeSnapshotError `json:"error,omitempty" protobuf:"bytes,4,opt,name=error,casttype=VolumeSnapshotError"` - // PVVolumeSnapshotContentRefList is the list of pairs of PV and - // VolumeSnapshotCOntent for this group snapshot + // PVVolumeSnapshotContentList is the list of pairs of PV and + // VolumeSnapshotContent for this group snapshot // The maximum number of allowed snapshots in the group is 100. // +optional - PVVolumeSnapshotContentRefList []PVVolumeSnapshotContentPair `json:"pvVolumeSnapshotContentRefList,omitempty" protobuf:"bytes,6,opt,name=pvVolumeSnapshotContentRefList"` + PVVolumeSnapshotContentList []PVVolumeSnapshotContentPair `json:"pvVolumeSnapshotContentList,omitempty" protobuf:"bytes,5,opt,name=pvVolumeSnapshotContentRefList"` } // PVVolumeSnapshotContentPair represent a pair of PV names and @@ -360,7 +360,7 @@ type PVVolumeSnapshotContentPair struct { PersistentVolumeName string `json:"persistentVolumeName,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeName"` // VolumeSnapshotContentName is the name of the volume snapshot content resource - VolumeSnapshotContentName string `json:"volumeSnapshotContentName,omitempty" protobuf:"bytes,1,opt,name=volumeSnapshotContentName"` + VolumeSnapshotContentName string `json:"volumeSnapshotContentName,omitempty" protobuf:"bytes,2,opt,name=volumeSnapshotContentName"` } // VolumeGroupSnapshotContentSource represents the CSI source of a group snapshot. diff --git a/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go b/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go index 47277fd40..a1a484569 100644 --- a/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go +++ b/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go @@ -317,8 +317,8 @@ func (in *VolumeGroupSnapshotContentStatus) DeepCopyInto(out *VolumeGroupSnapsho *out = new(v1.VolumeSnapshotError) (*in).DeepCopyInto(*out) } - if in.PVVolumeSnapshotContentRefList != nil { - in, out := &in.PVVolumeSnapshotContentRefList, &out.PVVolumeSnapshotContentRefList + if in.PVVolumeSnapshotContentList != nil { + in, out := &in.PVVolumeSnapshotContentList, &out.PVVolumeSnapshotContentList *out = make([]PVVolumeSnapshotContentPair, len(*in)) copy(*out, *in) } From 05d7861e4a121e3ea9eafd2b65adc2b08779ee86 Mon Sep 17 00:00:00 2001 From: Leonardo Cecchi Date: Wed, 24 Apr 2024 09:32:49 +0200 Subject: [PATCH 4/6] Use LocalObjectReference instead of ObjectReference Given `Kind` is implied in `pvcVolumeSnapshotRefList.persistentVolumeClaimRef` and in `pvcVolumeSnapshotRefList.volumeSnapshotRef`, let's avoid specifying it. Signed-off-by: Leonardo Cecchi --- .../volumegroupsnapshot/v1alpha1/types.go | 6 +- ...t.storage.k8s.io_volumegroupsnapshots.yaml | 68 ++----------------- .../groupsnapshot_controller_helper.go | 10 +-- .../volumegroupsnapshot/v1alpha1/types.go | 6 +- 4 files changed, 17 insertions(+), 73 deletions(-) diff --git a/client/apis/volumegroupsnapshot/v1alpha1/types.go b/client/apis/volumegroupsnapshot/v1alpha1/types.go index f55051f91..ffd247ff4 100644 --- a/client/apis/volumegroupsnapshot/v1alpha1/types.go +++ b/client/apis/volumegroupsnapshot/v1alpha1/types.go @@ -103,7 +103,7 @@ type VolumeGroupSnapshotStatus struct { // +optional Error *snapshotv1.VolumeSnapshotError `json:"error,omitempty" protobuf:"bytes,4,opt,name=error,casttype=VolumeSnapshotError"` - // VolumeSnapshotRefList is the list of PVC and VolumeSnapshot pair that + // VolumeSnapshotRefList is the list of PVC and VolumeSnapshot pairs that // is part of this group snapshot. // The maximum number of allowed snapshots in the group is 100. // +optional @@ -113,10 +113,10 @@ type VolumeGroupSnapshotStatus struct { // PVCVolumeSnapshotPair defines a pair of a PVC reference and a Volume Snapshot Reference type PVCVolumeSnapshotPair struct { // PersistentVolumeClaimRef is a reference to the PVC this pair is referring to - PersistentVolumeClaimRef core_v1.ObjectReference `json:"persistentVolumeClaimRef,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeClaimRef"` + PersistentVolumeClaimRef core_v1.LocalObjectReference `json:"persistentVolumeClaimRef,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeClaimRef"` // VolumeSnapshotRef is a reference to the VolumeSnapshot this pair is referring to - VolumeSnapshotRef core_v1.ObjectReference `json:"volumeSnapshotRef,omitempty" protobuf:"bytes,2,opt,name=volumeSnapshotRef"` + VolumeSnapshotRef core_v1.LocalObjectReference `json:"volumeSnapshotRef,omitempty" protobuf:"bytes,2,opt,name=volumeSnapshotRef"` } //+genclient diff --git a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml index 68805adbb..98f95f58f 100644 --- a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml +++ b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml @@ -185,7 +185,7 @@ spec: type: object pvcVolumeSnapshotRefList: description: VolumeSnapshotRefList is the list of PVC and VolumeSnapshot - pair that is part of this group snapshot. The maximum number of + pairs that is part of this group snapshot. The maximum number of allowed snapshots in the group is 100. items: description: PVCVolumeSnapshotPair defines a pair of a PVC reference @@ -195,38 +195,9 @@ spec: description: PersistentVolumeClaimRef is a reference to the PVC this pair is referring to properties: - apiVersion: - description: API version of the referent. - type: string - fieldPath: - description: 'If referring to a piece of an object instead - of an entire object, this string should contain a valid - JSON/Go field access statement, such as desiredState.manifest.containers[2]. - For example, if the object reference is to a container - within a pod, this would take on a value like: "spec.containers{name}" - (where "name" refers to the name of the container that - triggered the event) or if no container name is specified - "spec.containers[2]" (container with index 2 in this pod). - This syntax is chosen only to have some well-defined way - of referencing a part of an object. TODO: this design - is not final and this field is subject to change in the - future.' - type: string - kind: - description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' - type: string - namespace: - description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/' - type: string - resourceVersion: - description: 'Specific resourceVersion to which this reference - is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency' - type: string - uid: - description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids' + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' type: string type: object x-kubernetes-map-type: atomic @@ -234,38 +205,9 @@ spec: description: VolumeSnapshotRef is a reference to the VolumeSnapshot this pair is referring to properties: - apiVersion: - description: API version of the referent. - type: string - fieldPath: - description: 'If referring to a piece of an object instead - of an entire object, this string should contain a valid - JSON/Go field access statement, such as desiredState.manifest.containers[2]. - For example, if the object reference is to a container - within a pod, this would take on a value like: "spec.containers{name}" - (where "name" refers to the name of the container that - triggered the event) or if no container name is specified - "spec.containers[2]" (container with index 2 in this pod). - This syntax is chosen only to have some well-defined way - of referencing a part of an object. TODO: this design - is not final and this field is subject to change in the - future.' - type: string - kind: - description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' - type: string - namespace: - description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/' - type: string - resourceVersion: - description: 'Specific resourceVersion to which this reference - is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency' - type: string - uid: - description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids' + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' type: string type: object x-kubernetes-map-type: atomic diff --git a/pkg/common-controller/groupsnapshot_controller_helper.go b/pkg/common-controller/groupsnapshot_controller_helper.go index 9dd5142cf..7580cc117 100644 --- a/pkg/common-controller/groupsnapshot_controller_helper.go +++ b/pkg/common-controller/groupsnapshot_controller_helper.go @@ -572,7 +572,9 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot return nil, fmt.Errorf("failed to get group snapshot content %s from group snapshot content store: %v", contentRef.VolumeSnapshotContentName, err) } pvcVolumeSnapshotRefList = append(pvcVolumeSnapshotRefList, crdv1alpha1.PVCVolumeSnapshotPair{ - VolumeSnapshotRef: groupSnapshotContent.Spec.VolumeSnapshotRef, + VolumeSnapshotRef: v1.LocalObjectReference{ + Name: groupSnapshotContent.Spec.VolumeSnapshotRef.Name, + }, }) } } @@ -1140,7 +1142,7 @@ func (ctrl *csiSnapshotCommonController) processGroupSnapshotWithDeletionTimesta // used for restore a PVC // If yes, do nothing and wait until PVC restoration finishes for _, snapshotRef := range groupSnapshot.Status.PVCVolumeSnapshotRefList { - snapshot, err := ctrl.snapshotLister.VolumeSnapshots(snapshotRef.VolumeSnapshotRef.Namespace).Get(snapshotRef.VolumeSnapshotRef.Name) + snapshot, err := ctrl.snapshotLister.VolumeSnapshots(groupSnapshot.Namespace).Get(snapshotRef.VolumeSnapshotRef.Name) if err != nil { if apierrs.IsNotFound(err) { continue @@ -1188,9 +1190,9 @@ func (ctrl *csiSnapshotCommonController) processGroupSnapshotWithDeletionTimesta // Delete the individual snapshots part of the group snapshot for _, snapshot := range groupSnapshot.Status.PVCVolumeSnapshotRefList { - err := ctrl.clientset.SnapshotV1().VolumeSnapshots(snapshot.VolumeSnapshotRef.Namespace).Delete(context.TODO(), snapshot.VolumeSnapshotRef.Name, metav1.DeleteOptions{}) + err := ctrl.clientset.SnapshotV1().VolumeSnapshots(groupSnapshot.Namespace).Delete(context.TODO(), snapshot.VolumeSnapshotRef.Name, metav1.DeleteOptions{}) if err != nil && !apierrs.IsNotFound(err) { - msg := fmt.Sprintf("failed to delete snapshot API object %s/%s part of group snapshot %s: %v", snapshot.VolumeSnapshotRef.Namespace, snapshot.VolumeSnapshotRef.Name, utils.GroupSnapshotKey(groupSnapshot), err) + msg := fmt.Sprintf("failed to delete snapshot API object %s/%s part of group snapshot %s: %v", groupSnapshot.Namespace, snapshot.VolumeSnapshotRef.Name, utils.GroupSnapshotKey(groupSnapshot), err) klog.Error(msg) ctrl.eventRecorder.Event(groupSnapshot, v1.EventTypeWarning, "SnapshotDeleteError", msg) return fmt.Errorf(msg) diff --git a/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go b/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go index f55051f91..ffd247ff4 100644 --- a/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go +++ b/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go @@ -103,7 +103,7 @@ type VolumeGroupSnapshotStatus struct { // +optional Error *snapshotv1.VolumeSnapshotError `json:"error,omitempty" protobuf:"bytes,4,opt,name=error,casttype=VolumeSnapshotError"` - // VolumeSnapshotRefList is the list of PVC and VolumeSnapshot pair that + // VolumeSnapshotRefList is the list of PVC and VolumeSnapshot pairs that // is part of this group snapshot. // The maximum number of allowed snapshots in the group is 100. // +optional @@ -113,10 +113,10 @@ type VolumeGroupSnapshotStatus struct { // PVCVolumeSnapshotPair defines a pair of a PVC reference and a Volume Snapshot Reference type PVCVolumeSnapshotPair struct { // PersistentVolumeClaimRef is a reference to the PVC this pair is referring to - PersistentVolumeClaimRef core_v1.ObjectReference `json:"persistentVolumeClaimRef,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeClaimRef"` + PersistentVolumeClaimRef core_v1.LocalObjectReference `json:"persistentVolumeClaimRef,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeClaimRef"` // VolumeSnapshotRef is a reference to the VolumeSnapshot this pair is referring to - VolumeSnapshotRef core_v1.ObjectReference `json:"volumeSnapshotRef,omitempty" protobuf:"bytes,2,opt,name=volumeSnapshotRef"` + VolumeSnapshotRef core_v1.LocalObjectReference `json:"volumeSnapshotRef,omitempty" protobuf:"bytes,2,opt,name=volumeSnapshotRef"` } //+genclient From d273061b0960086641d33779e5206209b816563a Mon Sep 17 00:00:00 2001 From: Leonardo Cecchi Date: Wed, 24 Apr 2024 23:10:10 +0200 Subject: [PATCH 5/6] Use LocalObjectReference instead of ObjectReference in VolumeSnapshot Instead of using a field with the resource name, this patch uses LocalObjectReference in VolumeSnapshot too. This is being done for simmetry with VolumeGroupSnapshotContent. Signed-off-by: Leonardo Cecchi --- .../volumegroupsnapshot/v1alpha1/types.go | 8 +++--- .../v1alpha1/zz_generated.deepcopy.go | 2 ++ ...ge.k8s.io_volumegroupsnapshotcontents.yaml | 28 +++++++++++++------ .../groupsnapshot_controller_helper.go | 4 +-- .../groupsnapshot_helper.go | 12 +++++--- .../volumegroupsnapshot/v1alpha1/types.go | 8 +++--- .../v1alpha1/zz_generated.deepcopy.go | 2 ++ 7 files changed, 42 insertions(+), 22 deletions(-) diff --git a/client/apis/volumegroupsnapshot/v1alpha1/types.go b/client/apis/volumegroupsnapshot/v1alpha1/types.go index ffd247ff4..0db965352 100644 --- a/client/apis/volumegroupsnapshot/v1alpha1/types.go +++ b/client/apis/volumegroupsnapshot/v1alpha1/types.go @@ -356,11 +356,11 @@ type VolumeGroupSnapshotContentStatus struct { // PVVolumeSnapshotContentPair represent a pair of PV names and // VolumeSnapshotContent names type PVVolumeSnapshotContentPair struct { - // PersistentVolumeName is the name of the persistent volume - PersistentVolumeName string `json:"persistentVolumeName,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeName"` + // PersistentVolumeRef is a reference to the persistent volume resource + PersistentVolumeRef core_v1.LocalObjectReference `json:"persistentVolumeRef,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeRef"` - // VolumeSnapshotContentName is the name of the volume snapshot content resource - VolumeSnapshotContentName string `json:"volumeSnapshotContentName,omitempty" protobuf:"bytes,2,opt,name=volumeSnapshotContentName"` + // VolumeSnapshotContentRef is a reference to the volume snapshot content resource + VolumeSnapshotContentRef core_v1.LocalObjectReference `json:"volumeSnapshotContentRef,omitempty" protobuf:"bytes,2,opt,name=volumeSnapshotContentRef"` } // VolumeGroupSnapshotContentSource represents the CSI source of a group snapshot. diff --git a/client/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go b/client/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go index a1a484569..81bdf47cd 100644 --- a/client/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go +++ b/client/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go @@ -69,6 +69,8 @@ func (in *PVCVolumeSnapshotPair) DeepCopy() *PVCVolumeSnapshotPair { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PVVolumeSnapshotContentPair) DeepCopyInto(out *PVVolumeSnapshotContentPair) { *out = *in + out.PersistentVolumeRef = in.PersistentVolumeRef + out.VolumeSnapshotContentRef = in.VolumeSnapshotContentRef return } diff --git a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml index f9182782e..6effcd5d7 100644 --- a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml +++ b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml @@ -235,14 +235,26 @@ spec: description: PVVolumeSnapshotContentPair represent a pair of PV names and VolumeSnapshotContent names properties: - persistentVolumeName: - description: PersistentVolumeName is the name of the persistent - volume - type: string - volumeSnapshotContentName: - description: VolumeSnapshotContentName is the name of the volume - snapshot content resource - type: string + persistentVolumeRef: + description: PersistentVolumeRef is a reference to the persistent + volume resource + properties: + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + type: object + x-kubernetes-map-type: atomic + volumeSnapshotContentRef: + description: VolumeSnapshotContentRef is a reference to the + volume snapshot content resource + properties: + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + type: object + x-kubernetes-map-type: atomic type: object type: array readyToUse: diff --git a/pkg/common-controller/groupsnapshot_controller_helper.go b/pkg/common-controller/groupsnapshot_controller_helper.go index 7580cc117..c66ff4814 100644 --- a/pkg/common-controller/groupsnapshot_controller_helper.go +++ b/pkg/common-controller/groupsnapshot_controller_helper.go @@ -567,9 +567,9 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot var pvcVolumeSnapshotRefList []crdv1alpha1.PVCVolumeSnapshotPair if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.PVVolumeSnapshotContentList) != 0 { for _, contentRef := range groupSnapshotContent.Status.PVVolumeSnapshotContentList { - groupSnapshotContent, err := ctrl.contentLister.Get(contentRef.VolumeSnapshotContentName) + groupSnapshotContent, err := ctrl.contentLister.Get(contentRef.VolumeSnapshotContentRef.Name) if err != nil { - return nil, fmt.Errorf("failed to get group snapshot content %s from group snapshot content store: %v", contentRef.VolumeSnapshotContentName, err) + return nil, fmt.Errorf("failed to get group snapshot content %s from group snapshot content store: %v", contentRef.VolumeSnapshotContentRef.Name, err) } pvcVolumeSnapshotRefList = append(pvcVolumeSnapshotRefList, crdv1alpha1.PVCVolumeSnapshotPair{ VolumeSnapshotRef: v1.LocalObjectReference{ diff --git a/pkg/sidecar-controller/groupsnapshot_helper.go b/pkg/sidecar-controller/groupsnapshot_helper.go index a275c2fc4..c50bb13e6 100644 --- a/pkg/sidecar-controller/groupsnapshot_helper.go +++ b/pkg/sidecar-controller/groupsnapshot_helper.go @@ -242,9 +242,9 @@ func (ctrl *csiSnapshotSideCarController) deleteCSIGroupSnapshotOperation(groupS var snapshotIDs []string if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.PVVolumeSnapshotContentList) != 0 { for _, contentRef := range groupSnapshotContent.Status.PVVolumeSnapshotContentList { - snapshotContent, err := ctrl.contentLister.Get(contentRef.VolumeSnapshotContentName) + snapshotContent, err := ctrl.contentLister.Get(contentRef.VolumeSnapshotContentRef.Name) if err != nil { - return fmt.Errorf("failed to get snapshot content %s from snapshot content store: %v", contentRef.VolumeSnapshotContentName, err) + return fmt.Errorf("failed to get snapshot content %s from snapshot content store: %v", contentRef.VolumeSnapshotContentRef.Name, err) } snapshotIDs = append(snapshotIDs, *snapshotContent.Status.SnapshotHandle) } @@ -651,7 +651,9 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus( } for _, name := range snapshotContentNames { newStatus.PVVolumeSnapshotContentList = append(newStatus.PVVolumeSnapshotContentList, crdv1alpha1.PVVolumeSnapshotContentPair{ - VolumeSnapshotContentName: name, + VolumeSnapshotContentRef: v1.LocalObjectReference{ + Name: name, + }, }) } updated = true @@ -675,7 +677,9 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus( if len(newStatus.PVVolumeSnapshotContentList) == 0 { for _, name := range snapshotContentNames { newStatus.PVVolumeSnapshotContentList = append(newStatus.PVVolumeSnapshotContentList, crdv1alpha1.PVVolumeSnapshotContentPair{ - VolumeSnapshotContentName: name, + VolumeSnapshotContentRef: v1.LocalObjectReference{ + Name: name, + }, }) } updated = true diff --git a/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go b/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go index ffd247ff4..0db965352 100644 --- a/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go +++ b/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go @@ -356,11 +356,11 @@ type VolumeGroupSnapshotContentStatus struct { // PVVolumeSnapshotContentPair represent a pair of PV names and // VolumeSnapshotContent names type PVVolumeSnapshotContentPair struct { - // PersistentVolumeName is the name of the persistent volume - PersistentVolumeName string `json:"persistentVolumeName,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeName"` + // PersistentVolumeRef is a reference to the persistent volume resource + PersistentVolumeRef core_v1.LocalObjectReference `json:"persistentVolumeRef,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeRef"` - // VolumeSnapshotContentName is the name of the volume snapshot content resource - VolumeSnapshotContentName string `json:"volumeSnapshotContentName,omitempty" protobuf:"bytes,2,opt,name=volumeSnapshotContentName"` + // VolumeSnapshotContentRef is a reference to the volume snapshot content resource + VolumeSnapshotContentRef core_v1.LocalObjectReference `json:"volumeSnapshotContentRef,omitempty" protobuf:"bytes,2,opt,name=volumeSnapshotContentRef"` } // VolumeGroupSnapshotContentSource represents the CSI source of a group snapshot. diff --git a/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go b/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go index a1a484569..81bdf47cd 100644 --- a/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go +++ b/vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go @@ -69,6 +69,8 @@ func (in *PVCVolumeSnapshotPair) DeepCopy() *PVCVolumeSnapshotPair { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PVVolumeSnapshotContentPair) DeepCopyInto(out *PVVolumeSnapshotContentPair) { *out = *in + out.PersistentVolumeRef = in.PersistentVolumeRef + out.VolumeSnapshotContentRef = in.VolumeSnapshotContentRef return } From b5ab14a57768b280df4742867a6aaecb547fc6be Mon Sep 17 00:00:00 2001 From: Leonardo Cecchi Date: Mon, 13 May 2024 22:00:18 +0200 Subject: [PATCH 6/6] Refresh CRD manifest with controller-gen 0.15.0 Signed-off-by: Leonardo Cecchi --- ...ge.k8s.io_volumegroupsnapshotcontents.yaml | 26 ++++++++++++------- ...t.storage.k8s.io_volumegroupsnapshots.yaml | 21 +++++++++------ 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml index 9f5ca04c0..28584e56b 100644 --- a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml +++ b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml @@ -4,7 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: api-approved.kubernetes.io: "https://github.com/kubernetes-csi/external-snapshotter/pull/1068" - controller-gen.kubebuilder.io/version: v0.12.0 + controller-gen.kubebuilder.io/version: v0.15.0 name: volumegroupsnapshotcontents.groupsnapshot.storage.k8s.io spec: group: groupsnapshot.storage.k8s.io @@ -277,20 +277,24 @@ spec: type: string type: object pvVolumeSnapshotContentList: - description: PVVolumeSnapshotContentList is the list of pairs of PV - and VolumeSnapshotContent for this group snapshot The maximum number - of allowed snapshots in the group is 100. + description: |- + PVVolumeSnapshotContentList is the list of pairs of PV and + VolumeSnapshotContent for this group snapshot + The maximum number of allowed snapshots in the group is 100. items: - description: PVVolumeSnapshotContentPair represent a pair of PV - names and VolumeSnapshotContent names + description: |- + PVVolumeSnapshotContentPair represent a pair of PV names and + VolumeSnapshotContent names properties: persistentVolumeRef: description: PersistentVolumeRef is a reference to the persistent volume resource properties: name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - TODO: Add other useful fields. apiVersion, kind, uid?' + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? type: string type: object x-kubernetes-map-type: atomic @@ -299,8 +303,10 @@ spec: volume snapshot content resource properties: name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - TODO: Add other useful fields. apiVersion, kind, uid?' + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? type: string type: object x-kubernetes-map-type: atomic diff --git a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml index d0df0c912..3d9a771de 100644 --- a/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml +++ b/client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml @@ -4,7 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: api-approved.kubernetes.io: "https://github.com/kubernetes-csi/external-snapshotter/pull/1068" - controller-gen.kubebuilder.io/version: v0.12.0 + controller-gen.kubebuilder.io/version: v0.15.0 name: volumegroupsnapshots.groupsnapshot.storage.k8s.io spec: group: groupsnapshot.storage.k8s.io @@ -222,9 +222,10 @@ spec: type: string type: object pvcVolumeSnapshotRefList: - description: VolumeSnapshotRefList is the list of PVC and VolumeSnapshot - pairs that is part of this group snapshot. The maximum number of - allowed snapshots in the group is 100. + description: |- + VolumeSnapshotRefList is the list of PVC and VolumeSnapshot pairs that + is part of this group snapshot. + The maximum number of allowed snapshots in the group is 100. items: description: PVCVolumeSnapshotPair defines a pair of a PVC reference and a Volume Snapshot Reference @@ -234,8 +235,10 @@ spec: PVC this pair is referring to properties: name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - TODO: Add other useful fields. apiVersion, kind, uid?' + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? type: string type: object x-kubernetes-map-type: atomic @@ -244,8 +247,10 @@ spec: this pair is referring to properties: name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - TODO: Add other useful fields. apiVersion, kind, uid?' + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? type: string type: object x-kubernetes-map-type: atomic