-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the liveness theorem for the consumer controller (#507)
Signed-off-by: Xudong Sun <[email protected]>
- Loading branch information
1 parent
4d3b300
commit dcc8ca9
Showing
3 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/controller_examples/composition_example/consumer_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,50 @@ | ||
// Copyright 2022 VMware, Inc. | ||
// SPDX-License-Identifier: MIT | ||
#![allow(unused_imports)] | ||
use crate::consumer_controller::trusted::{spec_types::*, step::*}; | ||
use crate::kubernetes_api_objects::spec::{container::*, prelude::*}; | ||
use crate::kubernetes_cluster::spec::{cluster::*, cluster_state_machine::Step, message::*}; | ||
use crate::temporal_logic::defs::*; | ||
use vstd::prelude::*; | ||
|
||
verus! { | ||
|
||
pub open spec fn liveness_theorem() -> bool { cluster_spec().entails(tla_forall(|consumer: ConsumerView| liveness(consumer))) } | ||
|
||
pub open spec fn cluster_spec() -> TempPred<CCluster> { CCluster::sm_spec() } | ||
|
||
pub open spec fn liveness(consumer: ConsumerView) -> TempPred<CCluster> { | ||
always(lift_state(CCluster::desired_state_is(consumer))).leads_to(always(lift_state(current_state_matches(consumer)))) | ||
} | ||
|
||
pub open spec fn current_state_matches(consumer: ConsumerView) -> StatePred<CCluster> { | ||
|s: CCluster| { | ||
let obj = s.resources()[pod_key(consumer)]; | ||
let pod = PodView::unmarshal(obj).get_Ok_0(); | ||
&&& s.resources().contains_key(pod_key(consumer)) | ||
&&& PodView::unmarshal(obj).is_Ok() | ||
&&& pod.metadata.labels.get_Some_0().contains_pair("consumer_message"@, consumer.spec.message) | ||
&&& pod.spec == Some(PodSpecView { | ||
containers: seq![ContainerView { | ||
name: "nginx"@, | ||
image: Some("nginx:1.14.2"@), | ||
ports: Some(seq![ContainerPortView { | ||
container_port: 80, | ||
..ContainerPortView::default() | ||
}]), | ||
..ContainerView::default() | ||
}], | ||
..PodSpecView::default() | ||
}) | ||
} | ||
} | ||
|
||
pub open spec fn pod_key(consumer: ConsumerView) -> ObjectRef { | ||
ObjectRef { | ||
name: consumer.metadata.name.get_Some_0(), | ||
namespace: consumer.metadata.namespace.get_Some_0(), | ||
kind: Kind::PodKind, | ||
} | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
src/controller_examples/composition_example/consumer_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; |
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