Skip to content

Commit

Permalink
test/e2e: Quick cleanup of presubmit failures, deadcode, copyrights (#…
Browse files Browse the repository at this point in the history
…265)

Signed-off-by: Stephen Augustus <[email protected]>
  • Loading branch information
justaugustus authored and k8s-ci-robot committed Aug 30, 2019
1 parent a994d89 commit 60b7c60
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 96 deletions.
11 changes: 5 additions & 6 deletions test/e2e/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,20 @@ go_test(
tags = ["external"],
deps = [
"//pkg/apis/azureprovider/v1alpha1:go_default_library",
"//pkg/cloud/azure/actuators:go_default_library",
"//pkg/cloud/azure/actuators/machine:go_default_library",
"//pkg/cloudtest:go_default_library",
"//test/e2e/util/kind:go_default_library",
"//vendor/github.com/onsi/ginkgo:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library",
"//vendor/github.com/onsi/gomega/gstruct:go_default_library",
"//vendor/github.com/onsi/gomega/types:go_default_library",
"//vendor/k8s.io/api/apps/v1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
"//vendor/sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1:go_default_library",
"//vendor/sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset:go_default_library",
"//vendor/sigs.k8s.io/cluster-api/pkg/util:go_default_library",
"//vendor/sigs.k8s.io/controller-runtime/pkg/client:go_default_library",
],
)

Expand Down
28 changes: 12 additions & 16 deletions test/e2e/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apimachinerytypes "k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
capz "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1alpha1"
capi "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
"sigs.k8s.io/cluster-api/pkg/util"
crclient "sigs.k8s.io/controller-runtime/pkg/client"

capz "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1alpha1"
//capa "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsprovider/v1alpha1"
)

const (
workerClusterK8sVersion = "v1.15.1"
workerClusterK8sVersion = "v1.15.3"
)

var _ = Describe("functional tests", func() {
Expand Down Expand Up @@ -80,17 +78,17 @@ var _ = Describe("functional tests", func() {

fmt.Fprintf(GinkgoWriter, "Ensuring first control plane Machine is ready\n")
Eventually(
func() (*capa.AWSMachineProviderStatus, error) {
func() (*capz.AzureMachineProviderStatus, error) {
machine := &capi.Machine{}
if err := kindClient.Get(context.TODO(), apimachinerytypes.NamespacedName{Namespace: namespace, Name: machineName}, machine); err != nil {
return nil, err
}
if machine.Status.ProviderStatus == nil {
return &capa.AWSMachineProviderStatus{
InstanceState: &capa.InstanceStatePending,
return &capz.AzureMachineProviderStatus{
VMState: &capz.VMStateCreating,
}, nil
}
return capa.MachineStatusFromProviderStatus(machine.Status.ProviderStatus)
return capz.MachineStatusFromProviderStatus(machine.Status.ProviderStatus)
},
10*time.Minute, 15*time.Second,
).Should(beHealthy())
Expand Down Expand Up @@ -118,7 +116,7 @@ var _ = Describe("functional tests", func() {
return cluster.Annotations, nil
},
10*time.Minute, 15*time.Second,
).Should(HaveKeyWithValue(capa.AnnotationControlPlaneReady, capa.ValueReady))
).Should(HaveKeyWithValue(capz.AnnotationControlPlaneReady, capz.ValueReady))

// TODO: Retrieve Cluster kubeconfig
// TODO: Deploy Addons
Expand Down Expand Up @@ -161,15 +159,14 @@ func noOptionsDelete() crclient.DeleteOptionFunc {
func beHealthy() types.GomegaMatcher {
return PointTo(
MatchFields(IgnoreExtras, Fields{
"InstanceState": PointTo(Equal(capz.InstanceStateRunning)),
"VMState": PointTo(Equal(capz.VMStateSucceeded)),
}),
)
}

func makeCluster(name string) *capi.Cluster {
providerSpecValue, err := capz.EncodeClusterSpec(&capz.AzureClusterProviderSpec{
SSHKeyName: keyPairName,
Region: region,
// TODO: Determine bare minimum cluster spec to define here
})
Expect(err).To(BeNil())

Expand Down Expand Up @@ -207,14 +204,13 @@ func makeMachine(name, clusterName, role, k8sVersion string) *capi.Machine {
instanceRole = "control-plane.cluster-api-provider-azure.sigs.k8s.io"
machineVersionInfo.ControlPlane = k8sVersion
case "node":
instanceRole = "nodes.cluster-api-provider-aws.sigs.k8s.io"
instanceRole = "nodes.cluster-api-provider-azure.sigs.k8s.io"
}
Expect(instanceRole).ToNot(BeEmpty())

providerSpecValue, err := capz.EncodeMachineSpec(&capz.AzureMachineProviderSpec{
// KeyName: keyPairName,
// IAMInstanceProfile: instanceRole,
VMSize: "m5.large", //LOOK UP ACTUAL AZURE VM SIZES
// TODO: Determine bare minimum machine spec to define here
VMSize: "Standard_B2ms",
})
Expect(err).To(BeNil())

Expand Down
93 changes: 20 additions & 73 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/*
Copyright 2018 The Kubernetes Authors.
Copyright 2019 The Kubernetes Authors.
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.
Expand All @@ -22,32 +25,18 @@ import (
"testing"
"time"

"github.com/kubernetes-sigs/cluster-api-provider-aws/pkg/cloud/aws/services/awserrors"
"github.com/kubernetes-sigs/cluster-api-provider-aws/pkg/cloud/aws/services/cloudformation"
"github.com/kubernetes-sigs/cluster-api-provider-aws/pkg/cloud/aws/services/sts"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

// "github.com/aws/aws-sdk-go/aws"
// "github.com/aws/aws-sdk-go/aws/client"
// "github.com/aws/aws-sdk-go/aws/credentials"
// "github.com/aws/aws-sdk-go/aws/session"
// cfn "github.com/aws/aws-sdk-go/service/cloudformation"
// "github.com/aws/aws-sdk-go/service/ec2"
// awssts "github.com/aws/aws-sdk-go/service/sts"
appsv1 "k8s.io/api/apps/v1"
apimachinerytypes "k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/cluster-api-provider-azure/test/e2e/util/kind"
"sigs.k8s.io/cluster-api/pkg/util"
crclient "sigs.k8s.io/controller-runtime/pkg/client"

// "sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/aws/services/awserrors"
// "sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/aws/services/cloudformation"
// "sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/aws/services/sts"
"sigs.k8s.io/cluster-api-provider-azure/test/e2e/util/kind"
)

func TestE2e(t *testing.T) {
if err := initRegion(); err != nil {
if err := initLocation(); err != nil {
t.Fatal(err)
}
RegisterFailHandler(Fail)
Expand All @@ -58,21 +47,18 @@ const (
setupTimeout = 10 * 60
capzProviderNamespace = "azure-provider-system"
capzStatefulSetName = "azure-provider-controller-manager"
stackName = "cluster-api-provider-azure-sigs-k8s-io"
keyPairName = "cluster-api-provider-azure-sigs-k8s-io"
)

var (
credFile = flag.String("credFile", "", "path to an Azure credentials file")
regionFile = flag.String("regionFile", "", "The path to a text file containing the Azure region")
// TODO: Do we want to do file-based auth? Not suggested. If we determine no, remove this deadcode
//credFile = flag.String("credFile", "", "path to an Azure credentials file")
locationFile = flag.String("locationFile", "", "The path to a text file containing the Azure location")
providerComponentsYAML = flag.String("providerComponentsYAML", "", "path to the provider components YAML for the cluster API")
managerImageTar = flag.String("managerImageTar", "", "a script to load the manager Docker image into Docker")

kindCluster kind.Cluster
kindClient crclient.Client
sess client.ConfigProvider
accountID string
region string
location string
)

var _ = BeforeSuite(func() {
Expand All @@ -91,10 +77,7 @@ var _ = BeforeSuite(func() {
Expect(err).To(BeNil())

fmt.Fprintf(GinkgoWriter, "Creating Azure prerequisites\n")
// sess = getSession()
// accountID = getAccountID(sess)
// createKeyPair(sess)
// createIAMRoles(sess, accountID)
// TODO: Probably need to init auth session to Azure here

fmt.Fprintf(GinkgoWriter, "Ensuring ProviderComponents are deployed\n")
Eventually(
Expand All @@ -107,66 +90,30 @@ var _ = BeforeSuite(func() {
}, 5*time.Minute, 15*time.Second,
).ShouldNot(BeZero())

fmt.Fprintf(GinkgoWriter, "Running in Azure region: %s\n", region)
fmt.Fprintf(GinkgoWriter, "Running in Azure location: %s\n", location)
}, setupTimeout)

var _ = AfterSuite(func() {
fmt.Fprintf(GinkgoWriter, "Tearing down kind cluster\n")
kindCluster.Teardown()
})

func initRegion() error {
if regionFile != nil && *regionFile != "" {
data, err := ioutil.ReadFile(*regionFile)
// TODO: Determine if we need this
func initLocation() error {
if locationFile != nil && *locationFile != "" {
data, err := ioutil.ReadFile(*locationFile)
if err != nil {
return fmt.Errorf("error reading AWS region file: %v", err)
return fmt.Errorf("error reading AWS location file: %v", err)
}
region = string(bytes.TrimSpace(data))
location = string(bytes.TrimSpace(data))
return nil
}

region = "eastus2"
location = "eastus"
return nil
}

func getSession() client.ConfigProvider {
if credFile != nil && *credFile != "" {
creds := credentials.NewCredentials(&credentials.SharedCredentialsProvider{
Filename: *credFile,
})
sess, err := session.NewSession(aws.NewConfig().WithCredentials(creds).WithRegion(region))
Expect(err).To(BeNil())
return sess
}

sess, err := session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
})
Expect(err).To(BeNil())
return sess
}

func getAccountID(prov client.ConfigProvider) string {
stsSvc := sts.NewService(awssts.New(prov))
accountID, err := stsSvc.AccountID()
Expect(err).To(BeNil())
return accountID
}

func createIAMRoles(prov client.ConfigProvider, accountID string) {
cfnSvc := cloudformation.NewService(cfn.New(prov))
Expect(
cfnSvc.ReconcileBootstrapStack(stackName, accountID),
).To(Succeed())
}

func createKeyPair(prov client.ConfigProvider) {
ec2c := ec2.New(prov)
_, err := ec2c.CreateKeyPair(&ec2.CreateKeyPairInput{KeyName: aws.String(keyPairName)})
if code, _ := awserrors.Code(err); code != "InvalidKeyPair.Duplicate" {
Expect(err).To(BeNil())
}
}
// TODO: Add function to handle auth to Azure

func loadManagerImage(kindCluster kind.Cluster) {
if managerImageTar != nil && *managerImageTar != "" {
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/util/kind/setup.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/*
Copyright 2018 The Kubernetes Authors.
Copyright 2019 The Kubernetes Authors.
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.
Expand Down

0 comments on commit 60b7c60

Please sign in to comment.