-
Notifications
You must be signed in to change notification settings - Fork 72
/
ingress.go
219 lines (196 loc) · 6.51 KB
/
ingress.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package framework
import (
"fmt"
"net"
"path/filepath"
"testing"
"github.com/k8ssandra/k8ssandra-operator/pkg/utils"
"github.com/k8ssandra/k8ssandra-operator/test/kubectl"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type HostAndPort string
func (s HostAndPort) Host() string {
host, _, _ := net.SplitHostPort(string(s))
return host
}
func (s HostAndPort) Port() string {
_, port, _ := net.SplitHostPort(string(s))
return port
}
type ingressKustomization struct {
ServiceName string
Host string
}
type cqlIngressKustomization struct {
ServiceNamespace string
ServiceName string
Host string
}
func (f *E2eFramework) DeployStargateIngresses(t *testing.T, k8sContext, namespace, stargateServiceName string, stargateRestHostAndPort, stargateGrpcHostAndPort HostAndPort) {
f.deployIngress(t, k8sContext, namespace, "stargate-ingress.yaml", "stargate", stargateTemplate,
&ingressKustomization{stargateServiceName, stargateRestHostAndPort.Host()})
f.deployIngress(t, k8sContext, namespace, "stargate-grpc-ingress.yaml", "stargate-grpc", stargateGrpcTemplate,
&ingressKustomization{stargateServiceName, stargateGrpcHostAndPort.Host()})
f.deployIngress(t, k8sContext, "ingress-nginx", "stargate-cql-ingress.yaml", "stargate-cql", stargateCqlTemplate,
&cqlIngressKustomization{namespace, stargateServiceName, stargateRestHostAndPort.Host()})
}
func (f *E2eFramework) DeployReaperIngresses(t *testing.T, k8sContext, namespace, reaperServiceName string, reaperHostAndPort HostAndPort) {
f.deployIngress(t, k8sContext, namespace, "reaper-ingress.yaml", "reaper", reaperTemplate,
&ingressKustomization{reaperServiceName, reaperHostAndPort.Host()})
}
func (f *E2eFramework) DeploySolrIngresses(t *testing.T, k8sContext, namespace, solrServiceName string, solrHostAndPort HostAndPort) {
f.deployIngress(t, k8sContext, namespace, "solr-ingress.yaml", "solr", solrTemplate,
&ingressKustomization{solrServiceName, solrHostAndPort.Host()})
}
func (f *E2eFramework) DeployGraphIngresses(t *testing.T, k8sContext, namespace, graphServiceName string, graphHostAndPort HostAndPort) {
f.deployIngress(t, k8sContext, namespace, "graph-ingress.yaml", "graph", graphTemplate,
&ingressKustomization{graphServiceName, graphHostAndPort.Host()})
}
func (f *E2eFramework) deployIngress(t *testing.T, k8sContext, namespace, sourceYaml, buildDir, template string, templateData interface{}) {
src := filepath.Join("..", "..", "test", "testdata", "ingress", sourceYaml)
dest := filepath.Join("..", "..", "build", "test-config", "ingress", buildDir, k8sContext)
_, err := utils.CopyFileToDir(src, dest)
require.NoError(t, err)
err = generateKustomizationFile(fmt.Sprintf("ingress/%s/%s", buildDir, k8sContext), templateData, template)
require.NoError(t, err)
err = f.kustomizeAndApply(dest, namespace, k8sContext)
require.NoError(t, err)
}
func (f *E2eFramework) UndeployAllIngresses(t *testing.T, k8sContext, namespace string) {
options := kubectl.Options{Context: k8sContext, Namespace: namespace}
err := kubectl.DeleteAllOf(options, "Ingress")
assert.NoError(t, err)
}
const stargateTemplate = `apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- stargate-ingress.yaml
patches:
- target:
group: networking.k8s.io
version: v1
kind: Ingress
name: cluster1-dc1-stargate-service-http-ingress
patch: |-
- op: replace
path: /metadata/name
value: "{{ .ServiceName }}-http-ingress"
- op: replace
path: /spec/rules/0/host
value: "{{ .Host }}"
- op: replace
path: /spec/rules/0/http/paths/0/backend/service/name
value: "{{ .ServiceName }}"
- op: replace
path: /spec/rules/0/http/paths/1/backend/service/name
value: "{{ .ServiceName }}"
- op: replace
path: /spec/rules/0/http/paths/2/backend/service/name
value: "{{ .ServiceName }}"
`
const stargateGrpcTemplate = `apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- stargate-grpc-ingress.yaml
patches:
- target:
group: networking.k8s.io
version: v1
kind: Ingress
name: cluster1-dc1-stargate-service-grpc-ingress
patch: |-
- op: replace
path: /metadata/name
value: "{{ .ServiceName }}-grpc-ingress"
- op: replace
path: /spec/rules/0/host
value: "{{ .Host }}"
- op: replace
path: /spec/rules/0/http/paths/0/backend/service/name
value: "{{ .ServiceName }}"
- op: replace
path: /spec/tls/0/secretName
value: "{{ .ServiceName }}-grpc-tls-secret"
- op: replace
path: /spec/tls/0/hosts/0
value: "{{ .Host }}"
`
const stargateCqlTemplate = `apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- stargate-cql-ingress.yaml
patches:
- target:
group: ""
version: v1
kind: ConfigMap
name: ingress-nginx-tcp
patch: |-
- op: replace
path: /data/9042
value: "{{ .ServiceNamespace }}/{{ .ServiceName }}:9042"
`
const reaperTemplate = `apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- reaper-ingress.yaml
patches:
- target:
group: networking.k8s.io
version: v1
kind: Ingress
name: cluster1-dc1-reaper-service-http-ingress
patch: |-
- op: replace
path: /metadata/name
value: "{{ .ServiceName }}-http-ingress"
- op: replace
path: /spec/rules/0/host
value: "{{ .Host }}"
- op: replace
path: /spec/rules/0/http/paths/0/backend/service/name
value: "{{ .ServiceName }}"
`
const solrTemplate = `apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- solr-ingress.yaml
patches:
- target:
group: networking.k8s.io
version: v1
kind: Ingress
name: cluster1-dc1-solr-service-http-ingress
patch: |-
- op: replace
path: /metadata/name
value: "{{ .ServiceName }}-http-ingress"
- op: replace
path: /spec/rules/0/host
value: "{{ .Host }}"
- op: replace
path: /spec/rules/0/http/paths/0/backend/service/name
value: "{{ .ServiceName }}"
`
const graphTemplate = `apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- graph-ingress.yaml
patches:
- target:
group: networking.k8s.io
version: v1
kind: Ingress
name: cluster1-dc1-graph-service-http-ingress
patch: |-
- op: replace
path: /metadata/name
value: "{{ .ServiceName }}-http-ingress"
- op: replace
path: /spec/rules/0/host
value: "{{ .Host }}"
- op: replace
path: /spec/rules/0/http/paths/0/backend/service/name
value: "{{ .ServiceName }}"
`