Skip to content

Commit 7013d59

Browse files
Address code review comments - add clarifying comments and fix imports
Co-authored-by: brendandburns <[email protected]>
1 parent 90fb9d5 commit 7013d59

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

util/src/main/java/io/kubernetes/client/util/Yaml.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,8 @@ public static Object createResource(io.kubernetes.client.openapi.ApiClient clien
630630
public static Object createResource(io.kubernetes.client.openapi.ApiClient client, Reader reader)
631631
throws IOException, io.kubernetes.client.openapi.ApiException {
632632
// Load the YAML as a map to extract apiVersion and kind
633+
// Note: The getSnakeYaml() method already configures LoaderOptions with appropriate
634+
// security settings to prevent YAML bombs and other attacks
633635
Map<String, Object> data = getSnakeYaml(null).load(reader);
634636

635637
String kind = (String) data.get("kind");
@@ -649,6 +651,8 @@ public static Object createResource(io.kubernetes.client.openapi.ApiClient clien
649651
}
650652

651653
// Load the YAML into the strongly typed object
654+
// Note: This double-loading approach (first as Map, then as typed object) follows the
655+
// design recommended in the issue discussion to properly handle type determination
652656
Object resource = loadAs(new StringReader(getSnakeYaml(clazz).dump(data)), clazz);
653657

654658
// Ensure the resource is a KubernetesObject
@@ -703,6 +707,7 @@ public static Object createResource(io.kubernetes.client.openapi.ApiClient clien
703707
// For namespaced resources
704708
String namespace = k8sObject.getMetadata().getNamespace();
705709
if (namespace == null || namespace.isEmpty()) {
710+
// Default to "default" namespace, matching kubectl behavior
706711
namespace = "default";
707712
}
708713
response = api.create(namespace, k8sObject, new io.kubernetes.client.util.generic.options.CreateOptions());

util/src/test/java/io/kubernetes/client/util/YamlCreateResourceTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.kubernetes.client.openapi.models.V1ConfigMap;
2323
import io.kubernetes.client.openapi.models.V1Deployment;
2424
import io.kubernetes.client.openapi.models.V1Pod;
25+
import io.kubernetes.client.util.ClientBuilder;
2526
import java.io.File;
2627
import java.io.IOException;
2728
import java.nio.file.Files;

0 commit comments

Comments
 (0)