genpolicy: add topologySpreadConstraints support

Allow genpolicy to process Pod YAML files including
topologySpreadConstraints.

Signed-off-by: Dan Mihai <dmihai@microsoft.com>
This commit is contained in:
Dan Mihai
2023-11-29 01:34:36 +00:00
committed by Saul Paredes
parent b0cdf4eb0d
commit 75aee526a9
2 changed files with 30 additions and 0 deletions

View File

@@ -89,6 +89,9 @@ pub struct PodSpec {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
dnsPolicy: Option<String>, dnsPolicy: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
topologySpreadConstraints: Option<Vec<TopologySpreadConstraint>>,
} }
/// See Reference / Kubernetes API / Workload Resources / Pod. /// See Reference / Kubernetes API / Workload Resources / Pod.
@@ -503,6 +506,29 @@ struct PodDNSConfigOption {
value: Option<String>, value: Option<String>,
} }
/// See Reference / Kubernetes API / Workload Resources / Pod.
#[derive(Clone, Debug, Serialize, Deserialize)]
struct TopologySpreadConstraint {
maxSkew: i32,
topologyKey: String,
whenUnsatisfiable: String,
#[serde(skip_serializing_if = "Option::is_none")]
labelSelector: Option<yaml::LabelSelector>,
#[serde(skip_serializing_if = "Option::is_none")]
matchLabelKeys: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
minDomains: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
nodeAffinityPolicy: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
nodeTaintsPolicy: Option<String>,
}
impl Container { impl Container {
pub async fn init(&mut self, config: &Config) { pub async fn init(&mut self, config: &Config) {
// Load container image properties from the registry. // Load container image properties from the registry.

View File

@@ -27,3 +27,7 @@ spec:
securityContext: securityContext:
seccompProfile: seccompProfile:
type: RuntimeDefault type: RuntimeDefault
topologySpreadConstraints:
- maxSkew: 2
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway