@@ -14,11 +14,22 @@ use crate::utils::TryJoinAll;
14
14
15
15
pub mod templates;
16
16
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
+
17
28
/// Render challenge manifest templates and apply to cluster
18
29
pub async fn deploy_challenges (
19
30
profile_name : & str ,
20
31
build_results : & [ ( & ChallengeConfig , BuildResult ) ] ,
21
- ) -> Result < Vec < ( ) > > {
32
+ ) -> Result < Vec < DeployResult > > {
22
33
let profile = get_profile_config ( profile_name) ?;
23
34
24
35
// Kubernetes deployment needs to:
@@ -30,16 +41,29 @@ pub async fn deploy_challenges(
30
41
//
31
42
// 2. update ingress controller tcp ports
32
43
//
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 (?)
34
47
35
- build_results
48
+ let results = build_results
36
49
. iter ( )
37
50
. map ( |( chal, _) | deploy_single_challenge ( profile_name, chal) )
38
51
. try_join_all ( )
39
- . await
52
+ . await ?;
53
+
54
+ update_ingress_tcp ( ) . await ?;
55
+
56
+ Ok ( results)
40
57
}
41
58
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 > {
43
67
info ! ( " deploying chal {:?}..." , chal. directory) ;
44
68
// render templates
45
69
@@ -56,6 +80,8 @@ async fn deploy_single_challenge(profile_name: &str, chal: &ChallengeConfig) ->
56
80
debug ! ( "applying namespace for chal {:?}" , chal. directory) ;
57
81
apply_manifest_yaml ( & kube, & ns_manifest) . await ?;
58
82
83
+ let expose_results = DeployResult { exposed : vec ! [ ] } ;
84
+
59
85
for pod in & chal. pods {
60
86
let pod_image = chal. container_tag_for_pod ( profile_name, & pod. name ) ?;
61
87
let depl_manifest = minijinja:: render!(
@@ -88,6 +114,9 @@ async fn deploy_single_challenge(profile_name: &str, chal: &ChallengeConfig) ->
88
114
chal. directory, pod. name
89
115
) ;
90
116
apply_manifest_yaml ( & kube, & tcp_manifest) . await ?;
117
+
118
+ // TODO:
119
+ // expose_results.exposed.push(PodDeployResult::Tcp { port: tcp_ports[0]. });
91
120
}
92
121
93
122
if !http_ports. is_empty ( ) {
@@ -105,5 +134,12 @@ async fn deploy_single_challenge(profile_name: &str, chal: &ChallengeConfig) ->
105
134
}
106
135
}
107
136
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 < ( ) > {
108
144
Ok ( ( ) )
109
145
}
0 commit comments