-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add policy to exclude env vars. * docs * changelog * fix tests * Make policy optional for backwards compat. * typo * other typo * default serde and more explicit docs * fix mismatching policy * make it look more like config * make it pub * fix test * better docs Co-authored-by: Michał Smolarek <[email protected]> * better docs due Co-authored-by: Michał Smolarek <[email protected]> * rustfmt * Add policy for file ops. * no exclude * update protocol with open_local_version * bump protocol * lint test * docs * fix test * change min protocol version * e2e test for fspolicy * Ignore fs policy test/ * namespaced test * hopefully fixed policy test * the children get to live * fix test policy name Co-authored-by: t4lz <[email protected]> * fix go fs test * remove read_write * add newline to python test * changelog --------- Co-authored-by: Michał Smolarek <[email protected]> Co-authored-by: t4lz <[email protected]>
- Loading branch information
1 parent
2ec5ab3
commit a51e981
Showing
16 changed files
with
437 additions
and
174 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
Add policy to control file ops. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import fs from 'fs'; | ||
|
||
fs.open("/app/file.local", (fail, fd) => { | ||
console.log(`open file.local ${fd}`); | ||
if (fd) { | ||
console.log(`SUCCESS /app/file.local ${fd}`); | ||
} | ||
|
||
if (fail) { | ||
console.error(`FAIL /app/file.local ${fail}`); | ||
} | ||
}); | ||
|
||
fs.open("/app/file.not-found", (fail, fd) => { | ||
console.log(`open file.not-found ${fd}`); | ||
if (fd) { | ||
console.log(`SUCCESS /app/file.not-found ${fd}`); | ||
} | ||
|
||
if (fail) { | ||
console.error(`FAIL /app/file.not-found ${fail}`); | ||
} | ||
}); | ||
|
||
fs.open("/app/file.read-only", (fail, fd) => { | ||
if (fd) { | ||
console.log(`SUCCESS /app/file.read-only ${fd}`); | ||
} | ||
|
||
if (fail) { | ||
console.error(`FAIL /app/file.read-only ${fail}`); | ||
} | ||
}); | ||
|
||
fs.open("/app/file.read-only", "r+", (fail, fd) => { | ||
if (fd) { | ||
console.log(`SUCCESS r+ /app/file.read-only ${fd}`); | ||
} | ||
|
||
if (fail) { | ||
console.error(`FAIL r+ /app/file.read-only ${fail}`); | ||
} | ||
}); | ||
|
||
fs.open("/app/file.read-write", "r+", (fail, fd) => { | ||
if (fd) { | ||
console.log(`SUCCESS /app/file.read-write ${fd}`); | ||
} | ||
|
||
if (fail) { | ||
console.error(`FAIL /app/file.read-write ${fail}`); | ||
} | ||
}); | ||
|
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,87 @@ | ||
use std::{collections::HashSet, time::Duration}; | ||
|
||
use mirrord_operator::crd::policy::{FsPolicy, MirrordPolicy, MirrordPolicySpec}; | ||
use rstest::{fixture, rstest}; | ||
|
||
use crate::{ | ||
operator::policies::PolicyGuard, | ||
utils::{kube_client, service, Application, KubeService}, | ||
}; | ||
|
||
#[fixture] | ||
async fn fs_service(#[future] kube_client: kube::Client) -> KubeService { | ||
let namespace = format!("e2e-tests-fs-policies-{}", crate::utils::random_string()); | ||
|
||
service( | ||
&namespace, | ||
"NodePort", | ||
"ghcr.io/metalbear-co/mirrord-pytest:latest", | ||
"fs-policy-e2e-test-service", | ||
false, | ||
kube_client, | ||
) | ||
.await | ||
} | ||
|
||
#[rstest] | ||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
#[timeout(Duration::from_secs(60))] | ||
pub async fn create_cluster_fs_policy_and_try_file_operations( | ||
#[future] service: KubeService, | ||
#[future] kube_client: kube::Client, | ||
) { | ||
let kube_client = kube_client.await; | ||
let service = service.await; | ||
|
||
// Create policy, delete it when test exits. | ||
let _policy_guard = PolicyGuard::namespaced( | ||
kube_client, | ||
&MirrordPolicy::new( | ||
"e2e-test-fs-policy-with-path-pattern", | ||
MirrordPolicySpec { | ||
target_path: Some("fs_policy_e2e-test-*".into()), | ||
selector: None, | ||
block: Default::default(), | ||
env: Default::default(), | ||
fs: FsPolicy { | ||
read_only: HashSet::from_iter(vec!["file.read-only".to_string()]), | ||
local: HashSet::from_iter(vec!["file.local".to_string()]), | ||
not_found: HashSet::from_iter(vec!["file.not-found".to_string()]), | ||
}, | ||
}, | ||
), | ||
&service.namespace, | ||
) | ||
.await; | ||
|
||
let application = Application::NodeFsPolicy; | ||
println!("Running mirrord {application:?} against {}", &service.name); | ||
|
||
let mut test_process = application | ||
.run( | ||
&service.target, | ||
Some(&service.namespace), | ||
Some(vec!["--fs-mode=write"]), | ||
None, | ||
) | ||
.await; | ||
|
||
test_process.wait_assert_success().await; | ||
|
||
test_process | ||
.assert_stderr_contains("FAIL /app/file.local") | ||
.await; | ||
test_process | ||
.assert_stderr_contains("FAIL /app/file.not-found") | ||
.await; | ||
test_process | ||
.assert_stderr_contains("FAIL r+ /app/file.read-only") | ||
.await; | ||
|
||
test_process | ||
.assert_stdout_contains("SUCCESS /app/file.read-only") | ||
.await; | ||
test_process | ||
.assert_stdout_contains("SUCCESS /app/file.read-write") | ||
.await; | ||
} |
Oops, something went wrong.