added cast checks to controllers to prevent nil panics

This commit is contained in:
markturansky
2015-12-01 10:18:02 -05:00
parent 7de177b8b5
commit 4aacb76149
3 changed files with 66 additions and 20 deletions

View File

@@ -25,6 +25,7 @@ import (
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/client/cache"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/host_path"
@@ -369,6 +370,27 @@ func TestBindingWithExamples(t *testing.T) {
}
}
func TestCasting(t *testing.T) {
client := &testclient.Fake{}
binder := NewPersistentVolumeClaimBinder(client, 1*time.Second)
pv := &api.PersistentVolume{}
unk := cache.DeletedFinalStateUnknown{}
pvc := &api.PersistentVolumeClaim{
ObjectMeta: api.ObjectMeta{Name: "foo"},
Status: api.PersistentVolumeClaimStatus{Phase: api.ClaimBound},
}
// none of these should fail casting.
// the real test is not failing when passed DeletedFinalStateUnknown in the deleteHandler
binder.addVolume(pv)
binder.updateVolume(pv, pv)
binder.deleteVolume(pv)
binder.deleteVolume(unk)
binder.addClaim(pvc)
binder.updateClaim(pvc, pvc)
}
type mockBinderClient struct {
volume *api.PersistentVolume
claim *api.PersistentVolumeClaim