Skip to content

Commit 0d91f35

Browse files
authored
Merge pull request ovh#373 from matprig/kube/feat/kube_proxy_mode
feat(kube): Let user configure kube proxy
2 parents 2420262 + a8fa935 commit 0d91f35

9 files changed

+1492
-154
lines changed

ovh/data_cloud_project_kube.go

Lines changed: 138 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,77 @@ func dataSourceCloudProjectKube() *schema.Resource {
2929
Type: schema.TypeString,
3030
Optional: true,
3131
},
32-
kubeClusterCustomizationKey: {
32+
kubeClusterProxyModeKey: {
33+
Type: schema.TypeString,
34+
Optional: true,
35+
ForceNew: true,
36+
},
37+
kubeClusterCustomizationApiServerKey: {
3338
Type: schema.TypeSet,
3439
Computed: true,
3540
Optional: true,
41+
// Required: true,
3642
ForceNew: false,
37-
MaxItems: 1,
43+
// MaxItems: 1,
44+
Set: CustomSchemaSetFunc(),
3845
Elem: &schema.Resource{
3946
Schema: map[string]*schema.Schema{
40-
"apiserver": {
47+
"admissionplugins": {
4148
Type: schema.TypeSet,
4249
Computed: true,
4350
Optional: true,
51+
// Required: true,
4452
ForceNew: false,
45-
MaxItems: 1,
53+
// MaxItems: 1,
54+
Set: CustomSchemaSetFunc(),
55+
Elem: &schema.Resource{
56+
Schema: map[string]*schema.Schema{
57+
"enabled": {
58+
Type: schema.TypeList,
59+
Computed: true,
60+
Optional: true,
61+
// Required: true,
62+
ForceNew: false,
63+
Elem: &schema.Schema{Type: schema.TypeString},
64+
},
65+
"disabled": {
66+
Type: schema.TypeList,
67+
Computed: true,
68+
Optional: true,
69+
// Required: true,
70+
ForceNew: false,
71+
Elem: &schema.Schema{Type: schema.TypeString},
72+
},
73+
},
74+
},
75+
},
76+
},
77+
},
78+
},
79+
kubeClusterCustomization: {
80+
Type: schema.TypeSet,
81+
Computed: true,
82+
Optional: true,
83+
ForceNew: false,
84+
Set: CustomSchemaSetFunc(),
85+
Deprecated: fmt.Sprintf("Use %s instead", kubeClusterCustomizationApiServerKey),
86+
Elem: &schema.Resource{
87+
Schema: map[string]*schema.Schema{
88+
"apiserver": {
89+
Type: schema.TypeSet,
90+
Computed: true,
91+
Optional: true,
92+
ForceNew: false,
93+
Set: CustomSchemaSetFunc(),
94+
Deprecated: fmt.Sprintf("Use %s instead", kubeClusterCustomizationApiServerKey),
4695
Elem: &schema.Resource{
4796
Schema: map[string]*schema.Schema{
4897
"admissionplugins": {
4998
Type: schema.TypeSet,
5099
Computed: true,
51100
Optional: true,
52101
ForceNew: false,
53-
MaxItems: 1,
102+
Set: CustomSchemaSetFunc(),
54103
Elem: &schema.Resource{
55104
Schema: map[string]*schema.Schema{
56105
"enabled": {
@@ -76,6 +125,90 @@ func dataSourceCloudProjectKube() *schema.Resource {
76125
},
77126
},
78127
},
128+
kubeClusterCustomizationKubeProxyKey: {
129+
Type: schema.TypeSet,
130+
Computed: false,
131+
Optional: true,
132+
ForceNew: false,
133+
MaxItems: 1,
134+
Elem: &schema.Resource{
135+
Schema: map[string]*schema.Schema{
136+
"iptables": {
137+
Type: schema.TypeSet,
138+
Computed: false,
139+
Optional: true,
140+
ForceNew: false,
141+
MaxItems: 1,
142+
Set: CustomIPVSIPTablesSchemaSetFunc(),
143+
Elem: &schema.Resource{
144+
Schema: map[string]*schema.Schema{
145+
"min_sync_period": {
146+
Type: schema.TypeString,
147+
Computed: false,
148+
Optional: true,
149+
ForceNew: false,
150+
},
151+
"sync_period": {
152+
Type: schema.TypeString,
153+
Computed: false,
154+
Optional: true,
155+
ForceNew: false,
156+
},
157+
},
158+
},
159+
},
160+
"ipvs": {
161+
Type: schema.TypeSet,
162+
Computed: false,
163+
Optional: true,
164+
ForceNew: false,
165+
MaxItems: 1,
166+
Set: CustomIPVSIPTablesSchemaSetFunc(),
167+
Elem: &schema.Resource{
168+
Schema: map[string]*schema.Schema{
169+
"min_sync_period": {
170+
Type: schema.TypeString,
171+
Computed: false,
172+
Optional: true,
173+
ForceNew: false,
174+
},
175+
"sync_period": {
176+
Type: schema.TypeString,
177+
Computed: false,
178+
Optional: true,
179+
ForceNew: false,
180+
},
181+
"scheduler": {
182+
Type: schema.TypeString,
183+
Computed: false,
184+
Optional: true,
185+
ForceNew: false,
186+
},
187+
"tcp_fin_timeout": {
188+
Type: schema.TypeString,
189+
Computed: false,
190+
Optional: true,
191+
ForceNew: false,
192+
},
193+
"tcp_timeout": {
194+
Type: schema.TypeString,
195+
Computed: false,
196+
Optional: true,
197+
ForceNew: false,
198+
},
199+
"udp_timeout": {
200+
Type: schema.TypeString,
201+
Computed: false,
202+
Optional: true,
203+
ForceNew: false,
204+
},
205+
},
206+
},
207+
},
208+
},
209+
},
210+
},
211+
79212
"private_network_id": {
80213
Type: schema.TypeString,
81214
Computed: true,

ovh/data_cloud_project_kube_test.go

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,58 @@ func TestAccCloudProjectKubeDataSource_basic(t *testing.T) {
2525

2626
resource.Test(t, resource.TestCase{
2727
PreCheck: func() {
28+
testAccPreCheckCloud(t)
29+
testAccCheckCloudProjectExists(t)
2830
testAccPreCheckKubernetes(t)
2931
},
3032
Providers: testAccProviders,
3133
Steps: []resource.TestStep{
3234
{
3335
Config: config,
3436
Check: resource.ComposeTestCheckFunc(
35-
resource.TestCheckResourceAttr(
36-
"data.ovh_cloud_project_kube.cluster", "region", region),
37-
resource.TestCheckResourceAttr(
38-
"data.ovh_cloud_project_kube.cluster", "name", name),
39-
resource.TestMatchResourceAttr(
40-
"data.ovh_cloud_project_kube.cluster", "version", matchVersion),
37+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "region", region),
38+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "name", name),
39+
resource.TestMatchResourceAttr("data.ovh_cloud_project_kube.cluster", "version", matchVersion),
40+
),
41+
},
42+
},
43+
})
44+
}
45+
46+
func TestAccCloudProjectKubeDataSource_kubeProxy(t *testing.T) {
47+
name := acctest.RandomWithPrefix(test_prefix)
48+
region := os.Getenv("OVH_CLOUD_PROJECT_KUBE_REGION_TEST")
49+
config := fmt.Sprintf(
50+
testAccCloudProjectKubeDatasourceKubeProxyConfig,
51+
os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST"),
52+
name,
53+
region,
54+
)
55+
56+
resource.Test(t, resource.TestCase{
57+
PreCheck: func() {
58+
testAccPreCheckCloud(t)
59+
testAccCheckCloudProjectExists(t)
60+
testAccPreCheckKubernetes(t)
61+
},
62+
Providers: testAccProviders,
63+
Steps: []resource.TestStep{
64+
{
65+
Config: config,
66+
Check: resource.ComposeTestCheckFunc(
67+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "region", region),
68+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "name", name),
69+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "kube_proxy_mode", "ipvs"),
70+
71+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.iptables.0.min_sync_period", "PT30S"),
72+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.iptables.0.sync_period", "PT30S"),
73+
74+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.ipvs.0.min_sync_period", "PT30S"),
75+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.ipvs.0.sync_period", "PT30S"),
76+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.ipvs.0.scheduler", "rr"),
77+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.ipvs.0.tcp_fin_timeout", "PT30S"),
78+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.ipvs.0.tcp_timeout", "PT30S"),
79+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.ipvs.0.udp_timeout", "PT30S"),
4180
),
4281
},
4382
},
@@ -57,3 +96,33 @@ data "ovh_cloud_project_kube" "cluster" {
5796
kube_id = ovh_cloud_project_kube.cluster.id
5897
}
5998
`
99+
100+
var testAccCloudProjectKubeDatasourceKubeProxyConfig = `
101+
resource "ovh_cloud_project_kube" "cluster" {
102+
service_name = "%s"
103+
name = "%s"
104+
region = "%s"
105+
106+
kube_proxy_mode = "ipvs"
107+
customization_kube_proxy {
108+
iptables {
109+
min_sync_period = "PT30S"
110+
sync_period = "PT30S"
111+
}
112+
113+
ipvs {
114+
min_sync_period = "PT30S"
115+
sync_period = "PT30S"
116+
scheduler = "rr"
117+
tcp_fin_timeout = "PT30S"
118+
tcp_timeout = "PT30S"
119+
udp_timeout = "PT30S"
120+
}
121+
}
122+
}
123+
124+
data "ovh_cloud_project_kube" "cluster" {
125+
service_name = ovh_cloud_project_kube.cluster.service_name
126+
kube_id = ovh_cloud_project_kube.cluster.id
127+
}
128+
`

0 commit comments

Comments
 (0)