Remove e2e boilerplate
This commit is contained in:
parent
a06f724efa
commit
83dc4607c5
44 changed files with 432 additions and 871 deletions
|
|
@ -17,10 +17,9 @@ limitations under the License.
|
|||
package framework
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
|
|
@ -30,23 +29,23 @@ import (
|
|||
)
|
||||
|
||||
// NewEchoDeployment creates a new single replica deployment of the echoserver image in a particular namespace
|
||||
func (f *Framework) NewEchoDeployment() error {
|
||||
return f.NewEchoDeploymentWithReplicas(1)
|
||||
func (f *Framework) NewEchoDeployment() {
|
||||
f.NewEchoDeploymentWithReplicas(1)
|
||||
}
|
||||
|
||||
// NewEchoDeploymentWithReplicas creates a new deployment of the echoserver image in a particular namespace. Number of
|
||||
// replicas is configurable
|
||||
func (f *Framework) NewEchoDeploymentWithReplicas(replicas int32) error {
|
||||
return f.NewDeployment("http-svc", "gcr.io/kubernetes-e2e-test-images/echoserver:2.1", 8080, replicas)
|
||||
func (f *Framework) NewEchoDeploymentWithReplicas(replicas int32) {
|
||||
f.NewDeployment("http-svc", "gcr.io/kubernetes-e2e-test-images/echoserver:2.1", 8080, replicas)
|
||||
}
|
||||
|
||||
// NewHttpbinDeployment creates a new single replica deployment of the httpbin image in a particular namespace.
|
||||
func (f *Framework) NewHttpbinDeployment() error {
|
||||
return f.NewDeployment("httpbin", "kennethreitz/httpbin", 80, 1)
|
||||
func (f *Framework) NewHttpbinDeployment() {
|
||||
f.NewDeployment("httpbin", "kennethreitz/httpbin", 80, 1)
|
||||
}
|
||||
|
||||
// NewDeployment creates a new deployment in a particular namespace.
|
||||
func (f *Framework) NewDeployment(name, image string, port int32, replicas int32) error {
|
||||
func (f *Framework) NewDeployment(name, image string, port int32, replicas int32) {
|
||||
deployment := &extensions.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
|
|
@ -86,20 +85,13 @@ func (f *Framework) NewDeployment(name, image string, port int32, replicas int32
|
|||
}
|
||||
|
||||
d, err := f.EnsureDeployment(deployment)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if d == nil {
|
||||
return fmt.Errorf("unexpected error creating deployement %s", name)
|
||||
}
|
||||
Expect(err).NotTo(HaveOccurred(), "failed to create a deployment")
|
||||
Expect(d).NotTo(BeNil(), "expected a deployement but none returned")
|
||||
|
||||
err = WaitForPodsReady(f.KubeClientSet, 5*time.Minute, int(replicas), f.IngressController.Namespace, metav1.ListOptions{
|
||||
LabelSelector: fields.SelectorFromSet(fields.Set(d.Spec.Template.ObjectMeta.Labels)).String(),
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to wait for to become ready")
|
||||
}
|
||||
Expect(err).NotTo(HaveOccurred(), "failed to wait for to become ready")
|
||||
|
||||
service := &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
@ -121,14 +113,6 @@ func (f *Framework) NewDeployment(name, image string, port int32, replicas int32
|
|||
},
|
||||
}
|
||||
|
||||
s, err := f.EnsureService(service)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if s == nil {
|
||||
return fmt.Errorf("unexpected error creating service %s", name)
|
||||
}
|
||||
|
||||
return nil
|
||||
s := f.EnsureService(service)
|
||||
Expect(s).NotTo(BeNil(), "expected a service but none returned")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,14 +117,10 @@ func (f *Framework) BeforeEach() {
|
|||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
HTTPURL, err := f.GetNginxURL(HTTP)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
HTTPURL := f.GetNginxURL(HTTP)
|
||||
f.IngressController.HTTPURL = HTTPURL
|
||||
|
||||
HTTPSURL, err := f.GetNginxURL(HTTPS)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
HTTPSURL := f.GetNginxURL(HTTPS)
|
||||
f.IngressController.HTTPSURL = HTTPSURL
|
||||
|
||||
// we wait for any change in the informers and SSL certificate generation
|
||||
|
|
@ -154,8 +150,10 @@ func IngressNginxDescribe(text string, body func()) bool {
|
|||
|
||||
// GetNginxIP returns the IP address of the minikube cluster
|
||||
// where the NGINX ingress controller is running
|
||||
func (f *Framework) GetNginxIP() (string, error) {
|
||||
return os.Getenv("NODE_IP"), nil
|
||||
func (f *Framework) GetNginxIP() string {
|
||||
nodeIP := os.Getenv("NODE_IP")
|
||||
Expect(nodeIP).NotTo(BeEmpty(), "env variable NODE_IP is empty")
|
||||
return nodeIP
|
||||
}
|
||||
|
||||
// GetNginxPort returns the number of TCP port where NGINX is running
|
||||
|
|
@ -178,28 +176,24 @@ func (f *Framework) GetNginxPort(name string) (int, error) {
|
|||
}
|
||||
|
||||
// GetNginxURL returns the URL should be used to make a request to NGINX
|
||||
func (f *Framework) GetNginxURL(scheme RequestScheme) (string, error) {
|
||||
ip, err := f.GetNginxIP()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
func (f *Framework) GetNginxURL(scheme RequestScheme) string {
|
||||
ip := f.GetNginxIP()
|
||||
port, err := f.GetNginxPort(fmt.Sprintf("%v", scheme))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
Expect(err).NotTo(HaveOccurred(), "unexpected error obtaning NGINX Port")
|
||||
|
||||
return fmt.Sprintf("%v://%v:%v", scheme, ip, port), nil
|
||||
return fmt.Sprintf("%v://%v:%v", scheme, ip, port)
|
||||
}
|
||||
|
||||
// WaitForNginxServer waits until the nginx configuration contains a particular server section
|
||||
func (f *Framework) WaitForNginxServer(name string, matcher func(cfg string) bool) error {
|
||||
return wait.Poll(Poll, time.Minute*5, f.matchNginxConditions(name, matcher))
|
||||
func (f *Framework) WaitForNginxServer(name string, matcher func(cfg string) bool) {
|
||||
err := wait.Poll(Poll, time.Minute*5, f.matchNginxConditions(name, matcher))
|
||||
Expect(err).NotTo(HaveOccurred(), "unexpected error waiting for nginx server condition/s")
|
||||
}
|
||||
|
||||
// WaitForNginxConfiguration waits until the nginx configuration contains a particular configuration
|
||||
func (f *Framework) WaitForNginxConfiguration(matcher func(cfg string) bool) error {
|
||||
return wait.Poll(Poll, time.Minute*5, f.matchNginxConditions("", matcher))
|
||||
func (f *Framework) WaitForNginxConfiguration(matcher func(cfg string) bool) {
|
||||
err := wait.Poll(Poll, time.Minute*5, f.matchNginxConditions("", matcher))
|
||||
Expect(err).NotTo(HaveOccurred(), "unexpected error waiting for nginx server condition/s")
|
||||
}
|
||||
|
||||
func nginxLogs(client kubernetes.Interface, namespace string) (string, error) {
|
||||
|
|
@ -320,16 +314,12 @@ func (f *Framework) GetNginxConfigMapData() (map[string]string, error) {
|
|||
}
|
||||
|
||||
// SetNginxConfigMapData sets ingress-nginx's nginx-configuration configMap data
|
||||
func (f *Framework) SetNginxConfigMapData(cmData map[string]string) error {
|
||||
func (f *Framework) SetNginxConfigMapData(cmData map[string]string) {
|
||||
// Needs to do a Get and Set, Update will not take just the Data field
|
||||
// or a configMap that is not the very last revision
|
||||
config, err := f.getNginxConfigMap()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if config == nil {
|
||||
return fmt.Errorf("Unable to get nginx-configuration configMap")
|
||||
}
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(config).NotTo(BeNil(), "expected a configmap but none returned")
|
||||
|
||||
config.Data = cmData
|
||||
|
||||
|
|
@ -337,25 +327,19 @@ func (f *Framework) SetNginxConfigMapData(cmData map[string]string) error {
|
|||
CoreV1().
|
||||
ConfigMaps(f.IngressController.Namespace).
|
||||
Update(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateNginxConfigMapData updates single field in ingress-nginx's nginx-configuration map data
|
||||
func (f *Framework) UpdateNginxConfigMapData(key string, value string) error {
|
||||
func (f *Framework) UpdateNginxConfigMapData(key string, value string) {
|
||||
config, err := f.GetNginxConfigMapData()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
Expect(err).NotTo(HaveOccurred(), "unexpected error reading configmap")
|
||||
|
||||
config[key] = value
|
||||
|
||||
return f.SetNginxConfigMapData(config)
|
||||
f.SetNginxConfigMapData(config)
|
||||
}
|
||||
|
||||
// UpdateDeployment runs the given updateFunc on the deployment and waits for it to be updated
|
||||
|
|
@ -437,6 +421,7 @@ func newSingleIngress(name, path, host, ns, service string, port int, annotation
|
|||
},
|
||||
},
|
||||
}
|
||||
|
||||
if withTLS {
|
||||
ing.Spec.TLS = []extensions.IngressTLS{
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,10 +17,9 @@ limitations under the License.
|
|||
package framework
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
|
|
@ -31,13 +30,13 @@ import (
|
|||
|
||||
// NewGRPCFortuneTellerDeployment creates a new single replica
|
||||
// deployment of the fortune teller image in a particular namespace
|
||||
func (f *Framework) NewGRPCFortuneTellerDeployment() error {
|
||||
return f.NewNewGRPCFortuneTellerDeploymentWithReplicas(1)
|
||||
func (f *Framework) NewGRPCFortuneTellerDeployment() {
|
||||
f.NewNewGRPCFortuneTellerDeploymentWithReplicas(1)
|
||||
}
|
||||
|
||||
// NewNewGRPCFortuneTellerDeploymentWithReplicas creates a new deployment of the
|
||||
// fortune teller image in a particular namespace. Number of replicas is configurable
|
||||
func (f *Framework) NewNewGRPCFortuneTellerDeploymentWithReplicas(replicas int32) error {
|
||||
func (f *Framework) NewNewGRPCFortuneTellerDeploymentWithReplicas(replicas int32) {
|
||||
deployment := &extensions.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "fortune-teller",
|
||||
|
|
@ -77,20 +76,13 @@ func (f *Framework) NewNewGRPCFortuneTellerDeploymentWithReplicas(replicas int32
|
|||
}
|
||||
|
||||
d, err := f.EnsureDeployment(deployment)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if d == nil {
|
||||
return fmt.Errorf("unexpected error creating deployement for fortune-teller")
|
||||
}
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(d).NotTo(BeNil(), "expected a fortune-teller deployment")
|
||||
|
||||
err = WaitForPodsReady(f.KubeClientSet, 5*time.Minute, int(replicas), f.IngressController.Namespace, metav1.ListOptions{
|
||||
LabelSelector: fields.SelectorFromSet(fields.Set(d.Spec.Template.ObjectMeta.Labels)).String(),
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to wait for to become ready")
|
||||
}
|
||||
Expect(err).NotTo(HaveOccurred(), "failed to wait for to become ready")
|
||||
|
||||
service := &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
@ -112,14 +104,5 @@ func (f *Framework) NewNewGRPCFortuneTellerDeploymentWithReplicas(replicas int32
|
|||
},
|
||||
}
|
||||
|
||||
s, err := f.EnsureService(service)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if s == nil {
|
||||
return fmt.Errorf("unexpected error creating service for fortune-teller deployment")
|
||||
}
|
||||
|
||||
return nil
|
||||
f.EnsureService(service)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,9 @@ limitations under the License.
|
|||
package framework
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
|
|
@ -60,7 +59,7 @@ bind-address = "0.0.0.0:8088"
|
|||
|
||||
// NewInfluxDBDeployment creates an InfluxDB server configured to reply
|
||||
// on 8086/tcp and 8089/udp
|
||||
func (f *Framework) NewInfluxDBDeployment() error {
|
||||
func (f *Framework) NewInfluxDBDeployment() {
|
||||
configuration := &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "influxdb-config",
|
||||
|
|
@ -72,13 +71,9 @@ func (f *Framework) NewInfluxDBDeployment() error {
|
|||
}
|
||||
|
||||
cm, err := f.EnsureConfigMap(configuration)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
Expect(err).NotTo(HaveOccurred(), "failed to create an Influxdb deployment")
|
||||
|
||||
if cm == nil {
|
||||
return fmt.Errorf("unexpected error creating configmap for influxdb")
|
||||
}
|
||||
Expect(cm).NotTo(BeNil(), "expected a configmap but none returned")
|
||||
|
||||
deployment := &extensions.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
@ -143,20 +138,12 @@ func (f *Framework) NewInfluxDBDeployment() error {
|
|||
}
|
||||
|
||||
d, err := f.EnsureDeployment(deployment)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
Expect(err).NotTo(HaveOccurred(), "failed to create an Influxdb deployment")
|
||||
|
||||
if d == nil {
|
||||
return fmt.Errorf("unexpected error creating deployement for influxdb")
|
||||
}
|
||||
Expect(d).NotTo(BeNil(), "unexpected error creating deployement for influxdb")
|
||||
|
||||
err = WaitForPodsReady(f.KubeClientSet, 5*time.Minute, 1, f.IngressController.Namespace, metav1.ListOptions{
|
||||
LabelSelector: fields.SelectorFromSet(fields.Set(d.Spec.Template.ObjectMeta.Labels)).String(),
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to wait for influxdb to become ready")
|
||||
}
|
||||
|
||||
return nil
|
||||
Expect(err).NotTo(HaveOccurred(), "failed to wait for influxdb to become ready")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
api "k8s.io/api/core/v1"
|
||||
core "k8s.io/api/core/v1"
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
|
|
@ -31,15 +33,23 @@ import (
|
|||
)
|
||||
|
||||
// EnsureSecret creates a Secret object or returns it if it already exists.
|
||||
func (f *Framework) EnsureSecret(secret *api.Secret) (*api.Secret, error) {
|
||||
func (f *Framework) EnsureSecret(secret *api.Secret) *api.Secret {
|
||||
s, err := f.KubeClientSet.CoreV1().Secrets(secret.Namespace).Create(secret)
|
||||
if err != nil {
|
||||
if k8sErrors.IsAlreadyExists(err) {
|
||||
return f.KubeClientSet.CoreV1().Secrets(secret.Namespace).Update(secret)
|
||||
s, err := f.KubeClientSet.CoreV1().Secrets(secret.Namespace).Update(secret)
|
||||
Expect(err).NotTo(HaveOccurred(), "unexpected error updating secret")
|
||||
|
||||
return s
|
||||
}
|
||||
return nil, err
|
||||
|
||||
Expect(err).NotTo(HaveOccurred(), "unexpected error creating secret")
|
||||
}
|
||||
return s, nil
|
||||
|
||||
Expect(s).NotTo(BeNil())
|
||||
Expect(s.ObjectMeta).NotTo(BeNil())
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// EnsureConfigMap creates a ConfigMap object or returns it if it already exists.
|
||||
|
|
@ -51,40 +61,49 @@ func (f *Framework) EnsureConfigMap(configMap *api.ConfigMap) (*api.ConfigMap, e
|
|||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return cm, nil
|
||||
}
|
||||
|
||||
// EnsureIngress creates an Ingress object or returns it if it already exists.
|
||||
func (f *Framework) EnsureIngress(ingress *extensions.Ingress) (*extensions.Ingress, error) {
|
||||
s, err := f.KubeClientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Update(ingress)
|
||||
func (f *Framework) EnsureIngress(ingress *extensions.Ingress) *extensions.Ingress {
|
||||
ing, err := f.KubeClientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Update(ingress)
|
||||
if err != nil {
|
||||
if k8sErrors.IsNotFound(err) {
|
||||
s, err = f.KubeClientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Create(ingress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
return nil, err
|
||||
ing, err = f.KubeClientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Create(ingress)
|
||||
Expect(err).NotTo(HaveOccurred(), "unexpected error creating ingress")
|
||||
return ing
|
||||
}
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
if s.Annotations == nil {
|
||||
s.Annotations = make(map[string]string)
|
||||
Expect(ing).NotTo(BeNil())
|
||||
|
||||
if ing.Annotations == nil {
|
||||
ing.Annotations = make(map[string]string)
|
||||
}
|
||||
|
||||
return s, nil
|
||||
return ing
|
||||
}
|
||||
|
||||
// EnsureService creates a Service object or returns it if it already exists.
|
||||
func (f *Framework) EnsureService(service *core.Service) (*core.Service, error) {
|
||||
func (f *Framework) EnsureService(service *core.Service) *core.Service {
|
||||
s, err := f.KubeClientSet.CoreV1().Services(service.Namespace).Update(service)
|
||||
if err != nil {
|
||||
if k8sErrors.IsNotFound(err) {
|
||||
return f.KubeClientSet.CoreV1().Services(service.Namespace).Create(service)
|
||||
s, err := f.KubeClientSet.CoreV1().Services(service.Namespace).Create(service)
|
||||
Expect(err).NotTo(HaveOccurred(), "unexpected error creating service")
|
||||
return s
|
||||
|
||||
}
|
||||
return nil, err
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
return s, nil
|
||||
|
||||
Expect(s).NotTo(BeNil(), "expected a service but none returned")
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// EnsureDeployment creates a Deployment object or returns it if it already exists.
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
|
|
@ -140,8 +142,9 @@ func CreateIngressMASecret(client kubernetes.Interface, host string, secretName,
|
|||
}
|
||||
|
||||
// WaitForTLS waits until the TLS handshake with a given server completes successfully.
|
||||
func WaitForTLS(url string, tlsConfig *tls.Config) error {
|
||||
return wait.Poll(Poll, 30*time.Second, matchTLSServerName(url, tlsConfig))
|
||||
func WaitForTLS(url string, tlsConfig *tls.Config) {
|
||||
err := wait.Poll(Poll, 30*time.Second, matchTLSServerName(url, tlsConfig))
|
||||
Expect(err).NotTo(HaveOccurred(), "timeout waiting for TLS configuration in URL %s", url)
|
||||
}
|
||||
|
||||
// generateRSACert generates a basic self signed certificate using a key length
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue