forked from metalbear-co/mirrord
-
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.
moved MirrordPolicy to a separate module
- Loading branch information
Showing
3 changed files
with
55 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use kube::CustomResource; | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::label_selector::LabelSelector; | ||
|
||
/// Features and operations that can be blocked by a `MirrordPolicy`. | ||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, JsonSchema)] | ||
#[serde(rename_all = "kebab-case")] // StealWithoutFilter -> steal-without-filter in yaml. | ||
pub enum BlockedFeature { | ||
/// Blocks stealing traffic in any way (without or without filter). | ||
Steal, | ||
|
||
/// Blocks stealing traffic without specifying (any) filter. Client can still specify a | ||
/// filter that matches anything. | ||
StealWithoutFilter, | ||
|
||
/// Blocks mirroring traffic. | ||
Mirror, | ||
|
||
/// So that the operator is able to list all policies with [`kube::Api`], | ||
/// even if it doesn't recognize blocked features used in some of them. | ||
#[schemars(skip)] | ||
#[serde(other, skip_serializing)] | ||
Unknown, | ||
} | ||
|
||
/// Custom resource for policies that limit what mirrord features users can use. | ||
#[derive(CustomResource, Clone, Debug, Deserialize, Serialize, JsonSchema)] | ||
#[kube( | ||
// The operator group is handled by the operator, we want policies to be handled by k8s. | ||
group = "policies.mirrord.metalbear.co", | ||
version = "v1alpha", | ||
kind = "MirrordPolicy", | ||
namespaced | ||
)] | ||
#[serde(rename_all = "camelCase")] // target_path -> targetPath in yaml. | ||
pub struct MirrordPolicySpec { | ||
/// Specify the targets for which this policy applies, in the pod/my-pod deploy/my-deploy | ||
/// notation. Targets can be matched using `*` and `?` where `?` matches exactly one | ||
/// occurrence of any character and `*` matches arbitrary many (including zero) occurrences | ||
/// of any character. If not specified, this policy does not depend on the target's path. | ||
pub target_path: Option<String>, | ||
|
||
/// If specified in a policy, the policy will only apply to targets with labels that match all | ||
/// of the selector's rules. | ||
pub selector: Option<LabelSelector>, | ||
|
||
// TODO: make the k8s list type be set/map to prevent duplicates. | ||
/// List of features and operations blocked by this policy. | ||
pub block: Vec<BlockedFeature>, | ||
} |
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