Skip to content

How to use kube::Api::create with raw string YAMLs? #1564

Answered by clux
mati865 asked this question in Q&A
Discussion options

You must be logged in to vote

if the yaml are arbitrary resources, then you'd probably want to use the dynamic api.

Take a look at the kubectl example in the apply section:

kube/examples/kubectl.rs

Lines 156 to 181 in 7ff120a

async fn apply(&self, client: Client, discovery: &Discovery) -> Result<()> {
let ssapply = PatchParams::apply("kubectl-light").force();
let pth = self.file.clone().expect("apply needs a -f file supplied");
let yaml =
std::fs::read_to_string(&pth).with_context(|| format!("Failed to read {}", pth.display()))?;
for doc in multidoc_deserialize(&yaml)? {
let obj: DynamicObject = serde_yaml::from_value(doc)?;
let namespace = obj.metadata.namespace.as_deref().

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mati865
Comment options

@clux
Comment options

Answer selected by mati865
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants