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

Pull if #3664

Merged
merged 1 commit into from
Jan 21, 2015
Merged

Pull if #3664

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/images.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ All users of the cluster will have access to any private registry in the `.docke
## Preloading Images

Be default, the kubelet will try to pull each image from the specified registry.
However, if the `imagePullPolicy` property of the container is set to `PullIfNotPresent` or `PullNever`,
However, if the `imagePullPolicy` property of the container is set to `IfNotPresent` or `Never`,
then a local image is used (preferentially or exclusively, respectively).

This can be used to preload certain images for speed or as an alternative to authenticating to a private registry.
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/latest/latest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
c.RandString(): c.RandString(),
}
},
func(p *internal.PullPolicy, c fuzz.Continue) {
policies := []internal.PullPolicy{internal.PullAlways, internal.PullNever, internal.PullIfNotPresent}
*p = policies[c.Rand.Intn(len(policies))]
},
)

func TestInternalRoundTrip(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/api/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ func fuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
c.RandString(): c.RandString(),
}
},

func(q *resource.Quantity, c fuzz.Continue) {
// Real Quantity fuzz testing is done elsewhere;
// this limited subset of functionality survives
Expand All @@ -156,6 +155,10 @@ func fuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
//q.Amount.SetScale(inf.Scale(-c.Intn(12)))
q.Amount.SetUnscaled(c.Int63n(1000))
},
func(p *api.PullPolicy, c fuzz.Continue) {
policies := []api.PullPolicy{api.PullAlways, api.PullNever, api.PullIfNotPresent}
*p = policies[c.Rand.Intn(len(policies))]
},
)
return f
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ type PullPolicy string

const (
// PullAlways means that kubelet always attempts to pull the latest image. Container will fail If the pull fails.
PullAlways PullPolicy = "PullAlways"
PullAlways PullPolicy = "Always"
// PullNever means that kubelet never pulls an image, but only uses a local image. Container will fail if the image isn't present
PullNever PullPolicy = "PullNever"
PullNever PullPolicy = "Never"
// PullIfNotPresent means that kubelet pulls if the image isn't present on disk. Container will fail if the image isn't present and the pull fails.
PullIfNotPresent PullPolicy = "PullIfNotPresent"
PullIfNotPresent PullPolicy = "IfNotPresent"
)

// Container represents a single container that is expected to be run on the host.
Expand Down
33 changes: 33 additions & 0 deletions pkg/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,39 @@ func init() {
}
return nil
},

func(in *newer.PullPolicy, out *PullPolicy, s conversion.Scope) error {
switch *in {
case newer.PullAlways:
*out = PullAlways
case newer.PullNever:
*out = PullNever
case newer.PullIfNotPresent:
*out = PullIfNotPresent
case "":
*out = ""
default:
// Let unknown values through - they will get caught by validation
*out = PullPolicy(*in)
}
return nil
},
func(in *PullPolicy, out *newer.PullPolicy, s conversion.Scope) error {
switch *in {
case PullAlways:
*out = newer.PullAlways
case PullNever:
*out = newer.PullNever
case PullIfNotPresent:
*out = newer.PullIfNotPresent
case "":
*out = ""
default:
// Let unknown values through - they will get caught by validation
*out = newer.PullPolicy(*in)
}
return nil
},
)
if err != nil {
// If one of the conversion functions is malformed, detect it immediately.
Expand Down
46 changes: 46 additions & 0 deletions pkg/api/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,49 @@ func TestServiceEmptySelector(t *testing.T) {
t.Errorf("unexpected selector: %#v", obj)
}
}

func TestPullPolicyConversion(t *testing.T) {
table := []struct {
versioned current.PullPolicy
internal newer.PullPolicy
}{
{
versioned: current.PullAlways,
internal: newer.PullAlways,
}, {
versioned: current.PullNever,
internal: newer.PullNever,
}, {
versioned: current.PullIfNotPresent,
internal: newer.PullIfNotPresent,
}, {
versioned: "",
internal: "",
}, {
versioned: "invalid value",
internal: "invalid value",
},
}
for _, item := range table {
var got newer.PullPolicy
err := Convert(&item.versioned, &got)
if err != nil {
t.Errorf("Unexpected error: %v", err)
continue
}
if e, a := item.internal, got; e != a {
t.Errorf("Expected: %q, got %q", e, a)
}
}
for _, item := range table {
var got current.PullPolicy
err := Convert(&item.internal, &got)
if err != nil {
t.Errorf("Unexpected error: %v", err)
continue
}
if e, a := item.versioned, got; e != a {
t.Errorf("Expected: %q, got %q", e, a)
}
}
}
33 changes: 33 additions & 0 deletions pkg/api/v1beta2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,39 @@ func init() {
}
return nil
},

func(in *newer.PullPolicy, out *PullPolicy, s conversion.Scope) error {
switch *in {
case newer.PullAlways:
*out = PullAlways
case newer.PullNever:
*out = PullNever
case newer.PullIfNotPresent:
*out = PullIfNotPresent
case "":
*out = ""
default:
// Let unknown values through - they will get caught by validation
*out = PullPolicy(*in)
}
return nil
},
func(in *PullPolicy, out *newer.PullPolicy, s conversion.Scope) error {
switch *in {
case PullAlways:
*out = newer.PullAlways
case PullNever:
*out = newer.PullNever
case PullIfNotPresent:
*out = newer.PullIfNotPresent
case "":
*out = ""
default:
// Let unknown values through - they will get caught by validation
*out = newer.PullPolicy(*in)
}
return nil
},
)
if err != nil {
// If one of the conversion functions is malformed, detect it immediately.
Expand Down
46 changes: 46 additions & 0 deletions pkg/api/v1beta2/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,49 @@ func TestNodeConversion(t *testing.T) {
t.Errorf("unexpected encoding: %s - %#v", m["kind"], string(data))
}
}

func TestPullPolicyConversion(t *testing.T) {
table := []struct {
versioned current.PullPolicy
internal newer.PullPolicy
}{
{
versioned: current.PullAlways,
internal: newer.PullAlways,
}, {
versioned: current.PullNever,
internal: newer.PullNever,
}, {
versioned: current.PullIfNotPresent,
internal: newer.PullIfNotPresent,
}, {
versioned: "",
internal: "",
}, {
versioned: "invalid value",
internal: "invalid value",
},
}
for _, item := range table {
var got newer.PullPolicy
err := newer.Scheme.Convert(&item.versioned, &got)
if err != nil {
t.Errorf("Unexpected error: %v", err)
continue
}
if e, a := item.internal, got; e != a {
t.Errorf("Expected: %q, got %q", e, a)
}
}
for _, item := range table {
var got current.PullPolicy
err := newer.Scheme.Convert(&item.internal, &got)
if err != nil {
t.Errorf("Unexpected error: %v", err)
continue
}
if e, a := item.versioned, got; e != a {
t.Errorf("Expected: %q, got %q", e, a)
}
}
}
6 changes: 3 additions & 3 deletions pkg/api/v1beta3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,11 @@ type PullPolicy string

const (
// PullAlways means that kubelet always attempts to pull the latest image. Container will fail If the pull fails.
PullAlways PullPolicy = "PullAlways"
PullAlways PullPolicy = "Always"
// PullNever means that kubelet never pulls an image, but only uses a local image. Container will fail if the image isn't present
PullNever PullPolicy = "PullNever"
PullNever PullPolicy = "Never"
// PullIfNotPresent means that kubelet pulls if the image isn't present on disk. Container will fail if the image isn't present and the pull fails.
PullIfNotPresent PullPolicy = "PullIfNotPresent"
PullIfNotPresent PullPolicy = "IfNotPresent"
)

// Container represents a single container that is expected to be run on the host.
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/validation/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
c.RandString(): c.RandString(),
}
},
func(p *api.PullPolicy, c fuzz.Continue) {
policies := []api.PullPolicy{api.PullAlways, api.PullNever, api.PullIfNotPresent}
*p = policies[c.Rand.Intn(len(policies))]
},
)

func TestLoad(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions pkg/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,27 +227,27 @@ func TestValidatePullPolicy(t *testing.T) {
}
testCases := map[string]T{
"NotPresent1": {
api.Container{Name: "abc", Image: "image:latest", ImagePullPolicy: "PullIfNotPresent"},
api.Container{Name: "abc", Image: "image:latest", ImagePullPolicy: "IfNotPresent"},
api.PullIfNotPresent,
},
"NotPresent2": {
api.Container{Name: "abc1", Image: "image", ImagePullPolicy: "PullIfNotPresent"},
api.Container{Name: "abc1", Image: "image", ImagePullPolicy: "IfNotPresent"},
api.PullIfNotPresent,
},
"Always1": {
api.Container{Name: "123", Image: "image:latest", ImagePullPolicy: "PullAlways"},
api.Container{Name: "123", Image: "image:latest", ImagePullPolicy: "Always"},
api.PullAlways,
},
"Always2": {
api.Container{Name: "1234", Image: "image", ImagePullPolicy: "PullAlways"},
api.Container{Name: "1234", Image: "image", ImagePullPolicy: "Always"},
api.PullAlways,
},
"Never1": {
api.Container{Name: "abc-123", Image: "image:latest", ImagePullPolicy: "PullNever"},
api.Container{Name: "abc-123", Image: "image:latest", ImagePullPolicy: "Never"},
api.PullNever,
},
"Never2": {
api.Container{Name: "abc-1234", Image: "image", ImagePullPolicy: "PullNever"},
api.Container{Name: "abc-1234", Image: "image", ImagePullPolicy: "Never"},
api.PullNever,
},
"DefaultToNotPresent": {api.Container{Name: "notPresent", Image: "image"}, api.PullIfNotPresent},
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/config/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestExtractFromHTTP(t *testing.T) {
Name: "1",
Image: "foo",
TerminationMessagePath: "/dev/termination-log",
ImagePullPolicy: "PullIfNotPresent"}},
ImagePullPolicy: "IfNotPresent"}},
},
},
api.BoundPod{
Expand All @@ -171,7 +171,7 @@ func TestExtractFromHTTP(t *testing.T) {
Name: "1",
Image: "foo",
TerminationMessagePath: "/dev/termination-log",
ImagePullPolicy: "PullIfNotPresent"}},
ImagePullPolicy: "IfNotPresent"}},
},
}),
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func TestSyncPodsCreatesNetAndContainerPullsImage(t *testing.T) {
},
Spec: api.PodSpec{
Containers: []api.Container{
{Name: "bar", Image: "something", ImagePullPolicy: "PullIfNotPresent"},
{Name: "bar", Image: "something", ImagePullPolicy: "IfNotPresent"},
},
},
},
Expand Down