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

     1  // Package rhcos contains assets for RHCOS.
     2  package rhcos
     3  
     4  import (
     5  	"context"
     6  	"fmt"
     7  	"time"
     8  
     9  	"github.com/coreos/stream-metadata-go/arch"
    10  
    11  	"github.com/openshift/installer/pkg/asset"
    12  	"github.com/openshift/installer/pkg/asset/installconfig"
    13  	"github.com/openshift/installer/pkg/rhcos"
    14  	"github.com/openshift/installer/pkg/types/baremetal"
    15  )
    16  
    17  // BootstrapImage is location of the RHCOS image for the Bootstrap node
    18  // This stores the location of the image based on the platform.
    19  // eg. on AWS this contains ami-id, on Livirt this can be the URI for QEMU image etc.
    20  // Note that for most platforms this is the same as rhcos.Image
    21  type BootstrapImage string
    22  
    23  var _ asset.Asset = (*BootstrapImage)(nil)
    24  
    25  // Name returns the human-friendly name of the asset.
    26  func (i *BootstrapImage) Name() string {
    27  	return "BootstrapImage"
    28  }
    29  
    30  // Dependencies returns no dependencies.
    31  func (i *BootstrapImage) Dependencies() []asset.Asset {
    32  	return []asset.Asset{
    33  		&installconfig.InstallConfig{},
    34  		new(Image),
    35  	}
    36  }
    37  
    38  // Generate the RHCOS Bootstrap image location.
    39  func (i *BootstrapImage) Generate(ctx context.Context, p asset.Parents) error {
    40  	ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
    41  	defer cancel()
    42  
    43  	ic := &installconfig.InstallConfig{}
    44  	rhcosImage := new(Image)
    45  	p.Get(ic, rhcosImage)
    46  	config := ic.Config
    47  
    48  	switch config.Platform.Name() {
    49  	case baremetal.Name:
    50  		archName := arch.RpmArch(string(config.ControlPlane.Architecture))
    51  		st, err := rhcos.FetchCoreOSBuild(ctx)
    52  		if err != nil {
    53  			return err
    54  		}
    55  		streamArch, err := st.GetArchitecture(archName)
    56  		if err != nil {
    57  			return err
    58  		}
    59  
    60  		// Check for CoreOS image URL override
    61  		if boi := config.Platform.BareMetal.BootstrapOSImage; boi != "" {
    62  			*i = BootstrapImage(boi)
    63  			return nil
    64  		}
    65  		// Baremetal IPI launches a local VM for the bootstrap node
    66  		// Hence requires the QEMU image to use the libvirt backend
    67  		if a, ok := streamArch.Artifacts["qemu"]; ok {
    68  			u, err := rhcos.FindArtifactURL(a)
    69  			if err != nil {
    70  				return err
    71  			}
    72  			*i = BootstrapImage(u)
    73  			return nil
    74  		}
    75  		return fmt.Errorf("%s: No qemu build found", st.FormatPrefix(archName))
    76  	default:
    77  		// other platforms use the same image for all nodes
    78  		*i = BootstrapImage(rhcosImage.ControlPlane)
    79  		return nil
    80  	}
    81  }