mirror of https://github.com/k3s-io/k3s
Merge pull request #36221 from pospispa/86-5-add-checks-and-documentation-about-template-pods-for-recycling
Automatic merge from submit-queue (batch tested with PRs 37959, 36221) 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. cc: @jsafranepull/6/head
commit
3fe288d74e
|
@ -183,6 +183,9 @@ func AttemptToLoadRecycler(path string, config *volume.VolumeConfig) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = volume.ValidateRecyclerPodTemplate(recyclerPod); err != nil {
|
||||
return fmt.Errorf("Pod specification (%v): %v", path, err)
|
||||
}
|
||||
config.RecyclerPodTemplate = recyclerPod
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -563,3 +563,15 @@ func NewPersistentVolumeRecyclerPodTemplate() *v1.Pod {
|
|||
}
|
||||
return pod
|
||||
}
|
||||
|
||||
// Check validity of recycle pod template
|
||||
// List of checks:
|
||||
// - at least one volume is defined in the recycle pod template
|
||||
// If successful, returns nil
|
||||
// if unsuccessful, returns an error.
|
||||
func ValidateRecyclerPodTemplate(pod *v1.Pod) error {
|
||||
if len(pod.Spec.Volumes) < 1 {
|
||||
return fmt.Errorf("does not contain any volume(s)")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -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).")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue