Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit 2482601

Browse files
authored
Merge pull request #1342 from kinvolk/surajssd/fix-contour-envoy-regression
contour: Fix the hostPort regression
2 parents 7fe2070 + ce837ac commit 2482601

File tree

12 files changed

+505
-111
lines changed

12 files changed

+505
-111
lines changed

assets/charts/components/contour/templates/03-envoy.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ spec:
9595
fieldPath: metadata.name
9696
ports:
9797
- containerPort: 80
98-
hostPort: 80
9998
name: http
10099
protocol: TCP
101100
- containerPort: 443
102-
hostPort: 443
103101
name: https
104102
protocol: TCP
105103
readinessProbe:

pkg/assets/generated_assets.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/components/aws-ebs-csi-driver/component_test.go

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/kinvolk/lokomotive/pkg/components/internal/testutil"
2525
"github.com/kinvolk/lokomotive/pkg/components/util"
26+
"github.com/kinvolk/lokomotive/pkg/k8sutil"
2627
)
2728

2829
func TestStorageClassEmptyConfig(t *testing.T) {
@@ -144,16 +145,18 @@ func TestConversion(t *testing.T) { //nolint:funlen
144145
testCases := []struct {
145146
name string
146147
inputConfig string
147-
expectedManifestName string
148+
expectedManifestName k8sutil.ObjectMetadata
148149
expected string
149150
jsonPath string
150151
}{
151152
{
152-
name: "no_tolerations_node",
153-
inputConfig: `component "aws-ebs-csi-driver" {}`,
154-
expectedManifestName: "aws-ebs-csi-driver/templates/node.yaml",
155-
jsonPath: "{.spec.template.spec.tolerations[0].operator}",
156-
expected: "Exists",
153+
name: "no_tolerations_node",
154+
inputConfig: `component "aws-ebs-csi-driver" {}`,
155+
expectedManifestName: k8sutil.ObjectMetadata{
156+
Version: "apps/v1", Kind: "DaemonSet", Name: "ebs-csi-node",
157+
},
158+
jsonPath: "{.spec.template.spec.tolerations[0].operator}",
159+
expected: "Exists",
157160
},
158161
{
159162
name: "tolerations_node",
@@ -165,16 +168,20 @@ func TestConversion(t *testing.T) { //nolint:funlen
165168
effect = "NoSchedule"
166169
}
167170
}`,
168-
expectedManifestName: "aws-ebs-csi-driver/templates/node.yaml",
169-
jsonPath: "{.spec.template.spec.tolerations[0].value}",
170-
expected: "awesome",
171+
expectedManifestName: k8sutil.ObjectMetadata{
172+
Version: "apps/v1", Kind: "DaemonSet", Name: "ebs-csi-node",
173+
},
174+
jsonPath: "{.spec.template.spec.tolerations[0].value}",
175+
expected: "awesome",
171176
},
172177
{
173-
name: "no_tolerations_csi_controller",
174-
inputConfig: `component "aws-ebs-csi-driver" {}`,
175-
expectedManifestName: "aws-ebs-csi-driver/templates/controller.yaml",
176-
jsonPath: "{.spec.template.spec.tolerations[0].operator}",
177-
expected: "Exists",
178+
name: "no_tolerations_csi_controller",
179+
inputConfig: `component "aws-ebs-csi-driver" {}`,
180+
expectedManifestName: k8sutil.ObjectMetadata{
181+
Version: "apps/v1", Kind: "Deployment", Name: "ebs-csi-controller",
182+
},
183+
jsonPath: "{.spec.template.spec.tolerations[0].operator}",
184+
expected: "Exists",
178185
},
179186
{
180187
name: "tolerations_csi_controller",
@@ -186,16 +193,20 @@ func TestConversion(t *testing.T) { //nolint:funlen
186193
effect = "NoSchedule"
187194
}
188195
}`,
189-
expectedManifestName: "aws-ebs-csi-driver/templates/controller.yaml",
190-
jsonPath: "{.spec.template.spec.tolerations[0].key}",
191-
expected: "lokomotive.io",
196+
expectedManifestName: k8sutil.ObjectMetadata{
197+
Version: "apps/v1", Kind: "Deployment", Name: "ebs-csi-controller",
198+
},
199+
jsonPath: "{.spec.template.spec.tolerations[0].key}",
200+
expected: "lokomotive.io",
192201
},
193202
{
194-
name: "no_tolerations_snapshot_controller",
195-
inputConfig: `component "aws-ebs-csi-driver" {}`,
196-
expectedManifestName: "aws-ebs-csi-driver/templates/statefulset.yaml",
197-
jsonPath: "{.spec.template.spec.tolerations[0].operator}",
198-
expected: "Exists",
203+
name: "no_tolerations_snapshot_controller",
204+
inputConfig: `component "aws-ebs-csi-driver" {}`,
205+
expectedManifestName: k8sutil.ObjectMetadata{
206+
Version: "apps/v1", Kind: "StatefulSet", Name: "ebs-snapshot-controller",
207+
},
208+
jsonPath: "{.spec.template.spec.tolerations[0].operator}",
209+
expected: "Exists",
199210
},
200211
{
201212
name: "tolerations_snapshot_controller",
@@ -207,9 +218,11 @@ func TestConversion(t *testing.T) { //nolint:funlen
207218
effect = "NoSchedule"
208219
}
209220
}`,
210-
expectedManifestName: "aws-ebs-csi-driver/templates/statefulset.yaml",
211-
jsonPath: "{.spec.template.spec.tolerations[0].effect}",
212-
expected: "NoSchedule",
221+
expectedManifestName: k8sutil.ObjectMetadata{
222+
Version: "apps/v1", Kind: "StatefulSet", Name: "ebs-snapshot-controller",
223+
},
224+
jsonPath: "{.spec.template.spec.tolerations[0].effect}",
225+
expected: "NoSchedule",
213226
},
214227
{
215228
name: "affinity_csi_controller",
@@ -220,7 +233,9 @@ func TestConversion(t *testing.T) { //nolint:funlen
220233
values = ["storage"]
221234
}
222235
}`,
223-
expectedManifestName: "aws-ebs-csi-driver/templates/controller.yaml",
236+
expectedManifestName: k8sutil.ObjectMetadata{
237+
Version: "apps/v1", Kind: "Deployment", Name: "ebs-csi-controller",
238+
},
224239
jsonPath: "{.spec.template.spec.affinity.nodeAffinity." +
225240
"requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].key}",
226241
expected: "lokomotive.io/role",
@@ -234,26 +249,32 @@ func TestConversion(t *testing.T) { //nolint:funlen
234249
values = ["storage"]
235250
}
236251
}`,
237-
expectedManifestName: "aws-ebs-csi-driver/templates/statefulset.yaml",
252+
expectedManifestName: k8sutil.ObjectMetadata{
253+
Version: "apps/v1", Kind: "StatefulSet", Name: "ebs-snapshot-controller",
254+
},
238255
jsonPath: "{.spec.template.spec.affinity.nodeAffinity." +
239256
"requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].values[0]}",
240257
expected: "storage",
241258
},
242259
{
243-
name: "storage_class",
244-
inputConfig: `component "aws-ebs-csi-driver" {}`,
245-
expectedManifestName: "aws-ebs-csi-driver/templates/storageclass.yaml",
246-
jsonPath: "{.reclaimPolicy}",
247-
expected: "Retain",
260+
name: "storage_class",
261+
inputConfig: `component "aws-ebs-csi-driver" {}`,
262+
expectedManifestName: k8sutil.ObjectMetadata{
263+
Version: "storage.k8s.io/v1", Kind: "StorageClass", Name: "ebs-sc",
264+
},
265+
jsonPath: "{.reclaimPolicy}",
266+
expected: "Retain",
248267
},
249268
{
250269
name: "default_storage_class",
251270
inputConfig: `component "aws-ebs-csi-driver" {
252271
enable_default_storage_class = true
253272
}`,
254-
expectedManifestName: "aws-ebs-csi-driver/templates/storageclass.yaml",
255-
jsonPath: `{.metadata.annotations.storageclass\.kubernetes\.io\/is\-default\-class}`,
256-
expected: "true",
273+
expectedManifestName: k8sutil.ObjectMetadata{
274+
Version: "storage.k8s.io/v1", Kind: "StorageClass", Name: "ebs-sc",
275+
},
276+
jsonPath: `{.metadata.annotations.storageclass\.kubernetes\.io\/is\-default\-class}`,
277+
expected: "true",
257278
},
258279
}
259280

pkg/components/contour/component_test.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/kinvolk/lokomotive/pkg/components/internal/testutil"
2121
"github.com/kinvolk/lokomotive/pkg/components/util"
22+
"github.com/kinvolk/lokomotive/pkg/k8sutil"
2223
)
2324

2425
//nolint:funlen
@@ -96,7 +97,7 @@ func TestConversion(t *testing.T) {
9697
testCases := []struct {
9798
name string
9899
inputConfig string
99-
expectedManifestName string
100+
expectedManifestName k8sutil.ObjectMetadata
100101
expected string
101102
jsonPath string
102103
}{
@@ -108,9 +109,11 @@ func TestConversion(t *testing.T) {
108109
metrics_scrape_interval = "10s"
109110
}
110111
}`,
111-
expectedManifestName: "contour/templates/service-monitor.yaml",
112-
jsonPath: "{.spec.endpoints[0].interval}",
113-
expected: "10s",
112+
expectedManifestName: k8sutil.ObjectMetadata{
113+
Version: "monitoring.coreos.com/v1", Kind: "ServiceMonitor", Name: "envoy",
114+
},
115+
jsonPath: "{.spec.endpoints[0].interval}",
116+
expected: "10s",
114117
},
115118
}
116119

@@ -127,3 +130,18 @@ func TestConversion(t *testing.T) {
127130
})
128131
}
129132
}
133+
134+
func TestEnvoyHostPort(t *testing.T) {
135+
t.Parallel()
136+
137+
componentCfg := `component "contour" {}`
138+
expectedManifestName := k8sutil.ObjectMetadata{Version: "apps/v1", Kind: "DaemonSet", Name: "envoy"}
139+
jsonPath := "{.spec.template.spec.containers[1].ports[0].hostPort}"
140+
errExpected := "hostPort is not found"
141+
142+
component := NewConfig()
143+
m := testutil.RenderManifests(t, component, Name, componentCfg)
144+
gotConfig := testutil.ConfigFromMap(t, m, expectedManifestName)
145+
146+
testutil.JSONPathExists(t, gotConfig, jsonPath, errExpected)
147+
}

pkg/components/internal/testutil/common.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,33 @@ import (
2121

2222
"github.com/kinvolk/lokomotive/pkg/components"
2323
"github.com/kinvolk/lokomotive/pkg/components/util"
24+
"github.com/kinvolk/lokomotive/pkg/k8sutil"
2425
)
2526

26-
// ConfigFromMap takes a map and a key and returns the value associated with the key. If the key
27-
// does not exist in that map, the function fails.
28-
func ConfigFromMap(t *testing.T, m map[string]string, k string) string {
29-
ret, ok := m[k]
30-
if !ok {
31-
t.Fatalf("Config not found with filename: %q", k)
27+
// ConfigFromMap takes a map and a key. The function returns the YAML object associated with the
28+
// key. If the key does not exist in that map, the function fails.
29+
func ConfigFromMap(t *testing.T, m map[string]string, key k8sutil.ObjectMetadata) string {
30+
for _, v := range m {
31+
splittedYAML, err := k8sutil.SplitYAMLDocuments(v)
32+
if err != nil {
33+
t.Fatalf("Splitting YAML doc separated by '---': %v", err)
34+
}
35+
36+
for _, val := range splittedYAML {
37+
obj, err := k8sutil.YAMLToObjectMetadata(val)
38+
if err != nil {
39+
t.Fatalf("Converting YAML to ObjectMetadata: %v", err)
40+
}
41+
42+
if obj == key {
43+
return val
44+
}
45+
}
3246
}
3347

34-
return ret
48+
t.Fatalf("Given object not found: %+v", key)
49+
50+
return ""
3551
}
3652

3753
// RenderManifests converts a component into YAML manifests.

0 commit comments

Comments
 (0)