mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #7329 from chrismoos/check_claim_bound
Fix crash in kubelet when persistent volume claim is not bound.
This commit is contained in:
commit
8f30a21086
@ -57,6 +57,10 @@ func (plugin *persistentClaimPlugin) NewBuilder(spec *volume.Spec, podRef *api.O
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if claim.Status.VolumeRef == nil {
|
||||||
|
return nil, fmt.Errorf("The claim %+v is not yet bound to a volume", claim.Name)
|
||||||
|
}
|
||||||
|
|
||||||
pv, err := plugin.host.GetKubeClient().PersistentVolumes().Get(claim.Status.VolumeRef.Name)
|
pv, err := plugin.host.GetKubeClient().PersistentVolumes().Get(claim.Status.VolumeRef.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error finding persistent volume for claim: %+v\n", claim.Name)
|
glog.Errorf("Error finding persistent volume for claim: %+v\n", claim.Name)
|
||||||
|
@ -185,6 +185,56 @@ func TestNewBuilder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewBuilderClaimNotBound(t *testing.T) {
|
||||||
|
pv := &api.PersistentVolume{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Name: "pvC",
|
||||||
|
},
|
||||||
|
Spec: api.PersistentVolumeSpec{
|
||||||
|
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||||
|
GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{},
|
||||||
|
},
|
||||||
|
ClaimRef: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
claim := &api.PersistentVolumeClaim{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Name: "claimC",
|
||||||
|
Namespace: "nsA",
|
||||||
|
},
|
||||||
|
Status: api.PersistentVolumeClaimStatus{
|
||||||
|
Phase: api.ClaimBound,
|
||||||
|
VolumeRef: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
podVolume := api.VolumeSource{
|
||||||
|
PersistentVolumeClaimVolumeSource: &api.PersistentVolumeClaimVolumeSource{
|
||||||
|
ReadOnly: false,
|
||||||
|
ClaimName: "claimC",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
o := testclient.NewObjects(api.Scheme)
|
||||||
|
o.Add(pv)
|
||||||
|
o.Add(claim)
|
||||||
|
client := &testclient.Fake{ReactFn: testclient.ObjectReaction(o, latest.RESTMapper)}
|
||||||
|
|
||||||
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
|
plugMgr.InitPlugins(testProbeVolumePlugins(), newTestHost(t, client))
|
||||||
|
|
||||||
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/persistent-claim")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Can't find the plugin by name")
|
||||||
|
}
|
||||||
|
spec := &volume.Spec{
|
||||||
|
Name: "vol1",
|
||||||
|
VolumeSource: podVolume,
|
||||||
|
}
|
||||||
|
builder, err := plug.NewBuilder(spec, &api.ObjectReference{UID: types.UID("poduid")}, volume.VolumeOptions{})
|
||||||
|
if builder != nil {
|
||||||
|
t.Errorf("Expected a nil builder if the claim wasn't bound")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testProbeVolumePlugins() []volume.VolumePlugin {
|
func testProbeVolumePlugins() []volume.VolumePlugin {
|
||||||
allPlugins := []volume.VolumePlugin{}
|
allPlugins := []volume.VolumePlugin{}
|
||||||
allPlugins = append(allPlugins, gce_pd.ProbeVolumePlugins()...)
|
allPlugins = append(allPlugins, gce_pd.ProbeVolumePlugins()...)
|
||||||
|
Loading…
Reference in New Issue
Block a user