diff --git a/kube-core/src/params.rs b/kube-core/src/params.rs index 19461ce75..c608728db 100644 --- a/kube-core/src/params.rs +++ b/kube-core/src/params.rs @@ -183,6 +183,15 @@ pub struct PostParams { } impl PostParams { + pub(crate) fn populate_qp(&self, qp: &mut form_urlencoded::Serializer) { + if self.dry_run { + qp.append_pair("dryRun", "All"); + } + if let Some(ref fm) = self.field_manager { + qp.append_pair("fieldManager", fm); + } + } + pub(crate) fn validate(&self) -> Result<(), Error> { if let Some(field_manager) = &self.field_manager { // Implement the easy part of validation, in future this may be extended to provide validation as in go code diff --git a/kube-core/src/request.rs b/kube-core/src/request.rs index 40b9ee61b..f82c0be55 100644 --- a/kube-core/src/request.rs +++ b/kube-core/src/request.rs @@ -115,9 +115,7 @@ impl Request { pp.validate()?; let target = format!("{}?", self.url_path); let mut qp = form_urlencoded::Serializer::new(target); - if pp.dry_run { - qp.append_pair("dryRun", "All"); - } + pp.populate_qp(&mut qp); let urlstr = qp.finish(); let req = http::Request::post(urlstr).header(http::header::CONTENT_TYPE, JSON_MIME); req.body(data).map_err(Error::BuildRequest) @@ -192,9 +190,7 @@ impl Request { ) -> Result>, Error> { let target = format!("{}/{}?", self.url_path, name); let mut qp = form_urlencoded::Serializer::new(target); - if pp.dry_run { - qp.append_pair("dryRun", "All"); - } + pp.populate_qp(&mut qp); let urlstr = qp.finish(); let req = http::Request::put(urlstr).header(http::header::CONTENT_TYPE, JSON_MIME); req.body(data).map_err(Error::BuildRequest) @@ -226,9 +222,7 @@ impl Request { ) -> Result>, Error> { let target = format!("{}/{}/{}?", self.url_path, name, subresource_name); let mut qp = form_urlencoded::Serializer::new(target); - if pp.dry_run { - qp.append_pair("dryRun", "All"); - } + pp.populate_qp(&mut qp); let urlstr = qp.finish(); let req = http::Request::post(urlstr).header(http::header::CONTENT_TYPE, JSON_MIME); req.body(data).map_err(Error::BuildRequest) @@ -265,9 +259,7 @@ impl Request { ) -> Result>, Error> { let target = format!("{}/{}/{}?", self.url_path, name, subresource_name); let mut qp = form_urlencoded::Serializer::new(target); - if pp.dry_run { - qp.append_pair("dryRun", "All"); - } + pp.populate_qp(&mut qp); let urlstr = qp.finish(); let req = http::Request::put(urlstr).header(http::header::CONTENT_TYPE, JSON_MIME); req.body(data).map_err(Error::BuildRequest) diff --git a/kube-core/src/subresource.rs b/kube-core/src/subresource.rs index ae180d7df..ef527807d 100644 --- a/kube-core/src/subresource.rs +++ b/kube-core/src/subresource.rs @@ -102,9 +102,7 @@ impl Request { let pp = &ep.post_options; pp.validate()?; let mut qp = form_urlencoded::Serializer::new(target); - if pp.dry_run { - qp.append_pair("dryRun", "All"); - } + pp.populate_qp(&mut qp); let urlstr = qp.finish(); // eviction body parameters are awkward, need metadata with name let data = serde_json::to_vec(&serde_json::json!({