Add e2e tests
This commit is contained in:
parent
99a355f25d
commit
601fb7dacf
1163 changed files with 289217 additions and 14195 deletions
110
test/e2e/defaultbackend/default_backend.go
Normal file
110
test/e2e/defaultbackend/default_backend.go
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package defaultbackend
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/parnurzeal/gorequest"
|
||||
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
)
|
||||
|
||||
const defaultBackend = "default backend - 404"
|
||||
|
||||
var _ = framework.IngressNginxDescribe("Default backend", func() {
|
||||
f := framework.NewDefaultFramework("default-backend")
|
||||
|
||||
BeforeEach(func() {
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
})
|
||||
|
||||
It("should return 404 sending requests when only a default backend is running", func() {
|
||||
httpURL, err := f.GetNginxURL(framework.HTTP)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
httpsURL, err := f.GetNginxURL(framework.HTTPS)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
request := gorequest.New()
|
||||
|
||||
testCases := []struct {
|
||||
Name string
|
||||
Host string
|
||||
Scheme framework.RequestScheme
|
||||
Method string
|
||||
Path string
|
||||
Status int
|
||||
}{
|
||||
{"basic HTTP GET request without host to path / should return 404", "", framework.HTTP, "GET", "/", 404},
|
||||
{"basic HTTP GET request without host to path /demo should return 404", "", framework.HTTP, "GET", "/demo", 404},
|
||||
{"basic HTTPS GET request without host to path / should return 404", "", framework.HTTPS, "GET", "/", 404},
|
||||
{"basic HTTPS GET request without host to path /demo should return 404", "", framework.HTTPS, "GET", "/demo", 404},
|
||||
|
||||
{"basic HTTP POST request without host to path / should return 404", "", framework.HTTP, "POST", "/", 404},
|
||||
{"basic HTTP POST request without host to path /demo should return 404", "", framework.HTTP, "POST", "/demo", 404},
|
||||
{"basic HTTPS POST request without host to path / should return 404", "", framework.HTTPS, "POST", "/", 404},
|
||||
{"basic HTTPS POST request without host to path /demo should return 404", "", framework.HTTPS, "POST", "/demo", 404},
|
||||
|
||||
{"basic HTTP GET request to host foo.bar.com and path / should return 404", " foo.bar.com", framework.HTTP, "GET", "/", 404},
|
||||
{"basic HTTP GET request to host foo.bar.com and path /demo should return 404", " foo.bar.com", framework.HTTP, "GET", "/demo", 404},
|
||||
{"basic HTTPS GET request to host foo.bar.com and path / should return 404", " foo.bar.com", framework.HTTPS, "GET", "/", 404},
|
||||
{"basic HTTPS GET request to host foo.bar.com and path /demo should return 404", " foo.bar.com", framework.HTTPS, "GET", "/demo", 404},
|
||||
|
||||
{"basic HTTP POST request to host foo.bar.com and path / should return 404", " foo.bar.com", framework.HTTP, "POST", "/", 404},
|
||||
{"basic HTTP POST request to host foo.bar.com and path /demo should return 404", " foo.bar.com", framework.HTTP, "POST", "/demo", 404},
|
||||
{"basic HTTPS POST request to host foo.bar.com and path / should return 404", " foo.bar.com", framework.HTTPS, "POST", "/", 404},
|
||||
{"basic HTTPS POST request to host foo.bar.com and path /demo should return 404", " foo.bar.com", framework.HTTPS, "POST", "/demo", 404},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
By(test.Name)
|
||||
var errs []error
|
||||
var cm *gorequest.SuperAgent
|
||||
|
||||
switch test.Scheme {
|
||||
case framework.HTTP:
|
||||
cm = request.CustomMethod(test.Method, httpURL)
|
||||
break
|
||||
case framework.HTTPS:
|
||||
cm = request.CustomMethod(test.Method, httpsURL)
|
||||
// the default backend uses a self generated certificate
|
||||
cm.Transport = &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
}
|
||||
break
|
||||
default:
|
||||
Fail("Unexpected request scheme")
|
||||
}
|
||||
|
||||
if test.Host != "" {
|
||||
cm.Set("Host", test.Host)
|
||||
}
|
||||
|
||||
resp, _, errs := cm.End()
|
||||
Expect(len(errs)).Should(BeNumerically("==", 0))
|
||||
Expect(resp.StatusCode).Should(Equal(test.Status))
|
||||
}
|
||||
})
|
||||
})
|
||||
76
test/e2e/defaultbackend/ssl.go
Normal file
76
test/e2e/defaultbackend/ssl.go
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package defaultbackend
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/parnurzeal/gorequest"
|
||||
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
)
|
||||
|
||||
var _ = framework.IngressNginxDescribe("Default backend - SSL", func() {
|
||||
f := framework.NewDefaultFramework("default-backend")
|
||||
|
||||
BeforeEach(func() {
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
})
|
||||
|
||||
It("should return a self generated SSL certificate", func() {
|
||||
httpsURL, err := f.GetNginxURL(framework.HTTPS)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
request := gorequest.New()
|
||||
|
||||
By("checking SSL Certificate using the NGINX IP address")
|
||||
cm := request.Post(httpsURL)
|
||||
// the default backend uses a self generated certificate
|
||||
cm.Transport = &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
}
|
||||
resp, _, errs := cm.End()
|
||||
Expect(len(errs)).Should(BeNumerically("==", 0))
|
||||
Expect(len(resp.TLS.PeerCertificates)).Should(BeNumerically("==", 1))
|
||||
for _, pc := range resp.TLS.PeerCertificates {
|
||||
Expect(pc.Issuer.CommonName).Should(Equal("Kubernetes Ingress Controller Fake Certificate"))
|
||||
}
|
||||
|
||||
By("checking SSL Certificate using the NGINX catch all server")
|
||||
cm = request.Post(httpsURL)
|
||||
// the default backend uses a self generated certificate
|
||||
cm.Transport = &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
}
|
||||
cm.Set("Host", "foo.bar.com")
|
||||
resp, _, errs = cm.End()
|
||||
Expect(len(errs)).Should(BeNumerically("==", 0))
|
||||
Expect(len(resp.TLS.PeerCertificates)).Should(BeNumerically("==", 1))
|
||||
for _, pc := range resp.TLS.PeerCertificates {
|
||||
Expect(pc.Issuer.CommonName).Should(Equal("Kubernetes Ingress Controller Fake Certificate"))
|
||||
}
|
||||
})
|
||||
})
|
||||
44
test/e2e/e2e.go
Normal file
44
test/e2e/e2e.go
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/onsi/ginkgo"
|
||||
"github.com/onsi/ginkgo/config"
|
||||
"github.com/onsi/gomega"
|
||||
"k8s.io/apiserver/pkg/util/logs"
|
||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||
|
||||
_ "k8s.io/ingress-nginx/test/e2e/defaultbackend"
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
)
|
||||
|
||||
// RunE2ETests checks configuration parameters (specified through flags) and then runs
|
||||
// E2E tests using the Ginkgo runner.
|
||||
func RunE2ETests(t *testing.T) {
|
||||
logs.InitLogs()
|
||||
defer logs.FlushLogs()
|
||||
|
||||
gomega.RegisterFailHandler(ginkgo.Fail)
|
||||
// Disable skipped tests unless they are explicitly requested.
|
||||
if config.GinkgoConfig.FocusString == "" && config.GinkgoConfig.SkipString == "" {
|
||||
config.GinkgoConfig.SkipString = `\[Flaky\]|\[Feature:.+\]`
|
||||
}
|
||||
|
||||
glog.Infof("Starting e2e run %q on Ginkgo node %d", framework.RunId, config.GinkgoConfig.ParallelNode)
|
||||
ginkgo.RunSpecs(t, "nginx-ingress-controller e2e suite")
|
||||
}
|
||||
34
test/e2e/e2e_test.go
Normal file
34
test/e2e/e2e_test.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
)
|
||||
|
||||
func init() {
|
||||
framework.RegisterParseFlags()
|
||||
|
||||
if "" == framework.TestContext.KubeConfig {
|
||||
glog.Fatalf("environment variable %v must be set", clientcmd.RecommendedConfigPathEnvVar)
|
||||
}
|
||||
}
|
||||
func TestE2E(t *testing.T) {
|
||||
RunE2ETests(t)
|
||||
}
|
||||
60
test/e2e/framework/cleanup.go
Normal file
60
test/e2e/framework/cleanup.go
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package framework
|
||||
|
||||
import "sync"
|
||||
|
||||
type CleanupActionHandle *int
|
||||
|
||||
var cleanupActionsLock sync.Mutex
|
||||
var cleanupActions = map[CleanupActionHandle]func(){}
|
||||
|
||||
// AddCleanupAction installs a function that will be called in the event of the
|
||||
// whole test being terminated. This allows arbitrary pieces of the overall
|
||||
// test to hook into SynchronizedAfterSuite().
|
||||
func AddCleanupAction(fn func()) CleanupActionHandle {
|
||||
p := CleanupActionHandle(new(int))
|
||||
cleanupActionsLock.Lock()
|
||||
defer cleanupActionsLock.Unlock()
|
||||
cleanupActions[p] = fn
|
||||
return p
|
||||
}
|
||||
|
||||
// RemoveCleanupAction removes a function that was installed by AddCleanupAction.
|
||||
func RemoveCleanupAction(p CleanupActionHandle) {
|
||||
cleanupActionsLock.Lock()
|
||||
defer cleanupActionsLock.Unlock()
|
||||
delete(cleanupActions, p)
|
||||
}
|
||||
|
||||
// RunCleanupActions runs all functions installed by AddCleanupAction. It does
|
||||
// not remove them (see RemoveCleanupAction) but it does run unlocked, so they
|
||||
// may remove themselves.
|
||||
func RunCleanupActions() {
|
||||
list := []func(){}
|
||||
func() {
|
||||
cleanupActionsLock.Lock()
|
||||
defer cleanupActionsLock.Unlock()
|
||||
for _, fn := range cleanupActions {
|
||||
list = append(list, fn)
|
||||
}
|
||||
}()
|
||||
// Run unlocked.
|
||||
for _, fn := range list {
|
||||
fn()
|
||||
}
|
||||
}
|
||||
145
test/e2e/framework/framework.go
Normal file
145
test/e2e/framework/framework.go
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
Copyright 2017 Jetstack Ltd.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package framework
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
apiextcs "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
const (
|
||||
podName = "test-ingress-controller"
|
||||
)
|
||||
|
||||
type RequestScheme string
|
||||
|
||||
// These are valid test request schemes.
|
||||
const (
|
||||
HTTP RequestScheme = "http"
|
||||
HTTPS RequestScheme = "https"
|
||||
)
|
||||
|
||||
// Framework supports common operations used by e2e tests; it will keep a client & a namespace for you.
|
||||
type Framework struct {
|
||||
BaseName string
|
||||
|
||||
// A Kubernetes and Service Catalog client
|
||||
KubeClientSet kubernetes.Interface
|
||||
APIExtensionsClientSet apiextcs.Interface
|
||||
|
||||
// Namespace in which all test resources should reside
|
||||
Namespace *v1.Namespace
|
||||
|
||||
// To make sure that this framework cleans up after itself, no matter what,
|
||||
// we install a Cleanup action before each test and clear it after. If we
|
||||
// should abort, the AfterSuite hook should run all Cleanup actions.
|
||||
cleanupHandle CleanupActionHandle
|
||||
}
|
||||
|
||||
// NewFramework makes a new framework and sets up a BeforeEach/AfterEach for
|
||||
// you (you can write additional before/after each functions).
|
||||
func NewDefaultFramework(baseName string) *Framework {
|
||||
f := &Framework{
|
||||
BaseName: baseName,
|
||||
}
|
||||
|
||||
BeforeEach(f.BeforeEach)
|
||||
AfterEach(f.AfterEach)
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
// BeforeEach gets a client and makes a namespace.
|
||||
func (f *Framework) BeforeEach() {
|
||||
f.cleanupHandle = AddCleanupAction(f.AfterEach)
|
||||
|
||||
By("Creating a kubernetes client")
|
||||
kubeConfig, err := LoadConfig(TestContext.KubeConfig, TestContext.KubeContext)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
f.KubeClientSet, err = kubernetes.NewForConfig(kubeConfig)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Building a namespace api object")
|
||||
f.Namespace, err = CreateKubeNamespace(f.BaseName, f.KubeClientSet)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
// AfterEach deletes the namespace, after reading its events.
|
||||
func (f *Framework) AfterEach() {
|
||||
RemoveCleanupAction(f.cleanupHandle)
|
||||
|
||||
By("Deleting test namespace")
|
||||
err := DeleteKubeNamespace(f.KubeClientSet, f.Namespace.Name)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for test namespace to no longer exist")
|
||||
err = WaitForKubeNamespaceNotExist(f.KubeClientSet, f.Namespace.Name)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
// IngressNginxDescribe wrapper function for ginkgo describe. Adds namespacing.
|
||||
func IngressNginxDescribe(text string, body func()) bool {
|
||||
return Describe("[nginx-ingress] "+text, body)
|
||||
}
|
||||
|
||||
// GetNginxIP returns the IP address of the minikube cluster
|
||||
// where the NGINX ingress controller is running
|
||||
func (f *Framework) GetNginxIP() (string, error) {
|
||||
out, err := exec.Command("minikube", "ip").Output()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strings.TrimSpace(string(out)), nil
|
||||
}
|
||||
|
||||
// GetNginxPort returns the number of TCP port where NGINX is running
|
||||
func (f *Framework) GetNginxPort(name string) (int, error) {
|
||||
s, err := f.KubeClientSet.CoreV1().Services("ingress-nginx").Get("ingress-nginx", meta_v1.GetOptions{})
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
for _, p := range s.Spec.Ports {
|
||||
if p.NodePort != 0 && p.Name == name {
|
||||
return int(p.NodePort), nil
|
||||
}
|
||||
}
|
||||
|
||||
return -1, err
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
port, err := f.GetNginxPort(fmt.Sprintf("%v", scheme))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%v://%v:%v", scheme, ip, port), nil
|
||||
}
|
||||
56
test/e2e/framework/test_context.go
Normal file
56
test/e2e/framework/test_context.go
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package framework
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
"github.com/onsi/ginkgo/config"
|
||||
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
const (
|
||||
RecommendedConfigPathEnvVar = "INGRESSNGINXCONFIG"
|
||||
)
|
||||
|
||||
type TestContextType struct {
|
||||
KubeHost string
|
||||
KubeConfig string
|
||||
KubeContext string
|
||||
}
|
||||
|
||||
var TestContext TestContextType
|
||||
|
||||
// Register flags common to all e2e test suites.
|
||||
func RegisterCommonFlags() {
|
||||
// Turn on verbose by default to get spec names
|
||||
config.DefaultReporterConfig.Verbose = true
|
||||
|
||||
// Turn on EmitSpecProgress to get spec progress (especially on interrupt)
|
||||
config.GinkgoConfig.EmitSpecProgress = true
|
||||
|
||||
// Randomize specs as well as suites
|
||||
config.GinkgoConfig.RandomizeAllSpecs = true
|
||||
|
||||
flag.StringVar(&TestContext.KubeHost, "kubernetes-host", "http://127.0.0.1:8080", "The kubernetes host, or apiserver, to connect to")
|
||||
flag.StringVar(&TestContext.KubeConfig, "kubernetes-config", os.Getenv(clientcmd.RecommendedConfigPathEnvVar), "Path to config containing embedded authinfo for kubernetes. Default value is from environment variable "+clientcmd.RecommendedConfigPathEnvVar)
|
||||
flag.StringVar(&TestContext.KubeContext, "kubernetes-context", "", "config context to use for kuberentes. If unset, will use value from 'current-context'")
|
||||
}
|
||||
|
||||
func RegisterParseFlags() {
|
||||
RegisterCommonFlags()
|
||||
flag.Parse()
|
||||
}
|
||||
174
test/e2e/framework/util.go
Normal file
174
test/e2e/framework/util.go
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
Copyright 2014 The Kubernetes Authors.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package framework
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
"k8s.io/client-go/tools/clientcmd/api"
|
||||
)
|
||||
|
||||
const (
|
||||
// Poll how often to poll for conditions
|
||||
Poll = 2 * time.Second
|
||||
|
||||
// Default time to wait for operations to complete
|
||||
defaultTimeout = 30 * time.Second
|
||||
)
|
||||
|
||||
func nowStamp() string {
|
||||
return time.Now().Format(time.StampMilli)
|
||||
}
|
||||
|
||||
func log(level string, format string, args ...interface{}) {
|
||||
fmt.Fprintf(GinkgoWriter, nowStamp()+": "+level+": "+format+"\n", args...)
|
||||
}
|
||||
|
||||
func Logf(format string, args ...interface{}) {
|
||||
log("INFO", format, args...)
|
||||
}
|
||||
|
||||
func Failf(format string, args ...interface{}) {
|
||||
msg := fmt.Sprintf(format, args...)
|
||||
log("INFO", msg)
|
||||
Fail(nowStamp()+": "+msg, 1)
|
||||
}
|
||||
|
||||
func Skipf(format string, args ...interface{}) {
|
||||
msg := fmt.Sprintf(format, args...)
|
||||
log("INFO", msg)
|
||||
Skip(nowStamp() + ": " + msg)
|
||||
}
|
||||
|
||||
func RestclientConfig(config, context string) (*api.Config, error) {
|
||||
Logf(">>> config: %s\n", config)
|
||||
if config == "" {
|
||||
return nil, fmt.Errorf("Config file must be specified to load client config")
|
||||
}
|
||||
c, err := clientcmd.LoadFromFile(config)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error loading config: %v", err.Error())
|
||||
}
|
||||
if context != "" {
|
||||
Logf(">>> context: %s\n", context)
|
||||
c.CurrentContext = context
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
type ClientConfigGetter func() (*rest.Config, error)
|
||||
|
||||
func LoadConfig(config, context string) (*rest.Config, error) {
|
||||
c, err := RestclientConfig(config, context)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return clientcmd.NewDefaultClientConfig(*c, &clientcmd.ConfigOverrides{}).ClientConfig()
|
||||
}
|
||||
|
||||
// RunId unique identifier of the e2e run
|
||||
var RunId = uuid.NewUUID()
|
||||
|
||||
func CreateKubeNamespace(baseName string, c kubernetes.Interface) (*v1.Namespace, error) {
|
||||
ns := &v1.Namespace{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
GenerateName: fmt.Sprintf("e2e-tests-%v-", baseName),
|
||||
},
|
||||
}
|
||||
// Be robust about making the namespace creation call.
|
||||
var got *v1.Namespace
|
||||
err := wait.PollImmediate(Poll, defaultTimeout, func() (bool, error) {
|
||||
var err error
|
||||
got, err = c.Core().Namespaces().Create(ns)
|
||||
if err != nil {
|
||||
Logf("Unexpected error while creating namespace: %v", err)
|
||||
return false, nil
|
||||
}
|
||||
Logf("Created namespace: %v", got.Name)
|
||||
return true, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return got, nil
|
||||
}
|
||||
|
||||
func DeleteKubeNamespace(c kubernetes.Interface, namespace string) error {
|
||||
return c.Core().Namespaces().Delete(namespace, nil)
|
||||
}
|
||||
|
||||
func ExpectNoError(err error, explain ...interface{}) {
|
||||
if err != nil {
|
||||
Logf("Unexpected error occurred: %v", err)
|
||||
}
|
||||
ExpectWithOffset(1, err).NotTo(HaveOccurred(), explain...)
|
||||
}
|
||||
|
||||
func WaitForKubeNamespaceNotExist(c kubernetes.Interface, namespace string) error {
|
||||
return wait.PollImmediate(Poll, time.Minute*2, namespaceNotExist(c, namespace))
|
||||
}
|
||||
|
||||
func namespaceNotExist(c kubernetes.Interface, namespace string) wait.ConditionFunc {
|
||||
return func() (bool, error) {
|
||||
_, err := c.CoreV1().Namespaces().Get(namespace, metav1.GetOptions{})
|
||||
if apierrors.IsNotFound(err) {
|
||||
return true, nil
|
||||
}
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Waits default amount of time (PodStartTimeout) for the specified pod to become running.
|
||||
// Returns an error if timeout occurs first, or pod goes in to failed state.
|
||||
func WaitForPodRunningInNamespace(c kubernetes.Interface, pod *v1.Pod) error {
|
||||
if pod.Status.Phase == v1.PodRunning {
|
||||
return nil
|
||||
}
|
||||
return waitTimeoutForPodRunningInNamespace(c, pod.Name, pod.Namespace, defaultTimeout)
|
||||
}
|
||||
|
||||
func waitTimeoutForPodRunningInNamespace(c kubernetes.Interface, podName, namespace string, timeout time.Duration) error {
|
||||
return wait.PollImmediate(Poll, defaultTimeout, podRunning(c, podName, namespace))
|
||||
}
|
||||
|
||||
func podRunning(c kubernetes.Interface, podName, namespace string) wait.ConditionFunc {
|
||||
return func() (bool, error) {
|
||||
pod, err := c.CoreV1().Pods(namespace).Get(podName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
switch pod.Status.Phase {
|
||||
case v1.PodRunning:
|
||||
return true, nil
|
||||
case v1.PodFailed, v1.PodSucceeded:
|
||||
return false, fmt.Errorf("pod ran to completion")
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
61
test/e2e/up.sh
Executable file
61
test/e2e/up.sh
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright 2017 The Kubernetes Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'
|
||||
|
||||
echo "downloading kubectl..."
|
||||
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$KUBERNETES_VERSION/bin/linux/amd64/kubectl && \
|
||||
chmod +x kubectl && sudo mv kubectl /usr/local/bin/
|
||||
|
||||
echo "downloading minikube..."
|
||||
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && \
|
||||
chmod +x minikube && \
|
||||
sudo mv minikube /usr/local/bin/
|
||||
|
||||
echo "starting minikube..."
|
||||
sudo minikube start --vm-driver=none --kubernetes-version=$KUBERNETES_VERSION
|
||||
|
||||
minikube update-context
|
||||
|
||||
echo "waiting for kubernetes cluster"
|
||||
until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True";
|
||||
do
|
||||
sleep 1;
|
||||
done
|
||||
|
||||
echo "deploying NGINX Ingress controller"
|
||||
cat deploy/namespace.yaml | kubectl apply -f -
|
||||
cat deploy/default-backend.yaml | kubectl apply -f -
|
||||
cat deploy/configmap.yaml | kubectl apply -f -
|
||||
cat deploy/tcp-services-configmap.yaml | kubectl apply -f -
|
||||
cat deploy/udp-services-configmap.yaml | kubectl apply -f -
|
||||
cat deploy/without-rbac.yaml | kubectl apply -f -
|
||||
cat deploy/provider/baremetal/service-nodeport.yaml | kubectl apply -f -
|
||||
|
||||
echo "updating image..."
|
||||
kubectl set image \
|
||||
deployments \
|
||||
--namespace ingress-nginx \
|
||||
--selector app=ingress-nginx \
|
||||
nginx-ingress-controller=gcr.io/google_containers/nginx-ingress-controller:test
|
||||
|
||||
sleep 5
|
||||
|
||||
echo "waiting NGINX ingress pod..."
|
||||
until kubectl get pods -n ingress-nginx -l app=ingress-nginx -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True";
|
||||
do
|
||||
sleep 1;
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue