Skip to content

Commit c7cf3bf

Browse files
committed
run TSB test as part of the normal conformance bucket
1 parent 1243b94 commit c7cf3bf

File tree

9 files changed

+333
-77
lines changed

9 files changed

+333
-77
lines changed

test/testdata/templateservicebroker/templateservicebroker-template.yaml renamed to examples/templateservicebroker/templateservicebroker-template.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ objects:
3232
containers:
3333
- name: c
3434
image: ${IMAGE}
35-
imagePullPolicy: Never
3635
command:
3736
- "/usr/bin/openshift"
3837
- "start"

hack/update-generated-bindata.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ pushd "${OS_ROOT}" > /dev/null
3232
examples/heapster/... \
3333
examples/prometheus/... \
3434
examples/service-catalog/... \
35-
pkg/image/admission/imagepolicy/api/v1/... \
36-
test/testdata/templateservicebroker/...
35+
examples/templateservicebroker/... \
36+
pkg/image/admission/imagepolicy/api/v1/...
3737

3838
"$(os::util::find::gopath_binary go-bindata)" \
3939
-nocompress \
@@ -51,7 +51,8 @@ pushd "${OS_ROOT}" > /dev/null
5151
examples/sample-app \
5252
examples/prometheus/... \
5353
examples/hello-openshift \
54-
examples/jenkins/...
54+
examples/jenkins/... \
55+
examples/templateservicebroker/...
5556

5657
popd > /dev/null
5758

pkg/oc/bootstrap/bindata.go

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

pkg/oc/bootstrap/docker/openshift/templateservicebroker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
const (
2020
tsbNamespace = "openshift-template-service-broker"
2121
tsbTemplateName = "template-service-broker"
22-
tsbTemplateLocation = "test/testdata/templateservicebroker/templateservicebroker-template.yaml"
22+
tsbTemplateLocation = "examples/templateservicebroker/templateservicebroker-template.yaml"
2323
)
2424

2525
// InstallServiceCatalog checks whether the template service broker is installed and installs it if not already installed

pkg/openservicebroker/client/client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
)
1616

1717
type Client interface {
18+
Client() *http.Client
19+
1820
Catalog(ctx context.Context) (*api.CatalogResponse, error)
1921
Provision(ctx context.Context, instanceID string, preq *api.ProvisionRequest) (*api.ProvisionResponse, error)
2022
Deprovision(ctx context.Context, instanceID string) error
@@ -44,6 +46,10 @@ func newServerError(statusCode int, description string) error {
4446
return &ServerError{StatusCode: statusCode, Description: description}
4547
}
4648

49+
func (c *client) Client() *http.Client {
50+
return c.cli
51+
}
52+
4753
func (c *client) Catalog(ctx context.Context) (*api.CatalogResponse, error) {
4854
req, err := http.NewRequest(http.MethodGet, c.root+"/v2/catalog", nil)
4955
if err != nil {

test/extended/templates/helpers.go

Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
package templates
22

33
import (
4+
"crypto/tls"
5+
"encoding/json"
46
"fmt"
7+
"io/ioutil"
8+
"net/http"
9+
"os/exec"
10+
"time"
511

612
g "github.com/onsi/ginkgo"
713
o "github.com/onsi/gomega"
814

15+
kerrors "k8s.io/apimachinery/pkg/api/errors"
16+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17+
"k8s.io/apimachinery/pkg/util/wait"
18+
"k8s.io/client-go/pkg/apis/extensions"
19+
kapi "k8s.io/kubernetes/pkg/api"
20+
kapiv1 "k8s.io/kubernetes/pkg/api/v1"
21+
kexternalclientset "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
22+
e2e "k8s.io/kubernetes/test/e2e/framework"
23+
intframework "k8s.io/kubernetes/test/integration/framework"
24+
925
authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
26+
osbclient "github.com/openshift/origin/pkg/openservicebroker/client"
27+
templateapi "github.com/openshift/origin/pkg/template/apis/template"
1028
userapi "github.com/openshift/origin/pkg/user/apis/user"
1129
exutil "github.com/openshift/origin/test/extended/util"
12-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13-
kapi "k8s.io/kubernetes/pkg/api"
30+
)
31+
32+
const (
33+
tsbNS = "openshift-template-service-broker"
34+
tsbHost = "apiserver." + tsbNS + ".svc"
1435
)
1536

1637
func createUser(cli *exutil.CLI, name, role string) *userapi.User {
@@ -58,3 +79,98 @@ func setUser(cli *exutil.CLI, user *userapi.User) {
5879
cli.ChangeUser(user.Name)
5980
}
6081
}
82+
83+
// EnsureTSB makes sure the TSB is present where expected and returns a client to speak to it and
84+
// and exec command which provides the proxy. The caller must close the cmd, usually done in AfterEach
85+
func EnsureTSB(tsbOC *exutil.CLI) (osbclient.Client, *exec.Cmd) {
86+
exists := true
87+
if _, err := tsbOC.AdminKubeClient().Extensions().DaemonSets(tsbNS).Get("apiserver", metav1.GetOptions{}); err != nil {
88+
if !kerrors.IsNotFound(err) {
89+
o.Expect(err).NotTo(o.HaveOccurred())
90+
}
91+
exists = false
92+
}
93+
94+
if !exists {
95+
e2e.Logf("Installing TSB onto the cluster for testing")
96+
_, _, err := tsbOC.AsAdmin().WithoutNamespace().Run("create", "namespace").Args(tsbNS).Outputs()
97+
o.Expect(err).NotTo(o.HaveOccurred())
98+
configPath := exutil.FixturePath("..", "..", "examples", "templateservicebroker", "templateservicebroker-template.yaml")
99+
stdout, _, err := tsbOC.WithoutNamespace().Run("process").Args("-f", configPath).Outputs()
100+
o.Expect(err).NotTo(o.HaveOccurred())
101+
err = tsbOC.WithoutNamespace().AsAdmin().Run("create").Args("-f", "-").InputString(stdout).Execute()
102+
// this is weird, but we have to ignore this error in case some of this already exists (race between tests and the like)
103+
//o.Expect(err).NotTo(o.HaveOccurred())
104+
err = WaitForDaemonSetStatus(tsbOC.AdminKubeClient(), &extensions.DaemonSet{ObjectMeta: metav1.ObjectMeta{Name: "apiserver", Namespace: tsbNS}})
105+
o.Expect(err).NotTo(o.HaveOccurred())
106+
}
107+
108+
// we're trying to test the TSB, not the service. We're outside all the normal networks. Run a portforward to a particular
109+
// pod and test that
110+
pods, err := tsbOC.AdminKubeClient().Core().Pods(tsbNS).List(metav1.ListOptions{})
111+
o.Expect(err).NotTo(o.HaveOccurred())
112+
var pod *kapiv1.Pod
113+
for i := range pods.Items {
114+
currPod := pods.Items[i]
115+
for _, cond := range currPod.Status.Conditions {
116+
if cond.Type == kapiv1.PodReady && cond.Status == kapiv1.ConditionTrue {
117+
pod = &currPod
118+
break
119+
} else {
120+
out, _ := json.Marshal(currPod.Status)
121+
e2e.Logf("%v %v", currPod.Name, string(out))
122+
}
123+
}
124+
}
125+
if pod == nil {
126+
e2e.Failf("no ready pod found")
127+
}
128+
port, err := intframework.FindFreeLocalPort()
129+
o.Expect(err).NotTo(o.HaveOccurred())
130+
portForwardCmd, _, _, err := tsbOC.AsAdmin().WithoutNamespace().Run("port-forward").Args("-n="+tsbNS, pod.Name, fmt.Sprintf("%d:8443", port)).Background()
131+
o.Expect(err).NotTo(o.HaveOccurred())
132+
133+
svc, err := tsbOC.AdminKubeClient().Core().Services(tsbNS).Get("apiserver", metav1.GetOptions{})
134+
o.Expect(err).NotTo(o.HaveOccurred())
135+
tsbclient := osbclient.NewClient(&http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}}, fmt.Sprintf("https://localhost:%d%s", port, templateapi.ServiceBrokerRoot))
136+
137+
// wait to get back healthy from the tsb
138+
healthResponse := ""
139+
err = wait.Poll(e2e.Poll, 2*time.Minute, func() (bool, error) {
140+
resp, err := tsbclient.Client().Get("https://" + svc.Spec.ClusterIP + "/healthz")
141+
if err != nil {
142+
return false, err
143+
}
144+
defer resp.Body.Close()
145+
content, _ := ioutil.ReadAll(resp.Body)
146+
healthResponse = string(content)
147+
if resp.StatusCode == http.StatusOK {
148+
return true, nil
149+
}
150+
return false, nil
151+
})
152+
if err != nil {
153+
o.Expect(fmt.Errorf("error waiting for the TSB to be healthy: %v: %v", healthResponse, err)).NotTo(o.HaveOccurred())
154+
}
155+
156+
return tsbclient, portForwardCmd
157+
}
158+
159+
// Waits for the daemonset to have at least one ready pod
160+
func WaitForDaemonSetStatus(c kexternalclientset.Interface, d *extensions.DaemonSet) error {
161+
err := wait.Poll(e2e.Poll, 5*time.Minute, func() (bool, error) {
162+
var err error
163+
ds, err := c.Extensions().DaemonSets(d.Namespace).Get(d.Name, metav1.GetOptions{})
164+
if err != nil {
165+
return false, err
166+
}
167+
if ds.Status.NumberReady > 0 {
168+
return true, nil
169+
}
170+
return false, nil
171+
})
172+
if err != nil {
173+
return fmt.Errorf("error waiting for ds %q status to match expectation: %v", d.Name, err)
174+
}
175+
return nil
176+
}

0 commit comments

Comments
 (0)