Skip to content

Commit

Permalink
Fix apply Action within Example kubectl (#1216)
Browse files Browse the repository at this point in the history
* fix kubectl apply with namespaced resource yaml file

Signed-off-by: ZhengSheng0524 <j13tw@yahoo.com.tw>

* Update examples/kubectl.rs

Co-authored-by: Eirik A <sszynrae@gmail.com>
Signed-off-by: Sheng Zheng <s1410432021@nutc.edu.tw>

* fix suggestion code

Signed-off-by: ZhengSheng0524 <j13tw@yahoo.com.tw>

---------

Signed-off-by: ZhengSheng0524 <j13tw@yahoo.com.tw>
Signed-off-by: Sheng Zheng <s1410432021@nutc.edu.tw>
Co-authored-by: Eirik A <sszynrae@gmail.com>
  • Loading branch information
j13tw and clux authored May 19, 2023
1 parent 311f588 commit 49d33ec
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion examples/kubectl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,15 @@ impl App {
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.clone().or_else(|| self.namespace.clone());
let gvk = if let Some(tm) = &obj.types {
GroupVersionKind::try_from(tm)?
} else {
bail!("cannot apply object without valid TypeMeta {:?}", obj);
};
let name = obj.name_any();
if let Some((ar, caps)) = discovery.resolve_gvk(&gvk) {
let api = dynamic_api(ar, caps, client.clone(), &self.namespace, false);
let api = dynamic_api(ar, caps, client.clone(), &namespace, false);
trace!("Applying {}: \n{}", gvk.kind, serde_yaml::to_string(&obj)?);
let data: serde_json::Value = serde_json::to_value(&obj)?;
let _r = api.patch(&name, &ssapply, &Patch::Apply(data)).await?;
Expand Down

0 comments on commit 49d33ec

Please sign in to comment.