Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify PullPolicy handling #1922

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,4 +811,77 @@ env=["foo=bar"]`
gomega.Expect(config.Containers.BaseHostsFile).To(gomega.Equal("/etc/hosts2"))
gomega.Expect(config.Containers.EnableLabeledUsers).To(gomega.BeTrue())
})

It("ParsePullPolicy", func() {
for _, test := range []struct {
value string
policy PullPolicy
fail bool
}{
mheon marked this conversation as resolved.
Show resolved Hide resolved
{
value: "always",
policy: PullPolicyAlways,
},
{
value: "alWays",
policy: PullPolicyAlways,
},
{
value: "ALWAYS",
policy: PullPolicyAlways,
},
{
value: "never",
policy: PullPolicyNever,
},
{
value: "NEVER",
policy: PullPolicyNever,
},
{
value: "newer",
policy: PullPolicyNewer,
},
{
value: "ifnewer",
policy: PullPolicyNewer,
},
{
value: "NEWER",
policy: PullPolicyNewer,
},
{
value: "",
policy: PullPolicyMissing,
},
{
value: "missing",
policy: PullPolicyMissing,
},
{
value: "MISSING",
policy: PullPolicyMissing,
},
{
value: "IFMISSING",
vrothberg marked this conversation as resolved.
Show resolved Hide resolved
policy: PullPolicyMissing,
},
{
value: "ifnotpresent",
policy: PullPolicyMissing,
},
{
value: "bogus",
fail: true,
},
} {
p, err := ParsePullPolicy(test.value)
if test.fail {
gomega.Expect(err.Error()).To(gomega.Equal(fmt.Sprintf("unsupported pull policy %q", test.value)))
} else {
gomega.Expect(err).ToNot(gomega.HaveOccurred())
gomega.Expect(p).To(gomega.Equal(test.policy))
}
}
})
})
11 changes: 6 additions & 5 deletions pkg/config/pull_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"fmt"
"strings"
)

// PullPolicy determines how and which images are being pulled from a container
Expand Down Expand Up @@ -73,14 +74,14 @@ func (p PullPolicy) Validate() error {
// * "newer" <-> PullPolicyNewer (also "ifnewer")
// * "never" <-> PullPolicyNever
func ParsePullPolicy(s string) (PullPolicy, error) {
switch s {
case "always", "Always":
switch strings.ToLower(s) {
case "always":
return PullPolicyAlways, nil
case "missing", "Missing", "ifnotpresent", "IfNotPresent", "":
case "missing", "ifmissing", "ifnotpresent", "":
return PullPolicyMissing, nil
case "newer", "Newer", "ifnewer", "IfNewer":
case "newer", "ifnewer":
return PullPolicyNewer, nil
case "never", "Never":
case "never":
return PullPolicyNever, nil
default:
return PullPolicyUnsupported, fmt.Errorf("unsupported pull policy %q", s)
Expand Down