@@ -8,9 +8,9 @@ use tokio_retry::{
88use tracing:: * ;
99
1010use crate :: {
11- ExecIn , StepDown , Unseal , VaultVersion , VAULT_PORT ,
11+ is_active , is_pod_exporting_seal_status , ExecIn , StepDown , Unseal , VaultVersion , VAULT_PORT ,
1212 { is_pod_ready, is_pod_standby, is_pod_unsealed} , { is_seal_status_initialized, GetSealStatus } ,
13- { is_sealed, list_vault_pods, PodApi , StatefulSetApi , LABEL_KEY_VAULT_ACTIVE } ,
13+ { is_sealed, list_vault_pods, PodApi , StatefulSetApi } ,
1414} ;
1515
1616impl PodApi {
@@ -49,18 +49,7 @@ impl PodApi {
4949 // if Pod version is outdated (or upgrade is forced)
5050 if !Self :: is_current ( & pod, target) ? || force_upgrade {
5151 // if Pod is active
52- if pod
53- . metadata
54- . labels
55- . ok_or ( anyhow:: anyhow!( "pod does not have labels" ) ) ?
56- . get ( LABEL_KEY_VAULT_ACTIVE )
57- . ok_or ( anyhow:: anyhow!(
58- "pod does not have an {} label" ,
59- LABEL_KEY_VAULT_ACTIVE
60- ) ) ?
61- . as_str ( )
62- == "true"
63- {
52+ if is_active ( & pod) ? {
6453 // Step down active pod
6554 self . http ( name, VAULT_PORT ) . await ?. step_down ( token) . await ?;
6655
@@ -86,35 +75,45 @@ impl PodApi {
8675 anyhow:: anyhow!( "waiting for pod {} to be running: {}" , name, e. to_string( ) )
8776 } ) ?;
8877
89- let pod = self . api . get ( name ) . await ? ;
90-
91- let mut pf = Retry :: spawn (
92- ExponentialBackoff :: from_millis ( 50 ) . map ( jitter ) . take ( 5 ) ,
93- || async move { self . http ( name , VAULT_PORT ) . await } ,
78+ // Wait for pod to export its seal status
79+ kube :: runtime :: wait :: await_condition (
80+ self . api . clone ( ) ,
81+ name ,
82+ is_pod_exporting_seal_status ( ) ,
9483 )
95- . await
96- . map_err ( |e| {
97- anyhow:: anyhow!(
98- "attempting to forward http requests to {}: {}" ,
99- name,
100- e. to_string( )
101- )
102- } ) ?;
84+ . await ?;
10385
104- pf. await_seal_status ( is_seal_status_initialized ( ) )
105- . await
106- . map_err ( |e| {
107- anyhow:: anyhow!(
108- "waiting for pod to have required seal status {}: {}" ,
109- name,
110- e. to_string( )
111- )
112- } ) ?;
86+ // Refresh pod
87+ let pod = self . api . get ( name) . await ?;
11388
11489 if Self :: is_current ( & pod, target) ? {
11590 // Pod is sealed
11691 if is_sealed ( & pod) ? {
11792 if should_unseal {
93+ let mut pf = Retry :: spawn (
94+ ExponentialBackoff :: from_millis ( 50 ) . map ( jitter) . take ( 5 ) ,
95+ || async move { self . http ( name, VAULT_PORT ) . await } ,
96+ )
97+ . await
98+ . map_err ( |e| {
99+ anyhow:: anyhow!(
100+ "attempting to forward http requests to {}: {}" ,
101+ name,
102+ e. to_string( )
103+ )
104+ } ) ?;
105+
106+ // Wait for pod to have determined its seal status
107+ pf. await_seal_status ( is_seal_status_initialized ( ) )
108+ . await
109+ . map_err ( |e| {
110+ anyhow:: anyhow!(
111+ "waiting for pod to have required seal status {}: {}" ,
112+ name,
113+ e. to_string( )
114+ )
115+ } ) ?;
116+
118117 // Unseal pod
119118 pf. unseal ( keys) . await . map_err ( |e| {
120119 anyhow:: anyhow!( "unsealing pod {}: {}" , name, e. to_string( ) )
0 commit comments