Skip to content

Commit 08a4a5e

Browse files
authored
Add optional use-octavia flag to openstack cloud config (#870)
1 parent 6a45df4 commit 08a4a5e

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

pkg/cloudprovider/provider/openstack/types/cloudconfig.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ package types
1919
import (
2020
"bytes"
2121
"fmt"
22+
"strconv"
2223
"text/template"
2324

2425
"github.com/kubermatic/machine-controller/pkg/ini"
2526

2627
"github.com/Masterminds/sprig/v3"
2728
)
2829

30+
// use-octavia is enabled by default in CCM since v1.17.0, and disabled by
31+
// default with the in-tree cloud provider.
32+
// https://v1-18.docs.kubernetes.io/docs/concepts/cluster-administration/cloud-providers/#load-balancer
2933
const (
3034
cloudConfigTpl = `[Global]
3135
auth-url = {{ .Global.AuthURL | iniEscape }}
@@ -42,6 +46,9 @@ subnet-id = {{ .LoadBalancer.SubnetID | iniEscape }}
4246
floating-network-id = {{ .LoadBalancer.FloatingNetworkID | iniEscape }}
4347
lb-method = {{ default "ROUND_ROBIN" .LoadBalancer.LBMethod | iniEscape }}
4448
lb-provider = {{ .LoadBalancer.LBProvider | iniEscape }}
49+
{{- if .LoadBalancer.UseOctavia }}
50+
use-octavia = {{ .LoadBalancer.UseOctavia | boolPtr }}
51+
{{- end }}
4552
4653
{{- if .LoadBalancer.CreateMonitor }}
4754
create-monitor = {{ .LoadBalancer.CreateMonitor }}
@@ -76,6 +83,7 @@ type LoadBalancerOpts struct {
7683
MonitorTimeout ini.Duration `gcfg:"monitor-timeout"`
7784
MonitorMaxRetries uint `gcfg:"monitor-max-retries"`
7885
ManageSecurityGroups bool `gcfg:"manage-security-groups"`
86+
UseOctavia *bool `gcfg:"use-octavia"`
7987
}
8088

8189
type BlockStorageOpts struct {
@@ -106,6 +114,7 @@ type CloudConfig struct {
106114
func CloudConfigToString(c *CloudConfig) (string, error) {
107115
funcMap := sprig.TxtFuncMap()
108116
funcMap["iniEscape"] = ini.Escape
117+
funcMap["boolPtr"] = func(b *bool) string { return strconv.FormatBool(*b) }
109118

110119
tpl, err := template.New("cloud-config").Funcs(funcMap).Parse(cloudConfigTpl)
111120
if err != nil {

pkg/cloudprovider/provider/openstack/types/cloudconfig_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
"gopkg.in/gcfg.v1"
25+
"k8s.io/utils/pointer"
2526

2627
"github.com/kubermatic/machine-controller/pkg/ini"
2728
testhelper "github.com/kubermatic/machine-controller/pkg/test"
@@ -57,6 +58,54 @@ func TestCloudConfigToString(t *testing.T) {
5758
Version: "1.10.0",
5859
},
5960
},
61+
{
62+
name: "use-octavia-explicitly-enabled",
63+
config: &CloudConfig{
64+
Global: GlobalOpts{
65+
AuthURL: "https://127.0.0.1:8443",
66+
Username: "admin",
67+
Password: "password",
68+
DomainName: "Default",
69+
TenantName: "Test",
70+
Region: "eu-central1",
71+
},
72+
BlockStorage: BlockStorageOpts{
73+
BSVersion: "v2",
74+
IgnoreVolumeAZ: true,
75+
TrustDevicePath: true,
76+
NodeVolumeAttachLimit: 25,
77+
},
78+
LoadBalancer: LoadBalancerOpts{
79+
ManageSecurityGroups: true,
80+
UseOctavia: pointer.BoolPtr(true),
81+
},
82+
Version: "1.10.0",
83+
},
84+
},
85+
{
86+
name: "use-octavia-explicitly-disabled",
87+
config: &CloudConfig{
88+
Global: GlobalOpts{
89+
AuthURL: "https://127.0.0.1:8443",
90+
Username: "admin",
91+
Password: "password",
92+
DomainName: "Default",
93+
TenantName: "Test",
94+
Region: "eu-central1",
95+
},
96+
BlockStorage: BlockStorageOpts{
97+
BSVersion: "v2",
98+
IgnoreVolumeAZ: true,
99+
TrustDevicePath: true,
100+
NodeVolumeAttachLimit: 25,
101+
},
102+
LoadBalancer: LoadBalancerOpts{
103+
ManageSecurityGroups: true,
104+
UseOctavia: pointer.BoolPtr(false),
105+
},
106+
Version: "1.10.0",
107+
},
108+
},
60109
{
61110
name: "config-with-special-chars",
62111
config: &CloudConfig{
@@ -109,6 +158,7 @@ func TestCloudConfigToString(t *testing.T) {
109158
t.Fatal(err)
110159
}
111160

161+
t.Logf("Marshaled config: %s\n", s)
112162
nc := &CloudConfig{}
113163
if err := gcfg.ReadStringInto(nc, s); err != nil {
114164
t.Logf("\n%s", s)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[Global]
2+
auth-url = "https://127.0.0.1:8443"
3+
username = "admin"
4+
password = "password"
5+
tenant-name = "Test"
6+
tenant-id = ""
7+
domain-name = "Default"
8+
region = "eu-central1"
9+
10+
[LoadBalancer]
11+
lb-version = "v2"
12+
subnet-id = ""
13+
floating-network-id = ""
14+
lb-method = "ROUND_ROBIN"
15+
lb-provider = ""
16+
use-octavia = false
17+
18+
[BlockStorage]
19+
ignore-volume-az = true
20+
trust-device-path = true
21+
bs-version = "v2"
22+
node-volume-attach-limit = 25
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[Global]
2+
auth-url = "https://127.0.0.1:8443"
3+
username = "admin"
4+
password = "password"
5+
tenant-name = "Test"
6+
tenant-id = ""
7+
domain-name = "Default"
8+
region = "eu-central1"
9+
10+
[LoadBalancer]
11+
lb-version = "v2"
12+
subnet-id = ""
13+
floating-network-id = ""
14+
lb-method = "ROUND_ROBIN"
15+
lb-provider = ""
16+
use-octavia = true
17+
18+
[BlockStorage]
19+
ignore-volume-az = true
20+
trust-device-path = true
21+
bs-version = "v2"
22+
node-volume-attach-limit = 25

0 commit comments

Comments
 (0)