use super::{
BooleanValue, BuildExtraHosts, BuildNoCache, BuildProvenance, BuildSbom, FieldReference, KeyValueEntry, Labels,
Located, SecretGrant, ShmSize, Ulimits,
};
use crate::source::SourceSpan;
use std::fmt;
use std::sync::Arc;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Build {
Context(Located<String>),
Definition(BuildDefinition),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BuildDefinition {
span: SourceSpan,
values: Box<BuildValues>,
fields: Vec<BuildField>,
extension_fields: Vec<FieldReference>,
unknown_fields: Arc<Vec<FieldReference>>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
struct BuildValues {
additional_contexts: Option<BuildAdditionalContexts>,
entitlements: Option<Arc<Vec<Located<String>>>>,
extra_hosts: Option<BuildExtraHosts>,
context: Option<Located<String>>,
args: Option<BuildArgs>,
cache_from: Option<Arc<Vec<Located<String>>>>,
cache_to: Option<Arc<Vec<Located<String>>>>,
dockerfile: Option<Located<String>>,
dockerfile_inline: Option<Located<String>>,
target: Option<Located<String>>,
network: Option<Box<Located<String>>>,
isolation: Option<Box<Located<String>>>,
platforms: Option<Arc<Vec<Located<String>>>>,
no_cache: Option<Box<Located<BuildNoCache>>>,
no_cache_filter: Option<BuildNoCacheFilter>,
privileged: Option<Box<Located<BooleanValue>>>,
sbom: Option<Box<Located<BuildSbom>>>,
provenance: Option<Box<Located<BuildProvenance>>>,
pull: Option<Box<Located<BooleanValue>>>,
shm_size: Option<Box<ShmSize>>,
tags: Option<Arc<Vec<Located<String>>>>,
labels: Option<Box<Labels>>,
secrets: Option<Arc<Vec<SecretGrant>>>,
ssh: Option<BuildSsh>,
ulimits: Option<Box<Ulimits>>,
}
impl BuildDefinition {
pub(super) fn new(span: SourceSpan) -> Self {
Self {
span,
values: Box::new(BuildValues {
additional_contexts: None,
entitlements: None,
extra_hosts: None,
context: None,
args: None,
cache_from: None,
cache_to: None,
dockerfile: None,
dockerfile_inline: None,
target: None,
network: None,
isolation: None,
platforms: None,
no_cache: None,
no_cache_filter: None,
privileged: None,
sbom: None,
provenance: None,
pull: None,
shm_size: None,
tags: None,
labels: None,
secrets: None,
ssh: None,
ulimits: None,
}),
fields: Vec::new(),
extension_fields: Vec::new(),
unknown_fields: Arc::new(Vec::new()),
}
}
pub(super) fn push_field(&mut self, field: BuildField) {
self.fields.push(field);
}
pub(super) fn set_context(&mut self, context: Located<String>) {
self.values.context = Some(context);
}
pub(super) fn set_additional_contexts(&mut self, additional_contexts: Option<BuildAdditionalContexts>) {
self.values.additional_contexts = additional_contexts;
}
pub(super) fn set_entitlements(&mut self, entitlements: Vec<Located<String>>) {
self.values.entitlements = Some(Arc::new(entitlements));
}
pub(super) fn set_extra_hosts(&mut self, extra_hosts: BuildExtraHosts) {
self.values.extra_hosts = Some(extra_hosts);
}
pub(super) fn set_args(&mut self, args: BuildArgs) {
self.values.args = Some(args);
}
pub(super) fn set_cache_from(&mut self, cache_from: Vec<Located<String>>) {
self.values.cache_from = Some(Arc::new(cache_from));
}
pub(super) fn set_cache_to(&mut self, cache_to: Vec<Located<String>>) {
self.values.cache_to = Some(Arc::new(cache_to));
}
pub(super) fn set_dockerfile(&mut self, dockerfile: Located<String>) {
self.values.dockerfile = Some(dockerfile);
}
pub(super) fn set_dockerfile_inline(&mut self, dockerfile_inline: Located<String>) {
self.values.dockerfile_inline = Some(dockerfile_inline);
}
pub(super) fn set_target(&mut self, target: Located<String>) {
self.values.target = Some(target);
}
pub(super) fn set_network(&mut self, network: Located<String>) {
self.values.network = Some(Box::new(network));
}
pub(super) fn set_isolation(&mut self, isolation: Located<String>) {
self.values.isolation = Some(Box::new(isolation));
}
pub(super) fn set_platforms(&mut self, platforms: Vec<Located<String>>) {
self.values.platforms = Some(Arc::new(platforms));
}
pub(super) fn set_no_cache(&mut self, no_cache: Located<BuildNoCache>) {
self.values.no_cache = Some(Box::new(no_cache));
}
pub(super) fn set_no_cache_filter(&mut self, value: BuildNoCacheFilter) {
self.values.no_cache_filter = Some(value);
}
pub(super) fn set_privileged(&mut self, value: Located<BooleanValue>) {
self.values.privileged = Some(Box::new(value));
}
pub(super) fn set_sbom(&mut self, sbom: Located<BuildSbom>) {
self.values.sbom = Some(Box::new(sbom));
}
pub(super) fn set_provenance(&mut self, value: Located<BuildProvenance>) {
self.values.provenance = Some(Box::new(value));
}
pub(super) fn set_pull(&mut self, pull: Located<BooleanValue>) {
self.values.pull = Some(Box::new(pull));
}
pub(super) fn set_shm_size(&mut self, shm_size: ShmSize) {
self.values.shm_size = Some(Box::new(shm_size));
}
pub(super) fn set_tags(&mut self, tags: Vec<Located<String>>) {
self.values.tags = Some(Arc::new(tags));
}
pub(super) fn set_labels(&mut self, labels: Labels) {
self.values.labels = Some(Box::new(labels));
}
pub(super) fn set_secrets(&mut self, secrets: Vec<SecretGrant>) {
self.values.secrets = Some(Arc::new(secrets));
}
pub(super) fn set_ssh(&mut self, ssh: BuildSsh) {
self.values.ssh = Some(ssh);
}
pub(super) fn set_ulimits(&mut self, ulimits: Ulimits) {
self.values.ulimits = Some(Box::new(ulimits));
}
pub(super) fn push_extension(&mut self, field: FieldReference) {
self.extension_fields.push(field);
}
pub(super) fn push_unknown(&mut self, field: FieldReference) {
Arc::make_mut(&mut self.unknown_fields).push(field);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn context(&self) -> Option<&Located<String>> {
self.values.context.as_ref()
}
#[must_use]
pub const fn additional_contexts(&self) -> Option<&BuildAdditionalContexts> {
self.values.additional_contexts.as_ref()
}
#[must_use]
pub fn entitlements(&self) -> Option<&[Located<String>]> {
self.values.entitlements.as_deref().map(Vec::as_slice)
}
#[must_use]
pub const fn extra_hosts(&self) -> Option<&BuildExtraHosts> {
self.values.extra_hosts.as_ref()
}
#[must_use]
pub const fn args(&self) -> Option<&BuildArgs> {
self.values.args.as_ref()
}
#[must_use]
pub fn cache_from(&self) -> Option<&[Located<String>]> {
self.values.cache_from.as_deref().map(Vec::as_slice)
}
#[must_use]
pub fn cache_to(&self) -> Option<&[Located<String>]> {
self.values.cache_to.as_deref().map(Vec::as_slice)
}
#[must_use]
pub const fn dockerfile(&self) -> Option<&Located<String>> {
self.values.dockerfile.as_ref()
}
#[must_use]
pub const fn dockerfile_inline(&self) -> Option<&Located<String>> {
self.values.dockerfile_inline.as_ref()
}
#[must_use]
pub const fn target(&self) -> Option<&Located<String>> {
self.values.target.as_ref()
}
#[must_use]
pub fn network(&self) -> Option<&Located<String>> {
self.values.network.as_deref()
}
#[must_use]
pub fn isolation(&self) -> Option<&Located<String>> {
self.values.isolation.as_deref()
}
#[must_use]
pub fn platforms(&self) -> Option<&[Located<String>]> {
self.values.platforms.as_deref().map(Vec::as_slice)
}
#[must_use]
pub fn no_cache(&self) -> Option<&Located<BuildNoCache>> {
self.values.no_cache.as_deref()
}
#[must_use]
pub const fn no_cache_filter(&self) -> Option<&BuildNoCacheFilter> {
self.values.no_cache_filter.as_ref()
}
#[must_use]
pub fn privileged(&self) -> Option<&Located<BooleanValue>> {
self.values.privileged.as_deref()
}
#[must_use]
pub fn sbom(&self) -> Option<&Located<BuildSbom>> {
self.values.sbom.as_deref()
}
#[must_use]
pub fn provenance(&self) -> Option<&Located<BuildProvenance>> {
self.values.provenance.as_deref()
}
#[must_use]
pub fn pull(&self) -> Option<&Located<BooleanValue>> {
self.values.pull.as_deref()
}
#[must_use]
pub fn shm_size(&self) -> Option<&ShmSize> {
self.values.shm_size.as_deref()
}
#[must_use]
pub fn tags(&self) -> Option<&[Located<String>]> {
self.values.tags.as_deref().map(Vec::as_slice)
}
#[must_use]
pub fn labels(&self) -> Option<&Labels> {
self.values.labels.as_deref()
}
#[must_use]
pub fn secrets(&self) -> Option<&[SecretGrant]> {
self.values.secrets.as_deref().map(Vec::as_slice)
}
#[must_use]
pub const fn ssh(&self) -> Option<&BuildSsh> {
self.values.ssh.as_ref()
}
#[must_use]
pub fn ulimits(&self) -> Option<&Ulimits> {
self.values.ulimits.as_deref()
}
#[must_use]
pub fn fields(&self) -> &[BuildField] {
&self.fields
}
#[must_use]
pub fn field(&self, kind: BuildFieldKind) -> Option<&BuildField> {
self.fields.iter().find(|field| field.kind == kind)
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
self.unknown_fields.as_slice()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum BuildNoCacheFilter {
Scalar(Located<String>),
List(Vec<Located<String>>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BuildAdditionalContexts {
List {
span: SourceSpan,
values: Vec<Located<String>>,
},
Map {
span: SourceSpan,
entries: Vec<KeyValueEntry>,
},
}
impl BuildAdditionalContexts {
#[must_use]
pub const fn span(&self) -> SourceSpan {
match self {
Self::List { span, .. } | Self::Map { span, .. } => *span,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BuildArgs {
List {
span: SourceSpan,
values: Vec<Located<String>>,
},
Map {
span: SourceSpan,
entries: Vec<KeyValueEntry>,
},
}
impl BuildArgs {
#[must_use]
pub const fn span(&self) -> SourceSpan {
match self {
Self::List { span, .. } | Self::Map { span, .. } => *span,
}
}
}
#[derive(Clone, PartialEq, Eq)]
pub struct BuildSsh {
form: BuildSshForm,
span: SourceSpan,
storage: BuildSshStorage,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum BuildSshForm {
List,
Map,
}
#[derive(Clone, PartialEq, Eq)]
enum BuildSshStorage {
List(Vec<Located<String>>),
Map(Vec<KeyValueEntry>),
}
impl fmt::Debug for BuildSsh {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter
.debug_struct("BuildSsh")
.field("form", &self.form)
.field("span", &self.span)
.field("storage", &"<redacted>")
.finish()
}
}
impl BuildSsh {
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn form(&self) -> BuildSshForm {
self.form
}
#[must_use]
pub fn as_list(&self) -> Option<&[Located<String>]> {
let BuildSshStorage::List(values) = &self.storage else {
return None;
};
Some(values)
}
#[must_use]
pub fn as_map(&self) -> Option<&[KeyValueEntry]> {
let BuildSshStorage::Map(entries) = &self.storage else {
return None;
};
Some(entries)
}
pub(super) fn list(span: SourceSpan, values: Vec<Located<String>>) -> Self {
Self {
form: BuildSshForm::List,
span,
storage: BuildSshStorage::List(values),
}
}
pub(super) fn map(span: SourceSpan, entries: Vec<KeyValueEntry>) -> Self {
Self {
form: BuildSshForm::Map,
span,
storage: BuildSshStorage::Map(entries),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BuildField {
kind: BuildFieldKind,
reference: FieldReference,
}
impl BuildField {
pub(super) const fn new(kind: BuildFieldKind, reference: FieldReference) -> Self {
Self { kind, reference }
}
#[must_use]
pub const fn kind(&self) -> BuildFieldKind {
self.kind
}
#[must_use]
pub const fn reference(&self) -> &FieldReference {
&self.reference
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum BuildFieldKind {
AdditionalContexts,
Args,
CacheFrom,
CacheTo,
Context,
Dockerfile,
DockerfileInline,
Entitlements,
ExtraHosts,
Isolation,
Labels,
Network,
NoCache,
Platforms,
Privileged,
Provenance,
Pull,
Sbom,
Secrets,
Ssh,
ShmSize,
Tags,
Target,
Ulimits,
NoCacheFilter,
}
impl BuildFieldKind {
pub(super) fn from_name(name: &str) -> Option<Self> {
Some(match name {
"additional_contexts" => Self::AdditionalContexts,
"args" => Self::Args,
"cache_from" => Self::CacheFrom,
"cache_to" => Self::CacheTo,
"context" => Self::Context,
"dockerfile" => Self::Dockerfile,
"dockerfile_inline" => Self::DockerfileInline,
"entitlements" => Self::Entitlements,
"extra_hosts" => Self::ExtraHosts,
"isolation" => Self::Isolation,
"labels" => Self::Labels,
"network" => Self::Network,
"no_cache" => Self::NoCache,
"no_cache_filter" => Self::NoCacheFilter,
"platforms" => Self::Platforms,
"privileged" => Self::Privileged,
"provenance" => Self::Provenance,
"pull" => Self::Pull,
"sbom" => Self::Sbom,
"secrets" => Self::Secrets,
"ssh" => Self::Ssh,
"shm_size" => Self::ShmSize,
"tags" => Self::Tags,
"target" => Self::Target,
"ulimits" => Self::Ulimits,
_ => return None,
})
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployDefinition {
span: SourceSpan,
endpoint_mode: Option<Located<DeployEndpointMode>>,
labels: Option<Box<Labels>>,
mode: Option<Located<DeployMode>>,
placement: Option<Box<DeployPlacement>>,
replicas: Option<Located<DeployReplicas>>,
resources: Option<Box<DeployResources>>,
restart_policy: Option<Box<DeployRestartPolicy>>,
rollback_config: Option<Box<DeployRollbackConfig>>,
update_config: Option<Box<DeployUpdateConfig>>,
fields: Vec<DeployField>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl DeployDefinition {
pub(super) const fn new(span: SourceSpan) -> Self {
Self {
span,
endpoint_mode: None,
labels: None,
mode: None,
placement: None,
replicas: None,
resources: None,
restart_policy: None,
rollback_config: None,
update_config: None,
fields: Vec::new(),
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn push_field(&mut self, field: DeployField) {
self.fields.push(field);
}
pub(super) fn set_endpoint_mode(&mut self, endpoint_mode: Located<DeployEndpointMode>) {
self.endpoint_mode = Some(endpoint_mode);
}
pub(super) fn set_labels(&mut self, labels: Labels) {
self.labels = Some(Box::new(labels));
}
pub(super) fn set_mode(&mut self, mode: Located<DeployMode>) {
self.mode = Some(mode);
}
pub(super) fn set_placement(&mut self, placement: DeployPlacement) {
self.placement = Some(Box::new(placement));
}
pub(super) fn set_replicas(&mut self, replicas: Located<DeployReplicas>) {
self.replicas = Some(replicas);
}
pub(super) fn set_resources(&mut self, resources: DeployResources) {
self.resources = Some(Box::new(resources));
}
pub(super) fn set_restart_policy(&mut self, restart_policy: DeployRestartPolicy) {
self.restart_policy = Some(Box::new(restart_policy));
}
pub(super) fn set_rollback_config(&mut self, rollback_config: DeployRollbackConfig) {
self.rollback_config = Some(Box::new(rollback_config));
}
pub(super) fn set_update_config(&mut self, update_config: DeployUpdateConfig) {
self.update_config = Some(Box::new(update_config));
}
pub(super) fn push_extension(&mut self, field: FieldReference) {
self.extension_fields.push(field);
}
pub(super) fn push_unknown(&mut self, field: FieldReference) {
self.unknown_fields.push(field);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn endpoint_mode(&self) -> Option<&Located<DeployEndpointMode>> {
self.endpoint_mode.as_ref()
}
#[must_use]
pub fn labels(&self) -> Option<&Labels> {
self.labels.as_deref()
}
#[must_use]
pub const fn mode(&self) -> Option<&Located<DeployMode>> {
self.mode.as_ref()
}
#[must_use]
pub fn placement(&self) -> Option<&DeployPlacement> {
self.placement.as_deref()
}
#[must_use]
pub const fn replicas(&self) -> Option<&Located<DeployReplicas>> {
self.replicas.as_ref()
}
#[must_use]
pub fn resources(&self) -> Option<&DeployResources> {
self.resources.as_deref()
}
#[must_use]
pub fn restart_policy(&self) -> Option<&DeployRestartPolicy> {
self.restart_policy.as_deref()
}
#[must_use]
pub fn rollback_config(&self) -> Option<&DeployRollbackConfig> {
self.rollback_config.as_deref()
}
#[must_use]
pub fn update_config(&self) -> Option<&DeployUpdateConfig> {
self.update_config.as_deref()
}
#[must_use]
pub fn fields(&self) -> &[DeployField] {
&self.fields
}
#[must_use]
pub fn field(&self, kind: DeployFieldKind) -> Option<&DeployField> {
self.fields.iter().find(|field| field.kind == kind)
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployEndpointMode {
Vip,
Dnsrr,
Other(String),
}
impl DeployEndpointMode {
pub(crate) fn parse(value: String) -> Self {
match value.as_str() {
"vip" => Self::Vip,
"dnsrr" => Self::Dnsrr,
_ => Self::Other(value),
}
}
#[must_use]
pub const fn is_documented(&self) -> bool {
matches!(self, Self::Vip | Self::Dnsrr)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployMode {
Global,
Replicated,
Other(String),
}
impl DeployMode {
pub(crate) fn parse(value: String) -> Self {
match value.as_str() {
"global" => Self::Global,
"replicated" => Self::Replicated,
_ => Self::Other(value),
}
}
#[must_use]
pub const fn is_documented(&self) -> bool {
matches!(self, Self::Global | Self::Replicated)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployReplicas {
YamlNumber(String),
String(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployResources {
span: SourceSpan,
limits: Option<Box<DeployResourceLimits>>,
reservations: Option<Box<DeployResourceReservations>>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl DeployResources {
pub(super) const fn new(span: SourceSpan) -> Self {
Self {
span,
limits: None,
reservations: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn set_limits(&mut self, limits: DeployResourceLimits) {
self.limits = Some(Box::new(limits));
}
pub(super) fn set_reservations(&mut self, reservations: DeployResourceReservations) {
self.reservations = Some(Box::new(reservations));
}
pub(super) fn push_extension(&mut self, value: FieldReference) {
self.extension_fields.push(value);
}
pub(super) fn push_unknown(&mut self, value: FieldReference) {
self.unknown_fields.push(value);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub fn limits(&self) -> Option<&DeployResourceLimits> {
self.limits.as_deref()
}
#[must_use]
pub fn reservations(&self) -> Option<&DeployResourceReservations> {
self.reservations.as_deref()
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployResourceReservations {
span: SourceSpan,
cpus: Option<Located<DeployResourceCpus>>,
memory: Option<Located<DeployResourceMemory>>,
generic_resources: Option<DeployGenericResources>,
devices: Option<DeployReservationDevices>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl DeployResourceReservations {
pub(super) const fn new(span: SourceSpan) -> Self {
Self {
span,
cpus: None,
memory: None,
generic_resources: None,
devices: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn set_cpus(&mut self, cpus: Located<DeployResourceCpus>) {
self.cpus = Some(cpus);
}
pub(super) fn set_memory(&mut self, memory: Located<DeployResourceMemory>) {
self.memory = Some(memory);
}
pub(super) fn set_generic_resources(&mut self, generic_resources: DeployGenericResources) {
self.generic_resources = Some(generic_resources);
}
pub(super) fn set_devices(&mut self, devices: DeployReservationDevices) {
self.devices = Some(devices);
}
pub(super) fn push_extension(&mut self, value: FieldReference) {
self.extension_fields.push(value);
}
pub(super) fn push_unknown(&mut self, value: FieldReference) {
self.unknown_fields.push(value);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn cpus(&self) -> Option<&Located<DeployResourceCpus>> {
self.cpus.as_ref()
}
#[must_use]
pub const fn memory(&self) -> Option<&Located<DeployResourceMemory>> {
self.memory.as_ref()
}
#[must_use]
pub const fn generic_resources(&self) -> Option<&DeployGenericResources> {
self.generic_resources.as_ref()
}
#[must_use]
pub const fn devices(&self) -> Option<&DeployReservationDevices> {
self.devices.as_ref()
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployReservationDevices {
span: SourceSpan,
items: Vec<DeployReservationDevice>,
}
impl DeployReservationDevices {
pub(super) const fn new(span: SourceSpan, items: Vec<DeployReservationDevice>) -> Self {
Self { span, items }
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub fn items(&self) -> &[DeployReservationDevice] {
&self.items
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployReservationDevice {
span: SourceSpan,
form: DeployReservationDeviceForm,
capabilities: Option<DeployReservationDeviceCapabilities>,
driver: Option<Located<String>>,
count: Option<Located<DeployReservationDeviceCount>>,
device_ids: Option<DeployReservationDeviceIds>,
options: Option<DeployReservationDeviceOptions>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl DeployReservationDevice {
pub(super) fn new(span: SourceSpan) -> Self {
Self {
span,
form: DeployReservationDeviceForm::Mapping,
capabilities: None,
driver: None,
count: None,
device_ids: None,
options: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn unmodeled(span: SourceSpan) -> Self {
Self {
span,
form: DeployReservationDeviceForm::Unmodeled,
capabilities: None,
driver: None,
count: None,
device_ids: None,
options: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn set_capabilities(&mut self, capabilities: DeployReservationDeviceCapabilities) {
self.capabilities = Some(capabilities);
}
pub(super) fn set_driver(&mut self, driver: Located<String>) {
self.driver = Some(driver);
}
pub(super) fn set_count(&mut self, count: Located<DeployReservationDeviceCount>) {
self.count = Some(count);
}
pub(super) fn set_device_ids(&mut self, device_ids: DeployReservationDeviceIds) {
self.device_ids = Some(device_ids);
}
pub(super) fn set_options(&mut self, options: DeployReservationDeviceOptions) {
self.options = Some(options);
}
pub(super) fn push_extension(&mut self, value: FieldReference) {
self.extension_fields.push(value);
}
pub(super) fn push_unknown(&mut self, value: FieldReference) {
self.unknown_fields.push(value);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn form(&self) -> DeployReservationDeviceForm {
self.form
}
#[must_use]
pub const fn capabilities(&self) -> Option<&DeployReservationDeviceCapabilities> {
self.capabilities.as_ref()
}
#[must_use]
pub const fn driver(&self) -> Option<&Located<String>> {
self.driver.as_ref()
}
#[must_use]
pub const fn count(&self) -> Option<&Located<DeployReservationDeviceCount>> {
self.count.as_ref()
}
#[must_use]
pub const fn device_ids(&self) -> Option<&DeployReservationDeviceIds> {
self.device_ids.as_ref()
}
#[must_use]
pub const fn options(&self) -> Option<&DeployReservationDeviceOptions> {
self.options.as_ref()
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployReservationDeviceForm {
Mapping,
Unmodeled,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployReservationDeviceCount {
YamlInteger(String),
String(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployReservationDeviceIds {
span: SourceSpan,
items: Vec<DeployReservationDeviceId>,
}
impl DeployReservationDeviceIds {
pub(super) const fn new(span: SourceSpan, items: Vec<DeployReservationDeviceId>) -> Self {
Self { span, items }
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub fn items(&self) -> &[DeployReservationDeviceId] {
&self.items
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployReservationDeviceId {
span: SourceSpan,
form: DeployReservationDeviceIdForm,
value: Option<Located<String>>,
}
impl DeployReservationDeviceId {
pub(super) fn string(value: Located<String>) -> Self {
Self {
span: value.span(),
form: DeployReservationDeviceIdForm::String,
value: Some(value),
}
}
pub(super) const fn unmodeled(span: SourceSpan) -> Self {
Self {
span,
form: DeployReservationDeviceIdForm::Unmodeled,
value: None,
}
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn form(&self) -> DeployReservationDeviceIdForm {
self.form
}
#[must_use]
pub const fn value(&self) -> Option<&Located<String>> {
self.value.as_ref()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployReservationDeviceIdForm {
String,
Unmodeled,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployReservationDeviceOptions {
Map {
span: SourceSpan,
entries: Vec<KeyValueEntry>,
unmodeled_entries: Vec<FieldReference>,
},
List {
span: SourceSpan,
items: Vec<DeployReservationDeviceOptionItem>,
},
}
impl DeployReservationDeviceOptions {
#[must_use]
pub const fn span(&self) -> SourceSpan {
match self {
Self::Map { span, .. } | Self::List { span, .. } => *span,
}
}
#[must_use]
pub fn as_map(&self) -> Option<&[KeyValueEntry]> {
let Self::Map { entries, .. } = self else { return None };
Some(entries)
}
#[must_use]
pub fn unmodeled_entries(&self) -> Option<&[FieldReference]> {
let Self::Map { unmodeled_entries, .. } = self else {
return None;
};
Some(unmodeled_entries)
}
#[must_use]
pub fn as_list(&self) -> Option<&[DeployReservationDeviceOptionItem]> {
let Self::List { items, .. } = self else { return None };
Some(items)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployReservationDeviceOptionItem {
span: SourceSpan,
form: DeployReservationDeviceOptionItemForm,
value: Option<Located<String>>,
}
impl DeployReservationDeviceOptionItem {
pub(super) fn string(value: Located<String>) -> Self {
Self {
span: value.span(),
form: DeployReservationDeviceOptionItemForm::String,
value: Some(value),
}
}
pub(super) const fn unmodeled(span: SourceSpan) -> Self {
Self {
span,
form: DeployReservationDeviceOptionItemForm::Unmodeled,
value: None,
}
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn form(&self) -> DeployReservationDeviceOptionItemForm {
self.form
}
#[must_use]
pub const fn value(&self) -> Option<&Located<String>> {
self.value.as_ref()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployReservationDeviceOptionItemForm {
String,
Unmodeled,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployReservationDeviceCapabilities {
span: SourceSpan,
items: Vec<DeployReservationDeviceCapability>,
}
impl DeployReservationDeviceCapabilities {
pub(super) const fn new(span: SourceSpan, items: Vec<DeployReservationDeviceCapability>) -> Self {
Self { span, items }
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub fn items(&self) -> &[DeployReservationDeviceCapability] {
&self.items
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployReservationDeviceCapability {
span: SourceSpan,
form: DeployReservationDeviceCapabilityForm,
value: Option<Located<String>>,
}
impl DeployReservationDeviceCapability {
pub(super) fn string(value: Located<String>) -> Self {
Self {
span: value.span(),
form: DeployReservationDeviceCapabilityForm::String,
value: Some(value),
}
}
pub(super) const fn unmodeled(span: SourceSpan) -> Self {
Self {
span,
form: DeployReservationDeviceCapabilityForm::Unmodeled,
value: None,
}
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn form(&self) -> DeployReservationDeviceCapabilityForm {
self.form
}
#[must_use]
pub const fn value(&self) -> Option<&Located<String>> {
self.value.as_ref()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployReservationDeviceCapabilityForm {
String,
Unmodeled,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployGenericResources {
span: SourceSpan,
items: Vec<DeployGenericResource>,
}
impl DeployGenericResources {
pub(super) const fn new(span: SourceSpan, items: Vec<DeployGenericResource>) -> Self {
Self { span, items }
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub fn items(&self) -> &[DeployGenericResource] {
&self.items
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployGenericResource {
span: SourceSpan,
form: DeployGenericResourceForm,
discrete_resource_spec: Option<DeployDiscreteResourceSpec>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl DeployGenericResource {
pub(super) fn new(span: SourceSpan) -> Self {
Self {
span,
form: DeployGenericResourceForm::Mapping,
discrete_resource_spec: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn unmodeled(span: SourceSpan) -> Self {
Self {
span,
form: DeployGenericResourceForm::Unmodeled,
discrete_resource_spec: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn set_discrete_resource_spec(&mut self, value: DeployDiscreteResourceSpec) {
self.discrete_resource_spec = Some(value);
}
pub(super) fn push_extension(&mut self, value: FieldReference) {
self.extension_fields.push(value);
}
pub(super) fn push_unknown(&mut self, value: FieldReference) {
self.unknown_fields.push(value);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn form(&self) -> DeployGenericResourceForm {
self.form
}
#[must_use]
pub const fn discrete_resource_spec(&self) -> Option<&DeployDiscreteResourceSpec> {
self.discrete_resource_spec.as_ref()
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployGenericResourceForm {
Mapping,
Unmodeled,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployDiscreteResourceSpec {
span: SourceSpan,
kind: Option<Located<String>>,
value: Option<Located<DeployDiscreteResourceValue>>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl DeployDiscreteResourceSpec {
pub(super) fn new(span: SourceSpan) -> Self {
Self {
span,
kind: None,
value: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn set_kind(&mut self, value: Located<String>) {
self.kind = Some(value);
}
pub(super) fn set_value(&mut self, value: Located<DeployDiscreteResourceValue>) {
self.value = Some(value);
}
pub(super) fn push_extension(&mut self, value: FieldReference) {
self.extension_fields.push(value);
}
pub(super) fn push_unknown(&mut self, value: FieldReference) {
self.unknown_fields.push(value);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn kind(&self) -> Option<&Located<String>> {
self.kind.as_ref()
}
#[must_use]
pub const fn value(&self) -> Option<&Located<DeployDiscreteResourceValue>> {
self.value.as_ref()
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployDiscreteResourceValue {
YamlNumber(String),
String(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployResourceLimits {
span: SourceSpan,
cpus: Option<Located<DeployResourceCpus>>,
memory: Option<Located<DeployResourceMemory>>,
pids: Option<Located<DeployResourcePids>>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl DeployResourceLimits {
pub(super) const fn new(span: SourceSpan) -> Self {
Self {
span,
cpus: None,
memory: None,
pids: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn set_pids(&mut self, pids: Located<DeployResourcePids>) {
self.pids = Some(pids);
}
pub(super) fn set_cpus(&mut self, cpus: Located<DeployResourceCpus>) {
self.cpus = Some(cpus);
}
pub(super) fn set_memory(&mut self, memory: Located<DeployResourceMemory>) {
self.memory = Some(memory);
}
pub(super) fn push_extension(&mut self, value: FieldReference) {
self.extension_fields.push(value);
}
pub(super) fn push_unknown(&mut self, value: FieldReference) {
self.unknown_fields.push(value);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn pids(&self) -> Option<&Located<DeployResourcePids>> {
self.pids.as_ref()
}
#[must_use]
pub const fn cpus(&self) -> Option<&Located<DeployResourceCpus>> {
self.cpus.as_ref()
}
#[must_use]
pub const fn memory(&self) -> Option<&Located<DeployResourceMemory>> {
self.memory.as_ref()
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployResourcePids {
YamlInteger(String),
String(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployResourceCpus {
YamlNumber(String),
String(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployResourceMemory {
raw: String,
kind: DeployResourceMemoryKind,
}
impl DeployResourceMemory {
pub(crate) fn parse(raw: String) -> Self {
let kind = if raw.contains('$') {
DeployResourceMemoryKind::Expression
} else if let Some((amount_raw, unit)) = split_deploy_resource_memory_unit(&raw) {
if deploy_resource_memory_lexical_zero(amount_raw) {
DeployResourceMemoryKind::Zero {
amount_raw: amount_raw.to_owned(),
unit: Some(unit),
}
} else {
DeployResourceMemoryKind::Documented {
amount_raw: amount_raw.to_owned(),
unit,
}
}
} else if deploy_resource_memory_lexical_zero(&raw) {
DeployResourceMemoryKind::Zero {
amount_raw: raw.clone(),
unit: None,
}
} else {
DeployResourceMemoryKind::ProviderDependentString
};
Self { raw, kind }
}
#[must_use]
pub fn raw(&self) -> &str {
&self.raw
}
#[must_use]
pub const fn kind(&self) -> &DeployResourceMemoryKind {
&self.kind
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployResourceMemoryKind {
Documented {
amount_raw: String,
unit: DeployResourceMemoryUnit,
},
Zero {
amount_raw: String,
unit: Option<DeployResourceMemoryUnit>,
},
Expression,
ProviderDependentString,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum DeployResourceMemoryUnit {
B,
K,
Kb,
M,
Mb,
G,
Gb,
}
impl DeployResourceMemoryUnit {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::B => "b",
Self::K => "k",
Self::Kb => "kb",
Self::M => "m",
Self::Mb => "mb",
Self::G => "g",
Self::Gb => "gb",
}
}
}
fn split_deploy_resource_memory_unit(value: &str) -> Option<(&str, DeployResourceMemoryUnit)> {
for (suffix, unit) in [
("kb", DeployResourceMemoryUnit::Kb),
("mb", DeployResourceMemoryUnit::Mb),
("gb", DeployResourceMemoryUnit::Gb),
("b", DeployResourceMemoryUnit::B),
("k", DeployResourceMemoryUnit::K),
("m", DeployResourceMemoryUnit::M),
("g", DeployResourceMemoryUnit::G),
] {
if let Some(amount) = value.strip_suffix(suffix) {
if !amount.is_empty() {
return Some((amount, unit));
}
}
}
None
}
fn deploy_resource_memory_lexical_zero(value: &str) -> bool {
!value.is_empty() && value.bytes().all(|byte| byte == b'0')
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployRestartPolicy {
span: SourceSpan,
condition: Option<Located<DeployRestartCondition>>,
delay: Option<Located<DeployRestartDuration>>,
max_attempts: Option<Located<DeployRestartMaxAttempts>>,
window: Option<Located<DeployRestartDuration>>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl DeployRestartPolicy {
pub(super) const fn new(span: SourceSpan) -> Self {
Self {
span,
condition: None,
delay: None,
max_attempts: None,
window: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn set_condition(&mut self, value: Located<DeployRestartCondition>) {
self.condition = Some(value);
}
pub(super) fn set_delay(&mut self, value: Located<DeployRestartDuration>) {
self.delay = Some(value);
}
pub(super) fn set_max_attempts(&mut self, value: Located<DeployRestartMaxAttempts>) {
self.max_attempts = Some(value);
}
pub(super) fn set_window(&mut self, value: Located<DeployRestartDuration>) {
self.window = Some(value);
}
pub(super) fn push_extension(&mut self, value: FieldReference) {
self.extension_fields.push(value);
}
pub(super) fn push_unknown(&mut self, value: FieldReference) {
self.unknown_fields.push(value);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn condition(&self) -> Option<&Located<DeployRestartCondition>> {
self.condition.as_ref()
}
#[must_use]
pub const fn delay(&self) -> Option<&Located<DeployRestartDuration>> {
self.delay.as_ref()
}
#[must_use]
pub const fn max_attempts(&self) -> Option<&Located<DeployRestartMaxAttempts>> {
self.max_attempts.as_ref()
}
#[must_use]
pub const fn window(&self) -> Option<&Located<DeployRestartDuration>> {
self.window.as_ref()
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployRestartCondition {
None,
OnFailure,
Any,
Expression(String),
Other(String),
}
impl DeployRestartCondition {
pub(crate) fn parse(value: String) -> Self {
match value.as_str() {
"none" => Self::None,
"on-failure" => Self::OnFailure,
"any" => Self::Any,
_ if value.contains('$') => Self::Expression(value),
_ => Self::Other(value),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployRestartDuration(String);
impl DeployRestartDuration {
pub(crate) const fn new(value: String) -> Self {
Self(value)
}
#[must_use]
pub fn raw(&self) -> &str {
&self.0
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployRestartMaxAttempts {
YamlNumber(String),
String(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployRollbackConfig {
span: SourceSpan,
parallelism: Option<Located<DeployRollbackParallelism>>,
delay: Option<Located<String>>,
monitor: Option<Located<String>>,
failure_action: Option<Located<String>>,
max_failure_ratio: Option<Located<DeployRollbackMaxFailureRatio>>,
order: Option<Located<DeployRollbackOrder>>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl DeployRollbackConfig {
pub(super) const fn new(span: SourceSpan) -> Self {
Self {
span,
parallelism: None,
delay: None,
monitor: None,
failure_action: None,
max_failure_ratio: None,
order: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn set_parallelism(&mut self, value: Located<DeployRollbackParallelism>) {
self.parallelism = Some(value);
}
pub(super) fn set_delay(&mut self, value: Located<String>) {
self.delay = Some(value);
}
pub(super) fn set_monitor(&mut self, value: Located<String>) {
self.monitor = Some(value);
}
pub(super) fn set_failure_action(&mut self, value: Located<String>) {
self.failure_action = Some(value);
}
pub(super) fn set_max_failure_ratio(&mut self, value: Located<DeployRollbackMaxFailureRatio>) {
self.max_failure_ratio = Some(value);
}
pub(super) fn set_order(&mut self, value: Located<DeployRollbackOrder>) {
self.order = Some(value);
}
pub(super) fn push_extension(&mut self, value: FieldReference) {
self.extension_fields.push(value);
}
pub(super) fn push_unknown(&mut self, value: FieldReference) {
self.unknown_fields.push(value);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn parallelism(&self) -> Option<&Located<DeployRollbackParallelism>> {
self.parallelism.as_ref()
}
#[must_use]
pub const fn delay(&self) -> Option<&Located<String>> {
self.delay.as_ref()
}
#[must_use]
pub const fn monitor(&self) -> Option<&Located<String>> {
self.monitor.as_ref()
}
#[must_use]
pub const fn failure_action(&self) -> Option<&Located<String>> {
self.failure_action.as_ref()
}
#[must_use]
pub const fn max_failure_ratio(&self) -> Option<&Located<DeployRollbackMaxFailureRatio>> {
self.max_failure_ratio.as_ref()
}
#[must_use]
pub const fn order(&self) -> Option<&Located<DeployRollbackOrder>> {
self.order.as_ref()
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployRollbackParallelism {
YamlInteger(String),
String(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployRollbackMaxFailureRatio {
YamlNumber(String),
String(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployRollbackOrder {
StopFirst,
StartFirst,
Other(String),
}
impl DeployRollbackOrder {
pub(crate) fn parse(value: String) -> Self {
match value.as_str() {
"stop-first" => Self::StopFirst,
"start-first" => Self::StartFirst,
_ => Self::Other(value),
}
}
pub(crate) const fn is_documented(&self) -> bool {
matches!(self, Self::StopFirst | Self::StartFirst)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployUpdateConfig {
span: SourceSpan,
parallelism: Option<Located<DeployUpdateParallelism>>,
delay: Option<Located<String>>,
monitor: Option<Located<String>>,
failure_action: Option<Located<String>>,
max_failure_ratio: Option<Located<DeployUpdateMaxFailureRatio>>,
order: Option<Located<DeployUpdateOrder>>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl DeployUpdateConfig {
pub(super) const fn new(span: SourceSpan) -> Self {
Self {
span,
parallelism: None,
delay: None,
monitor: None,
failure_action: None,
max_failure_ratio: None,
order: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn set_parallelism(&mut self, value: Located<DeployUpdateParallelism>) {
self.parallelism = Some(value);
}
pub(super) fn set_delay(&mut self, value: Located<String>) {
self.delay = Some(value);
}
pub(super) fn set_monitor(&mut self, value: Located<String>) {
self.monitor = Some(value);
}
pub(super) fn set_failure_action(&mut self, value: Located<String>) {
self.failure_action = Some(value);
}
pub(super) fn set_max_failure_ratio(&mut self, value: Located<DeployUpdateMaxFailureRatio>) {
self.max_failure_ratio = Some(value);
}
pub(super) fn set_order(&mut self, value: Located<DeployUpdateOrder>) {
self.order = Some(value);
}
pub(super) fn push_extension(&mut self, value: FieldReference) {
self.extension_fields.push(value);
}
pub(super) fn push_unknown(&mut self, value: FieldReference) {
self.unknown_fields.push(value);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn parallelism(&self) -> Option<&Located<DeployUpdateParallelism>> {
self.parallelism.as_ref()
}
#[must_use]
pub const fn delay(&self) -> Option<&Located<String>> {
self.delay.as_ref()
}
#[must_use]
pub const fn monitor(&self) -> Option<&Located<String>> {
self.monitor.as_ref()
}
#[must_use]
pub const fn failure_action(&self) -> Option<&Located<String>> {
self.failure_action.as_ref()
}
#[must_use]
pub const fn max_failure_ratio(&self) -> Option<&Located<DeployUpdateMaxFailureRatio>> {
self.max_failure_ratio.as_ref()
}
#[must_use]
pub const fn order(&self) -> Option<&Located<DeployUpdateOrder>> {
self.order.as_ref()
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployUpdateParallelism {
YamlInteger(String),
String(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployUpdateMaxFailureRatio {
YamlNumber(String),
String(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployUpdateOrder {
StopFirst,
StartFirst,
Other(String),
}
impl DeployUpdateOrder {
pub(crate) fn parse(value: String) -> Self {
match value.as_str() {
"stop-first" => Self::StopFirst,
"start-first" => Self::StartFirst,
_ => Self::Other(value),
}
}
pub(crate) const fn is_documented(&self) -> bool {
matches!(self, Self::StopFirst | Self::StartFirst)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployPlacement {
span: SourceSpan,
constraints: Option<Vec<Located<String>>>,
preferences: Option<Vec<DeployPlacementPreference>>,
max_replicas_per_node: Option<Located<DeployPlacementMaxReplicasPerNode>>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl DeployPlacement {
pub(super) const fn new(span: SourceSpan) -> Self {
Self {
span,
constraints: None,
preferences: None,
max_replicas_per_node: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn set_constraints(&mut self, constraints: Vec<Located<String>>) {
self.constraints = Some(constraints);
}
pub(super) fn set_preferences(&mut self, preferences: Vec<DeployPlacementPreference>) {
self.preferences = Some(preferences);
}
pub(super) fn set_max_replicas_per_node(&mut self, value: Located<DeployPlacementMaxReplicasPerNode>) {
self.max_replicas_per_node = Some(value);
}
pub(super) fn push_extension(&mut self, value: FieldReference) {
self.extension_fields.push(value);
}
pub(super) fn push_unknown(&mut self, value: FieldReference) {
self.unknown_fields.push(value);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub fn constraints(&self) -> Option<&[Located<String>]> {
self.constraints.as_deref()
}
#[must_use]
pub fn preferences(&self) -> Option<&[DeployPlacementPreference]> {
self.preferences.as_deref()
}
#[must_use]
pub const fn max_replicas_per_node(&self) -> Option<&Located<DeployPlacementMaxReplicasPerNode>> {
self.max_replicas_per_node.as_ref()
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployPlacementPreference {
span: SourceSpan,
spread: Option<Located<String>>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl DeployPlacementPreference {
pub(super) const fn new(span: SourceSpan) -> Self {
Self {
span,
spread: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn set_spread(&mut self, spread: Located<String>) {
self.spread = Some(spread);
}
pub(super) fn push_extension(&mut self, value: FieldReference) {
self.extension_fields.push(value);
}
pub(super) fn push_unknown(&mut self, value: FieldReference) {
self.unknown_fields.push(value);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn spread(&self) -> Option<&Located<String>> {
self.spread.as_ref()
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployPlacementMaxReplicasPerNode {
YamlInteger(String),
String(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeployField {
kind: DeployFieldKind,
reference: FieldReference,
}
impl DeployField {
pub(super) const fn new(kind: DeployFieldKind, reference: FieldReference) -> Self {
Self { kind, reference }
}
#[must_use]
pub const fn kind(&self) -> DeployFieldKind {
self.kind
}
#[must_use]
pub const fn reference(&self) -> &FieldReference {
&self.reference
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum DeployFieldKind {
EndpointMode,
Labels,
Mode,
Placement,
Replicas,
Resources,
RestartPolicy,
RollbackConfig,
UpdateConfig,
}
impl DeployFieldKind {
pub(super) fn from_name(name: &str) -> Option<Self> {
Some(match name {
"endpoint_mode" => Self::EndpointMode,
"labels" => Self::Labels,
"mode" => Self::Mode,
"placement" => Self::Placement,
"replicas" => Self::Replicas,
"resources" => Self::Resources,
"restart_policy" => Self::RestartPolicy,
"rollback_config" => Self::RollbackConfig,
"update_config" => Self::UpdateConfig,
_ => return None,
})
}
}