3939import org .slf4j .Logger ;
4040import org .slf4j .LoggerFactory ;
4141import org .yaml .snakeyaml .DumperOptions ;
42- import org .yaml .snakeyaml .DumperOptions .FlowStyle ;
4342import org .yaml .snakeyaml .LoaderOptions ;
4443import org .yaml .snakeyaml .TypeDescription ;
4544import 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 ();
0 commit comments