mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
kubeadm: fix image pull policy integration
If the user has not specified a pull policy we must assume a default of v1.PullIfNotPresent. Add some extra verbose output to help users monitor what policy is used and what images are skipped / pulled. Use "fallthrough" and case handle "v1.PullAlways". Update unit test.
This commit is contained in:
parent
2453f07e93
commit
3b36e6bcea
@ -832,9 +832,15 @@ func (ImagePullCheck) Name() string {
|
||||
|
||||
// Check pulls images required by kubeadm. This is a mutating check
|
||||
func (ipc ImagePullCheck) Check() (warnings, errorList []error) {
|
||||
policy := ipc.imagePullPolicy
|
||||
if len(policy) == 0 {
|
||||
policy = v1.PullIfNotPresent // Default behavior if the policy is unset
|
||||
}
|
||||
klog.V(1).Infof("using image pull policy: %s", policy)
|
||||
for _, image := range ipc.imageList {
|
||||
switch ipc.imagePullPolicy {
|
||||
switch policy {
|
||||
case v1.PullNever:
|
||||
klog.V(1).Infof("skipping pull of image: %s", image)
|
||||
continue
|
||||
case v1.PullIfNotPresent:
|
||||
ret, err := ipc.runtime.ImageExists(image)
|
||||
@ -845,11 +851,16 @@ func (ipc ImagePullCheck) Check() (warnings, errorList []error) {
|
||||
if err != nil {
|
||||
errorList = append(errorList, errors.Wrapf(err, "failed to check if image %s exists", image))
|
||||
}
|
||||
}
|
||||
|
||||
klog.V(1).Infof("pulling %s", image)
|
||||
if err := ipc.runtime.PullImage(image); err != nil {
|
||||
errorList = append(errorList, errors.Wrapf(err, "failed to pull image %s", image))
|
||||
fallthrough // Proceed with pulling the image if it does not exist
|
||||
case v1.PullAlways:
|
||||
klog.V(1).Infof("pulling: %s", image)
|
||||
if err := ipc.runtime.PullImage(image); err != nil {
|
||||
errorList = append(errorList, errors.Wrapf(err, "failed to pull image %s", image))
|
||||
}
|
||||
default:
|
||||
// If the policy is unknown return early with an error
|
||||
errorList = append(errorList, errors.Errorf("unsupported pull policy %q", policy))
|
||||
return warnings, errorList
|
||||
}
|
||||
}
|
||||
return warnings, errorList
|
||||
|
@ -31,7 +31,6 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
@ -924,7 +923,7 @@ func TestImagePullCheck(t *testing.T) {
|
||||
check := ImagePullCheck{
|
||||
runtime: containerRuntime,
|
||||
imageList: []string{"img1", "img2", "img3"},
|
||||
imagePullPolicy: v1.PullIfNotPresent,
|
||||
imagePullPolicy: "", // should be defaulted to v1.PullIfNotPresent
|
||||
}
|
||||
warnings, errors := check.Check()
|
||||
if len(warnings) != 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user