Skip to content

Commit 3afaf4f

Browse files
authored
Handle empty YAML documents in v1 API conversion (#12326)
Signed-off-by: Jakub Scholz <www@scholzj.com>
1 parent daa9965 commit 3afaf4f

File tree

10 files changed

+246
-2
lines changed

10 files changed

+246
-2
lines changed

v1-api-conversion/src/main/java/io/strimzi/kafka/api/conversion/v1/cli/ConvertFileCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ protected String run(byte[] data) throws IOException {
9494
for (JsonNode doc : docs) {
9595
JsonNode result;
9696

97-
if (isStrimziResource(doc)) {
97+
if (doc.isNull() || doc.isEmpty()) {
98+
continue;
99+
} else if (isStrimziResource(doc)) {
98100
result = run(doc);
99101
} else {
100102
result = doc;

v1-api-conversion/src/test/java/io/strimzi/kafka/api/conversion/v1/cli/ConvertFileCommandTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ private static Stream<Arguments> correctSamples() {
171171
Arguments.of("mm2-many-mirrors.yaml", "mm2-many-mirrors.out"),
172172
Arguments.of("kafka-v1beta2.yaml", "kafka-v1beta2.out"),
173173
Arguments.of("kafka-all-out.yaml", "kafka-all-out.out"),
174-
Arguments.of("kafka-up-to-date.yaml", "kafka-up-to-date.out")
174+
Arguments.of("kafka-up-to-date.yaml", "kafka-up-to-date.out"),
175+
Arguments.of("empty-yaml.yaml", "empty-yaml.out"),
176+
Arguments.of("empty-yaml-with-doc-marker.yaml", "empty-yaml-with-doc-marker.out"),
177+
Arguments.of("strimzi-resource-with-empty-document.yaml", "strimzi-resource-with-empty-document.out"),
178+
Arguments.of("strimzi-resource-with-kubernetes-resource-and-empty-document.yaml", "strimzi-resource-with-kubernetes-resource-and-empty-document.out")
175179
);
176180
}
177181

v1-api-conversion/src/test/resources/io/strimzi/kafka/api/conversion/v1/cli/empty-yaml-with-doc-marker.out

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
---

v1-api-conversion/src/test/resources/io/strimzi/kafka/api/conversion/v1/cli/empty-yaml.out

Whitespace-only changes.

v1-api-conversion/src/test/resources/io/strimzi/kafka/api/conversion/v1/cli/empty-yaml.yaml

Whitespace-only changes.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
apiVersion: kafka.strimzi.io/v1
3+
kind: KafkaUser
4+
metadata:
5+
name: my-user
6+
labels:
7+
strimzi.io/cluster: my-cluster
8+
spec:
9+
authentication:
10+
type: tls
11+
authorization:
12+
type: simple
13+
acls:
14+
- resource:
15+
type: topic
16+
name: my-topic
17+
operations:
18+
- Read
19+
- resource:
20+
type: topic
21+
name: my-topic
22+
operations:
23+
- Describe
24+
- resource:
25+
type: group
26+
name: my-group
27+
operations:
28+
- Read
29+
- resource:
30+
type: topic
31+
name: my-topic
32+
operations:
33+
- Write
34+
- resource:
35+
type: topic
36+
name: my-topic
37+
operations:
38+
- Create
39+
- resource:
40+
type: topic
41+
name: my-topic
42+
operations:
43+
- Describe
44+
- resource:
45+
type: transactionalId
46+
name: schema-registry-
47+
patternType: prefix
48+
operations:
49+
- Describe
50+
- resource:
51+
type: transactionalId
52+
name: schema-registry-
53+
patternType: prefix
54+
operations:
55+
- Write
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
apiVersion: kafka.strimzi.io/v1beta2
2+
kind: KafkaUser
3+
metadata:
4+
name: my-user
5+
labels:
6+
strimzi.io/cluster: my-cluster
7+
spec:
8+
authentication:
9+
type: tls
10+
authorization:
11+
type: simple
12+
acls:
13+
# Example consumer Acls for topic my-topic using consumer group my-group
14+
- resource:
15+
type: topic
16+
name: my-topic
17+
patternType: literal
18+
operation: Read
19+
- resource:
20+
type: topic
21+
name: my-topic
22+
patternType: literal
23+
operation: Describe
24+
- resource:
25+
type: group
26+
name: my-group
27+
patternType: literal
28+
operation: Read
29+
# Example Producer Acls for topic my-topic
30+
- resource:
31+
type: topic
32+
name: my-topic
33+
patternType: literal
34+
operation: Write
35+
- resource:
36+
type: topic
37+
name: my-topic
38+
patternType: literal
39+
operation: Create
40+
- resource:
41+
type: topic
42+
name: my-topic
43+
patternType: literal
44+
operation: Describe
45+
# transactionalId resources
46+
- resource:
47+
type: transactionalId
48+
name: schema-registry-
49+
patternType: prefix
50+
operation: Describe
51+
- resource:
52+
type: transactionalId
53+
name: schema-registry-
54+
patternType: prefix
55+
operation: Write
56+
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
apiVersion: kafka.strimzi.io/v1
3+
kind: KafkaUser
4+
metadata:
5+
name: my-user
6+
labels:
7+
strimzi.io/cluster: my-cluster
8+
spec:
9+
authentication:
10+
type: tls
11+
authorization:
12+
type: simple
13+
acls:
14+
- resource:
15+
type: topic
16+
name: my-topic
17+
operations:
18+
- Read
19+
- resource:
20+
type: topic
21+
name: my-topic
22+
operations:
23+
- Describe
24+
- resource:
25+
type: group
26+
name: my-group
27+
operations:
28+
- Read
29+
- resource:
30+
type: topic
31+
name: my-topic
32+
operations:
33+
- Write
34+
- resource:
35+
type: topic
36+
name: my-topic
37+
operations:
38+
- Create
39+
- resource:
40+
type: topic
41+
name: my-topic
42+
operations:
43+
- Describe
44+
- resource:
45+
type: transactionalId
46+
name: schema-registry-
47+
patternType: prefix
48+
operations:
49+
- Describe
50+
- resource:
51+
type: transactionalId
52+
name: schema-registry-
53+
patternType: prefix
54+
operations:
55+
- Write
56+
---
57+
apiVersion: v1
58+
kind: ConfigMap
59+
metadata:
60+
name: connector-configuration
61+
data:
62+
hello: world
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
apiVersion: kafka.strimzi.io/v1beta2
2+
kind: KafkaUser
3+
metadata:
4+
name: my-user
5+
labels:
6+
strimzi.io/cluster: my-cluster
7+
spec:
8+
authentication:
9+
type: tls
10+
authorization:
11+
type: simple
12+
acls:
13+
# Example consumer Acls for topic my-topic using consumer group my-group
14+
- resource:
15+
type: topic
16+
name: my-topic
17+
patternType: literal
18+
operation: Read
19+
- resource:
20+
type: topic
21+
name: my-topic
22+
patternType: literal
23+
operation: Describe
24+
- resource:
25+
type: group
26+
name: my-group
27+
patternType: literal
28+
operation: Read
29+
# Example Producer Acls for topic my-topic
30+
- resource:
31+
type: topic
32+
name: my-topic
33+
patternType: literal
34+
operation: Write
35+
- resource:
36+
type: topic
37+
name: my-topic
38+
patternType: literal
39+
operation: Create
40+
- resource:
41+
type: topic
42+
name: my-topic
43+
patternType: literal
44+
operation: Describe
45+
# transactionalId resources
46+
- resource:
47+
type: transactionalId
48+
name: schema-registry-
49+
patternType: prefix
50+
operation: Describe
51+
- resource:
52+
type: transactionalId
53+
name: schema-registry-
54+
patternType: prefix
55+
operation: Write
56+
---
57+
58+
apiVersion: v1
59+
kind: ConfigMap
60+
metadata:
61+
name: connector-configuration
62+
data:
63+
hello: "world"
64+
---

0 commit comments

Comments
 (0)