Skip to content

Commit

Permalink
Rename some variables
Browse files Browse the repository at this point in the history
Signed-off-by: Wenjie Ma <[email protected]>
  • Loading branch information
euclidgame committed Jul 26, 2023
1 parent 7c1eccf commit a0e752a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
14 changes: 7 additions & 7 deletions src/controller_examples/zookeeper_controller/exec/reconciler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ pub struct ZookeeperReconcileState {
// reconcile_step, like a program counter, is used to track the progress of reconcile_core
// since reconcile_core is frequently "trapped" into the controller_runtime spec.
pub reconcile_step: ZookeeperReconcileStep,
pub old_sts: Option<StatefulSet>,
pub sts_from_get: Option<StatefulSet>,
}

impl ZookeeperReconcileState {
pub open spec fn to_view(&self) -> zk_spec::ZookeeperReconcileState {
zk_spec::ZookeeperReconcileState {
reconcile_step: self.reconcile_step,
old_sts: match &self.old_sts {
sts_from_get: match &self.sts_from_get {
Some(sts) => Option::Some(sts@),
None => Option::None,
},
Expand Down Expand Up @@ -73,7 +73,7 @@ pub fn reconcile_init_state() -> (state: ZookeeperReconcileState)
{
ZookeeperReconcileState {
reconcile_step: ZookeeperReconcileStep::Init,
old_sts: Option::None,
sts_from_get: Option::None,
}
}

Expand Down Expand Up @@ -186,7 +186,7 @@ pub fn reconcile_core(
if found_stateful_set.is_ok(){
let state_prime = ZookeeperReconcileState {
reconcile_step: ZookeeperReconcileStep::AfterUpdateZKNode,
old_sts: Some(found_stateful_set.unwrap()),
sts_from_get: Some(found_stateful_set.unwrap()),
..state
};
let path = cluster_size_zk_node_path(zk);
Expand Down Expand Up @@ -252,8 +252,8 @@ pub fn reconcile_core(
// update sts
if resp_o.is_some() && resp_o.as_ref().unwrap().is_external_response()
&& resp_o.as_ref().unwrap().as_external_response_ref().is_reconcile_zk_node()
&& state.old_sts.is_some() {
let found_stateful_set = state.old_sts;
&& state.sts_from_get.is_some() {
let found_stateful_set = state.sts_from_get;
let mut new_stateful_set = found_stateful_set.unwrap();
let stateful_set = make_stateful_set(zk);
new_stateful_set.set_spec(stateful_set.spec().unwrap());
Expand All @@ -265,7 +265,7 @@ pub fn reconcile_core(
});
let state_prime = ZookeeperReconcileState {
reconcile_step: ZookeeperReconcileStep::AfterUpdateStatefulSet,
old_sts: Option::None
sts_from_get: Option::None
};
return (state_prime, Option::Some(Request::KRequest(req_o)));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,35 @@ pub fn reconcile_zk_node(path: String, uri: String, replicas: String) -> ZKNodeR
match path_look_up {
Some(_) => {
// Update the cluster size
if zk_client
.set_data(
if zk_client.set_data(
path.as_rust_string_ref(),
new_strlit("CLUSTER_SIZE=").to_string().concat(replicas.as_str())
.as_str()
.into_rust_str()
.as_bytes()
.to_vec(),
Some(-1),
).is_err() {
return ZKNodeResult{ res: Err(Error::ClusterSizeZKNodeUpdateFailed)};
}
return ZKNodeResult{ res: Ok(())};
)
.is_err() {
return ZKNodeResult{ res: Err(Error::ClusterSizeZKNodeUpdateFailed) };
}
return ZKNodeResult{ res: Ok(()) };
},
None => {
// First create the parent node
if zk_client
.create(
if zk_client.create(
"/zookeeper-operator",
new_strlit("")
.into_rust_str()
.as_bytes()
.to_vec(),
Acl::open_unsafe().clone(),
CreateMode::Persistent,
).is_err() {
)
.is_err() {
return ZKNodeResult{ res: Err(Error::ClusterSizeZKNodeCreationFailed) };
}
if zk_client
.create(
if zk_client.create(
path.as_rust_string_ref(),
new_strlit("CLUSTER_SIZE=").to_string().concat(replicas.as_str())
.as_str()
Expand All @@ -76,8 +75,9 @@ pub fn reconcile_zk_node(path: String, uri: String, replicas: String) -> ZKNodeR
.to_vec(),
Acl::open_unsafe().clone(),
CreateMode::Persistent,
).is_err() {
return ZKNodeResult{ res: Err(Error::ClusterSizeZKNodeCreationFailed)};
)
.is_err() {
return ZKNodeResult{ res: Err(Error::ClusterSizeZKNodeCreationFailed) };
}
return ZKNodeResult{ res: Ok(()) };
}
Expand Down
12 changes: 6 additions & 6 deletions src/controller_examples/zookeeper_controller/spec/reconciler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ verus! {

pub struct ZookeeperReconcileState {
pub reconcile_step: ZookeeperReconcileStep,
pub old_sts: Option<StatefulSetView>,
pub sts_from_get: Option<StatefulSetView>,
}

pub struct ZookeeperReconciler {}
Expand Down Expand Up @@ -56,7 +56,7 @@ impl Reconciler<ZookeeperClusterView> for ZookeeperReconciler {
pub open spec fn reconcile_init_state() -> ZookeeperReconcileState {
ZookeeperReconcileState {
reconcile_step: ZookeeperReconcileStep::Init,
old_sts: Option::None,
sts_from_get: Option::None,
}
}

Expand Down Expand Up @@ -155,7 +155,7 @@ pub open spec fn reconcile_core(
let found_stateful_set = StatefulSetView::from_dynamic_object(get_sts_resp.get_Ok_0()).get_Ok_0();
let state_prime = ZookeeperReconcileState {
reconcile_step: ZookeeperReconcileStep::AfterUpdateZKNode,
old_sts: Option::Some(found_stateful_set),
sts_from_get: Option::Some(found_stateful_set),
..state
};
let ext_req = ZKSupportInputView::ReconcileZKNode(
Expand Down Expand Up @@ -218,15 +218,15 @@ pub open spec fn reconcile_core(
ZookeeperReconcileStep::AfterUpdateZKNode => {
if resp_o.is_Some() && resp_o.get_Some_0().is_ExternalResponse()
&& resp_o.get_Some_0().get_ExternalResponse_0().is_ReconcileZKNode()
&& state.old_sts.is_Some(){
let found_stateful_set = state.old_sts.get_Some_0();
&& state.sts_from_get.is_Some(){
let found_stateful_set = state.sts_from_get.get_Some_0();
let req_o = APIRequest::UpdateRequest(UpdateRequest {
key: make_stateful_set_key(zk.object_ref()),
obj: update_stateful_set(zk, found_stateful_set).to_dynamic_object(),
});
let state_prime = ZookeeperReconcileState {
reconcile_step: ZookeeperReconcileStep::AfterUpdateStatefulSet,
old_sts: Option::None,
sts_from_get: Option::None,
};
(state_prime, Option::Some(RequestView::KRequest(req_o)))
} else {
Expand Down

0 comments on commit a0e752a

Please sign in to comment.