Skip to content

Commit

Permalink
Added handling of arm64 images (#6325)
Browse files Browse the repository at this point in the history
  • Loading branch information
melinath authored Jul 26, 2022
1 parent 4fcb876 commit a211a18
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 8 deletions.
19 changes: 15 additions & 4 deletions mmv1/templates/terraform/constants/disk.erb
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,14 @@ func diskImageEquals(oldImageName, newImageName string) bool {
func diskImageFamilyEquals(imageName, familyName string) bool {
// Handles the case when the image name includes the family name
// e.g. image name: debian-9-drawfork-v20180109, family name: debian-9
if strings.Contains(imageName, familyName) {
return true
// We have to check for arm64 because of cases like:
// image name: opensuse-leap-15-4-v20220713-arm64, family name: opensuse-leap (should not suppress)
if strings.Contains(imageName, strings.TrimSuffix(familyName, "-arm64")) {
if strings.Contains(imageName, "-arm64") {
return strings.HasSuffix(familyName, "-arm64")
} else {
return !strings.HasSuffix(familyName, "-arm64")
}
}
if suppressCanonicalFamilyDiff(imageName, familyName) {
Expand All @@ -138,8 +144,13 @@ func diskImageFamilyEquals(imageName, familyName string) bool {
// e.g. image: ubuntu-1404-trusty-v20180122, family: ubuntu-1404-lts
func suppressCanonicalFamilyDiff(imageName, familyName string) bool {
parts := canonicalUbuntuLtsImage.FindStringSubmatch(imageName)
if len(parts) == 3 {
f := fmt.Sprintf("ubuntu-%s%s-lts", parts[1], parts[2])
if len(parts) == 4 {
var f string
if parts[3] == "" {
f = fmt.Sprintf("ubuntu-%s%s-lts", parts[1], parts[2])
} else {
f = fmt.Sprintf("ubuntu-%s%s-lts-%s", parts[1], parts[2], parts[3])
}
if f == familyName {
return true
}
Expand Down
86 changes: 83 additions & 3 deletions mmv1/third_party/terraform/tests/resource_compute_disk_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,92 @@ func TestDiskImageDiffSuppress(t *testing.T) {
New: "different-cloud/debian-8",
ExpectDiffSuppress: false,
},
// arm images
"matching image opensuse arm64 self_link": {
Old: "https://www.googleapis.com/compute/v1/projects/opensuse-cloud/global/images/opensuse-leap-15-4-v20220713-arm64",
New: "opensuse-leap-arm64",
ExpectDiffSuppress: true,
},
"matching image sles arm64 self_link": {
Old: "https://www.googleapis.com/compute/v1/projects/suse-cloud/global/images/sles-15-sp4-v20220713-arm64",
New: "sles-15-arm64",
ExpectDiffSuppress: true,
},
"matching image ubuntu arm64 self_link": {
Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-1804-bionic-arm64-v20220712",
New: "ubuntu-1804-lts-arm64",
ExpectDiffSuppress: true,
},
"matching image ubuntu-minimal arm64 self_link": {
Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-minimal-2004-focal-arm64-v20220713",
New: "ubuntu-minimal-2004-lts-arm64",
ExpectDiffSuppress: true,
},
"matching image debian arm64 self_link": {
Old: "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-11-bullseye-arm64-v20220719",
New: "debian-11-arm64",
ExpectDiffSuppress: true,
},
"different architecture image opensuse arm64 self_link": {
Old: "https://www.googleapis.com/compute/v1/projects/opensuse-cloud/global/images/opensuse-leap-15-4-v20220713-arm64",
New: "opensuse-leap",
ExpectDiffSuppress: false,
},
"different architecture image sles arm64 self_link": {
Old: "https://www.googleapis.com/compute/v1/projects/suse-cloud/global/images/sles-15-sp4-v20220713-arm64",
New: "sles-15",
ExpectDiffSuppress: false,
},
"different architecture image ubuntu arm64 self_link": {
Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-1804-bionic-arm64-v20220712",
New: "ubuntu-1804-lts",
ExpectDiffSuppress: false,
},
"different architecture image ubuntu-minimal arm64 self_link": {
Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-minimal-2004-focal-arm64-v20220713",
New: "ubuntu-minimal-2004-lts",
ExpectDiffSuppress: false,
},
"different architecture image debian arm64 self_link": {
Old: "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-11-bullseye-arm64-v20220719",
New: "debian-11",
ExpectDiffSuppress: false,
},
"different architecture image opensuse arm64 family": {
Old: "https://www.googleapis.com/compute/v1/projects/opensuse-cloud/global/images/opensuse-leap-15-2-v20200702",
New: "opensuse-leap-arm64",
ExpectDiffSuppress: false,
},
"different architecture image sles arm64 family": {
Old: "https://www.googleapis.com/compute/v1/projects/suse-cloud/global/images/sles-15-sp4-v20220722-x86-64",
New: "sles-15-arm64",
ExpectDiffSuppress: false,
},
"different architecture image ubuntu arm64 family": {
Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-1804-bionic-v20220712",
New: "ubuntu-1804-lts-arm64",
ExpectDiffSuppress: false,
},
"different architecture image ubuntu-minimal arm64 family": {
Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-minimal-2004-focal-v20220713",
New: "ubuntu-minimal-2004-lts-arm64",
ExpectDiffSuppress: false,
},
"different architecture image debian arm64 family": {
Old: "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-11-bullseye-v20220719",
New: "debian-11-arm64",
ExpectDiffSuppress: false,
},
}

for tn, tc := range cases {
if diskImageDiffSuppress("image", tc.Old, tc.New, nil) != tc.ExpectDiffSuppress {
t.Errorf("bad: %s, %q => %q expect DiffSuppress to return %t", tn, tc.Old, tc.New, tc.ExpectDiffSuppress)
}
tc := tc
t.Run(tn, func(t *testing.T) {
t.Parallel()
if diskImageDiffSuppress("image", tc.Old, tc.New, nil) != tc.ExpectDiffSuppress {
t.Fatalf("%q => %q expect DiffSuppress to return %t", tc.Old, tc.New, tc.ExpectDiffSuppress)
}
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion mmv1/third_party/terraform/utils/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
resolveImageLink = regexp.MustCompile(fmt.Sprintf("^https://www.googleapis.com/compute/[a-z0-9]+/projects/(%s)/global/images/(%s)", ProjectRegex, resolveImageImageRegex))

windowsSqlImage = regexp.MustCompile("^sql-(?:server-)?([0-9]{4})-([a-z]+)-windows-(?:server-)?([0-9]{4})(?:-r([0-9]+))?-dc-v[0-9]+$")
canonicalUbuntuLtsImage = regexp.MustCompile("^ubuntu-(minimal-)?([0-9]+)-")
canonicalUbuntuLtsImage = regexp.MustCompile("^ubuntu-(minimal-)?([0-9]+)(?:.*(arm64))?.*$")
cosLtsImage = regexp.MustCompile("^cos-([0-9]+)-")
)

Expand Down

0 comments on commit a211a18

Please sign in to comment.