Skip to content

Commit

Permalink
Support arm64 (gardener#690)
Browse files Browse the repository at this point in the history
* Extend API for arm64 support

Co-Authored-By: Konstantinos Angelopoulos <[email protected]>
Co-Authored-By: Robin Schneider <[email protected]>

* Adapt worker controller to use architecture mapping

Co-Authored-By: Konstantinos Angelopoulos <[email protected]>
Co-Authored-By: Robin Schneider <[email protected]>

* Validate region and architecture mappings

Co-Authored-By: Konstantinos Angelopoulos <[email protected]>
Co-Authored-By: Robin Schneider <[email protected]>

* Update docs for `CloudProfileConfig`

Co-Authored-By: Konstantinos Angelopoulos <[email protected]>
Co-Authored-By: Robin Schneider <[email protected]>

---------

Co-authored-by: Robin Schneider <[email protected]>
Co-authored-by: Konstantinos Angelopoulos <[email protected]>
Co-authored-by: Robin Schneider <[email protected]>
(cherry picked from commit 5387c16)
  • Loading branch information
timebertt authored and robinschneider committed Mar 13, 2024
1 parent aabcb86 commit 32707a8
Show file tree
Hide file tree
Showing 16 changed files with 450 additions and 97 deletions.
37 changes: 37 additions & 0 deletions docs/operations/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,19 @@ machineImages:
- name: coreos
versions:
- version: 2135.6.0
# Fallback to image name if no region mapping is found
# Only works for amd64 and is strongly discouraged. Prefer image IDs!
image: coreos-2135.6.0
regions:
- name: europe
id: "1234-amd64"
architecture: amd64 # optional, defaults to amd64
- name: europe
id: "1234-arm64"
architecture: arm64
- name: asia
id: "5678-amd64"
architecture: amd64
# keystoneURL: https://url-to-keystone/v3/
# keystoneURLs:
# - region: europe
Expand Down Expand Up @@ -158,11 +170,24 @@ spec:
- name: coreos
versions:
- version: 2135.6.0
architectures: # optional, defaults to [amd64]
- amd64
- arm64
machineTypes:
- name: medium_4_8
cpu: "4"
gpu: "0"
memory: 8Gi
architecture: amd64 # optional, defaults to amd64
storage:
class: standard
type: default
size: 40Gi
- name: medium_4_8_arm
cpu: "4"
gpu: "0"
memory: 8Gi
architecture: arm64
storage:
class: standard
type: default
Expand All @@ -180,7 +205,19 @@ spec:
- name: coreos
versions:
- version: 2135.6.0
# Fallback to image name if no region mapping is found
# Only works for amd64 and is strongly discouraged. Prefer image IDs!
image: coreos-2135.6.0
regions:
- name: europe
id: "1234-amd64"
architecture: amd64 # optional, defaults to amd64
- name: europe
id: "1234-arm64"
architecture: arm64
- name: asia
id: "5678-amd64"
architecture: amd64
keystoneURL: https://url-to-keystone/v3/
constraints:
floatingPools:
Expand Down
24 changes: 24 additions & 0 deletions hack/api-reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,18 @@ string
<p>ID is the id of the image. (one of Image or ID must be set)</p>
</td>
</tr>
<tr>
<td>
<code>architecture</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Architecture is the CPU architecture of the machine image</p>
</td>
</tr>
</tbody>
</table>
<h3 id="openstack.provider.extensions.gardener.cloud/v1alpha1.MachineImageVersion">MachineImageVersion
Expand Down Expand Up @@ -1480,6 +1492,18 @@ string
<p>ID is the ID for the machine image in the given region.</p>
</td>
</tr>
<tr>
<td>
<code>architecture</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Architecture is the CPU architecture of the machine image</p>
</td>
</tr>
</tbody>
</table>
<h3 id="openstack.provider.extensions.gardener.cloud/v1alpha1.Router">Router
Expand Down
36 changes: 25 additions & 11 deletions pkg/apis/openstack/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ package helper
import (
"fmt"

v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
"k8s.io/utils/pointer"

api "github.com/gardener/gardener-extension-provider-openstack/pkg/apis/openstack"
"github.com/gardener/gardener-extension-provider-openstack/pkg/utils"
)
Expand Down Expand Up @@ -48,9 +51,11 @@ func FindSecurityGroupByPurpose(securityGroups []api.SecurityGroup, purpose api.
// FindMachineImage takes a list of machine images and tries to find the first entry
// whose name, version, and zone matches with the given name, version, and cloud profile. If no such
// entry is found then an error will be returned.
func FindMachineImage(machineImages []api.MachineImage, name, version string) (*api.MachineImage, error) {
func FindMachineImage(machineImages []api.MachineImage, name, version, architecture string) (*api.MachineImage, error) {
for _, machineImage := range machineImages {
if machineImage.Name == name && machineImage.Version == version {
// If the architecture field is not present, ignore it for backwards-compatibility.
if machineImage.Name == name && machineImage.Version == version &&
(machineImage.Architecture == nil || *machineImage.Architecture == architecture) {
return &machineImage, nil
}
}
Expand All @@ -60,7 +65,7 @@ func FindMachineImage(machineImages []api.MachineImage, name, version string) (*
// FindImageFromCloudProfile takes a list of machine images, and the desired image name and version. It tries
// to find the image with the given name and version in the desired cloud profile. If it cannot be found then an error
// is returned.
func FindImageFromCloudProfile(cloudProfileConfig *api.CloudProfileConfig, imageName, imageVersion, regionName string) (*api.MachineImage, error) {
func FindImageFromCloudProfile(cloudProfileConfig *api.CloudProfileConfig, imageName, imageVersion, regionName, architecture string) (*api.MachineImage, error) {
if cloudProfileConfig != nil {
for _, machineImage := range cloudProfileConfig.MachineImages {
if machineImage.Name != imageName {
Expand All @@ -71,19 +76,28 @@ func FindImageFromCloudProfile(cloudProfileConfig *api.CloudProfileConfig, image
continue
}
for _, region := range version.Regions {
if regionName == region.Name {
if regionName == region.Name && architecture == pointer.StringDeref(region.Architecture, v1beta1constants.ArchitectureAMD64) {
return &api.MachineImage{
Name: imageName,
Version: imageVersion,
ID: region.ID,
Name: imageName,
Version: imageVersion,
Architecture: &architecture,
ID: region.ID,
}, nil
}
}
if version.Image != "" {

// if we haven't found a region mapping, fallback to the image name
if version.Image != "" && architecture == v1beta1constants.ArchitectureAMD64 {
// The fallback image name doesn't specify an architecture, but we assume it is amd64 as arm was not supported
// previously.
// Referencing images by name is error-prone and is highly discouraged anyways.
// If people want to use arm images in their CloudProfile, they need to specify a region mapping and can't
// use the fallback MachineImage by name.
return &api.MachineImage{
Name: imageName,
Version: imageVersion,
Image: version.Image,
Name: imageName,
Version: imageVersion,
Architecture: pointer.String(v1beta1constants.ArchitectureAMD64),
Image: version.Image,
}, nil
}
}
Expand Down
Loading

0 comments on commit 32707a8

Please sign in to comment.