-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add Yaml.createResource() for type-agnostic resource creation from YAML #4427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…ry YAML Co-authored-by: brendandburns <[email protected]>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Copilot 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 |
1 similar comment
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Copilot 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 |
Co-authored-by: brendandburns <[email protected]>
Co-authored-by: brendandburns <[email protected]>
brendandburns
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Generally looks good. Please remove the markdown doc which is unnecessary and address this comment.
| // Load the YAML into the strongly typed object | ||
| // Note: This double-loading approach (first as Map, then as typed object) follows the | ||
| // design recommended in the issue discussion to properly handle type determination | ||
| Object resource = loadAs(new StringReader(getSnakeYaml(clazz).dump(data)), clazz); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Load the Reader into a byte array at the beginning of this function and use the same byte array in both cases vs dumping it back out to YAML.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 1caa15d. Now reads the Reader into a string buffer first and uses the same content for both parsing (to extract apiVersion/kind) and loading into the typed object.
…ve docs Co-authored-by: brendandburns <[email protected]>
Implement YAML resource creation without type differentiation
This PR addresses the issue of submitting arbitrary YAML resources to Kubernetes without having to differentiate between Kind types, similar to
kubectl create -f file.yaml.Implementation Complete
Yaml.createResource()methods that accept arbitrary YAML and creates resources using the generic clientTechnical Implementation
The solution implements three new public methods in the
Yamlclass:Yaml.createResource(ApiClient, String)- Create from YAML stringYaml.createResource(ApiClient, File)- Create from YAML fileYaml.createResource(ApiClient, Reader)- Create from YAML streamThese methods:
Usage Example
Original prompt
💡 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.