Skip to content

Commit

Permalink
Added handling of amd64 images on compute disk (#6769) (#12961)
Browse files Browse the repository at this point in the history
* Added handling of amd64 images on compute disk

* Removed Test Cases from the TestDiskImageDiffSuppress

* Added test cases for amd64 images

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Nov 7, 2022
1 parent a03efd4 commit be79911
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/6769.txt
@@ -0,0 +1,3 @@
```release-note:bug
compute: fixed perma-diff on `google_compute_disk` for new amd64 images
```
13 changes: 13 additions & 0 deletions google/resource_compute_disk.go
Expand Up @@ -151,6 +151,19 @@ 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-11-bullseye-v20220719, family name: debian-11

// First condition is to check if image contains arm64 because of case like:
// image name: opensuse-leap-15-4-v20220713-arm64, family name: opensuse-leap (should not be evaluated during handling of amd64 cases)
// In second condition, we have to check for amd64 because of cases like:
// image name: ubuntu-2210-kinetic-amd64-v20221022, family name: ubuntu-2210 (should not suppress)
if !strings.Contains(imageName, "-arm64") && strings.Contains(imageName, strings.TrimSuffix(familyName, "-amd64")) {
if strings.Contains(imageName, "-amd64") {
return strings.HasSuffix(familyName, "-amd64")
} else {
return !strings.HasSuffix(familyName, "-amd64")
}
}

// 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")) {
Expand Down
31 changes: 31 additions & 0 deletions google/resource_compute_disk_test.go
Expand Up @@ -247,6 +247,37 @@ func TestDiskImageDiffSuppress(t *testing.T) {
New: "debian-11-arm64",
ExpectDiffSuppress: false,
},
// amd images
"matching image ubuntu amd64 self_link": {
Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2210-kinetic-amd64-v20221022",
New: "ubuntu-2210-amd64",
ExpectDiffSuppress: true,
},
"matching image ubuntu-minimal amd64 self_link": {
Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-minimal-2210-kinetic-amd64-v20221022",
New: "ubuntu-minimal-2210-amd64",
ExpectDiffSuppress: true,
},
"different architecture image ubuntu amd64 self_link": {
Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2210-kinetic-amd64-v20221022",
New: "ubuntu-2210",
ExpectDiffSuppress: false,
},
"different architecture image ubuntu-minimal amd64 self_link": {
Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-minimal-2210-kinetic-amd64-v20221022",
New: "ubuntu-minimal-2210",
ExpectDiffSuppress: false,
},
"different architecture image ubuntu amd64 family": {
Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2210-kinetic-v20221022",
New: "ubuntu-2210-amd64",
ExpectDiffSuppress: false,
},
"different architecture image ubuntu-minimal amd64 family": {
Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-minimal-2210-kinetic-v20221022",
New: "ubuntu-minimal-2210-amd64",
ExpectDiffSuppress: false,
},
}

for tn, tc := range cases {
Expand Down

0 comments on commit be79911

Please sign in to comment.