Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciprian Hacman committed Nov 9, 2020
1 parent fdf9768 commit 1d6a51a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
10 changes: 5 additions & 5 deletions pkg/resources/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func ListResourcesAWS(cloud awsup.AWSCloud, clusterName string) (map[string]*res
if err != nil {
return nil, err
}
lts, err := FindAutoScalingLaunchTemplates(cloud, clusterName, securityGroups)
lts, err := FindAutoScalingLaunchTemplates(cloud, clusterName)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1179,17 +1179,17 @@ func ListAutoScalingGroups(cloud fi.Cloud, clusterName string) ([]*resources.Res
return resourceTrackers, nil
}

// FindAutoScalingLaunchTemplates finds any launch configurations which reference the security groups
func FindAutoScalingLaunchTemplates(cloud fi.Cloud, clusterName string, securityGroups sets.String) ([]*resources.Resource, error) {
// FindAutoScalingLaunchTemplates finds any launch templates owned by the cluster (by tag).
func FindAutoScalingLaunchTemplates(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {
c := cloud.(awsup.AWSCloud)

klog.V(2).Infof("Finding all AutoScaling LaunchTemplates owned by the cluster")

input := &ec2.DescribeLaunchTemplatesInput{
Filters: []*ec2.Filter{
{
Name: aws.String("tag:KubernetesCluster"),
Values: []*string{aws.String(clusterName)},
Name: aws.String("tag:kubernetes.io/cluster/" + clusterName),
Values: []*string{aws.String("owned")},
},
},
}
Expand Down
9 changes: 4 additions & 5 deletions upup/pkg/fi/cloudup/awstasks/launchtemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,14 @@ func (t *LaunchTemplate) CheckChanges(a, e, changes *LaunchTemplate) error {
func (t *LaunchTemplate) FindDeletions(c *fi.Context) ([]fi.Deletion, error) {
var removals []fi.Deletion

configurations, err := t.findAllLaunchTemplates(c)
list, err := t.findAllLaunchTemplates(c)
if err != nil {
return nil, err
}

prefix := fmt.Sprintf("%s-", fi.StringValue(t.Name))
for _, configuration := range configurations {
if strings.HasPrefix(aws.StringValue(configuration.LaunchTemplateName), prefix) {
removals = append(removals, &deleteLaunchTemplate{lc: configuration})
for _, lt := range list {
if aws.StringValue(lt.LaunchTemplateName) != aws.StringValue(t.Name) {
removals = append(removals, &deleteLaunchTemplate{lc: lt})
}
}

Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (t *LaunchTemplate) findAllLaunchTemplates(c *fi.Context) ([]*ec2.LaunchTem
return list, nil
}

// findLatestLaunchTemplateVersion returns the latest template
// findLatestLaunchTemplateVersion returns the latest template version
func (t *LaunchTemplate) findLatestLaunchTemplateVersion(c *fi.Context) (*ec2.LaunchTemplateVersion, error) {
cloud, ok := c.Cloud.(awsup.AWSCloud)
if !ok {
Expand Down
6 changes: 3 additions & 3 deletions upup/pkg/fi/cloudup/awsup/aws_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,10 @@ func findAutoscalingGroupLaunchConfiguration(c AWSCloud, g *autoscaling.Group) (
return "", fmt.Errorf("error finding launch template by ID: %q", id)
}
launchTemplate := output.LaunchTemplates[0]
if version == "" || version == "$Default" {
version = strconv.FormatInt(*launchTemplate.DefaultVersionNumber, 10)
} else {
if version == "$Latest" {
version = strconv.FormatInt(*launchTemplate.LatestVersionNumber, 10)
} else {
version = strconv.FormatInt(*launchTemplate.DefaultVersionNumber, 10)
}
}
klog.V(4).Infof("Launch Template Version used for compare: %q", version)
Expand Down

0 comments on commit 1d6a51a

Please sign in to comment.