Skip to content

Commit

Permalink
create clusters in before suites (#3296)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Klein committed Feb 22, 2021
1 parent 1d6574f commit 98d777c
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 196 deletions.
18 changes: 9 additions & 9 deletions integration/tests/addons/addons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var _ = Describe("(Integration) [EKS Addons test]", func() {
Context("Creating a cluster with addons", func() {
clusterName := params.NewClusterName("addons")

BeforeEach(func() {
BeforeSuite(func() {
clusterConfig := api.NewClusterConfig()
clusterConfig.Metadata.Name = clusterName
clusterConfig.Metadata.Version = "1.19"
Expand Down Expand Up @@ -68,6 +68,14 @@ var _ = Describe("(Integration) [EKS Addons test]", func() {

})

AfterSuite(func() {
cmd := params.EksctlDeleteCmd.WithArgs(
"cluster", clusterName,
"--verbose", "2",
)
Expect(cmd).To(RunSuccessfully())
})

It("should support addons", func() {
By("Asserting the addon is listed in `get addons`")
cmd := params.EksctlGetCmd.
Expand Down Expand Up @@ -100,14 +108,6 @@ var _ = Describe("(Integration) [EKS Addons test]", func() {
)
Expect(cmd).To(RunSuccessfully())
})

AfterEach(func() {
cmd := params.EksctlDeleteCmd.WithArgs(
"cluster", clusterName,
"--verbose", "2",
)
Expect(cmd).To(RunSuccessfully())
})
})

It("should describe addons", func() {
Expand Down
28 changes: 13 additions & 15 deletions integration/tests/before_active/createdeletebeforeactive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,19 @@ const (
var _ = Describe("(Integration) Create & Delete before Active", func() {
const initNG = "ng-0"

Context("when creating a new cluster", func() {
It("should not return an error", func() {
cmd := params.EksctlCreateCmd.WithArgs(
"cluster",
"--verbose", "2",
"--name", params.ClusterName,
"--tags", "alpha.eksctl.io/description=eksctl delete before active test",
"--without-nodegroup",
"--version", params.Version,
)
cmd.Start()
awsSession := NewSession(params.Region)
Eventually(awsSession, timeOutSeconds, pollInterval).Should(
HaveExistingCluster(params.ClusterName, awseks.ClusterStatusCreating, params.Version))
})
BeforeSuite(func() {
cmd := params.EksctlCreateCmd.WithArgs(
"cluster",
"--verbose", "2",
"--name", params.ClusterName,
"--tags", "alpha.eksctl.io/description=eksctl delete before active test",
"--without-nodegroup",
"--version", params.Version,
)
cmd.Start()
awsSession := NewSession(params.Region)
Eventually(awsSession, timeOutSeconds, pollInterval).Should(
HaveExistingCluster(params.ClusterName, awseks.ClusterStatusCreating, params.Version))
})

Context("when deleting the cluster in process of being created", func() {
Expand Down
80 changes: 39 additions & 41 deletions integration/tests/crud/creategetdelete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ import (
"testing"
"time"

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

"k8s.io/client-go/kubernetes"

awseks "github.com/aws/aws-sdk-go/service/eks"
harness "github.com/dlespiau/kube-test-harness"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
. "github.com/weaveworks/eksctl/integration/matchers"
. "github.com/weaveworks/eksctl/integration/runner"
"github.com/weaveworks/eksctl/integration/tests"
Expand All @@ -23,13 +30,6 @@ import (
"github.com/weaveworks/eksctl/pkg/iam"
iamoidc "github.com/weaveworks/eksctl/pkg/iam/oidc"
"github.com/weaveworks/eksctl/pkg/testutils"
"github.com/weaveworks/eksctl/pkg/utils/file"

awseks "github.com/aws/aws-sdk-go/service/eks"
harness "github.com/dlespiau/kube-test-harness"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -64,6 +64,37 @@ var _ = Describe("(Integration) Create, Get, Scale & Delete", func() {
params.KubeconfigPath = f.Name()
params.KubeconfigTemp = true
}

if params.SkipCreate {
fmt.Fprintf(GinkgoWriter, "will use existing cluster %s", params.ClusterName)
if !file.Exists(params.KubeconfigPath) {
// Generate the Kubernetes configuration that eksctl create
// would have generated otherwise:
cmd := params.EksctlUtilsCmd.WithArgs(
"write-kubeconfig",
"--verbose", "4",
"--cluster", params.ClusterName,
"--kubeconfig", params.KubeconfigPath,
)
Expect(cmd).To(RunSuccessfully())
}
return
}

fmt.Fprintf(GinkgoWriter, "Using kubeconfig: %s\n", params.KubeconfigPath)

cmd := params.EksctlCreateCmd.WithArgs(
"cluster",
"--verbose", "4",
"--name", params.ClusterName,
"--tags", "alpha.eksctl.io/description=eksctl integration test",
"--nodegroup-name", initNG,
"--node-labels", "ng-name="+initNG,
"--nodes", "1",
"--version", params.Version,
"--kubeconfig", params.KubeconfigPath,
)
Expect(cmd).To(RunSuccessfully())
})

AfterSuite(func() {
Expand All @@ -75,40 +106,7 @@ var _ = Describe("(Integration) Create, Get, Scale & Delete", func() {
os.RemoveAll(params.TestDirectory)
})

Describe("when creating a cluster with 1 node", func() {
It("should not return an error", func() {
if params.SkipCreate {
fmt.Fprintf(GinkgoWriter, "will use existing cluster %s", params.ClusterName)
if !file.Exists(params.KubeconfigPath) {
// Generate the Kubernetes configuration that eksctl create
// would have generated otherwise:
cmd := params.EksctlUtilsCmd.WithArgs(
"write-kubeconfig",
"--verbose", "4",
"--cluster", params.ClusterName,
"--kubeconfig", params.KubeconfigPath,
)
Expect(cmd).To(RunSuccessfully())
}
return
}

fmt.Fprintf(GinkgoWriter, "Using kubeconfig: %s\n", params.KubeconfigPath)

cmd := params.EksctlCreateCmd.WithArgs(
"cluster",
"--verbose", "4",
"--name", params.ClusterName,
"--tags", "alpha.eksctl.io/description=eksctl integration test",
"--nodegroup-name", initNG,
"--node-labels", "ng-name="+initNG,
"--nodes", "1",
"--version", params.Version,
"--kubeconfig", params.KubeconfigPath,
)
Expect(cmd).To(RunSuccessfully())
})

Describe("cluster with 1 node", func() {
It("should have created an EKS cluster and two CloudFormation stacks", func() {
awsSession := NewSession(params.Region)

Expand Down
133 changes: 59 additions & 74 deletions integration/tests/inferentia/inferentia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@ package inferentia

import (
"context"
"fmt"
"io/ioutil"
"os"
"testing"

"k8s.io/client-go/kubernetes"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
. "github.com/weaveworks/eksctl/integration/matchers"
. "github.com/weaveworks/eksctl/integration/runner"
"github.com/weaveworks/eksctl/integration/tests"
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
"github.com/weaveworks/eksctl/pkg/eks"
"github.com/weaveworks/eksctl/pkg/testutils"
"github.com/weaveworks/eksctl/pkg/utils/file"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var defaultCluster string
var noInstallCluster string
var params *tests.Params
var (
defaultCluster string
noInstallCluster string
params *tests.Params
clusterWithNeuronPlugin string
clusterWithoutPlugin string
)

func init() {
// Call testing.Init() prior to tests.NewParams(), as otherwise -test.* will not be recognised. See also: https://golang.org/doc/go1.13#testing
Expand All @@ -54,6 +55,40 @@ var _ = Describe("(Integration) Inferentia nodes", func() {
params.KubeconfigPath = f.Name()
params.KubeconfigTemp = true
}

clusterWithoutPlugin = noInstallCluster
clusterWithNeuronPlugin = defaultCluster

if !params.SkipCreate {
cmd := params.EksctlCreateCmd.WithArgs(
"cluster",
"--verbose", "4",
"--name", clusterWithoutPlugin,
"--tags", "alpha.eksctl.io/description=eksctl integration test",
"--install-neuron-plugin=false",
"--nodegroup-name", initNG,
"--node-labels", "ng-name="+initNG,
"--nodes", "1",
"--node-type", "inf1.xlarge",
"--version", params.Version,
"--kubeconfig", params.KubeconfigPath,
)
Expect(cmd).To(RunSuccessfully())

cmd = params.EksctlCreateCmd.WithArgs(
"cluster",
"--verbose", "4",
"--name", clusterWithNeuronPlugin,
"--tags", "alpha.eksctl.io/description=eksctl integration test",
"--nodegroup-name", initNG,
"--node-labels", "ng-name="+initNG,
"--nodes", "1",
"--node-type", "inf1.xlarge",
"--version", params.Version,
"--kubeconfig", params.KubeconfigPath,
)
Expect(cmd).To(RunSuccessfully())
}
})

AfterSuite(func() {
Expand All @@ -65,101 +100,51 @@ var _ = Describe("(Integration) Inferentia nodes", func() {
os.RemoveAll(params.TestDirectory)
})

When("creating a cluster with inf1 nodes", func() {
Context("cluster with inf1 nodes", func() {
Context("by default", func() {
clusterName := defaultCluster
It("should not return an error", func() {
if params.SkipCreate {
fmt.Fprintf(GinkgoWriter, "will use existing cluster %s", defaultCluster)
if !file.Exists(params.KubeconfigPath) {
// Generate the Kubernetes configuration that eksctl create
// would have generated otherwise:
cmd := params.EksctlUtilsCmd.WithArgs(
"write-kubeconfig",
"--verbose", "4",
"--cluster", clusterName,
"--kubeconfig", params.KubeconfigPath,
)
Expect(cmd).To(RunSuccessfully())
}
return
}

fmt.Fprintf(GinkgoWriter, "Using kubeconfig: %s\n", params.KubeconfigPath)

cmd := params.EksctlCreateCmd.WithArgs(
"cluster",
BeforeEach(func() {
cmd := params.EksctlUtilsCmd.WithArgs(
"write-kubeconfig",
"--verbose", "4",
"--name", clusterName,
"--tags", "alpha.eksctl.io/description=eksctl integration test",
"--nodegroup-name", initNG,
"--node-labels", "ng-name="+initNG,
"--nodes", "1",
"--node-type", "inf1.xlarge",
"--version", params.Version,
"--cluster", clusterWithoutPlugin,
"--kubeconfig", params.KubeconfigPath,
)
Expect(cmd).To(RunSuccessfully())
})

It("should have installed the neuron device plugin", func() {
clientSet := newClientSet(clusterName)
clientSet := newClientSet(clusterWithNeuronPlugin)
_, err := clientSet.AppsV1().DaemonSets("kube-system").Get(context.TODO(), "neuron-device-plugin-daemonset", metav1.GetOptions{})
Expect(err).ShouldNot(HaveOccurred())
})

It("should not have installed the nvidia device plugin", func() {
_, err := newClientSet(clusterName).AppsV1().DaemonSets("kube-system").Get(context.TODO(), "nvidia-device-plugin-daemonset", metav1.GetOptions{})
_, err := newClientSet(clusterWithNeuronPlugin).AppsV1().DaemonSets("kube-system").Get(context.TODO(), "nvidia-device-plugin-daemonset", metav1.GetOptions{})
Expect(err).Should(BeNotFoundError())
})
})

Context("with --install-neuron-plugin=false", func() {
clusterName := noInstallCluster
It("should not return an error", func() {
if params.SkipCreate {
fmt.Fprintf(GinkgoWriter, "will use existing cluster %s", noInstallCluster)
if !file.Exists(params.KubeconfigPath) {
// Generate the Kubernetes configuration that eksctl create
// would have generated otherwise:
cmd := params.EksctlUtilsCmd.WithArgs(
"write-kubeconfig",
"--verbose", "4",
"--cluster", clusterName,
"--kubeconfig", params.KubeconfigPath,
)
Expect(cmd).To(RunSuccessfully())
}
return
}

fmt.Fprintf(GinkgoWriter, "Using kubeconfig: %s\n", params.KubeconfigPath)

cmd := params.EksctlCreateCmd.WithArgs(
"cluster",
BeforeEach(func() {
cmd := params.EksctlUtilsCmd.WithArgs(
"write-kubeconfig",
"--verbose", "4",
"--name", clusterName,
"--tags", "alpha.eksctl.io/description=eksctl integration test",
"--install-neuron-plugin=false",
"--nodegroup-name", initNG,
"--node-labels", "ng-name="+initNG,
"--nodes", "1",
"--node-type", "inf1.xlarge",
"--version", params.Version,
"--cluster", clusterWithoutPlugin,
"--kubeconfig", params.KubeconfigPath,
)
Expect(cmd).To(RunSuccessfully())
})

It("should not have installed the neuron device plugin", func() {
_, err := newClientSet(clusterName).AppsV1().DaemonSets("kube-system").Get(context.TODO(), "neuron-device-plugin-daemonset", metav1.GetOptions{})
_, err := newClientSet(clusterWithoutPlugin).AppsV1().DaemonSets("kube-system").Get(context.TODO(), "neuron-device-plugin-daemonset", metav1.GetOptions{})
Expect(err).Should(BeNotFoundError())
})

When("adding a nodegroup by default", func() {
It("should install without error", func() {
cmd := params.EksctlCreateCmd.WithArgs(
"nodegroup",
"--cluster", clusterName,
"--cluster", clusterWithoutPlugin,
"--nodes", "1",
"--verbose", "4",
"--name", newNG,
Expand All @@ -172,7 +157,7 @@ var _ = Describe("(Integration) Inferentia nodes", func() {
Expect(cmd).To(RunSuccessfully())
})
It("should install the neuron device plugin", func() {
_, err := newClientSet(clusterName).AppsV1().DaemonSets("kube-system").Get(context.TODO(), "neuron-device-plugin-daemonset", metav1.GetOptions{})
_, err := newClientSet(clusterWithoutPlugin).AppsV1().DaemonSets("kube-system").Get(context.TODO(), "neuron-device-plugin-daemonset", metav1.GetOptions{})
Expect(err).ShouldNot(HaveOccurred())
})
})
Expand Down

0 comments on commit 98d777c

Please sign in to comment.