1
1
use std:: path:: PathBuf ;
2
+ use std:: time:: Duration ;
2
3
3
4
use anyhow:: { anyhow, bail, Context , Error , Ok , Result } ;
4
5
use itertools:: Itertools ;
5
6
use minijinja;
6
7
use simplelog:: * ;
8
+ use tokio:: time:: timeout;
7
9
8
10
use crate :: builder:: BuildResult ;
9
- use crate :: clients:: { apply_manifest_yaml, kube_client} ;
11
+ use crate :: clients:: { apply_manifest_yaml, kube_client, wait_for_status } ;
10
12
use crate :: configparser:: challenge:: ExposeType ;
11
13
use crate :: configparser:: config:: ProfileConfig ;
12
14
use crate :: configparser:: { get_config, get_profile_config, ChallengeConfig } ;
@@ -78,9 +80,17 @@ async fn deploy_single_challenge(
78
80
trace ! ( "NAMESPACE:\n {}" , ns_manifest) ;
79
81
80
82
debug ! ( "applying namespace for chal {:?}" , chal. directory) ;
81
- apply_manifest_yaml ( & kube, & ns_manifest) . await ?;
82
83
83
- let expose_results = DeployResult { exposed : vec ! [ ] } ;
84
+ // apply namespace manifest
85
+ apply_manifest_yaml ( & kube, & ns_manifest)
86
+ . await ?
87
+ . iter ( )
88
+ // and then wait for it to be ready
89
+ . map ( |object| wait_for_status ( & kube, object) )
90
+ . try_join_all ( )
91
+ . await ?;
92
+
93
+ let results = DeployResult { exposed : vec ! [ ] } ;
84
94
85
95
for pod in & chal. pods {
86
96
let pod_image = chal. container_tag_for_pod ( profile_name, & pod. name ) ?;
@@ -94,7 +104,26 @@ async fn deploy_single_challenge(
94
104
"applying deployment for chal {:?} pod {:?}" ,
95
105
chal. directory, pod. name
96
106
) ;
97
- apply_manifest_yaml ( & kube, & depl_manifest) . await ?;
107
+ let depl = apply_manifest_yaml ( & kube, & depl_manifest) . await ?;
108
+ for object in depl {
109
+ // wait for objects to be ready, with 5m timeout
110
+ timeout ( Duration :: from_secs ( 5 * 60 ) , wait_for_status ( & kube, & object) )
111
+ . await
112
+ // timeout wraps with another Result
113
+ . with_context ( || {
114
+ format ! (
115
+ "timed out waiting for chal {:?} pod {:?} deployment to become ready" ,
116
+ chal. directory, pod. name
117
+ )
118
+ } ) ?
119
+ // inner result from wait_for_status
120
+ . with_context ( || {
121
+ format ! (
122
+ "failed to get status for chal {:?} pod {:?} deployment" ,
123
+ chal. directory, pod. name
124
+ )
125
+ } ) ?;
126
+ }
98
127
99
128
// tcp and http exposes need to he handled separately, so separate them by type
100
129
let ( tcp_ports, http_ports) : ( Vec < _ > , Vec < _ > ) = pod
@@ -113,7 +142,26 @@ async fn deploy_single_challenge(
113
142
"applying tcp service for chal {:?} pod {:?}" ,
114
143
chal. directory, pod. name
115
144
) ;
116
- apply_manifest_yaml ( & kube, & tcp_manifest) . await ?;
145
+ let tcp = apply_manifest_yaml ( & kube, & tcp_manifest) . await ?;
146
+ for object in tcp {
147
+ // wait for objects to be ready, with 5m timeout
148
+ timeout ( Duration :: from_secs ( 5 * 60 ) , wait_for_status ( & kube, & object) )
149
+ . await
150
+ // timeout wraps with another Result
151
+ . with_context ( || {
152
+ format ! (
153
+ "timed out waiting for chal {:?} pod {:?} exposed TCP service to become ready" ,
154
+ chal. directory, pod. name
155
+ )
156
+ } ) ?
157
+ // inner result from wait_for_status
158
+ . with_context ( || {
159
+ format ! (
160
+ "failed to get status for chal {:?} pod {:?} exposed TCP service" ,
161
+ chal. directory, pod. name
162
+ )
163
+ } ) ?;
164
+ }
117
165
118
166
// TODO:
119
167
// expose_results.exposed.push(PodDeployResult::Tcp { port: tcp_ports[0]. });
@@ -130,11 +178,30 @@ async fn deploy_single_challenge(
130
178
"applying http service and ingress for chal {:?} pod {:?}" ,
131
179
chal. directory, pod. name
132
180
) ;
133
- apply_manifest_yaml ( & kube, & http_manifest) . await ?;
181
+ let ingress = apply_manifest_yaml ( & kube, & http_manifest) . await ?;
182
+ for object in ingress {
183
+ // wait for objects to be ready, with 5m timeout
184
+ timeout ( Duration :: from_secs ( 5 * 60 ) , wait_for_status ( & kube, & object) )
185
+ . await
186
+ // timeout wraps with another Result
187
+ . with_context ( || {
188
+ format ! (
189
+ "timed out waiting for chal {:?} pod {:?} ingress to become ready" ,
190
+ chal. directory, pod. name
191
+ )
192
+ } ) ?
193
+ // inner result from wait_for_status
194
+ . with_context ( || {
195
+ format ! (
196
+ "failed to get status for chal {:?} pod {:?} ingress" ,
197
+ chal. directory, pod. name
198
+ )
199
+ } ) ?;
200
+ }
134
201
}
135
202
}
136
203
137
- Ok ( expose_results )
204
+ Ok ( results )
138
205
}
139
206
140
207
// Updates the current ingress controller chart with the current set of TCP
0 commit comments