pub mod munge;
pub mod ser {
use std::collections::{BTreeMap, HashMap};
pub trait Skip {
fn skip(&self) -> bool;
}
impl Skip for String {
fn skip(&self) -> bool {
self.is_empty()
}
}
impl Skip for bool {
fn skip(&self) -> bool {
!*self
}
}
impl Skip for i32 {
fn skip(&self) -> bool {
*self == 0
}
}
impl<T> Skip for Option<T> {
fn skip(&self) -> bool {
self.is_none()
}
}
impl<T> Skip for Vec<T> {
fn skip(&self) -> bool {
self.is_empty()
}
}
impl<K, V> Skip for HashMap<K, V> {
fn skip(&self) -> bool {
self.is_empty()
}
}
impl<K, V> Skip for BTreeMap<K, V> {
fn skip(&self) -> bool {
self.is_empty()
}
}
impl Skip for serde_norway::Value {
fn skip(&self) -> bool {
matches!(self, serde_norway::Value::Null)
}
}
pub fn skip<T: Skip>(value: &T) -> bool {
value.skip()
}
}
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
macro_rules! argo {
($(
$(#[$m:meta])*
pub struct $name:ident { $(
$(#[$fm:meta])*
pub $fld:ident : $ty:ty
),* $(,)? }
)*) => {$(
$(#[$m])*
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct $name {
$(
$(#[$fm])*
#[serde(default, skip_serializing_if = "crate::ser::skip")]
pub $fld : $ty,
)*
}
)*};
}
argo! {
pub struct Workflow {
pub api_version: String,
pub kind: String,
pub metadata: Option<ObjectMeta>,
pub spec: Option<WorkflowSpec>,
}
pub struct WorkflowTemplate {
pub api_version: String,
pub kind: String,
pub metadata: Option<ObjectMeta>,
pub spec: Option<WorkflowSpec>,
}
pub struct ObjectMeta {
pub name: String,
pub generate_name: String,
pub namespace: String,
pub labels: BTreeMap<String, String>,
pub annotations: BTreeMap<String, String>,
}
pub struct WorkflowSpec {
pub entrypoint: String,
pub templates: Vec<Template>,
pub arguments: Option<Arguments>,
pub workflow_template_ref: Option<WorkflowTemplateRef>,
pub service_account_name: String,
pub node_selector: BTreeMap<String, String>,
pub hooks: BTreeMap<String, LifecycleHook>,
pub ttl_strategy: Option<TtlStrategy>,
#[serde(rename = "podGC")]
pub pod_gc: Option<PodGc>,
pub active_deadline_seconds: Option<i64>,
pub synchronization: Option<Synchronization>,
pub priority: Option<i32>,
pub tolerations: Vec<Toleration>,
pub affinity: Option<serde_norway::Value>,
pub pod_spec_patch: Option<String>,
pub image_pull_secrets: Vec<LocalObjectReference>,
pub parallelism: Option<i64>,
pub volume_claim_templates: Vec<PersistentVolumeClaim>,
}
pub struct Toleration {
pub key: String,
pub operator: String,
pub value: String,
pub effect: String,
pub toleration_seconds: Option<i64>,
}
pub struct LocalObjectReference {
pub name: String,
}
pub struct TtlStrategy {
pub seconds_after_completion: Option<i32>,
pub seconds_after_success: Option<i32>,
pub seconds_after_failure: Option<i32>,
}
pub struct PodGc {
pub strategy: String,
}
pub struct WorkflowTemplateRef {
pub name: String,
pub cluster_scope: bool,
}
pub struct TemplateRef {
pub name: String,
pub template: String,
pub cluster_scope: bool,
}
pub struct Template {
pub name: String,
pub metadata: Option<ObjectMeta>,
pub inputs: Option<Inputs>,
pub outputs: Option<Outputs>,
pub container: Option<Container>,
pub dag: Option<DagTemplate>,
pub script: Option<ScriptTemplate>,
pub daemon: Option<bool>,
pub volumes: Vec<Volume>,
pub service_account_name: String,
pub node_selector: BTreeMap<String, String>,
pub steps: Vec<Vec<DagTask>>,
pub retry_strategy: Option<RetryStrategy>,
pub timeout: String,
pub active_deadline_seconds: Option<i32>,
pub synchronization: Option<Synchronization>,
pub tolerations: Vec<Toleration>,
pub affinity: Option<serde_norway::Value>,
pub pod_spec_patch: Option<String>,
pub parallelism: Option<i64>,
}
pub struct Synchronization {
pub mutexes: Vec<Mutex>,
}
pub struct Mutex {
pub name: String,
pub namespace: String,
}
pub struct RetryStrategy {
pub limit: Option<i32>,
pub retry_policy: String,
pub backoff: Option<Backoff>,
}
pub struct Backoff {
pub duration: String,
pub factor: Option<i32>,
pub max_duration: String,
}
pub struct Inputs {
pub parameters: Vec<Parameter>,
pub artifacts: Vec<Artifact>,
}
pub struct Outputs {
pub parameters: Vec<Parameter>,
pub artifacts: Vec<Artifact>,
}
pub struct Parameter {
pub name: String,
pub value: Option<String>,
pub default: Option<String>,
pub value_from: Option<ValueFrom>,
}
pub struct ValueFrom {
pub path: String,
pub parameter: String,
pub expression: String,
}
pub struct Artifact {
pub name: String,
pub path: String,
pub s3: Option<S3Artifact>,
pub archive: Option<ArchiveStrategy>,
pub mode: Option<i32>,
pub from: String,
}
pub struct SecretKeySelector {
pub name: String,
pub key: String,
pub optional: bool,
}
pub struct S3Artifact {
pub endpoint: String,
pub bucket: String,
pub region: String,
pub insecure: bool,
pub key: String,
pub access_key_secret: Option<SecretKeySelector>,
pub secret_key_secret: Option<SecretKeySelector>,
}
pub struct ArchiveStrategy {
pub none: Option<NoneStrategy>,
}
pub struct NoneStrategy {}
pub struct Arguments {
pub parameters: Vec<Parameter>,
pub artifacts: Vec<Artifact>,
}
pub struct DagTemplate {
pub tasks: Vec<DagTask>,
}
pub struct DagTask {
pub name: String,
pub template: String,
pub dependencies: Vec<String>,
pub arguments: Option<Arguments>,
pub template_ref: Option<TemplateRef>,
pub continue_on: Option<ContinueOn>,
pub hooks: BTreeMap<String, LifecycleHook>,
pub with_param: String,
pub when: String,
}
pub struct ContinueOn {
pub error: bool,
pub failed: bool,
}
pub struct LifecycleHook {
pub template_ref: Option<TemplateRef>,
pub arguments: Option<Arguments>,
pub expression: String,
}
pub struct Container {
pub image: String,
pub command: Vec<String>,
pub args: Vec<String>,
pub env: Vec<EnvVar>,
pub volume_mounts: Vec<VolumeMount>,
pub working_dir: String,
pub security_context: Option<SecurityContext>,
}
pub struct SecurityContext {
pub privileged: bool,
}
pub struct ScriptTemplate {
pub image: String,
pub command: Vec<String>,
pub source: String,
}
pub struct EnvVar {
pub name: String,
pub value: String,
pub value_from: Option<EnvVarSource>,
}
pub struct EnvVarSource {
pub secret_key_ref: Option<SecretKeySelector>,
}
pub struct Volume {
pub name: String,
pub host_path: Option<HostPathVolumeSource>,
pub empty_dir: Option<EmptyDirVolumeSource>,
pub persistent_volume_claim: Option<PersistentVolumeClaimVolumeSource>,
}
pub struct HostPathVolumeSource {
pub path: String,
pub r#type: String,
}
pub struct EmptyDirVolumeSource {}
pub struct PersistentVolumeClaimVolumeSource {
pub claim_name: String,
pub read_only: bool,
}
pub struct VolumeMount {
pub name: String,
pub mount_path: String,
pub read_only: bool,
}
pub struct PersistentVolumeClaim {
pub metadata: Option<ObjectMeta>,
pub spec: Option<PersistentVolumeClaimSpec>,
}
pub struct PersistentVolumeClaimSpec {
pub access_modes: Vec<String>,
pub resources: Option<VolumeResourceRequirements>,
pub storage_class_name: String,
}
pub struct VolumeResourceRequirements {
pub requests: BTreeMap<String, String>,
}
}
pub const API_VERSION: &str = "argoproj.io/v1alpha1";
pub const KIND_WORKFLOW: &str = "Workflow";
pub const KIND_WORKFLOW_TEMPLATE: &str = "WorkflowTemplate";