Skip to content

Commit 0550dcd

Browse files
committed
run TSB test as part of the normal conformance bucket
1 parent 07ec3d2 commit 0550dcd

File tree

8 files changed

+330
-76
lines changed

8 files changed

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

0 commit comments

Comments
 (0)