diff --git a/pkg/asset/installconfig/installconfig.go b/pkg/asset/installconfig/installconfig.go index 256991ae50a..2b6e4bc88d7 100644 --- a/pkg/asset/installconfig/installconfig.go +++ b/pkg/asset/installconfig/installconfig.go @@ -1,6 +1,7 @@ package installconfig import ( + "encoding/json" "fmt" "net" @@ -17,11 +18,6 @@ import ( var ( defaultServiceCIDR = parseCIDR("10.3.0.0/16") defaultPodCIDR = parseCIDR("10.2.0.0/16") - defaultVPCCIDR = "10.0.0.0/16" - - defaultLibvirtNetworkIfName = "tt0" - defaultLibvirtNetworkIPRange = "192.168.124.0/24" - defaultLibvirtImageURL = "http://aos-ostree.rhev-ci-vms.eng.rdu2.redhat.com/rhcos/images/cloud/latest/rhcos-qemu.qcow2.gz" ) // installConfig generates the install-config.yml file. @@ -86,11 +82,10 @@ func (a *installConfig) Generate(dependencies map[asset.Asset]*asset.State) (*as platform := string(platformState.Contents[0].Data) switch platform { case AWSPlatformType: - region := string(platformState.Contents[1].Data) - installConfig.AWS = &types.AWSPlatform{ - Region: region, - VPCCIDRBlock: defaultVPCCIDR, + if err := json.Unmarshal(platformState.Contents[1].Data, &installConfig.AWS); err != nil { + return nil, err } + installConfig.Machines = []types.MachinePool{ { Name: "master", @@ -102,19 +97,10 @@ func (a *installConfig) Generate(dependencies map[asset.Asset]*asset.State) (*as }, } case LibvirtPlatformType: - uri := string(platformState.Contents[1].Data) - - installConfig.Libvirt = &types.LibvirtPlatform{ - URI: uri, - Network: types.LibvirtNetwork{ - Name: clusterName, - IfName: defaultLibvirtNetworkIfName, - IPRange: defaultLibvirtNetworkIPRange, - }, - DefaultMachinePlatform: &types.LibvirtMachinePoolPlatform{ - Image: defaultLibvirtImageURL, - }, + if err := json.Unmarshal(platformState.Contents[1].Data, &installConfig.Libvirt); err != nil { + return nil, err } + installConfig.Libvirt.Network.Name = clusterName installConfig.Machines = []types.MachinePool{ { Name: "master", diff --git a/pkg/asset/installconfig/platform.go b/pkg/asset/installconfig/platform.go index 9901324c6b0..6144f26b5d8 100644 --- a/pkg/asset/installconfig/platform.go +++ b/pkg/asset/installconfig/platform.go @@ -1,14 +1,17 @@ package installconfig import ( + "encoding/json" "fmt" "net/url" + "os" "sort" "strings" "github.com/AlecAivazis/survey" "github.com/openshift/installer/pkg/asset" + "github.com/openshift/installer/pkg/types" ) const ( @@ -41,6 +44,12 @@ var ( "us-west-1": "N. California", "us-west-2": "Oregon", } + + defaultVPCCIDR = "10.0.0.0/16" + + defaultLibvirtNetworkIfName = "tt0" + defaultLibvirtNetworkIPRange = "192.168.124.0/24" + defaultLibvirtImageURL = "http://aos-ostree.rhev-ci-vms.eng.rdu2.redhat.com/rhcos/images/cloud/latest/rhcos-qemu.qcow2.gz" ) // Platform is an asset that queries the user for the platform on which to install @@ -113,6 +122,10 @@ func (a *Platform) queryUserForPlatform() (string, error) { } func (a *Platform) awsPlatform() (*asset.State, error) { + platform := &types.AWSPlatform{ + VPCCIDRBlock: defaultVPCCIDR, + } + longRegions := make([]string, 0, len(validAWSRegions)) shortRegions := make([]string, 0, len(validAWSRegions)) for id, location := range validAWSRegions { @@ -148,14 +161,44 @@ func (a *Platform) awsPlatform() (*asset.State, error) { if err != nil { return nil, err } + platform.Region = string(region.Contents[0].Data) - return assetStateForStringContents( - AWSPlatformType, - string(region.Contents[0].Data), - ), nil + if value, ok := os.LookupEnv("_CI_ONLY_STAY_AWAY_OPENSHIFT_INSTALL_AWS_USER_TAGS"); ok { + if err := json.Unmarshal([]byte(value), &platform.UserTags); err != nil { + return nil, fmt.Errorf("_CI_ONLY_STAY_AWAY_OPENSHIFT_INSTALL_AWS_USER_TAGS contains invalid JSON: %s (%v)", value, err) + } + } + + data, err := json.Marshal(platform) + if err != nil { + return nil, err + } + + return &asset.State{ + Contents: []asset.Content{ + { + Name: "platform", + Data: []byte(AWSPlatformType), + }, + { + Name: "platform.json", + Data: data, + }, + }, + }, nil } func (a *Platform) libvirtPlatform() (*asset.State, error) { + platform := &types.LibvirtPlatform{ + Network: types.LibvirtNetwork{ + IfName: defaultLibvirtNetworkIfName, + IPRange: defaultLibvirtNetworkIPRange, + }, + DefaultMachinePlatform: &types.LibvirtMachinePoolPlatform{ + Image: defaultLibvirtImageURL, + }, + } + prompt := asset.UserProvided{ Question: &survey.Question{ Prompt: &survey.Input{ @@ -181,21 +224,23 @@ func (a *Platform) libvirtPlatform() (*asset.State, error) { if err != nil { return nil, err } + platform.URI = string(uri.Contents[0].Data) - return assetStateForStringContents( - LibvirtPlatformType, - string(uri.Contents[0].Data), - ), nil -} - -func assetStateForStringContents(s ...string) *asset.State { - c := make([]asset.Content, len(s)) - for i, d := range s { - c[i] = asset.Content{ - Data: []byte(d), - } + data, err := json.Marshal(platform) + if err != nil { + return nil, err } + return &asset.State{ - Contents: c, - } + Contents: []asset.Content{ + { + Name: "platform-type", + Data: []byte(LibvirtPlatformType), + }, + { + Name: "platform.json", + Data: data, + }, + }, + }, nil }