Skip to content

Commit

Permalink
(CAT-1545) - Add machine type to matrix
Browse files Browse the repository at this point in the history
This commit adds a machine_type field to each object in the matrix
platforms.
This means that for arm-based architectures, we can return the
t2a-standard-2 machine which supports arm.
If not arm based, then resort back to default.
  • Loading branch information
jordanbreen28 committed Nov 10, 2023
1 parent 367db32 commit 3cbfb26
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ In order to use this new functionality, run:

`$: bundle exec matrix_from_metadata_v2 --custom-matrix matrix.json`

> Note: The file should contain a valid Array of JSON Objects (i.e. `[{"label":"AlmaLinux-8","provider":"provision_service","image":"almalinux-cloud/almalinux-8"}, {..}]`), otherwise it will throw an error.
> Note: The file should contain a valid Array of JSON Objects (i.e. `[{"label":"AlmaLinux-8","provider":"provision_service","image":"almalinux-cloud/almalinux-8","machine_type":"n1-standard-2"}, {"label":"RedHat-9-arm","provider":"provision_service","image":"rhel-9-arm64","machine_type":"t2a-standard-2"}, {..}]`), otherwise it will throw an error.
## Documentation

Expand Down
11 changes: 8 additions & 3 deletions exe/matrix_from_metadata_v2
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ IMAGE_TABLE = {
'RedHat-7' => 'rhel-7',
'RedHat-8' => 'rhel-8',
'RedHat-9' => 'rhel-9',
'RedHat-9-arm' => 'rhel-9-arm64',
'SLES-12' => 'sles-12',
'SLES-15' => 'sles-15',
'Windows-2016' => 'windows-2016',
Expand Down Expand Up @@ -116,7 +115,7 @@ if ARGV.include?('--provision-service')
updated_list = IMAGE_TABLE.dup.clone
updated_list.merge!(updated_platforms)

IMAGE_TABLE = updated_list.freeze
IMAGE_TABLE = updated_list
DOCKER_PLATFORMS = {}.freeze
end

Expand Down Expand Up @@ -150,14 +149,20 @@ else
# Set platforms based on declared operating system support
metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do |sup|
os = sup['operatingsystem']
if os.casecmp('redhat').zero? && sup['operatingsystemrelease'].include?('9')
IMAGE_TABLE['RedHat-9-arm'] = 'rhel-9-arm64'
sup['operatingsystemrelease'] << '9-arm'
end
sup['operatingsystemrelease'].sort_by(&:to_i).each do |ver|
image_key = "#{os}-#{ver}"

if IMAGE_TABLE.key?(image_key) && !exclude_list.include?(image_key.downcase)
matrix[:platforms] << {
label: image_key,
provider: 'provision_service',
image: IMAGE_TABLE[image_key]
image: IMAGE_TABLE[image_key],
# if the image is to be an ARM based instance, use t2a-standard-2 machine type
machine_type: image_key.end_with?('-arm') ? 't2a-standard-2' : 'n1-standard-2'
}
elsif DOCKER_PLATFORMS.key?(image_key) && !exclude_list.include?(image_key.downcase)
matrix[:platforms] << {
Expand Down
2 changes: 1 addition & 1 deletion spec/exe/fake_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"operatingsystem": "RedHat",
"operatingsystemrelease": [
"8",
"9-arm"
"9"
]
},
{
Expand Down
20 changes: 11 additions & 9 deletions spec/exe/matrix_from_metadata_v2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
expect(result.status_code).to eq 0
end

it 'generates the matrix' do
it 'generates the matrix' do # rubocop:disable RSpec/ExampleLength
expect(result.stdout).to include('::warning::Cannot find image for Ubuntu-14.04')
expect(github_output_content).to include(
[
'matrix={',
'"platforms":[',
'{"label":"CentOS-6","provider":"docker","image":"litmusimage/centos:6"},',
'{"label":"RedHat-8","provider":"provision_service","image":"rhel-8"},',
'{"label":"RedHat-9-arm","provider":"provision_service","image":"rhel-9-arm64"},',
'{"label":"RedHat-8","provider":"provision_service","image":"rhel-8","machine_type":"n1-standard-2"},',
'{"label":"RedHat-9","provider":"provision_service","image":"rhel-9","machine_type":"n1-standard-2"},',
'{"label":"RedHat-9-arm","provider":"provision_service","image":"rhel-9-arm64","machine_type":"t2a-standard-2"},',
'{"label":"Ubuntu-18.04","provider":"docker","image":"litmusimage/ubuntu:18.04"}',
'],',
'"collection":[',
Expand All @@ -36,7 +37,7 @@
expect(github_output_content).to include(
'spec_matrix={"include":[{"puppet_version":"~> 7.24","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}'
)
expect(result.stdout).to include("Created matrix with 10 cells:\n - Acceptance Test Cells: 8\n - Spec Test Cells: 2")
expect(result.stdout).to include("Created matrix with 12 cells:\n - Acceptance Test Cells: 10\n - Spec Test Cells: 2")
end
end

Expand All @@ -53,16 +54,17 @@
expect(result.status_code).to eq 0
end

it 'generates the matrix without excluded platforms' do
it 'generates the matrix without excluded platforms' do # rubocop:disable RSpec/ExampleLength
expect(result.stdout).to include('::warning::Cannot find image for Ubuntu-14.04')
expect(result.stdout).to include('::warning::Ubuntu-18.04 was excluded from testing')
expect(github_output_content).to include(
[
'matrix={',
'"platforms":[',
'{"label":"CentOS-6","provider":"docker","image":"litmusimage/centos:6"},',
'{"label":"RedHat-8","provider":"provision_service","image":"rhel-8"},',
'{"label":"RedHat-9-arm","provider":"provision_service","image":"rhel-9-arm64"}',
'{"label":"RedHat-8","provider":"provision_service","image":"rhel-8","machine_type":"n1-standard-2"},',
'{"label":"RedHat-9","provider":"provision_service","image":"rhel-9","machine_type":"n1-standard-2"},',
'{"label":"RedHat-9-arm","provider":"provision_service","image":"rhel-9-arm64","machine_type":"t2a-standard-2"}',
'],',
'"collection":[',
'"puppet7-nightly","puppet8-nightly"',
Expand All @@ -73,7 +75,7 @@
expect(github_output_content).to include(
'spec_matrix={"include":[{"puppet_version":"~> 7.24","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}'
)
expect(result.stdout).to include("Created matrix with 8 cells:\n - Acceptance Test Cells: 6\n - Spec Test Cells: 2")
expect(result.stdout).to include("Created matrix with 10 cells:\n - Acceptance Test Cells: 8\n - Spec Test Cells: 2")
end
end

Expand All @@ -99,7 +101,7 @@
'matrix={',
'"platforms":[',
'{"label":"CentOS-6","provider":"docker","image":"litmusimage/centos:6"},',
'{"label":"RedHat-9-arm","provider":"provision_service","image":"rhel-9-arm64"}',
'{"label":"RedHat-9-arm","provider":"provision_service","image":"rhel-9-arm64","machine_type":"t2a-standard-2"}',
'],',
'"collection":[',
'"puppet7-nightly","puppet8-nightly"',
Expand Down

0 comments on commit 3cbfb26

Please sign in to comment.