Skip to main content

alien_core/
prepared_resources.rs

1//! Markers on the `default-network` and `kubernetes` resources the preflight mutations add.
2//!
3//! A generator that only sees the prepared stack needs to tell a resource the source stack
4//! declares (always expected) from one a mutation added because of the deployment's settings
5//! (expected only for the settings the module is applied with).
6
7use crate::ResourceEntry;
8
9/// Id of the network the network mutation adds.
10pub const PREPARED_NETWORK_ID: &str = "default-network";
11/// Display name of the network the network mutation adds.
12pub const PREPARED_NETWORK_DISPLAY_NAME: &str = "Network";
13/// Description of the network the network mutation adds.
14pub const PREPARED_NETWORK_DESCRIPTION: &str =
15    "Provides the network and subnet connections used by application resources.";
16
17/// Id of the cluster the Kubernetes cluster mutation adds.
18pub const PREPARED_CLUSTER_ID: &str = "kubernetes";
19/// Display name of the cluster the Kubernetes cluster mutation adds.
20pub const PREPARED_CLUSTER_DISPLAY_NAME: &str = "Kubernetes cluster";
21/// Description of the cluster the Kubernetes cluster mutation adds.
22pub const PREPARED_CLUSTER_DESCRIPTION: &str =
23    "Provides the Kubernetes cluster used by application workloads.";
24
25/// True for a `default-network` the network mutation added, false for one the stack declares.
26pub fn is_prepared_network(id: &str, entry: &ResourceEntry) -> bool {
27    id == PREPARED_NETWORK_ID
28        && entry.enabled_when.is_none()
29        && entry.display_name.as_deref() == Some(PREPARED_NETWORK_DISPLAY_NAME)
30        && entry.description.as_deref() == Some(PREPARED_NETWORK_DESCRIPTION)
31}
32
33/// True for a cluster the Kubernetes cluster mutation added, false for one the stack declares.
34pub fn is_prepared_cluster(id: &str, entry: &ResourceEntry) -> bool {
35    id == PREPARED_CLUSTER_ID
36        && entry.enabled_when.is_none()
37        && entry.display_name.as_deref() == Some(PREPARED_CLUSTER_DISPLAY_NAME)
38        && entry.description.as_deref() == Some(PREPARED_CLUSTER_DESCRIPTION)
39}