Skip to content

Commit

Permalink
fixup! asset: rhcos: make asset multi-arch aware
Browse files Browse the repository at this point in the history
  • Loading branch information
r4f4 committed Jul 3, 2024
1 parent 11a224f commit 9f1f813
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 58 deletions.
4 changes: 2 additions & 2 deletions pkg/asset/cluster/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func PreTerraform(ctx context.Context, tfvarsFile *asset.File, installConfig *in
// upload the corresponding image to Glance if rhcosImage contains a
// URL. If rhcosImage contains a name, then that points to an existing
// Glance image.
if imageName, isURL := rhcos.GenerateOpenStackImageName(rhcosImage.ControlPlane(), clusterID.InfraID); isURL {
if err := preprovision.UploadBaseImage(ctx, installConfig.Config.Platform.OpenStack.Cloud, rhcosImage.ControlPlane(), imageName, clusterID.InfraID, installConfig.Config.Platform.OpenStack.ClusterOSImageProperties); err != nil {
if imageName, isURL := rhcos.GenerateOpenStackImageName(rhcosImage.ControlPlane, clusterID.InfraID); isURL {
if err := preprovision.UploadBaseImage(ctx, installConfig.Config.Platform.OpenStack.Cloud, rhcosImage.ControlPlane, imageName, clusterID.InfraID, installConfig.Config.Platform.OpenStack.ClusterOSImageProperties); err != nil {
return err
}
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/asset/cluster/tfvars/tfvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (t *TerraformVariables) Generate(ctx context.Context, parents asset.Parents
for i, m := range workers {
workerConfigs[i] = m.Spec.Template.Spec.ProviderSpec.Value.Object.(*machinev1beta1.AWSMachineProviderConfig) //nolint:errcheck // legacy, pre-linter
}
osImage := strings.SplitN(rhcosImage.ControlPlane(), ",", 2)
osImage := strings.SplitN(rhcosImage.ControlPlane, ",", 2)
osImageID := osImage[0]
osImageRegion := installConfig.Config.AWS.Region
if len(osImage) == 2 {
Expand Down Expand Up @@ -418,7 +418,7 @@ func (t *TerraformVariables) Generate(ctx context.Context, parents asset.Parents
BaseDomainResourceGroupName: installConfig.Config.Azure.BaseDomainResourceGroupName,
MasterConfigs: masterConfigs,
WorkerConfigs: workerConfigs,
ImageURL: rhcosImage.ControlPlane(),
ImageURL: rhcosImage.ControlPlane,
ImageRelease: rhcosRelease.GetAzureReleaseVersion(),
PreexistingNetwork: preexistingnetwork,
Publish: installConfig.Config.Publish,
Expand Down Expand Up @@ -733,7 +733,7 @@ func (t *TerraformVariables) Generate(ctx context.Context, parents asset.Parents
CISInstanceCRN: cisCRN,
DNSInstanceID: dnsID,
EndpointsJSONFile: endpointsJSONFile,
ImageURL: rhcosImage.ControlPlane(),
ImageURL: rhcosImage.ControlPlane,
MasterConfigs: masterConfigs,
MasterDedicatedHosts: masterDedicatedHosts,
NetworkResourceGroupName: installConfig.Config.Platform.IBMCloud.NetworkResourceGroupName,
Expand All @@ -759,7 +759,7 @@ func (t *TerraformVariables) Generate(ctx context.Context, parents asset.Parents
installConfig,
mastersAsset,
workersAsset,
rhcosImage.ControlPlane(),
rhcosImage.ControlPlane,
clusterID,
bootstrapIgn,
)
Expand Down Expand Up @@ -831,7 +831,7 @@ func (t *TerraformVariables) Generate(ctx context.Context, parents asset.Parents
installConfig.Config.Platform.Ovirt.StorageDomainID,
installConfig.Config.Platform.Ovirt.NetworkName,
installConfig.Config.Platform.Ovirt.VNICProfileID,
rhcosImage.ControlPlane(),
rhcosImage.ControlPlane,
clusterID.InfraID,
masters[0].Spec.ProviderSpec.Value.Object.(*ovirtprovider.OvirtMachineProviderSpec),
installConfig.Config.Platform.Ovirt.AffinityGroups,
Expand Down Expand Up @@ -969,7 +969,7 @@ func (t *TerraformVariables) Generate(ctx context.Context, parents asset.Parents
return err
}

osImage := strings.SplitN(rhcosImage.ControlPlane(), "/", 2)
osImage := strings.SplitN(rhcosImage.ControlPlane, "/", 2)
data, err = powervstfvars.TFVars(
powervstfvars.TFVarsSources{
MasterConfigs: masterConfigs,
Expand Down Expand Up @@ -1018,7 +1018,7 @@ func (t *TerraformVariables) Generate(ctx context.Context, parents asset.Parents
controlPlaneConfigs[i] = c.Spec.ProviderSpec.Value.Object.(*machinev1.NutanixMachineProviderConfig) //nolint:errcheck // legacy, pre-linter
}

imgURI := rhcosImage.ControlPlane()
imgURI := rhcosImage.ControlPlane
if installConfig.Config.Nutanix.ClusterOSImage != "" {
imgURI = installConfig.Config.Nutanix.ClusterOSImage
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/ignition/bootstrap/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (a *Common) getTemplateData(dependencies asset.Parents, bootstrapInPlace bo
EtcdCluster: strings.Join(etcdEndpoints, ","),
Proxy: &proxy.Config.Status,
Registries: registries,
BootImage: rhcosImage.ControlPlane(),
BootImage: rhcosImage.ControlPlane,
PlatformData: platformData,
ClusterProfile: clusterProfile,
BootstrapInPlace: bootstrapInPlaceConfig,
Expand Down
8 changes: 4 additions & 4 deletions pkg/asset/machines/clusterapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (c *ClusterAPI) Generate(ctx context.Context, dependencies asset.Parents) e

mpool := defaultAWSMachinePoolPlatform("master")

osImage := strings.SplitN(rhcosImage.ControlPlane(), ",", 2)
osImage := strings.SplitN(rhcosImage.ControlPlane, ",", 2)
osImageID := osImage[0]
if len(osImage) == 2 {
osImageID = "" // the AMI will be generated later on
Expand Down Expand Up @@ -298,7 +298,7 @@ func (c *ClusterAPI) Generate(ctx context.Context, dependencies asset.Parents) e
installConfig,
clusterID.InfraID,
&pool,
rhcosImage.ControlPlane(),
rhcosImage.ControlPlane,
)
if err != nil {
return fmt.Errorf("failed to create master machine objects %w", err)
Expand All @@ -311,7 +311,7 @@ func (c *ClusterAPI) Generate(ctx context.Context, dependencies asset.Parents) e
installConfig,
clusterID.InfraID,
&pool,
rhcosImage.ControlPlane(),
rhcosImage.ControlPlane,
)
if err != nil {
return fmt.Errorf("failed to create bootstrap machine objects %w", err)
Expand Down Expand Up @@ -394,7 +394,7 @@ func (c *ClusterAPI) Generate(ctx context.Context, dependencies asset.Parents) e
mpool.Set(pool.Platform.OpenStack)
pool.Platform.OpenStack = &mpool

imageName, _ := rhcosutils.GenerateOpenStackImageName(rhcosImage.ControlPlane(), clusterID.InfraID)
imageName, _ := rhcosutils.GenerateOpenStackImageName(rhcosImage.ControlPlane, clusterID.InfraID)

for _, role := range []string{"master", "bootstrap"} {
openStackMachines, err := openstack.GenerateMachines(
Expand Down
10 changes: 5 additions & 5 deletions pkg/asset/machines/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (m *Master) Generate(ctx context.Context, dependencies asset.Parents) error

mpool := defaultAWSMachinePoolPlatform("master")

osImage := strings.SplitN(rhcosImage.ControlPlane(), ",", 2)
osImage := strings.SplitN(rhcosImage.ControlPlane, ",", 2)
osImageID := osImage[0]
if len(osImage) == 2 {
osImageID = "" // the AMI will be generated later on
Expand Down Expand Up @@ -257,7 +257,7 @@ func (m *Master) Generate(ctx context.Context, dependencies asset.Parents) error
mpool.Zones = azs
}
pool.Platform.GCP = &mpool
machines, controlPlaneMachineSet, err = gcp.Machines(clusterID.InfraID, ic, &pool, rhcosImage.ControlPlane(), "master", masterUserDataSecretName)
machines, controlPlaneMachineSet, err = gcp.Machines(clusterID.InfraID, ic, &pool, rhcosImage.ControlPlane, "master", masterUserDataSecretName)
if err != nil {
return errors.Wrap(err, "failed to create master machine objects")
}
Expand Down Expand Up @@ -319,7 +319,7 @@ func (m *Master) Generate(ctx context.Context, dependencies asset.Parents) error
mpool.Set(pool.Platform.OpenStack)
pool.Platform.OpenStack = &mpool

imageName, _ := rhcosutils.GenerateOpenStackImageName(rhcosImage.ControlPlane(), clusterID.InfraID)
imageName, _ := rhcosutils.GenerateOpenStackImageName(rhcosImage.ControlPlane, clusterID.InfraID)

machines, controlPlaneMachineSet, err = openstack.Machines(ctx, clusterID.InfraID, ic, &pool, imageName, "master", masterUserDataSecretName)
if err != nil {
Expand Down Expand Up @@ -378,7 +378,7 @@ func (m *Master) Generate(ctx context.Context, dependencies asset.Parents) error
return err
}
useImageGallery := installConfig.Azure.CloudName != azuretypes.StackCloud
machines, controlPlaneMachineSet, err = azure.Machines(clusterID.InfraID, ic, &pool, rhcosImage.ControlPlane(), "master", masterUserDataSecretName, capabilities, useImageGallery)
machines, controlPlaneMachineSet, err = azure.Machines(clusterID.InfraID, ic, &pool, rhcosImage.ControlPlane, "master", masterUserDataSecretName, capabilities, useImageGallery)
if err != nil {
return errors.Wrap(err, "failed to create master machine objects")
}
Expand Down Expand Up @@ -430,7 +430,7 @@ func (m *Master) Generate(ctx context.Context, dependencies asset.Parents) error
mpool.Set(pool.Platform.Ovirt)
pool.Platform.Ovirt = &mpool

imageName, _ := rhcosutils.GenerateOpenStackImageName(rhcosImage.ControlPlane(), clusterID.InfraID)
imageName, _ := rhcosutils.GenerateOpenStackImageName(rhcosImage.ControlPlane, clusterID.InfraID)

machines, err = ovirt.Machines(clusterID.InfraID, ic, &pool, imageName, "master", masterUserDataSecretName)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/asset/machines/master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ spec:
},
},
}),
rhcos.MakeAsset("test-image", ""),
rhcos.MakeAsset("test-image"),
(*rhcos.Release)(pointer.StringPtr("412.86.202208101040-0")),
&machine.Master{
File: &asset.File{
Expand Down Expand Up @@ -223,7 +223,7 @@ func TestControlPlaneIsNotModified(t *testing.T) {
InfraID: "test-infra-id",
},
installConfig,
rhcos.MakeAsset("test-image", ""),
rhcos.MakeAsset("test-image"),
(*rhcos.Release)(pointer.StringPtr("412.86.202208101040-0")),
&machine.Master{
File: &asset.File{
Expand Down Expand Up @@ -292,7 +292,7 @@ func TestBaremetalGeneratedAssetFiles(t *testing.T) {
InfraID: "test-infra-id",
},
installConfig,
rhcos.MakeAsset("test-image", ""),
rhcos.MakeAsset("test-image"),
(*rhcos.Release)(pointer.StringPtr("412.86.202208101040-0")),
&machine.Master{
File: &asset.File{
Expand Down
10 changes: 5 additions & 5 deletions pkg/asset/machines/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (w *Worker) Generate(ctx context.Context, dependencies asset.Parents) error
}
mpool := defaultAWSMachinePoolPlatform(pool.Name)

osImage := strings.SplitN(rhcosImage.Compute(), ",", 2)
osImage := strings.SplitN(rhcosImage.Compute, ",", 2)
osImageID := osImage[0]
if len(osImage) == 2 {
osImageID = "" // the AMI will be generated later on
Expand Down Expand Up @@ -492,7 +492,7 @@ func (w *Worker) Generate(ctx context.Context, dependencies asset.Parents) error
}

useImageGallery := ic.Platform.Azure.CloudName != azuretypes.StackCloud
sets, err := azure.MachineSets(clusterID.InfraID, ic, &pool, rhcosImage.Compute(), "worker", workerUserDataSecretName, capabilities, useImageGallery)
sets, err := azure.MachineSets(clusterID.InfraID, ic, &pool, rhcosImage.Compute, "worker", workerUserDataSecretName, capabilities, useImageGallery)
if err != nil {
return errors.Wrap(err, "failed to create worker machine objects")
}
Expand Down Expand Up @@ -527,7 +527,7 @@ func (w *Worker) Generate(ctx context.Context, dependencies asset.Parents) error
mpool.Zones = azs
}
pool.Platform.GCP = &mpool
sets, err := gcp.MachineSets(clusterID.InfraID, ic, &pool, rhcosImage.Compute(), "worker", workerUserDataSecretName)
sets, err := gcp.MachineSets(clusterID.InfraID, ic, &pool, rhcosImage.Compute, "worker", workerUserDataSecretName)
if err != nil {
return errors.Wrap(err, "failed to create worker machine objects")
}
Expand Down Expand Up @@ -569,7 +569,7 @@ func (w *Worker) Generate(ctx context.Context, dependencies asset.Parents) error
mpool.Set(pool.Platform.OpenStack)
pool.Platform.OpenStack = &mpool

imageName, _ := rhcosutils.GenerateOpenStackImageName(rhcosImage.Compute(), clusterID.InfraID)
imageName, _ := rhcosutils.GenerateOpenStackImageName(rhcosImage.Compute, clusterID.InfraID)

sets, err := openstack.MachineSets(ctx, clusterID.InfraID, ic, &pool, imageName, "worker", workerUserDataSecretName)
if err != nil {
Expand Down Expand Up @@ -619,7 +619,7 @@ func (w *Worker) Generate(ctx context.Context, dependencies asset.Parents) error
mpool.Set(pool.Platform.Ovirt)
pool.Platform.Ovirt = &mpool

imageName, _ := rhcosutils.GenerateOpenStackImageName(rhcosImage.Compute(), clusterID.InfraID)
imageName, _ := rhcosutils.GenerateOpenStackImageName(rhcosImage.Compute, clusterID.InfraID)

sets, err := ovirt.MachineSets(clusterID.InfraID, ic, &pool, imageName, "worker", workerUserDataSecretName)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/asset/machines/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ spec:
},
},
}),
rhcos.MakeAsset("test-image", ""),
rhcos.MakeAsset("test-image"),
(*rhcos.Release)(pointer.StringPtr("412.86.202208101040-0")),
&machine.Worker{
File: &asset.File{
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestComputeIsNotModified(t *testing.T) {
InfraID: "test-infra-id",
},
installConfig,
rhcos.MakeAsset("test-image", ""),
rhcos.MakeAsset("test-image"),
(*rhcos.Release)(pointer.StringPtr("412.86.202208101040-0")),
&machine.Worker{
File: &asset.File{
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/manifests/clusterapi/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (c *Cluster) Generate(_ context.Context, dependencies asset.Parents) error
}
case powervstypes.Name:
var err error
osImage := strings.SplitN(rhcosImage.ControlPlane(), "/", 2)
osImage := strings.SplitN(rhcosImage.ControlPlane, "/", 2)
out, err = powervs.GenerateClusterAssets(installConfig, clusterID, osImage[0], osImage[1])
if err != nil {
return fmt.Errorf("failed to generate PowerVS manifests %w", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/manifests/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (o *Openshift) Generate(ctx context.Context, dependencies asset.Parents) er
case baremetaltypes.Name:
bmTemplateData := baremetalTemplateData{
Baremetal: installConfig.Config.Platform.BareMetal,
ProvisioningOSDownloadURL: rhcosImage.ControlPlane(),
ProvisioningOSDownloadURL: rhcosImage.ControlPlane,
}
assetData["99_baremetal-provisioning-config.yaml"] = applyTemplateData(baremetalConfig.Files()[0].Data, bmTemplateData)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/rhcos/bootstrap_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (i *BootstrapImage) Generate(ctx context.Context, p asset.Parents) error {
return fmt.Errorf("%s: No qemu build found", st.FormatPrefix(archName))
default:
// other platforms use the same image for all nodes
*i = BootstrapImage(rhcosImage.ControlPlane())
*i = BootstrapImage(rhcosImage.ControlPlane)
return nil
}
}
34 changes: 12 additions & 22 deletions pkg/asset/rhcos/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
// This stores the location of the image based on the platform.
// eg. on AWS this contains ami-id, on Livirt this can be the URI for QEMU image etc.
type Image struct {
controlPlane string
compute string
ControlPlane string
Compute string
}

var _ asset.Asset = (*Image)(nil)
Expand All @@ -51,25 +51,11 @@ func (i *Image) Dependencies() []asset.Asset {
}
}

// ControlPlane returns the RHCOS image for the control plane nodes.
func (i *Image) ControlPlane() string {
return i.controlPlane
}

// Compute returns the RHCOS image for the compute nodes.
func (i *Image) Compute() string {
if len(i.compute) > 0 {
return i.compute
}
// For compatibility with before the asset was multi-arch aware.
return i.controlPlane
}

// Generate the RHCOS image location.
func (i *Image) Generate(ctx context.Context, p asset.Parents) error {
if oi, ok := os.LookupEnv("OPENSHIFT_INSTALL_OS_IMAGE_OVERRIDE"); ok && oi != "" {
logrus.Warn("Found override for OS Image. Please be warned, this is not advised")
*i = *MakeAsset(oi, "")
*i = *MakeAsset(oi)
return nil
}

Expand All @@ -80,8 +66,12 @@ func (i *Image) Generate(ctx context.Context, p asset.Parents) error {
if err != nil {
return err
}
// For compatibility with before the asset had multi-arch support
if len(osImageCompute) == 0 {
osImageCompute = osimageControlPlane
}
logrus.Infof("<== generated rhcos image: (%q, %q)", osimageControlPlane, osImageCompute)
*i = *MakeAsset(osimageControlPlane, osImageCompute)
*i = Image{osimageControlPlane, osImageCompute}
return nil
}

Expand Down Expand Up @@ -253,10 +243,10 @@ func osImage(ctx context.Context, config *types.InstallConfig) (string, string,
}
}

// MakeAsset returns an Image asset with the given os images.
func MakeAsset(osImageControlPlane, osImageCompute string) *Image {
// MakeAsset returns an Image asset with the given os image.
func MakeAsset(osImage string) *Image {
return &Image{
controlPlane: osImageControlPlane,
compute: osImageCompute,
ControlPlane: osImage,
Compute: osImage,
}
}
2 changes: 1 addition & 1 deletion pkg/infrastructure/aws/clusterapi/ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

// copyAMIToRegion copies the AMI to the region configured in the installConfig if needed.
func copyAMIToRegion(ctx context.Context, installConfig *installconfig.InstallConfig, infraID string, rhcosImage *rhcos.Image) (string, error) {
osImage := strings.SplitN(rhcosImage.ControlPlane(), ",", 2)
osImage := strings.SplitN(rhcosImage.ControlPlane, ",", 2)
amiID, amiRegion := osImage[0], osImage[1]

logrus.Infof("Copying AMI %s to region %s", amiID, installConfig.AWS.Region)
Expand Down
2 changes: 1 addition & 1 deletion pkg/infrastructure/nutanix/clusterapi/clusterapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (p Provider) PreProvision(ctx context.Context, in infracapi.PreProvisionInp

// upload the rhcos image.
imgName := nutanixtypes.RHCOSImageName(in.InfraID)
imgURI := in.RhcosImage.ControlPlane()
imgURI := in.RhcosImage.ControlPlane
imgReq := &nutanixclientv3.ImageIntentInput{}
imgSpec := &nutanixclientv3.Image{
Name: &imgName,
Expand Down
2 changes: 1 addition & 1 deletion pkg/infrastructure/openstack/clusterapi/clusterapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (p Provider) PreProvision(ctx context.Context, in clusterapi.PreProvisionIn
var (
infraID = in.InfraID
installConfig = in.InstallConfig
rhcosImage = in.RhcosImage.ControlPlane()
rhcosImage = in.RhcosImage.ControlPlane
manifestsAsset = in.ManifestsAsset
machineManifests = in.MachineManifests
workersAsset = in.WorkersAsset
Expand Down
2 changes: 1 addition & 1 deletion pkg/infrastructure/vsphere/clusterapi/clusterapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (p Provider) PreProvision(ctx context.Context, in clusterapi.PreProvisionIn
clusterID := &installconfig.ClusterID{InfraID: in.InfraID}
var tagID string

cachedImage, err := cache.DownloadImageFile(in.RhcosImage.ControlPlane(), cache.InstallerApplicationName)
cachedImage, err := cache.DownloadImageFile(in.RhcosImage.ControlPlane, cache.InstallerApplicationName)
if err != nil {
return fmt.Errorf("failed to use cached vsphere image: %w", err)
}
Expand Down

0 comments on commit 9f1f813

Please sign in to comment.