-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.go
73 lines (63 loc) · 1.89 KB
/
image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Package rhcos contains assets for RHCOS.
package rhcos
import (
"context"
"os"
"time"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/rhcos"
"github.com/openshift/installer/pkg/types/aws"
"github.com/openshift/installer/pkg/types/libvirt"
"github.com/openshift/installer/pkg/types/none"
"github.com/openshift/installer/pkg/types/openstack"
"github.com/openshift/installer/pkg/types/vsphere"
)
// Image is location of RHCOS image.
// 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 string
var _ asset.Asset = (*Image)(nil)
// Name returns the human-friendly name of the asset.
func (i *Image) Name() string {
return "Image"
}
// Dependencies returns no dependencies.
func (i *Image) Dependencies() []asset.Asset {
return []asset.Asset{
&installconfig.InstallConfig{},
}
}
// Generate the RHCOS image location.
func (i *Image) Generate(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 = Image(oi)
return nil
}
ic := &installconfig.InstallConfig{}
p.Get(ic)
config := ic.Config
var osimage string
var err error
ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second)
defer cancel()
switch config.Platform.Name() {
case aws.Name:
osimage, err = rhcos.AMI(ctx, rhcos.DefaultChannel, config.Platform.AWS.Region)
case libvirt.Name:
osimage, err = rhcos.QEMU(ctx, rhcos.DefaultChannel)
case openstack.Name:
osimage = "rhcos"
case none.Name, vsphere.Name:
default:
return errors.New("invalid Platform")
}
if err != nil {
return err
}
*i = Image(osimage)
return nil
}