Skip to content

Commit

Permalink
Added handling of amd64 images on compute disk (#6769)
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
  • Loading branch information
AlfatahB committed Nov 7, 2022
1 parent b2a5ec8 commit 33a71b9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mmv1/templates/terraform/constants/disk.erb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,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 mmv1/third_party/terraform/tests/resource_compute_disk_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,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 33a71b9

Please sign in to comment.