mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-07 04:03:20 +00:00
AWS e2e: don't try to build a full cloudprovider in e2e
We have previously tried building a full cloudprovider in e2e for AWS; this wasn't the best idea, because e2e runs on a different machine than normal operations, and often doesn't even run in AWS. In turn, this meant that the cloudprovider had to do extra work and have extra code, which we would like to get rid of. Indeed, I got rid of some code which tolerated not running in AWS, and this broke e2e.
This commit is contained in:
@@ -27,27 +27,35 @@ import (
|
|||||||
// AWSCloud implements InstanceGroups
|
// AWSCloud implements InstanceGroups
|
||||||
var _ InstanceGroups = &AWSCloud{}
|
var _ InstanceGroups = &AWSCloud{}
|
||||||
|
|
||||||
// Implement InstanceGroups.ResizeInstanceGroup
|
// ResizeInstanceGroup sets the size of the specificed instancegroup Exported
|
||||||
// Set the size to the fixed size
|
// so it can be used by the e2e tests, which don't want to instantiate a full
|
||||||
func (a *AWSCloud) ResizeInstanceGroup(instanceGroupName string, size int) error {
|
// cloudprovider.
|
||||||
|
func ResizeInstanceGroup(asg ASG, instanceGroupName string, size int) error {
|
||||||
request := &autoscaling.UpdateAutoScalingGroupInput{
|
request := &autoscaling.UpdateAutoScalingGroupInput{
|
||||||
AutoScalingGroupName: aws.String(instanceGroupName),
|
AutoScalingGroupName: aws.String(instanceGroupName),
|
||||||
MinSize: aws.Int64(int64(size)),
|
MinSize: aws.Int64(int64(size)),
|
||||||
MaxSize: aws.Int64(int64(size)),
|
MaxSize: aws.Int64(int64(size)),
|
||||||
}
|
}
|
||||||
if _, err := a.asg.UpdateAutoScalingGroup(request); err != nil {
|
if _, err := asg.UpdateAutoScalingGroup(request); err != nil {
|
||||||
return fmt.Errorf("error resizing AWS autoscaling group: %v", err)
|
return fmt.Errorf("error resizing AWS autoscaling group: %v", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement InstanceGroups.DescribeInstanceGroup
|
// Implement InstanceGroups.ResizeInstanceGroup
|
||||||
// Queries the cloud provider for information about the specified instance group
|
// Set the size to the fixed size
|
||||||
func (a *AWSCloud) DescribeInstanceGroup(instanceGroupName string) (InstanceGroupInfo, error) {
|
func (a *AWSCloud) ResizeInstanceGroup(instanceGroupName string, size int) error {
|
||||||
|
return ResizeInstanceGroup(a.asg, instanceGroupName, size)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescribeInstanceGroup gets info about the specified instancegroup
|
||||||
|
// Exported so it can be used by the e2e tests,
|
||||||
|
// which don't want to instantiate a full cloudprovider.
|
||||||
|
func DescribeInstanceGroup(asg ASG, instanceGroupName string) (InstanceGroupInfo, error) {
|
||||||
request := &autoscaling.DescribeAutoScalingGroupsInput{
|
request := &autoscaling.DescribeAutoScalingGroupsInput{
|
||||||
AutoScalingGroupNames: []*string{aws.String(instanceGroupName)},
|
AutoScalingGroupNames: []*string{aws.String(instanceGroupName)},
|
||||||
}
|
}
|
||||||
response, err := a.asg.DescribeAutoScalingGroups(request)
|
response, err := asg.DescribeAutoScalingGroups(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error listing AWS autoscaling group (%s): %v", instanceGroupName, err)
|
return nil, fmt.Errorf("error listing AWS autoscaling group (%s): %v", instanceGroupName, err)
|
||||||
}
|
}
|
||||||
@@ -62,6 +70,12 @@ func (a *AWSCloud) DescribeInstanceGroup(instanceGroupName string) (InstanceGrou
|
|||||||
return &awsInstanceGroup{group: group}, nil
|
return &awsInstanceGroup{group: group}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implement InstanceGroups.DescribeInstanceGroup
|
||||||
|
// Queries the cloud provider for information about the specified instance group
|
||||||
|
func (a *AWSCloud) DescribeInstanceGroup(instanceGroupName string) (InstanceGroupInfo, error) {
|
||||||
|
return DescribeInstanceGroup(a.asg, instanceGroupName)
|
||||||
|
}
|
||||||
|
|
||||||
// awsInstanceGroup implements InstanceGroupInfo
|
// awsInstanceGroup implements InstanceGroupInfo
|
||||||
var _ InstanceGroupInfo = &awsInstanceGroup{}
|
var _ InstanceGroupInfo = &awsInstanceGroup{}
|
||||||
|
|
||||||
|
@@ -21,7 +21,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -36,7 +35,6 @@ import (
|
|||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
|
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
|
||||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
|
||||||
gcecloud "k8s.io/kubernetes/pkg/cloudprovider/providers/gce"
|
gcecloud "k8s.io/kubernetes/pkg/cloudprovider/providers/gce"
|
||||||
"k8s.io/kubernetes/pkg/util"
|
"k8s.io/kubernetes/pkg/util"
|
||||||
"k8s.io/kubernetes/pkg/util/runtime"
|
"k8s.io/kubernetes/pkg/util/runtime"
|
||||||
@@ -125,22 +123,9 @@ func setupProviderConfig() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "aws":
|
case "aws":
|
||||||
awsConfig := "[Global]\n"
|
|
||||||
if cloudConfig.Zone == "" {
|
if cloudConfig.Zone == "" {
|
||||||
return fmt.Errorf("gce-zone must be specified for AWS")
|
return fmt.Errorf("gce-zone must be specified for AWS")
|
||||||
}
|
}
|
||||||
awsConfig += fmt.Sprintf("Zone=%s\n", cloudConfig.Zone)
|
|
||||||
|
|
||||||
if cloudConfig.ClusterTag == "" {
|
|
||||||
return fmt.Errorf("--cluster-tag must be specified for AWS")
|
|
||||||
}
|
|
||||||
awsConfig += fmt.Sprintf("KubernetesClusterTag=%s\n", cloudConfig.ClusterTag)
|
|
||||||
|
|
||||||
var err error
|
|
||||||
cloudConfig.Provider, err = cloudprovider.GetCloudProvider(testContext.Provider, strings.NewReader(awsConfig))
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Error building AWS provider: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,6 +24,10 @@ import (
|
|||||||
|
|
||||||
"google.golang.org/api/googleapi"
|
"google.golang.org/api/googleapi"
|
||||||
|
|
||||||
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
|
"github.com/aws/aws-sdk-go/service/ec2"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
@@ -320,14 +324,25 @@ func createPD() (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return pdName, nil
|
return pdName, nil
|
||||||
} else {
|
} else if testContext.Provider == "aws" {
|
||||||
volumes, ok := testContext.CloudConfig.Provider.(awscloud.Volumes)
|
client := ec2.New(session.New())
|
||||||
if !ok {
|
|
||||||
return "", fmt.Errorf("Provider does not support volumes")
|
request := &ec2.CreateVolumeInput{}
|
||||||
|
request.AvailabilityZone = aws.String(cloudConfig.Zone)
|
||||||
|
request.Size = aws.Int64(10)
|
||||||
|
request.VolumeType = aws.String(awscloud.DefaultVolumeType)
|
||||||
|
response, err := client.CreateVolume(request)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
}
|
}
|
||||||
volumeOptions := &awscloud.VolumeOptions{}
|
|
||||||
volumeOptions.CapacityGB = 10
|
az := aws.StringValue(response.AvailabilityZone)
|
||||||
return volumes.CreateDisk(volumeOptions)
|
awsID := aws.StringValue(response.VolumeId)
|
||||||
|
|
||||||
|
volumeName := "aws://" + az + "/" + awsID
|
||||||
|
return volumeName, nil
|
||||||
|
} else {
|
||||||
|
return "", fmt.Errorf("Provider does not support volume creation")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,20 +364,24 @@ func deletePD(pdName string) error {
|
|||||||
Logf("Error deleting PD %q: %v", pdName, err)
|
Logf("Error deleting PD %q: %v", pdName, err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
} else {
|
} else if testContext.Provider == "aws" {
|
||||||
volumes, ok := testContext.CloudConfig.Provider.(awscloud.Volumes)
|
client := ec2.New(session.New())
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("Provider does not support volumes")
|
tokens := strings.Split(pdName, "/")
|
||||||
}
|
awsVolumeID := tokens[len(tokens)-1]
|
||||||
deleted, err := volumes.DeleteDisk(pdName)
|
|
||||||
|
request := &ec2.DeleteVolumeInput{VolumeId: aws.String(awsVolumeID)}
|
||||||
|
_, err := client.DeleteVolume(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
if awsError, ok := err.(awserr.Error); ok && awsError.Code() == "InvalidVolume.NotFound" {
|
||||||
} else {
|
|
||||||
if !deleted {
|
|
||||||
Logf("Volume deletion implicitly succeeded because volume %q does not exist.", pdName)
|
Logf("Volume deletion implicitly succeeded because volume %q does not exist.", pdName)
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("error deleting EBS volumes: %v", err)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("Provider does not support volume deletion")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,14 +405,23 @@ func detachPD(hostName, pdName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
} else if testContext.Provider == "aws" {
|
||||||
|
client := ec2.New(session.New())
|
||||||
|
|
||||||
} else {
|
tokens := strings.Split(pdName, "/")
|
||||||
volumes, ok := testContext.CloudConfig.Provider.(awscloud.Volumes)
|
awsVolumeID := tokens[len(tokens)-1]
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("Provider does not support volumes")
|
request := ec2.DetachVolumeInput{
|
||||||
|
VolumeId: aws.String(awsVolumeID),
|
||||||
}
|
}
|
||||||
_, err := volumes.DetachDisk(pdName, hostName)
|
|
||||||
return err
|
_, err := client.DetachVolume(&request)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error detaching EBS volume: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("Provider does not support volume detaching")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,6 +30,8 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/labels"
|
"k8s.io/kubernetes/pkg/labels"
|
||||||
"k8s.io/kubernetes/pkg/util/intstr"
|
"k8s.io/kubernetes/pkg/util/intstr"
|
||||||
|
|
||||||
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
|
"github.com/aws/aws-sdk-go/service/autoscaling"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
"k8s.io/kubernetes/pkg/client/cache"
|
"k8s.io/kubernetes/pkg/client/cache"
|
||||||
@@ -65,13 +67,11 @@ func resizeGroup(size int) error {
|
|||||||
Logf("Failed to resize node instance group: %v", string(output))
|
Logf("Failed to resize node instance group: %v", string(output))
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
} else if testContext.Provider == "aws" {
|
||||||
|
client := autoscaling.New(session.New())
|
||||||
|
return awscloud.ResizeInstanceGroup(client, testContext.CloudConfig.NodeInstanceGroup, size)
|
||||||
} else {
|
} else {
|
||||||
// Supported by aws
|
return fmt.Errorf("Provider does not support InstanceGroups")
|
||||||
instanceGroups, ok := testContext.CloudConfig.Provider.(awscloud.InstanceGroups)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("Provider does not support InstanceGroups")
|
|
||||||
}
|
|
||||||
return instanceGroups.ResizeInstanceGroup(testContext.CloudConfig.NodeInstanceGroup, size)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,13 +87,9 @@ func groupSize() (int, error) {
|
|||||||
}
|
}
|
||||||
re := regexp.MustCompile("RUNNING")
|
re := regexp.MustCompile("RUNNING")
|
||||||
return len(re.FindAllString(string(output), -1)), nil
|
return len(re.FindAllString(string(output), -1)), nil
|
||||||
} else {
|
} else if testContext.Provider == "aws" {
|
||||||
// Supported by aws
|
client := autoscaling.New(session.New())
|
||||||
instanceGroups, ok := testContext.CloudConfig.Provider.(awscloud.InstanceGroups)
|
instanceGroup, err := awscloud.DescribeInstanceGroup(client, testContext.CloudConfig.NodeInstanceGroup)
|
||||||
if !ok {
|
|
||||||
return -1, fmt.Errorf("provider does not support InstanceGroups")
|
|
||||||
}
|
|
||||||
instanceGroup, err := instanceGroups.DescribeInstanceGroup(testContext.CloudConfig.NodeInstanceGroup)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, fmt.Errorf("error describing instance group: %v", err)
|
return -1, fmt.Errorf("error describing instance group: %v", err)
|
||||||
}
|
}
|
||||||
@@ -101,6 +97,8 @@ func groupSize() (int, error) {
|
|||||||
return -1, fmt.Errorf("instance group not found: %s", testContext.CloudConfig.NodeInstanceGroup)
|
return -1, fmt.Errorf("instance group not found: %s", testContext.CloudConfig.NodeInstanceGroup)
|
||||||
}
|
}
|
||||||
return instanceGroup.CurrentSize()
|
return instanceGroup.CurrentSize()
|
||||||
|
} else {
|
||||||
|
return -1, fmt.Errorf("provider does not support InstanceGroups")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user