Skip to content

Commit

Permalink
add fieldManager querystring to all operations (#1031)
Browse files Browse the repository at this point in the history
* add fieldManager querystring to all operations

Signed-off-by: goenning <me@goenning.net>

* refactor post_params -> queryparam usage and use it on all operations

Signed-off-by: goenning <me@goenning.net>

Signed-off-by: goenning <me@goenning.net>
  • Loading branch information
goenning committed Sep 27, 2022
1 parent 2821378 commit de7afa5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
9 changes: 9 additions & 0 deletions kube-core/src/params.rs
Expand Up @@ -183,6 +183,15 @@ pub struct PostParams {
}

impl PostParams {
pub(crate) fn populate_qp(&self, qp: &mut form_urlencoded::Serializer<String>) {
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
Expand Down
16 changes: 4 additions & 12 deletions kube-core/src/request.rs
Expand Up @@ -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)
Expand Down Expand Up @@ -192,9 +190,7 @@ impl Request {
) -> Result<http::Request<Vec<u8>>, 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)
Expand Down Expand Up @@ -226,9 +222,7 @@ impl Request {
) -> Result<http::Request<Vec<u8>>, 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)
Expand Down Expand Up @@ -265,9 +259,7 @@ impl Request {
) -> Result<http::Request<Vec<u8>>, 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)
Expand Down
4 changes: 1 addition & 3 deletions kube-core/src/subresource.rs
Expand Up @@ -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!({
Expand Down

0 comments on commit de7afa5

Please sign in to comment.