forked from knative/serving
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_pull_error_test.go
94 lines (79 loc) · 3.12 KB
/
image_pull_error_test.go
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
//go:build e2e
// +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"
"k8s.io/apimachinery/pkg/util/sets"
v1 "knative.dev/serving/pkg/apis/serving/v1"
"knative.dev/serving/test"
v1test "knative.dev/serving/test/v1"
)
func TestImagePullError(t *testing.T) {
t.Parallel()
clients := Setup(t)
names := test.ResourceNames{
Config: test.ObjectNameForTest(t),
// TODO: Replace this when sha256 is broken.
Image: "ubuntu@sha256:0000000000000000000000000000000000000000000000000000000000000000",
}
test.EnsureTearDown(t, clients, &names)
t.Logf("Creating a new Configuration %s:%s", names.Config, names.Image)
_, err := createLatestConfig(t, clients, names)
if err != nil {
t.Fatalf("Failed to create Config %s: %v", names.Config, err)
}
const wantCfgReason = "RevisionFailed"
if err := v1test.WaitForConfigurationState(clients.ServingClient, names.Config, func(r *v1.Configuration) (bool, error) {
cond := r.Status.GetCondition(v1.ConfigurationConditionReady)
if cond != nil && !cond.IsUnknown() {
if cond.IsFalse() {
if cond.Reason == wantCfgReason {
return true, nil
}
}
t.Logf("Reason: %q; Message: %q; Status: %q", cond.Reason, cond.Message, cond.Status)
return true, fmt.Errorf("the Config %s ReadyCondition = (Reason=%q, Message=%q, Status=%q), wantReason: %q",
names.Config, cond.Reason, cond.Message, cond.Status, wantCfgReason)
}
return false, nil
}, "ContainerUnpullable"); err != nil {
t.Fatal("Failed to validate configuration state:", 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.")
wantRevReasons := sets.New("ImagePullBackOff", "ErrImagePull")
if err := v1test.CheckRevisionState(clients.ServingClient, revisionName, func(r *v1.Revision) (bool, error) {
cond := r.Status.GetCondition(v1.RevisionConditionReady)
if cond != nil {
if wantRevReasons.Has(cond.Reason) {
return true, nil
}
return true, fmt.Errorf("the Revision %s ReadyCondition = (Reason=%q, Message=%q), wantReasons: %v",
revisionName, cond.Reason, cond.Message, wantRevReasons.UnsortedList())
}
return false, nil
}); err != nil {
t.Fatal("Failed to validate revision state:", err)
}
}
func createLatestConfig(t *testing.T, clients *test.Clients, names test.ResourceNames) (*v1.Configuration, error) {
return v1test.CreateConfiguration(t, clients, names, func(c *v1.Configuration) {
c.Spec = *v1test.ConfigurationSpec(names.Image)
})
}