Skip to content

Commit

Permalink
asset: add rhcos Image asset to generate image location
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavdahiya committed Jan 11, 2019
1 parent 7182727 commit 8957997
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions pkg/asset/rhcos/image.go
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
}

0 comments on commit 8957997

Please sign in to comment.