forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
templateinstance_readiness.go
230 lines (194 loc) · 7.41 KB
/
templateinstance_readiness.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
package templates
import (
"errors"
"fmt"
"time"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/v1"
deployapi "github.com/openshift/origin/pkg/apps/apis/apps"
buildapi "github.com/openshift/origin/pkg/build/apis/build"
templateapi "github.com/openshift/origin/pkg/template/apis/template"
exutil "github.com/openshift/origin/test/extended/util"
)
// ensure that template instantiation waits for annotated objects
var _ = g.Describe("[Conformance][templates] templateinstance readiness test", func() {
defer g.GinkgoRecover()
var (
cli = exutil.NewCLI("templates", exutil.KubeConfigPath())
template *templateapi.Template
templateinstance *templateapi.TemplateInstance
templatefixture = exutil.FixturePath("..", "..", "examples", "quickstarts", "cakephp-mysql.json")
)
waitSettle := func() (bool, error) {
var err error
// must read the templateinstance before the build/dc
templateinstance, err = cli.TemplateClient().Template().TemplateInstances(cli.Namespace()).Get(templateinstance.Name, metav1.GetOptions{})
if err != nil {
return false, err
}
build, err := cli.BuildClient().Build().Builds(cli.Namespace()).Get("cakephp-mysql-example-1", metav1.GetOptions{})
if err != nil {
if kerrors.IsNotFound(err) {
err = nil
}
return false, err
}
dc, err := cli.AppsClient().Apps().DeploymentConfigs(cli.Namespace()).Get("cakephp-mysql-example", metav1.GetOptions{})
if err != nil {
if kerrors.IsNotFound(err) {
err = nil
}
return false, err
}
// if the instantiation has settled, quit
switch build.Status.Phase {
case buildapi.BuildPhaseCancelled, buildapi.BuildPhaseError, buildapi.BuildPhaseFailed:
return true, nil
case buildapi.BuildPhaseComplete:
var progressing, available *deployapi.DeploymentCondition
for i, condition := range dc.Status.Conditions {
switch condition.Type {
case deployapi.DeploymentProgressing:
progressing = &dc.Status.Conditions[i]
case deployapi.DeploymentAvailable:
available = &dc.Status.Conditions[i]
}
}
if (progressing != nil &&
progressing.Status == kapi.ConditionTrue &&
progressing.Reason == deployapi.NewRcAvailableReason &&
available != nil &&
available.Status == kapi.ConditionTrue) ||
(progressing != nil &&
progressing.Status == kapi.ConditionFalse) {
return true, nil
}
}
// the build or dc have not settled; the templateinstance must also
// indicate this
if templateinstance.HasCondition(templateapi.TemplateInstanceReady, kapi.ConditionTrue) {
return false, errors.New("templateinstance unexpectedly reported ready")
}
if templateinstance.HasCondition(templateapi.TemplateInstanceInstantiateFailure, kapi.ConditionTrue) {
return false, errors.New("templateinstance unexpectedly reported failure")
}
return false, nil
}
g.Context("", func() {
g.BeforeEach(func() {
err := exutil.WaitForBuilderAccount(cli.KubeClient().Core().ServiceAccounts(cli.Namespace()))
o.Expect(err).NotTo(o.HaveOccurred())
err = cli.Run("create").Args("-f", templatefixture).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
template, err = cli.TemplateClient().Template().Templates(cli.Namespace()).Get("cakephp-mysql-example", metav1.GetOptions{})
o.Expect(err).NotTo(o.HaveOccurred())
})
g.AfterEach(func() {
if g.CurrentGinkgoTestDescription().Failed {
exutil.DumpPodStates(cli)
exutil.DumpPodLogsStartingWith("", cli)
}
})
g.It("should report ready soon after all annotated objects are ready", func() {
var err error
templateinstance = &templateapi.TemplateInstance{
ObjectMeta: metav1.ObjectMeta{
Name: "templateinstance",
},
Spec: templateapi.TemplateInstanceSpec{
Template: *template,
},
}
g.By("instantiating the templateinstance")
templateinstance, err = cli.TemplateClient().Template().TemplateInstances(cli.Namespace()).Create(templateinstance)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("waiting for build and dc to settle")
err = wait.Poll(time.Second, 20*time.Minute, waitSettle)
if err != nil {
err := dumpObjectReadiness(cli, templateinstance)
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "error running dumpObjectReadiness: %v", err)
}
}
o.Expect(err).NotTo(o.HaveOccurred())
g.By("waiting for the templateinstance to indicate ready")
// in principle, this should happen within 20 seconds
err = wait.Poll(time.Second, 30*time.Second, func() (bool, error) {
templateinstance, err = cli.TemplateClient().Template().TemplateInstances(cli.Namespace()).Get(templateinstance.Name, metav1.GetOptions{})
if err != nil {
return false, err
}
if templateinstance.HasCondition(templateapi.TemplateInstanceInstantiateFailure, kapi.ConditionTrue) {
return false, errors.New("templateinstance unexpectedly reported failure")
}
return templateinstance.HasCondition(templateapi.TemplateInstanceReady, kapi.ConditionTrue), nil
})
if err != nil {
err := dumpObjectReadiness(cli, templateinstance)
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "error running dumpObjectReadiness: %v", err)
}
}
o.Expect(err).NotTo(o.HaveOccurred())
})
g.It("should report failed soon after an annotated objects has failed", func() {
var err error
secret, err := cli.KubeClient().Core().Secrets(cli.Namespace()).Create(&v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "secret",
},
Data: map[string][]byte{
"SOURCE_REPOSITORY_URL": []byte("https://bad"),
},
})
o.Expect(err).NotTo(o.HaveOccurred())
templateinstance = &templateapi.TemplateInstance{
ObjectMeta: metav1.ObjectMeta{
Name: "templateinstance",
},
Spec: templateapi.TemplateInstanceSpec{
Template: *template,
Secret: &kapi.LocalObjectReference{
Name: secret.Name,
},
},
}
g.By("instantiating the templateinstance")
templateinstance, err = cli.TemplateClient().Template().TemplateInstances(cli.Namespace()).Create(templateinstance)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("waiting for build and dc to settle")
err = wait.Poll(time.Second, 20*time.Minute, waitSettle)
if err != nil {
err := dumpObjectReadiness(cli, templateinstance)
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "error running dumpObjectReadiness: %v", err)
}
}
o.Expect(err).NotTo(o.HaveOccurred())
g.By("waiting for the templateinstance to indicate failed")
// in principle, this should happen within 20 seconds
err = wait.Poll(time.Second, 30*time.Second, func() (bool, error) {
templateinstance, err = cli.TemplateClient().Template().TemplateInstances(cli.Namespace()).Get(templateinstance.Name, metav1.GetOptions{})
if err != nil {
return false, err
}
if templateinstance.HasCondition(templateapi.TemplateInstanceReady, kapi.ConditionTrue) {
return false, errors.New("templateinstance unexpectedly reported ready")
}
return templateinstance.HasCondition(templateapi.TemplateInstanceInstantiateFailure, kapi.ConditionTrue), nil
})
if err != nil {
err := dumpObjectReadiness(cli, templateinstance)
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "error running dumpObjectReadiness: %v", err)
}
}
o.Expect(err).NotTo(o.HaveOccurred())
})
})
})