/// generate statefulset spec from cluster spec
generate statefulset spec from cluster spec
generate statefulset spec from cluster spec
fn generate_stateful(
    spg_spec: &SpuGroupSpec,
    name: &str,
    group_svc_name: String,
    namespace: &str) -> StatefulSetSpec {
    let replicas = spg_spec.replicas;
    let spg_template = &spg_spec.template.spec;
    let mut public_port = ContainerPortSpec {
        container_port: spg_template.public_endpoint.as_ref().map(|t| t.port).unwrap_or(SPU_PUBLIC_PORT),
        ..Default::default()
    };
    public_port.name = Some("public".to_owned());
    let mut private_port = ContainerPortSpec {
        container_port: spg_template.private_endpoint.as_ref().map(|t|t.port).unwrap_or(SPU_PRIVATE_PORT),
        ..Default::default()
    };
    private_port.name = Some("private".to_owned());
    // storage is special because defaults are explicit.
    let storage = spg_spec.template.spec.storage.clone().unwrap_or_default();
    let size =  storage.size();
    let mut env = vec![
        Env::key_field_ref("SPU_INDEX", "metadata.name"),
        Env::key_value("FLV_SC_PRIVATE_HOST",&format!("flv-sc-internal.{}.svc.cluster.local",namespace)),
        Env::key_value("SPU_MIN", &format!("{}",spg_spec.min_id())),
        Env::key_value(FLV_LOG_BASE_DIR,&storage.log_dir()),
        Env::key_value(FLV_LOG_SIZE, &size)
    ];
    env.append(&mut spg_template.env.clone());
    let template = TemplateSpec {
        metadata: Some(TemplateMeta::default().set_labels(
            vec![
                ("app", SPU_DEFAULT_NAME),
                ("group",name)
            ])),
        spec: PodSpec {
            termination_grace_period_seconds: Some(10),
            containers: vec![ContainerSpec {
                name: SPU_DEFAULT_NAME.to_owned(),
                image: Some(find_spu_image()),
                ports: vec![public_port, private_port],
                volume_mounts: vec![VolumeMount {
                    name: "data".to_owned(),
                    mount_path: format!("/var/lib/{}/data", PRODUCT_NAME),
                    ..Default::default()
                }],
                env: Some(env),
                ..Default::default()
            }],
            ..Default::default()
        },
    };
    let claim = PersistentVolumeClaim {
        access_modes: vec![VolumeAccessMode::ReadWriteOnce],
        storage_class_name: format!("{}-{}", PRODUCT_NAME, SPU_DEFAULT_NAME),
        resources: ResourceRequirements {
            requests: VolumeRequest {
                storage: size
            },
        },
    };
    StatefulSetSpec {
        replicas: Some(replicas),
        service_name: group_svc_name,
        selector: LabelSelector::new_labels(vec![
            ("app", SPU_DEFAULT_NAME),
            ("group",name)
        ]),
        template,
        volume_claim_templates: vec![TemplateSpec {
            spec: claim,
            metadata: Some(TemplateMeta::named("data")),
        }],
        ..Default::default()
    }
}
fn generate_stateful ( spg_spec : & SpuGroupSpec , name : & str , group_svc_name : String , namespace : & str ) -> StatefulSetSpec { let replicas = spg_spec . replicas ; let spg_template = & spg_spec . template . spec ; let mut public_port = ContainerPortSpec { container_port : spg_template . public_endpoint . as_ref ( ) . map ( | t | t . port ) . unwrap_or ( SPU_PUBLIC_PORT ) , .. Default :: default ( ) } ; public_port . name = Some ( " " . to_owned ( ) ) ; let mut private_port = ContainerPortSpec { container_port : spg_template . private_endpoint . as_ref ( ) . map ( | t | t . port ) . unwrap_or ( SPU_PRIVATE_PORT ) , .. Default :: default ( ) } ; private_port . name = Some ( " " . to_owned ( ) ) ; // storage is special because defaults are explicit. let storage = spg_spec . template . spec . storage . clone ( ) . unwrap_or_default ( ) ; let size = storage . size ( ) ; let mut env = vec ! [ Env key_field_ref ( " " " " ) Env key_value ( " " format ( " " namespace ) ) Env key_value ( " " format ( " " spg_spec min_id ( ) ) ) Env key_value ( FLV_LOG_BASE_DIR storage log_dir ( ) ) Env key_value ( FLV_LOG_SIZE size ) ] ; env . append ( & mut spg_template . env . clone ( ) ) ; let template = TemplateSpec { metadata : Some ( TemplateMeta :: default ( ) . set_labels ( vec ! [ ( " " SPU_DEFAULT_NAME ) ( " " name ) ] ) ) , spec : PodSpec { termination_grace_period_seconds : Some ( 10 ) , containers : vec ! [ ContainerSpec { name SPU_DEFAULT_NAME to_owned ( ) image Some ( find_spu_image ( ) ) ports vec [ public_port private_port ] volume_mounts vec [ VolumeMount { name " " to_owned ( ) mount_path format ( " " PRODUCT_NAME ) Default default ( ) } ] env Some ( env ) Default default ( ) } ] , .. Default :: default ( ) } , } ; let claim = PersistentVolumeClaim { access_modes : vec ! [ VolumeAccessMode ReadWriteOnce ] , storage_class_name : format ! ( " " PRODUCT_NAME SPU_DEFAULT_NAME ) , resources : ResourceRequirements { requests : VolumeRequest { storage : size } , } , } ; StatefulSetSpec { replicas : Some ( replicas ) , service_name : group_svc_name , selector : LabelSelector :: new_labels ( vec ! [ ( " " SPU_DEFAULT_NAME ) ( " " name ) ] ) , template , volume_claim_templates : vec ! [ TemplateSpec { spec claim metadata Some ( TemplateMeta named ( " " ) ) } ] , .. Default :: default ( ) } }
generate statefulset spec from cluster spec
generate statefulset spec from cluster spec
spg_spec
&SpuGroupSpec
name
&str
group_svc_name
String
namespace
&str