Skip to content

Commit d11e516

Browse files
Apply code formatting fixes with google-java-format
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
1 parent 1caa15d commit d11e516

File tree

4 files changed

+42
-38
lines changed

4 files changed

+42
-38
lines changed

examples/examples-release-latest/src/main/java/io/kubernetes/client/examples/YamlCreateResourceExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static void main(String[] args) throws IOException, ApiException {
9898
System.out.println("\nCleaning up...");
9999
api.deleteNamespacedConfigMap("example-config", "default").execute();
100100
System.out.println("Deleted ConfigMap");
101-
101+
102102
api.deleteNamespacedPod("example-pod", "default").execute();
103103
System.out.println("Deleted Pod");
104104
}

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.slf4j.Logger;
4040
import org.slf4j.LoggerFactory;
4141
import org.yaml.snakeyaml.DumperOptions;
42-
import org.yaml.snakeyaml.DumperOptions.FlowStyle;
4342
import org.yaml.snakeyaml.LoaderOptions;
4443
import org.yaml.snakeyaml.TypeDescription;
4544
import org.yaml.snakeyaml.constructor.BaseConstructor;
@@ -367,7 +366,7 @@ protected NodeTuple representJavaBeanProperty(
367366
if (propertyValue == null) {
368367
return null;
369368
}
370-
if (propertyValue instanceof List<?> && ((List<?>)propertyValue).size() == 0) {
369+
if (propertyValue instanceof List<?> && ((List<?>) propertyValue).size() == 0) {
371370
return null;
372371
}
373372
return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
@@ -575,6 +574,7 @@ public static void addModelMap(String apiGroupVersion, String kind, Class<?> cla
575574
* <p>This is equivalent to `kubectl create -f <yaml-content>`.
576575
*
577576
* <p>Example usage:
577+
*
578578
* <pre>{@code
579579
* ApiClient client = Config.defaultClient();
580580
* String yaml = "apiVersion: v1\n" +
@@ -589,7 +589,8 @@ public static void addModelMap(String apiGroupVersion, String kind, Class<?> cla
589589
* @param content The YAML content as a string
590590
* @return The created resource object
591591
* @throws IOException If an error occurs while reading or parsing the YAML
592-
* @throws io.kubernetes.client.openapi.ApiException If an error occurs while creating the resource in the cluster
592+
* @throws io.kubernetes.client.openapi.ApiException If an error occurs while creating the
593+
* resource in the cluster
593594
*/
594595
public static Object createResource(io.kubernetes.client.openapi.ApiClient client, String content)
595596
throws IOException, io.kubernetes.client.openapi.ApiException {
@@ -607,7 +608,8 @@ public static Object createResource(io.kubernetes.client.openapi.ApiClient clien
607608
* @param f The YAML file to load
608609
* @return The created resource object
609610
* @throws IOException If an error occurs while reading or parsing the YAML
610-
* @throws io.kubernetes.client.openapi.ApiException If an error occurs while creating the resource in the cluster
611+
* @throws io.kubernetes.client.openapi.ApiException If an error occurs while creating the
612+
* resource in the cluster
611613
*/
612614
public static Object createResource(io.kubernetes.client.openapi.ApiClient client, File f)
613615
throws IOException, io.kubernetes.client.openapi.ApiException {
@@ -625,7 +627,8 @@ public static Object createResource(io.kubernetes.client.openapi.ApiClient clien
625627
* @param reader The stream to load
626628
* @return The created resource object
627629
* @throws IOException If an error occurs while reading or parsing the YAML
628-
* @throws io.kubernetes.client.openapi.ApiException If an error occurs while creating the resource in the cluster
630+
* @throws io.kubernetes.client.openapi.ApiException If an error occurs while creating the
631+
* resource in the cluster
629632
*/
630633
public static Object createResource(io.kubernetes.client.openapi.ApiClient client, Reader reader)
631634
throws IOException, io.kubernetes.client.openapi.ApiException {
@@ -642,7 +645,7 @@ public static Object createResource(io.kubernetes.client.openapi.ApiClient clien
642645
// Note: The getSnakeYaml() method already configures LoaderOptions with appropriate
643646
// security settings to prevent YAML bombs and other attacks
644647
Map<String, Object> data = getSnakeYaml(null).load(new StringReader(yamlContent));
645-
648+
646649
String kind = (String) data.get("kind");
647650
if (kind == null) {
648651
throw new IOException("Missing kind in YAML!");
@@ -664,8 +667,7 @@ public static Object createResource(io.kubernetes.client.openapi.ApiClient clien
664667

665668
// Ensure the resource is a KubernetesObject
666669
if (!(resource instanceof io.kubernetes.client.common.KubernetesObject)) {
667-
throw new IOException(
668-
"Resource is not a KubernetesObject: " + resource.getClass().getName());
670+
throw new IOException("Resource is not a KubernetesObject: " + resource.getClass().getName());
669671
}
670672

671673
io.kubernetes.client.common.KubernetesObject k8sObject =
@@ -678,13 +680,13 @@ public static Object createResource(io.kubernetes.client.openapi.ApiClient clien
678680
// Get the resource metadata to determine the plural name
679681
io.kubernetes.client.apimachinery.GroupVersionResource gvr =
680682
ModelMapper.getGroupVersionResourceByClass(clazz);
681-
683+
682684
if (gvr == null) {
683685
// If no GVR mapping exists, we need to perform discovery
684686
io.kubernetes.client.Discovery discovery = new io.kubernetes.client.Discovery(client);
685687
ModelMapper.refresh(discovery);
686688
gvr = ModelMapper.getGroupVersionResourceByClass(clazz);
687-
689+
688690
if (gvr == null) {
689691
throw new IOException(
690692
"Unable to determine resource plural name for " + apiVersion + "/" + kind);
@@ -708,7 +710,7 @@ public static Object createResource(io.kubernetes.client.openapi.ApiClient clien
708710
io.kubernetes.client.util.generic.KubernetesApiResponse<
709711
io.kubernetes.client.common.KubernetesObject>
710712
response;
711-
713+
712714
Boolean isNamespaced = ModelMapper.isNamespaced(clazz);
713715
if (isNamespaced != null && isNamespaced) {
714716
// For namespaced resources
@@ -717,16 +719,18 @@ public static Object createResource(io.kubernetes.client.openapi.ApiClient clien
717719
// Default to "default" namespace, matching kubectl behavior
718720
namespace = "default";
719721
}
720-
response = api.create(namespace, k8sObject, new io.kubernetes.client.util.generic.options.CreateOptions());
722+
response =
723+
api.create(
724+
namespace, k8sObject, new io.kubernetes.client.util.generic.options.CreateOptions());
721725
} else {
722726
// For cluster-scoped resources
723-
response = api.create(k8sObject, new io.kubernetes.client.util.generic.options.CreateOptions());
727+
response =
728+
api.create(k8sObject, new io.kubernetes.client.util.generic.options.CreateOptions());
724729
}
725730

726731
if (!response.isSuccess()) {
727732
throw new io.kubernetes.client.openapi.ApiException(
728-
response.getHttpStatusCode(),
729-
"Failed to create resource: " + response.getStatus());
733+
response.getHttpStatusCode(), "Failed to create resource: " + response.getStatus());
730734
}
731735

732736
return response.getObject();

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
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;
2625
import java.io.File;
2726
import java.io.IOException;
2827
import java.nio.file.Files;

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

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void loadAllFile() throws Exception {
142142
assertThat(secret.getKind()).isEqualTo("Secret");
143143
assertThat(secret.getMetadata().getName()).isEqualTo("secret");
144144
assertThat(secret.getType()).isEqualTo("Opaque");
145-
assertThat( new String(secret.getData().get("secret-data"), UTF_8)).isEqualTo("hello");
145+
assertThat(new String(secret.getData().get("secret-data"), UTF_8)).isEqualTo("hello");
146146
k8ObjectList.add(secret);
147147
} else {
148148
throw new Exception("some thing wrong happened");
@@ -255,14 +255,15 @@ void loadDumpCRDWithIntOrStringExtension() {
255255
V1CustomResourceDefinition crd = Yaml.loadAs(data, V1CustomResourceDefinition.class);
256256
assertThat(crd).isNotNull();
257257
assertThat(
258-
crd.getSpec()
259-
.getVersions()
260-
.get(0)
261-
.getSchema()
262-
.getOpenAPIV3Schema()
263-
.getProperties()
264-
.get("foo")
265-
.getxKubernetesIntOrString()).isTrue();
258+
crd.getSpec()
259+
.getVersions()
260+
.get(0)
261+
.getSchema()
262+
.getOpenAPIV3Schema()
263+
.getProperties()
264+
.get("foo")
265+
.getxKubernetesIntOrString())
266+
.isTrue();
266267
String dumped = Yaml.dump(crd);
267268
assertThat(dumped).isEqualTo(data);
268269
}
@@ -272,25 +273,25 @@ void createResourceFromYaml() throws Exception {
272273
// This test validates that the createResource method can parse YAML
273274
// and determine the correct resource type without requiring the caller
274275
// to specify the type upfront.
275-
276-
String configMapYaml =
277-
"apiVersion: v1\n" +
278-
"kind: ConfigMap\n" +
279-
"metadata:\n" +
280-
" name: test-config\n" +
281-
" namespace: default\n" +
282-
"data:\n" +
283-
" key1: value1\n";
284-
276+
277+
String configMapYaml =
278+
"apiVersion: v1\n"
279+
+ "kind: ConfigMap\n"
280+
+ "metadata:\n"
281+
+ " name: test-config\n"
282+
+ " namespace: default\n"
283+
+ "data:\n"
284+
+ " key1: value1\n";
285+
285286
// Note: This test only validates that the YAML can be parsed and the
286287
// correct type is determined. It does not actually create the resource
287288
// in a cluster, as that would require a real or mocked API server.
288289
// The actual creation logic is tested in integration tests.
289-
290+
290291
// Test that we can load the YAML and determine the type
291292
Object obj = Yaml.load(configMapYaml);
292293
assertThat(obj).isInstanceOf(V1ConfigMap.class);
293-
294+
294295
V1ConfigMap configMap = (V1ConfigMap) obj;
295296
assertThat(configMap.getMetadata().getName()).isEqualTo("test-config");
296297
assertThat(configMap.getMetadata().getNamespace()).isEqualTo("default");

0 commit comments

Comments
 (0)