Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Aug 30, 2018
1 parent bedea13 commit d5a5cc7
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 72 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@ test:
@go test -v -covermode=count -coverprofile=coverage.out ./pkg/... ./cmd/...
@test -z $(COVERALLS_TOKEN) || goveralls -coverprofile=coverage.out -service=circle-ci

.PHONY: integration-test-dev
integration-test-dev: build
@go test -tags integration -v -timeout 21m ./tests/integration/... \
-args \
-eksctl.cluster=integration-test-dev \
-eksctl.create=false \
-eksctl.delete=false \
-eksctl.kubeconfig=$(HOME)/.kube/config

.PHONY: integration-test
integration-test: build
@go test -tags integration -v -timeout 21m ./tests/integration/... -args -skip-creation false
@go test -tags integration -v -timeout 21m ./tests/integration/...

.PHONY: generated
generate:
Expand Down
132 changes: 82 additions & 50 deletions tests/integration/create_get_delete/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,77 @@ import (
"time"

awseks "github.com/aws/aws-sdk-go/service/eks"

harness "github.com/dlespiau/kube-test-harness"
"github.com/dlespiau/kube-test-harness/logger"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"

"github.com/weaveworks/eksctl/pkg/utils"

"github.com/weaveworks/eksctl/pkg/testutils/aws"
. "github.com/weaveworks/eksctl/pkg/testutils/matchers"
"github.com/weaveworks/eksctl/tests/integration"
//"k8s.io/client-go/tools/clientcmd"
)

const (
clusterName = "int-cluster"
createTimeoutInMins = 20
eksRegion = "us-west-2"
createTimeout = 20
region = "us-west-2"
)

var (
pathToEksCtl string
autoGeneratedConf bool
eksctlPath string

// Flags to help with the development of the integration tests
clusterName string
doCreate bool
doDelete bool
kubeconfigPath string

// Flags to help with developing the integration tests
skipCreation bool
skipCleanup bool
pathKubeCtlConf string
kubeconfigTemp bool
)

func TestCreateIntegration(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Integration - Create Suite")
}

type tInterface interface {
GinkgoTInterface
Helper()
}

type tHelper struct{ GinkgoTInterface }

func (t *tHelper) Helper() { return }
func (t *tHelper) Name() string { return "eksctl-test" }

func newKubeTest(h *harness.Harness) *harness.Test {
return h.NewTest(&tHelper{GinkgoT()})
}

var _ = Describe("Create (Integration)", func() {

BeforeSuite(func() {
if pathKubeCtlConf == "" {
currentdir, _ := os.Getwd()
tempFile, _ := ioutil.TempFile(currentdir, "kubeconf")
pathKubeCtlConf = tempFile.Name()
autoGeneratedConf = true
kubeconfigTemp = false
if kubeconfigPath == "" {
wd, _ := os.Getwd()
f, _ := ioutil.TempFile(wd, "kubeconfig-")
kubeconfigPath = f.Name()
kubeconfigTemp = true
}
fmt.Printf("Using kubeconfig: %s\n", pathKubeCtlConf)
})

AfterSuite(func() {
gexec.KillAndWait()
if !skipCleanup {
integration.CleanupAws(clusterName, eksRegion)
if autoGeneratedConf {
os.Remove(pathKubeCtlConf)
}
if kubeconfigTemp {
os.Remove(kubeconfigPath)
}
if doCreate && doDelete {
integration.CleanupAws(clusterName, region)
}
})

Expand All @@ -73,31 +93,37 @@ var _ = Describe("Create (Integration)", func() {
)

It("should not return an error", func() {
if skipCreation {
fmt.Printf("Creation test skip: %t\n", skipCreation)
if !doCreate {
fmt.Printf("will use existing cluster %s", clusterName)
return
}

args := []string{"create", "cluster", "-n", clusterName, "-t", "t2.medium", "-N", "1", "-r", eksRegion, "--kubeconfig", pathToEksCtl}
fmt.Printf("Using kubeconfig: %s\n", kubeconfigPath)

if clusterName == "" {
clusterName = utils.ClusterName("", "")
}

args := []string{"create", "cluster", "--name", clusterName, "--node-type", "t2.medium", "--nodes", "1", "--region", region, "--kubeconfig", kubeconfigPath}

command := exec.Command(pathToEksCtl, args...)
command := exec.Command(eksctlPath, args...)
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)

if err != nil {
Fail(fmt.Sprintf("error starting process: %v", err), 1)
}

session.Wait(createTimeoutInMins * time.Minute)
session.Wait(createTimeout * time.Minute)
Expect(session.ExitCode()).Should(Equal(0))
})

It("should have created an EKS cluster", func() {
session := aws.NewSession(eksRegion)
session := aws.NewSession(region)
Expect(session).To(HaveEksCluster(clusterName, awseks.ClusterStatusActive, "1.10"))
})

It("should have the required cloudformation stacks", func() {
session := aws.NewSession(eksRegion)
session := aws.NewSession(region)

Expect(session).To(HaveCfnStack(fmt.Sprintf("EKS-%s-VPC", clusterName)))
Expect(session).To(HaveCfnStack(fmt.Sprintf("EKS-%s-ControlPlane", clusterName)))
Expand All @@ -116,43 +142,49 @@ var _ = Describe("Create (Integration)", func() {
})*/

Context("and we create a deployment using kubectl", func() {
var (
kube *harness.Harness
)
var test *harness.Test

h := harness.New(harness.Options{
Kubeconfig: kubeconfigPath,
Logger: &logger.TestLogger{},
})

BeforeEach(func() {
opts := harness.Options{
Kubeconfig: pathKubeCtlConf,
Logger: &logger.TestLogger{},
}
kube = harness.New(opts)
err := h.Setup()
Expect(err).ShouldNot(HaveOccurred())
test = newKubeTest(h)
test.CreateNamespace(test.Namespace)
})

It("should deploy the service to the cluster", func() {
test := kube.NewTest(GinkgoT()).Setup()
defer test.Close()
AfterEach(func() {
test.Close()
})

d := test.CreateDeploymentFromFile("default", "nginx-deployment.yaml")
It("should deploy the service to the cluster", func() {
d := test.CreateDeploymentFromFile(test.Namespace, "podinfo.yaml")
test.WaitForDeploymentReady(d, 1*time.Minute)

// For each pod of the Deployment, check we receive a sensible response to a
// GET request on /.
for _, pod := range test.ListPodsFromDeployment(d).Items {
_, err := test.PodProxyGet(&pod, "80", "/").DoRaw()
pods := test.ListPodsFromDeployment(d)
Expect(len(pods.Items)).To(Equal(2))
// // For each pod of the Deployment, check we receive a sensible response to a
// // GET request on /.
// for _, pod := range pods.Items {
// _, err := test.PodProxyGet(&pod, "http", "/").DoRaw()

Expect(err).ShouldNot(HaveOccurred())
//TODO: compare response???
}
// Expect(err).ShouldNot(HaveOccurred())
// //TODO: compare response???
// }
})
})
})
})

func init() {
flag.StringVar(&pathToEksCtl, "eksctl-path", "./eksctl", "Path to eksctl")
flag.StringVar(&eksctlPath, "eksctl.path", "../../../eksctl", "Path to eksctl")

// Flags to help with the development of the integration tests
flag.BoolVar(&skipCreation, "skip-creation", false, "Skip the creation tests. Useful for debugging the tests")
flag.BoolVar(&skipCleanup, "skip-cleanup", false, "Skip the cleanup after the tests have run")
flag.StringVar(&pathKubeCtlConf, "kubeconf-path", "", "Path to kubectl config. Default is to create a temporary file")
flag.StringVar(&clusterName, "eksctl.cluster", "", "Cluster name (default: generate one)")
flag.BoolVar(&doCreate, "eksctl.create", true, "Skip the creation tests. Useful for debugging the tests")
flag.BoolVar(&doDelete, "eksctl.delete", true, "Skip the cleanup after the tests have run")
flag.StringVar(&kubeconfigPath, "eksctl.kubeconfig", "", "Path to kubeconfig (default: create it a temporary file)")
}
21 changes: 0 additions & 21 deletions tests/integration/create_get_delete/nginx-deployment.yaml

This file was deleted.

47 changes: 47 additions & 0 deletions tests/integration/create_get_delete/podinfo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: podinfo
labels:
app: podinfo
spec:
replicas: 2
selector:
matchLabels:
app: podinfo
template:
metadata:
labels:
app: podinfo
annotations:
prometheus.io/scrape: 'true'
spec:
containers:
- name: podinfod
image: quay.io/stefanprodan/podinfo:1.0.1
command:
- ./podinfo
- --port=8080
ports:
- name: http
containerPort: 8080
protocol: TCP
readinessProbe:
httpGet:
path: /readyz
port: 8080
initialDelaySeconds: 1
periodSeconds: 5
failureThreshold: 1
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 1
periodSeconds: 10
failureThreshold: 2
resources:
requests:
memory: "32Mi"
cpu: "10m"

0 comments on commit d5a5cc7

Please sign in to comment.