mz_cloud_resources/crd/
vpc_endpoint.rs1use std::fmt;
13
14use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition;
15use kube::CustomResource;
16use schemars::JsonSchema;
17use serde::{Deserialize, Serialize};
18
19pub mod v1 {
20 use super::*;
21
22 #[derive(CustomResource, Clone, Debug, Default, Deserialize, Serialize, JsonSchema)]
24 #[serde(rename_all = "camelCase")]
25 #[kube(
26 group = "materialize.cloud",
27 version = "v1",
28 kind = "VpcEndpoint",
29 singular = "vpcendpoint",
30 plural = "vpcendpoints",
31 shortname = "vpce",
32 namespaced,
33 status = "VpcEndpointStatus",
34 printcolumn = r#"{"name": "AwsServiceName", "type": "string", "description": "Name of the VPC Endpoint Service to connect to.", "jsonPath": ".spec.awsServiceName", "priority": 1}"#,
35 printcolumn = r#"{"name": "AvailabilityZoneIDs", "type": "string", "description": "Availability Zone IDs", "jsonPath": ".spec.availabilityZoneIds", "priority": 1}"#
36 )]
37 pub struct VpcEndpointSpec {
41 pub aws_service_name: String,
43 pub availability_zone_ids: Vec<String>,
45 pub role_suffix: String,
47 }
48
49 #[derive(Clone, Debug, Default, Deserialize, Serialize, JsonSchema, PartialEq)]
50 #[serde(rename_all = "camelCase")]
51 pub struct VpcEndpointStatus {
52 pub vpc_endpoint_id: Option<String>,
55 pub state: Option<VpcEndpointState>,
56 pub conditions: Option<Vec<Condition>>,
57 }
58
59 #[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
60 #[serde(rename_all = "camelCase")]
61 pub enum VpcEndpointState {
62 PendingServiceDiscovery,
64 CreatingEndpoint,
65 RecreatingEndpoint,
66 UpdatingEndpoint,
67
68 Available,
71 Deleted,
72 Deleting,
73 Expired,
74 Failed,
75 Pending,
77 PendingAcceptance,
79 Rejected,
80 Unknown,
81 }
82
83 impl fmt::Display for VpcEndpointState {
84 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
85 let repr = match self {
86 VpcEndpointState::PendingServiceDiscovery => "pending-service-discovery",
87 VpcEndpointState::CreatingEndpoint => "creating-endpoint",
88 VpcEndpointState::RecreatingEndpoint => "recreating-endpoint",
89 VpcEndpointState::UpdatingEndpoint => "updating-endpoint",
90 VpcEndpointState::Available => "available",
91 VpcEndpointState::Deleted => "deleted",
92 VpcEndpointState::Deleting => "deleting",
93 VpcEndpointState::Expired => "expired",
94 VpcEndpointState::Failed => "failed",
95 VpcEndpointState::Pending => "pending",
96 VpcEndpointState::PendingAcceptance => "pending-acceptance",
97 VpcEndpointState::Rejected => "rejected",
98 VpcEndpointState::Unknown => "unknown",
99 };
100 write!(f, "{}", repr)
101 }
102 }
103}
104
105#[cfg(test)]
106mod tests {
107 use std::fs;
108
109 use kube::CustomResourceExt;
110 use kube::core::crd::merge_crds;
111
112 #[mz_ore::test]
113 fn test_vpc_endpoint_crd_matches() {
114 let crd = merge_crds(vec![super::v1::VpcEndpoint::crd()], "v1").unwrap();
115 let crd_json = serde_json::to_string(&serde_json::json!(&crd)).unwrap();
116 let exported_crd_json = fs::read_to_string("src/crd/generated/vpcendpoints.json").unwrap();
117 let exported_crd_json = exported_crd_json.trim();
118 assert_eq!(
119 &crd_json, exported_crd_json,
120 "VpcEndpoint CRD json does not match exported json.\n\nCRD:\n{}\n\nExported CRD:\n{}",
121 &crd_json, exported_crd_json,
122 );
123 }
124}