Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useSNAT option to CloudProfile #165

Merged
merged 1 commit into from
Oct 22, 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
3 changes: 3 additions & 0 deletions charts/internal/openstack-infra/templates/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ resource "openstack_networking_router_v2" "router" {
name = "{{ required "clusterName is required" .Values.clusterName }}"
region = "{{ required "openstack.region is required" .Values.openstack.region }}"
external_network_id = data.openstack_networking_network_v2.fip.id
{{ if .Values.router.enableSNAT -}}
enable_snat = true
{{- end }}
{{ if .Values.router.floatingPoolSubnetName -}}
external_fixed_ip {
subnet_id = data.openstack_networking_subnet_v2.fip_subnet.id
Expand Down
1 change: 1 addition & 0 deletions charts/internal/openstack-infra/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sshPublicKey: sshkey-12345

router:
id: openstack_networking_router_v2.router.id
# enableSNAT: true
# floatingPoolSubnetName: my-fip-subnet-name

dnsServers:
Expand Down
3 changes: 3 additions & 0 deletions docs/usage-as-operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ machineImages:
# - 10.10.10.12
# requestTimeout: 60s
# useOctavia: true
# useSNAT: true
timuthy marked this conversation as resolved.
Show resolved Hide resolved
# rescanBlockStorageOnResize: true
constraints:
floatingPools:
Expand Down Expand Up @@ -98,6 +99,8 @@ Some OpenStack environments don't need these regional mappings, hence, the `regi
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`.

If Gardener creates and manages the router of a shoot cluster, it is additionally possible to specify that the [enable_snat](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/networking_router_v2#enable_snat) field is set to `true` via `useSNAT: true` in the `CloudProfileConfig`.

## Example `CloudProfile` manifest

Please find below an example `CloudProfile` manifest:
Expand Down
12 changes: 12 additions & 0 deletions hack/api-reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ bool
<p>UseOctavia specifies whether the OpenStack Octavia network load balancing is used.</p>
</td>
</tr>
<tr>
<td>
<code>useSNAT</code></br>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>UseSNAT specifies whether S-NAT is supposed to be used for the Gardener managed OpenStack router.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="openstack.provider.extensions.gardener.cloud/v1alpha1.ControlPlaneConfig">ControlPlaneConfig
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/openstack/types_cloudprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type CloudProfileConfig struct {
RescanBlockStorageOnResize *bool
// UseOctavia specifies whether the OpenStack Octavia network load balancing is used.
UseOctavia *bool
// UseSNAT specifies whether S-NAT is supposed to be used for the Gardener managed OpenStack router.
UseSNAT *bool
}

// Constraints is an object containing constraints for the shoots.
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/openstack/v1alpha1/types_cloudprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type CloudProfileConfig struct {
// UseOctavia specifies whether the OpenStack Octavia network load balancing is used.
// +optional
UseOctavia *bool `json:"useOctavia,omitempty"`
// UseSNAT specifies whether S-NAT is supposed to be used for the Gardener managed OpenStack router.
// +optional
UseSNAT *bool `json:"useSNAT,omitempty"`
}

// Constraints is an object containing constraints for the shoots.
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/openstack/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/apis/openstack/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/apis/openstack/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/internal/infrastructure/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ func ComputeTerraformerChartValues(
return nil, err
}

if cloudProfileConfig.UseSNAT != nil {
routerConfig["enableSNAT"] = *cloudProfileConfig.UseSNAT
}

workersCIDR := config.Networks.Workers
// Backwards compatibility - remove this code in a future version.
if workersCIDR == "" {
Expand Down
7 changes: 7 additions & 0 deletions pkg/internal/infrastructure/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"encoding/json"
"strconv"

"k8s.io/utils/pointer"

api "github.com/gardener/gardener-extension-provider-openstack/pkg/apis/openstack"
apiv1alpha1 "github.com/gardener/gardener-extension-provider-openstack/pkg/apis/openstack/v1alpha1"
"github.com/gardener/gardener-extension-provider-openstack/pkg/openstack"
Expand Down Expand Up @@ -162,9 +164,14 @@ var _ = Describe("Terraform", func() {
})

It("should correctly compute the terraformer chart values with vpc creation", func() {
cloudProfileConfig.UseSNAT = pointer.BoolPtr(true)
cloudProfileConfigJSON, _ = json.Marshal(cloudProfileConfig)
cluster.CloudProfile.Spec.ProviderConfig.Raw = cloudProfileConfigJSON

config.Networks.Router = nil
expectedCreateValues["router"] = true
expectedRouterValues["id"] = DefaultRouterID
expectedRouterValues["enableSNAT"] = true

values, err := ComputeTerraformerChartValues(infra, credentials, config, cluster)
Expect(err).To(BeNil())
Expand Down