-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add liveness specification for VReplicaSet controller #497
Merged
marshtompsxd
merged 5 commits into
anvil-verifier:main
from
xlab-uiuc:cody/specify-replica-set
Jun 7, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dfcac2b
Write basic liveness theorem for VReplicaSet
codyjrivera 12ca92d
Fix typo
codyjrivera 00c7428
Filter out objects that aren't pods
codyjrivera 93aff3a
Add liveness theorem to modules (+ stubbing out a model reconciler)
codyjrivera a9b33bf
Only count pods that aren't terminating
codyjrivera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Copyright 2022 VMware, Inc. | ||
// SPDX-License-Identifier: MIT | ||
pub mod reconciler; |
59 changes: 59 additions & 0 deletions
59
src/controller_examples/v_replica_set_controller/model/reconciler.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2022 VMware, Inc. | ||
// SPDX-License-Identifier: MIT | ||
#![allow(unused_imports)] | ||
use crate::external_api::spec::*; | ||
use crate::v_replica_set_controller::trusted::{ | ||
spec_types::*, step::*, | ||
}; | ||
use crate::kubernetes_api_objects::spec::prelude::*; | ||
use crate::reconciler::spec::{io::*, reconciler::*}; | ||
use vstd::{prelude::*, string::*}; | ||
|
||
verus! { | ||
|
||
impl Reconciler<VReplicaSetView, EmptyAPI> for VReplicaSetReconciler { | ||
type T = VReplicaSetReconcileState; | ||
|
||
open spec fn reconcile_init_state() -> VReplicaSetReconcileState { | ||
reconcile_init_state() | ||
} | ||
|
||
open spec fn reconcile_core(fb: VReplicaSetView, resp_o: Option<ResponseView<EmptyTypeView>>, state: VReplicaSetReconcileState) | ||
-> (VReplicaSetReconcileState, Option<RequestView<EmptyTypeView>>) { | ||
reconcile_core(fb, resp_o, state) | ||
} | ||
|
||
open spec fn reconcile_done(state: VReplicaSetReconcileState) -> bool { | ||
reconcile_done(state) | ||
} | ||
|
||
open spec fn reconcile_error(state: VReplicaSetReconcileState) -> bool { | ||
reconcile_error(state) | ||
} | ||
|
||
open spec fn expect_from_user(obj: DynamicObjectView) -> bool { false /* expect nothing: stub */ } | ||
} | ||
|
||
pub open spec fn reconcile_init_state() -> VReplicaSetReconcileState { | ||
VReplicaSetReconcileState { | ||
reconcile_step: VReplicaSetReconcileStepView::Init, | ||
filtered_pods: None, | ||
} | ||
} | ||
|
||
pub open spec fn reconcile_done(state: VReplicaSetReconcileState) -> bool { | ||
false | ||
} | ||
|
||
pub open spec fn reconcile_error(state: VReplicaSetReconcileState) -> bool { | ||
false | ||
} | ||
|
||
pub open spec fn reconcile_core( | ||
fb: VReplicaSetView, resp_o: Option<ResponseView<EmptyTypeView>>, state: VReplicaSetReconcileState | ||
) -> (VReplicaSetReconcileState, Option<RequestView<EmptyTypeView>>) { | ||
(state, None) | ||
} | ||
|
||
} | ||
|
44 changes: 44 additions & 0 deletions
44
src/controller_examples/v_replica_set_controller/trusted/liveness_theorem.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2022 VMware, Inc. | ||
// SPDX-License-Identifier: MIT | ||
#![allow(unused_imports)] | ||
use crate::v_replica_set_controller::trusted::{spec_types::*, step::*}; | ||
use crate::kubernetes_api_objects::spec::prelude::*; | ||
use crate::kubernetes_cluster::spec::{cluster::*, cluster_state_machine::Step, message::*}; | ||
use crate::temporal_logic::defs::*; | ||
use crate::vstd_ext::string_view::int_to_string_view; | ||
use vstd::prelude::*; | ||
|
||
verus! { | ||
|
||
pub open spec fn liveness_theorem() -> bool { cluster_spec().entails(tla_forall(|vrs: VReplicaSetView| liveness(vrs))) } | ||
|
||
pub open spec fn cluster_spec() -> TempPred<VRSCluster> { VRSCluster::sm_spec() } | ||
|
||
pub open spec fn liveness(vrs: VReplicaSetView) -> TempPred<VRSCluster> { | ||
always(lift_state(desired_state_is(vrs))).leads_to(always(lift_state(current_state_matches(vrs)))) | ||
} | ||
|
||
pub open spec fn desired_state_is(vrs: VReplicaSetView) -> StatePred<VRSCluster> { VRSCluster::desired_state_is(vrs) } | ||
|
||
pub open spec fn current_state_matches(vrs: VReplicaSetView) -> StatePred<VRSCluster> { | ||
|s: VRSCluster| { | ||
resource_state_matches(vrs, s.resources()) | ||
} | ||
} | ||
|
||
pub open spec fn resource_state_matches(vrs: VReplicaSetView, resources: StoredState) -> bool { | ||
let pods: Set<ObjectRef> = Set::new(|k: ObjectRef| owned_selector_match_is(vrs, resources, k)); | ||
&&& pods.finite() | ||
&&& pods.len() == vrs.spec.replicas.unwrap_or(0) | ||
} | ||
|
||
pub open spec fn owned_selector_match_is(vrs: VReplicaSetView, resources: StoredState, key: ObjectRef) -> bool { | ||
let obj = resources[key]; | ||
&&& resources.contains_key(key) | ||
&&& obj.kind == PodView::kind() | ||
&&& obj.metadata.owner_references_contains(vrs.controller_owner_ref()) | ||
&&& vrs.spec.selector.matches(obj.metadata.labels.unwrap_or(Map::empty())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @codyjrivera could you add one more line here
Basically we only want to count the pods that are NOT in terminating state. |
||
&&& obj.metadata.deletion_timestamp.is_None() | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
src/controller_examples/v_replica_set_controller/trusted/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// Copyright 2022 VMware, Inc. | ||
// SPDX-License-Identifier: MIT | ||
pub mod exec_types; | ||
pub mod liveness_theorem; | ||
pub mod spec_types; | ||
pub mod step; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious: do we need this line since we have the next line that talks about the length of the pods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file https://github.com/verus-lang/verus/blob/main/source/vstd/set.rs says that
len
is only meaningful when the set is finite: infinite sets are allowed. Also it can't return anything like -1 to represent an infinite set.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK