Skip to content

Commit

Permalink
Merge pull request #27 from xenit-eu/ACC-1547
Browse files Browse the repository at this point in the history
[ACC-1547] Add property that can be used to disable kubernetes configuration discovery
  • Loading branch information
vierbergenlars authored Aug 21, 2024
2 parents b991001 + 32b27cb commit d9e8a03
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ Configuration is automatically updated when changes are made in Kubernetes.

This module can be automatically configured when a `KubernetesClient` bean is available. (e.g. when using spring-cloud-kubernetes)

| Property | Type | Description |
|------------------------------------------------------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `contentgrid.configuration.discovery.kubernetes.namespace` | `string` | Sets the kubernetes namespace in which configuration discovery will be done. If unset, defaults to the namespace that the application is deployed in (or `default` if the application is running outside of Kubernetes) |
| Property | Type | Description |
|------------------------------------------------------------|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `contentgrid.configuration.discovery.kubernetes.enabled` | `boolean` | Enables configuration discovery through Kubernetes (default `true`) |
| `contentgrid.configuration.discovery.kubernetes.namespace` | `string` | Sets the kubernetes namespace in which configuration discovery will be done. If unset, defaults to the namespace that the application is deployed in (or `default` if the application is running outside of Kubernetes) |


Other configuration for the Kubernetes client should be done in [spring-cloud-kubernetes](https://docs.spring.io/spring-cloud-kubernetes/docs/current/reference/html/appendix.html), or a custom created `KubernetesClient`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration;
import org.springframework.context.annotation.Bean;
Expand All @@ -17,6 +18,7 @@
@ConditionalOnClass({KubernetesInformerObservableFactory.class, KubernetesClient.class})
@ConditionalOnBean(KubernetesClient.class)
@Import(KubernetesConfigurationMappingApplicationConfiguration.class)
@ConditionalOnProperty(value = "contentgrid.configuration.discovery.kubernetes.enabled", matchIfMissing = true)
public class ConfigurationDiscoveryKubernetesAutoConfiguration {

@Bean(name = "com.contentgrid.configuration.kubernetes.fabric8.KubernetesInformerObservableFactory")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ void discovers_withKubernetesClient() {
});
}

@Test
void doesNotActivate_propertyDisabled() {
contextRunner
.withBean(KubernetesClient.class, () -> {
return Mockito.mock(KubernetesClient.class, Mockito.RETURNS_MOCKS);
})
.withPropertyValues("contentgrid.configuration.discovery.kubernetes.enabled=false")
.run(context -> {
assertThat(context.getBeanProvider(APPLICATION_OBSERVABLE)).isEmpty();
});
}

@Test
void doesNotActivate_missingApplicationClass() {
contextRunner
Expand Down

0 comments on commit d9e8a03

Please sign in to comment.