-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
asset: add rhcos Image asset to generate image location
- Loading branch information
1 parent
7182727
commit 8957997
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// 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" | ||
) | ||
|
||
// 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: | ||
default: | ||
return errors.New("invalid Platform") | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
*i = Image(osimage) | ||
return nil | ||
} |