Skip to content
This repository was archived by the owner on Oct 2, 2025. It is now read-only.

Commit 95d0e68

Browse files
mergify[bot]christosarvanitisjasonmcintosh
authored
fix(gcp): Relaxed health check for GCP accounts (backport #6200) (#6201)
* fix(gcp): Relaxed health check for GCP accounts (#6200) (cherry picked from commit 28599eb) # Conflicts: # clouddriver-google/src/main/groovy/com/netflix/spinnaker/clouddriver/google/health/GoogleHealthIndicator.groovy * fix: Fixes PR to match 1.28 versions of credential repository APIs --------- Co-authored-by: Christos Arvanitis <christos.arvanitis@armory.io> Co-authored-by: Jason McIntosh <jason.mcintosh@harness.io>
1 parent 860f4a4 commit 95d0e68

File tree

3 files changed

+65
-21
lines changed

3 files changed

+65
-21
lines changed

clouddriver-google/src/main/groovy/com/netflix/spinnaker/clouddriver/google/health/GoogleHealthIndicator.groovy

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.netflix.spinnaker.clouddriver.google.health
1818

1919
import com.netflix.spectator.api.Registry
2020
import com.netflix.spinnaker.clouddriver.google.GoogleExecutorTraits
21+
import com.netflix.spinnaker.clouddriver.google.config.GoogleConfigurationProperties
2122
import com.netflix.spinnaker.clouddriver.google.security.GoogleCredentials
2223
import com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials
2324
import com.netflix.spinnaker.clouddriver.security.AccountCredentialsProvider
@@ -47,6 +48,9 @@ class GoogleHealthIndicator implements HealthIndicator, GoogleExecutorTraits {
4748

4849
private final AtomicReference<Exception> lastException = new AtomicReference<>(null)
4950

51+
@Autowired
52+
GoogleConfigurationProperties googleConfigurationProperties
53+
5054
@Override
5155
Health health() {
5256
def ex = lastException.get()
@@ -61,21 +65,25 @@ class GoogleHealthIndicator implements HealthIndicator, GoogleExecutorTraits {
6165
@Scheduled(fixedDelay = 300000L)
6266
void checkHealth() {
6367
try {
64-
Set<GoogleNamedAccountCredentials> googleCredentialsSet = accountCredentialsProvider.all.findAll {
65-
it instanceof GoogleNamedAccountCredentials
66-
} as Set<GoogleNamedAccountCredentials>
67-
68-
for (GoogleNamedAccountCredentials accountCredentials in googleCredentialsSet) {
69-
try {
70-
// This verifies that the specified credentials are sufficient to access the referenced project.
71-
timeExecute(accountCredentials.compute.projects().get(accountCredentials.project),
72-
"compute.projects.get",
73-
TAG_SCOPE, SCOPE_GLOBAL)
74-
} catch (IOException e) {
75-
throw new GoogleIOException(e)
68+
if (googleConfigurationProperties.getHealth().getVerifyAccountHealth()) {
69+
LOG.info("google.health.verifyAccountHealth flag is enabled - verifying connection to the Google accounts")
70+
Set<GoogleNamedAccountCredentials> googleCredentialsSet = accountCredentialsProvider.all.findAll {
71+
it instanceof GoogleNamedAccountCredentials
72+
} as Set<GoogleNamedAccountCredentials>
73+
74+
for (GoogleNamedAccountCredentials accountCredentials in googleCredentialsSet) {
75+
try {
76+
// This verifies that the specified credentials are sufficient to access the referenced project.
77+
timeExecute(accountCredentials.compute.projects().get(accountCredentials.project),
78+
"compute.projects.get",
79+
TAG_SCOPE, SCOPE_GLOBAL)
80+
} catch (IOException e) {
81+
throw new GoogleIOException(e)
82+
}
7683
}
84+
} else {
85+
LOG.info("google.health.verifyAccountHealth flag is disabled - Not verifying connection to the Google accounts");
7786
}
78-
7987
lastException.set(null)
8088
} catch (Exception ex) {
8189
LOG.warn "Unhealthy", ex

clouddriver-google/src/main/groovy/com/netflix/spinnaker/config/GoogleConfiguration.groovy

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ class GoogleConfiguration {
4545
new GoogleConfigurationProperties()
4646
}
4747

48-
@Bean
49-
@ConditionalOnProperty("google.health.verifyAccountHealth")
50-
GoogleHealthIndicator googleHealthIndicator() {
51-
new GoogleHealthIndicator()
52-
}
53-
5448
@Bean
5549
GoogleOperationPoller googleOperationPoller() {
5650
new GoogleOperationPoller()

clouddriver-google/src/test/groovy/com/netflix/spinnaker/clouddriver/google/health/GoogleHealthIndicatorSpec.groovy

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableList
2121
import com.google.common.collect.ImmutableMap
2222
import com.netflix.spectator.api.NoopRegistry
2323
import com.netflix.spectator.api.Registry
24+
import com.netflix.spinnaker.clouddriver.google.config.GoogleConfigurationProperties
2425
import com.netflix.spinnaker.clouddriver.google.provider.agent.StubComputeFactory
2526
import com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials
2627
import com.netflix.spinnaker.clouddriver.security.DefaultAccountCredentialsProvider
@@ -62,7 +63,7 @@ class GoogleHealthIndicatorSpec extends Specification {
6263

6364
def accountCredentialsProvider = new DefaultAccountCredentialsProvider(credentialsRepository)
6465

65-
def indicator = new GoogleHealthIndicator()
66+
def indicator = new GoogleHealthIndicator(googleConfigurationProperties: new GoogleConfigurationProperties())
6667
indicator.registry = REGISTRY
6768
indicator.accountCredentialsProvider = accountCredentialsProvider
6869

@@ -101,7 +102,7 @@ class GoogleHealthIndicatorSpec extends Specification {
101102

102103
def accountCredentialsProvider = new DefaultAccountCredentialsProvider(credentialsRepository)
103104

104-
def indicator = new GoogleHealthIndicator()
105+
def indicator = new GoogleHealthIndicator(googleConfigurationProperties: new GoogleConfigurationProperties())
105106
indicator.registry = REGISTRY
106107
indicator.accountCredentialsProvider = accountCredentialsProvider
107108

@@ -114,4 +115,45 @@ class GoogleHealthIndicatorSpec extends Specification {
114115

115116
health == null
116117
}
118+
119+
@Unroll
120+
def "health succeeds when google is unreachable and verifyAccountHealth is false"() {
121+
setup:
122+
def project = new Project()
123+
project.setName(PROJECT)
124+
125+
def compute = new StubComputeFactory()
126+
.setProjects(project)
127+
.setProjectException(new IOException("Read timed out"))
128+
.create()
129+
130+
def googleNamedAccountCredentials =
131+
new GoogleNamedAccountCredentials.Builder()
132+
.project(PROJECT)
133+
.name(ACCOUNT_NAME)
134+
.compute(compute)
135+
.regionToZonesMap(ImmutableMap.of(REGION, ImmutableList.of(ZONE)))
136+
.build()
137+
138+
def credentials = [googleNamedAccountCredentials]
139+
def credentialsRepository = Stub(MapBackedAccountCredentialsRepository) {
140+
getAll() >> credentials
141+
}
142+
143+
def accountCredentialsProvider = new DefaultAccountCredentialsProvider(credentialsRepository)
144+
145+
146+
def indicator = new GoogleHealthIndicator(googleConfigurationProperties: new GoogleConfigurationProperties())
147+
indicator.googleConfigurationProperties.health.setVerifyAccountHealth(false)
148+
indicator.registry = REGISTRY
149+
150+
151+
when:
152+
indicator.checkHealth()
153+
def health = indicator.health()
154+
155+
then:
156+
health.status == Status.UP
157+
health.details.isEmpty()
158+
}
117159
}

0 commit comments

Comments
 (0)