Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip checking Vault health #8524

Merged
merged 4 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions nomad/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,22 +458,12 @@ func (v *vaultClient) establishConnection() {
// Create the retry timer and set initial duration to zero so it fires
// immediately
retryTimer := time.NewTimer(0)
initStatus := false
OUTER:
for {
select {
case <-v.tomb.Dying():
return
case <-retryTimer.C:
// Ensure the API is reachable
if !initStatus {
if _, err := v.clientSys.Sys().InitStatus(); err != nil {
v.logger.Warn("failed to contact Vault API", "retry", v.config.ConnectionRetryIntv, "error", err)
retryTimer.Reset(v.config.ConnectionRetryIntv)
continue OUTER
}
initStatus = true
}
// Retry validating the token till success
if err := v.parseSelfToken(); err != nil {
v.logger.Error("failed to validate self token/role", "retry", v.config.ConnectionRetryIntv, "error", err)
Expand Down Expand Up @@ -1239,7 +1229,7 @@ func (v *vaultClient) revokeDaemon() {
case <-v.tomb.Dying():
return
case now := <-ticker.C:
if established, _ := v.ConnectionEstablished(); !established {
if established, err := v.ConnectionEstablished(); !established || err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code here was introduced in 42f7bc8#diff-87a4c76eca3de54716c55ba6b8c06475 - where established is true only when there is no error. So checking error wasn't strictly necessary. After many modifications, this file consistently checks for established && err == nil, but we missed this spot.

For some reason, not so clear to me, #3957 chose to represent invalid tokens as established with true but non-nil error. It seems like we missed this spot.

continue
}

Expand Down
3 changes: 2 additions & 1 deletion nomad/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@ func TestVaultClient_LookupToken_RateLimit(t *testing.T) {

// Spin up many requests. These should block
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

cancels := 0
numRequests := 20
Expand All @@ -1028,7 +1029,7 @@ func TestVaultClient_LookupToken_RateLimit(t *testing.T) {
cancels += 1
return
}
t.Fatalf("self lookup failed: %v", err)
t.Errorf("self lookup failed: %v", err)
return
}

Expand Down