forked from knative/serving
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_pull_error_test.go
More file actions
107 lines (90 loc) · 3.72 KB
/
image_pull_error_test.go
File metadata and controls
107 lines (90 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// +build e2e
/*
Copyright 2019 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package e2e
import (
"fmt"
"testing"
"knative.dev/pkg/test/logstream"
"knative.dev/serving/pkg/apis/serving/v1alpha1"
serviceresourcenames "knative.dev/serving/pkg/reconciler/service/resources/names"
v1alpha1testing "knative.dev/serving/pkg/testing/v1alpha1"
"knative.dev/serving/test"
v1a1test "knative.dev/serving/test/v1alpha1"
)
func TestImagePullError(t *testing.T) {
t.Parallel()
cancel := logstream.Start(t)
defer cancel()
clients := Setup(t)
names := test.ResourceNames{
Service: test.ObjectNameForTest(t),
// TODO: Replace this when sha256 is broken.
Image: "ubuntu@sha256:0000000000000000000000000000000000000000000000000000000000000000",
}
defer test.TearDown(clients, names)
test.CleanupOnInterrupt(func() { test.TearDown(clients, names) })
t.Logf("Creating a new Service %s", names.Image)
var (
svc *v1alpha1.Service
err error
)
if svc, err = createLatestService(t, clients, names); err != nil {
t.Fatalf("Failed to create Service %s: %v", names.Service, err)
}
names.Config = serviceresourcenames.Configuration(svc)
err = v1a1test.WaitForServiceState(clients.ServingAlphaClient, names.Service, func(r *v1alpha1.Service) (bool, error) {
cond := r.Status.GetCondition(v1alpha1.ServiceConditionConfigurationsReady)
if cond != nil && !cond.IsUnknown() {
if cond.IsFalse() {
if cond.Reason == "RevisionFailed" {
return true, nil
}
}
t.Logf("Reason: %s ; Message: %s ; Status: %s", cond.Reason, cond.Message, cond.Status)
return true, fmt.Errorf("the service %s was not marked with expected error condition, but with (Reason=%q, Message=%q, Status=%q)",
names.Service, cond.Reason, cond.Message, cond.Status)
}
return false, nil
}, "ContainerUnpullable")
if err != nil {
t.Fatalf("Failed to validate service state: %s", err)
}
revisionName, err := revisionFromConfiguration(clients, names.Config)
if err != nil {
t.Fatalf("Failed to get revision from configuration %s: %v", names.Config, err)
}
t.Log("When the images are not pulled, the revision should have error status.")
err = v1a1test.CheckRevisionState(clients.ServingAlphaClient, revisionName, func(r *v1alpha1.Revision) (bool, error) {
cond := r.Status.GetCondition(v1alpha1.RevisionConditionReady)
if cond != nil {
if cond.Reason == "ImagePullBackOff" || cond.Reason == "ErrImagePull" {
return true, nil
}
return true, fmt.Errorf("the revision %s was not marked with expected error condition, but with (Reason=%q, Message=%q)",
revisionName, cond.Reason, cond.Message)
}
return false, nil
})
if err != nil {
t.Fatalf("Failed to validate revision state: %s", err)
}
}
// Wrote our own thing so that we can pass in an image by digest.
// knative/pkg/test.ImagePath currently assumes there's a tag, which fails to parse.
func createLatestService(t *testing.T, clients *test.Clients, names test.ResourceNames) (*v1alpha1.Service, error) {
opt := v1alpha1testing.WithInlineConfigSpec(*v1a1test.ConfigurationSpec(names.Image))
service := v1alpha1testing.ServiceWithoutNamespace(names.Service, opt)
v1a1test.LogResourceObject(t, v1a1test.ResourceObjects{Service: service})
return clients.ServingAlphaClient.Services.Create(service)
}