1use super::{
4 BooleanValue, BuildExtraHosts, BuildNoCache, BuildProvenance, BuildSbom, FieldReference, KeyValueEntry, Labels,
5 Located, SecretGrant, ShmSize, Ulimits,
6};
7use crate::source::SourceSpan;
8use std::fmt;
9use std::sync::Arc;
10
11#[derive(Debug, Clone, PartialEq, Eq)]
13pub enum Build {
14 Context(Located<String>),
16 Definition(BuildDefinition),
18}
19
20#[derive(Debug, Clone, PartialEq, Eq)]
22pub struct BuildDefinition {
23 span: SourceSpan,
24 values: Box<BuildValues>,
25 fields: Vec<BuildField>,
26 extension_fields: Vec<FieldReference>,
27 unknown_fields: Arc<Vec<FieldReference>>,
28}
29
30#[derive(Debug, Clone, PartialEq, Eq)]
33struct BuildValues {
34 additional_contexts: Option<BuildAdditionalContexts>,
35 entitlements: Option<Arc<Vec<Located<String>>>>,
36 extra_hosts: Option<BuildExtraHosts>,
37 context: Option<Located<String>>,
38 args: Option<BuildArgs>,
39 cache_from: Option<Arc<Vec<Located<String>>>>,
40 cache_to: Option<Arc<Vec<Located<String>>>>,
41 dockerfile: Option<Located<String>>,
42 dockerfile_inline: Option<Located<String>>,
43 target: Option<Located<String>>,
44 network: Option<Box<Located<String>>>,
45 isolation: Option<Box<Located<String>>>,
46 platforms: Option<Arc<Vec<Located<String>>>>,
47 no_cache: Option<Box<Located<BuildNoCache>>>,
48 no_cache_filter: Option<BuildNoCacheFilter>,
49 privileged: Option<Box<Located<BooleanValue>>>,
50 sbom: Option<Box<Located<BuildSbom>>>,
51 provenance: Option<Box<Located<BuildProvenance>>>,
52 pull: Option<Box<Located<BooleanValue>>>,
53 shm_size: Option<Box<ShmSize>>,
54 tags: Option<Arc<Vec<Located<String>>>>,
55 labels: Option<Box<Labels>>,
56 secrets: Option<Arc<Vec<SecretGrant>>>,
57 ssh: Option<BuildSsh>,
58 ulimits: Option<Box<Ulimits>>,
59}
60
61impl BuildDefinition {
62 pub(super) fn new(span: SourceSpan) -> Self {
63 Self {
64 span,
65 values: Box::new(BuildValues {
66 additional_contexts: None,
67 entitlements: None,
68 extra_hosts: None,
69 context: None,
70 args: None,
71 cache_from: None,
72 cache_to: None,
73 dockerfile: None,
74 dockerfile_inline: None,
75 target: None,
76 network: None,
77 isolation: None,
78 platforms: None,
79 no_cache: None,
80 no_cache_filter: None,
81 privileged: None,
82 sbom: None,
83 provenance: None,
84 pull: None,
85 shm_size: None,
86 tags: None,
87 labels: None,
88 secrets: None,
89 ssh: None,
90 ulimits: None,
91 }),
92 fields: Vec::new(),
93 extension_fields: Vec::new(),
94 unknown_fields: Arc::new(Vec::new()),
95 }
96 }
97
98 pub(super) fn push_field(&mut self, field: BuildField) {
99 self.fields.push(field);
100 }
101
102 pub(super) fn set_context(&mut self, context: Located<String>) {
103 self.values.context = Some(context);
104 }
105
106 pub(super) fn set_additional_contexts(&mut self, additional_contexts: Option<BuildAdditionalContexts>) {
107 self.values.additional_contexts = additional_contexts;
108 }
109
110 pub(super) fn set_entitlements(&mut self, entitlements: Vec<Located<String>>) {
111 self.values.entitlements = Some(Arc::new(entitlements));
112 }
113
114 pub(super) fn set_extra_hosts(&mut self, extra_hosts: BuildExtraHosts) {
115 self.values.extra_hosts = Some(extra_hosts);
116 }
117
118 pub(super) fn set_args(&mut self, args: BuildArgs) {
119 self.values.args = Some(args);
120 }
121
122 pub(super) fn set_cache_from(&mut self, cache_from: Vec<Located<String>>) {
123 self.values.cache_from = Some(Arc::new(cache_from));
124 }
125
126 pub(super) fn set_cache_to(&mut self, cache_to: Vec<Located<String>>) {
127 self.values.cache_to = Some(Arc::new(cache_to));
128 }
129
130 pub(super) fn set_dockerfile(&mut self, dockerfile: Located<String>) {
131 self.values.dockerfile = Some(dockerfile);
132 }
133
134 pub(super) fn set_dockerfile_inline(&mut self, dockerfile_inline: Located<String>) {
135 self.values.dockerfile_inline = Some(dockerfile_inline);
136 }
137
138 pub(super) fn set_target(&mut self, target: Located<String>) {
139 self.values.target = Some(target);
140 }
141
142 pub(super) fn set_network(&mut self, network: Located<String>) {
143 self.values.network = Some(Box::new(network));
144 }
145
146 pub(super) fn set_isolation(&mut self, isolation: Located<String>) {
147 self.values.isolation = Some(Box::new(isolation));
148 }
149
150 pub(super) fn set_platforms(&mut self, platforms: Vec<Located<String>>) {
151 self.values.platforms = Some(Arc::new(platforms));
152 }
153
154 pub(super) fn set_no_cache(&mut self, no_cache: Located<BuildNoCache>) {
155 self.values.no_cache = Some(Box::new(no_cache));
156 }
157 pub(super) fn set_no_cache_filter(&mut self, value: BuildNoCacheFilter) {
158 self.values.no_cache_filter = Some(value);
159 }
160 pub(super) fn set_privileged(&mut self, value: Located<BooleanValue>) {
161 self.values.privileged = Some(Box::new(value));
162 }
163
164 pub(super) fn set_sbom(&mut self, sbom: Located<BuildSbom>) {
165 self.values.sbom = Some(Box::new(sbom));
166 }
167 pub(super) fn set_provenance(&mut self, value: Located<BuildProvenance>) {
168 self.values.provenance = Some(Box::new(value));
169 }
170
171 pub(super) fn set_pull(&mut self, pull: Located<BooleanValue>) {
172 self.values.pull = Some(Box::new(pull));
173 }
174
175 pub(super) fn set_shm_size(&mut self, shm_size: ShmSize) {
176 self.values.shm_size = Some(Box::new(shm_size));
177 }
178
179 pub(super) fn set_tags(&mut self, tags: Vec<Located<String>>) {
180 self.values.tags = Some(Arc::new(tags));
181 }
182
183 pub(super) fn set_labels(&mut self, labels: Labels) {
184 self.values.labels = Some(Box::new(labels));
185 }
186
187 pub(super) fn set_secrets(&mut self, secrets: Vec<SecretGrant>) {
188 self.values.secrets = Some(Arc::new(secrets));
189 }
190
191 pub(super) fn set_ssh(&mut self, ssh: BuildSsh) {
192 self.values.ssh = Some(ssh);
193 }
194
195 pub(super) fn set_ulimits(&mut self, ulimits: Ulimits) {
196 self.values.ulimits = Some(Box::new(ulimits));
197 }
198
199 pub(super) fn push_extension(&mut self, field: FieldReference) {
200 self.extension_fields.push(field);
201 }
202
203 pub(super) fn push_unknown(&mut self, field: FieldReference) {
204 Arc::make_mut(&mut self.unknown_fields).push(field);
205 }
206
207 #[must_use]
212 pub const fn span(&self) -> SourceSpan {
213 self.span
214 }
215
216 #[must_use]
222 pub const fn context(&self) -> Option<&Located<String>> {
223 self.values.context.as_ref()
224 }
225
226 #[must_use]
233 pub const fn additional_contexts(&self) -> Option<&BuildAdditionalContexts> {
234 self.values.additional_contexts.as_ref()
235 }
236
237 #[must_use]
244 pub fn entitlements(&self) -> Option<&[Located<String>]> {
245 self.values.entitlements.as_deref().map(Vec::as_slice)
246 }
247
248 #[must_use]
255 pub const fn extra_hosts(&self) -> Option<&BuildExtraHosts> {
256 self.values.extra_hosts.as_ref()
257 }
258
259 #[must_use]
265 pub const fn args(&self) -> Option<&BuildArgs> {
266 self.values.args.as_ref()
267 }
268
269 #[must_use]
276 pub fn cache_from(&self) -> Option<&[Located<String>]> {
277 self.values.cache_from.as_deref().map(Vec::as_slice)
278 }
279
280 #[must_use]
287 pub fn cache_to(&self) -> Option<&[Located<String>]> {
288 self.values.cache_to.as_deref().map(Vec::as_slice)
289 }
290
291 #[must_use]
297 pub const fn dockerfile(&self) -> Option<&Located<String>> {
298 self.values.dockerfile.as_ref()
299 }
300
301 #[must_use]
307 pub const fn dockerfile_inline(&self) -> Option<&Located<String>> {
308 self.values.dockerfile_inline.as_ref()
309 }
310
311 #[must_use]
315 pub const fn target(&self) -> Option<&Located<String>> {
316 self.values.target.as_ref()
317 }
318
319 #[must_use]
324 pub fn network(&self) -> Option<&Located<String>> {
325 self.values.network.as_deref()
326 }
327
328 #[must_use]
334 pub fn isolation(&self) -> Option<&Located<String>> {
335 self.values.isolation.as_deref()
336 }
337
338 #[must_use]
343 pub fn platforms(&self) -> Option<&[Located<String>]> {
344 self.values.platforms.as_deref().map(Vec::as_slice)
345 }
346
347 #[must_use]
353 pub fn no_cache(&self) -> Option<&Located<BuildNoCache>> {
354 self.values.no_cache.as_deref()
355 }
356 #[must_use]
358 pub const fn no_cache_filter(&self) -> Option<&BuildNoCacheFilter> {
359 self.values.no_cache_filter.as_ref()
360 }
361 #[must_use]
363 pub fn privileged(&self) -> Option<&Located<BooleanValue>> {
364 self.values.privileged.as_deref()
365 }
366
367 #[must_use]
373 pub fn sbom(&self) -> Option<&Located<BuildSbom>> {
374 self.values.sbom.as_deref()
375 }
376 #[must_use]
378 pub fn provenance(&self) -> Option<&Located<BuildProvenance>> {
379 self.values.provenance.as_deref()
380 }
381
382 #[must_use]
388 pub fn pull(&self) -> Option<&Located<BooleanValue>> {
389 self.values.pull.as_deref()
390 }
391
392 #[must_use]
399 pub fn shm_size(&self) -> Option<&ShmSize> {
400 self.values.shm_size.as_deref()
401 }
402
403 #[must_use]
408 pub fn tags(&self) -> Option<&[Located<String>]> {
409 self.values.tags.as_deref().map(Vec::as_slice)
410 }
411
412 #[must_use]
417 pub fn labels(&self) -> Option<&Labels> {
418 self.values.labels.as_deref()
419 }
420
421 #[must_use]
427 pub fn secrets(&self) -> Option<&[SecretGrant]> {
428 self.values.secrets.as_deref().map(Vec::as_slice)
429 }
430
431 #[must_use]
436 pub const fn ssh(&self) -> Option<&BuildSsh> {
437 self.values.ssh.as_ref()
438 }
439
440 #[must_use]
446 pub fn ulimits(&self) -> Option<&Ulimits> {
447 self.values.ulimits.as_deref()
448 }
449
450 #[must_use]
452 pub fn fields(&self) -> &[BuildField] {
453 &self.fields
454 }
455
456 #[must_use]
458 pub fn field(&self, kind: BuildFieldKind) -> Option<&BuildField> {
459 self.fields.iter().find(|field| field.kind == kind)
460 }
461
462 #[must_use]
464 pub fn extension_fields(&self) -> &[FieldReference] {
465 &self.extension_fields
466 }
467
468 #[must_use]
470 pub fn unknown_fields(&self) -> &[FieldReference] {
471 self.unknown_fields.as_slice()
472 }
473}
474
475#[derive(Debug, Clone, PartialEq, Eq)]
477#[non_exhaustive]
478pub enum BuildNoCacheFilter {
479 Scalar(Located<String>),
481 List(Vec<Located<String>>),
483}
484
485#[derive(Debug, Clone, PartialEq, Eq)]
487pub enum BuildAdditionalContexts {
488 List {
490 span: SourceSpan,
492 values: Vec<Located<String>>,
494 },
495 Map {
497 span: SourceSpan,
499 entries: Vec<KeyValueEntry>,
501 },
502}
503
504impl BuildAdditionalContexts {
505 #[must_use]
507 pub const fn span(&self) -> SourceSpan {
508 match self {
509 Self::List { span, .. } | Self::Map { span, .. } => *span,
510 }
511 }
512}
513
514#[derive(Debug, Clone, PartialEq, Eq)]
516pub enum BuildArgs {
517 List {
519 span: SourceSpan,
521 values: Vec<Located<String>>,
523 },
524 Map {
526 span: SourceSpan,
528 entries: Vec<KeyValueEntry>,
530 },
531}
532
533impl BuildArgs {
534 #[must_use]
536 pub const fn span(&self) -> SourceSpan {
537 match self {
538 Self::List { span, .. } | Self::Map { span, .. } => *span,
539 }
540 }
541}
542
543#[derive(Clone, PartialEq, Eq)]
560pub struct BuildSsh {
561 form: BuildSshForm,
562 span: SourceSpan,
563 storage: BuildSshStorage,
564}
565
566#[derive(Clone, Copy, Debug, PartialEq, Eq)]
567#[non_exhaustive]
568pub enum BuildSshForm {
570 List,
572 Map,
574}
575
576#[derive(Clone, PartialEq, Eq)]
577enum BuildSshStorage {
578 List(Vec<Located<String>>),
579 Map(Vec<KeyValueEntry>),
580}
581
582impl fmt::Debug for BuildSsh {
583 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
584 formatter
585 .debug_struct("BuildSsh")
586 .field("form", &self.form)
587 .field("span", &self.span)
588 .field("storage", &"<redacted>")
589 .finish()
590 }
591}
592
593impl BuildSsh {
594 #[must_use]
596 pub const fn span(&self) -> SourceSpan {
597 self.span
598 }
599
600 #[must_use]
602 pub const fn form(&self) -> BuildSshForm {
603 self.form
604 }
605
606 #[must_use]
608 pub fn as_list(&self) -> Option<&[Located<String>]> {
609 let BuildSshStorage::List(values) = &self.storage else {
610 return None;
611 };
612 Some(values)
613 }
614
615 #[must_use]
617 pub fn as_map(&self) -> Option<&[KeyValueEntry]> {
618 let BuildSshStorage::Map(entries) = &self.storage else {
619 return None;
620 };
621 Some(entries)
622 }
623
624 pub(super) fn list(span: SourceSpan, values: Vec<Located<String>>) -> Self {
625 Self {
626 form: BuildSshForm::List,
627 span,
628 storage: BuildSshStorage::List(values),
629 }
630 }
631
632 pub(super) fn map(span: SourceSpan, entries: Vec<KeyValueEntry>) -> Self {
633 Self {
634 form: BuildSshForm::Map,
635 span,
636 storage: BuildSshStorage::Map(entries),
637 }
638 }
639}
640
641#[derive(Debug, Clone, PartialEq, Eq)]
643pub struct BuildField {
644 kind: BuildFieldKind,
645 reference: FieldReference,
646}
647
648impl BuildField {
649 pub(super) const fn new(kind: BuildFieldKind, reference: FieldReference) -> Self {
650 Self { kind, reference }
651 }
652
653 #[must_use]
655 pub const fn kind(&self) -> BuildFieldKind {
656 self.kind
657 }
658
659 #[must_use]
661 pub const fn reference(&self) -> &FieldReference {
662 &self.reference
663 }
664}
665
666#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
668#[non_exhaustive]
669pub enum BuildFieldKind {
670 AdditionalContexts,
672 Args,
674 CacheFrom,
676 CacheTo,
678 Context,
680 Dockerfile,
682 DockerfileInline,
684 Entitlements,
686 ExtraHosts,
688 Isolation,
690 Labels,
692 Network,
694 NoCache,
696 Platforms,
698 Privileged,
700 Provenance,
702 Pull,
704 Sbom,
706 Secrets,
708 Ssh,
710 ShmSize,
712 Tags,
714 Target,
716 Ulimits,
718 NoCacheFilter,
720}
721
722impl BuildFieldKind {
723 pub(super) fn from_name(name: &str) -> Option<Self> {
724 Some(match name {
725 "additional_contexts" => Self::AdditionalContexts,
726 "args" => Self::Args,
727 "cache_from" => Self::CacheFrom,
728 "cache_to" => Self::CacheTo,
729 "context" => Self::Context,
730 "dockerfile" => Self::Dockerfile,
731 "dockerfile_inline" => Self::DockerfileInline,
732 "entitlements" => Self::Entitlements,
733 "extra_hosts" => Self::ExtraHosts,
734 "isolation" => Self::Isolation,
735 "labels" => Self::Labels,
736 "network" => Self::Network,
737 "no_cache" => Self::NoCache,
738 "no_cache_filter" => Self::NoCacheFilter,
739 "platforms" => Self::Platforms,
740 "privileged" => Self::Privileged,
741 "provenance" => Self::Provenance,
742 "pull" => Self::Pull,
743 "sbom" => Self::Sbom,
744 "secrets" => Self::Secrets,
745 "ssh" => Self::Ssh,
746 "shm_size" => Self::ShmSize,
747 "tags" => Self::Tags,
748 "target" => Self::Target,
749 "ulimits" => Self::Ulimits,
750 _ => return None,
751 })
752 }
753}
754
755#[derive(Debug, Clone, PartialEq, Eq)]
757pub struct DeployDefinition {
758 span: SourceSpan,
759 endpoint_mode: Option<Located<DeployEndpointMode>>,
760 labels: Option<Box<Labels>>,
761 mode: Option<Located<DeployMode>>,
762 placement: Option<Box<DeployPlacement>>,
763 replicas: Option<Located<DeployReplicas>>,
764 resources: Option<Box<DeployResources>>,
765 restart_policy: Option<Box<DeployRestartPolicy>>,
766 rollback_config: Option<Box<DeployRollbackConfig>>,
767 update_config: Option<Box<DeployUpdateConfig>>,
768 fields: Vec<DeployField>,
769 extension_fields: Vec<FieldReference>,
770 unknown_fields: Vec<FieldReference>,
771}
772
773impl DeployDefinition {
774 pub(super) const fn new(span: SourceSpan) -> Self {
775 Self {
776 span,
777 endpoint_mode: None,
778 labels: None,
779 mode: None,
780 placement: None,
781 replicas: None,
782 resources: None,
783 restart_policy: None,
784 rollback_config: None,
785 update_config: None,
786 fields: Vec::new(),
787 extension_fields: Vec::new(),
788 unknown_fields: Vec::new(),
789 }
790 }
791
792 pub(super) fn push_field(&mut self, field: DeployField) {
793 self.fields.push(field);
794 }
795
796 pub(super) fn set_endpoint_mode(&mut self, endpoint_mode: Located<DeployEndpointMode>) {
797 self.endpoint_mode = Some(endpoint_mode);
798 }
799
800 pub(super) fn set_labels(&mut self, labels: Labels) {
801 self.labels = Some(Box::new(labels));
802 }
803
804 pub(super) fn set_mode(&mut self, mode: Located<DeployMode>) {
805 self.mode = Some(mode);
806 }
807
808 pub(super) fn set_placement(&mut self, placement: DeployPlacement) {
809 self.placement = Some(Box::new(placement));
810 }
811
812 pub(super) fn set_replicas(&mut self, replicas: Located<DeployReplicas>) {
813 self.replicas = Some(replicas);
814 }
815
816 pub(super) fn set_resources(&mut self, resources: DeployResources) {
817 self.resources = Some(Box::new(resources));
818 }
819
820 pub(super) fn set_restart_policy(&mut self, restart_policy: DeployRestartPolicy) {
821 self.restart_policy = Some(Box::new(restart_policy));
822 }
823 pub(super) fn set_rollback_config(&mut self, rollback_config: DeployRollbackConfig) {
824 self.rollback_config = Some(Box::new(rollback_config));
825 }
826 pub(super) fn set_update_config(&mut self, update_config: DeployUpdateConfig) {
827 self.update_config = Some(Box::new(update_config));
828 }
829
830 pub(super) fn push_extension(&mut self, field: FieldReference) {
831 self.extension_fields.push(field);
832 }
833
834 pub(super) fn push_unknown(&mut self, field: FieldReference) {
835 self.unknown_fields.push(field);
836 }
837
838 #[must_use]
840 pub const fn span(&self) -> SourceSpan {
841 self.span
842 }
843
844 #[must_use]
846 pub const fn endpoint_mode(&self) -> Option<&Located<DeployEndpointMode>> {
847 self.endpoint_mode.as_ref()
848 }
849
850 #[must_use]
852 pub fn labels(&self) -> Option<&Labels> {
853 self.labels.as_deref()
854 }
855
856 #[must_use]
858 pub const fn mode(&self) -> Option<&Located<DeployMode>> {
859 self.mode.as_ref()
860 }
861
862 #[must_use]
864 pub fn placement(&self) -> Option<&DeployPlacement> {
865 self.placement.as_deref()
866 }
867
868 #[must_use]
870 pub const fn replicas(&self) -> Option<&Located<DeployReplicas>> {
871 self.replicas.as_ref()
872 }
873
874 #[must_use]
876 pub fn resources(&self) -> Option<&DeployResources> {
877 self.resources.as_deref()
878 }
879
880 #[must_use]
882 pub fn restart_policy(&self) -> Option<&DeployRestartPolicy> {
883 self.restart_policy.as_deref()
884 }
885 #[must_use]
887 pub fn rollback_config(&self) -> Option<&DeployRollbackConfig> {
888 self.rollback_config.as_deref()
889 }
890 #[must_use]
892 pub fn update_config(&self) -> Option<&DeployUpdateConfig> {
893 self.update_config.as_deref()
894 }
895
896 #[must_use]
898 pub fn fields(&self) -> &[DeployField] {
899 &self.fields
900 }
901
902 #[must_use]
904 pub fn field(&self, kind: DeployFieldKind) -> Option<&DeployField> {
905 self.fields.iter().find(|field| field.kind == kind)
906 }
907
908 #[must_use]
910 pub fn extension_fields(&self) -> &[FieldReference] {
911 &self.extension_fields
912 }
913
914 #[must_use]
916 pub fn unknown_fields(&self) -> &[FieldReference] {
917 &self.unknown_fields
918 }
919}
920
921#[derive(Debug, Clone, PartialEq, Eq)]
923#[non_exhaustive]
924pub enum DeployEndpointMode {
925 Vip,
927 Dnsrr,
929 Other(String),
931}
932
933impl DeployEndpointMode {
934 pub(crate) fn parse(value: String) -> Self {
935 match value.as_str() {
936 "vip" => Self::Vip,
937 "dnsrr" => Self::Dnsrr,
938 _ => Self::Other(value),
939 }
940 }
941
942 #[must_use]
944 pub const fn is_documented(&self) -> bool {
945 matches!(self, Self::Vip | Self::Dnsrr)
946 }
947}
948
949#[derive(Debug, Clone, PartialEq, Eq)]
951#[non_exhaustive]
952pub enum DeployMode {
953 Global,
955 Replicated,
957 Other(String),
959}
960
961impl DeployMode {
962 pub(crate) fn parse(value: String) -> Self {
963 match value.as_str() {
964 "global" => Self::Global,
965 "replicated" => Self::Replicated,
966 _ => Self::Other(value),
967 }
968 }
969
970 #[must_use]
972 pub const fn is_documented(&self) -> bool {
973 matches!(self, Self::Global | Self::Replicated)
974 }
975}
976
977#[derive(Debug, Clone, PartialEq, Eq)]
979#[non_exhaustive]
980pub enum DeployReplicas {
981 YamlNumber(String),
983 String(String),
985}
986
987#[derive(Debug, Clone, PartialEq, Eq)]
989pub struct DeployResources {
990 span: SourceSpan,
991 limits: Option<Box<DeployResourceLimits>>,
992 reservations: Option<Box<DeployResourceReservations>>,
993 extension_fields: Vec<FieldReference>,
994 unknown_fields: Vec<FieldReference>,
995}
996
997impl DeployResources {
998 pub(super) const fn new(span: SourceSpan) -> Self {
999 Self {
1000 span,
1001 limits: None,
1002 reservations: None,
1003 extension_fields: Vec::new(),
1004 unknown_fields: Vec::new(),
1005 }
1006 }
1007
1008 pub(super) fn set_limits(&mut self, limits: DeployResourceLimits) {
1009 self.limits = Some(Box::new(limits));
1010 }
1011
1012 pub(super) fn set_reservations(&mut self, reservations: DeployResourceReservations) {
1013 self.reservations = Some(Box::new(reservations));
1014 }
1015
1016 pub(super) fn push_extension(&mut self, value: FieldReference) {
1017 self.extension_fields.push(value);
1018 }
1019
1020 pub(super) fn push_unknown(&mut self, value: FieldReference) {
1021 self.unknown_fields.push(value);
1022 }
1023
1024 #[must_use]
1026 pub const fn span(&self) -> SourceSpan {
1027 self.span
1028 }
1029
1030 #[must_use]
1032 pub fn limits(&self) -> Option<&DeployResourceLimits> {
1033 self.limits.as_deref()
1034 }
1035
1036 #[must_use]
1038 pub fn reservations(&self) -> Option<&DeployResourceReservations> {
1039 self.reservations.as_deref()
1040 }
1041
1042 #[must_use]
1044 pub fn extension_fields(&self) -> &[FieldReference] {
1045 &self.extension_fields
1046 }
1047
1048 #[must_use]
1050 pub fn unknown_fields(&self) -> &[FieldReference] {
1051 &self.unknown_fields
1052 }
1053}
1054
1055#[derive(Debug, Clone, PartialEq, Eq)]
1057pub struct DeployResourceReservations {
1058 span: SourceSpan,
1059 cpus: Option<Located<DeployResourceCpus>>,
1060 memory: Option<Located<DeployResourceMemory>>,
1061 generic_resources: Option<DeployGenericResources>,
1062 devices: Option<DeployReservationDevices>,
1063 extension_fields: Vec<FieldReference>,
1064 unknown_fields: Vec<FieldReference>,
1065}
1066
1067impl DeployResourceReservations {
1068 pub(super) const fn new(span: SourceSpan) -> Self {
1069 Self {
1070 span,
1071 cpus: None,
1072 memory: None,
1073 generic_resources: None,
1074 devices: None,
1075 extension_fields: Vec::new(),
1076 unknown_fields: Vec::new(),
1077 }
1078 }
1079
1080 pub(super) fn set_cpus(&mut self, cpus: Located<DeployResourceCpus>) {
1081 self.cpus = Some(cpus);
1082 }
1083
1084 pub(super) fn set_memory(&mut self, memory: Located<DeployResourceMemory>) {
1085 self.memory = Some(memory);
1086 }
1087
1088 pub(super) fn set_generic_resources(&mut self, generic_resources: DeployGenericResources) {
1089 self.generic_resources = Some(generic_resources);
1090 }
1091
1092 pub(super) fn set_devices(&mut self, devices: DeployReservationDevices) {
1093 self.devices = Some(devices);
1094 }
1095
1096 pub(super) fn push_extension(&mut self, value: FieldReference) {
1097 self.extension_fields.push(value);
1098 }
1099
1100 pub(super) fn push_unknown(&mut self, value: FieldReference) {
1101 self.unknown_fields.push(value);
1102 }
1103
1104 #[must_use]
1106 pub const fn span(&self) -> SourceSpan {
1107 self.span
1108 }
1109
1110 #[must_use]
1112 pub const fn cpus(&self) -> Option<&Located<DeployResourceCpus>> {
1113 self.cpus.as_ref()
1114 }
1115
1116 #[must_use]
1118 pub const fn memory(&self) -> Option<&Located<DeployResourceMemory>> {
1119 self.memory.as_ref()
1120 }
1121
1122 #[must_use]
1124 pub const fn generic_resources(&self) -> Option<&DeployGenericResources> {
1125 self.generic_resources.as_ref()
1126 }
1127
1128 #[must_use]
1130 pub const fn devices(&self) -> Option<&DeployReservationDevices> {
1131 self.devices.as_ref()
1132 }
1133
1134 #[must_use]
1136 pub fn extension_fields(&self) -> &[FieldReference] {
1137 &self.extension_fields
1138 }
1139
1140 #[must_use]
1142 pub fn unknown_fields(&self) -> &[FieldReference] {
1143 &self.unknown_fields
1144 }
1145}
1146
1147#[derive(Debug, Clone, PartialEq, Eq)]
1149pub struct DeployReservationDevices {
1150 span: SourceSpan,
1151 items: Vec<DeployReservationDevice>,
1152}
1153
1154impl DeployReservationDevices {
1155 pub(super) const fn new(span: SourceSpan, items: Vec<DeployReservationDevice>) -> Self {
1156 Self { span, items }
1157 }
1158
1159 #[must_use]
1161 pub const fn span(&self) -> SourceSpan {
1162 self.span
1163 }
1164
1165 #[must_use]
1167 pub fn items(&self) -> &[DeployReservationDevice] {
1168 &self.items
1169 }
1170}
1171
1172#[derive(Debug, Clone, PartialEq, Eq)]
1174pub struct DeployReservationDevice {
1175 span: SourceSpan,
1176 form: DeployReservationDeviceForm,
1177 capabilities: Option<DeployReservationDeviceCapabilities>,
1178 driver: Option<Located<String>>,
1179 count: Option<Located<DeployReservationDeviceCount>>,
1180 device_ids: Option<DeployReservationDeviceIds>,
1181 options: Option<DeployReservationDeviceOptions>,
1182 extension_fields: Vec<FieldReference>,
1183 unknown_fields: Vec<FieldReference>,
1184}
1185
1186impl DeployReservationDevice {
1187 pub(super) fn new(span: SourceSpan) -> Self {
1188 Self {
1189 span,
1190 form: DeployReservationDeviceForm::Mapping,
1191 capabilities: None,
1192 driver: None,
1193 count: None,
1194 device_ids: None,
1195 options: None,
1196 extension_fields: Vec::new(),
1197 unknown_fields: Vec::new(),
1198 }
1199 }
1200
1201 pub(super) fn unmodeled(span: SourceSpan) -> Self {
1202 Self {
1203 span,
1204 form: DeployReservationDeviceForm::Unmodeled,
1205 capabilities: None,
1206 driver: None,
1207 count: None,
1208 device_ids: None,
1209 options: None,
1210 extension_fields: Vec::new(),
1211 unknown_fields: Vec::new(),
1212 }
1213 }
1214
1215 pub(super) fn set_capabilities(&mut self, capabilities: DeployReservationDeviceCapabilities) {
1216 self.capabilities = Some(capabilities);
1217 }
1218
1219 pub(super) fn set_driver(&mut self, driver: Located<String>) {
1220 self.driver = Some(driver);
1221 }
1222
1223 pub(super) fn set_count(&mut self, count: Located<DeployReservationDeviceCount>) {
1224 self.count = Some(count);
1225 }
1226
1227 pub(super) fn set_device_ids(&mut self, device_ids: DeployReservationDeviceIds) {
1228 self.device_ids = Some(device_ids);
1229 }
1230
1231 pub(super) fn set_options(&mut self, options: DeployReservationDeviceOptions) {
1232 self.options = Some(options);
1233 }
1234
1235 pub(super) fn push_extension(&mut self, value: FieldReference) {
1236 self.extension_fields.push(value);
1237 }
1238
1239 pub(super) fn push_unknown(&mut self, value: FieldReference) {
1240 self.unknown_fields.push(value);
1241 }
1242
1243 #[must_use]
1245 pub const fn span(&self) -> SourceSpan {
1246 self.span
1247 }
1248
1249 #[must_use]
1251 pub const fn form(&self) -> DeployReservationDeviceForm {
1252 self.form
1253 }
1254
1255 #[must_use]
1257 pub const fn capabilities(&self) -> Option<&DeployReservationDeviceCapabilities> {
1258 self.capabilities.as_ref()
1259 }
1260
1261 #[must_use]
1263 pub const fn driver(&self) -> Option<&Located<String>> {
1264 self.driver.as_ref()
1265 }
1266
1267 #[must_use]
1269 pub const fn count(&self) -> Option<&Located<DeployReservationDeviceCount>> {
1270 self.count.as_ref()
1271 }
1272
1273 #[must_use]
1275 pub const fn device_ids(&self) -> Option<&DeployReservationDeviceIds> {
1276 self.device_ids.as_ref()
1277 }
1278
1279 #[must_use]
1281 pub const fn options(&self) -> Option<&DeployReservationDeviceOptions> {
1282 self.options.as_ref()
1283 }
1284
1285 #[must_use]
1287 pub fn extension_fields(&self) -> &[FieldReference] {
1288 &self.extension_fields
1289 }
1290
1291 #[must_use]
1293 pub fn unknown_fields(&self) -> &[FieldReference] {
1294 &self.unknown_fields
1295 }
1296}
1297
1298#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1300#[non_exhaustive]
1301pub enum DeployReservationDeviceForm {
1302 Mapping,
1304 Unmodeled,
1306}
1307
1308#[derive(Debug, Clone, PartialEq, Eq)]
1310#[non_exhaustive]
1311pub enum DeployReservationDeviceCount {
1312 YamlInteger(String),
1314 String(String),
1316}
1317
1318#[derive(Debug, Clone, PartialEq, Eq)]
1320pub struct DeployReservationDeviceIds {
1321 span: SourceSpan,
1322 items: Vec<DeployReservationDeviceId>,
1323}
1324
1325impl DeployReservationDeviceIds {
1326 pub(super) const fn new(span: SourceSpan, items: Vec<DeployReservationDeviceId>) -> Self {
1327 Self { span, items }
1328 }
1329
1330 #[must_use]
1332 pub const fn span(&self) -> SourceSpan {
1333 self.span
1334 }
1335
1336 #[must_use]
1338 pub fn items(&self) -> &[DeployReservationDeviceId] {
1339 &self.items
1340 }
1341}
1342
1343#[derive(Debug, Clone, PartialEq, Eq)]
1345pub struct DeployReservationDeviceId {
1346 span: SourceSpan,
1347 form: DeployReservationDeviceIdForm,
1348 value: Option<Located<String>>,
1349}
1350
1351impl DeployReservationDeviceId {
1352 pub(super) fn string(value: Located<String>) -> Self {
1353 Self {
1354 span: value.span(),
1355 form: DeployReservationDeviceIdForm::String,
1356 value: Some(value),
1357 }
1358 }
1359
1360 pub(super) const fn unmodeled(span: SourceSpan) -> Self {
1361 Self {
1362 span,
1363 form: DeployReservationDeviceIdForm::Unmodeled,
1364 value: None,
1365 }
1366 }
1367
1368 #[must_use]
1370 pub const fn span(&self) -> SourceSpan {
1371 self.span
1372 }
1373
1374 #[must_use]
1376 pub const fn form(&self) -> DeployReservationDeviceIdForm {
1377 self.form
1378 }
1379
1380 #[must_use]
1382 pub const fn value(&self) -> Option<&Located<String>> {
1383 self.value.as_ref()
1384 }
1385}
1386
1387#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1389#[non_exhaustive]
1390pub enum DeployReservationDeviceIdForm {
1391 String,
1393 Unmodeled,
1395}
1396
1397#[derive(Debug, Clone, PartialEq, Eq)]
1399#[non_exhaustive]
1400pub enum DeployReservationDeviceOptions {
1401 Map {
1403 span: SourceSpan,
1405 entries: Vec<KeyValueEntry>,
1407 unmodeled_entries: Vec<FieldReference>,
1409 },
1410 List {
1412 span: SourceSpan,
1414 items: Vec<DeployReservationDeviceOptionItem>,
1416 },
1417}
1418
1419impl DeployReservationDeviceOptions {
1420 #[must_use]
1422 pub const fn span(&self) -> SourceSpan {
1423 match self {
1424 Self::Map { span, .. } | Self::List { span, .. } => *span,
1425 }
1426 }
1427
1428 #[must_use]
1430 pub fn as_map(&self) -> Option<&[KeyValueEntry]> {
1431 let Self::Map { entries, .. } = self else { return None };
1432 Some(entries)
1433 }
1434
1435 #[must_use]
1437 pub fn unmodeled_entries(&self) -> Option<&[FieldReference]> {
1438 let Self::Map { unmodeled_entries, .. } = self else {
1439 return None;
1440 };
1441 Some(unmodeled_entries)
1442 }
1443
1444 #[must_use]
1446 pub fn as_list(&self) -> Option<&[DeployReservationDeviceOptionItem]> {
1447 let Self::List { items, .. } = self else { return None };
1448 Some(items)
1449 }
1450}
1451
1452#[derive(Debug, Clone, PartialEq, Eq)]
1454pub struct DeployReservationDeviceOptionItem {
1455 span: SourceSpan,
1456 form: DeployReservationDeviceOptionItemForm,
1457 value: Option<Located<String>>,
1458}
1459
1460impl DeployReservationDeviceOptionItem {
1461 pub(super) fn string(value: Located<String>) -> Self {
1462 Self {
1463 span: value.span(),
1464 form: DeployReservationDeviceOptionItemForm::String,
1465 value: Some(value),
1466 }
1467 }
1468 pub(super) const fn unmodeled(span: SourceSpan) -> Self {
1469 Self {
1470 span,
1471 form: DeployReservationDeviceOptionItemForm::Unmodeled,
1472 value: None,
1473 }
1474 }
1475 #[must_use]
1477 pub const fn span(&self) -> SourceSpan {
1478 self.span
1479 }
1480 #[must_use]
1482 pub const fn form(&self) -> DeployReservationDeviceOptionItemForm {
1483 self.form
1484 }
1485 #[must_use]
1487 pub const fn value(&self) -> Option<&Located<String>> {
1488 self.value.as_ref()
1489 }
1490}
1491
1492#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1494#[non_exhaustive]
1495pub enum DeployReservationDeviceOptionItemForm {
1496 String,
1498 Unmodeled,
1500}
1501
1502#[derive(Debug, Clone, PartialEq, Eq)]
1504pub struct DeployReservationDeviceCapabilities {
1505 span: SourceSpan,
1506 items: Vec<DeployReservationDeviceCapability>,
1507}
1508
1509impl DeployReservationDeviceCapabilities {
1510 pub(super) const fn new(span: SourceSpan, items: Vec<DeployReservationDeviceCapability>) -> Self {
1511 Self { span, items }
1512 }
1513
1514 #[must_use]
1516 pub const fn span(&self) -> SourceSpan {
1517 self.span
1518 }
1519
1520 #[must_use]
1522 pub fn items(&self) -> &[DeployReservationDeviceCapability] {
1523 &self.items
1524 }
1525}
1526
1527#[derive(Debug, Clone, PartialEq, Eq)]
1529pub struct DeployReservationDeviceCapability {
1530 span: SourceSpan,
1531 form: DeployReservationDeviceCapabilityForm,
1532 value: Option<Located<String>>,
1533}
1534
1535impl DeployReservationDeviceCapability {
1536 pub(super) fn string(value: Located<String>) -> Self {
1537 Self {
1538 span: value.span(),
1539 form: DeployReservationDeviceCapabilityForm::String,
1540 value: Some(value),
1541 }
1542 }
1543
1544 pub(super) const fn unmodeled(span: SourceSpan) -> Self {
1545 Self {
1546 span,
1547 form: DeployReservationDeviceCapabilityForm::Unmodeled,
1548 value: None,
1549 }
1550 }
1551
1552 #[must_use]
1554 pub const fn span(&self) -> SourceSpan {
1555 self.span
1556 }
1557
1558 #[must_use]
1560 pub const fn form(&self) -> DeployReservationDeviceCapabilityForm {
1561 self.form
1562 }
1563
1564 #[must_use]
1566 pub const fn value(&self) -> Option<&Located<String>> {
1567 self.value.as_ref()
1568 }
1569}
1570
1571#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1573#[non_exhaustive]
1574pub enum DeployReservationDeviceCapabilityForm {
1575 String,
1577 Unmodeled,
1579}
1580
1581#[derive(Debug, Clone, PartialEq, Eq)]
1583pub struct DeployGenericResources {
1584 span: SourceSpan,
1585 items: Vec<DeployGenericResource>,
1586}
1587
1588impl DeployGenericResources {
1589 pub(super) const fn new(span: SourceSpan, items: Vec<DeployGenericResource>) -> Self {
1590 Self { span, items }
1591 }
1592
1593 #[must_use]
1595 pub const fn span(&self) -> SourceSpan {
1596 self.span
1597 }
1598
1599 #[must_use]
1601 pub fn items(&self) -> &[DeployGenericResource] {
1602 &self.items
1603 }
1604}
1605
1606#[derive(Debug, Clone, PartialEq, Eq)]
1608pub struct DeployGenericResource {
1609 span: SourceSpan,
1610 form: DeployGenericResourceForm,
1611 discrete_resource_spec: Option<DeployDiscreteResourceSpec>,
1612 extension_fields: Vec<FieldReference>,
1613 unknown_fields: Vec<FieldReference>,
1614}
1615
1616impl DeployGenericResource {
1617 pub(super) fn new(span: SourceSpan) -> Self {
1618 Self {
1619 span,
1620 form: DeployGenericResourceForm::Mapping,
1621 discrete_resource_spec: None,
1622 extension_fields: Vec::new(),
1623 unknown_fields: Vec::new(),
1624 }
1625 }
1626 pub(super) fn unmodeled(span: SourceSpan) -> Self {
1627 Self {
1628 span,
1629 form: DeployGenericResourceForm::Unmodeled,
1630 discrete_resource_spec: None,
1631 extension_fields: Vec::new(),
1632 unknown_fields: Vec::new(),
1633 }
1634 }
1635 pub(super) fn set_discrete_resource_spec(&mut self, value: DeployDiscreteResourceSpec) {
1636 self.discrete_resource_spec = Some(value);
1637 }
1638 pub(super) fn push_extension(&mut self, value: FieldReference) {
1639 self.extension_fields.push(value);
1640 }
1641 pub(super) fn push_unknown(&mut self, value: FieldReference) {
1642 self.unknown_fields.push(value);
1643 }
1644 #[must_use]
1646 pub const fn span(&self) -> SourceSpan {
1647 self.span
1648 }
1649 #[must_use]
1651 pub const fn form(&self) -> DeployGenericResourceForm {
1652 self.form
1653 }
1654 #[must_use]
1656 pub const fn discrete_resource_spec(&self) -> Option<&DeployDiscreteResourceSpec> {
1657 self.discrete_resource_spec.as_ref()
1658 }
1659 #[must_use]
1661 pub fn extension_fields(&self) -> &[FieldReference] {
1662 &self.extension_fields
1663 }
1664 #[must_use]
1666 pub fn unknown_fields(&self) -> &[FieldReference] {
1667 &self.unknown_fields
1668 }
1669}
1670
1671#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1673#[non_exhaustive]
1674pub enum DeployGenericResourceForm {
1675 Mapping,
1677 Unmodeled,
1679}
1680
1681#[derive(Debug, Clone, PartialEq, Eq)]
1683pub struct DeployDiscreteResourceSpec {
1684 span: SourceSpan,
1685 kind: Option<Located<String>>,
1686 value: Option<Located<DeployDiscreteResourceValue>>,
1687 extension_fields: Vec<FieldReference>,
1688 unknown_fields: Vec<FieldReference>,
1689}
1690
1691impl DeployDiscreteResourceSpec {
1692 pub(super) fn new(span: SourceSpan) -> Self {
1693 Self {
1694 span,
1695 kind: None,
1696 value: None,
1697 extension_fields: Vec::new(),
1698 unknown_fields: Vec::new(),
1699 }
1700 }
1701 pub(super) fn set_kind(&mut self, value: Located<String>) {
1702 self.kind = Some(value);
1703 }
1704 pub(super) fn set_value(&mut self, value: Located<DeployDiscreteResourceValue>) {
1705 self.value = Some(value);
1706 }
1707 pub(super) fn push_extension(&mut self, value: FieldReference) {
1708 self.extension_fields.push(value);
1709 }
1710 pub(super) fn push_unknown(&mut self, value: FieldReference) {
1711 self.unknown_fields.push(value);
1712 }
1713 #[must_use]
1715 pub const fn span(&self) -> SourceSpan {
1716 self.span
1717 }
1718 #[must_use]
1720 pub const fn kind(&self) -> Option<&Located<String>> {
1721 self.kind.as_ref()
1722 }
1723 #[must_use]
1725 pub const fn value(&self) -> Option<&Located<DeployDiscreteResourceValue>> {
1726 self.value.as_ref()
1727 }
1728 #[must_use]
1730 pub fn extension_fields(&self) -> &[FieldReference] {
1731 &self.extension_fields
1732 }
1733 #[must_use]
1735 pub fn unknown_fields(&self) -> &[FieldReference] {
1736 &self.unknown_fields
1737 }
1738}
1739
1740#[derive(Debug, Clone, PartialEq, Eq)]
1742#[non_exhaustive]
1743pub enum DeployDiscreteResourceValue {
1744 YamlNumber(String),
1746 String(String),
1748}
1749
1750#[derive(Debug, Clone, PartialEq, Eq)]
1752pub struct DeployResourceLimits {
1753 span: SourceSpan,
1754 cpus: Option<Located<DeployResourceCpus>>,
1755 memory: Option<Located<DeployResourceMemory>>,
1756 pids: Option<Located<DeployResourcePids>>,
1757 extension_fields: Vec<FieldReference>,
1758 unknown_fields: Vec<FieldReference>,
1759}
1760
1761impl DeployResourceLimits {
1762 pub(super) const fn new(span: SourceSpan) -> Self {
1763 Self {
1764 span,
1765 cpus: None,
1766 memory: None,
1767 pids: None,
1768 extension_fields: Vec::new(),
1769 unknown_fields: Vec::new(),
1770 }
1771 }
1772
1773 pub(super) fn set_pids(&mut self, pids: Located<DeployResourcePids>) {
1774 self.pids = Some(pids);
1775 }
1776
1777 pub(super) fn set_cpus(&mut self, cpus: Located<DeployResourceCpus>) {
1778 self.cpus = Some(cpus);
1779 }
1780
1781 pub(super) fn set_memory(&mut self, memory: Located<DeployResourceMemory>) {
1782 self.memory = Some(memory);
1783 }
1784
1785 pub(super) fn push_extension(&mut self, value: FieldReference) {
1786 self.extension_fields.push(value);
1787 }
1788
1789 pub(super) fn push_unknown(&mut self, value: FieldReference) {
1790 self.unknown_fields.push(value);
1791 }
1792
1793 #[must_use]
1795 pub const fn span(&self) -> SourceSpan {
1796 self.span
1797 }
1798
1799 #[must_use]
1801 pub const fn pids(&self) -> Option<&Located<DeployResourcePids>> {
1802 self.pids.as_ref()
1803 }
1804
1805 #[must_use]
1807 pub const fn cpus(&self) -> Option<&Located<DeployResourceCpus>> {
1808 self.cpus.as_ref()
1809 }
1810
1811 #[must_use]
1813 pub const fn memory(&self) -> Option<&Located<DeployResourceMemory>> {
1814 self.memory.as_ref()
1815 }
1816
1817 #[must_use]
1819 pub fn extension_fields(&self) -> &[FieldReference] {
1820 &self.extension_fields
1821 }
1822
1823 #[must_use]
1825 pub fn unknown_fields(&self) -> &[FieldReference] {
1826 &self.unknown_fields
1827 }
1828}
1829
1830#[derive(Debug, Clone, PartialEq, Eq)]
1832#[non_exhaustive]
1833pub enum DeployResourcePids {
1834 YamlInteger(String),
1836 String(String),
1838}
1839
1840#[derive(Debug, Clone, PartialEq, Eq)]
1842#[non_exhaustive]
1843pub enum DeployResourceCpus {
1844 YamlNumber(String),
1846 String(String),
1848}
1849
1850#[derive(Debug, Clone, PartialEq, Eq)]
1852pub struct DeployResourceMemory {
1853 raw: String,
1854 kind: DeployResourceMemoryKind,
1855}
1856
1857impl DeployResourceMemory {
1858 pub(crate) fn parse(raw: String) -> Self {
1859 let kind = if raw.contains('$') {
1860 DeployResourceMemoryKind::Expression
1861 } else if let Some((amount_raw, unit)) = split_deploy_resource_memory_unit(&raw) {
1862 if deploy_resource_memory_lexical_zero(amount_raw) {
1863 DeployResourceMemoryKind::Zero {
1864 amount_raw: amount_raw.to_owned(),
1865 unit: Some(unit),
1866 }
1867 } else {
1868 DeployResourceMemoryKind::Documented {
1869 amount_raw: amount_raw.to_owned(),
1870 unit,
1871 }
1872 }
1873 } else if deploy_resource_memory_lexical_zero(&raw) {
1874 DeployResourceMemoryKind::Zero {
1875 amount_raw: raw.clone(),
1876 unit: None,
1877 }
1878 } else {
1879 DeployResourceMemoryKind::ProviderDependentString
1880 };
1881 Self { raw, kind }
1882 }
1883
1884 #[must_use]
1886 pub fn raw(&self) -> &str {
1887 &self.raw
1888 }
1889
1890 #[must_use]
1892 pub const fn kind(&self) -> &DeployResourceMemoryKind {
1893 &self.kind
1894 }
1895}
1896
1897#[derive(Debug, Clone, PartialEq, Eq)]
1899#[non_exhaustive]
1900pub enum DeployResourceMemoryKind {
1901 Documented {
1903 amount_raw: String,
1905 unit: DeployResourceMemoryUnit,
1907 },
1908 Zero {
1910 amount_raw: String,
1912 unit: Option<DeployResourceMemoryUnit>,
1914 },
1915 Expression,
1917 ProviderDependentString,
1919}
1920
1921#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1923#[non_exhaustive]
1924pub enum DeployResourceMemoryUnit {
1925 B,
1927 K,
1929 Kb,
1931 M,
1933 Mb,
1935 G,
1937 Gb,
1939}
1940
1941impl DeployResourceMemoryUnit {
1942 #[must_use]
1944 pub const fn as_str(self) -> &'static str {
1945 match self {
1946 Self::B => "b",
1947 Self::K => "k",
1948 Self::Kb => "kb",
1949 Self::M => "m",
1950 Self::Mb => "mb",
1951 Self::G => "g",
1952 Self::Gb => "gb",
1953 }
1954 }
1955}
1956
1957fn split_deploy_resource_memory_unit(value: &str) -> Option<(&str, DeployResourceMemoryUnit)> {
1958 for (suffix, unit) in [
1959 ("kb", DeployResourceMemoryUnit::Kb),
1960 ("mb", DeployResourceMemoryUnit::Mb),
1961 ("gb", DeployResourceMemoryUnit::Gb),
1962 ("b", DeployResourceMemoryUnit::B),
1963 ("k", DeployResourceMemoryUnit::K),
1964 ("m", DeployResourceMemoryUnit::M),
1965 ("g", DeployResourceMemoryUnit::G),
1966 ] {
1967 if let Some(amount) = value.strip_suffix(suffix) {
1968 if !amount.is_empty() {
1969 return Some((amount, unit));
1970 }
1971 }
1972 }
1973 None
1974}
1975
1976fn deploy_resource_memory_lexical_zero(value: &str) -> bool {
1977 !value.is_empty() && value.bytes().all(|byte| byte == b'0')
1978}
1979
1980#[derive(Debug, Clone, PartialEq, Eq)]
1982pub struct DeployRestartPolicy {
1983 span: SourceSpan,
1984 condition: Option<Located<DeployRestartCondition>>,
1985 delay: Option<Located<DeployRestartDuration>>,
1986 max_attempts: Option<Located<DeployRestartMaxAttempts>>,
1987 window: Option<Located<DeployRestartDuration>>,
1988 extension_fields: Vec<FieldReference>,
1989 unknown_fields: Vec<FieldReference>,
1990}
1991
1992impl DeployRestartPolicy {
1993 pub(super) const fn new(span: SourceSpan) -> Self {
1994 Self {
1995 span,
1996 condition: None,
1997 delay: None,
1998 max_attempts: None,
1999 window: None,
2000 extension_fields: Vec::new(),
2001 unknown_fields: Vec::new(),
2002 }
2003 }
2004 pub(super) fn set_condition(&mut self, value: Located<DeployRestartCondition>) {
2005 self.condition = Some(value);
2006 }
2007 pub(super) fn set_delay(&mut self, value: Located<DeployRestartDuration>) {
2008 self.delay = Some(value);
2009 }
2010 pub(super) fn set_max_attempts(&mut self, value: Located<DeployRestartMaxAttempts>) {
2011 self.max_attempts = Some(value);
2012 }
2013 pub(super) fn set_window(&mut self, value: Located<DeployRestartDuration>) {
2014 self.window = Some(value);
2015 }
2016 pub(super) fn push_extension(&mut self, value: FieldReference) {
2017 self.extension_fields.push(value);
2018 }
2019 pub(super) fn push_unknown(&mut self, value: FieldReference) {
2020 self.unknown_fields.push(value);
2021 }
2022 #[must_use]
2024 pub const fn span(&self) -> SourceSpan {
2025 self.span
2026 }
2027 #[must_use]
2029 pub const fn condition(&self) -> Option<&Located<DeployRestartCondition>> {
2030 self.condition.as_ref()
2031 }
2032 #[must_use]
2034 pub const fn delay(&self) -> Option<&Located<DeployRestartDuration>> {
2035 self.delay.as_ref()
2036 }
2037 #[must_use]
2039 pub const fn max_attempts(&self) -> Option<&Located<DeployRestartMaxAttempts>> {
2040 self.max_attempts.as_ref()
2041 }
2042 #[must_use]
2044 pub const fn window(&self) -> Option<&Located<DeployRestartDuration>> {
2045 self.window.as_ref()
2046 }
2047 #[must_use]
2049 pub fn extension_fields(&self) -> &[FieldReference] {
2050 &self.extension_fields
2051 }
2052 #[must_use]
2054 pub fn unknown_fields(&self) -> &[FieldReference] {
2055 &self.unknown_fields
2056 }
2057}
2058
2059#[derive(Debug, Clone, PartialEq, Eq)]
2061#[non_exhaustive]
2062pub enum DeployRestartCondition {
2063 None,
2065 OnFailure,
2067 Any,
2069 Expression(String),
2071 Other(String),
2073}
2074impl DeployRestartCondition {
2075 pub(crate) fn parse(value: String) -> Self {
2076 match value.as_str() {
2077 "none" => Self::None,
2078 "on-failure" => Self::OnFailure,
2079 "any" => Self::Any,
2080 _ if value.contains('$') => Self::Expression(value),
2081 _ => Self::Other(value),
2082 }
2083 }
2084}
2085
2086#[derive(Debug, Clone, PartialEq, Eq)]
2088pub struct DeployRestartDuration(String);
2089impl DeployRestartDuration {
2090 pub(crate) const fn new(value: String) -> Self {
2091 Self(value)
2092 }
2093 #[must_use]
2095 pub fn raw(&self) -> &str {
2096 &self.0
2097 }
2098}
2099
2100#[derive(Debug, Clone, PartialEq, Eq)]
2102#[non_exhaustive]
2103pub enum DeployRestartMaxAttempts {
2104 YamlNumber(String),
2106 String(String),
2108}
2109
2110#[derive(Debug, Clone, PartialEq, Eq)]
2112pub struct DeployRollbackConfig {
2113 span: SourceSpan,
2114 parallelism: Option<Located<DeployRollbackParallelism>>,
2115 delay: Option<Located<String>>,
2116 monitor: Option<Located<String>>,
2117 failure_action: Option<Located<String>>,
2118 max_failure_ratio: Option<Located<DeployRollbackMaxFailureRatio>>,
2119 order: Option<Located<DeployRollbackOrder>>,
2120 extension_fields: Vec<FieldReference>,
2121 unknown_fields: Vec<FieldReference>,
2122}
2123impl DeployRollbackConfig {
2124 pub(super) const fn new(span: SourceSpan) -> Self {
2125 Self {
2126 span,
2127 parallelism: None,
2128 delay: None,
2129 monitor: None,
2130 failure_action: None,
2131 max_failure_ratio: None,
2132 order: None,
2133 extension_fields: Vec::new(),
2134 unknown_fields: Vec::new(),
2135 }
2136 }
2137 pub(super) fn set_parallelism(&mut self, value: Located<DeployRollbackParallelism>) {
2138 self.parallelism = Some(value);
2139 }
2140 pub(super) fn set_delay(&mut self, value: Located<String>) {
2141 self.delay = Some(value);
2142 }
2143 pub(super) fn set_monitor(&mut self, value: Located<String>) {
2144 self.monitor = Some(value);
2145 }
2146 pub(super) fn set_failure_action(&mut self, value: Located<String>) {
2147 self.failure_action = Some(value);
2148 }
2149 pub(super) fn set_max_failure_ratio(&mut self, value: Located<DeployRollbackMaxFailureRatio>) {
2150 self.max_failure_ratio = Some(value);
2151 }
2152 pub(super) fn set_order(&mut self, value: Located<DeployRollbackOrder>) {
2153 self.order = Some(value);
2154 }
2155 pub(super) fn push_extension(&mut self, value: FieldReference) {
2156 self.extension_fields.push(value);
2157 }
2158 pub(super) fn push_unknown(&mut self, value: FieldReference) {
2159 self.unknown_fields.push(value);
2160 }
2161 #[must_use]
2163 pub const fn span(&self) -> SourceSpan {
2164 self.span
2165 }
2166 #[must_use]
2168 pub const fn parallelism(&self) -> Option<&Located<DeployRollbackParallelism>> {
2169 self.parallelism.as_ref()
2170 }
2171 #[must_use]
2173 pub const fn delay(&self) -> Option<&Located<String>> {
2174 self.delay.as_ref()
2175 }
2176 #[must_use]
2178 pub const fn monitor(&self) -> Option<&Located<String>> {
2179 self.monitor.as_ref()
2180 }
2181 #[must_use]
2183 pub const fn failure_action(&self) -> Option<&Located<String>> {
2184 self.failure_action.as_ref()
2185 }
2186 #[must_use]
2188 pub const fn max_failure_ratio(&self) -> Option<&Located<DeployRollbackMaxFailureRatio>> {
2189 self.max_failure_ratio.as_ref()
2190 }
2191 #[must_use]
2193 pub const fn order(&self) -> Option<&Located<DeployRollbackOrder>> {
2194 self.order.as_ref()
2195 }
2196 #[must_use]
2198 pub fn extension_fields(&self) -> &[FieldReference] {
2199 &self.extension_fields
2200 }
2201 #[must_use]
2203 pub fn unknown_fields(&self) -> &[FieldReference] {
2204 &self.unknown_fields
2205 }
2206}
2207#[derive(Debug, Clone, PartialEq, Eq)]
2209#[non_exhaustive]
2210pub enum DeployRollbackParallelism {
2211 YamlInteger(String),
2213 String(String),
2215}
2216#[derive(Debug, Clone, PartialEq, Eq)]
2218#[non_exhaustive]
2219pub enum DeployRollbackMaxFailureRatio {
2220 YamlNumber(String),
2222 String(String),
2224}
2225#[derive(Debug, Clone, PartialEq, Eq)]
2227#[non_exhaustive]
2228pub enum DeployRollbackOrder {
2229 StopFirst,
2231 StartFirst,
2233 Other(String),
2235}
2236impl DeployRollbackOrder {
2237 pub(crate) fn parse(value: String) -> Self {
2238 match value.as_str() {
2239 "stop-first" => Self::StopFirst,
2240 "start-first" => Self::StartFirst,
2241 _ => Self::Other(value),
2242 }
2243 }
2244 pub(crate) const fn is_documented(&self) -> bool {
2245 matches!(self, Self::StopFirst | Self::StartFirst)
2246 }
2247}
2248
2249#[derive(Debug, Clone, PartialEq, Eq)]
2251pub struct DeployUpdateConfig {
2252 span: SourceSpan,
2253 parallelism: Option<Located<DeployUpdateParallelism>>,
2254 delay: Option<Located<String>>,
2255 monitor: Option<Located<String>>,
2256 failure_action: Option<Located<String>>,
2257 max_failure_ratio: Option<Located<DeployUpdateMaxFailureRatio>>,
2258 order: Option<Located<DeployUpdateOrder>>,
2259 extension_fields: Vec<FieldReference>,
2260 unknown_fields: Vec<FieldReference>,
2261}
2262impl DeployUpdateConfig {
2263 pub(super) const fn new(span: SourceSpan) -> Self {
2264 Self {
2265 span,
2266 parallelism: None,
2267 delay: None,
2268 monitor: None,
2269 failure_action: None,
2270 max_failure_ratio: None,
2271 order: None,
2272 extension_fields: Vec::new(),
2273 unknown_fields: Vec::new(),
2274 }
2275 }
2276 pub(super) fn set_parallelism(&mut self, value: Located<DeployUpdateParallelism>) {
2277 self.parallelism = Some(value);
2278 }
2279 pub(super) fn set_delay(&mut self, value: Located<String>) {
2280 self.delay = Some(value);
2281 }
2282 pub(super) fn set_monitor(&mut self, value: Located<String>) {
2283 self.monitor = Some(value);
2284 }
2285 pub(super) fn set_failure_action(&mut self, value: Located<String>) {
2286 self.failure_action = Some(value);
2287 }
2288 pub(super) fn set_max_failure_ratio(&mut self, value: Located<DeployUpdateMaxFailureRatio>) {
2289 self.max_failure_ratio = Some(value);
2290 }
2291 pub(super) fn set_order(&mut self, value: Located<DeployUpdateOrder>) {
2292 self.order = Some(value);
2293 }
2294 pub(super) fn push_extension(&mut self, value: FieldReference) {
2295 self.extension_fields.push(value);
2296 }
2297 pub(super) fn push_unknown(&mut self, value: FieldReference) {
2298 self.unknown_fields.push(value);
2299 }
2300 #[must_use]
2302 pub const fn span(&self) -> SourceSpan {
2303 self.span
2304 }
2305 #[must_use]
2307 pub const fn parallelism(&self) -> Option<&Located<DeployUpdateParallelism>> {
2308 self.parallelism.as_ref()
2309 }
2310 #[must_use]
2312 pub const fn delay(&self) -> Option<&Located<String>> {
2313 self.delay.as_ref()
2314 }
2315 #[must_use]
2317 pub const fn monitor(&self) -> Option<&Located<String>> {
2318 self.monitor.as_ref()
2319 }
2320 #[must_use]
2322 pub const fn failure_action(&self) -> Option<&Located<String>> {
2323 self.failure_action.as_ref()
2324 }
2325 #[must_use]
2327 pub const fn max_failure_ratio(&self) -> Option<&Located<DeployUpdateMaxFailureRatio>> {
2328 self.max_failure_ratio.as_ref()
2329 }
2330 #[must_use]
2332 pub const fn order(&self) -> Option<&Located<DeployUpdateOrder>> {
2333 self.order.as_ref()
2334 }
2335 #[must_use]
2337 pub fn extension_fields(&self) -> &[FieldReference] {
2338 &self.extension_fields
2339 }
2340 #[must_use]
2342 pub fn unknown_fields(&self) -> &[FieldReference] {
2343 &self.unknown_fields
2344 }
2345}
2346#[derive(Debug, Clone, PartialEq, Eq)]
2348#[non_exhaustive]
2349pub enum DeployUpdateParallelism {
2350 YamlInteger(String),
2352 String(String),
2354}
2355#[derive(Debug, Clone, PartialEq, Eq)]
2357#[non_exhaustive]
2358pub enum DeployUpdateMaxFailureRatio {
2359 YamlNumber(String),
2361 String(String),
2363}
2364#[derive(Debug, Clone, PartialEq, Eq)]
2366#[non_exhaustive]
2367pub enum DeployUpdateOrder {
2368 StopFirst,
2370 StartFirst,
2372 Other(String),
2374}
2375impl DeployUpdateOrder {
2376 pub(crate) fn parse(value: String) -> Self {
2377 match value.as_str() {
2378 "stop-first" => Self::StopFirst,
2379 "start-first" => Self::StartFirst,
2380 _ => Self::Other(value),
2381 }
2382 }
2383 pub(crate) const fn is_documented(&self) -> bool {
2384 matches!(self, Self::StopFirst | Self::StartFirst)
2385 }
2386}
2387
2388#[derive(Debug, Clone, PartialEq, Eq)]
2390pub struct DeployPlacement {
2391 span: SourceSpan,
2392 constraints: Option<Vec<Located<String>>>,
2393 preferences: Option<Vec<DeployPlacementPreference>>,
2394 max_replicas_per_node: Option<Located<DeployPlacementMaxReplicasPerNode>>,
2395 extension_fields: Vec<FieldReference>,
2396 unknown_fields: Vec<FieldReference>,
2397}
2398
2399impl DeployPlacement {
2400 pub(super) const fn new(span: SourceSpan) -> Self {
2401 Self {
2402 span,
2403 constraints: None,
2404 preferences: None,
2405 max_replicas_per_node: None,
2406 extension_fields: Vec::new(),
2407 unknown_fields: Vec::new(),
2408 }
2409 }
2410
2411 pub(super) fn set_constraints(&mut self, constraints: Vec<Located<String>>) {
2412 self.constraints = Some(constraints);
2413 }
2414
2415 pub(super) fn set_preferences(&mut self, preferences: Vec<DeployPlacementPreference>) {
2416 self.preferences = Some(preferences);
2417 }
2418
2419 pub(super) fn set_max_replicas_per_node(&mut self, value: Located<DeployPlacementMaxReplicasPerNode>) {
2420 self.max_replicas_per_node = Some(value);
2421 }
2422
2423 pub(super) fn push_extension(&mut self, value: FieldReference) {
2424 self.extension_fields.push(value);
2425 }
2426
2427 pub(super) fn push_unknown(&mut self, value: FieldReference) {
2428 self.unknown_fields.push(value);
2429 }
2430
2431 #[must_use]
2433 pub const fn span(&self) -> SourceSpan {
2434 self.span
2435 }
2436
2437 #[must_use]
2439 pub fn constraints(&self) -> Option<&[Located<String>]> {
2440 self.constraints.as_deref()
2441 }
2442
2443 #[must_use]
2445 pub fn preferences(&self) -> Option<&[DeployPlacementPreference]> {
2446 self.preferences.as_deref()
2447 }
2448
2449 #[must_use]
2451 pub const fn max_replicas_per_node(&self) -> Option<&Located<DeployPlacementMaxReplicasPerNode>> {
2452 self.max_replicas_per_node.as_ref()
2453 }
2454
2455 #[must_use]
2457 pub fn extension_fields(&self) -> &[FieldReference] {
2458 &self.extension_fields
2459 }
2460
2461 #[must_use]
2463 pub fn unknown_fields(&self) -> &[FieldReference] {
2464 &self.unknown_fields
2465 }
2466}
2467
2468#[derive(Debug, Clone, PartialEq, Eq)]
2470pub struct DeployPlacementPreference {
2471 span: SourceSpan,
2472 spread: Option<Located<String>>,
2473 extension_fields: Vec<FieldReference>,
2474 unknown_fields: Vec<FieldReference>,
2475}
2476
2477impl DeployPlacementPreference {
2478 pub(super) const fn new(span: SourceSpan) -> Self {
2479 Self {
2480 span,
2481 spread: None,
2482 extension_fields: Vec::new(),
2483 unknown_fields: Vec::new(),
2484 }
2485 }
2486
2487 pub(super) fn set_spread(&mut self, spread: Located<String>) {
2488 self.spread = Some(spread);
2489 }
2490
2491 pub(super) fn push_extension(&mut self, value: FieldReference) {
2492 self.extension_fields.push(value);
2493 }
2494
2495 pub(super) fn push_unknown(&mut self, value: FieldReference) {
2496 self.unknown_fields.push(value);
2497 }
2498
2499 #[must_use]
2501 pub const fn span(&self) -> SourceSpan {
2502 self.span
2503 }
2504
2505 #[must_use]
2507 pub const fn spread(&self) -> Option<&Located<String>> {
2508 self.spread.as_ref()
2509 }
2510
2511 #[must_use]
2513 pub fn extension_fields(&self) -> &[FieldReference] {
2514 &self.extension_fields
2515 }
2516
2517 #[must_use]
2519 pub fn unknown_fields(&self) -> &[FieldReference] {
2520 &self.unknown_fields
2521 }
2522}
2523
2524#[derive(Debug, Clone, PartialEq, Eq)]
2526#[non_exhaustive]
2527pub enum DeployPlacementMaxReplicasPerNode {
2528 YamlInteger(String),
2530 String(String),
2532}
2533
2534#[derive(Debug, Clone, PartialEq, Eq)]
2536pub struct DeployField {
2537 kind: DeployFieldKind,
2538 reference: FieldReference,
2539}
2540
2541impl DeployField {
2542 pub(super) const fn new(kind: DeployFieldKind, reference: FieldReference) -> Self {
2543 Self { kind, reference }
2544 }
2545
2546 #[must_use]
2548 pub const fn kind(&self) -> DeployFieldKind {
2549 self.kind
2550 }
2551
2552 #[must_use]
2554 pub const fn reference(&self) -> &FieldReference {
2555 &self.reference
2556 }
2557}
2558
2559#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2561#[non_exhaustive]
2562pub enum DeployFieldKind {
2563 EndpointMode,
2565 Labels,
2567 Mode,
2569 Placement,
2571 Replicas,
2573 Resources,
2575 RestartPolicy,
2577 RollbackConfig,
2579 UpdateConfig,
2581}
2582
2583impl DeployFieldKind {
2584 pub(super) fn from_name(name: &str) -> Option<Self> {
2585 Some(match name {
2586 "endpoint_mode" => Self::EndpointMode,
2587 "labels" => Self::Labels,
2588 "mode" => Self::Mode,
2589 "placement" => Self::Placement,
2590 "replicas" => Self::Replicas,
2591 "resources" => Self::Resources,
2592 "restart_policy" => Self::RestartPolicy,
2593 "rollback_config" => Self::RollbackConfig,
2594 "update_config" => Self::UpdateConfig,
2595 _ => return None,
2596 })
2597 }
2598}