Skip to content

Commit 542f2dc

Browse files
committed
Introduce new kubelet volume manager
This commit adds a new volume manager in kubelet that synchronizes volume mount/unmount (and attach/detach, if attach/detach controller is not enabled). This eliminates the race conditions between the pod creation loop and the orphaned volumes loops. It also removes the unmount/detach from the `syncPod()` path so volume clean up never blocks the `syncPod` loop.
1 parent 9b6a505 commit 542f2dc

File tree

85 files changed

+5521
-2067
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+5521
-2067
lines changed

Diff for: api/swagger-spec/v1.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16767,7 +16767,7 @@
1676716767
"items": {
1676816768
"$ref": "v1.UniqueVolumeName"
1676916769
},
16770-
"description": "List of attachable volume devices in use (mounted) by the node."
16770+
"description": "List of attachable volumes in use (mounted) by the node."
1677116771
}
1677216772
}
1677316773
},

Diff for: docs/api-reference/v1/definitions.html

+7-5
Original file line numberDiff line numberDiff line change
@@ -2766,6 +2766,10 @@ <h3 id="_v1_persistentvolumeclaimstatus">v1.PersistentVolumeClaimStatus</h3>
27662766
</tbody>
27672767
</table>
27682768

2769+
</div>
2770+
<div class="sect2">
2771+
<h3 id="_v1_uniquevolumename">v1.UniqueVolumeName</h3>
2772+
27692773
</div>
27702774
<div class="sect2">
27712775
<h3 id="_unversioned_labelselector">unversioned.LabelSelector</h3>
@@ -2806,9 +2810,7 @@ <h3 id="_unversioned_labelselector">unversioned.LabelSelector</h3>
28062810
</tr>
28072811
</tbody>
28082812
</table>
2809-
</div>
2810-
<div class="sect2">
2811-
<h3 id="_v1_uniquevolumename">v1.UniqueVolumeName</h3>
2813+
28122814
</div>
28132815
<div class="sect2">
28142816
<h3 id="_v1_endpointsubset">v1.EndpointSubset</h3>
@@ -4755,7 +4757,7 @@ <h3 id="_v1_nodestatus">v1.NodeStatus</h3>
47554757
</tr>
47564758
<tr>
47574759
<td class="tableblock halign-left valign-top"><p class="tableblock">volumesInUse</p></td>
4758-
<td class="tableblock halign-left valign-top"><p class="tableblock">List of attachable volume devices in use (mounted) by the node.</p></td>
4760+
<td class="tableblock halign-left valign-top"><p class="tableblock">List of attachable volumes in use (mounted) by the node.</p></td>
47594761
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
47604762
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#_v1_uniquevolumename">v1.UniqueVolumeName</a> array</p></td>
47614763
<td class="tableblock halign-left valign-top"></td>
@@ -8103,7 +8105,7 @@ <h3 id="_any">any</h3>
81038105
</div>
81048106
<div id="footer">
81058107
<div id="footer-text">
8106-
Last updated 2016-06-06 17:05:06 UTC
8108+
Last updated 2016-06-08 04:10:38 UTC
81078109
</div>
81088110
</div>
81098111
</body>

Diff for: pkg/api/v1/generated.proto

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pkg/api/v1/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2386,7 +2386,7 @@ type NodeStatus struct {
23862386
NodeInfo NodeSystemInfo `json:"nodeInfo,omitempty" protobuf:"bytes,7,opt,name=nodeInfo"`
23872387
// List of container images on this node
23882388
Images []ContainerImage `json:"images,omitempty" protobuf:"bytes,8,rep,name=images"`
2389-
// List of attachable volume devices in use (mounted) by the node.
2389+
// List of attachable volumes in use (mounted) by the node.
23902390
VolumesInUse []UniqueVolumeName `json:"volumesInUse,omitempty" protobuf:"bytes,9,rep,name=volumesInUse"`
23912391
}
23922392

Diff for: pkg/api/v1/types_swagger_doc_generated.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ var map_NodeStatus = map[string]string{
880880
"daemonEndpoints": "Endpoints of daemons running on the Node.",
881881
"nodeInfo": "Set of ids/uuids to uniquely identify the node. More info: http://releases.k8s.io/HEAD/docs/admin/node.md#node-info",
882882
"images": "List of container images on this node",
883-
"volumesInUse": "List of attachable volume devices in use (mounted) by the node.",
883+
"volumesInUse": "List of attachable volumes in use (mounted) by the node.",
884884
}
885885

886886
func (NodeStatus) SwaggerDoc() map[string]string {

Diff for: pkg/controller/persistentvolume/framework_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -980,14 +980,22 @@ func (plugin *mockVolumePlugin) Init(host vol.VolumeHost) error {
980980
return nil
981981
}
982982

983-
func (plugin *mockVolumePlugin) Name() string {
983+
func (plugin *mockVolumePlugin) GetPluginName() string {
984984
return mockPluginName
985985
}
986986

987+
func (plugin *mockVolumePlugin) GetVolumeName(spec *vol.Spec) (string, error) {
988+
return spec.Name(), nil
989+
}
990+
987991
func (plugin *mockVolumePlugin) CanSupport(spec *vol.Spec) bool {
988992
return true
989993
}
990994

995+
func (plugin *mockVolumePlugin) RequiresRemount() bool {
996+
return false
997+
}
998+
991999
func (plugin *mockVolumePlugin) NewMounter(spec *vol.Spec, podRef *api.Pod, opts vol.VolumeOptions) (vol.Mounter, error) {
9921000
return nil, fmt.Errorf("Mounter is not supported by this plugin")
9931001
}

Diff for: pkg/controller/persistentvolume/volume_host.go

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package persistentvolume
1818

1919
import (
2020
"fmt"
21+
"net"
2122

2223
"k8s.io/kubernetes/pkg/api"
2324
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
@@ -71,3 +72,11 @@ func (ctrl *PersistentVolumeController) GetWriter() io.Writer {
7172
func (ctrl *PersistentVolumeController) GetHostName() string {
7273
return ""
7374
}
75+
76+
func (ctrl *PersistentVolumeController) GetHostIP() (net.IP, error) {
77+
return nil, fmt.Errorf("PersistentVolumeController.GetHostIP() is not implemented")
78+
}
79+
80+
func (ctrl *PersistentVolumeController) GetRootContext() string {
81+
return ""
82+
}

Diff for: pkg/controller/volume/attach_detach_controller.go

+17-12
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,27 @@ package volume
2020

2121
import (
2222
"fmt"
23+
"net"
2324
"time"
2425

2526
"github.com/golang/glog"
2627
"k8s.io/kubernetes/pkg/api"
2728
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
2829
"k8s.io/kubernetes/pkg/cloudprovider"
2930
"k8s.io/kubernetes/pkg/controller/framework"
30-
"k8s.io/kubernetes/pkg/controller/volume/attacherdetacher"
3131
"k8s.io/kubernetes/pkg/controller/volume/cache"
3232
"k8s.io/kubernetes/pkg/controller/volume/reconciler"
3333
"k8s.io/kubernetes/pkg/types"
3434
"k8s.io/kubernetes/pkg/util/io"
3535
"k8s.io/kubernetes/pkg/util/mount"
3636
"k8s.io/kubernetes/pkg/util/runtime"
3737
"k8s.io/kubernetes/pkg/volume"
38+
"k8s.io/kubernetes/pkg/volume/util/operationexecutor"
3839
"k8s.io/kubernetes/pkg/volume/util/volumehelper"
3940
)
4041

4142
const (
42-
// loopPeriod is the ammount of time the reconciler loop waits between
43+
// loopPeriod is the amount of time the reconciler loop waits between
4344
// successive executions
4445
reconcilerLoopPeriod time.Duration = 100 * time.Millisecond
4546

@@ -103,7 +104,8 @@ func NewAttachDetachController(
103104

104105
adc.desiredStateOfWorld = cache.NewDesiredStateOfWorld(&adc.volumePluginMgr)
105106
adc.actualStateOfWorld = cache.NewActualStateOfWorld(&adc.volumePluginMgr)
106-
adc.attacherDetacher = attacherdetacher.NewAttacherDetacher(&adc.volumePluginMgr)
107+
adc.attacherDetacher =
108+
operationexecutor.NewOperationExecutor(&adc.volumePluginMgr)
107109
adc.reconciler = reconciler.NewReconciler(
108110
reconcilerLoopPeriod,
109111
reconcilerMaxWaitForUnmountDuration,
@@ -152,7 +154,7 @@ type attachDetachController struct {
152154
actualStateOfWorld cache.ActualStateOfWorld
153155

154156
// attacherDetacher is used to start asynchronous attach and operations
155-
attacherDetacher attacherdetacher.AttacherDetacher
157+
attacherDetacher operationexecutor.OperationExecutor
156158

157159
// reconciler is used to run an asynchronous periodic loop to reconcile the
158160
// desiredStateOfWorld with the actualStateOfWorld by triggering attach
@@ -205,7 +207,7 @@ func (adc *attachDetachController) nodeAdd(obj interface{}) {
205207
}
206208

207209
nodeName := node.Name
208-
if _, exists := node.Annotations[volumehelper.ControllerManagedAnnotation]; exists {
210+
if _, exists := node.Annotations[volumehelper.ControllerManagedAttachAnnotation]; exists {
209211
// Node specifies annotation indicating it should be managed by attach
210212
// detach controller. Add it to desired state of world.
211213
adc.desiredStateOfWorld.AddNode(nodeName)
@@ -284,7 +286,7 @@ func (adc *attachDetachController) processPodVolumes(
284286
continue
285287
}
286288

287-
uniquePodName := getUniquePodName(pod)
289+
uniquePodName := volumehelper.GetUniquePodName(pod)
288290
if addVolumes {
289291
// Add volume to desired state of world
290292
_, err := adc.desiredStateOfWorld.AddPod(
@@ -304,7 +306,7 @@ func (adc *attachDetachController) processPodVolumes(
304306
attachableVolumePlugin, volumeSpec)
305307
if err != nil {
306308
glog.V(10).Infof(
307-
"Failed to delete volume %q for pod %q/%q from desiredStateOfWorld. GenerateUniqueVolumeName failed with %v",
309+
"Failed to delete volume %q for pod %q/%q from desiredStateOfWorld. GetUniqueVolumeNameFromSpec failed with %v",
308310
podVolume.Name,
309311
pod.Namespace,
310312
pod.Name,
@@ -502,11 +504,6 @@ func (adc *attachDetachController) processVolumesInUse(
502504
}
503505
}
504506

505-
// getUniquePodName returns a unique name to reference pod by in memory caches
506-
func getUniquePodName(pod *api.Pod) types.UniquePodName {
507-
return types.NamespacedName{Namespace: pod.Namespace, Name: pod.Name}.UniquePodName()
508-
}
509-
510507
// VolumeHost implementation
511508
// This is an unfortunate requirement of the current factoring of volume plugin
512509
// initializing code. It requires kubelet specific methods used by the mounting
@@ -552,3 +549,11 @@ func (adc *attachDetachController) GetWriter() io.Writer {
552549
func (adc *attachDetachController) GetHostName() string {
553550
return ""
554551
}
552+
553+
func (adc *attachDetachController) GetHostIP() (net.IP, error) {
554+
return nil, fmt.Errorf("GetHostIP() not supported by Attach/Detach controller's VolumeHost implementation")
555+
}
556+
557+
func (adc *attachDetachController) GetRootContext() string {
558+
return ""
559+
}

0 commit comments

Comments
 (0)