Skip to content

Commit 7e5b68c

Browse files
authored
Add StateUpgrader for LoadBalancerIngress (#1098)
Also update EKS test-infra to allow using load balancers with Ingress.
1 parent 484112d commit 7e5b68c

21 files changed

+54821
-510
lines changed

kubernetes/data_source_kubernetes_ingress.go

Lines changed: 92 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,66 @@ import (
1010
)
1111

1212
func dataSourceKubernetesIngress() *schema.Resource {
13+
return &schema.Resource{
14+
ReadContext: dataSourceKubernetesIngressRead,
15+
StateUpgraders: []schema.StateUpgrader{
16+
{
17+
Type: dataSourceKubernetesIngressV0().CoreConfigSchema().ImpliedType(),
18+
Upgrade: dataSourceKubernetesIngressStateUpgradeV0,
19+
Version: 0,
20+
},
21+
},
22+
SchemaVersion: 1,
23+
Schema: dataSourceKubernetesIngressSchemaV1(),
24+
}
25+
}
26+
27+
func dataSourceKubernetesIngressSchemaV1() map[string]*schema.Schema {
1328
docHTTPIngressPath := networking.HTTPIngressPath{}.SwaggerDoc()
1429
docHTTPIngressRuleValue := networking.HTTPIngressPath{}.SwaggerDoc()
1530
docIngress := networking.Ingress{}.SwaggerDoc()
1631
docIngressTLS := networking.IngressTLS{}.SwaggerDoc()
1732
docIngressRule := networking.IngressRule{}.SwaggerDoc()
1833
docIngressSpec := networking.IngressSpec{}.SwaggerDoc()
1934

20-
return &schema.Resource{
21-
ReadContext: dataSourceKubernetesIngressRead,
22-
23-
Schema: map[string]*schema.Schema{
24-
"metadata": namespacedMetadataSchema("ingress", false),
25-
"spec": {
26-
Type: schema.TypeList,
27-
Description: docIngress["spec"],
28-
Computed: true,
29-
Elem: &schema.Resource{
30-
Schema: map[string]*schema.Schema{
31-
"backend": backendSpecFields(defaultBackendDescription),
32-
// FIXME: this field is inconsistent with the k8s API 'rules'
33-
"rule": {
34-
Type: schema.TypeList,
35-
Description: docIngressSpec["rules"],
36-
Computed: true,
37-
Elem: &schema.Resource{
38-
Schema: map[string]*schema.Schema{
39-
"host": {
40-
Type: schema.TypeString,
41-
Description: docIngressRule["host"],
42-
Computed: true,
43-
},
44-
"http": {
45-
Type: schema.TypeList,
46-
Computed: true,
47-
Description: docIngressRule[""],
48-
Elem: &schema.Resource{
49-
Schema: map[string]*schema.Schema{
50-
// FIXME: this field is inconsistent with the k8s API 'paths'
51-
"path": {
52-
Type: schema.TypeList,
53-
Computed: true,
54-
Description: docHTTPIngressRuleValue["paths"],
55-
Elem: &schema.Resource{
56-
Schema: map[string]*schema.Schema{
57-
"path": {
58-
Type: schema.TypeString,
59-
Description: docHTTPIngressPath["path"],
60-
Computed: true,
61-
},
62-
"backend": backendSpecFields(ruleBackedDescription),
35+
return map[string]*schema.Schema{
36+
"metadata": namespacedMetadataSchema("ingress", false),
37+
"spec": {
38+
Type: schema.TypeList,
39+
Description: docIngress["spec"],
40+
Computed: true,
41+
Elem: &schema.Resource{
42+
Schema: map[string]*schema.Schema{
43+
"backend": backendSpecFields(defaultBackendDescription),
44+
"rule": {
45+
Type: schema.TypeList,
46+
Description: docIngressSpec["rules"],
47+
Computed: true,
48+
Elem: &schema.Resource{
49+
Schema: map[string]*schema.Schema{
50+
"host": {
51+
Type: schema.TypeString,
52+
Description: docIngressRule["host"],
53+
Computed: true,
54+
},
55+
"http": {
56+
Type: schema.TypeList,
57+
Computed: true,
58+
Description: docIngressRule[""],
59+
Elem: &schema.Resource{
60+
Schema: map[string]*schema.Schema{
61+
"path": {
62+
Type: schema.TypeList,
63+
Computed: true,
64+
Description: docHTTPIngressRuleValue["paths"],
65+
Elem: &schema.Resource{
66+
Schema: map[string]*schema.Schema{
67+
"path": {
68+
Type: schema.TypeString,
69+
Description: docHTTPIngressPath["path"],
70+
Computed: true,
6371
},
72+
"backend": backendSpecFields(ruleBackedDescription),
6473
},
6574
},
6675
},
@@ -69,52 +78,52 @@ func dataSourceKubernetesIngress() *schema.Resource {
6978
},
7079
},
7180
},
72-
"tls": {
73-
Type: schema.TypeList,
74-
Description: docIngressSpec["tls"],
75-
Computed: true,
76-
Elem: &schema.Resource{
77-
Schema: map[string]*schema.Schema{
78-
"hosts": {
79-
Type: schema.TypeList,
80-
Description: docIngressTLS["hosts"],
81-
Computed: true,
82-
Elem: &schema.Schema{Type: schema.TypeString},
83-
},
84-
"secret_name": {
85-
Type: schema.TypeString,
86-
Description: docIngressTLS["secretName"],
87-
Computed: true,
88-
},
81+
},
82+
"tls": {
83+
Type: schema.TypeList,
84+
Description: docIngressSpec["tls"],
85+
Computed: true,
86+
Elem: &schema.Resource{
87+
Schema: map[string]*schema.Schema{
88+
"hosts": {
89+
Type: schema.TypeList,
90+
Description: docIngressTLS["hosts"],
91+
Computed: true,
92+
Elem: &schema.Schema{Type: schema.TypeString},
93+
},
94+
"secret_name": {
95+
Type: schema.TypeString,
96+
Description: docIngressTLS["secretName"],
97+
Computed: true,
8998
},
9099
},
91100
},
92101
},
93102
},
94103
},
95-
"status": {
96-
Type: schema.TypeList,
97-
Computed: true,
98-
Elem: &schema.Resource{
99-
Schema: map[string]*schema.Schema{
100-
"load_balancer": {
101-
Type: schema.TypeList,
102-
Computed: true,
103-
Elem: &schema.Resource{
104-
Schema: map[string]*schema.Schema{
105-
"ingress": {
106-
Type: schema.TypeList,
107-
Computed: true,
108-
Elem: &schema.Resource{
109-
Schema: map[string]*schema.Schema{
110-
"ip": {
111-
Type: schema.TypeString,
112-
Computed: true,
113-
},
114-
"hostname": {
115-
Type: schema.TypeString,
116-
Computed: true,
117-
},
104+
},
105+
"status": {
106+
Type: schema.TypeList,
107+
Computed: true,
108+
Elem: &schema.Resource{
109+
Schema: map[string]*schema.Schema{
110+
"load_balancer": {
111+
Type: schema.TypeList,
112+
Computed: true,
113+
Elem: &schema.Resource{
114+
Schema: map[string]*schema.Schema{
115+
"ingress": {
116+
Type: schema.TypeList,
117+
Computed: true,
118+
Elem: &schema.Resource{
119+
Schema: map[string]*schema.Schema{
120+
"ip": {
121+
Type: schema.TypeString,
122+
Computed: true,
123+
},
124+
"hostname": {
125+
Type: schema.TypeString,
126+
Computed: true,
118127
},
119128
},
120129
},
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
package kubernetes
2+
3+
import (
4+
"context"
5+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
6+
networking "k8s.io/api/networking/v1beta1"
7+
"log"
8+
)
9+
10+
// dataSourceKubernetesIngressV0 is a copy of the Kubernetes Ingress schema (before migration).
11+
func dataSourceKubernetesIngressV0() *schema.Resource {
12+
docHTTPIngressPath := networking.HTTPIngressPath{}.SwaggerDoc()
13+
docHTTPIngressRuleValue := networking.HTTPIngressPath{}.SwaggerDoc()
14+
docIngress := networking.Ingress{}.SwaggerDoc()
15+
docIngressTLS := networking.IngressTLS{}.SwaggerDoc()
16+
docIngressRule := networking.IngressRule{}.SwaggerDoc()
17+
docIngressSpec := networking.IngressSpec{}.SwaggerDoc()
18+
return &schema.Resource{
19+
Schema: map[string]*schema.Schema{
20+
"metadata": namespacedMetadataSchema("ingress", true),
21+
"spec": {
22+
Type: schema.TypeList,
23+
Description: docIngress["spec"],
24+
Required: true,
25+
MaxItems: 1,
26+
Elem: &schema.Resource{
27+
Schema: map[string]*schema.Schema{
28+
"ingress_class_name": {
29+
Type: schema.TypeString,
30+
Description: docIngressSpec["ingressClassName"],
31+
Optional: true,
32+
},
33+
"backend": backendSpecFields(defaultBackendDescription),
34+
"rule": {
35+
Type: schema.TypeList,
36+
Description: docIngress["rules"],
37+
Optional: true,
38+
Elem: &schema.Resource{
39+
Schema: map[string]*schema.Schema{
40+
"host": {
41+
Type: schema.TypeString,
42+
Description: docIngressRule["host"],
43+
Optional: true,
44+
},
45+
"http": {
46+
Type: schema.TypeList,
47+
Required: true,
48+
MaxItems: 1,
49+
Description: "http is a list of http selectors pointing to backends. In the example: http:///? -> backend where where parts of the url correspond to RFC 3986, this resource will be used to match against everything after the last '/' and before the first '?' or '#'.",
50+
Elem: &schema.Resource{
51+
Schema: map[string]*schema.Schema{
52+
"path": {
53+
Type: schema.TypeList,
54+
Required: true,
55+
Description: docHTTPIngressRuleValue["paths"],
56+
Elem: &schema.Resource{
57+
Schema: map[string]*schema.Schema{
58+
"path": {
59+
Type: schema.TypeString,
60+
Description: docHTTPIngressPath["path"],
61+
Optional: true,
62+
},
63+
"backend": backendSpecFields(ruleBackedDescription),
64+
},
65+
},
66+
},
67+
},
68+
},
69+
},
70+
},
71+
},
72+
},
73+
"tls": {
74+
Type: schema.TypeList,
75+
Description: docIngressSpec["tls"],
76+
Optional: true,
77+
Elem: &schema.Resource{
78+
Schema: map[string]*schema.Schema{
79+
"hosts": {
80+
Type: schema.TypeList,
81+
Description: docIngressTLS["hosts"],
82+
Optional: true,
83+
Elem: &schema.Schema{Type: schema.TypeString},
84+
},
85+
"secret_name": {
86+
Type: schema.TypeString,
87+
Description: docIngressTLS["secretName"],
88+
Optional: true,
89+
},
90+
},
91+
},
92+
},
93+
},
94+
},
95+
},
96+
"status": {
97+
Type: schema.TypeList,
98+
Computed: true,
99+
Elem: &schema.Resource{
100+
Schema: map[string]*schema.Schema{
101+
"load_balancer": {
102+
Type: schema.TypeList,
103+
Computed: true,
104+
Elem: &schema.Resource{
105+
Schema: map[string]*schema.Schema{
106+
"ingress": {
107+
Type: schema.TypeList,
108+
Computed: true,
109+
Elem: &schema.Resource{
110+
Schema: map[string]*schema.Schema{
111+
"ip": {
112+
Type: schema.TypeString,
113+
Computed: true,
114+
},
115+
"hostname": {
116+
Type: schema.TypeString,
117+
Computed: true,
118+
},
119+
},
120+
},
121+
},
122+
},
123+
},
124+
},
125+
},
126+
},
127+
},
128+
"wait_for_load_balancer": {
129+
Type: schema.TypeBool,
130+
Optional: true,
131+
Description: "Terraform will wait for the load balancer to have at least 1 endpoint before considering the resource created.",
132+
},
133+
},
134+
}
135+
}
136+
137+
func dataSourceKubernetesIngressStateUpgradeV0(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
138+
log.Println("[INFO] Found Kubernetes Service state v0; upgrading state to v1")
139+
delete(rawState, "load_balancer_ingress")
140+
return rawState, nil
141+
}

0 commit comments

Comments
 (0)