Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 21, 2025

Enables creating Kubernetes resources from arbitrary YAML without pre-specifying the resource type, equivalent to kubectl create -f file.yaml.

Changes

New API methods in Yaml class:

  • createResource(ApiClient, String) - from YAML string
  • createResource(ApiClient, File) - from YAML file
  • createResource(ApiClient, Reader) - from YAML stream

Implementation:

  1. Parse YAML as unstructured data to extract apiVersion and kind
  2. Use ModelMapper to resolve the strongly-typed Java class
  3. Deserialize YAML into that class
  4. Create resource via GenericKubernetesApi with discovered GVK/GVR
  5. Auto-discover resource metadata via API discovery when needed
  6. Default namespaced resources to default namespace if unspecified

Testing:

  • Added YamlCreateResourceTest with ConfigMap, Pod, and Deployment test cases
  • All existing tests pass (289 tests in util module)

Example

ApiClient client = Config.defaultClient();

String yaml = 
    "apiVersion: v1\n" +
    "kind: ConfigMap\n" +
    "metadata:\n" +
    "  name: my-config\n" +
    "data:\n" +
    "  key: value\n";

// No need to specify V1ConfigMap.class
Object resource = Yaml.createResource(client, yaml);

Before:

V1ConfigMap cm = Yaml.loadAs(yaml, V1ConfigMap.class);
new CoreV1Api().createNamespacedConfigMap("default", cm).execute();

After:

Yaml.createResource(client, yaml);  // Works for any resource type

Documentation

  • Added YamlCreateResourceExample.java with usage examples
  • Added docs/yaml-create-resource.md with comprehensive guide
Original prompt

This section details on the original issue you should resolve

<issue_title>how to submit a yaml like kubectl create -f file.yaml ?</issue_title>
<issue_description>Is there a method to submit YAML resources of any type to Kubernetes ?
What I mean is not having to differentiate between Kind types.</issue_description>

<agent_instructions>Extend the kubectl create implementation to take arbitrary yaml and use the generic client to create that resource</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@brendandburns This is not currently possible. You would need to modify the `Yaml` class here:

https://github.com/kubernetes-client/java/blob/master/util/src/main/java/io/kubernetes/client/util/Yaml.java

To load unstructured YAML and then pick out the API group/version/kind and then use the ModelMapper here:
https://github.com/kubernetes-client/java/blob/master/util/src/main/java/io/kubernetes/client/util/ModelMapper.java

To determine the right strongly typed object, and then use Yaml.load again to reload the YAML into that strongly typed object.

Then you would need to pass that object to a GenericApi handler that was configured with the group/version/kind that you found above.

So it's possible, but it will require you to write a bunch of code. If you do, do that, feel free to send a PR.</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 21, 2025
…ry YAML

Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Copilot
Once this PR has been reviewed and has the lgtm label, please ask for approval from brendandburns. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

1 similar comment
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Copilot
Once this PR has been reviewed and has the lgtm label, please ask for approval from brendandburns. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 21, 2025
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 21, 2025
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Copilot AI changed the title [WIP] Extend kubectl create to submit arbitrary YAML resources Add Yaml.createResource() for type-agnostic resource creation from YAML Nov 21, 2025
Copilot AI requested a review from brendandburns November 21, 2025 04:41
Copilot finished work on behalf of brendandburns November 21, 2025 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

how to submit a yaml like kubectl create -f file.yaml ?

3 participants