forked from anvil-verifier/anvil
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
preconditions
for Delete request (anvil-verifier#545)
This PR introduces `preconditions` of Kubernetes delete requests. The `preconditions` contain a uid and a resource version. When handling the delete request, the API server checks whether the object's uid and resource version match the ones provided by the request and returns `Conflict` error if not. Kubernetes implements this feature here: https://github.com/kubernetes/kubernetes/blob/v1.30.0/staging/src/k8s.io/apiserver/pkg/storage/interfaces.go#L140-L153. The `preconditions` is optional. Introducing `preconditions` mainly requires changes to the API server model (modeling the uid and resource version checking) and the shim layer (passing the `preconditions` to `kube`). This PR also fixes some of the lemmas that are broken due to `preconditions`. Having `preconditions` allows us to use more restrictive deletion. This is useful to ensure no interference between controllers that manage pods --- when a controller decides to delete a pod that the controller believes belongs to itself, the controller should pass to the `preconditions` the resource version of the pod it observes. When API server handles the delete request, if the pod happens to be owned by a different controller, then the deletion will be invalidated (because the resource version must have already changed since the controller's observation) so that the controller won't interfere with the new owner of the pod. --------- Signed-off-by: Xudong Sun <[email protected]>
- Loading branch information
1 parent
9f6a0ff
commit 52e8753
Showing
26 changed files
with
237 additions
and
52 deletions.
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
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
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
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
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 | ||
use crate::kubernetes_api_objects::exec::{object_meta::*, resource::*}; | ||
use crate::kubernetes_api_objects::spec::preconditions::*; | ||
use crate::vstd_ext::string_view::*; | ||
use vstd::{prelude::*, string::*, view::*}; | ||
|
||
verus! { | ||
|
||
#[verifier(external_body)] | ||
pub struct Preconditions { | ||
inner: deps_hack::kube::api::Preconditions, | ||
} | ||
|
||
impl View for Preconditions { | ||
type V = PreconditionsView; | ||
|
||
spec fn view(&self) -> PreconditionsView; | ||
} | ||
|
||
impl std::clone::Clone for Preconditions { | ||
#[verifier(external_body)] | ||
fn clone(&self) -> (result: Preconditions) | ||
ensures result@ == self@ | ||
{ | ||
Preconditions { inner: self.inner.clone() } | ||
} | ||
} | ||
|
||
impl Preconditions { | ||
#[verifier(external_body)] | ||
pub fn default() -> (preconditions: Preconditions) | ||
ensures preconditions@ == PreconditionsView::default(), | ||
{ | ||
Preconditions { inner: deps_hack::kube::api::Preconditions::default() } | ||
} | ||
|
||
#[verifier(external_body)] | ||
pub fn set_uid_from_object_meta(&mut self, object_meta: ObjectMeta) | ||
ensures self@ == old(self)@.set_uid_from_object_meta(object_meta@), | ||
{ | ||
self.inner.uid = object_meta.into_kube().uid; | ||
} | ||
|
||
#[verifier(external_body)] | ||
pub fn set_resource_version_from_object_meta(&mut self, object_meta: ObjectMeta) | ||
ensures self@ == old(self)@.set_resource_version_from_object_meta(object_meta@), | ||
{ | ||
self.inner.resource_version = object_meta.into_kube().resource_version; | ||
} | ||
|
||
#[verifier(external)] | ||
pub fn from_kube(inner: deps_hack::kube::api::Preconditions) -> Preconditions { Preconditions { inner: inner } } | ||
|
||
#[verifier(external)] | ||
pub fn into_kube(self) -> deps_hack::kube::api::Preconditions { self.inner } | ||
} | ||
|
||
} |
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
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
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
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,39 @@ | ||
// Copyright 2022 VMware, Inc. | ||
// SPDX-License-Identifier: MIT | ||
use crate::kubernetes_api_objects::spec::{ | ||
common::{ResourceVersion, Uid}, | ||
object_meta::*, | ||
}; | ||
use vstd::prelude::*; | ||
|
||
verus! { | ||
|
||
pub struct PreconditionsView { | ||
pub uid: Option<Uid>, | ||
pub resource_version: Option<ResourceVersion>, | ||
} | ||
|
||
impl PreconditionsView { | ||
pub open spec fn default() -> PreconditionsView { | ||
PreconditionsView { | ||
uid: None, | ||
resource_version: None, | ||
} | ||
} | ||
|
||
pub open spec fn set_uid_from_object_meta(self, object_meta: ObjectMetaView) -> PreconditionsView { | ||
PreconditionsView { | ||
uid: object_meta.uid, | ||
..self | ||
} | ||
} | ||
|
||
pub open spec fn set_resource_version_from_object_meta(self, object_meta: ObjectMetaView) -> PreconditionsView { | ||
PreconditionsView { | ||
resource_version: object_meta.resource_version, | ||
..self | ||
} | ||
} | ||
} | ||
|
||
} |
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.