2015-10-26 01:01:02 +00:00
/ *
2016-06-03 00:25:58 +00:00
Copyright 2015 The Kubernetes Authors .
2015-10-26 01:01:02 +00:00
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 (
"fmt"
2015-11-19 01:41:21 +00:00
"path/filepath"
2015-10-26 01:01:02 +00:00
"time"
2016-04-07 17:21:31 +00:00
"k8s.io/kubernetes/test/e2e/framework"
2015-10-26 01:01:02 +00:00
. "github.com/onsi/ginkgo"
)
2016-05-31 19:12:58 +00:00
const (
// parent path to yaml test manifests.
ingressManifestPath = "test/e2e/testing-manifests/ingress"
// timeout on a single http request.
reqTimeout = 10 * time . Second
// healthz port used to verify glbc restarted correctly on the master.
glbcHealthzPort = 8086
// On average it takes ~6 minutes for a single backend to come online in GCE.
lbPollTimeout = 15 * time . Minute
2016-06-17 17:35:16 +00:00
// General cloud resource poll timeout (eg: create static ip, firewall etc)
cloudResourcePollTimeout = 5 * time . Minute
2016-05-31 19:12:58 +00:00
// Time required by the loadbalancer to cleanup, proportional to numApps/Ing.
lbCleanupTimeout = 5 * time . Minute
lbPollInterval = 30 * time . Second
2015-10-26 01:01:02 +00:00
2016-05-23 02:08:46 +00:00
// Name of the config-map and key the ingress controller stores its uid in.
uidConfigMap = "ingress-uid"
uidKey = "uid"
2016-05-31 19:12:58 +00:00
// GCE only allows names < 64 characters, and the loadbalancer controller inserts
// a single character of padding.
nameLenLimit = 62
)
2015-10-26 01:01:02 +00:00
2016-05-31 19:12:58 +00:00
var _ = framework . KubeDescribe ( "Loadbalancing: L7 [Feature:Ingress]" , func ( ) {
defer GinkgoRecover ( )
2016-07-29 08:01:41 +00:00
var (
ns string
jig * testJig
conformanceTests [ ] conformanceTests
)
2016-05-31 19:12:58 +00:00
f := framework . NewDefaultFramework ( "ingress" )
2015-11-08 00:48:11 +00:00
2016-05-31 19:12:58 +00:00
BeforeEach ( func ( ) {
f . BeforeEach ( )
2016-10-18 13:00:38 +00:00
jig = newTestJig ( f . ClientSet )
2016-05-31 19:12:58 +00:00
ns = f . Namespace . Name
} )
2016-02-17 23:46:25 +00:00
2016-05-31 19:12:58 +00:00
// Before enabling this loadbalancer test in any other test list you must
// make sure the associated project has enough quota. At the time of this
// writing a GCE project is allowed 3 backend services by default. This
// test requires at least 5.
//
// Slow by design ~10m for each "It" block dominated by loadbalancer setup time
// TODO: write similar tests for nginx, haproxy and AWS Ingress.
2016-08-22 22:15:12 +00:00
framework . KubeDescribe ( "GCE [Slow] [Feature: Ingress]" , func ( ) {
2016-05-31 19:12:58 +00:00
var gceController * GCEIngressController
// Platform specific setup
BeforeEach ( func ( ) {
framework . SkipUnlessProviderIs ( "gce" , "gke" )
By ( "Initializing gce controller" )
2016-09-07 00:18:48 +00:00
gceController = & GCEIngressController {
ns : ns ,
c : jig . client ,
cloud : framework . TestContext . CloudConfig ,
}
2016-05-31 19:12:58 +00:00
gceController . init ( )
} )
2015-10-26 01:01:02 +00:00
2016-05-31 19:12:58 +00:00
// Platform specific cleanup
AfterEach ( func ( ) {
if CurrentGinkgoTestDescription ( ) . Failed {
describeIng ( ns )
}
if jig . ing == nil {
By ( "No ingress created, no cleanup necessary" )
return
}
By ( "Deleting ingress" )
jig . deleteIngress ( )
By ( "Cleaning up cloud resources" )
2016-07-29 08:01:41 +00:00
cleanupGCE ( gceController )
2016-05-31 19:12:58 +00:00
} )
2015-11-19 01:41:21 +00:00
2016-05-31 19:12:58 +00:00
It ( "should conform to Ingress spec" , func ( ) {
2016-08-18 01:49:08 +00:00
conformanceTests = createComformanceTests ( jig , ns )
2016-05-31 19:12:58 +00:00
for _ , t := range conformanceTests {
By ( t . entryLog )
t . execute ( )
By ( t . exitLog )
jig . waitForIngress ( )
}
} )
2015-11-19 01:41:21 +00:00
2016-05-31 19:12:58 +00:00
It ( "shoud create ingress with given static-ip " , func ( ) {
2016-10-21 21:29:25 +00:00
// ip released when the rest of lb resources are deleted in cleanupGCE
2016-05-31 19:12:58 +00:00
ip := gceController . staticIP ( ns )
By ( fmt . Sprintf ( "allocated static ip %v: %v through the GCE cloud provider" , ns , ip ) )
jig . createIngress ( filepath . Join ( ingressManifestPath , "static-ip" ) , ns , map [ string ] string {
"kubernetes.io/ingress.global-static-ip-name" : ns ,
"kubernetes.io/ingress.allow-http" : "false" ,
} )
By ( "waiting for Ingress to come up with ip: " + ip )
httpClient := buildInsecureClient ( reqTimeout )
2016-08-24 07:51:03 +00:00
ExpectNoError ( pollURL ( fmt . Sprintf ( "https://%v/" , ip ) , "" , lbPollTimeout , httpClient , false ) )
2016-05-31 19:12:58 +00:00
By ( "should reject HTTP traffic" )
2016-08-24 07:51:03 +00:00
ExpectNoError ( pollURL ( fmt . Sprintf ( "http://%v/" , ip ) , "" , lbPollTimeout , httpClient , true ) )
2016-05-31 19:12:58 +00:00
// TODO: uncomment the restart test once we have a way to synchronize
// and know that the controller has resumed watching. If we delete
// the ingress before the controller is ready we will leak.
// By("restaring glbc")
// restarter := NewRestartConfig(
// framework.GetMasterHost(), "glbc", glbcHealthzPort, restartPollInterval, restartTimeout)
// restarter.restart()
// By("should continue serving on provided static-ip for 30 seconds")
// ExpectNoError(jig.verifyURL(fmt.Sprintf("https://%v/", ip), "", 30, 1*time.Second, httpClient))
} )
2016-01-01 12:41:27 +00:00
2016-05-31 19:12:58 +00:00
// TODO: Implement a multizone e2e that verifies traffic reaches each
// zone based on pod labels.
} )
2016-08-22 22:15:12 +00:00
// Time: borderline 5m, slow by design
2016-09-07 00:40:30 +00:00
framework . KubeDescribe ( "Nginx [Slow]" , func ( ) {
2016-08-22 22:15:12 +00:00
var nginxController * NginxIngressController
BeforeEach ( func ( ) {
framework . SkipUnlessProviderIs ( "gce" , "gke" )
By ( "Initializing nginx controller" )
jig . class = "nginx"
nginxController = & NginxIngressController { ns : ns , c : jig . client }
// TODO: This test may fail on other platforms. We can simply skip it
// but we want to allow easy testing where a user might've hand
// configured firewalls.
if framework . ProviderIs ( "gce" , "gke" ) {
2016-08-26 17:06:00 +00:00
ExpectNoError ( gcloudCreate ( "firewall-rules" , fmt . Sprintf ( "ingress-80-443-%v" , ns ) , framework . TestContext . CloudConfig . ProjectID , "--allow" , "tcp:80,tcp:443" , "--network" , framework . TestContext . CloudConfig . Network ) )
2016-08-22 22:15:12 +00:00
} else {
framework . Logf ( "WARNING: Not running on GCE/GKE, cannot create firewall rules for :80, :443. Assuming traffic can reach the external ips of all nodes in cluster on those ports." )
}
nginxController . init ( )
} )
AfterEach ( func ( ) {
if framework . ProviderIs ( "gce" , "gke" ) {
ExpectNoError ( gcloudDelete ( "firewall-rules" , fmt . Sprintf ( "ingress-80-443-%v" , ns ) , framework . TestContext . CloudConfig . ProjectID ) )
}
if CurrentGinkgoTestDescription ( ) . Failed {
describeIng ( ns )
}
if jig . ing == nil {
By ( "No ingress created, no cleanup necessary" )
return
}
By ( "Deleting ingress" )
jig . deleteIngress ( )
} )
It ( "should conform to Ingress spec" , func ( ) {
conformanceTests = createComformanceTests ( jig , ns )
for _ , t := range conformanceTests {
By ( t . entryLog )
t . execute ( )
By ( t . exitLog )
jig . waitForIngress ( )
}
} )
} )
2016-05-31 19:12:58 +00:00
} )