use std::fmt;
use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition;
use kube::CustomResource;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
pub mod v1 {
use super::*;
#[derive(CustomResource, Clone, Debug, Default, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
#[kube(
group = "materialize.cloud",
version = "v1",
kind = "VpcEndpoint",
singular = "vpcendpoint",
plural = "vpcendpoints",
shortname = "vpce",
namespaced,
status = "VpcEndpointStatus",
printcolumn = r#"{"name": "AwsServiceName", "type": "string", "description": "Name of the VPC Endpoint Service to connect to.", "jsonPath": ".spec.awsServiceName", "priority": 1}"#,
printcolumn = r#"{"name": "AvailabilityZoneIDs", "type": "string", "description": "Availability Zone IDs", "jsonPath": ".spec.availabilityZoneIds", "priority": 1}"#
)]
pub struct VpcEndpointSpec {
pub aws_service_name: String,
pub availability_zone_ids: Vec<String>,
pub role_suffix: String,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, JsonSchema, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct VpcEndpointStatus {
pub vpc_endpoint_id: Option<String>,
pub state: Option<VpcEndpointState>,
pub conditions: Option<Vec<Condition>>,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum VpcEndpointState {
PendingServiceDiscovery,
CreatingEndpoint,
RecreatingEndpoint,
UpdatingEndpoint,
Available,
Deleted,
Deleting,
Expired,
Failed,
Pending,
PendingAcceptance,
Rejected,
Unknown,
}
impl fmt::Display for VpcEndpointState {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let repr = match self {
VpcEndpointState::PendingServiceDiscovery => "pending-service-discovery",
VpcEndpointState::CreatingEndpoint => "creating-endpoint",
VpcEndpointState::RecreatingEndpoint => "recreating-endpoint",
VpcEndpointState::UpdatingEndpoint => "updating-endpoint",
VpcEndpointState::Available => "available",
VpcEndpointState::Deleted => "deleted",
VpcEndpointState::Deleting => "deleting",
VpcEndpointState::Expired => "expired",
VpcEndpointState::Failed => "failed",
VpcEndpointState::Pending => "pending",
VpcEndpointState::PendingAcceptance => "pending-acceptance",
VpcEndpointState::Rejected => "rejected",
VpcEndpointState::Unknown => "unknown",
};
write!(f, "{}", repr)
}
}
}
#[cfg(test)]
mod tests {
use std::fs;
use kube::core::crd::merge_crds;
use kube::CustomResourceExt;
#[mz_ore::test]
fn test_vpc_endpoint_crd_matches() {
let crd = merge_crds(vec![super::v1::VpcEndpoint::crd()], "v1").unwrap();
let crd_json = serde_json::to_string(&serde_json::json!(&crd)).unwrap();
let exported_crd_json = fs::read_to_string("src/crd/gen/vpcendpoints.json").unwrap();
let exported_crd_json = exported_crd_json.trim();
assert_eq!(
&crd_json, exported_crd_json,
"VpcEndpoint CRD json does not match exported json.\n\nCRD:\n{}\n\nExported CRD:\n{}",
&crd_json, exported_crd_json,
);
}
}