mirror of https://github.com/k3s-io/k3s
commit
bf1bb5d309
|
@ -27,27 +27,35 @@ import (
|
|||
// AWSCloud implements InstanceGroups
|
||||
var _ InstanceGroups = &AWSCloud{}
|
||||
|
||||
// Implement InstanceGroups.ResizeInstanceGroup
|
||||
// Set the size to the fixed size
|
||||
func (a *AWSCloud) ResizeInstanceGroup(instanceGroupName string, size int) error {
|
||||
// ResizeInstanceGroup sets the size of the specificed instancegroup Exported
|
||||
// so it can be used by the e2e tests, which don't want to instantiate a full
|
||||
// cloudprovider.
|
||||
func ResizeInstanceGroup(asg ASG, instanceGroupName string, size int) error {
|
||||
request := &autoscaling.UpdateAutoScalingGroupInput{
|
||||
AutoScalingGroupName: aws.String(instanceGroupName),
|
||||
MinSize: 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 nil
|
||||
}
|
||||
|
||||
// Implement InstanceGroups.DescribeInstanceGroup
|
||||
// Queries the cloud provider for information about the specified instance group
|
||||
func (a *AWSCloud) DescribeInstanceGroup(instanceGroupName string) (InstanceGroupInfo, error) {
|
||||
// Implement InstanceGroups.ResizeInstanceGroup
|
||||
// Set the size to the fixed size
|
||||
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{
|
||||
AutoScalingGroupNames: []*string{aws.String(instanceGroupName)},
|
||||
}
|
||||
response, err := a.asg.DescribeAutoScalingGroups(request)
|
||||
response, err := asg.DescribeAutoScalingGroups(request)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
// 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
|
||||
var _ InstanceGroupInfo = &awsInstanceGroup{}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -36,7 +35,6 @@ import (
|
|||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
|
||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||
gcecloud "k8s.io/kubernetes/pkg/cloudprovider/providers/gce"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/util/runtime"
|
||||
|
@ -125,22 +123,9 @@ func setupProviderConfig() error {
|
|||
}
|
||||
|
||||
case "aws":
|
||||
awsConfig := "[Global]\n"
|
||||
if cloudConfig.Zone == "" {
|
||||
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"
|
||||
|
||||
"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/gomega"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
|
@ -320,14 +324,25 @@ func createPD() (string, error) {
|
|||
return "", err
|
||||
}
|
||||
return pdName, nil
|
||||
} else {
|
||||
volumes, ok := testContext.CloudConfig.Provider.(awscloud.Volumes)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("Provider does not support volumes")
|
||||
} else if testContext.Provider == "aws" {
|
||||
client := ec2.New(session.New())
|
||||
|
||||
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
|
||||
return volumes.CreateDisk(volumeOptions)
|
||||
|
||||
az := aws.StringValue(response.AvailabilityZone)
|
||||
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)
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
volumes, ok := testContext.CloudConfig.Provider.(awscloud.Volumes)
|
||||
if !ok {
|
||||
return fmt.Errorf("Provider does not support volumes")
|
||||
}
|
||||
deleted, err := volumes.DeleteDisk(pdName)
|
||||
} else if testContext.Provider == "aws" {
|
||||
client := ec2.New(session.New())
|
||||
|
||||
tokens := strings.Split(pdName, "/")
|
||||
awsVolumeID := tokens[len(tokens)-1]
|
||||
|
||||
request := &ec2.DeleteVolumeInput{VolumeId: aws.String(awsVolumeID)}
|
||||
_, err := client.DeleteVolume(request)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
if !deleted {
|
||||
if awsError, ok := err.(awserr.Error); ok && awsError.Code() == "InvalidVolume.NotFound" {
|
||||
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
|
||||
} else if testContext.Provider == "aws" {
|
||||
client := ec2.New(session.New())
|
||||
|
||||
} else {
|
||||
volumes, ok := testContext.CloudConfig.Provider.(awscloud.Volumes)
|
||||
if !ok {
|
||||
return fmt.Errorf("Provider does not support volumes")
|
||||
tokens := strings.Split(pdName, "/")
|
||||
awsVolumeID := tokens[len(tokens)-1]
|
||||
|
||||
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/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/gomega"
|
||||
"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))
|
||||
}
|
||||
return err
|
||||
} else if testContext.Provider == "aws" {
|
||||
client := autoscaling.New(session.New())
|
||||
return awscloud.ResizeInstanceGroup(client, testContext.CloudConfig.NodeInstanceGroup, size)
|
||||
} else {
|
||||
// Supported by aws
|
||||
instanceGroups, ok := testContext.CloudConfig.Provider.(awscloud.InstanceGroups)
|
||||
if !ok {
|
||||
return fmt.Errorf("Provider does not support InstanceGroups")
|
||||
}
|
||||
return instanceGroups.ResizeInstanceGroup(testContext.CloudConfig.NodeInstanceGroup, size)
|
||||
return fmt.Errorf("Provider does not support InstanceGroups")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,13 +87,9 @@ func groupSize() (int, error) {
|
|||
}
|
||||
re := regexp.MustCompile("RUNNING")
|
||||
return len(re.FindAllString(string(output), -1)), nil
|
||||
} else {
|
||||
// Supported by aws
|
||||
instanceGroups, ok := testContext.CloudConfig.Provider.(awscloud.InstanceGroups)
|
||||
if !ok {
|
||||
return -1, fmt.Errorf("provider does not support InstanceGroups")
|
||||
}
|
||||
instanceGroup, err := instanceGroups.DescribeInstanceGroup(testContext.CloudConfig.NodeInstanceGroup)
|
||||
} else if testContext.Provider == "aws" {
|
||||
client := autoscaling.New(session.New())
|
||||
instanceGroup, err := awscloud.DescribeInstanceGroup(client, testContext.CloudConfig.NodeInstanceGroup)
|
||||
if err != nil {
|
||||
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 instanceGroup.CurrentSize()
|
||||
} else {
|
||||
return -1, fmt.Errorf("provider does not support InstanceGroups")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue