github.com/openshift/installer@v1.4.17/pkg/rhcos/ami_regions.go (about)

     1  package rhcos
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/coreos/stream-metadata-go/arch"
     7  	"github.com/sirupsen/logrus"
     8  	"k8s.io/apimachinery/pkg/util/sets"
     9  
    10  	"github.com/openshift/installer/pkg/types"
    11  )
    12  
    13  // AMIRegions returns the AWS regions in which an RHCOS AMI for the specified architecture is published.
    14  func AMIRegions(architecture types.Architecture) sets.String {
    15  	stream, err := FetchCoreOSBuild(context.Background())
    16  	if err != nil {
    17  		logrus.Errorf("could not fetch the rhcos stream data: %v", err)
    18  		return nil
    19  	}
    20  	rpmArch := arch.RpmArch(string(architecture))
    21  	awsImages := stream.Architectures[rpmArch].Images.Aws
    22  	if awsImages == nil {
    23  		return nil
    24  	}
    25  	regions := make([]string, 0, len(awsImages.Regions))
    26  	for name, r := range awsImages.Regions {
    27  		if r.Image == "" {
    28  			continue
    29  		}
    30  		regions = append(regions, name)
    31  	}
    32  	return sets.NewString(regions...)
    33  }