Skip to content

Commit

Permalink
Name v1alpha2 imports
Browse files Browse the repository at this point in the history
Signed-off-by: Joonas Bergius <jbergius@vmware.com>
  • Loading branch information
Joonas Bergius committed Aug 29, 2019
1 parent b01c4f7 commit 44fe118
Show file tree
Hide file tree
Showing 26 changed files with 369 additions and 370 deletions.
4 changes: 2 additions & 2 deletions cmd/clusterawsadm/cmd/alpha/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
awstags "github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi"
"github.com/spf13/cobra"
"sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
)

var (
Expand Down Expand Up @@ -133,7 +133,7 @@ func applyNewTags(svc *awstags.ResourceGroupsTaggingAPI, arns []*string, name st
input := &awstags.TagResourcesInput{
ResourceARNList: arns[i*maxARNs : end],
Tags: map[string]*string{
v1alpha2.ClusterTagKey(name): aws.String("owned"),
infrav1.ClusterTagKey(name): aws.String("owned"),
},
}

Expand Down
4 changes: 2 additions & 2 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
. "github.com/onsi/gomega"
"k8s.io/klog"
"k8s.io/klog/klogr"
"sigs.k8s.io/cluster-api/api/v1alpha2"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha2"

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -70,7 +70,7 @@ var _ = BeforeSuite(func(done Done) {
Expect(err).ToNot(HaveOccurred())
Expect(cfg).ToNot(BeNil())

Expect(v1alpha2.AddToScheme(scheme.Scheme)).To(Succeed())
Expect(clusterv1.AddToScheme(scheme.Scheme)).To(Succeed())
Expect(infrav1.AddToScheme(scheme.Scheme)).To(Succeed())

// +kubebuilder:scaffold:scheme
Expand Down
8 changes: 4 additions & 4 deletions pkg/cloud/converters/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
)

// SDKToInstance converts an EC2 instance type to the CAPA
// instance type.
// Note: This does not return a complete instance, as rootVolumeSize
// can not be determined via the output of EC2.DescribeInstances.
func SDKToInstance(v *ec2.Instance) *v1alpha2.Instance {
i := &v1alpha2.Instance{
func SDKToInstance(v *ec2.Instance) *infrav1.Instance {
i := &infrav1.Instance{
ID: aws.StringValue(v.InstanceId),
State: v1alpha2.InstanceState(*v.State.Name),
State: infrav1.InstanceState(*v.State.Name),
Type: aws.StringValue(v.InstanceType),
SubnetID: aws.StringValue(v.SubnetId),
ImageID: aws.StringValue(v.ImageId),
Expand Down
22 changes: 11 additions & 11 deletions pkg/cloud/converters/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/elb"
"sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
)

// TagsToMap converts a []*ec2.Tag into a v1alpha2.Tags.
func TagsToMap(src []*ec2.Tag) v1alpha2.Tags {
tags := make(v1alpha2.Tags, len(src))
// TagsToMap converts a []*ec2.Tag into a infrav1.Tags.
func TagsToMap(src []*ec2.Tag) infrav1.Tags {
tags := make(infrav1.Tags, len(src))

for _, t := range src {
tags[*t.Key] = *t.Value
Expand All @@ -34,8 +34,8 @@ func TagsToMap(src []*ec2.Tag) v1alpha2.Tags {
return tags
}

// MapToTags converts a v1alpha2.Tags to a []*ec2.Tag
func MapToTags(src v1alpha2.Tags) []*ec2.Tag {
// MapToTags converts a infrav1.Tags to a []*ec2.Tag
func MapToTags(src infrav1.Tags) []*ec2.Tag {
tags := make([]*ec2.Tag, 0, len(src))

for k, v := range src {
Expand All @@ -50,9 +50,9 @@ func MapToTags(src v1alpha2.Tags) []*ec2.Tag {
return tags
}

// ELBTagsToMap converts a []*elb.Tag into a v1alpha2.Tags.
func ELBTagsToMap(src []*elb.Tag) v1alpha2.Tags {
tags := make(v1alpha2.Tags, len(src))
// ELBTagsToMap converts a []*elb.Tag into a infrav1.Tags.
func ELBTagsToMap(src []*elb.Tag) infrav1.Tags {
tags := make(infrav1.Tags, len(src))

for _, t := range src {
tags[*t.Key] = *t.Value
Expand All @@ -61,8 +61,8 @@ func ELBTagsToMap(src []*elb.Tag) v1alpha2.Tags {
return tags
}

// MapToELBTags converts a v1alpha2.Tags to a []*elb.Tag
func MapToELBTags(src v1alpha2.Tags) []*elb.Tag {
// MapToELBTags converts a infrav1.Tags to a []*elb.Tag
func MapToELBTags(src infrav1.Tags) []*elb.Tag {
tags := make([]*elb.Tag, 0, len(src))

for k, v := range src {
Expand Down
14 changes: 7 additions & 7 deletions pkg/cloud/filter/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
)

const (
Expand All @@ -42,7 +42,7 @@ type ec2Filters struct{}
func (ec2Filters) Cluster(clusterName string) *ec2.Filter {
return &ec2.Filter{
Name: aws.String(filterNameTagKey),
Values: aws.StringSlice([]string{v1alpha2.ClusterTagKey(clusterName)}),
Values: aws.StringSlice([]string{infrav1.ClusterTagKey(clusterName)}),
}
}

Expand All @@ -58,24 +58,24 @@ func (ec2Filters) Name(name string) *ec2.Filter {
// the resource is owned
func (ec2Filters) ClusterOwned(clusterName string) *ec2.Filter {
return &ec2.Filter{
Name: aws.String(fmt.Sprintf("tag:%s", v1alpha2.ClusterTagKey(clusterName))),
Values: aws.StringSlice([]string{string(v1alpha2.ResourceLifecycleOwned)}),
Name: aws.String(fmt.Sprintf("tag:%s", infrav1.ClusterTagKey(clusterName))),
Values: aws.StringSlice([]string{string(infrav1.ResourceLifecycleOwned)}),
}
}

// ClusterShared returns a filter using the Cluster API per-cluster tag where
// the resource is shared.
func (ec2Filters) ClusterShared(clusterName string) *ec2.Filter {
return &ec2.Filter{
Name: aws.String(fmt.Sprintf("tag:%s", v1alpha2.ClusterTagKey(clusterName))),
Values: aws.StringSlice([]string{string(v1alpha2.ResourceLifecycleShared)}),
Name: aws.String(fmt.Sprintf("tag:%s", infrav1.ClusterTagKey(clusterName))),
Values: aws.StringSlice([]string{string(infrav1.ResourceLifecycleShared)}),
}
}

// ProviderRole returns a filter using cluster-api-provider-aws role tag.
func (ec2Filters) ProviderRole(role string) *ec2.Filter {
return &ec2.Filter{
Name: aws.String(fmt.Sprintf("tag:%s", v1alpha2.NameAWSClusterAPIRole)),
Name: aws.String(fmt.Sprintf("tag:%s", infrav1.NameAWSClusterAPIRole)),
Values: aws.StringSlice([]string{role}),
}
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"github.com/go-logr/logr"
"github.com/pkg/errors"
"k8s.io/klog/klogr"
"sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
clusterv1alpha2 "sigs.k8s.io/cluster-api/api/v1alpha2"
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha2"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -36,8 +36,8 @@ type ClusterScopeParams struct {
AWSClients
Client client.Client
Logger logr.Logger
Cluster *clusterv1alpha2.Cluster
AWSCluster *v1alpha2.AWSCluster
Cluster *clusterv1.Cluster
AWSCluster *infrav1.AWSCluster
}

// NewClusterScope creates a new Scope from the supplied parameters.
Expand Down Expand Up @@ -88,27 +88,27 @@ type ClusterScope struct {
patchHelper *patch.Helper

AWSClients
Cluster *clusterv1alpha2.Cluster
AWSCluster *v1alpha2.AWSCluster
Cluster *clusterv1.Cluster
AWSCluster *infrav1.AWSCluster
}

// Network returns the cluster network object.
func (s *ClusterScope) Network() *v1alpha2.Network {
func (s *ClusterScope) Network() *infrav1.Network {
return &s.AWSCluster.Status.Network
}

// VPC returns the cluster VPC.
func (s *ClusterScope) VPC() *v1alpha2.VPCSpec {
func (s *ClusterScope) VPC() *infrav1.VPCSpec {
return &s.AWSCluster.Spec.NetworkSpec.VPC
}

// Subnets returns the cluster subnets.
func (s *ClusterScope) Subnets() v1alpha2.Subnets {
func (s *ClusterScope) Subnets() infrav1.Subnets {
return s.AWSCluster.Spec.NetworkSpec.Subnets
}

// SecurityGroups returns the cluster security groups as a map, it creates the map if empty.
func (s *ClusterScope) SecurityGroups() map[v1alpha2.SecurityGroupRole]v1alpha2.SecurityGroup {
func (s *ClusterScope) SecurityGroups() map[infrav1.SecurityGroupRole]infrav1.SecurityGroup {
return s.AWSCluster.Status.Network.SecurityGroups
}

Expand Down Expand Up @@ -136,7 +136,7 @@ func (s *ClusterScope) ControlPlaneConfigMapName() string {
// ListOptionsLabelSelector returns a ListOptions with a label selector for clusterName.
func (s *ClusterScope) ListOptionsLabelSelector() client.ListOption {
return client.MatchingLabels(map[string]string{
clusterv1alpha2.MachineClusterLabelName: s.Cluster.Name,
clusterv1.MachineClusterLabelName: s.Cluster.Name,
})
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud/services/ec2/ami_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package ec2
import (
"testing"

"sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestAMIs(t *testing.T) {

scope, err := scope.NewClusterScope(scope.ClusterScopeParams{
Cluster: &clusterv1.Cluster{},
AWSCluster: &v1alpha2.AWSCluster{},
AWSCluster: &infrav1.AWSCluster{},
AWSClients: scope.AWSClients{
EC2: ec2Mock,
},
Expand Down
18 changes: 9 additions & 9 deletions pkg/cloud/services/ec2/bastion.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/pkg/errors"
"sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/awserrors"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/converters"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/filter"
Expand Down Expand Up @@ -102,10 +102,10 @@ func (s *Service) DeleteBastion() error {
return nil
}

func (s *Service) describeBastionInstance() (*v1alpha2.Instance, error) {
func (s *Service) describeBastionInstance() (*infrav1.Instance, error) {
input := &ec2.DescribeInstancesInput{
Filters: []*ec2.Filter{
filter.EC2.ProviderRole(v1alpha2.BastionRoleTagValue),
filter.EC2.ProviderRole(infrav1.BastionRoleTagValue),
filter.EC2.Cluster(s.scope.Name()),
filter.EC2.InstanceStates(ec2.InstanceStateNamePending, ec2.InstanceStateNameRunning),
},
Expand All @@ -129,7 +129,7 @@ func (s *Service) describeBastionInstance() (*v1alpha2.Instance, error) {
return nil, awserrors.NewNotFound(errors.New("bastion host not found"))
}

func (s *Service) getDefaultBastion() *v1alpha2.Instance {
func (s *Service) getDefaultBastion() *infrav1.Instance {
name := fmt.Sprintf("%s-bastion", s.scope.Name())
userData, _ := userdata.NewBastion(&userdata.BastionInput{})

Expand All @@ -138,20 +138,20 @@ func (s *Service) getDefaultBastion() *v1alpha2.Instance {
keyName = s.scope.AWSCluster.Spec.SSHKeyName
}

i := &v1alpha2.Instance{
i := &infrav1.Instance{
Type: "t2.micro",
SubnetID: s.scope.Subnets().FilterPublic()[0].ID,
ImageID: s.defaultBastionAMILookup(s.scope.AWSCluster.Spec.Region),
KeyName: aws.String(keyName),
UserData: aws.String(base64.StdEncoding.EncodeToString([]byte(userData))),
SecurityGroupIDs: []string{
s.scope.Network().SecurityGroups[v1alpha2.SecurityGroupBastion].ID,
s.scope.Network().SecurityGroups[infrav1.SecurityGroupBastion].ID,
},
Tags: v1alpha2.Build(v1alpha2.BuildParams{
Tags: infrav1.Build(infrav1.BuildParams{
ClusterName: s.scope.Name(),
Lifecycle: v1alpha2.ResourceLifecycleOwned,
Lifecycle: infrav1.ResourceLifecycleOwned,
Name: aws.String(name),
Role: aws.String(v1alpha2.BastionRoleTagValue),
Role: aws.String(infrav1.BastionRoleTagValue),
}),
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/cloud/services/ec2/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/pkg/errors"
"sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/awserrors"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/filter"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/services/wait"
Expand Down Expand Up @@ -57,10 +57,10 @@ func (s *Service) allocateAddress(role string) (string, error) {
if err := wait.WaitForWithRetryable(wait.NewBackoff(), func() (bool, error) {
if err := tags.Apply(&tags.ApplyParams{
EC2Client: s.scope.EC2,
BuildParams: v1alpha2.BuildParams{
BuildParams: infrav1.BuildParams{
ClusterName: s.scope.Name(),
ResourceID: *out.AllocationId,
Lifecycle: v1alpha2.ResourceLifecycleOwned,
Lifecycle: infrav1.ResourceLifecycleOwned,
Name: aws.String(fmt.Sprintf("%s-eip-%s", s.scope.Name(), role)),
Role: aws.String(role),
},
Expand Down
12 changes: 6 additions & 6 deletions pkg/cloud/services/ec2/gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/pkg/errors"
"sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha2"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/awserrors"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/converters"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/filter"
Expand Down Expand Up @@ -142,7 +142,7 @@ func (s *Service) createInternetGateway() (*ec2.InternetGateway, error) {

// Update the tags, so that when ig.InternetGateway is returned it has the
// latest tag data rather than returning empty tags.
ig.InternetGateway.Tags = converters.MapToTags(v1alpha2.Build(tagParams))
ig.InternetGateway.Tags = converters.MapToTags(infrav1.Build(tagParams))
if err := wait.WaitForWithRetryable(wait.NewBackoff(), func() (bool, error) {
if _, err := s.scope.EC2.AttachInternetGateway(&ec2.AttachInternetGatewayInput{
InternetGatewayId: ig.InternetGateway.InternetGatewayId,
Expand Down Expand Up @@ -179,14 +179,14 @@ func (s *Service) describeVpcInternetGateways() ([]*ec2.InternetGateway, error)
return out.InternetGateways, nil
}

func (s *Service) getGatewayTagParams(id string) v1alpha2.BuildParams {
func (s *Service) getGatewayTagParams(id string) infrav1.BuildParams {
name := fmt.Sprintf("%s-igw", s.scope.Name())

return v1alpha2.BuildParams{
return infrav1.BuildParams{
ClusterName: s.scope.Name(),
ResourceID: id,
Lifecycle: v1alpha2.ResourceLifecycleOwned,
Lifecycle: infrav1.ResourceLifecycleOwned,
Name: aws.String(name),
Role: aws.String(v1alpha2.CommonRoleTagValue),
Role: aws.String(infrav1.CommonRoleTagValue),
}
}
Loading

0 comments on commit 44fe118

Please sign in to comment.