1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 15:47:14 +01:00

OpenStack: remove region from install config

This parameter is not used by the installer and completely ignored
during the installation, so it just confuses users and should be removed.

The real region value is taken from clouds.yaml file.
This commit is contained in:
Mike Fedosin
2019-09-09 13:02:40 +02:00
parent 3f34b38a1a
commit 3f2c3a0eba
19 changed files with 6 additions and 506 deletions

4
Gopkg.lock generated
View File

@@ -336,7 +336,7 @@
[[projects]]
branch = "master"
digest = "1:215e0c79e138993bdcc6914d5488284fd04c4b9ab2e15a6b432c49acbed62577"
digest = "1:cefed4accadc52d320ac8aed4fc0cd3abb3d9b01045ad42e7531e5e19774bf81"
name = "github.com/gophercloud/gophercloud"
packages = [
".",
@@ -349,7 +349,6 @@
"openstack/compute/v2/servers",
"openstack/identity/v2/tenants",
"openstack/identity/v2/tokens",
"openstack/identity/v3/regions",
"openstack/identity/v3/tokens",
"openstack/loadbalancer/v2/apiversions",
"openstack/loadbalancer/v2/l7policies",
@@ -1323,7 +1322,6 @@
"github.com/gophercloud/gophercloud/openstack/common/extensions",
"github.com/gophercloud/gophercloud/openstack/compute/v2/flavors",
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers",
"github.com/gophercloud/gophercloud/openstack/identity/v3/regions",
"github.com/gophercloud/gophercloud/openstack/identity/v3/tokens",
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/apiversions",
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers",

View File

@@ -289,11 +289,6 @@ variable "openstack_master_flavor_name" {
description = "Instance size for the master node(s). Example: `m1.medium`."
}
variable "openstack_region" {
type = string
description = "The target OpenStack region for the cluster."
}
variable "openstack_trunk_support" {
type = string

View File

@@ -10,7 +10,7 @@ Beyond the [platform-agnostic `install-config.yaml` properties](../customization
* `externalNetwork` (required string): The OpenStack external network name to be used for installation.
* `lbFloatingIP` (required string): Existing Floating IP to associate with the API load balancer.
* `octaviaSupport` (optional string): Whether OpenStack supports Octavia (`1` for true or `0` for false)
* `region` (required string): The OpenStack region where the cluster will be created.
* `region` (deprecated string): The OpenStack region where the cluster will be created. Currently this value is not used by the installer.
* `trunkSupport` (optional string): Whether OpenStack ports can be trunked (`1` for true or `0` for false)
## Machine pools

View File

@@ -10,8 +10,7 @@ import (
// Metadata converts an install configuration to OpenStack metadata.
func Metadata(infraID string, config *types.InstallConfig) *openstack.Metadata {
return &openstack.Metadata{
Region: config.Platform.OpenStack.Region,
Cloud: config.Platform.OpenStack.Cloud,
Cloud: config.Platform.OpenStack.Cloud,
Identifier: map[string]string{
"openshiftClusterID": infraID,
},

View File

@@ -262,7 +262,6 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
data, err = openstacktfvars.TFVars(
masters[0].Spec.ProviderSpec.Value.Object.(*openstackprovider.OpenstackProviderSpec),
installConfig.Config.Platform.OpenStack.Cloud,
installConfig.Config.Platform.OpenStack.Region,
installConfig.Config.Platform.OpenStack.ExternalNetwork,
installConfig.Config.Platform.OpenStack.LbFloatingIP,
apiVIP.String(),

View File

@@ -44,33 +44,6 @@ func Platform() (*openstack.Platform, error) {
return nil, err
}
regionNames, err := validValuesFetcher.GetRegionNames(cloud)
if err != nil {
return nil, err
}
sort.Strings(regionNames)
var region string
err = survey.Ask([]*survey.Question{
{
Prompt: &survey.Select{
Message: "Region",
Help: "The OpenStack region to be used for installation.",
Options: regionNames,
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
value := ans.(string)
i := sort.SearchStrings(regionNames, value)
if i == len(regionNames) || regionNames[i] != value {
return errors.Errorf("invalid region name %q, should be one of %+v", value, strings.Join(regionNames, ", "))
}
return nil
}),
},
}, &region)
if err != nil {
return nil, err
}
networkNames, err := validValuesFetcher.GetNetworkNames(cloud)
if err != nil {
return nil, err
@@ -179,7 +152,6 @@ func Platform() (*openstack.Platform, error) {
}
return &openstack.Platform{
Region: region,
Cloud: cloud,
ExternalNetwork: extNet,
FlavorName: flavor,

View File

@@ -8,7 +8,6 @@ import (
)
type config struct {
Region string `json:"openstack_region,omitempty"`
BaseImage string `json:"openstack_base_image,omitempty"`
ExternalNetwork string `json:"openstack_external_network,omitempty"`
Cloud string `json:"openstack_credentials_cloud,omitempty"`
@@ -22,9 +21,8 @@ type config struct {
}
// TFVars generates OpenStack-specific Terraform variables.
func TFVars(masterConfig *v1alpha1.OpenstackProviderSpec, cloud string, region string, externalNetwork string, lbFloatingIP string, apiVIP string, dnsVIP string, ingressVIP string, trunkSupport string, octaviaSupport string) ([]byte, error) {
func TFVars(masterConfig *v1alpha1.OpenstackProviderSpec, cloud string, externalNetwork string, lbFloatingIP string, apiVIP string, dnsVIP string, ingressVIP string, trunkSupport string, octaviaSupport string) ([]byte, error) {
cfg := &config{
Region: region,
BaseImage: masterConfig.Image,
ExternalNetwork: externalNetwork,
Cloud: cloud,

View File

@@ -2,8 +2,7 @@ package openstack
// Metadata contains OpenStack metadata (e.g. for uninstalling the cluster).
type Metadata struct {
Region string `json:"region"`
Cloud string `json:"cloud"`
Cloud string `json:"cloud"`
// Most OpenStack resources are tagged with these tags as identifier.
Identifier map[string]string `json:"identifier"`
}

View File

@@ -4,6 +4,7 @@ package openstack
// machinesets use.
type Platform struct {
// Region specifies the OpenStack region where the cluster will be created.
// Deprecated: this value is not used by the installer.
Region string `json:"region"`
// DefaultMachinePlatform is the default configuration used when

View File

@@ -47,21 +47,6 @@ func (mr *MockValidValuesFetcherMockRecorder) GetCloudNames() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCloudNames", reflect.TypeOf((*MockValidValuesFetcher)(nil).GetCloudNames))
}
// GetRegionNames mocks base method
func (m *MockValidValuesFetcher) GetRegionNames(cloud string) ([]string, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetRegionNames", cloud)
ret0, _ := ret[0].([]string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetRegionNames indicates an expected call of GetRegionNames
func (mr *MockValidValuesFetcherMockRecorder) GetRegionNames(cloud interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRegionNames", reflect.TypeOf((*MockValidValuesFetcher)(nil).GetRegionNames), cloud)
}
// GetNetworkNames mocks base method
func (m *MockValidValuesFetcher) GetNetworkNames(cloud string) ([]string, error) {
m.ctrl.T.Helper()

View File

@@ -18,12 +18,6 @@ func ValidatePlatform(p *openstack.Platform, n *types.Networking, fldPath *field
} else if !isValidValue(p.Cloud, validClouds) {
allErrs = append(allErrs, field.NotSupported(fldPath.Child("cloud"), p.Cloud, validClouds))
} else {
validRegions, err := fetcher.GetRegionNames(p.Cloud)
if err != nil {
allErrs = append(allErrs, field.InternalError(fldPath.Child("region"), errors.New("could not retrieve valid regions")))
} else if !isValidValue(p.Region, validRegions) {
allErrs = append(allErrs, field.NotSupported(fldPath.Child("region"), p.Region, validRegions))
}
validNetworks, err := fetcher.GetNetworkNames(p.Cloud)
if err != nil {
allErrs = append(allErrs, field.InternalError(fldPath.Child("externalNetwork"), errors.New("could not retrieve valid networks")))

View File

@@ -15,7 +15,6 @@ import (
func validPlatform() *openstack.Platform {
return &openstack.Platform{
Region: "test-region",
Cloud: "test-cloud",
ExternalNetwork: "test-network",
FlavorName: "test-flavor",
@@ -27,7 +26,6 @@ func TestValidatePlatform(t *testing.T) {
name string
platform *openstack.Platform
noClouds bool
noRegions bool
noNetworks bool
noFlavors bool
noNetExts bool
@@ -39,15 +37,6 @@ func TestValidatePlatform(t *testing.T) {
platform: validPlatform(),
valid: true,
},
{
name: "missing region",
platform: func() *openstack.Platform {
p := validPlatform()
p.Region = ""
return p
}(),
valid: false,
},
{
name: "missing cloud",
platform: func() *openstack.Platform {
@@ -81,12 +70,6 @@ func TestValidatePlatform(t *testing.T) {
noClouds: true,
valid: false,
},
{
name: "regions fetch failure",
platform: validPlatform(),
noRegions: true,
valid: false,
},
{
name: "networks fetch failure",
platform: validPlatform(),
@@ -125,15 +108,6 @@ func TestValidatePlatform(t *testing.T) {
fetcher.EXPECT().GetCloudNames().
Return([]string{"test-cloud"}, nil)
}
if tc.noRegions {
fetcher.EXPECT().GetRegionNames(tc.platform.Cloud).
Return(nil, errors.New("no regions")).
MaxTimes(1)
} else {
fetcher.EXPECT().GetRegionNames(tc.platform.Cloud).
Return([]string{"test-region"}, nil).
MaxTimes(1)
}
if tc.noNetworks {
fetcher.EXPECT().GetNetworkNames(tc.platform.Cloud).
Return(nil, errors.New("no networks")).

View File

@@ -5,7 +5,6 @@ import (
"github.com/gophercloud/gophercloud/openstack/common/extensions"
"github.com/gophercloud/gophercloud/openstack/compute/v2/flavors"
"github.com/gophercloud/gophercloud/openstack/identity/v3/regions"
"github.com/gophercloud/gophercloud/openstack/identity/v3/tokens"
netext "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
@@ -35,36 +34,6 @@ func (f realValidValuesFetcher) GetCloudNames() ([]string, error) {
return cloudNames, nil
}
// GetRegionNames gets the valid region names.
func (f realValidValuesFetcher) GetRegionNames(cloud string) ([]string, error) {
opts := &clientconfig.ClientOpts{
Cloud: cloud,
}
conn, err := clientconfig.NewServiceClient("identity", opts)
if err != nil {
return nil, err
}
listOpts := regions.ListOpts{}
allPages, err := regions.List(conn, listOpts).AllPages()
if err != nil {
return nil, err
}
allRegions, err := regions.ExtractRegions(allPages)
if err != nil {
return nil, err
}
regionNames := make([]string, len(allRegions))
for x, region := range allRegions {
regionNames[x] = region.ID
}
return regionNames, nil
}
// GetNetworkNames gets the valid network names.
func (f realValidValuesFetcher) GetNetworkNames(cloud string) ([]string, error) {
opts := &clientconfig.ClientOpts{

View File

@@ -6,8 +6,6 @@ package validation
type ValidValuesFetcher interface {
// GetCloudNames gets the valid cloud names.
GetCloudNames() ([]string, error)
// GetRegionNames gets the valid region names.
GetRegionNames(cloud string) ([]string, error)
// GetNetworkNames gets the valid network names.
GetNetworkNames(cloud string) ([]string, error)
// GetFlavorNames gets the valid flavor names.

View File

@@ -106,7 +106,6 @@ func validBareMetalPlatform() *baremetal.Platform {
func validOpenStackPlatform() *openstack.Platform {
return &openstack.Platform{
Region: "test-region",
Cloud: "test-cloud",
ExternalNetwork: "test-network",
FlavorName: "test-flavor",
@@ -709,7 +708,6 @@ func TestValidateInstallConfig(t *testing.T) {
fetcher := mock.NewMockValidValuesFetcher(mockCtrl)
fetcher.EXPECT().GetCloudNames().Return([]string{"test-cloud"}, nil).AnyTimes()
fetcher.EXPECT().GetRegionNames(gomock.Any()).Return([]string{"test-region"}, nil).AnyTimes()
fetcher.EXPECT().GetNetworkNames(gomock.Any()).Return([]string{"test-network"}, nil).AnyTimes()
fetcher.EXPECT().GetFlavorNames(gomock.Any()).Return([]string{"test-flavor"}, nil).AnyTimes()
fetcher.EXPECT().GetNetworkExtensionsAliases(gomock.Any()).Return([]string{"trunk"}, nil).AnyTimes()

View File

@@ -1,63 +0,0 @@
/*
Package regions manages and retrieves Regions in the OpenStack Identity Service.
Example to List Regions
listOpts := regions.ListOpts{
ParentRegionID: "RegionOne",
}
allPages, err := regions.List(identityClient, listOpts).AllPages()
if err != nil {
panic(err)
}
allRegions, err := regions.ExtractRegions(allPages)
if err != nil {
panic(err)
}
for _, region := range allRegions {
fmt.Printf("%+v\n", region)
}
Example to Create a Region
createOpts := regions.CreateOpts{
ID: "TestRegion",
Description: "Region for testing"
Extra: map[string]interface{}{
"email": "testregionsupport@example.com",
}
}
region, err := regions.Create(identityClient, createOpts).Extract()
if err != nil {
panic(err)
}
Example to Update a Region
regionID := "TestRegion"
// There is currently a bug in Keystone where updating the optional Extras
// attributes set in regions.Create is not supported, see:
// https://bugs.launchpad.net/keystone/+bug/1729933
updateOpts := regions.UpdateOpts{
Description: "Updated Description for region",
}
region, err := regions.Update(identityClient, regionID, updateOpts).Extract()
if err != nil {
panic(err)
}
Example to Delete a Region
regionID := "TestRegion"
err := regions.Delete(identityClient, regionID).ExtractErr()
if err != nil {
panic(err)
}
*/
package regions

View File

@@ -1,164 +0,0 @@
package regions
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// ListOptsBuilder allows extensions to add additional parameters to
// the List request
type ListOptsBuilder interface {
ToRegionListQuery() (string, error)
}
// ListOpts provides options to filter the List results.
type ListOpts struct {
// ParentRegionID filters the response by a parent region ID.
ParentRegionID string `q:"parent_region_id"`
}
// ToRegionListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToRegionListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
return q.String(), err
}
// List enumerates the Regions to which the current token has access.
func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := listURL(client)
if opts != nil {
query, err := opts.ToRegionListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
return RegionPage{pagination.LinkedPageBase{PageResult: r}}
})
}
// Get retrieves details on a single region, by ID.
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
_, r.Err = client.Get(getURL(client, id), &r.Body, nil)
return
}
// CreateOptsBuilder allows extensions to add additional parameters to
// the Create request.
type CreateOptsBuilder interface {
ToRegionCreateMap() (map[string]interface{}, error)
}
// CreateOpts provides options used to create a region.
type CreateOpts struct {
// ID is the ID of the new region.
ID string `json:"id,omitempty"`
// Description is a description of the region.
Description string `json:"description,omitempty"`
// ParentRegionID is the ID of the parent the region to add this region under.
ParentRegionID string `json:"parent_region_id,omitempty"`
// Extra is free-form extra key/value pairs to describe the region.
Extra map[string]interface{} `json:"-"`
}
// ToRegionCreateMap formats a CreateOpts into a create request.
func (opts CreateOpts) ToRegionCreateMap() (map[string]interface{}, error) {
b, err := gophercloud.BuildRequestBody(opts, "region")
if err != nil {
return nil, err
}
if opts.Extra != nil {
if v, ok := b["region"].(map[string]interface{}); ok {
for key, value := range opts.Extra {
v[key] = value
}
}
}
return b, nil
}
// Create creates a new Region.
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToRegionCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(createURL(client), &b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{201},
})
return
}
// UpdateOptsBuilder allows extensions to add additional parameters to
// the Update request.
type UpdateOptsBuilder interface {
ToRegionUpdateMap() (map[string]interface{}, error)
}
// UpdateOpts provides options for updating a region.
type UpdateOpts struct {
// Description is a description of the region.
Description *string `json:"description,omitempty"`
// ParentRegionID is the ID of the parent region.
ParentRegionID string `json:"parent_region_id,omitempty"`
/*
// Due to a bug in Keystone, the Extra column of the Region table
// is not updatable, see: https://bugs.launchpad.net/keystone/+bug/1729933
// The following lines should be uncommented once the fix is merged.
// Extra is free-form extra key/value pairs to describe the region.
Extra map[string]interface{} `json:"-"`
*/
}
// ToRegionUpdateMap formats a UpdateOpts into an update request.
func (opts UpdateOpts) ToRegionUpdateMap() (map[string]interface{}, error) {
b, err := gophercloud.BuildRequestBody(opts, "region")
if err != nil {
return nil, err
}
/*
// Due to a bug in Keystone, the Extra column of the Region table
// is not updatable, see: https://bugs.launchpad.net/keystone/+bug/1729933
// The following lines should be uncommented once the fix is merged.
if opts.Extra != nil {
if v, ok := b["region"].(map[string]interface{}); ok {
for key, value := range opts.Extra {
v[key] = value
}
}
}
*/
return b, nil
}
// Update updates an existing Region.
func Update(client *gophercloud.ServiceClient, regionID string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToRegionUpdateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Patch(updateURL(client, regionID), &b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
return
}
// Delete deletes a region.
func Delete(client *gophercloud.ServiceClient, regionID string) (r DeleteResult) {
_, r.Err = client.Delete(deleteURL(client, regionID), nil)
return
}

View File

@@ -1,129 +0,0 @@
package regions
import (
"encoding/json"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/internal"
"github.com/gophercloud/gophercloud/pagination"
)
// Region helps manage related users.
type Region struct {
// Description describes the region purpose.
Description string `json:"description"`
// ID is the unique ID of the region.
ID string `json:"id"`
// Extra is a collection of miscellaneous key/values.
Extra map[string]interface{} `json:"-"`
// Links contains referencing links to the region.
Links map[string]interface{} `json:"links"`
// ParentRegionID is the ID of the parent region.
ParentRegionID string `json:"parent_region_id"`
}
func (r *Region) UnmarshalJSON(b []byte) error {
type tmp Region
var s struct {
tmp
Extra map[string]interface{} `json:"extra"`
}
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*r = Region(s.tmp)
// Collect other fields and bundle them into Extra
// but only if a field titled "extra" wasn't sent.
if s.Extra != nil {
r.Extra = s.Extra
} else {
var result interface{}
err := json.Unmarshal(b, &result)
if err != nil {
return err
}
if resultMap, ok := result.(map[string]interface{}); ok {
r.Extra = internal.RemainingKeys(Region{}, resultMap)
}
}
return err
}
type regionResult struct {
gophercloud.Result
}
// GetResult is the response from a Get operation. Call its Extract method
// to interpret it as a Region.
type GetResult struct {
regionResult
}
// CreateResult is the response from a Create operation. Call its Extract method
// to interpret it as a Region.
type CreateResult struct {
regionResult
}
// UpdateResult is the response from an Update operation. Call its Extract
// method to interpret it as a Region.
type UpdateResult struct {
regionResult
}
// DeleteResult is the response from a Delete operation. Call its ExtractErr to
// determine if the request succeeded or failed.
type DeleteResult struct {
gophercloud.ErrResult
}
// RegionPage is a single page of Region results.
type RegionPage struct {
pagination.LinkedPageBase
}
// IsEmpty determines whether or not a page of Regions contains any results.
func (r RegionPage) IsEmpty() (bool, error) {
regions, err := ExtractRegions(r)
return len(regions) == 0, err
}
// NextPageURL extracts the "next" link from the links section of the result.
func (r RegionPage) NextPageURL() (string, error) {
var s struct {
Links struct {
Next string `json:"next"`
Previous string `json:"previous"`
} `json:"links"`
}
err := r.ExtractInto(&s)
if err != nil {
return "", err
}
return s.Links.Next, err
}
// ExtractRegions returns a slice of Regions contained in a single page of results.
func ExtractRegions(r pagination.Page) ([]Region, error) {
var s struct {
Regions []Region `json:"regions"`
}
err := (r.(RegionPage)).ExtractInto(&s)
return s.Regions, err
}
// Extract interprets any region results as a Region.
func (r regionResult) Extract() (*Region, error) {
var s struct {
Region *Region `json:"region"`
}
err := r.ExtractInto(&s)
return s.Region, err
}

View File

@@ -1,23 +0,0 @@
package regions
import "github.com/gophercloud/gophercloud"
func listURL(client *gophercloud.ServiceClient) string {
return client.ServiceURL("regions")
}
func getURL(client *gophercloud.ServiceClient, regionID string) string {
return client.ServiceURL("regions", regionID)
}
func createURL(client *gophercloud.ServiceClient) string {
return client.ServiceURL("regions")
}
func updateURL(client *gophercloud.ServiceClient, regionID string) string {
return client.ServiceURL("regions", regionID)
}
func deleteURL(client *gophercloud.ServiceClient, regionID string) string {
return client.ServiceURL("regions", regionID)
}