Skip to content
This repository has been archived by the owner on Apr 7, 2020. It is now read-only.

Allow region-ized fields in OpenStack CloudProfileConfig #482

Merged
merged 1 commit into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 0 additions & 70 deletions controllers/provider-azure/pkg/internal/scheme.go

This file was deleted.

18 changes: 17 additions & 1 deletion controllers/provider-openstack/docs/usage-as-operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,39 @@ machineImages:
- name: coreos
version: 2135.6.0
image: coreos-2135.6.0
keystoneURL: https://url-to-keystone/v3/
# keystoneURL: https://url-to-keystone/v3/
# keystoneURLs:
# - region: europe
# url: https://europe.example.com/v3/
# - region: asia
# url: https://asia.example.com/v3/
# dnsServers:
# - 10.10.10.11
# - 10.10.10.12
# requestTimeout: 60s
constraints:
floatingPools:
- name: fp-pool-1
# region: europe
# loadBalancerClasses:
# - name: lb-class-1
# floatingSubnetID: "1234"
# floatingNetworkID: "4567"
# subnetID: "7890"
loadBalancerProviders:
- name: haproxy
# region: europe
# - name: f5
# region: asia
```

Please note that it is possible to configure a region mapping for keystone URLs, floating pools, and load balancer providers.
The default behavior is that, if found, the regional entry is taken.
If no entry for the given region exists then the fallback value is the first entry in the list without a `region` field (or the `keystoneURL` value for the keystone URLs).
Some OpenStack environments don't need these regional mappings, hence, the `region` and `keystoneURLs` fields are optional.
If your OpenStack environment only has regional values and it doesn't make sense to provide a (non-regional) fallback then simply
omit `keystoneURL` and always specify `region`.

## Example `CloudProfile` manifest

Please find below an example `CloudProfile` manifest:
Expand Down
80 changes: 80 additions & 0 deletions controllers/provider-openstack/hack/api-reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,26 @@ string
</em>
</td>
<td>
<em>(Optional)</em>
<p>KeyStoneURL is the URL for auth{n,z} in OpenStack (pointing to KeyStone).</p>
</td>
</tr>
<tr>
<td>
<code>keystoneURLs</code></br>
<em>
<a href="#openstack.provider.extensions.gardener.cloud/v1alpha1.KeyStoneURL">
[]KeyStoneURL
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>KeyStoneURLs is a region-URL mapping for auth{n,z} in OpenStack (pointing to KeyStone).</p>
</td>
</tr>
<tr>
<td>
<code>machineImages</code></br>
<em>
<a href="#openstack.provider.extensions.gardener.cloud/v1alpha1.MachineImages">
Expand Down Expand Up @@ -420,6 +435,18 @@ string
</tr>
<tr>
<td>
<code>region</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Region is the region name.</p>
</td>
</tr>
<tr>
<td>
<code>loadBalancerClasses</code></br>
<em>
<a href="#openstack.provider.extensions.gardener.cloud/v1alpha1.LoadBalancerClass">
Expand Down Expand Up @@ -529,6 +556,47 @@ NodeStatus
</tr>
</tbody>
</table>
<h3 id="openstack.provider.extensions.gardener.cloud/v1alpha1.KeyStoneURL">KeyStoneURL
</h3>
<p>
(<em>Appears on:</em>
<a href="#openstack.provider.extensions.gardener.cloud/v1alpha1.CloudProfileConfig">CloudProfileConfig</a>)
</p>
<p>
<p>KeyStoneURL is a region-URL mapping for auth{n,z} in OpenStack (pointing to KeyStone).</p>
</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>region</code></br>
<em>
string
</em>
</td>
<td>
<p>Region is the name of the region.</p>
</td>
</tr>
<tr>
<td>
<code>url</code></br>
<em>
string
</em>
</td>
<td>
<p>URL is the keystone URL.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="openstack.provider.extensions.gardener.cloud/v1alpha1.LoadBalancerClass">LoadBalancerClass
</h3>
<p>
Expand Down Expand Up @@ -625,6 +693,18 @@ string
<p>Name is the name of the load balancer provider.</p>
</td>
</tr>
<tr>
<td>
<code>region</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Region is the region name.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="openstack.provider.extensions.gardener.cloud/v1alpha1.MachineImage">MachineImage
Expand Down
17 changes: 17 additions & 0 deletions controllers/provider-openstack/pkg/apis/openstack/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,20 @@ func FindImageFromCloudProfile(cloudProfileConfig *api.CloudProfileConfig, image

return nil, fmt.Errorf("could not find an image for name %q in version %q for region %q", imageName, imageVersion, regionName)
}

// FindKeyStoneURL takes a list of keystone URLs and tries to find the first entry
// whose region matches with the given region. If no such entry is found then it tries to use the non-regional
// keystone URL. If this is not specified then an error will be returned.
func FindKeyStoneURL(keyStoneURLs []api.KeyStoneURL, keystoneURL, region string) (string, error) {
for _, keyStoneURL := range keyStoneURLs {
if keyStoneURL.Region == region {
return keyStoneURL.URL, nil
}
}

if len(keystoneURL) > 0 {
return keystoneURL, nil
}

return "", fmt.Errorf("cannot find keystone URL for region %q", region)
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,26 @@ var _ = Describe("Helper", func() {
Entry("profile region entry", makeProfileRegionMachineImages("ubuntu", "1", "image-1234", regionName), "ubuntu", "1", regionName, "image-1234"),
Entry("profile region not found", makeProfileRegionMachineImages("ubuntu", "1", "image-1234", regionName+"x"), "ubuntu", "1", regionName, ""),
)

DescribeTable("#FindKeyStoneURL",
func(keyStoneURLs []api.KeyStoneURL, keystoneURL, region, expectedKeyStoneURL string, expectErr bool) {
result, err := FindKeyStoneURL(keyStoneURLs, keystoneURL, region)

if !expectErr {
Expect(result).To(Equal(expectedKeyStoneURL))
Expect(err).NotTo(HaveOccurred())
} else {
Expect(result).To(BeEmpty())
Expect(err).To(HaveOccurred())
}
},

Entry("list is nil", nil, "default", "europe", "default", false),
Entry("empty list", []api.KeyStoneURL{}, "default", "europe", "default", false),
Entry("region not found", []api.KeyStoneURL{{URL: "bar", Region: "asia"}}, "default", "europe", "default", false),
Entry("region exists", []api.KeyStoneURL{{URL: "bar", Region: "europe"}}, "default", "europe", "bar", false),
Entry("no default URL", []api.KeyStoneURL{{URL: "bar", Region: "europe"}}, "", "asia", "", true),
)
})

func makeProfileMachineImages(name, version, image string) []api.MachineImages {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type CloudProfileConfig struct {
DHCPDomain *string
// KeyStoneURL is the URL for auth{n,z} in OpenStack (pointing to KeyStone).
KeyStoneURL string
// KeyStoneURLs is a region-URL mapping for auth{n,z} in OpenStack (pointing to KeyStone).
KeyStoneURLs []KeyStoneURL
// MachineImages is the list of machine images that are understood by the controller. It maps
// logical names and versions to provider-specific identifiers.
MachineImages []MachineImages
Expand All @@ -52,10 +54,20 @@ type Constraints struct {
type FloatingPool struct {
// Name is the name of the floating pool.
Name string
// Region is the region name.
Region *string
// LoadBalancerClasses contains a list of supported labeled load balancer network settings.
LoadBalancerClasses []LoadBalancerClass
}

// KeyStoneURL is a region-URL mapping for auth{n,z} in OpenStack (pointing to KeyStone).
type KeyStoneURL struct {
// Region is the name of the region.
Region string
// URL is the keystone URL.
URL string
}

// LoadBalancerClass defines a restricted network setting for generic LoadBalancer classes.
type LoadBalancerClass struct {
// Name is the name of the LB class
Expand All @@ -73,6 +85,8 @@ type LoadBalancerClass struct {
type LoadBalancerProvider struct {
// Name is the name of the load balancer provider.
Name string
// Region is the region name.
Region *string
}

// MachineImages is a mapping from logical names and versions to provider-specific identifiers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ type CloudProfileConfig struct {
// +optional
DHCPDomain *string `json:"dhcpDomain,omitempty"`
// KeyStoneURL is the URL for auth{n,z} in OpenStack (pointing to KeyStone).
KeyStoneURL string `json:"keystoneURL"`
// +optional
KeyStoneURL string `json:"keystoneURL,omitempty"`
// KeyStoneURLs is a region-URL mapping for auth{n,z} in OpenStack (pointing to KeyStone).
// +optional
KeyStoneURLs []KeyStoneURL `json:"keystoneURLs,omitempty"`
// MachineImages is the list of machine images that are understood by the controller. It maps
// logical names and versions to provider-specific identifiers.
MachineImages []MachineImages `json:"machineImages"`
Expand All @@ -56,11 +60,22 @@ type Constraints struct {
type FloatingPool struct {
// Name is the name of the floating pool.
Name string `json:"name"`
// Region is the region name.
// +optional
Region *string `json:"region,omitempty"`
// LoadBalancerClasses contains a list of supported labeled load balancer network settings.
// +optional
LoadBalancerClasses []LoadBalancerClass `json:"loadBalancerClasses,omitempty"`
}

// KeyStoneURL is a region-URL mapping for auth{n,z} in OpenStack (pointing to KeyStone).
type KeyStoneURL struct {
// Region is the name of the region.
Region string `json:"region"`
// URL is the keystone URL.
URL string `json:"url"`
}

// LoadBalancerClass defines a restricted network setting for generic LoadBalancer classes.
type LoadBalancerClass struct {
// Name is the name of the LB class
Expand All @@ -81,6 +96,9 @@ type LoadBalancerClass struct {
type LoadBalancerProvider struct {
// Name is the name of the load balancer provider.
Name string `json:"name"`
// Region is the region name.
// +optional
Region *string `json:"region,omitempty"`
}

// MachineImages is a mapping from logical names and versions to provider-specific identifiers.
Expand Down
Loading