Skip to content

Commit ae02b62

Browse files
committed
Skeleton for returning deploy expose results in struct
Signed-off-by: Robert Detjens <[email protected]>
1 parent 10edf40 commit ae02b62

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

src/deploy/kubernetes/mod.rs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,22 @@ use crate::utils::TryJoinAll;
1414

1515
pub mod templates;
1616

17+
/// How and where a challenge was deployed/exposed at
18+
pub struct DeployResult {
19+
// challenges could have multiple exposed services
20+
pub exposed: Vec<PodDeployResult>,
21+
}
22+
23+
pub enum PodDeployResult {
24+
Http { domain: String },
25+
Tcp { port: usize },
26+
}
27+
1728
/// Render challenge manifest templates and apply to cluster
1829
pub async fn deploy_challenges(
1930
profile_name: &str,
2031
build_results: &[(&ChallengeConfig, BuildResult)],
21-
) -> Result<Vec<()>> {
32+
) -> Result<Vec<DeployResult>> {
2233
let profile = get_profile_config(profile_name)?;
2334

2435
// Kubernetes deployment needs to:
@@ -30,16 +41,29 @@ pub async fn deploy_challenges(
3041
//
3142
// 2. update ingress controller tcp ports
3243
//
33-
// 3. wait for all challenges to become ready (?)
44+
// 3. wait for all challenges to become ready
45+
//
46+
// 4. record domains and IPs of challenges to pass to frontend (?)
3447

35-
build_results
48+
let results = build_results
3649
.iter()
3750
.map(|(chal, _)| deploy_single_challenge(profile_name, chal))
3851
.try_join_all()
39-
.await
52+
.await?;
53+
54+
update_ingress_tcp().await?;
55+
56+
Ok(results)
4057
}
4158

42-
async fn deploy_single_challenge(profile_name: &str, chal: &ChallengeConfig) -> Result<()> {
59+
// Deploy all K8S resources for a single challenge `chal`.
60+
//
61+
// Creates the challenge namespace, deployments, services, and ingresses needed
62+
// to deploy and expose the challenge.
63+
async fn deploy_single_challenge(
64+
profile_name: &str,
65+
chal: &ChallengeConfig,
66+
) -> Result<DeployResult> {
4367
info!(" deploying chal {:?}...", chal.directory);
4468
// render templates
4569

@@ -56,6 +80,8 @@ async fn deploy_single_challenge(profile_name: &str, chal: &ChallengeConfig) ->
5680
debug!("applying namespace for chal {:?}", chal.directory);
5781
apply_manifest_yaml(&kube, &ns_manifest).await?;
5882

83+
let expose_results = DeployResult { exposed: vec![] };
84+
5985
for pod in &chal.pods {
6086
let pod_image = chal.container_tag_for_pod(profile_name, &pod.name)?;
6187
let depl_manifest = minijinja::render!(
@@ -88,6 +114,9 @@ async fn deploy_single_challenge(profile_name: &str, chal: &ChallengeConfig) ->
88114
chal.directory, pod.name
89115
);
90116
apply_manifest_yaml(&kube, &tcp_manifest).await?;
117+
118+
// TODO:
119+
// expose_results.exposed.push(PodDeployResult::Tcp { port: tcp_ports[0]. });
91120
}
92121

93122
if !http_ports.is_empty() {
@@ -105,5 +134,12 @@ async fn deploy_single_challenge(profile_name: &str, chal: &ChallengeConfig) ->
105134
}
106135
}
107136

137+
Ok(expose_results)
138+
}
139+
140+
// Updates the current ingress controller chart with the current set of TCP
141+
// ports needed for challenges.
142+
// TODO: move to Gateway to avoid needing to redeploy ingress?
143+
async fn update_ingress_tcp() -> Result<()> {
108144
Ok(())
109145
}

0 commit comments

Comments
 (0)