Merge pull request #7329 from chrismoos/check_claim_bound

Fix crash in kubelet when persistent volume claim is not bound.
pull/6/head
Jerzy Szczepkowski 2015-04-27 09:05:25 +02:00
commit 8f30a21086
2 changed files with 54 additions and 0 deletions

View File

@ -57,6 +57,10 @@ func (plugin *persistentClaimPlugin) NewBuilder(spec *volume.Spec, podRef *api.O
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)
if err != nil {
glog.Errorf("Error finding persistent volume for claim: %+v\n", claim.Name)

View File

@ -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 {
allPlugins := []volume.VolumePlugin{}
allPlugins = append(allPlugins, gce_pd.ProbeVolumePlugins()...)