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

Add arm support #477

Merged
merged 4 commits into from
Sep 8, 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
3 changes: 3 additions & 0 deletions docs/usage-as-operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This section describes, how the configuration for `CloudProfile`s looks like for

The cloud profile configuration contains information about the real machine image IDs in the GCP environment (image URLs).
You have to map every version that you specify in `.spec.machineImages[].versions` here such that the GCP extension knows the image URL for every version you want to offer.
For each machine image version an `architecture` field can be specified which specifies the CPU architecture of the machine on which given machine image can be used.

An example `CloudProfileConfig` for the GCP extension looks as follows:

Expand All @@ -25,6 +26,7 @@ machineImages:
versions:
- version: 2135.6.0
image: projects/coreos-cloud/global/images/coreos-stable-2135-6-0-v20190801
# architecture: amd64 # optional
```

### Example `CloudProfile` manifest
Expand Down Expand Up @@ -74,6 +76,7 @@ spec:
versions:
- version: 2135.6.0
image: projects/coreos-cloud/global/images/coreos-stable-2135-6-0-v20190801
# architecture: amd64 # optional
```

## `Seed` resource
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 @@ -537,6 +537,18 @@ string
<p>Image is the path to the image.</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="gcp.provider.extensions.gardener.cloud/v1alpha1.MachineImageVersion">MachineImageVersion
Expand Down Expand Up @@ -578,6 +590,18 @@ string
<p>Image is the path to the image.</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="gcp.provider.extensions.gardener.cloud/v1alpha1.MachineImages">MachineImages
Expand Down
17 changes: 9 additions & 8 deletions pkg/apis/gcp/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"

api "github.com/gardener/gardener-extension-provider-gcp/pkg/apis/gcp"
"k8s.io/utils/pointer"
)

// FindSubnetByPurpose takes a list of subnets and tries to find the first entry
Expand All @@ -33,33 +34,33 @@ func FindSubnetByPurpose(subnets []api.Subnet, purpose api.SubnetPurpose) (*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 zone. If no such entry is
// whose name, version, architecture and zone matches with the given name, version, and zone. 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 string, architecture *string) (*api.MachineImage, error) {
for _, machineImage := range machineImages {
if machineImage.Name == name && machineImage.Version == version {
if machineImage.Name == name && machineImage.Version == version && pointer.StringEqual(architecture, machineImage.Architecture) {
return &machineImage, nil
}
}
return nil, fmt.Errorf("no machine image with name %q, version %q found", name, version)
return nil, fmt.Errorf("no machine image found with name %q, architecture %q and version %q", name, *architecture, version)
}

// 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
// to find the image with the given name, architecture and version in the desired cloud profile. If it cannot be found then an error
// is returned.
func FindImageFromCloudProfile(cloudProfileConfig *api.CloudProfileConfig, imageName, imageVersion string) (string, error) {
func FindImageFromCloudProfile(cloudProfileConfig *api.CloudProfileConfig, imageName, imageVersion string, architecture *string) (string, error) {
if cloudProfileConfig != nil {
for _, machineImage := range cloudProfileConfig.MachineImages {
if machineImage.Name != imageName {
continue
}
for _, version := range machineImage.Versions {
if imageVersion == version.Version {
if imageVersion == version.Version && pointer.StringEqual(architecture, version.Architecture) {
return version.Image, nil
}
}
}
}

return "", fmt.Errorf("could not find an image for name %q in version %q", imageName, imageVersion)
return "", fmt.Errorf("could not find an image for name %q and architecture %q in version %q", imageName, *architecture, imageVersion)
}
38 changes: 21 additions & 17 deletions pkg/apis/gcp/helper/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package helper_test
import (
api "github.com/gardener/gardener-extension-provider-gcp/pkg/apis/gcp"
. "github.com/gardener/gardener-extension-provider-gcp/pkg/apis/gcp/helper"
"k8s.io/utils/pointer"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -43,23 +44,24 @@ var _ = Describe("Helper", func() {
)

DescribeTable("#FindMachineImage",
func(machineImages []api.MachineImage, name, version string, expectedMachineImage *api.MachineImage, expectErr bool) {
machineImage, err := FindMachineImage(machineImages, name, version)
func(machineImages []api.MachineImage, name, version string, architecture *string, expectedMachineImage *api.MachineImage, expectErr bool) {
machineImage, err := FindMachineImage(machineImages, name, version, architecture)
expectResults(machineImage, expectedMachineImage, err, expectErr)
},

Entry("list is nil", nil, "foo", "1.2.3", nil, true),
Entry("empty list", []api.MachineImage{}, "foo", "1.2.3", nil, true),
Entry("entry not found (no name)", []api.MachineImage{{Name: "bar", Version: "1.2.3", Image: "image123"}}, "foo", "1.2.3", nil, true),
Entry("entry not found (no version)", []api.MachineImage{{Name: "bar", Version: "1.2.3", Image: "image123"}}, "foo", "1.2.4", nil, true),
Entry("entry exists", []api.MachineImage{{Name: "bar", Version: "1.2.3", Image: "image123"}}, "bar", "1.2.3", &api.MachineImage{Name: "bar", Version: "1.2.3", Image: "image123"}, false),
Entry("list is nil", nil, "foo", "1.2.3", pointer.String("foo"), nil, true),
Entry("empty list", []api.MachineImage{}, "foo", "1.2.3", pointer.String("foo"), nil, true),
Entry("entry not found (no name)", []api.MachineImage{{Name: "bar", Version: "1.2.3", Image: "image123"}}, "foo", "1.2.3", pointer.String("foo"), nil, true),
Entry("entry not found (no version)", []api.MachineImage{{Name: "bar", Version: "1.2.3", Image: "image123"}}, "foo", "1.2.4", pointer.String("foo"), nil, true),
Entry("entry not found (no architecture)", []api.MachineImage{{Name: "bar", Version: "1.2.3", Image: "image123", Architecture: pointer.String("foo")}}, "foo", "1.2.4", pointer.String("foo"), nil, true),
Entry("entry exists", []api.MachineImage{{Name: "bar", Version: "1.2.3", Image: "image123", Architecture: pointer.String("foo")}}, "bar", "1.2.3", pointer.String("foo"), &api.MachineImage{Name: "bar", Version: "1.2.3", Image: "image123", Architecture: pointer.String("foo")}, false),
)

DescribeTable("#FindImage",
func(profileImages []api.MachineImages, imageName, version string, expectedImage string) {
func(profileImages []api.MachineImages, imageName, version string, architecture *string, expectedImage string) {
cfg := &api.CloudProfileConfig{}
cfg.MachineImages = profileImages
image, err := FindImageFromCloudProfile(cfg, imageName, version)
image, err := FindImageFromCloudProfile(cfg, imageName, version, architecture)

Expect(image).To(Equal(expectedImage))
if expectedImage != "" {
Expand All @@ -69,20 +71,22 @@ var _ = Describe("Helper", func() {
}
},

Entry("list is nil", nil, "ubuntu", "1", ""),
Entry("list is nil", nil, "ubuntu", "1", pointer.String("foo"), ""),

Entry("profile empty list", []api.MachineImages{}, "ubuntu", "1", ""),
Entry("profile entry not found (image does not exist)", makeProfileMachineImages("debian", "1"), "ubuntu", "1", ""),
Entry("profile entry not found (version does not exist)", makeProfileMachineImages("ubuntu", "2"), "ubuntu", "1", ""),
Entry("profile entry", makeProfileMachineImages("ubuntu", "1"), "ubuntu", "1", profileImage),
Entry("profile empty list", []api.MachineImages{}, "ubuntu", "1", pointer.String("foo"), ""),
Entry("profile entry not found (image does not exist)", makeProfileMachineImages("debian", "1", pointer.String("foo")), "ubuntu", "1", pointer.String("foo"), ""),
Entry("profile entry not found (version does not exist)", makeProfileMachineImages("ubuntu", "2", pointer.String("foo")), "ubuntu", "1", pointer.String("foo"), ""),
Entry("profile entry not found (no architecture)", makeProfileMachineImages("ubuntu", "2", pointer.String("bar")), "ubuntu", "1", pointer.String("foo"), ""),
Entry("profile entry", makeProfileMachineImages("ubuntu", "1", pointer.String("foo")), "ubuntu", "1", pointer.String("foo"), profileImage),
)
})

func makeProfileMachineImages(name, version string) []api.MachineImages {
func makeProfileMachineImages(name, version string, architecture *string) []api.MachineImages {
var versions []api.MachineImageVersion
versions = append(versions, api.MachineImageVersion{
Version: version,
Image: profileImage,
Version: version,
Image: profileImage,
Architecture: architecture,
})

return []api.MachineImages{
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/gcp/types_cloudprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ type MachineImageVersion struct {
Version string
// Image is the path to the image.
Image string
// Architecture is the CPU architecture of the machine image.
Architecture *string
}
2 changes: 2 additions & 0 deletions pkg/apis/gcp/types_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ type MachineImage struct {
Version string
// Image is the path to the image.
Image string
// Architecture is the CPU architecture of the machine image.
Architecture *string
}

// ServiceAccount is a GCP service account.
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/gcp/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@
package v1alpha1

import (
v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/pointer"
)

func addDefaultingFuncs(scheme *runtime.Scheme) error {
return RegisterDefaults(scheme)
}

// SetDefaults_MachineImageVersion set the architecture of machine image.
func SetDefaults_MachineImageVersion(obj *MachineImageVersion) {
if obj.Architecture == nil {
obj.Architecture = pointer.String(v1beta1constants.ArchitectureAMD64)
}
}
35 changes: 35 additions & 0 deletions pkg/apis/gcp/v1alpha1/defaults_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2022 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1_test

import (
. "github.com/gardener/gardener-extension-provider-gcp/pkg/apis/gcp/v1alpha1"

v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Defaults", func() {
Describe("#SetDefaults_MachineImageVersion", func() {
It("should default the architecture to amd64", func() {
obj := &MachineImageVersion{}

SetDefaults_MachineImageVersion(obj)

Expect(*obj.Architecture).To(Equal(v1beta1constants.ArchitectureAMD64))
})
})
})
3 changes: 3 additions & 0 deletions pkg/apis/gcp/v1alpha1/types_cloudprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ type MachineImageVersion struct {
Version string `json:"version"`
// Image is the path to the image.
Image string `json:"image"`
// Architecture is the CPU architecture of the machine image.
// +optional
Architecture *string `json:"architecture,omitempty"`
}
3 changes: 3 additions & 0 deletions pkg/apis/gcp/v1alpha1/types_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ type MachineImage struct {
Version string `json:"version"`
// Image is the path to the image.
Image string `json:"image"`
// Architecture is the CPU architecture of the machine image.
// +optional
Architecture *string `json:"architecture,omitempty"`
}

// ServiceAccount is a GCP service account.
Expand Down
27 changes: 27 additions & 0 deletions pkg/apis/gcp/v1alpha1/v1alpha1_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2022 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestV1alpha1(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "API V1Alpha1 Suite")
}
4 changes: 4 additions & 0 deletions pkg/apis/gcp/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions pkg/apis/gcp/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions pkg/apis/gcp/v1alpha1/zz_generated.defaults.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading