Skip to content

Commit

Permalink
chore(azure): Adding a verifyAccountHealth configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
christosarvanitis committed Oct 21, 2024
1 parent 32106c5 commit 6e364f8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class AzureResourceManagerClient extends AzureBaseClient {
} catch (Exception e) {
// Something went wrong. log the exception
log.error("Unable to register Azure Provider: ${namespace}", e)
throw e
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package com.netflix.spinnaker.clouddriver.azure.config
import com.netflix.spinnaker.clouddriver.azure.resources.vmimage.model.AzureCustomImageStorage
import com.netflix.spinnaker.clouddriver.azure.resources.vmimage.model.AzureVMImage
import com.netflix.spinnaker.fiat.model.resources.Permissions
import groovy.transform.Canonical
import groovy.transform.ToString
import org.springframework.boot.context.properties.NestedConfigurationProperty

class AzureConfigurationProperties {

Expand All @@ -42,4 +44,16 @@ class AzureConfigurationProperties {
}

List<ManagedAccount> accounts = []
/**
* health check related config settings
*/
@Canonical
static class HealthConfig {
/**
* flag to toggle verifying account health check. by default, account health check is enabled.
*/
boolean verifyAccountHealth = true
}
@NestedConfigurationProperty
final HealthConfig health = new HealthConfig()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.netflix.spinnaker.clouddriver.azure.health

import com.netflix.spinnaker.clouddriver.azure.config.AzureConfigurationProperties
import com.netflix.spinnaker.clouddriver.azure.security.AzureNamedAccountCredentials
import com.netflix.spinnaker.clouddriver.security.AccountCredentialsProvider
import groovy.transform.CompileStatic
Expand All @@ -41,6 +42,9 @@ class AzureHealthIndicator implements HealthIndicator {
@Autowired
AccountCredentialsProvider accountCredentialsProvider

@Autowired
AzureConfigurationProperties azureConfigurationProperties

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

@Override
Expand All @@ -57,6 +61,8 @@ class AzureHealthIndicator implements HealthIndicator {
@Scheduled(fixedDelay = 300000L)
void checkHealth() {
try {
if (azureConfigurationProperties.getHealth().getVerifyAccountHealth()) {
LOG.info("azure.health.verifyAccountHealth flag is enabled - verifying connection to the Azure accounts")
Set<AzureNamedAccountCredentials> azureCredentialsSet = accountCredentialsProvider.all.findAll {
it instanceof AzureNamedAccountCredentials
} as Set<AzureNamedAccountCredentials>
Expand All @@ -73,7 +79,9 @@ class AzureHealthIndicator implements HealthIndicator {
throw new AzureIOException(e)
}
}

} else {
LOG.info("azure.health.verifyAccountHealth flag is disabled - Not verifying connection to the Azure accounts");
}
lastException.set(null)
} catch (Exception ex) {
LOG.warn "Unhealthy", ex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import com.netflix.spinnaker.clouddriver.azure.client.AzureComputeClient
import com.netflix.spinnaker.clouddriver.azure.client.AzureNetworkClient
import com.netflix.spinnaker.clouddriver.azure.client.AzureResourceManagerClient
import com.netflix.spinnaker.clouddriver.azure.client.AzureStorageClient
import groovy.util.logging.Slf4j

@Slf4j
class AzureCredentials {

final String tenantId
Expand Down Expand Up @@ -63,7 +65,12 @@ class AzureCredentials {

storageClient = new AzureStorageClient(this.subscriptionId, token, azureProfile)

registerProviders()
try {
registerProviders()
} catch (Exception e) {
log.error("Failed to register providers with AzureResourceManagerClient", e)
throw e
}
}

/**
Expand Down

0 comments on commit 6e364f8

Please sign in to comment.