mirror of https://github.com/kubernetes/kops.git
Merge pull request #9909 from johngmyers/template-filter
Get launch template versions after filtering templates
This commit is contained in:
commit
041f774642
|
|
@ -301,22 +301,26 @@ func (t *LaunchTemplate) findAllLaunchTemplates(c *fi.Context) ([]*ec2.LaunchTem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// findAllLaunchTemplateVersions returns all the launch templates versions for us
|
// findLaunchTemplates returns a list of launch templates
|
||||||
func (t *LaunchTemplate) findAllLaunchTemplatesVersions(c *fi.Context) ([]*ec2.LaunchTemplateVersion, error) {
|
func (t *LaunchTemplate) findLaunchTemplates(c *fi.Context) ([]*ec2.LaunchTemplateVersion, error) {
|
||||||
var list []*ec2.LaunchTemplateVersion
|
|
||||||
|
|
||||||
cloud, ok := c.Cloud.(awsup.AWSCloud)
|
cloud, ok := c.Cloud.(awsup.AWSCloud)
|
||||||
if !ok {
|
if !ok {
|
||||||
return []*ec2.LaunchTemplateVersion{}, fmt.Errorf("invalid cloud provider: %v, expected: awsup.AWSCloud", c.Cloud)
|
return []*ec2.LaunchTemplateVersion{}, fmt.Errorf("invalid cloud provider: %v, expected: awsup.AWSCloud", c.Cloud)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @step: get a list of the launch templates
|
||||||
templates, err := t.findAllLaunchTemplates(c)
|
templates, err := t.findAllLaunchTemplates(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prefix := fmt.Sprintf("%s-", fi.StringValue(t.Name))
|
||||||
|
|
||||||
|
// @step: get the launch template versions for the templates we are interested in
|
||||||
|
var list []*ec2.LaunchTemplateVersion
|
||||||
var next *string
|
var next *string
|
||||||
for _, x := range templates {
|
for _, x := range templates {
|
||||||
|
if strings.HasPrefix(aws.StringValue(x.LaunchTemplateName), prefix) {
|
||||||
err := func() error {
|
err := func() error {
|
||||||
for {
|
for {
|
||||||
resp, err := cloud.EC2().DescribeLaunchTemplateVersions(&ec2.DescribeLaunchTemplateVersionsInput{
|
resp, err := cloud.EC2().DescribeLaunchTemplateVersions(&ec2.DescribeLaunchTemplateVersionsInput{
|
||||||
|
|
@ -338,31 +342,12 @@ func (t *LaunchTemplate) findAllLaunchTemplatesVersions(c *fi.Context) ([]*ec2.L
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// findLaunchTemplates returns a list of launch templates
|
|
||||||
func (t *LaunchTemplate) findLaunchTemplates(c *fi.Context) ([]*ec2.LaunchTemplateVersion, error) {
|
|
||||||
// @step: get a list of the launch templates
|
|
||||||
list, err := t.findAllLaunchTemplatesVersions(c)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
prefix := fmt.Sprintf("%s-", fi.StringValue(t.Name))
|
|
||||||
|
|
||||||
// @step: filter out the templates we are interested in
|
|
||||||
var filtered []*ec2.LaunchTemplateVersion
|
|
||||||
for _, x := range list {
|
|
||||||
if strings.HasPrefix(aws.StringValue(x.LaunchTemplateName), prefix) {
|
|
||||||
filtered = append(filtered, x)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @step: we can sort the configurations in chronological order
|
// @step: sort the configurations in chronological order
|
||||||
sort.Slice(filtered, func(i, j int) bool {
|
sort.Slice(list, func(i, j int) bool {
|
||||||
ti := filtered[i].CreateTime
|
ti := list[i].CreateTime
|
||||||
tj := filtered[j].CreateTime
|
tj := list[j].CreateTime
|
||||||
if tj == nil {
|
if tj == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -372,7 +357,7 @@ func (t *LaunchTemplate) findLaunchTemplates(c *fi.Context) ([]*ec2.LaunchTempla
|
||||||
return ti.UnixNano() < tj.UnixNano()
|
return ti.UnixNano() < tj.UnixNano()
|
||||||
})
|
})
|
||||||
|
|
||||||
return filtered, nil
|
return list, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// findLatestLaunchTemplate returns the latest template
|
// findLatestLaunchTemplate returns the latest template
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue