Skip to content

Commit f3498df

Browse files
authored
Merge pull request kubernetes#128522 from huww98/multi-volume-part-0
Cleanups about kubelet/volumemanager
2 parents 4c487b0 + b3fe7a6 commit f3498df

12 files changed

+88
-78
lines changed

pkg/kubelet/volumemanager/cache/actual_state_of_world.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ type mountedPod struct {
370370
// call for volumes that do not need to update contents should not fail.
371371
remountRequired bool
372372

373-
// volumeGidValue contains the value of the GID annotation, if present.
374-
volumeGidValue string
373+
// volumeGIDValue contains the value of the GID annotation, if present.
374+
volumeGIDValue string
375375

376376
// volumeMountStateForPod stores state of volume mount for the pod. if it is:
377377
// - VolumeMounted: means volume for pod has been successfully mounted
@@ -484,7 +484,7 @@ func (asw *actualStateOfWorld) CheckAndMarkVolumeAsUncertainViaReconstruction(op
484484
mounter := opts.Mounter
485485
blockVolumeMapper := opts.BlockVolumeMapper
486486
outerVolumeSpecName := opts.OuterVolumeSpecName
487-
volumeGidValue := opts.VolumeGidVolume
487+
volumeGIDValue := opts.VolumeGIDVolume
488488
volumeSpec := opts.VolumeSpec
489489

490490
podObj = mountedPod{
@@ -493,7 +493,7 @@ func (asw *actualStateOfWorld) CheckAndMarkVolumeAsUncertainViaReconstruction(op
493493
mounter: mounter,
494494
blockVolumeMapper: blockVolumeMapper,
495495
outerVolumeSpecName: outerVolumeSpecName,
496-
volumeGidValue: volumeGidValue,
496+
volumeGIDValue: volumeGIDValue,
497497
volumeSpec: volumeSpec,
498498
remountRequired: false,
499499
volumeMountStateForPod: operationexecutor.VolumeMountUncertain,
@@ -731,7 +731,7 @@ func (asw *actualStateOfWorld) AddPodToVolume(markVolumeOpts operationexecutor.M
731731
mounter := markVolumeOpts.Mounter
732732
blockVolumeMapper := markVolumeOpts.BlockVolumeMapper
733733
outerVolumeSpecName := markVolumeOpts.OuterVolumeSpecName
734-
volumeGidValue := markVolumeOpts.VolumeGidVolume
734+
volumeGIDValue := markVolumeOpts.VolumeGIDVolume
735735
volumeSpec := markVolumeOpts.VolumeSpec
736736
asw.Lock()
737737
defer asw.Unlock()
@@ -760,7 +760,7 @@ func (asw *actualStateOfWorld) AddPodToVolume(markVolumeOpts operationexecutor.M
760760
mounter: mounter,
761761
blockVolumeMapper: blockVolumeMapper,
762762
outerVolumeSpecName: outerVolumeSpecName,
763-
volumeGidValue: volumeGidValue,
763+
volumeGIDValue: volumeGIDValue,
764764
volumeSpec: volumeSpec,
765765
volumeMountStateForPod: markVolumeOpts.VolumeMountState,
766766
seLinuxMountContext: markVolumeOpts.SELinuxMountContext,
@@ -1311,7 +1311,7 @@ func getMountedVolume(
13111311
PodUID: mountedPod.podUID,
13121312
Mounter: mountedPod.mounter,
13131313
BlockVolumeMapper: mountedPod.blockVolumeMapper,
1314-
VolumeGidValue: mountedPod.volumeGidValue,
1314+
VolumeGIDValue: mountedPod.volumeGIDValue,
13151315
VolumeSpec: mountedPod.volumeSpec,
13161316
DeviceMountPath: attachedVolume.deviceMountPath,
13171317
SELinuxMountContext: seLinuxMountContext}}

pkg/kubelet/volumemanager/cache/desired_state_of_world.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type DesiredStateOfWorld interface {
6161
// added.
6262
// If a pod with the same unique name already exists under the specified
6363
// volume, this is a no-op.
64-
AddPodToVolume(podName types.UniquePodName, pod *v1.Pod, volumeSpec *volume.Spec, outerVolumeSpecName string, volumeGidValue string, seLinuxContainerContexts []*v1.SELinuxOptions) (v1.UniqueVolumeName, error)
64+
AddPodToVolume(podName types.UniquePodName, pod *v1.Pod, volumeSpec *volume.Spec, outerVolumeSpecName string, volumeGIDValue string, seLinuxContainerContexts []*v1.SELinuxOptions) (v1.UniqueVolumeName, error)
6565

6666
// MarkVolumesReportedInUse sets the ReportedInUse value to true for the
6767
// reportedVolumes. For volumes not in the reportedVolumes list, the
@@ -193,8 +193,8 @@ type volumeToMount struct {
193193
// the volume.DeviceMounter interface
194194
pluginIsDeviceMountable bool
195195

196-
// volumeGidValue contains the value of the GID annotation, if present.
197-
volumeGidValue string
196+
// volumeGIDValue contains the value of the GID annotation, if present.
197+
volumeGIDValue string
198198

199199
// reportedInUse indicates that the volume was successfully added to the
200200
// VolumesInUse field in the node's status.
@@ -262,7 +262,7 @@ func (dsw *desiredStateOfWorld) AddPodToVolume(
262262
pod *v1.Pod,
263263
volumeSpec *volume.Spec,
264264
outerVolumeSpecName string,
265-
volumeGidValue string,
265+
volumeGIDValue string,
266266
seLinuxContainerContexts []*v1.SELinuxOptions) (v1.UniqueVolumeName, error) {
267267
dsw.Lock()
268268
defer dsw.Unlock()
@@ -336,7 +336,7 @@ func (dsw *desiredStateOfWorld) AddPodToVolume(
336336
podsToMount: make(map[types.UniquePodName]podToMount),
337337
pluginIsAttachable: attachable,
338338
pluginIsDeviceMountable: deviceMountable,
339-
volumeGidValue: volumeGidValue,
339+
volumeGIDValue: volumeGIDValue,
340340
reportedInUse: false,
341341
desiredSizeLimit: sizeLimit,
342342
effectiveSELinuxMountFileLabel: effectiveSELinuxMountLabel,
@@ -574,7 +574,7 @@ func (dsw *desiredStateOfWorld) GetVolumesToMount() []VolumeToMount {
574574
PluginIsAttachable: volumeObj.pluginIsAttachable,
575575
PluginIsDeviceMountable: volumeObj.pluginIsDeviceMountable,
576576
OuterVolumeSpecName: podObj.outerVolumeSpecName,
577-
VolumeGidValue: volumeObj.volumeGidValue,
577+
VolumeGIDValue: volumeObj.volumeGIDValue,
578578
ReportedInUse: volumeObj.reportedInUse,
579579
MountRequestTime: podObj.mountRequestTime,
580580
DesiredSizeLimit: volumeObj.desiredSizeLimit,

pkg/kubelet/volumemanager/cache/desired_state_of_world_test.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func Test_AddPodToVolume_Positive_NewPodNewVolume(t *testing.T) {
6565

6666
// Act
6767
generatedVolumeName, err := dsw.AddPodToVolume(
68-
podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGidValue */, nil /* seLinuxContainerContexts */)
68+
podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGIDValue */, nil /* seLinuxContainerContexts */)
6969

7070
// Assert
7171
if err != nil {
@@ -89,8 +89,8 @@ func Test_AddPodToVolume_Positive_ExistingPodExistingVolume(t *testing.T) {
8989
dsw := NewDesiredStateOfWorld(volumePluginMgr, seLinuxTranslator)
9090
pod := &v1.Pod{
9191
ObjectMeta: metav1.ObjectMeta{
92-
Name: "pod3",
93-
UID: "pod3uid",
92+
Name: "pod4",
93+
UID: "pod4uid",
9494
},
9595
Spec: v1.PodSpec{
9696
Volumes: []v1.Volume{
@@ -111,13 +111,20 @@ func Test_AddPodToVolume_Positive_ExistingPodExistingVolume(t *testing.T) {
111111

112112
// Act
113113
generatedVolumeName, err := dsw.AddPodToVolume(
114-
podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGidValue */, nil /* seLinuxContainerContexts */)
115-
116-
// Assert
114+
podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGIDValue */, nil /* seLinuxContainerContexts */)
115+
if err != nil {
116+
t.Fatalf("AddPodToVolume failed. Expected: <no error> Actual: <%v>", err)
117+
}
118+
generatedVolumeName2, err := dsw.AddPodToVolume(
119+
podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGIDValue */, nil /* seLinuxContainerContexts */)
117120
if err != nil {
118121
t.Fatalf("AddPodToVolume failed. Expected: <no error> Actual: <%v>", err)
119122
}
120123

124+
// Assert
125+
if generatedVolumeName != generatedVolumeName2 {
126+
t.Fatalf("AddPodToVolume should generate same names, but got %q != %q", generatedVolumeName, generatedVolumeName2)
127+
}
121128
verifyVolumeExistsDsw(t, generatedVolumeName, "" /* SELinuxContext */, dsw)
122129
verifyVolumeExistsInVolumesToMount(
123130
t, generatedVolumeName, false /* expectReportedInUse */, dsw)
@@ -318,7 +325,7 @@ func Test_DeletePodFromVolume_Positive_PodExistsVolumeExists(t *testing.T) {
318325
volumeSpec := &volume.Spec{Volume: &pod.Spec.Volumes[0]}
319326
podName := util.GetUniquePodName(pod)
320327
generatedVolumeName, err := dsw.AddPodToVolume(
321-
podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGidValue */, nil /* seLinuxContainerContexts */)
328+
podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGIDValue */, nil /* seLinuxContainerContexts */)
322329
if err != nil {
323330
t.Fatalf("AddPodToVolume failed. Expected: <no error> Actual: <%v>", err)
324331
}
@@ -417,19 +424,19 @@ func Test_MarkVolumesReportedInUse_Positive_NewPodNewVolume(t *testing.T) {
417424
pod3Name := util.GetUniquePodName(pod3)
418425

419426
generatedVolume1Name, err := dsw.AddPodToVolume(
420-
pod1Name, pod1, volume1Spec, volume1Spec.Name(), "" /* volumeGidValue */, nil /* seLinuxContainerContexts */)
427+
pod1Name, pod1, volume1Spec, volume1Spec.Name(), "" /* volumeGIDValue */, nil /* seLinuxContainerContexts */)
421428
if err != nil {
422429
t.Fatalf("AddPodToVolume failed. Expected: <no error> Actual: <%v>", err)
423430
}
424431

425432
generatedVolume2Name, err := dsw.AddPodToVolume(
426-
pod2Name, pod2, volume2Spec, volume2Spec.Name(), "" /* volumeGidValue */, nil /* seLinuxContainerContexts */)
433+
pod2Name, pod2, volume2Spec, volume2Spec.Name(), "" /* volumeGIDValue */, nil /* seLinuxContainerContexts */)
427434
if err != nil {
428435
t.Fatalf("AddPodToVolume failed. Expected: <no error> Actual: <%v>", err)
429436
}
430437

431438
generatedVolume3Name, err := dsw.AddPodToVolume(
432-
pod3Name, pod3, volume3Spec, volume3Spec.Name(), "" /* volumeGidValue */, nil /* seLinuxContainerContexts */)
439+
pod3Name, pod3, volume3Spec, volume3Spec.Name(), "" /* volumeGIDValue */, nil /* seLinuxContainerContexts */)
433440
if err != nil {
434441
t.Fatalf("AddPodToVolume failed. Expected: <no error> Actual: <%v>", err)
435442
}
@@ -865,7 +872,7 @@ func Test_AddPodToVolume_SELinuxSinglePod(t *testing.T) {
865872

866873
// Act
867874
generatedVolumeName, err := dsw.AddPodToVolume(
868-
podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGidValue */, seLinuxContainerContexts)
875+
podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGIDValue */, seLinuxContainerContexts)
869876

870877
// Assert
871878
if tc.expectError {
@@ -1214,7 +1221,7 @@ func Test_AddPodToVolume_SELinux_MultiplePods(t *testing.T) {
12141221

12151222
// Act
12161223
generatedVolumeName, err := dsw.AddPodToVolume(
1217-
podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGidValue */, seLinuxContainerContexts)
1224+
podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGIDValue */, seLinuxContainerContexts)
12181225

12191226
// Assert
12201227
if err != nil {
@@ -1238,7 +1245,7 @@ func Test_AddPodToVolume_SELinux_MultiplePods(t *testing.T) {
12381245

12391246
// Act
12401247
generatedVolumeName2, err := dsw.AddPodToVolume(
1241-
pod2Name, pod2, volumeSpec, volumeSpec.Name(), "" /* volumeGidValue */, seLinuxContainerContexts)
1248+
pod2Name, pod2, volumeSpec, volumeSpec.Name(), "" /* volumeGIDValue */, seLinuxContainerContexts)
12421249
// Assert
12431250
if tc.expectError {
12441251
if err == nil {

pkg/kubelet/volumemanager/populator/desired_state_of_world_populator.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (dswp *desiredStateOfWorldPopulator) processPodVolumes(
312312
continue
313313
}
314314

315-
pvc, volumeSpec, volumeGidValue, err :=
315+
pvc, volumeSpec, volumeGIDValue, err :=
316316
dswp.createVolumeSpec(logger, podVolume, pod, mounts, devices)
317317
if err != nil {
318318
logger.Error(err, "Error processing volume", "pod", klog.KObj(pod), "volumeName", podVolume.Name)
@@ -323,7 +323,7 @@ func (dswp *desiredStateOfWorldPopulator) processPodVolumes(
323323

324324
// Add volume to desired state of world
325325
_, err = dswp.desiredStateOfWorld.AddPodToVolume(
326-
uniquePodName, pod, volumeSpec, podVolume.Name, volumeGidValue, seLinuxContainerContexts[podVolume.Name])
326+
uniquePodName, pod, volumeSpec, podVolume.Name, volumeGIDValue, seLinuxContainerContexts[podVolume.Name])
327327
if err != nil {
328328
logger.Error(err, "Failed to add volume to desiredStateOfWorld", "pod", klog.KObj(pod), "volumeName", podVolume.Name, "volumeSpecName", volumeSpec.Name())
329329
dswp.desiredStateOfWorld.AddErrorToPod(uniquePodName, err.Error())
@@ -494,7 +494,7 @@ func (dswp *desiredStateOfWorldPopulator) createVolumeSpec(
494494
pvName, pvcUID := pvc.Spec.VolumeName, pvc.UID
495495
logger.V(5).Info("Found bound PV for PVC", "PVC", klog.KRef(pod.Namespace, pvcSource.ClaimName), "PVCUID", pvcUID, "PVName", pvName)
496496
// Fetch actual PV object
497-
volumeSpec, volumeGidValue, err :=
497+
volumeSpec, volumeGIDValue, err :=
498498
dswp.getPVSpec(pvName, pvcSource.ReadOnly, pvcUID)
499499
if err != nil {
500500
return nil, nil, "", fmt.Errorf(
@@ -533,7 +533,7 @@ func (dswp *desiredStateOfWorldPopulator) createVolumeSpec(
533533
podVolume.Name,
534534
volumeMode)
535535
}
536-
return pvc, volumeSpec, volumeGidValue, nil
536+
return pvc, volumeSpec, volumeGIDValue, nil
537537
}
538538

539539
// Do not return the original volume object, since the source could mutate it
@@ -614,8 +614,8 @@ func (dswp *desiredStateOfWorldPopulator) getPVSpec(
614614
expectedClaimUID)
615615
}
616616

617-
volumeGidValue := getPVVolumeGidAnnotationValue(pv)
618-
return volume.NewSpecFromPersistentVolume(pv, pvcReadOnly), volumeGidValue, nil
617+
volumeGIDValue := getPVVolumeGidAnnotationValue(pv)
618+
return volume.NewSpecFromPersistentVolume(pv, pvcReadOnly), volumeGIDValue, nil
619619
}
620620

621621
func getPVVolumeGidAnnotationValue(pv *v1.PersistentVolume) string {

pkg/kubelet/volumemanager/populator/desired_state_of_world_populator_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func TestFindAndRemoveDeletedPodsWithUncertain(t *testing.T) {
406406
PodUID: pod.UID,
407407
VolumeName: expectedVolumeName,
408408
OuterVolumeSpecName: "dswp-test-volume-name",
409-
VolumeGidVolume: "",
409+
VolumeGIDVolume: "",
410410
VolumeSpec: volume.NewSpecFromPersistentVolume(pv, false),
411411
VolumeMountState: operationexecutor.VolumeMountUncertain,
412412
}
@@ -1392,7 +1392,7 @@ func reconcileASW(asw cache.ActualStateOfWorld, dsw cache.DesiredStateOfWorld, t
13921392
PodUID: volumeToMount.Pod.UID,
13931393
VolumeName: volumeToMount.VolumeName,
13941394
OuterVolumeSpecName: volumeToMount.OuterVolumeSpecName,
1395-
VolumeGidVolume: volumeToMount.VolumeGidValue,
1395+
VolumeGIDVolume: volumeToMount.VolumeGIDValue,
13961396
VolumeSpec: volumeToMount.VolumeSpec,
13971397
VolumeMountState: operationexecutor.VolumeMounted,
13981398
}

0 commit comments

Comments
 (0)