Skip to content

Commit 3db3b18

Browse files
authored
Merge pull request #3812 from Ankitasw/revert-3790-ami-naming
Revert "Change naming format of AMIs while searching for AMIs"
2 parents daebd7f + cea1993 commit 3db3b18

File tree

4 files changed

+4
-53
lines changed

4 files changed

+4
-53
lines changed

cmd/clusterawsadm/ami/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func getAllImages(ec2Client ec2iface.EC2API, ownerID string) (map[string][]*ec2.
229229
}
230230

231231
func findAMI(imagesMap map[string][]*ec2.Image, baseOS, kubernetesVersion string) (*ec2.Image, error) {
232-
amiNameFormat := "capa-ami-{{.BaseOS}}-{{.K8sVersion}}-*"
232+
amiNameFormat := "capa-ami-{{.BaseOS}}-{{.K8sVersion}}"
233233
amiName, err := ec2service.GenerateAmiName(amiNameFormat, baseOS, kubernetesVersion)
234234
if err != nil {
235235
return nil, errors.Wrapf(err, "failed to process ami format: %q", amiNameFormat)

cmd/clusterawsadm/ami/helper_test.go

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ package ami
1919
import (
2020
"testing"
2121

22-
"github.com/aws/aws-sdk-go/aws"
23-
"github.com/aws/aws-sdk-go/service/ec2"
2422
"github.com/google/go-cmp/cmp"
25-
. "github.com/onsi/gomega"
2623
)
2724

2825
func TestAllPatchVersions(t *testing.T) {
@@ -54,50 +51,3 @@ func TestAllPatchVersions(t *testing.T) {
5451
})
5552
}
5653
}
57-
58-
func TestFindAMI(t *testing.T) {
59-
tests := []struct {
60-
name string
61-
imagesMap map[string][]*ec2.Image
62-
want *ec2.Image
63-
}{
64-
{
65-
name: "find AMI based on the latest ami format",
66-
imagesMap: map[string][]*ec2.Image{
67-
"capa-ami-amazon-2-v1.23.5-*": {
68-
{
69-
ImageId: aws.String("capa-ami-amazon-2-v1.25.3-1664536077"),
70-
CreationDate: aws.String("2011-02-08T17:02:31.000Z"),
71-
},
72-
},
73-
},
74-
want: &ec2.Image{
75-
ImageId: aws.String("capa-ami-amazon-2-v1.25.3-1664536077"),
76-
CreationDate: aws.String("2011-02-08T17:02:31.000Z"),
77-
},
78-
},
79-
{
80-
name: "find AMI based on the old ami format",
81-
imagesMap: map[string][]*ec2.Image{
82-
"capa-ami-amazon-2-1.23.5": {
83-
{
84-
ImageId: aws.String("capa-ami-amazon-2-1.25.3-00-1664536077"),
85-
CreationDate: aws.String("2011-02-08T17:02:31.000Z"),
86-
},
87-
},
88-
},
89-
want: nil,
90-
},
91-
}
92-
93-
for _, tt := range tests {
94-
t.Run(tt.name, func(t *testing.T) {
95-
g := NewWithT(t)
96-
got, err := findAMI(tt.imagesMap, "amazon-2", "v1.23.5")
97-
if err != nil {
98-
t.Fatalf("error while finding AMI %+v", err)
99-
}
100-
g.Expect(got).Should(Equal(tt.want))
101-
})
102-
}
103-
}

pkg/cloud/services/ec2/ami.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"bytes"
2121
"fmt"
2222
"sort"
23+
"strings"
2324
"text/template"
2425
"time"
2526

@@ -76,7 +77,7 @@ type AMILookup struct {
7677

7778
// GenerateAmiName will generate an AMI name.
7879
func GenerateAmiName(amiNameFormat, baseOS, kubernetesVersion string) (string, error) {
79-
amiNameParameters := AMILookup{baseOS, kubernetesVersion}
80+
amiNameParameters := AMILookup{baseOS, strings.TrimPrefix(kubernetesVersion, "v")}
8081
// revert to default if not specified
8182
if amiNameFormat == "" {
8283
amiNameFormat = DefaultAmiNameFormat

pkg/cloud/services/ec2/ami_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func TestGenerateAmiName(t *testing.T) {
265265
args: args{
266266
kubernetesVersion: "v1.23.3",
267267
},
268-
want: "capa-ami--?v1.23.3-*",
268+
want: "capa-ami--?1.23.3-*",
269269
},
270270
{
271271
name: "Should return valid amiName if default AMI name format passed",

0 commit comments

Comments
 (0)