Skip to content

Commit

Permalink
Run e2e with Ginkgo
Browse files Browse the repository at this point in the history
  • Loading branch information
ingvagabund committed Sep 28, 2018
1 parent f08b1ca commit a89ebc6
Show file tree
Hide file tree
Showing 6 changed files with 1,114 additions and 114 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ test: # Run unit test
integration: ## Run integration test
go test -v sigs.k8s.io/cluster-api-provider-aws/test/integration

.PHONY: test-e2e
test-e2e: ## Run e2e test
go test -v sigs.k8s.io/cluster-api-provider-aws/test/machines -kubeconfig $${KUBECONFIG:-~/.kube/config} -cluster-id $${ENVIRONMENT_ID:-""} -ginkgo.v

.PHONY: lint
lint: ## Go lint your code
hack/go-lint.sh -min_confidence 0.3 $(go list -f '{{ .ImportPath }}' ./...)
hack/go-lint.sh -min_confidence 0.3 $$(go list -f '{{ .ImportPath }}' ./... | grep -v 'sigs.k8s.io/cluster-api-provider-aws/test')

.PHONY: fmt
fmt: ## Go fmt your code
Expand Down
23 changes: 14 additions & 9 deletions cloud/aws/actuators/machine/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,19 +309,24 @@ func (a *Actuator) CreateMachine(cluster *clusterv1.Cluster, machine *clusterv1.

userDataEnc := base64.StdEncoding.EncodeToString(userData)

var iamInstanceProfile *ec2.IamInstanceProfileSpecification
if machineProviderConfig.IAMInstanceProfile != nil && machineProviderConfig.IAMInstanceProfile.ID != nil {
iamInstanceProfile = &ec2.IamInstanceProfileSpecification{
Name: aws.String(*machineProviderConfig.IAMInstanceProfile.ID),
}
}

inputConfig := ec2.RunInstancesInput{
ImageId: amiID,
InstanceType: aws.String(machineProviderConfig.InstanceType),
// Only a single instance of the AWS instance allowed
MinCount: aws.Int64(1),
MaxCount: aws.Int64(1),
KeyName: machineProviderConfig.KeyName,
IamInstanceProfile: &ec2.IamInstanceProfileSpecification{
Name: aws.String(*machineProviderConfig.IAMInstanceProfile.ID),
},
TagSpecifications: []*ec2.TagSpecification{tagInstance, tagVolume},
NetworkInterfaces: networkInterfaces,
UserData: &userDataEnc,
MinCount: aws.Int64(1),
MaxCount: aws.Int64(1),
KeyName: machineProviderConfig.KeyName,
IamInstanceProfile: iamInstanceProfile,
TagSpecifications: []*ec2.TagSpecification{tagInstance, tagVolume},
NetworkInterfaces: networkInterfaces,
UserData: &userDataEnc,
}

runResult, err := client.RunInstances(&inputConfig)
Expand Down
86 changes: 86 additions & 0 deletions test/framework/framework.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package framework

import (
"flag"
"strings"

"github.com/kubernetes-incubator/apiserver-builder/pkg/controller"
"k8s.io/client-go/kubernetes"
apiregistrationclientset "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"
"sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset"

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

var kubeconfig string

// ClusterID set by -cluster-id flag
var ClusterID string

func init() {
flag.StringVar(&kubeconfig, "kubeconfig", "", "kubeconfig file")
flag.StringVar(&ClusterID, "cluster-id", "", "cluster ID")
flag.Parse()
}

// Framework supports common operations used by tests
type Framework struct {
KubeClient *kubernetes.Clientset
CAPIClient *clientset.Clientset
APIRegistrationClient *apiregistrationclientset.Clientset
Kubeconfig string
}

// NewFramework setups a new framework
func NewFramework() *Framework {
f := &Framework{
Kubeconfig: kubeconfig,
}

BeforeEach(f.BeforeEach)

return f
}

// BeforeEach to be run before each spec responsible for building various clientsets
func (f *Framework) BeforeEach() {
By("Creating a kubernetes client")

if f.KubeClient == nil {
config, err := controller.GetConfig(f.Kubeconfig)
Expect(err).NotTo(HaveOccurred())
f.KubeClient, err = kubernetes.NewForConfig(config)
Expect(err).NotTo(HaveOccurred())
}

if f.CAPIClient == nil {
config, err := controller.GetConfig(f.Kubeconfig)
Expect(err).NotTo(HaveOccurred())
f.CAPIClient, err = clientset.NewForConfig(config)
Expect(err).NotTo(HaveOccurred())
}

if f.APIRegistrationClient == nil {
config, err := controller.GetConfig(f.Kubeconfig)
Expect(err).NotTo(HaveOccurred())
f.APIRegistrationClient, err = apiregistrationclientset.NewForConfig(config)
Expect(err).NotTo(HaveOccurred())
}

}

// IgnoreNotFoundErr ignores not found errors in case resource
// that does not exist is to be deleted
func IgnoreNotFoundErr(err error) {
if err != nil {
if !strings.Contains(err.Error(), "not found") {
Expect(err).NotTo(HaveOccurred())
}
}
}

// SigKubeDescribe is a wrapper function for ginkgo describe. Adds namespacing.
func SigKubeDescribe(text string, body func()) bool {
return Describe("[sigs.k8s.io] "+text, body)
}
104 changes: 0 additions & 104 deletions test/infra.tf

This file was deleted.

Loading

0 comments on commit a89ebc6

Please sign in to comment.