From 6e8e9606fd4a5a34fee50fc0034ce93d76069c4b Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 28 Sep 2018 00:17:35 -0700 Subject: [PATCH 1/2] pkg/asset/installconfig: Pass platforms as JSON Instead of as an array of strings. This makes it much easier to add control over additional properties, because the consuming logic remains "just unpack the JSON into the appropriate structure". --- pkg/asset/installconfig/installconfig.go | 28 +++------ pkg/asset/installconfig/platform.go | 74 ++++++++++++++++++------ 2 files changed, 63 insertions(+), 39 deletions(-) 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..9a7f40b073f 100644 --- a/pkg/asset/installconfig/platform.go +++ b/pkg/asset/installconfig/platform.go @@ -1,6 +1,7 @@ package installconfig import ( + "encoding/json" "fmt" "net/url" "sort" @@ -9,6 +10,7 @@ import ( "github.com/AlecAivazis/survey" "github.com/openshift/installer/pkg/asset" + "github.com/openshift/installer/pkg/types" ) const ( @@ -41,6 +43,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 +121,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 +160,38 @@ 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 + 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 +217,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 } From 98a3531632f9fcab7f8ba44b61d2a8daf26fc327 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 28 Sep 2018 00:21:01 -0700 Subject: [PATCH 2/2] pkg/asset/installconfig: Add _CI_ONLY_STAY_AWAY_OPENSHIFT_INSTALL_AWS_USER_TAGS With a JSON string containing the intended values. This is not how we're going to expose this long-term, so I'm using an embarrassing name and not documenting the enviroment variable. But I want this so we can get back to tagging expirationData in CI, without waiting for asset state <-> disk (de)serialization. --- pkg/asset/installconfig/platform.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/asset/installconfig/platform.go b/pkg/asset/installconfig/platform.go index 9a7f40b073f..6144f26b5d8 100644 --- a/pkg/asset/installconfig/platform.go +++ b/pkg/asset/installconfig/platform.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/url" + "os" "sort" "strings" @@ -162,6 +163,12 @@ func (a *Platform) awsPlatform() (*asset.State, error) { } platform.Region = string(region.Contents[0].Data) + 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