Skip to content

Commit

Permalink
rhcos: ami regions from rhcos stream at runtime
Browse files Browse the repository at this point in the history
Currently, the installer relies on a generated go file for determining
the AWS region in which the RHCOS image is published. The `go generate`
directive was inadvertently removed in openshift#4582.
Rather than resurrecting the directive, this commit removes the generated
code in favor of gathering the regions directly from the rhcos stream
data when needed.

https://issues.redhat.com/browse/CORS-1838
  • Loading branch information
staebler committed Dec 9, 2021
1 parent eaaf64f commit abca904
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 175 deletions.
2 changes: 0 additions & 2 deletions hack/verify-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
if [ "$IS_CONTAINER" != "" ]; then
set -xe
go generate ./pkg/types/installconfig.go
# See https://github.com/openshift/installer/pull/5447#discussion_r762340594
# go generate ./pkg/rhcos/ami.go
set +ex
git diff --exit-code
else
Expand Down
6 changes: 1 addition & 5 deletions pkg/asset/installconfig/aws/regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package aws

import (
"github.com/aws/aws-sdk-go/aws/endpoints"
"k8s.io/apimachinery/pkg/util/sets"

"github.com/openshift/installer/pkg/rhcos"
"github.com/openshift/installer/pkg/types"
Expand All @@ -12,10 +11,7 @@ import (
// This is subset of AWS regions and the regions where RHEL CoreOS images are published.
// The result is a map of region identifier to region description
func knownRegions(architecture types.Architecture) map[string]string {
required := sets.NewString(rhcos.AMIRegionsX86_64...)
if architecture == types.ArchitectureARM64 {
required = sets.NewString(rhcos.AMIRegionsAARCH64...)
}
required := rhcos.AMIRegions(architecture)

regions := make(map[string]string)
for _, partition := range endpoints.DefaultPartitions() {
Expand Down
14 changes: 2 additions & 12 deletions pkg/asset/installconfig/aws/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/openshift/installer/pkg/rhcos"
"github.com/openshift/installer/pkg/types"
awstypes "github.com/openshift/installer/pkg/types/aws"
awsvalidation "github.com/openshift/installer/pkg/types/aws/validation"
)

type resourceRequirements struct {
Expand Down Expand Up @@ -81,17 +80,8 @@ func validatePlatform(ctx context.Context, meta *Metadata, fldPath *field.Path,

func validateAMI(ctx context.Context, config *types.InstallConfig) field.ErrorList {
// accept AMI from the rhcos stream metadata
switch config.ControlPlane.Architecture {
case types.ArchitectureAMD64:
if sets.NewString(rhcos.AMIRegionsX86_64...).Has(config.Platform.AWS.Region) {
return nil
}
case types.ArchitectureARM64:
if sets.NewString(rhcos.AMIRegionsAARCH64...).Has(config.Platform.AWS.Region) {
return nil
}
default:
return field.ErrorList{field.NotSupported(field.NewPath("controlPlane", "architecture"), config.ControlPlane.Architecture, awsvalidation.ValidArchitectureValues)}
if rhcos.AMIRegions(config.ControlPlane.Architecture).Has(config.Platform.AWS.Region) {
return nil
}

// accept AMI specified at the platform level
Expand Down
33 changes: 33 additions & 0 deletions pkg/rhcos/ami_regions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package rhcos

import (
"context"

"github.com/coreos/stream-metadata-go/arch"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/sets"

"github.com/openshift/installer/pkg/types"
)

// AMIRegions returns the AWS regions in which an RHCOS AMI for the specified architecture is published.
func AMIRegions(architecture types.Architecture) sets.String {
stream, err := FetchCoreOSBuild(context.Background())
if err != nil {
logrus.Error("could not fetch the rhcos stream data: %w", err)
return nil
}
rpmArch := arch.RpmArch(string(architecture))
awsImages := stream.Architectures[rpmArch].Images.Aws
if awsImages == nil {
return nil
}
regions := make([]string, 0, len(awsImages.Regions))
for name, r := range awsImages.Regions {
if r.Image == "" {
continue
}
regions = append(regions, name)
}
return sets.NewString(regions...)
}
26 changes: 0 additions & 26 deletions pkg/rhcos/ami_regions_aarch64.go

This file was deleted.

102 changes: 0 additions & 102 deletions pkg/rhcos/ami_regions_generate.go

This file was deleted.

28 changes: 0 additions & 28 deletions pkg/rhcos/ami_regions_x86_64.go

This file was deleted.

0 comments on commit abca904

Please sign in to comment.