Skip to content

Commit 6fe240f

Browse files
author
Mengqi Yu
authored
use k8s casing for flag --image-pull-policy (#2551)
1 parent c16d0c9 commit 6fe240f

File tree

14 files changed

+28
-24
lines changed

14 files changed

+28
-24
lines changed

e2e/fn_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build docker
12
// +build docker
23

34
// Copyright 2021 Google LLC

e2e/testdata/fn-eval/image-pull-policy-always/.expected/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
testType: eval
1616
image: gcr.io/kpt-fn-demo/foo:v0.1
1717
sequential: true
18-
imagePullPolicy: always
18+
imagePullPolicy: Always
1919
exitCode: 1
2020
stdErr: foo

e2e/testdata/fn-eval/image-pull-policy-if-not-present/.expected/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
testType: eval
1616
image: gcr.io/kpt-fn-demo/bar:v0.1
1717
sequential: true
18-
imagePullPolicy: ifNotPresent
18+
imagePullPolicy: IfNotPresent
1919
exitCode: 1
2020
stdErr: foo

e2e/testdata/fn-eval/image-pull-policy-never/.expected/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
testType: eval
1616
image: gcr.io/kpt-fn/not-exist:v0.1
17-
imagePullPolicy: never
17+
imagePullPolicy: Never
1818
exitCode: 1
1919
stdErr: "No such image"

e2e/testdata/fn-render/image-pull-policy-always/.expected/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
imagePullPolicy: always
15+
imagePullPolicy: Always
1616
sequential: true
1717
exitCode: 1
1818
stdErr: foo

e2e/testdata/fn-render/image-pull-policy-if-not-present/.expected/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
imagePullPolicy: ifNotPresent
15+
imagePullPolicy: IfNotPresent
1616
sequential: true
1717
exitCode: 1
1818
stdErr: foo

e2e/testdata/fn-render/image-pull-policy-never/.expected/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
imagePullPolicy: never
15+
imagePullPolicy: Never
1616
exitCode: 1
1717
stdErr: "No such image"

internal/cmdrender/cmdrender.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424

2525
docs "github.com/GoogleContainerTools/kpt/internal/docs/generated/fndocs"
26+
"github.com/GoogleContainerTools/kpt/internal/fnruntime"
2627
"github.com/GoogleContainerTools/kpt/internal/printer"
2728
"github.com/GoogleContainerTools/kpt/internal/util/argutil"
2829
"github.com/GoogleContainerTools/kpt/internal/util/cmdutil"
@@ -44,8 +45,8 @@ func NewRunner(ctx context.Context, parent string) *Runner {
4445
"path to a directory to save function results")
4546
c.Flags().StringVarP(&r.dest, "output", "o", "",
4647
fmt.Sprintf("output resources are written to provided location. Allowed values: %s|%s|<OUT_DIR_PATH>", cmdutil.Stdout, cmdutil.Unwrap))
47-
c.Flags().StringVar(&r.imagePullPolicy, "image-pull-policy", "always",
48-
"pull image before running the container. It should be one of always, ifNotPresent and never.")
48+
c.Flags().StringVar(&r.imagePullPolicy, "image-pull-policy", string(fnruntime.AlwaysPull),
49+
fmt.Sprintf("pull image before running the container. It must be one of %s, %s and %s.", fnruntime.AlwaysPull, fnruntime.IfNotPresentPull, fnruntime.NeverPull))
4950
cmdutil.FixDocs("kpt", parent, c)
5051
r.Command = c
5152
return r

internal/fnruntime/container.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ const (
4040
defaultShortTimeout time.Duration = 5 * time.Second
4141
dockerBin string = "docker"
4242

43-
AlwaysPull ImagePullPolicy = "always"
44-
IfNotPresentPull ImagePullPolicy = "ifNotPresent"
45-
NeverPull ImagePullPolicy = "never"
43+
AlwaysPull ImagePullPolicy = "Always"
44+
IfNotPresentPull ImagePullPolicy = "IfNotPresent"
45+
NeverPull ImagePullPolicy = "Never"
4646
)
4747

4848
type ImagePullPolicy string

internal/util/cmdutil/cmdutil.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,20 @@ To install docker, follow the instructions at https://docs.docker.com/get-docker
107107
}
108108

109109
func ValidateImagePullPolicyValue(v string) error {
110-
if v != string(fnruntime.AlwaysPull) && v != string(fnruntime.IfNotPresentPull) && v != string(fnruntime.NeverPull) {
110+
v = strings.ToLower(v)
111+
if v != strings.ToLower(string(fnruntime.AlwaysPull)) &&
112+
v != strings.ToLower(string(fnruntime.IfNotPresentPull)) &&
113+
v != strings.ToLower(string(fnruntime.NeverPull)) {
111114
return fmt.Errorf("image pull policy must be one of %s, %s and %s", fnruntime.AlwaysPull, fnruntime.IfNotPresentPull, fnruntime.NeverPull)
112115
}
113116
return nil
114117
}
115118

116119
func StringToImagePullPolicy(v string) fnruntime.ImagePullPolicy {
117-
switch v {
118-
case string(fnruntime.NeverPull):
120+
switch strings.ToLower(v) {
121+
case strings.ToLower(string(fnruntime.NeverPull)):
119122
return fnruntime.NeverPull
120-
case string(fnruntime.IfNotPresentPull):
123+
case strings.ToLower(string(fnruntime.IfNotPresentPull)):
121124
return fnruntime.IfNotPresentPull
122125
default:
123126
return fnruntime.AlwaysPull

0 commit comments

Comments
 (0)