Recycle Pod Template Check
The kube-controller-manager has two command line arguments (--pv-recycler-pod-template-filepath-hostpath and --pv-recycler-pod-template-filepath-nfs) that specify a recycle pod template. The recycle pod template may not contain the volume that shall be recycled. A check is added to make sure that the recycle pod template contains at least a volume.
This commit is contained in:
@@ -104,3 +104,41 @@ func TestVolumePluginMgrFunc(t *testing.T) {
|
||||
t.Errorf("Wrong name: %s", plug.GetPluginName())
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ValidatePodTemplate(t *testing.T) {
|
||||
pod := &v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Volumes: []v1.Volume{
|
||||
{
|
||||
Name: "vol",
|
||||
VolumeSource: v1.VolumeSource{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
var want error
|
||||
if got := ValidateRecyclerPodTemplate(pod); got != want {
|
||||
t.Errorf("isPodTemplateValid(%v) returned (%v), want (%v)", pod.String(), got.Error(), want)
|
||||
}
|
||||
|
||||
// Check that the default recycle pod template is valid
|
||||
pod = NewPersistentVolumeRecyclerPodTemplate()
|
||||
want = nil
|
||||
if got := ValidateRecyclerPodTemplate(pod); got != want {
|
||||
t.Errorf("isPodTemplateValid(%v) returned (%v), want (%v)", pod.String(), got.Error(), want)
|
||||
}
|
||||
|
||||
pod = &v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Name: "pv-recycler",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
// want = an error
|
||||
if got := ValidateRecyclerPodTemplate(pod); got == nil {
|
||||
t.Errorf("isPodTemplateValid(%v) returned (%v), want (%v)", pod.String(), got, "Error: pod specification does not contain any volume(s).")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user