Merge pull request #4456 from JoshVanL/vault-client-health-err-check

Vault internal client should check health conn err before checking response status
This commit is contained in:
jetstack-bot 2021-09-27 13:07:46 +01:00 committed by GitHub
commit 5a8b970c97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -383,13 +383,25 @@ func (v *Vault) IsVaultInitializedAndUnsealed() error {
healthURL := path.Join("/v1", "sys", "health")
healthRequest := v.client.NewRequest("GET", healthURL)
healthResp, err := v.client.RawRequest(healthRequest)
if healthResp != nil {
defer healthResp.Body.Close()
}
// 429 = if unsealed and standby
// 472 = if disaster recovery mode replication secondary and active
// 473 = if performance standby
if err != nil && healthResp.StatusCode != 429 && healthResp.StatusCode != 472 && healthResp.StatusCode != 473 {
return err
if err != nil {
switch {
case healthResp == nil:
return err
case healthResp.StatusCode == 429, healthResp.StatusCode == 472, healthResp.StatusCode == 473:
return nil
default:
return fmt.Errorf("error calling Vault %s: %w", healthURL, err)
}
}
defer healthResp.Body.Close()
return nil
}