Skip to content

Commit d89a59f

Browse files
Merge pull request #2061 from hardys/issue_2037
Decouple bootstrap and cluster bootimages
2 parents 5e2ea73 + 44fea9e commit d89a59f

6 files changed

Lines changed: 1029 additions & 872 deletions

File tree

docs/design/resource_dep.svg

Lines changed: 918 additions & 865 deletions
Loading

pkg/asset/cluster/tfvars.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func (t *TerraformVariables) Dependencies() []asset.Asset {
7474
&installconfig.ClusterID{},
7575
&installconfig.InstallConfig{},
7676
new(rhcos.Image),
77+
new(rhcos.BootstrapImage),
7778
&bootstrap.Bootstrap{},
7879
&machine.Master{},
7980
&machines.Master{},
@@ -90,7 +91,8 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
9091
mastersAsset := &machines.Master{}
9192
workersAsset := &machines.Worker{}
9293
rhcosImage := new(rhcos.Image)
93-
parents.Get(clusterID, installConfig, bootstrapIgnAsset, masterIgnAsset, mastersAsset, workersAsset, rhcosImage)
94+
rhcosBootstrapImage := new(rhcos.BootstrapImage)
95+
parents.Get(clusterID, installConfig, bootstrapIgnAsset, masterIgnAsset, mastersAsset, workersAsset, rhcosImage, rhcosBootstrapImage)
9496

9597
platform := installConfig.Config.Platform.Name()
9698
switch platform {
@@ -263,7 +265,7 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
263265
data, err = baremetaltfvars.TFVars(
264266
installConfig.Config.Platform.BareMetal.LibvirtURI,
265267
installConfig.Config.Platform.BareMetal.IronicURI,
266-
string(*rhcosImage),
268+
string(*rhcosBootstrapImage),
267269
"baremetal",
268270
"provisioning",
269271
installConfig.Config.Platform.BareMetal.Hosts,

pkg/asset/rhcos/bootstrap_image.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
}

pkg/asset/rhcos/image.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/openshift/installer/pkg/asset"
1313
"github.com/openshift/installer/pkg/asset/installconfig"
1414
"github.com/openshift/installer/pkg/rhcos"
15+
"github.com/openshift/installer/pkg/types"
1516
"github.com/openshift/installer/pkg/types/aws"
1617
"github.com/openshift/installer/pkg/types/azure"
1718
"github.com/openshift/installer/pkg/types/baremetal"
@@ -52,7 +53,15 @@ func (i *Image) Generate(p asset.Parents) error {
5253
ic := &installconfig.InstallConfig{}
5354
p.Get(ic)
5455
config := ic.Config
56+
osimage, err := osImage(config)
57+
if err != nil {
58+
return err
59+
}
60+
*i = Image(osimage)
61+
return nil
62+
}
5563

64+
func osImage(config *types.InstallConfig) (string, error) {
5665
var osimage string
5766
var err error
5867
ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second)
@@ -73,14 +82,16 @@ func (i *Image) Generate(p asset.Parents) error {
7382
case azure.Name:
7483
osimage, err = rhcos.VHD(ctx)
7584
case baremetal.Name:
76-
osimage, err = rhcos.QEMU(ctx)
85+
// Note that baremetal IPI currently uses the OpenStack image
86+
// because this contains the necessary ironic config drive
87+
// ignition support, which isn't enabled in the UPI BM images
88+
osimage, err = rhcos.OpenStack(ctx)
7789
case none.Name, vsphere.Name:
7890
default:
79-
return errors.New("invalid Platform")
91+
return "", errors.New("invalid Platform")
8092
}
8193
if err != nil {
82-
return err
94+
return "", err
8395
}
84-
*i = Image(osimage)
85-
return nil
96+
return osimage, nil
8697
}

pkg/rhcos/builds.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ type metadata struct {
2727
Path string `json:"path"`
2828
SHA256 string `json:"sha256"`
2929
} `json:"qemu"`
30+
OpenStack struct {
31+
Path string `json:"path"`
32+
SHA256 string `json:"sha256"`
33+
} `json:"openstack"`
3034
} `json:"images"`
3135
OSTreeVersion string `json:"ostree-version"`
3236
}

pkg/rhcos/openstack.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package rhcos
2+
3+
import (
4+
"context"
5+
"net/url"
6+
7+
"github.com/pkg/errors"
8+
)
9+
10+
// OpenStack fetches the URL of the Red Hat Enterprise Linux CoreOS release,
11+
// for the openstack platform
12+
func OpenStack(ctx context.Context) (string, error) {
13+
meta, err := fetchRHCOSBuild(ctx)
14+
if err != nil {
15+
return "", errors.Wrap(err, "failed to fetch RHCOS metadata")
16+
}
17+
18+
base, err := url.Parse(meta.BaseURI)
19+
if err != nil {
20+
return "", err
21+
}
22+
23+
relOpenStack, err := url.Parse(meta.Images.OpenStack.Path)
24+
if err != nil {
25+
return "", err
26+
}
27+
28+
return base.ResolveReference(relOpenStack).String(), nil
29+
}

0 commit comments

Comments
 (0)