Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default Ubuntu to 22.04 for new k8s versions #2807

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions azure/services/virtualmachineimages/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,17 @@ func (s *Service) getSKUAndVersion(ctx context.Context, location, publisher, off

// getUbuntuOSVersion returns the default Ubuntu OS version for the given Kubernetes version.
func getUbuntuOSVersion(major, minor, patch uint64) string {
// Default to Ubuntu 20.04 LTS, except for k8s versions which have only 18.04 reference images.
osVersion := "2004"
if (major == 1 && minor == 21 && patch < 2) ||
(major == 1 && minor == 20 && patch < 8) ||
(major == 1 && minor == 19 && patch < 12) ||
(major == 1 && minor == 18 && patch < 20) ||
(major == 1 && minor < 18) {
// Default to Ubuntu 22.04 LTS for Kubernetes v1.25.3 and later.
osVersion := "2204"
if major == 1 && minor == 21 && patch < 2 ||
major == 1 && minor == 20 && patch < 8 ||
major == 1 && minor == 19 && patch < 12 ||
major == 1 && minor == 18 && patch < 20 ||
major == 1 && minor < 18 {
osVersion = "1804"
} else if major == 1 && minor == 25 && patch < 3 ||
major == 1 && minor < 25 {
osVersion = "2004"
}
return osVersion
}
Expand Down
112 changes: 110 additions & 2 deletions azure/services/virtualmachineimages/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ func TestGetDefaultUbuntuImage(t *testing.T) {
},
},
},
{
k8sVersion: "v1.22.16",
expectedSKU: "ubuntu-2004-gen1",
expectedVersion: "122.16.20221117",
versions: compute.ListVirtualMachineImageResource{
Value: &[]compute.VirtualMachineImageResource{
{Name: to.StringPtr("122.16.20221117")},
},
},
},
{
k8sVersion: "v1.23.6",
expectedSKU: "k8s-1dot23dot6-ubuntu-2004",
Expand Down Expand Up @@ -143,6 +153,66 @@ func TestGetDefaultUbuntuImage(t *testing.T) {
},
},
},
{
k8sVersion: "v1.23.12",
expectedSKU: "ubuntu-2004-gen1",
expectedVersion: "123.12.20220921",
versions: compute.ListVirtualMachineImageResource{
Value: &[]compute.VirtualMachineImageResource{
{Name: to.StringPtr("123.12.20220921")},
},
},
},
{
k8sVersion: "v1.23.13",
expectedSKU: "ubuntu-2004-gen1",
expectedVersion: "123.13.20221014",
versions: compute.ListVirtualMachineImageResource{
Value: &[]compute.VirtualMachineImageResource{
{Name: to.StringPtr("123.13.20221014")},
},
},
},
{
k8sVersion: "v1.24.6",
expectedSKU: "ubuntu-2004-gen1",
expectedVersion: "124.6.20220921",
versions: compute.ListVirtualMachineImageResource{
Value: &[]compute.VirtualMachineImageResource{
{Name: to.StringPtr("124.6.20220921")},
},
},
},
{
k8sVersion: "v1.24.7",
expectedSKU: "ubuntu-2004-gen1",
expectedVersion: "124.7.20221014",
versions: compute.ListVirtualMachineImageResource{
Value: &[]compute.VirtualMachineImageResource{
{Name: to.StringPtr("124.7.20221014")},
},
},
},
{
k8sVersion: "v1.25.2",
expectedSKU: "ubuntu-2004-gen1",
expectedVersion: "125.2.20220921",
versions: compute.ListVirtualMachineImageResource{
Value: &[]compute.VirtualMachineImageResource{
{Name: to.StringPtr("125.2.20220921")},
},
},
},
{
k8sVersion: "v1.25.3",
expectedSKU: "ubuntu-2204-gen1",
expectedVersion: "125.3.20221014",
versions: compute.ListVirtualMachineImageResource{
Value: &[]compute.VirtualMachineImageResource{
{Name: to.StringPtr("125.3.20221014")},
},
},
},
}

location := "westus3"
Expand Down Expand Up @@ -393,11 +463,37 @@ func TestGetDefaultImageSKUID(t *testing.T) {
osAndVersion: "ubuntu-2004",
},
{
k8sVersion: "v1.23.13",
k8sVersion: "v1.22.0",
expectedSKU: "k8s-1dot22dot0-ubuntu-2004",
expectedVersion: "latest",
expectedError: false,
osAndVersion: "ubuntu-2004",
},
{
k8sVersion: "v1.22.9",
expectedSKU: "k8s-1dot22dot9-ubuntu-2004",
expectedVersion: "latest",
expectedError: false,
osAndVersion: "ubuntu-2004",
},
{
k8sVersion: "v1.23.12",
expectedSKU: "ubuntu-2004-gen1",
expectedVersion: "123.13.20220524",
expectedVersion: "123.12.20220921",
expectedError: false,
osAndVersion: "ubuntu-2004",
versions: compute.ListVirtualMachineImageResource{
Value: &[]compute.VirtualMachineImageResource{
{Name: to.StringPtr("123.12.20220921")},
},
},
},
{
k8sVersion: "v1.23.13",
expectedSKU: "ubuntu-2204-gen1",
expectedVersion: "123.13.20220524",
expectedError: false,
osAndVersion: "ubuntu-2204",
versions: compute.ListVirtualMachineImageResource{
Value: &[]compute.VirtualMachineImageResource{
{Name: to.StringPtr("123.13.20220524")},
Expand Down Expand Up @@ -446,6 +542,18 @@ func TestGetDefaultImageSKUID(t *testing.T) {
},
},
},
{
k8sVersion: "v1.25.4",
expectedSKU: "ubuntu-2204-gen1",
expectedVersion: "125.4.20221011",
expectedError: false,
osAndVersion: "ubuntu-2204",
versions: compute.ListVirtualMachineImageResource{
Value: &[]compute.VirtualMachineImageResource{
{Name: to.StringPtr("125.4.20221011")},
},
},
},
}

location := "francesouth"
Expand Down