Skip to content

Commit 05d7861

Browse files
committed
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 <[email protected]>
1 parent 519eacf commit 05d7861

File tree

4 files changed

+17
-73
lines changed

4 files changed

+17
-73
lines changed

client/apis/volumegroupsnapshot/v1alpha1/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ type VolumeGroupSnapshotStatus struct {
103103
// +optional
104104
Error *snapshotv1.VolumeSnapshotError `json:"error,omitempty" protobuf:"bytes,4,opt,name=error,casttype=VolumeSnapshotError"`
105105

106-
// VolumeSnapshotRefList is the list of PVC and VolumeSnapshot pair that
106+
// VolumeSnapshotRefList is the list of PVC and VolumeSnapshot pairs that
107107
// is part of this group snapshot.
108108
// The maximum number of allowed snapshots in the group is 100.
109109
// +optional
@@ -113,10 +113,10 @@ type VolumeGroupSnapshotStatus struct {
113113
// PVCVolumeSnapshotPair defines a pair of a PVC reference and a Volume Snapshot Reference
114114
type PVCVolumeSnapshotPair struct {
115115
// PersistentVolumeClaimRef is a reference to the PVC this pair is referring to
116-
PersistentVolumeClaimRef core_v1.ObjectReference `json:"persistentVolumeClaimRef,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeClaimRef"`
116+
PersistentVolumeClaimRef core_v1.LocalObjectReference `json:"persistentVolumeClaimRef,omitempty" protobuf:"bytes,1,opt,name=persistentVolumeClaimRef"`
117117

118118
// VolumeSnapshotRef is a reference to the VolumeSnapshot this pair is referring to
119-
VolumeSnapshotRef core_v1.ObjectReference `json:"volumeSnapshotRef,omitempty" protobuf:"bytes,2,opt,name=volumeSnapshotRef"`
119+
VolumeSnapshotRef core_v1.LocalObjectReference `json:"volumeSnapshotRef,omitempty" protobuf:"bytes,2,opt,name=volumeSnapshotRef"`
120120
}
121121

122122
//+genclient

client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml

Lines changed: 5 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ spec:
185185
type: object
186186
pvcVolumeSnapshotRefList:
187187
description: VolumeSnapshotRefList is the list of PVC and VolumeSnapshot
188-
pair that is part of this group snapshot. The maximum number of
188+
pairs that is part of this group snapshot. The maximum number of
189189
allowed snapshots in the group is 100.
190190
items:
191191
description: PVCVolumeSnapshotPair defines a pair of a PVC reference
@@ -195,77 +195,19 @@ spec:
195195
description: PersistentVolumeClaimRef is a reference to the
196196
PVC this pair is referring to
197197
properties:
198-
apiVersion:
199-
description: API version of the referent.
200-
type: string
201-
fieldPath:
202-
description: 'If referring to a piece of an object instead
203-
of an entire object, this string should contain a valid
204-
JSON/Go field access statement, such as desiredState.manifest.containers[2].
205-
For example, if the object reference is to a container
206-
within a pod, this would take on a value like: "spec.containers{name}"
207-
(where "name" refers to the name of the container that
208-
triggered the event) or if no container name is specified
209-
"spec.containers[2]" (container with index 2 in this pod).
210-
This syntax is chosen only to have some well-defined way
211-
of referencing a part of an object. TODO: this design
212-
is not final and this field is subject to change in the
213-
future.'
214-
type: string
215-
kind:
216-
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
217-
type: string
218198
name:
219-
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
220-
type: string
221-
namespace:
222-
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
223-
type: string
224-
resourceVersion:
225-
description: 'Specific resourceVersion to which this reference
226-
is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
227-
type: string
228-
uid:
229-
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
199+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
200+
TODO: Add other useful fields. apiVersion, kind, uid?'
230201
type: string
231202
type: object
232203
x-kubernetes-map-type: atomic
233204
volumeSnapshotRef:
234205
description: VolumeSnapshotRef is a reference to the VolumeSnapshot
235206
this pair is referring to
236207
properties:
237-
apiVersion:
238-
description: API version of the referent.
239-
type: string
240-
fieldPath:
241-
description: 'If referring to a piece of an object instead
242-
of an entire object, this string should contain a valid
243-
JSON/Go field access statement, such as desiredState.manifest.containers[2].
244-
For example, if the object reference is to a container
245-
within a pod, this would take on a value like: "spec.containers{name}"
246-
(where "name" refers to the name of the container that
247-
triggered the event) or if no container name is specified
248-
"spec.containers[2]" (container with index 2 in this pod).
249-
This syntax is chosen only to have some well-defined way
250-
of referencing a part of an object. TODO: this design
251-
is not final and this field is subject to change in the
252-
future.'
253-
type: string
254-
kind:
255-
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
256-
type: string
257208
name:
258-
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
259-
type: string
260-
namespace:
261-
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
262-
type: string
263-
resourceVersion:
264-
description: 'Specific resourceVersion to which this reference
265-
is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
266-
type: string
267-
uid:
268-
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
209+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
210+
TODO: Add other useful fields. apiVersion, kind, uid?'
269211
type: string
270212
type: object
271213
x-kubernetes-map-type: atomic

pkg/common-controller/groupsnapshot_controller_helper.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,9 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot
572572
return nil, fmt.Errorf("failed to get group snapshot content %s from group snapshot content store: %v", contentRef.VolumeSnapshotContentName, err)
573573
}
574574
pvcVolumeSnapshotRefList = append(pvcVolumeSnapshotRefList, crdv1alpha1.PVCVolumeSnapshotPair{
575-
VolumeSnapshotRef: groupSnapshotContent.Spec.VolumeSnapshotRef,
575+
VolumeSnapshotRef: v1.LocalObjectReference{
576+
Name: groupSnapshotContent.Spec.VolumeSnapshotRef.Name,
577+
},
576578
})
577579
}
578580
}
@@ -1140,7 +1142,7 @@ func (ctrl *csiSnapshotCommonController) processGroupSnapshotWithDeletionTimesta
11401142
// used for restore a PVC
11411143
// If yes, do nothing and wait until PVC restoration finishes
11421144
for _, snapshotRef := range groupSnapshot.Status.PVCVolumeSnapshotRefList {
1143-
snapshot, err := ctrl.snapshotLister.VolumeSnapshots(snapshotRef.VolumeSnapshotRef.Namespace).Get(snapshotRef.VolumeSnapshotRef.Name)
1145+
snapshot, err := ctrl.snapshotLister.VolumeSnapshots(groupSnapshot.Namespace).Get(snapshotRef.VolumeSnapshotRef.Name)
11441146
if err != nil {
11451147
if apierrs.IsNotFound(err) {
11461148
continue
@@ -1188,9 +1190,9 @@ func (ctrl *csiSnapshotCommonController) processGroupSnapshotWithDeletionTimesta
11881190

11891191
// Delete the individual snapshots part of the group snapshot
11901192
for _, snapshot := range groupSnapshot.Status.PVCVolumeSnapshotRefList {
1191-
err := ctrl.clientset.SnapshotV1().VolumeSnapshots(snapshot.VolumeSnapshotRef.Namespace).Delete(context.TODO(), snapshot.VolumeSnapshotRef.Name, metav1.DeleteOptions{})
1193+
err := ctrl.clientset.SnapshotV1().VolumeSnapshots(groupSnapshot.Namespace).Delete(context.TODO(), snapshot.VolumeSnapshotRef.Name, metav1.DeleteOptions{})
11921194
if err != nil && !apierrs.IsNotFound(err) {
1193-
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)
1195+
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)
11941196
klog.Error(msg)
11951197
ctrl.eventRecorder.Event(groupSnapshot, v1.EventTypeWarning, "SnapshotDeleteError", msg)
11961198
return fmt.Errorf(msg)

vendor/github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumegroupsnapshot/v1alpha1/types.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)