|
| 1 | +// Package rhcos contains assets for RHCOS. |
| 2 | +package rhcos |
| 3 | + |
| 4 | +import ( |
| 5 | + "context" |
| 6 | + "time" |
| 7 | + |
| 8 | + "github.com/openshift/installer/pkg/asset" |
| 9 | + "github.com/openshift/installer/pkg/asset/installconfig" |
| 10 | + "github.com/openshift/installer/pkg/rhcos" |
| 11 | + "github.com/openshift/installer/pkg/types/baremetal" |
| 12 | +) |
| 13 | + |
| 14 | +// BootstrapImage is location of the RHCOS image for the Bootstrap node |
| 15 | +// This stores the location of the image based on the platform. |
| 16 | +// eg. on AWS this contains ami-id, on Livirt this can be the URI for QEMU image etc. |
| 17 | +// Note that for most platforms this is the same as rhcos.Image |
| 18 | +type BootstrapImage string |
| 19 | + |
| 20 | +var _ asset.Asset = (*BootstrapImage)(nil) |
| 21 | + |
| 22 | +// Name returns the human-friendly name of the asset. |
| 23 | +func (i *BootstrapImage) Name() string { |
| 24 | + return "BootstrapImage" |
| 25 | +} |
| 26 | + |
| 27 | +// Dependencies returns no dependencies. |
| 28 | +func (i *BootstrapImage) Dependencies() []asset.Asset { |
| 29 | + return []asset.Asset{ |
| 30 | + &installconfig.InstallConfig{}, |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +// Generate the RHCOS Bootstrap image location. |
| 35 | +func (i *BootstrapImage) Generate(p asset.Parents) error { |
| 36 | + ic := &installconfig.InstallConfig{} |
| 37 | + p.Get(ic) |
| 38 | + config := ic.Config |
| 39 | + |
| 40 | + var osimage string |
| 41 | + var err error |
| 42 | + ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second) |
| 43 | + defer cancel() |
| 44 | + switch config.Platform.Name() { |
| 45 | + case baremetal.Name: |
| 46 | + // Baremetal IPI launches a local VM for the bootstrap node |
| 47 | + // Hence requires the QEMU image to use the libvirt backend |
| 48 | + osimage, err = rhcos.QEMU(ctx) |
| 49 | + default: |
| 50 | + // other platforms use the same image for all nodes |
| 51 | + osimage, err = osImage(config) |
| 52 | + } |
| 53 | + if err != nil { |
| 54 | + return err |
| 55 | + } |
| 56 | + *i = BootstrapImage(osimage) |
| 57 | + return nil |
| 58 | +} |
0 commit comments