2015-06-20 18:57:07 +00:00
/ *
2016-06-03 00:25:58 +00:00
Copyright 2015 The Kubernetes Authors .
2015-06-20 18:57:07 +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-07-10 09:54:54 +00:00
"io/ioutil"
"os"
2015-06-20 18:57:07 +00:00
"path/filepath"
"strings"
2016-03-09 21:32:32 +00:00
"sync"
2015-06-20 18:57:07 +00:00
"time"
2015-08-05 22:03:47 +00:00
"k8s.io/kubernetes/pkg/api"
2015-08-13 19:01:50 +00:00
client "k8s.io/kubernetes/pkg/client/unversioned"
2016-06-09 01:45:58 +00:00
"k8s.io/kubernetes/pkg/labels"
2016-04-07 17:21:31 +00:00
"k8s.io/kubernetes/test/e2e/framework"
2015-06-20 18:57:07 +00:00
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
const (
2016-04-07 17:21:31 +00:00
serverStartTimeout = framework . PodStartTimeout + 3 * time . Minute
2015-06-20 18:57:07 +00:00
)
2016-04-07 17:21:31 +00:00
var _ = framework . KubeDescribe ( "[Feature:Example]" , func ( ) {
f := framework . NewDefaultFramework ( "examples" )
2016-06-17 00:00:00 +00:00
// Reusable cluster state function. This won't be adversly affected by lazy initialization of framework.
clusterState := func ( selectorKey string , selectorValue string ) * framework . ClusterVerification {
return f . NewClusterVerification (
2016-03-31 18:45:08 +00:00
framework . PodStateVerification {
Selectors : map [ string ] string { selectorKey : selectorValue } ,
ValidPhases : [ ] api . PodPhase { api . PodRunning } ,
2016-06-17 00:00:00 +00:00
} )
}
// Customized ForEach wrapper for this test.
forEachPod := func ( selectorKey string , selectorValue string , fn func ( api . Pod ) ) {
clusterState ( selectorKey , selectorValue ) . ForEach ( fn )
2016-03-31 18:45:08 +00:00
}
2015-06-20 18:57:07 +00:00
var c * client . Client
var ns string
BeforeEach ( func ( ) {
2016-04-07 17:21:31 +00:00
c = f . Client
ns = f . Namespace . Name
2015-06-20 18:57:07 +00:00
} )
2016-04-07 17:21:31 +00:00
framework . KubeDescribe ( "Redis" , func ( ) {
2015-06-20 18:57:07 +00:00
It ( "should create and stop redis servers" , func ( ) {
mkpath := func ( file string ) string {
2016-06-21 22:43:29 +00:00
return filepath . Join ( framework . TestContext . RepoRoot , "examples/storage/redis" , file )
2015-06-20 18:57:07 +00:00
}
bootstrapYaml := mkpath ( "redis-master.yaml" )
sentinelServiceYaml := mkpath ( "redis-sentinel-service.yaml" )
sentinelControllerYaml := mkpath ( "redis-sentinel-controller.yaml" )
controllerYaml := mkpath ( "redis-controller.yaml" )
bootstrapPodName := "redis-master"
redisRC := "redis"
sentinelRC := "redis-sentinel"
nsFlag := fmt . Sprintf ( "--namespace=%v" , ns )
expectedOnServer := "The server is now ready to accept connections"
expectedOnSentinel := "+monitor master"
By ( "starting redis bootstrap" )
2016-04-07 17:21:31 +00:00
framework . RunKubectlOrDie ( "create" , "-f" , bootstrapYaml , nsFlag )
2016-06-29 07:19:26 +00:00
err := framework . WaitForPodNameRunningInNamespace ( c , bootstrapPodName , ns )
2015-06-20 18:57:07 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2016-04-07 17:21:31 +00:00
_ , err = framework . LookForStringInLog ( ns , bootstrapPodName , "master" , expectedOnServer , serverStartTimeout )
2015-06-20 18:57:07 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2016-04-07 17:21:31 +00:00
_ , err = framework . LookForStringInLog ( ns , bootstrapPodName , "sentinel" , expectedOnSentinel , serverStartTimeout )
2015-06-20 18:57:07 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
By ( "setting up services and controllers" )
2016-04-07 17:21:31 +00:00
framework . RunKubectlOrDie ( "create" , "-f" , sentinelServiceYaml , nsFlag )
framework . RunKubectlOrDie ( "create" , "-f" , sentinelControllerYaml , nsFlag )
framework . RunKubectlOrDie ( "create" , "-f" , controllerYaml , nsFlag )
2016-06-17 23:10:58 +00:00
label := labels . SelectorFromSet ( labels . Set ( map [ string ] string { sentinelRC : "true" } ) )
2016-06-09 01:45:58 +00:00
err = framework . WaitForPodsWithLabelRunning ( c , ns , label )
Expect ( err ) . NotTo ( HaveOccurred ( ) )
label = labels . SelectorFromSet ( labels . Set ( map [ string ] string { "name" : redisRC } ) )
err = framework . WaitForPodsWithLabelRunning ( c , ns , label )
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2015-06-20 18:57:07 +00:00
By ( "scaling up the deployment" )
2016-04-07 17:21:31 +00:00
framework . RunKubectlOrDie ( "scale" , "rc" , redisRC , "--replicas=3" , nsFlag )
framework . RunKubectlOrDie ( "scale" , "rc" , sentinelRC , "--replicas=3" , nsFlag )
2016-06-09 01:45:58 +00:00
framework . WaitForRCToStabilize ( c , ns , redisRC , framework . PodReadyBeforeTimeout )
framework . WaitForRCToStabilize ( c , ns , sentinelRC , framework . PodReadyBeforeTimeout )
2015-06-20 18:57:07 +00:00
By ( "checking up the services" )
checkAllLogs := func ( ) {
2016-06-17 23:10:58 +00:00
selectorKey , selectorValue := "name" , redisRC
label := labels . SelectorFromSet ( labels . Set ( map [ string ] string { selectorKey : selectorValue } ) )
err = framework . WaitForPodsWithLabelRunning ( c , ns , label )
Expect ( err ) . NotTo ( HaveOccurred ( ) )
forEachPod ( selectorKey , selectorValue , func ( pod api . Pod ) {
2015-06-20 18:57:07 +00:00
if pod . Name != bootstrapPodName {
2016-04-07 17:21:31 +00:00
_ , err := framework . LookForStringInLog ( ns , pod . Name , "redis" , expectedOnServer , serverStartTimeout )
2015-06-20 18:57:07 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
}
} )
2016-06-17 23:10:58 +00:00
selectorKey , selectorValue = sentinelRC , "true"
label = labels . SelectorFromSet ( labels . Set ( map [ string ] string { selectorKey : selectorValue } ) )
err = framework . WaitForPodsWithLabelRunning ( c , ns , label )
Expect ( err ) . NotTo ( HaveOccurred ( ) )
forEachPod ( selectorKey , selectorValue , func ( pod api . Pod ) {
2015-06-20 18:57:07 +00:00
if pod . Name != bootstrapPodName {
2016-04-07 17:21:31 +00:00
_ , err := framework . LookForStringInLog ( ns , pod . Name , "sentinel" , expectedOnSentinel , serverStartTimeout )
2015-06-20 18:57:07 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
}
} )
}
checkAllLogs ( )
By ( "turning down bootstrap" )
2016-04-07 17:21:31 +00:00
framework . RunKubectlOrDie ( "delete" , "-f" , bootstrapYaml , nsFlag )
err = framework . WaitForRCPodToDisappear ( c , ns , redisRC , bootstrapPodName )
2015-06-20 18:57:07 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
By ( "waiting for the new master election" )
checkAllLogs ( )
} )
} )
2016-04-07 17:21:31 +00:00
framework . KubeDescribe ( "Spark" , func ( ) {
2015-07-30 07:47:56 +00:00
It ( "should start spark master, driver and workers" , func ( ) {
2015-07-10 13:23:34 +00:00
mkpath := func ( file string ) string {
2016-07-12 01:35:16 +00:00
return filepath . Join ( framework . TestContext . RepoRoot , "examples/spark" , file )
2015-07-10 13:23:34 +00:00
}
2016-02-20 22:31:13 +00:00
// TODO: Add Zepplin and Web UI to this example.
serviceYaml := mkpath ( "spark-master-service.yaml" )
masterYaml := mkpath ( "spark-master-controller.yaml" )
workerControllerYaml := mkpath ( "spark-worker-controller.yaml" )
2015-07-10 13:23:34 +00:00
nsFlag := fmt . Sprintf ( "--namespace=%v" , ns )
2016-02-20 22:31:13 +00:00
master := func ( ) {
By ( "starting master" )
2016-04-07 17:21:31 +00:00
framework . RunKubectlOrDie ( "create" , "-f" , serviceYaml , nsFlag )
framework . RunKubectlOrDie ( "create" , "-f" , masterYaml , nsFlag )
2016-06-17 00:00:00 +00:00
selectorKey , selectorValue := "component" , "spark-master"
label := labels . SelectorFromSet ( labels . Set ( map [ string ] string { selectorKey : selectorValue } ) )
2016-06-09 01:45:58 +00:00
err := framework . WaitForPodsWithLabelRunning ( c , ns , label )
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2015-07-10 13:23:34 +00:00
2016-04-07 17:21:31 +00:00
framework . Logf ( "Now polling for Master startup..." )
2016-02-20 22:31:13 +00:00
// Only one master pod: But its a natural way to look up pod names.
2016-06-17 00:00:00 +00:00
forEachPod ( selectorKey , selectorValue , func ( pod api . Pod ) {
2016-04-07 17:21:31 +00:00
framework . Logf ( "Now waiting for master to startup in %v" , pod . Name )
_ , err := framework . LookForStringInLog ( ns , pod . Name , "spark-master" , "Starting Spark master at" , serverStartTimeout )
2016-02-20 22:31:13 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
} )
By ( "waiting for master endpoint" )
2016-06-09 01:45:58 +00:00
err = framework . WaitForEndpoint ( c , ns , "spark-master" )
2015-07-10 13:23:34 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2016-06-17 00:00:00 +00:00
forEachPod ( selectorKey , selectorValue , func ( pod api . Pod ) {
2016-03-31 18:45:08 +00:00
_ , maErr := framework . LookForStringInLog ( f . Namespace . Name , pod . Name , "spark-master" , "Starting Spark master at" , serverStartTimeout )
if maErr != nil {
framework . Failf ( "Didn't find target string. error:" , maErr )
}
} )
2016-02-20 22:31:13 +00:00
}
worker := func ( ) {
By ( "starting workers" )
2016-04-07 17:21:31 +00:00
framework . Logf ( "Now starting Workers" )
framework . RunKubectlOrDie ( "create" , "-f" , workerControllerYaml , nsFlag )
2016-06-17 00:00:00 +00:00
selectorKey , selectorValue := "component" , "spark-worker"
label := labels . SelectorFromSet ( labels . Set ( map [ string ] string { selectorKey : selectorValue } ) )
2016-06-09 01:45:58 +00:00
err := framework . WaitForPodsWithLabelRunning ( c , ns , label )
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2016-02-20 22:31:13 +00:00
// For now, scaling is orthogonal to the core test.
2016-04-07 17:21:31 +00:00
// framework.ScaleRC(c, ns, "spark-worker-controller", 2, true)
2016-02-20 22:31:13 +00:00
2016-04-07 17:21:31 +00:00
framework . Logf ( "Now polling for worker startup..." )
2016-06-17 00:00:00 +00:00
forEachPod ( selectorKey , selectorValue ,
2016-03-31 18:45:08 +00:00
func ( pod api . Pod ) {
_ , slaveErr := framework . LookForStringInLog ( ns , pod . Name , "spark-worker" , "Successfully registered with master" , serverStartTimeout )
Expect ( slaveErr ) . NotTo ( HaveOccurred ( ) )
} )
2016-02-20 22:31:13 +00:00
}
// Run the worker verification after we turn up the master.
defer worker ( )
master ( )
2015-07-10 13:23:34 +00:00
} )
} )
2015-07-09 22:18:54 +00:00
2016-04-07 17:21:31 +00:00
framework . KubeDescribe ( "Cassandra" , func ( ) {
2015-07-09 22:18:54 +00:00
It ( "should create and scale cassandra" , func ( ) {
mkpath := func ( file string ) string {
2016-07-12 01:35:16 +00:00
return filepath . Join ( framework . TestContext . RepoRoot , "examples/storage/cassandra" , file )
2015-07-09 22:18:54 +00:00
}
serviceYaml := mkpath ( "cassandra-service.yaml" )
controllerYaml := mkpath ( "cassandra-controller.yaml" )
nsFlag := fmt . Sprintf ( "--namespace=%v" , ns )
2016-03-10 17:26:39 +00:00
By ( "Starting the cassandra service" )
2016-04-07 17:21:31 +00:00
framework . RunKubectlOrDie ( "create" , "-f" , serviceYaml , nsFlag )
framework . Logf ( "wait for service" )
2016-06-09 01:45:58 +00:00
err := framework . WaitForService ( c , ns , "cassandra" , true , framework . Poll , framework . ServiceRespondingTimeout )
2015-10-06 11:16:20 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2015-10-02 15:22:31 +00:00
2016-02-23 00:05:38 +00:00
// Create an RC with n nodes in it. Each node will then be verified.
By ( "Creating a Cassandra RC" )
2016-04-07 17:21:31 +00:00
framework . RunKubectlOrDie ( "create" , "-f" , controllerYaml , nsFlag )
2016-06-09 01:45:58 +00:00
label := labels . SelectorFromSet ( labels . Set ( map [ string ] string { "app" : "cassandra" } ) )
err = framework . WaitForPodsWithLabelRunning ( c , ns , label )
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2016-03-31 18:45:08 +00:00
forEachPod ( "app" , "cassandra" , func ( pod api . Pod ) {
2016-04-07 17:21:31 +00:00
framework . Logf ( "Verifying pod %v " , pod . Name )
_ , err = framework . LookForStringInLog ( ns , pod . Name , "cassandra" , "Listening for thrift clients" , serverStartTimeout )
2015-07-09 22:18:54 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2016-04-07 17:21:31 +00:00
_ , err = framework . LookForStringInLog ( ns , pod . Name , "cassandra" , "Handshaking version" , serverStartTimeout )
2015-07-09 22:18:54 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
} )
2016-02-23 00:05:38 +00:00
By ( "Finding each node in the nodetool status lines" )
2016-03-31 18:45:08 +00:00
forEachPod ( "app" , "cassandra" , func ( pod api . Pod ) {
2016-06-09 01:45:58 +00:00
output := framework . RunKubectlOrDie ( "exec" , pod . Name , nsFlag , "--" , "nodetool" , "status" )
2015-07-09 22:18:54 +00:00
if ! strings . Contains ( output , pod . Status . PodIP ) {
2016-04-07 17:21:31 +00:00
framework . Failf ( "Pod ip %s not found in nodetool status" , pod . Status . PodIP )
2015-07-09 22:18:54 +00:00
}
} )
} )
} )
2015-07-03 13:30:07 +00:00
2016-04-07 17:21:31 +00:00
framework . KubeDescribe ( "Storm" , func ( ) {
2015-07-03 13:30:07 +00:00
It ( "should create and stop Zookeeper, Nimbus and Storm worker servers" , func ( ) {
mkpath := func ( file string ) string {
2016-07-12 01:35:16 +00:00
return filepath . Join ( framework . TestContext . RepoRoot , "examples/storm" , file )
2015-07-03 13:30:07 +00:00
}
zookeeperServiceJson := mkpath ( "zookeeper-service.json" )
zookeeperPodJson := mkpath ( "zookeeper.json" )
nimbusServiceJson := mkpath ( "storm-nimbus-service.json" )
nimbusPodJson := mkpath ( "storm-nimbus.json" )
workerControllerJson := mkpath ( "storm-worker-controller.json" )
nsFlag := fmt . Sprintf ( "--namespace=%v" , ns )
zookeeperPod := "zookeeper"
By ( "starting Zookeeper" )
2016-04-07 17:21:31 +00:00
framework . RunKubectlOrDie ( "create" , "-f" , zookeeperPodJson , nsFlag )
framework . RunKubectlOrDie ( "create" , "-f" , zookeeperServiceJson , nsFlag )
2016-06-29 07:19:26 +00:00
err := framework . WaitForPodNameRunningInNamespace ( c , zookeeperPod , ns )
2015-07-03 13:30:07 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
By ( "checking if zookeeper is up and running" )
2016-04-07 17:21:31 +00:00
_ , err = framework . LookForStringInLog ( ns , zookeeperPod , "zookeeper" , "binding to port" , serverStartTimeout )
2015-07-03 13:30:07 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2016-04-07 17:21:31 +00:00
err = framework . WaitForEndpoint ( c , ns , "zookeeper" )
2015-10-06 11:16:20 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2015-07-03 13:30:07 +00:00
By ( "starting Nimbus" )
2016-04-07 17:21:31 +00:00
framework . RunKubectlOrDie ( "create" , "-f" , nimbusPodJson , nsFlag )
framework . RunKubectlOrDie ( "create" , "-f" , nimbusServiceJson , nsFlag )
2016-06-29 07:19:26 +00:00
err = framework . WaitForPodNameRunningInNamespace ( c , "nimbus" , ns )
2015-07-03 13:30:07 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2015-10-06 11:16:20 +00:00
2016-04-07 17:21:31 +00:00
err = framework . WaitForEndpoint ( c , ns , "nimbus" )
2015-10-06 11:16:20 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2015-07-03 13:30:07 +00:00
By ( "starting workers" )
2016-04-07 17:21:31 +00:00
framework . RunKubectlOrDie ( "create" , "-f" , workerControllerJson , nsFlag )
2016-06-09 01:45:58 +00:00
label := labels . SelectorFromSet ( labels . Set ( map [ string ] string { "name" : "storm-worker" } ) )
err = framework . WaitForPodsWithLabelRunning ( c , ns , label )
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2016-03-31 18:45:08 +00:00
forEachPod ( "name" , "storm-worker" , func ( pod api . Pod ) {
2015-07-03 13:30:07 +00:00
//do nothing, just wait for the pod to be running
} )
// TODO: Add logging configuration to nimbus & workers images and then
// look for a string instead of sleeping.
time . Sleep ( 20 * time . Second )
By ( "checking if there are established connections to Zookeeper" )
2016-04-07 17:21:31 +00:00
_ , err = framework . LookForStringInLog ( ns , zookeeperPod , "zookeeper" , "Established session" , serverStartTimeout )
2015-07-03 13:30:07 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
By ( "checking if Nimbus responds to requests" )
2016-04-07 17:21:31 +00:00
framework . LookForString ( "No topologies running." , time . Minute , func ( ) string {
return framework . RunKubectlOrDie ( "exec" , "nimbus" , nsFlag , "--" , "bin/storm" , "list" )
2015-07-03 13:30:07 +00:00
} )
} )
} )
2016-04-07 17:21:31 +00:00
framework . KubeDescribe ( "Liveness" , func ( ) {
2015-07-24 08:03:48 +00:00
It ( "liveness pods should be automatically restarted" , func ( ) {
mkpath := func ( file string ) string {
2016-09-01 14:37:13 +00:00
path := filepath . Join ( "test/fixtures/doc-yaml/user-guide/liveness" , file )
ExpectNoError ( framework . CreateFileForGoBinData ( path , path ) )
return path
2015-07-24 08:03:48 +00:00
}
execYaml := mkpath ( "exec-liveness.yaml" )
httpYaml := mkpath ( "http-liveness.yaml" )
nsFlag := fmt . Sprintf ( "--namespace=%v" , ns )
2016-09-01 14:37:13 +00:00
framework . RunKubectlOrDie ( "create" , "-f" , filepath . Join ( framework . TestContext . OutputDir , execYaml ) , nsFlag )
framework . RunKubectlOrDie ( "create" , "-f" , filepath . Join ( framework . TestContext . OutputDir , httpYaml ) , nsFlag )
2016-03-09 21:32:32 +00:00
// Since both containers start rapidly, we can easily run this test in parallel.
var wg sync . WaitGroup
passed := true
2015-07-24 08:03:48 +00:00
checkRestart := func ( podName string , timeout time . Duration ) {
2016-06-29 07:19:26 +00:00
err := framework . WaitForPodNameRunningInNamespace ( c , podName , ns )
2015-07-24 08:03:48 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2016-04-07 17:21:31 +00:00
for t := time . Now ( ) ; time . Since ( t ) < timeout ; time . Sleep ( framework . Poll ) {
2015-07-24 08:03:48 +00:00
pod , err := c . Pods ( ns ) . Get ( podName )
2016-04-07 17:21:31 +00:00
framework . ExpectNoError ( err , fmt . Sprintf ( "getting pod %s" , podName ) )
2016-03-09 21:32:32 +00:00
stat := api . GetExistingContainerStatus ( pod . Status . ContainerStatuses , podName )
2016-04-07 17:21:31 +00:00
framework . Logf ( "Pod: %s, restart count:%d" , stat . Name , stat . RestartCount )
2016-03-09 21:32:32 +00:00
if stat . RestartCount > 0 {
2016-04-07 17:21:31 +00:00
framework . Logf ( "Saw %v restart, succeeded..." , podName )
2016-03-09 21:32:32 +00:00
wg . Done ( )
2015-07-24 08:03:48 +00:00
return
}
}
2016-04-07 17:21:31 +00:00
framework . Logf ( "Failed waiting for %v restart! " , podName )
2016-03-09 21:32:32 +00:00
passed = false
wg . Done ( )
2015-07-24 08:03:48 +00:00
}
2016-03-09 21:32:32 +00:00
2015-07-24 08:03:48 +00:00
By ( "Check restarts" )
2016-03-09 21:32:32 +00:00
// Start the "actual test", and wait for both pods to complete.
// If 2 fail: Something is broken with the test (or maybe even with liveness).
// If 1 fails: Its probably just an error in the examples/ files themselves.
wg . Add ( 2 )
for _ , c := range [ ] string { "liveness-http" , "liveness-exec" } {
go checkRestart ( c , 2 * time . Minute )
}
wg . Wait ( )
if ! passed {
2016-04-07 17:21:31 +00:00
framework . Failf ( "At least one liveness example failed. See the logs above." )
2016-03-09 21:32:32 +00:00
}
2015-07-24 08:03:48 +00:00
} )
} )
2015-07-24 10:27:55 +00:00
2016-04-07 17:21:31 +00:00
framework . KubeDescribe ( "Secret" , func ( ) {
2015-07-24 10:27:55 +00:00
It ( "should create a pod that reads a secret" , func ( ) {
mkpath := func ( file string ) string {
2016-09-01 14:37:13 +00:00
path := filepath . Join ( "test/fixtures/doc-yaml/user-guide/secrets" , file )
ExpectNoError ( framework . CreateFileForGoBinData ( path , path ) )
return path
2015-07-24 10:27:55 +00:00
}
secretYaml := mkpath ( "secret.yaml" )
podYaml := mkpath ( "secret-pod.yaml" )
2016-09-01 14:37:13 +00:00
2015-07-24 10:27:55 +00:00
nsFlag := fmt . Sprintf ( "--namespace=%v" , ns )
2016-02-27 00:35:21 +00:00
podName := "secret-test-pod"
2015-07-24 10:27:55 +00:00
By ( "creating secret and pod" )
2016-09-01 14:37:13 +00:00
framework . RunKubectlOrDie ( "create" , "-f" , filepath . Join ( framework . TestContext . OutputDir , secretYaml ) , nsFlag )
framework . RunKubectlOrDie ( "create" , "-f" , filepath . Join ( framework . TestContext . OutputDir , podYaml ) , nsFlag )
2016-06-29 07:19:26 +00:00
err := framework . WaitForPodNoLongerRunningInNamespace ( c , podName , ns , "" )
2016-02-27 00:35:21 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2015-07-24 10:27:55 +00:00
By ( "checking if secret was read correctly" )
2016-04-07 17:21:31 +00:00
_ , err = framework . LookForStringInLog ( ns , "secret-test-pod" , "test-container" , "value-1" , serverStartTimeout )
2015-07-24 10:27:55 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
} )
} )
2016-04-07 17:21:31 +00:00
framework . KubeDescribe ( "Downward API" , func ( ) {
2015-07-24 10:27:55 +00:00
It ( "should create a pod that prints his name and namespace" , func ( ) {
mkpath := func ( file string ) string {
2016-09-01 14:37:13 +00:00
path := filepath . Join ( "test/fixtures/doc-yaml/user-guide/downward-api" , file )
ExpectNoError ( framework . CreateFileForGoBinData ( path , path ) )
return path
2015-07-24 10:27:55 +00:00
}
podYaml := mkpath ( "dapi-pod.yaml" )
nsFlag := fmt . Sprintf ( "--namespace=%v" , ns )
podName := "dapi-test-pod"
By ( "creating the pod" )
2016-09-01 14:37:13 +00:00
framework . RunKubectlOrDie ( "create" , "-f" , filepath . Join ( framework . TestContext . OutputDir , podYaml ) , nsFlag )
2016-06-29 07:19:26 +00:00
err := framework . WaitForPodNoLongerRunningInNamespace ( c , podName , ns , "" )
2016-02-27 00:35:21 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2015-07-24 10:27:55 +00:00
By ( "checking if name and namespace were passed correctly" )
2016-04-07 17:21:31 +00:00
_ , err = framework . LookForStringInLog ( ns , podName , "test-container" , fmt . Sprintf ( "MY_POD_NAMESPACE=%v" , ns ) , serverStartTimeout )
2015-07-24 10:27:55 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2016-04-07 17:21:31 +00:00
_ , err = framework . LookForStringInLog ( ns , podName , "test-container" , fmt . Sprintf ( "MY_POD_NAME=%v" , podName ) , serverStartTimeout )
2015-07-24 10:27:55 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
} )
} )
2015-07-24 12:51:52 +00:00
2016-04-07 17:21:31 +00:00
framework . KubeDescribe ( "RethinkDB" , func ( ) {
2015-07-24 12:51:52 +00:00
It ( "should create and stop rethinkdb servers" , func ( ) {
mkpath := func ( file string ) string {
2016-07-12 01:35:16 +00:00
return filepath . Join ( framework . TestContext . RepoRoot , "examples/storage/rethinkdb" , file )
2015-07-24 12:51:52 +00:00
}
driverServiceYaml := mkpath ( "driver-service.yaml" )
rethinkDbControllerYaml := mkpath ( "rc.yaml" )
adminPodYaml := mkpath ( "admin-pod.yaml" )
adminServiceYaml := mkpath ( "admin-service.yaml" )
nsFlag := fmt . Sprintf ( "--namespace=%v" , ns )
By ( "starting rethinkdb" )
2016-04-07 17:21:31 +00:00
framework . RunKubectlOrDie ( "create" , "-f" , driverServiceYaml , nsFlag )
framework . RunKubectlOrDie ( "create" , "-f" , rethinkDbControllerYaml , nsFlag )
2016-06-09 01:45:58 +00:00
label := labels . SelectorFromSet ( labels . Set ( map [ string ] string { "db" : "rethinkdb" } ) )
err := framework . WaitForPodsWithLabelRunning ( c , ns , label )
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2015-07-24 12:51:52 +00:00
checkDbInstances := func ( ) {
2016-03-31 18:45:08 +00:00
forEachPod ( "db" , "rethinkdb" , func ( pod api . Pod ) {
2016-06-09 01:45:58 +00:00
_ , err = framework . LookForStringInLog ( ns , pod . Name , "rethinkdb" , "Server ready" , serverStartTimeout )
2015-07-24 12:51:52 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
} )
}
checkDbInstances ( )
2016-06-09 01:45:58 +00:00
err = framework . WaitForEndpoint ( c , ns , "rethinkdb-driver" )
2015-10-06 11:16:20 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2015-07-24 12:51:52 +00:00
By ( "scaling rethinkdb" )
2016-04-07 17:21:31 +00:00
framework . ScaleRC ( c , ns , "rethinkdb-rc" , 2 , true )
2015-07-24 12:51:52 +00:00
checkDbInstances ( )
By ( "starting admin" )
2016-04-07 17:21:31 +00:00
framework . RunKubectlOrDie ( "create" , "-f" , adminServiceYaml , nsFlag )
framework . RunKubectlOrDie ( "create" , "-f" , adminPodYaml , nsFlag )
2016-06-29 07:19:26 +00:00
err = framework . WaitForPodNameRunningInNamespace ( c , "rethinkdb-admin" , ns )
2015-07-24 12:51:52 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
checkDbInstances ( )
2016-04-07 17:21:31 +00:00
content , err := makeHttpRequestToService ( c , ns , "rethinkdb-admin" , "/" , framework . EndpointRegisterTimeout )
2015-07-24 12:51:52 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
if ! strings . Contains ( content , "<title>RethinkDB Administration Console</title>" ) {
2016-04-07 17:21:31 +00:00
framework . Failf ( "RethinkDB console is not running" )
2015-07-24 12:51:52 +00:00
}
} )
} )
2015-07-24 14:01:33 +00:00
2016-04-07 17:21:31 +00:00
framework . KubeDescribe ( "Hazelcast" , func ( ) {
2015-07-24 14:01:33 +00:00
It ( "should create and scale hazelcast" , func ( ) {
2016-09-01 23:25:33 +00:00
framework . Skipf ( "Skipping because of upstream race condition. Remove Skip when https://github.com/pires/hazelcast-kubernetes-bootstrapper/issues/9 is fixed" )
2015-07-24 14:01:33 +00:00
mkpath := func ( file string ) string {
2016-07-12 01:35:16 +00:00
return filepath . Join ( framework . TestContext . RepoRoot , "examples/storage/hazelcast" , file )
2015-07-24 14:01:33 +00:00
}
serviceYaml := mkpath ( "hazelcast-service.yaml" )
controllerYaml := mkpath ( "hazelcast-controller.yaml" )
nsFlag := fmt . Sprintf ( "--namespace=%v" , ns )
By ( "starting hazelcast" )
2016-04-07 17:21:31 +00:00
framework . RunKubectlOrDie ( "create" , "-f" , serviceYaml , nsFlag )
framework . RunKubectlOrDie ( "create" , "-f" , controllerYaml , nsFlag )
2016-06-09 01:45:58 +00:00
label := labels . SelectorFromSet ( labels . Set ( map [ string ] string { "name" : "hazelcast" } ) )
err := framework . WaitForPodsWithLabelRunning ( c , ns , label )
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2016-03-31 18:45:08 +00:00
forEachPod ( "name" , "hazelcast" , func ( pod api . Pod ) {
2016-04-07 17:21:31 +00:00
_ , err := framework . LookForStringInLog ( ns , pod . Name , "hazelcast" , "Members [1]" , serverStartTimeout )
2015-07-24 14:01:33 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2016-04-07 17:21:31 +00:00
_ , err = framework . LookForStringInLog ( ns , pod . Name , "hazelcast" , "is STARTED" , serverStartTimeout )
2015-07-24 14:01:33 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
} )
2016-06-09 01:45:58 +00:00
err = framework . WaitForEndpoint ( c , ns , "hazelcast" )
2015-10-06 11:16:20 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
2015-10-02 15:22:31 +00:00
2015-07-24 14:01:33 +00:00
By ( "scaling hazelcast" )
2016-04-07 17:21:31 +00:00
framework . ScaleRC ( c , ns , "hazelcast" , 2 , true )
2016-03-31 18:45:08 +00:00
forEachPod ( "name" , "hazelcast" , func ( pod api . Pod ) {
2016-04-07 17:21:31 +00:00
_ , err := framework . LookForStringInLog ( ns , pod . Name , "hazelcast" , "Members [2]" , serverStartTimeout )
2015-07-24 14:01:33 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
} )
} )
} )
2015-06-20 18:57:07 +00:00
} )
2015-07-30 11:34:45 +00:00
func makeHttpRequestToService ( c * client . Client , ns , service , path string , timeout time . Duration ) ( string , error ) {
var result [ ] byte
var err error
2016-04-07 17:21:31 +00:00
for t := time . Now ( ) ; time . Since ( t ) < timeout ; time . Sleep ( framework . Poll ) {
proxyRequest , errProxy := framework . GetServicesProxyRequest ( c , c . Get ( ) )
2015-11-18 03:42:03 +00:00
if errProxy != nil {
break
}
result , err = proxyRequest . Namespace ( ns ) .
2015-07-30 11:34:45 +00:00
Name ( service ) .
Suffix ( path ) .
Do ( ) .
Raw ( )
if err != nil {
break
}
}
2015-07-08 09:01:55 +00:00
return string ( result ) , err
}
2015-07-10 09:54:54 +00:00
// pass enough context with the 'old' parameter so that it replaces what your really intended.
func prepareResourceWithReplacedString ( inputFile , old , new string ) string {
f , err := os . Open ( inputFile )
Expect ( err ) . NotTo ( HaveOccurred ( ) )
defer f . Close ( )
data , err := ioutil . ReadAll ( f )
Expect ( err ) . NotTo ( HaveOccurred ( ) )
podYaml := strings . Replace ( string ( data ) , old , new , 1 )
return podYaml
}