Skip to content

Commit

Permalink
models/yamlgen: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jpculp committed Oct 4, 2022
1 parent 043bc41 commit e1c5818
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
16 changes: 6 additions & 10 deletions models/src/node/crd/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,13 @@ impl BottlerocketShadowState {
impl From<BottlerocketShadowStateV1> for BottlerocketShadowState {
fn from(previous_state: BottlerocketShadowStateV1) -> Self {
// TODO: Remap the state when merge PR with preventing controller from being unscheduled
let new_state = match previous_state {
match previous_state {
BottlerocketShadowStateV1::Idle => Self::Idle,
BottlerocketShadowStateV1::StagedUpdate => Self::StagedAndPerformedUpdate,
BottlerocketShadowStateV1::PerformedUpdate => Self::StagedAndPerformedUpdate,
BottlerocketShadowStateV1::RebootedIntoUpdate => Self::RebootedIntoUpdate,
BottlerocketShadowStateV1::MonitoringUpdate => Self::MonitoringUpdate,
};
new_state
}
}
}

Expand Down Expand Up @@ -290,13 +289,11 @@ impl From<BottleRocketShadowV1> for BottlerocketShadow {
let previous_spec = previous_shadow.spec;
let previous_status = previous_shadow.status;

let status = match previous_status {
None => None,
Some(previous_status) => Some(BottlerocketShadowStatus::from(previous_status)),
};
let status = previous_status.map(BottlerocketShadowStatus::from);

let spec = BottlerocketShadowSpec::from(previous_spec);
let new_shadow = BottlerocketShadow {

BottlerocketShadow {
metadata: ObjectMeta {
/// The converted object has to maintain the same name, namespace and uid
name: previous_metadata.name,
Expand All @@ -307,8 +304,7 @@ impl From<BottleRocketShadowV1> for BottlerocketShadow {
},
spec,
status,
};
new_shadow
}
}
}

Expand Down
15 changes: 7 additions & 8 deletions models/src/node/drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ pub(crate) async fn drain_node(
stream::iter(target_pods)
.for_each_concurrent(CONCURRENT_EVICTIONS, move |pod| {
let k8s_client = k8s_client.clone();
let pod = pod.clone();
async move {
// If an eviction for a Pod fails, it's either because:
// * The eviction would never succeed (the Pod doesn't exist, we lack permissions to evict them, etc)
Expand Down Expand Up @@ -169,7 +168,7 @@ fn filter_pods<F: Iterator<Item = Pod>>(pods: F) -> impl Iterator<Item = Pod> {
}
}

return true;
true
})
}

Expand Down Expand Up @@ -226,7 +225,7 @@ async fn evict_pod(k8s_client: &kube::Client, pod: &Pod) -> Result<(), error::Ev
Ok(StatusCode::NOT_FOUND) => {
return Err(error::EvictionError::NonRetriableEviction {
source: kube::Error::Api(e.clone()),
pod_name: pod.name().to_string(),
pod_name: pod.name(),
});
}
Ok(StatusCode::FORBIDDEN) => {
Expand All @@ -235,7 +234,7 @@ async fn evict_pod(k8s_client: &kube::Client, pod: &Pod) -> Result<(), error::Ev
// API error statuses to determine if we can proceed, so we ignore these.
return Err(error::EvictionError::NonRetriableEviction {
source: kube::Error::Api(e.clone()),
pod_name: pod.name().to_string(),
pod_name: pod.name(),
});
}
Ok(_) => {
Expand All @@ -247,7 +246,7 @@ async fn evict_pod(k8s_client: &kube::Client, pod: &Pod) -> Result<(), error::Ev
);
return Err(error::EvictionError::RetriableEviction {
source: kube::Error::Api(e.clone()),
pod_name: pod.name().to_string(),
pod_name: pod.name(),
});
}
Err(_) => {
Expand All @@ -258,7 +257,7 @@ async fn evict_pod(k8s_client: &kube::Client, pod: &Pod) -> Result<(), error::Ev
);
return Err(error::EvictionError::RetriableEviction {
source: kube::Error::Api(e.clone()),
pod_name: pod.name().to_string(),
pod_name: pod.name(),
});
}
}
Expand All @@ -267,7 +266,7 @@ async fn evict_pod(k8s_client: &kube::Client, pod: &Pod) -> Result<(), error::Ev
event!(Level::ERROR, "Eviction failed: '{}'. Retrying...", e);
return Err(error::EvictionError::RetriableEviction {
source: e,
pod_name: pod.name().to_string(),
pod_name: pod.name(),
});
}
}
Expand Down Expand Up @@ -328,7 +327,7 @@ async fn wait_for_deletion(k8s_client: &kube::Client, pod: &Pod) -> Result<(), e
/// Creates a kube::Api<Pod> for interacting with Pods in the namespace associated with the given Pod.
fn namespaced_pod_api(k8s_client: &kube::Client, pod: &Pod) -> Api<Pod> {
match pod.metadata.namespace.as_ref() {
Some(ns) => Api::namespaced(k8s_client.clone(), &ns),
Some(ns) => Api::namespaced(k8s_client.clone(), ns),
None => Api::default_namespaced(k8s_client.clone()),
}
}
Expand Down
6 changes: 3 additions & 3 deletions yamlgen/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn main() {
.to_lowercase();
// Make sure it is integer if it is not "unlimited"
if !max_concurrent_update.eq("unlimited") {
max_concurrent_update.clone().parse::<usize>().unwrap();
max_concurrent_update.parse::<usize>().unwrap();
}
serde_yaml::to_writer(&brupop_resources, &brupop_namespace()).unwrap();

Expand Down Expand Up @@ -109,8 +109,8 @@ fn main() {
serde_yaml::to_writer(
&brupop_resources,
&controller_deployment(
brupop_image.clone(),
brupop_image_pull_secrets.clone(),
brupop_image,
brupop_image_pull_secrets,
max_concurrent_update,
),
)
Expand Down

0 comments on commit e1c5818

Please sign in to comment.