Skip to content

Commit

Permalink
Default Ubuntu to 22.04 for new k8s versions
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma authored and k8s-infra-cherrypick-robot committed Dec 6, 2022
1 parent 88f9511 commit 9c3d9fa
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 9 deletions.
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

0 comments on commit 9c3d9fa

Please sign in to comment.