Skip to content
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

Specify VRS state validation rules #557

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions src/v2/controllers/vreplicaset_controller/trusted/spec_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ pub struct VReplicaSetView {
pub type VReplicaSetStatusView = EmptyStatusView;

impl VReplicaSetView {
// TODO: well_formed should just call state_validation
pub open spec fn well_formed(self) -> bool {
&&& self.metadata.name.is_Some()
&&& self.metadata.namespace.is_Some()
&&& self.metadata.uid.is_Some()
// TODO: ensure that the following is consistent with k8s's ReplicaSet
&&& self.spec.template.is_Some()
&&& self.spec.template.get_Some_0().metadata.is_Some()
&&& self.spec.template.get_Some_0().spec.is_Some()
&&& self.metadata.well_formed()
&&& self.state_validation()
}

pub open spec fn controller_owner_ref(self) -> OwnerReferenceView {
Expand Down Expand Up @@ -122,26 +116,39 @@ impl ResourceView for VReplicaSetView {

proof fn unmarshal_result_determined_by_unmarshal_spec_and_status() {}

// TODO: keep it consistent with k8s's ReplicaSet
open spec fn state_validation(self) -> bool {
self.spec.replicas.is_Some() ==> self.spec.replicas.get_Some_0() >= 0
// replicas is non-negative
&&& self.spec.replicas.is_Some() ==> self.spec.replicas.get_Some_0() >= 0
// selector exists, and its match_labels is not empty
// TODO: revise it after supporting selector.match_expressions
&&& self.spec.selector.match_labels.is_Some()
&&& self.spec.selector.match_labels.get_Some_0().len() > 0
// template and its metadata ane spec exists
&&& self.spec.template.is_Some()
&&& self.spec.template.get_Some_0().metadata.is_Some()
&&& self.spec.template.get_Some_0().spec.is_Some()
// selector matches template's metadata's labels
&&& self.spec.selector.matches(self.spec.template.get_Some_0().metadata.get_Some_0().labels.unwrap_or(Map::empty()))
}

open spec fn transition_validation(self, old_obj: VReplicaSetView) -> bool {
true
}

}

impl CustomResourceView for VReplicaSetView {
proof fn kind_is_custom_resource() {}

open spec fn spec_status_validation(obj_spec: Self::Spec, obj_status: Self::Status) -> bool {
obj_spec.replicas.is_Some() ==> obj_spec.replicas.get_Some_0() >= 0
VReplicaSetView {
metadata: arbitrary(),
spec: obj_spec,
status: obj_status,
}.state_validation()
}

proof fn validation_result_determined_by_spec_and_status()
ensures forall |obj: Self| #[trigger] obj.state_validation() == Self::spec_status_validation(obj.spec(), obj.status())
{}
proof fn validation_result_determined_by_spec_and_status() {}
}

pub struct VReplicaSetSpecView {
Expand Down
Loading