|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package resources
|
|
|
|
|
package aws
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
|
|
|
@ -32,6 +32,7 @@ import (
|
|
|
|
|
"github.com/golang/glog"
|
|
|
|
|
"k8s.io/apimachinery/pkg/util/sets"
|
|
|
|
|
"k8s.io/kops/pkg/dns"
|
|
|
|
|
"k8s.io/kops/pkg/resources"
|
|
|
|
|
"k8s.io/kops/upup/pkg/fi"
|
|
|
|
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
|
|
|
|
)
|
|
|
|
@ -43,10 +44,10 @@ const (
|
|
|
|
|
TypeLoadBalancer = "load-balancer"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type listFn func(fi.Cloud, string) ([]*Resource, error)
|
|
|
|
|
type listFn func(fi.Cloud, string) ([]*resources.Resource, error)
|
|
|
|
|
|
|
|
|
|
func ListResourcesAWS(cloud awsup.AWSCloud, clusterName string) (map[string]*Resource, error) {
|
|
|
|
|
resources := make(map[string]*Resource)
|
|
|
|
|
func ListResourcesAWS(cloud awsup.AWSCloud, clusterName string) (map[string]*resources.Resource, error) {
|
|
|
|
|
resourceTrackers := make(map[string]*resources.Resource)
|
|
|
|
|
|
|
|
|
|
// These are the functions that are used for looking up
|
|
|
|
|
// cluster resources by their tags.
|
|
|
|
@ -78,12 +79,12 @@ func ListResourcesAWS(cloud awsup.AWSCloud, clusterName string) (map[string]*Res
|
|
|
|
|
ListIAMRoles,
|
|
|
|
|
}
|
|
|
|
|
for _, fn := range listFunctions {
|
|
|
|
|
resourceTrackers, err := fn(cloud, clusterName)
|
|
|
|
|
rt, err := fn(cloud, clusterName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
for _, t := range resourceTrackers {
|
|
|
|
|
resources[t.Type+":"+t.ID] = t
|
|
|
|
|
for _, t := range rt {
|
|
|
|
|
resourceTrackers[t.Type+":"+t.ID] = t
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -104,9 +105,9 @@ func ListResourcesAWS(cloud awsup.AWSCloud, clusterName string) (map[string]*Res
|
|
|
|
|
if vpcID == "" || igwID == "" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
vpc := resources["vpc:"+vpcID]
|
|
|
|
|
if vpc != nil && resources["internet-gateway:"+igwID] == nil {
|
|
|
|
|
resources["internet-gateway:"+igwID] = &Resource{
|
|
|
|
|
vpc := resourceTrackers["vpc:"+vpcID]
|
|
|
|
|
if vpc != nil && resourceTrackers["internet-gateway:"+igwID] == nil {
|
|
|
|
|
resourceTrackers["internet-gateway:"+igwID] = &resources.Resource{
|
|
|
|
|
Name: FindName(igw.Tags),
|
|
|
|
|
ID: igwID,
|
|
|
|
|
Type: "internet-gateway",
|
|
|
|
@ -121,7 +122,7 @@ func ListResourcesAWS(cloud awsup.AWSCloud, clusterName string) (map[string]*Res
|
|
|
|
|
{
|
|
|
|
|
// We delete a launch configuration if it is bound to one of the tagged security groups
|
|
|
|
|
securityGroups := sets.NewString()
|
|
|
|
|
for k := range resources {
|
|
|
|
|
for k := range resourceTrackers {
|
|
|
|
|
if !strings.HasPrefix(k, "security-group:") {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
@ -134,18 +135,18 @@ func ListResourcesAWS(cloud awsup.AWSCloud, clusterName string) (map[string]*Res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, t := range lcs {
|
|
|
|
|
resources[t.Type+":"+t.ID] = t
|
|
|
|
|
resourceTrackers[t.Type+":"+t.ID] = t
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := addUntaggedRouteTables(cloud, clusterName, resources); err != nil {
|
|
|
|
|
if err := addUntaggedRouteTables(cloud, clusterName, resourceTrackers); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// We delete a NAT gateway if it is linked to our route table
|
|
|
|
|
routeTableIds := make(map[string]*Resource)
|
|
|
|
|
for _, resource := range resources {
|
|
|
|
|
routeTableIds := make(map[string]*resources.Resource)
|
|
|
|
|
for _, resource := range resourceTrackers {
|
|
|
|
|
if resource.Type != ec2.ResourceTypeRouteTable {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
@ -158,16 +159,16 @@ func ListResourcesAWS(cloud awsup.AWSCloud, clusterName string) (map[string]*Res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, t := range natGateways {
|
|
|
|
|
resources[t.Type+":"+t.ID] = t
|
|
|
|
|
resourceTrackers[t.Type+":"+t.ID] = t
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for k, t := range resources {
|
|
|
|
|
for k, t := range resourceTrackers {
|
|
|
|
|
if t.Done {
|
|
|
|
|
delete(resources, k)
|
|
|
|
|
delete(resourceTrackers, k)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return resources, nil
|
|
|
|
|
return resourceTrackers, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BuildEC2Filters(cloud fi.Cloud) []*ec2.Filter {
|
|
|
|
@ -182,7 +183,7 @@ func BuildEC2Filters(cloud fi.Cloud) []*ec2.Filter {
|
|
|
|
|
return filters
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func addUntaggedRouteTables(cloud awsup.AWSCloud, clusterName string, resources map[string]*Resource) error {
|
|
|
|
|
func addUntaggedRouteTables(cloud awsup.AWSCloud, clusterName string, resources map[string]*resources.Resource) error {
|
|
|
|
|
// We sometimes have trouble tagging the route table (eventual consistency, e.g. #597)
|
|
|
|
|
// If we are deleting the VPC, we should delete the route table
|
|
|
|
|
// (no real reason not to; easy to recreate; no real state etc)
|
|
|
|
@ -279,7 +280,7 @@ func matchesElbTags(tags map[string]string, actual []*elb.Tag) bool {
|
|
|
|
|
// Delete(cloud fi.Cloud) error
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
func DeleteInstance(cloud fi.Cloud, t *Resource) error {
|
|
|
|
|
func DeleteInstance(cloud fi.Cloud, t *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
id := t.ID
|
|
|
|
@ -298,7 +299,7 @@ func DeleteInstance(cloud fi.Cloud, t *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteCloudFormationStack(cloud fi.Cloud, t *Resource) error {
|
|
|
|
|
func DeleteCloudFormationStack(cloud fi.Cloud, t *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
id := t.ID
|
|
|
|
@ -314,7 +315,7 @@ func DeleteCloudFormationStack(cloud fi.Cloud, t *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DumpCloudFormationStack(op *DumpOperation, r *Resource) error {
|
|
|
|
|
func DumpCloudFormationStack(op *resources.DumpOperation, r *resources.Resource) error {
|
|
|
|
|
data := make(map[string]interface{})
|
|
|
|
|
data["id"] = r.ID
|
|
|
|
|
data["type"] = r.Type
|
|
|
|
@ -323,8 +324,8 @@ func DumpCloudFormationStack(op *DumpOperation, r *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ListCloudFormationStacks(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
func ListCloudFormationStacks(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
request := &cloudformation.ListStacksInput{}
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
response, err := c.CloudFormation().ListStacks(request)
|
|
|
|
@ -333,7 +334,7 @@ func ListCloudFormationStacks(cloud fi.Cloud, clusterName string) ([]*Resource,
|
|
|
|
|
}
|
|
|
|
|
for _, stack := range response.StackSummaries {
|
|
|
|
|
if *stack.StackName == clusterName {
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: *stack.StackName,
|
|
|
|
|
ID: *stack.StackId,
|
|
|
|
|
Type: "cloud-formation",
|
|
|
|
@ -348,7 +349,7 @@ func ListCloudFormationStacks(cloud fi.Cloud, clusterName string) ([]*Resource,
|
|
|
|
|
return resourceTrackers, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ListInstances(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
func ListInstances(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
glog.V(2).Infof("Querying EC2 instances")
|
|
|
|
@ -356,7 +357,7 @@ func ListInstances(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
Filters: BuildEC2Filters(cloud),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
|
|
|
|
|
err := c.EC2().DescribeInstancesPages(request, func(p *ec2.DescribeInstancesOutput, lastPage bool) bool {
|
|
|
|
|
for _, reservation := range p.Reservations {
|
|
|
|
@ -378,7 +379,7 @@ func ListInstances(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: FindName(instance.Tags),
|
|
|
|
|
ID: id,
|
|
|
|
|
Type: ec2.ResourceTypeInstance,
|
|
|
|
@ -417,7 +418,7 @@ func ListInstances(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
return resourceTrackers, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DumpInstance(op *DumpOperation, r *Resource) error {
|
|
|
|
|
func DumpInstance(op *resources.DumpOperation, r *resources.Resource) error {
|
|
|
|
|
data := make(map[string]interface{})
|
|
|
|
|
data["id"] = r.ID
|
|
|
|
|
data["type"] = ec2.ResourceTypeInstance
|
|
|
|
@ -425,7 +426,7 @@ func DumpInstance(op *DumpOperation, r *Resource) error {
|
|
|
|
|
op.Dump.Resources = append(op.Dump.Resources, data)
|
|
|
|
|
|
|
|
|
|
ec2Instance := r.Obj.(*ec2.Instance)
|
|
|
|
|
i := &Instance{
|
|
|
|
|
i := &resources.Instance{
|
|
|
|
|
Name: r.ID,
|
|
|
|
|
}
|
|
|
|
|
for _, networkInterface := range ec2Instance.NetworkInterfaces {
|
|
|
|
@ -449,7 +450,7 @@ func DumpInstance(op *DumpOperation, r *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteSecurityGroup(cloud fi.Cloud, t *Resource) error {
|
|
|
|
|
func DeleteSecurityGroup(cloud fi.Cloud, t *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
id := t.ID
|
|
|
|
@ -504,7 +505,7 @@ func DeleteSecurityGroup(cloud fi.Cloud, t *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DumpSecurityGroup(op *DumpOperation, r *Resource) error {
|
|
|
|
|
func DumpSecurityGroup(op *resources.DumpOperation, r *resources.Resource) error {
|
|
|
|
|
data := make(map[string]interface{})
|
|
|
|
|
data["id"] = r.ID
|
|
|
|
|
data["type"] = ec2.ResourceTypeSecurityGroup
|
|
|
|
@ -513,16 +514,16 @@ func DumpSecurityGroup(op *DumpOperation, r *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ListSecurityGroups(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
func ListSecurityGroups(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
groups, err := DescribeSecurityGroups(cloud)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
|
|
|
|
|
for _, sg := range groups {
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: FindName(sg.Tags),
|
|
|
|
|
ID: aws.StringValue(sg.GroupId),
|
|
|
|
|
Type: "security-group",
|
|
|
|
@ -557,7 +558,7 @@ func DescribeSecurityGroups(cloud fi.Cloud) ([]*ec2.SecurityGroup, error) {
|
|
|
|
|
return response.SecurityGroups, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteVolume(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
func DeleteVolume(cloud fi.Cloud, r *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
id := r.ID
|
|
|
|
@ -580,20 +581,20 @@ func DeleteVolume(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ListVolumes(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
func ListVolumes(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
volumes, err := DescribeVolumes(cloud)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
|
|
|
|
|
elasticIPs := make(map[string]bool)
|
|
|
|
|
for _, volume := range volumes {
|
|
|
|
|
id := aws.StringValue(volume.VolumeId)
|
|
|
|
|
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: FindName(volume.Tags),
|
|
|
|
|
ID: id,
|
|
|
|
|
Type: "volume",
|
|
|
|
@ -635,7 +636,7 @@ func ListVolumes(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: ip,
|
|
|
|
|
ID: aws.StringValue(address.AllocationId),
|
|
|
|
|
Type: TypeElasticIp,
|
|
|
|
@ -673,7 +674,7 @@ func DescribeVolumes(cloud fi.Cloud) ([]*ec2.Volume, error) {
|
|
|
|
|
return volumes, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteKeypair(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
func DeleteKeypair(cloud fi.Cloud, r *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
name := r.Name
|
|
|
|
@ -689,7 +690,7 @@ func DeleteKeypair(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ListKeypairs(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
func ListKeypairs(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
if !strings.Contains(clusterName, ".") {
|
|
|
|
|
glog.Infof("cluster %q is legacy (kube-up) cluster; won't delete keypairs", clusterName)
|
|
|
|
|
return nil, nil
|
|
|
|
@ -709,14 +710,14 @@ func ListKeypairs(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
return nil, fmt.Errorf("error listing KeyPairs: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
|
|
|
|
|
for _, keypair := range response.KeyPairs {
|
|
|
|
|
name := aws.StringValue(keypair.KeyName)
|
|
|
|
|
if name != keypairName && !strings.HasPrefix(name, keypairName+"-") {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: name,
|
|
|
|
|
ID: name,
|
|
|
|
|
Type: "keypair",
|
|
|
|
@ -742,7 +743,7 @@ func IsDependencyViolation(err error) bool {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteSubnet(cloud fi.Cloud, tracker *Resource) error {
|
|
|
|
|
func DeleteSubnet(cloud fi.Cloud, tracker *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
id := tracker.ID
|
|
|
|
@ -764,14 +765,14 @@ func DeleteSubnet(cloud fi.Cloud, tracker *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ListSubnets(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
func ListSubnets(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
subnets, err := DescribeSubnets(cloud)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("error listing subnets: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
elasticIPs := sets.NewString()
|
|
|
|
|
ownedElasticIPs := sets.NewString()
|
|
|
|
|
natGatewayIds := sets.NewString()
|
|
|
|
@ -780,7 +781,7 @@ func ListSubnets(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
subnetID := aws.StringValue(subnet.SubnetId)
|
|
|
|
|
|
|
|
|
|
shared := HasSharedTag("subnet:"+subnetID, subnet.Tags, clusterName)
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: FindName(subnet.Tags),
|
|
|
|
|
ID: subnetID,
|
|
|
|
|
Type: "subnet",
|
|
|
|
@ -831,7 +832,7 @@ func ListSubnets(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: ip,
|
|
|
|
|
ID: aws.StringValue(address.AllocationId),
|
|
|
|
|
Type: TypeElasticIp,
|
|
|
|
@ -881,7 +882,7 @@ func ListSubnets(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: id,
|
|
|
|
|
ID: id,
|
|
|
|
|
Type: TypeNatGateway,
|
|
|
|
@ -918,7 +919,7 @@ func DescribeSubnets(cloud fi.Cloud) ([]*ec2.Subnet, error) {
|
|
|
|
|
return response.Subnets, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteRouteTable(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
func DeleteRouteTable(cloud fi.Cloud, r *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
id := r.ID
|
|
|
|
@ -972,13 +973,13 @@ func DescribeRouteTables(cloud fi.Cloud) ([]*ec2.RouteTable, error) {
|
|
|
|
|
return response.RouteTables, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ListRouteTables(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
func ListRouteTables(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
routeTables, err := DescribeRouteTables(cloud)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
|
|
|
|
|
for _, rt := range routeTables {
|
|
|
|
|
resourceTracker := buildTrackerForRouteTable(rt, clusterName)
|
|
|
|
@ -988,8 +989,8 @@ func ListRouteTables(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
return resourceTrackers, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func buildTrackerForRouteTable(rt *ec2.RouteTable, clusterName string) *Resource {
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
func buildTrackerForRouteTable(rt *ec2.RouteTable, clusterName string) *resources.Resource {
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: FindName(rt.Tags),
|
|
|
|
|
ID: aws.StringValue(rt.RouteTableId),
|
|
|
|
|
Type: ec2.ResourceTypeRouteTable,
|
|
|
|
@ -1012,7 +1013,7 @@ func buildTrackerForRouteTable(rt *ec2.RouteTable, clusterName string) *Resource
|
|
|
|
|
return resourceTracker
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteDhcpOptions(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
func DeleteDhcpOptions(cloud fi.Cloud, r *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
id := r.ID
|
|
|
|
@ -1031,16 +1032,16 @@ func DeleteDhcpOptions(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ListDhcpOptions(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
func ListDhcpOptions(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
dhcpOptions, err := DescribeDhcpOptions(cloud)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
|
|
|
|
|
for _, o := range dhcpOptions {
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: FindName(o.Tags),
|
|
|
|
|
ID: aws.StringValue(o.DhcpOptionsId),
|
|
|
|
|
Type: "dhcp-options",
|
|
|
|
@ -1073,7 +1074,7 @@ func DescribeDhcpOptions(cloud fi.Cloud) ([]*ec2.DhcpOptions, error) {
|
|
|
|
|
return response.DhcpOptions, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteInternetGateway(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
func DeleteInternetGateway(cloud fi.Cloud, r *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
id := r.ID
|
|
|
|
@ -1137,16 +1138,16 @@ func DeleteInternetGateway(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ListInternetGateways(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
func ListInternetGateways(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
gateways, err := DescribeInternetGateways(cloud)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
|
|
|
|
|
for _, o := range gateways {
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: FindName(o.Tags),
|
|
|
|
|
ID: aws.StringValue(o.InternetGatewayId),
|
|
|
|
|
Type: "internet-gateway",
|
|
|
|
@ -1210,7 +1211,7 @@ func DescribeInternetGatewaysIgnoreTags(cloud fi.Cloud) ([]*ec2.InternetGateway,
|
|
|
|
|
return gateways, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteVPC(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
func DeleteVPC(cloud fi.Cloud, r *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
id := r.ID
|
|
|
|
@ -1229,7 +1230,7 @@ func DeleteVPC(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DumpVPC(op *DumpOperation, r *Resource) error {
|
|
|
|
|
func DumpVPC(op *resources.DumpOperation, r *resources.Resource) error {
|
|
|
|
|
data := make(map[string]interface{})
|
|
|
|
|
data["id"] = r.ID
|
|
|
|
|
data["type"] = ec2.ResourceTypeVpc
|
|
|
|
@ -1253,17 +1254,17 @@ func DescribeVPCs(cloud fi.Cloud) ([]*ec2.Vpc, error) {
|
|
|
|
|
return response.Vpcs, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ListVPCs(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
func ListVPCs(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
vpcs, err := DescribeVPCs(cloud)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
for _, v := range vpcs {
|
|
|
|
|
vpcID := aws.StringValue(v.VpcId)
|
|
|
|
|
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: FindName(v.Tags),
|
|
|
|
|
ID: vpcID,
|
|
|
|
|
Type: ec2.ResourceTypeVpc,
|
|
|
|
@ -1284,7 +1285,7 @@ func ListVPCs(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
return resourceTrackers, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteAutoScalingGroup(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
func DeleteAutoScalingGroup(cloud fi.Cloud, r *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
id := r.ID
|
|
|
|
@ -1304,7 +1305,7 @@ func DeleteAutoScalingGroup(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ListAutoScalingGroups(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
func ListAutoScalingGroups(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
tags := c.Tags()
|
|
|
|
@ -1314,10 +1315,10 @@ func ListAutoScalingGroups(cloud fi.Cloud, clusterName string) ([]*Resource, err
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
|
|
|
|
|
for _, asg := range asgs {
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: FindASGName(asg.Tags),
|
|
|
|
|
ID: aws.StringValue(asg.AutoScalingGroupName),
|
|
|
|
|
Type: "autoscaling-group",
|
|
|
|
@ -1342,12 +1343,12 @@ func ListAutoScalingGroups(cloud fi.Cloud, clusterName string) ([]*Resource, err
|
|
|
|
|
return resourceTrackers, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func FindAutoScalingLaunchConfigurations(cloud fi.Cloud, securityGroups sets.String) ([]*Resource, error) {
|
|
|
|
|
func FindAutoScalingLaunchConfigurations(cloud fi.Cloud, securityGroups sets.String) ([]*resources.Resource, error) {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
glog.V(2).Infof("Finding all Autoscaling LaunchConfigurations by security group")
|
|
|
|
|
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
|
|
|
|
|
request := &autoscaling.DescribeLaunchConfigurationsInput{}
|
|
|
|
|
err := c.Autoscaling().DescribeLaunchConfigurationsPages(request, func(p *autoscaling.DescribeLaunchConfigurationsOutput, lastPage bool) bool {
|
|
|
|
@ -1363,7 +1364,7 @@ func FindAutoScalingLaunchConfigurations(cloud fi.Cloud, securityGroups sets.Str
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: aws.StringValue(t.LaunchConfigurationName),
|
|
|
|
|
ID: aws.StringValue(t.LaunchConfigurationName),
|
|
|
|
|
Type: TypeAutoscalingLaunchConfig,
|
|
|
|
@ -1386,7 +1387,7 @@ func FindAutoScalingLaunchConfigurations(cloud fi.Cloud, securityGroups sets.Str
|
|
|
|
|
return resourceTrackers, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func FindNatGateways(cloud fi.Cloud, routeTables map[string]*Resource, clusterName string) ([]*Resource, error) {
|
|
|
|
|
func FindNatGateways(cloud fi.Cloud, routeTables map[string]*resources.Resource, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
if len(routeTables) == 0 {
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
@ -1433,7 +1434,7 @@ func FindNatGateways(cloud fi.Cloud, routeTables map[string]*Resource, clusterNa
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
if len(natGatewayIds) != 0 {
|
|
|
|
|
request := &ec2.DescribeNatGatewaysInput{}
|
|
|
|
|
for natGatewayId := range natGatewayIds {
|
|
|
|
@ -1450,7 +1451,7 @@ func FindNatGateways(cloud fi.Cloud, routeTables map[string]*Resource, clusterNa
|
|
|
|
|
|
|
|
|
|
for _, t := range response.NatGateways {
|
|
|
|
|
natGatewayId := aws.StringValue(t.NatGatewayId)
|
|
|
|
|
ngwTracker := &Resource{
|
|
|
|
|
ngwTracker := &resources.Resource{
|
|
|
|
|
Name: natGatewayId,
|
|
|
|
|
ID: natGatewayId,
|
|
|
|
|
Type: TypeNatGateway,
|
|
|
|
@ -1478,7 +1479,7 @@ func FindNatGateways(cloud fi.Cloud, routeTables map[string]*Resource, clusterNa
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, eip := range response.Addresses {
|
|
|
|
|
eipTracker := &Resource{
|
|
|
|
|
eipTracker := &resources.Resource{
|
|
|
|
|
Name: name,
|
|
|
|
|
ID: aws.StringValue(address.AllocationId),
|
|
|
|
|
Type: TypeElasticIp,
|
|
|
|
@ -1543,7 +1544,7 @@ func extractClusterName(userData string) string {
|
|
|
|
|
return clusterName
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
func DeleteAutoscalingLaunchConfiguration(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
func DeleteAutoscalingLaunchConfiguration(cloud fi.Cloud, r *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
id := r.ID
|
|
|
|
@ -1558,7 +1559,7 @@ func DeleteAutoscalingLaunchConfiguration(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteELB(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
func DeleteELB(cloud fi.Cloud, r *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
id := r.ID
|
|
|
|
@ -1577,7 +1578,7 @@ func DeleteELB(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DumpELB(op *DumpOperation, r *Resource) error {
|
|
|
|
|
func DumpELB(op *resources.DumpOperation, r *resources.Resource) error {
|
|
|
|
|
data := make(map[string]interface{})
|
|
|
|
|
data["id"] = r.ID
|
|
|
|
|
data["type"] = TypeLoadBalancer
|
|
|
|
@ -1586,16 +1587,16 @@ func DumpELB(op *DumpOperation, r *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ListELBs(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
func ListELBs(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
elbs, elbTags, err := DescribeELBs(cloud)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
for _, elb := range elbs {
|
|
|
|
|
id := aws.StringValue(elb.LoadBalancerName)
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: FindELBName(elbTags[id]),
|
|
|
|
|
ID: id,
|
|
|
|
|
Type: TypeLoadBalancer,
|
|
|
|
@ -1680,7 +1681,7 @@ func DescribeELBs(cloud fi.Cloud) ([]*elb.LoadBalancerDescription, map[string][]
|
|
|
|
|
return elbs, elbTags, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteElasticIP(cloud fi.Cloud, t *Resource) error {
|
|
|
|
|
func DeleteElasticIP(cloud fi.Cloud, t *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
id := t.ID
|
|
|
|
@ -1704,7 +1705,7 @@ func DeleteElasticIP(cloud fi.Cloud, t *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteNatGateway(cloud fi.Cloud, t *Resource) error {
|
|
|
|
|
func DeleteNatGateway(cloud fi.Cloud, t *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
id := t.ID
|
|
|
|
@ -1723,7 +1724,7 @@ func DeleteNatGateway(cloud fi.Cloud, t *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func deleteRoute53Records(cloud fi.Cloud, zone *route53.HostedZone, resourceTrackers []*Resource) error {
|
|
|
|
|
func deleteRoute53Records(cloud fi.Cloud, zone *route53.HostedZone, resourceTrackers []*resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
var changes []*route53.Change
|
|
|
|
@ -1752,8 +1753,8 @@ func deleteRoute53Records(cloud fi.Cloud, zone *route53.HostedZone, resourceTrac
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ListRoute53Records(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
func ListRoute53Records(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
|
|
|
|
|
if dns.IsGossipHostname(clusterName) {
|
|
|
|
|
return resourceTrackers, nil
|
|
|
|
@ -1822,12 +1823,12 @@ func ListRoute53Records(cloud fi.Cloud, clusterName string) ([]*Resource, error)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: aws.StringValue(rrs.Name),
|
|
|
|
|
ID: hostedZoneID + "/" + aws.StringValue(rrs.Name),
|
|
|
|
|
Type: "route53-record",
|
|
|
|
|
GroupKey: hostedZoneID,
|
|
|
|
|
GroupDeleter: func(cloud fi.Cloud, resourceTrackers []*Resource) error {
|
|
|
|
|
GroupDeleter: func(cloud fi.Cloud, resourceTrackers []*resources.Resource) error {
|
|
|
|
|
return deleteRoute53Records(cloud, zone, resourceTrackers)
|
|
|
|
|
},
|
|
|
|
|
Obj: rrs,
|
|
|
|
@ -1844,7 +1845,7 @@ func ListRoute53Records(cloud fi.Cloud, clusterName string) ([]*Resource, error)
|
|
|
|
|
return resourceTrackers, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteIAMRole(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
func DeleteIAMRole(cloud fi.Cloud, r *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
roleName := r.Name
|
|
|
|
@ -1896,7 +1897,7 @@ func DeleteIAMRole(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ListIAMRoles(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
func ListIAMRoles(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
remove := make(map[string]bool)
|
|
|
|
@ -1922,11 +1923,11 @@ func ListIAMRoles(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
|
|
|
|
|
for _, role := range roles {
|
|
|
|
|
name := aws.StringValue(role.RoleName)
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: name,
|
|
|
|
|
ID: name,
|
|
|
|
|
Type: "iam-role",
|
|
|
|
@ -1938,7 +1939,7 @@ func ListIAMRoles(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
return resourceTrackers, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteIAMInstanceProfile(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
func DeleteIAMInstanceProfile(cloud fi.Cloud, r *resources.Resource) error {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
profile := r.Obj.(*iam.InstanceProfile)
|
|
|
|
@ -1974,7 +1975,7 @@ func DeleteIAMInstanceProfile(cloud fi.Cloud, r *Resource) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ListIAMInstanceProfiles(cloud fi.Cloud, clusterName string) ([]*Resource, error) {
|
|
|
|
|
func ListIAMInstanceProfiles(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
|
|
|
|
|
c := cloud.(awsup.AWSCloud)
|
|
|
|
|
|
|
|
|
|
remove := make(map[string]bool)
|
|
|
|
@ -1998,11 +1999,11 @@ func ListIAMInstanceProfiles(cloud fi.Cloud, clusterName string) ([]*Resource, e
|
|
|
|
|
return nil, fmt.Errorf("error listing IAM instance profiles: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resourceTrackers []*Resource
|
|
|
|
|
var resourceTrackers []*resources.Resource
|
|
|
|
|
|
|
|
|
|
for _, profile := range profiles {
|
|
|
|
|
name := aws.StringValue(profile.InstanceProfileName)
|
|
|
|
|
resourceTracker := &Resource{
|
|
|
|
|
resourceTracker := &resources.Resource{
|
|
|
|
|
Name: name,
|
|
|
|
|
ID: name,
|
|
|
|
|
Type: "iam-instance-profile",
|