Skip to content

Commit d029a8e

Browse files
Merge pull request #15966 from jim-minter/template-test-fixes
Automatic merge from submit-queue Template test fixes - add all template tests to Conformance - don't use persistent templates for templateservicebroker tests - additional template instance controller readiness checking testing - increase tsb loglevel in extended tests fixes #15912 fixes #15961
2 parents 37382f4 + 3f68b9d commit d029a8e

16 files changed

+235
-126
lines changed

examples/templateservicebroker/templateservicebroker-template.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ objects:
5555
name: serving-cert
5656
- mountPath: /var/apiserver-config
5757
name: apiserver-config
58+
readinessProbe:
59+
httpGet:
60+
path: /healthz
61+
port: 8443
62+
scheme: HTTPS
5863
volumes:
5964
- name: serving-cert
6065
secret:

hack/update-generated-bindata.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pushd "${OS_ROOT}" > /dev/null
5959
popd > /dev/null
6060

6161
# If you hit this, please reduce other tests instead of importing more
62-
if [[ "$( cat "${OUTPUT_PARENT}/test/extended/testdata/bindata.go" | wc -c )" -gt 920000 ]]; then
62+
if [[ "$( cat "${OUTPUT_PARENT}/test/extended/testdata/bindata.go" | wc -c )" -gt 950000 ]]; then
6363
echo "error: extended bindata is $( cat "${OUTPUT_PARENT}/test/extended/testdata/bindata.go" | wc -c ) bytes, reduce the size of the import" 1>&2
6464
exit 1
6565
fi

pkg/oc/bootstrap/bindata.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/template/controller/templateinstance_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (c *TemplateInstanceController) sync(key string) error {
155155
}
156156

157157
if !templateInstance.HasCondition(templateapi.TemplateInstanceInstantiateFailure, kapi.ConditionTrue) {
158-
ready, err := c.checkReadiness(templateInstance)
158+
ready, err := c.checkReadiness(templateInstance, time.Now())
159159
if err != nil {
160160
glog.V(4).Infof("TemplateInstance controller: checkReadiness %s returned %v", key, err)
161161

@@ -205,8 +205,8 @@ func (c *TemplateInstanceController) sync(key string) error {
205205
return nil
206206
}
207207

208-
func (c *TemplateInstanceController) checkReadiness(templateInstance *templateapi.TemplateInstance) (bool, error) {
209-
if time.Now().After(templateInstance.CreationTimestamp.Add(readinessTimeout)) {
208+
func (c *TemplateInstanceController) checkReadiness(templateInstance *templateapi.TemplateInstance, now time.Time) (bool, error) {
209+
if now.After(templateInstance.CreationTimestamp.Add(readinessTimeout)) {
210210
return false, fmt.Errorf("Timeout")
211211
}
212212

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package controller
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"io/ioutil"
7+
"net/http"
8+
"testing"
9+
"time"
10+
11+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12+
"k8s.io/apimachinery/pkg/runtime"
13+
"k8s.io/client-go/rest"
14+
clientgotesting "k8s.io/client-go/testing"
15+
kapi "k8s.io/kubernetes/pkg/api"
16+
"k8s.io/kubernetes/pkg/apis/authorization"
17+
batchv1 "k8s.io/kubernetes/pkg/apis/batch/v1"
18+
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
19+
20+
"github.com/openshift/origin/pkg/client"
21+
templateapi "github.com/openshift/origin/pkg/template/apis/template"
22+
)
23+
24+
type roundtripper func(*http.Request) (*http.Response, error)
25+
26+
func (rt roundtripper) RoundTrip(r *http.Request) (*http.Response, error) {
27+
return rt(r)
28+
}
29+
30+
// TestControllerCheckReadiness verifies the basic behaviour of
31+
// TemplateInstanceController.checkReadiness(): that it can return ready, not
32+
// ready and timed out correctly.
33+
func TestControllerCheckReadiness(t *testing.T) {
34+
job := batchv1.Job{
35+
TypeMeta: metav1.TypeMeta{
36+
APIVersion: "batch/v1",
37+
Kind: "Job",
38+
},
39+
ObjectMeta: metav1.ObjectMeta{
40+
Annotations: map[string]string{
41+
templateapi.WaitForReadyAnnotation: "true",
42+
},
43+
},
44+
}
45+
46+
// fake generic API server, responds to any HTTP req with the above job
47+
// object
48+
fakerestconfig := &rest.Config{
49+
WrapTransport: func(http.RoundTripper) http.RoundTripper {
50+
return roundtripper(func(req *http.Request) (*http.Response, error) {
51+
b, err := json.Marshal(job)
52+
if err != nil {
53+
panic(err)
54+
}
55+
return &http.Response{
56+
StatusCode: http.StatusOK,
57+
Body: ioutil.NopCloser(bytes.NewBuffer(b)),
58+
}, nil
59+
})
60+
},
61+
}
62+
63+
// fakeclient, respond "allowed" to any subjectaccessreview
64+
fakeclientset := &fake.Clientset{}
65+
c := &TemplateInstanceController{
66+
restmapper: client.DefaultMultiRESTMapper(),
67+
kc: fakeclientset,
68+
config: fakerestconfig,
69+
}
70+
fakeclientset.AddReactor("create", "subjectaccessreviews", func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {
71+
return true, &authorization.SubjectAccessReview{Status: authorization.SubjectAccessReviewStatus{Allowed: true}}, nil
72+
})
73+
74+
now := time.Now()
75+
templateInstance := &templateapi.TemplateInstance{
76+
ObjectMeta: metav1.ObjectMeta{
77+
CreationTimestamp: metav1.Time{Time: now},
78+
},
79+
Spec: templateapi.TemplateInstanceSpec{
80+
Requester: &templateapi.TemplateInstanceRequester{},
81+
},
82+
Status: templateapi.TemplateInstanceStatus{
83+
Objects: []templateapi.TemplateInstanceObject{
84+
{
85+
Ref: kapi.ObjectReference{
86+
APIVersion: "batch/v1",
87+
Kind: "Job",
88+
Namespace: "namespace",
89+
Name: "name",
90+
},
91+
},
92+
},
93+
},
94+
}
95+
96+
// should report not ready yet
97+
ready, err := c.checkReadiness(templateInstance, now)
98+
if ready || err != nil {
99+
t.Error(ready, err)
100+
}
101+
102+
// should report timed out
103+
ready, err = c.checkReadiness(templateInstance, now.Add(readinessTimeout+1))
104+
if ready || err == nil || err.Error() != "Timeout" {
105+
t.Error(ready, err)
106+
}
107+
108+
// should report ready
109+
job.Status.CompletionTime = &metav1.Time{Time: now}
110+
ready, err = c.checkReadiness(templateInstance, now)
111+
if !ready || err != nil {
112+
t.Error(ready, err)
113+
}
114+
115+
// should report failed
116+
job.Status.Failed = int32(1)
117+
ready, err = c.checkReadiness(templateInstance, now)
118+
if ready || err == nil || err.Error() != "Readiness failed on Job namespace/name" {
119+
t.Error(ready, err)
120+
}
121+
}

test/extended/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ From the top-level origin directory, run
1212

1313
Where \<some_script\>.sh is one of the bucket scripts such as "core.sh".
1414

15-
You can further narrow the set of tests being run by passing
16-
`--ginkgo.focus='regex'` where 'regex' is a regular expression matching the
15+
You can further narrow the set of tests being run by setting the environment
16+
variable `FOCUS='regex'` where 'regex' is a regular expression matching the
1717
description of the test you want to run. For example one of the s2i tests
1818
(s2i_incremental.go) defines:
1919

2020
var _ = g.Describe("[builds][Slow] incremental s2i build", func() {
2121

22-
So you can write a focus regex that includes this test by passing
23-
`--ginkgo.focus='\[builds\]'` or `--ginkgo.focus='incremental s2i'`.
22+
So you can write a focus regex that includes this test by setting
23+
`FOCUS='\[builds\]'` or `FOCUS='incremental s2i'`.
2424

2525
Prerequisites
2626
-------------
@@ -53,18 +53,18 @@ $ export KUBECONFIG=${KUBECONFIG-$HOME/.kube/config}
5353
Then, for example:
5454
```console
5555
$ make build-extended-test
56-
$ TEST_ONLY=1 test/extended/core.sh --ginkgo.focus='\[builds\]'
56+
$ FOCUS='\[builds\]' TEST_ONLY=1 test/extended/core.sh
5757
```
5858

5959
By default the Kubernetes test framework will remove the project associated with
6060
your test spec when it completes, regardless of whether it fails or not.
61-
Origin's wrapper scripts may also do clean-up. This can be inconvenient when
62-
debugging. To stop this behaviour, set the `SKIP_TEARDOWN` environment variable
63-
and add the argument `--delete-namespace=false`:
61+
Origin's wrapper scripts may also do clean-up. Running tests in parallel can
62+
also hinder debugging. To stop these behaviours, set the `SKIP_TEARDOWN`
63+
environment variable, set `DELETE_NAMESPACE=false`, and set `PARALLEL_NODES=1`:
6464

6565
```console
6666
$ make build-extended-test
67-
$ SKIP_TEARDOWN=1 TEST_ONLY=1 test/extended/core.sh --delete-namespace=false --ginkgo.focus='\[builds\]'
67+
$ FOCUS='\[builds\]' TEST_ONLY=1 SKIP_TEARDOWN=1 DELETE_NAMESPACE=false PARALLEL_NODES=1 test/extended/core.sh
6868
```
6969

7070
Test labels

0 commit comments

Comments
 (0)