Skip to content

Commit

Permalink
Added handling of arm64 images (#6325) (#4533)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jul 26, 2022
1 parent 468b55b commit 594984d
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changelog/6325.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: fixed perma-diff on `google_compute_disk` for new arm64 images
```
2 changes: 1 addition & 1 deletion google-beta/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
19 changes: 15 additions & 4 deletions google-beta/resource_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,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 @@ -167,8 +173,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 google-beta/resource_compute_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,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

0 comments on commit 594984d

Please sign in to comment.