|
16 | 16 |
|
17 | 17 | package org.springframework.cloud.kubernetes.profile;
|
18 | 18 |
|
| 19 | +import io.fabric8.kubernetes.client.DefaultKubernetesClient; |
19 | 20 | import org.apache.commons.logging.Log;
|
20 | 21 | import org.apache.commons.logging.LogFactory;
|
21 | 22 |
|
22 |
| -import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; |
23 |
| -import org.springframework.cloud.kubernetes.PodUtils; |
24 |
| -import org.springframework.context.ApplicationListener; |
| 23 | +import org.springframework.boot.SpringApplication; |
| 24 | +import org.springframework.boot.context.config.ConfigFileApplicationListener; |
| 25 | +import org.springframework.boot.env.EnvironmentPostProcessor; |
| 26 | +import org.springframework.cloud.kubernetes.StandardPodUtils; |
25 | 27 | import org.springframework.core.Ordered;
|
26 | 28 | import org.springframework.core.env.ConfigurableEnvironment;
|
27 | 29 | import org.springframework.core.env.Environment;
|
28 | 30 |
|
29 |
| -/** |
30 |
| - * Adds Kubernetes profiles. |
31 |
| - * |
32 |
| - * @author Ioannis Canellos |
33 |
| - */ |
34 |
| -public class KubernetesProfileApplicationListener |
35 |
| - implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered { |
| 31 | +public class KubernetesProfileEnvironmentPostProcessor |
| 32 | + implements EnvironmentPostProcessor, Ordered { |
36 | 33 |
|
37 | 34 | private static final Log LOG = LogFactory
|
38 |
| - .getLog(KubernetesProfileApplicationListener.class); |
39 |
| - |
40 |
| - private static final String KUBERNETES_PROFILE = "kubernetes"; |
41 |
| - |
42 |
| - private static final int OFFSET = 1; |
| 35 | + .getLog(KubernetesProfileEnvironmentPostProcessor.class); |
43 | 36 |
|
44 |
| - private static final int ORDER = Ordered.HIGHEST_PRECEDENCE + OFFSET; |
| 37 | + // Before ConfigFileApplicationListener so values there can use these ones |
| 38 | + private static final int ORDER = ConfigFileApplicationListener.DEFAULT_ORDER - 1; |
45 | 39 |
|
46 |
| - private final PodUtils utils; |
47 |
| - |
48 |
| - public KubernetesProfileApplicationListener(PodUtils utils) { |
49 |
| - this.utils = utils; |
50 |
| - } |
| 40 | + private static final String KUBERNETES_PROFILE = "kubernetes"; |
51 | 41 |
|
52 | 42 | @Override
|
53 |
| - public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { |
54 |
| - ConfigurableEnvironment environment = event.getEnvironment(); |
55 |
| - addKubernetesProfile(environment); |
56 |
| - } |
57 |
| - |
58 |
| - void addKubernetesProfile(ConfigurableEnvironment environment) { |
59 |
| - if (this.utils.isInsideKubernetes()) { |
| 43 | + public void postProcessEnvironment(ConfigurableEnvironment environment, |
| 44 | + SpringApplication application) { |
| 45 | + final StandardPodUtils podUtils = new StandardPodUtils( |
| 46 | + new DefaultKubernetesClient()); |
| 47 | + if (podUtils.isInsideKubernetes()) { |
60 | 48 | if (hasKubernetesProfile(environment)) {
|
61 | 49 | if (LOG.isDebugEnabled()) {
|
62 | 50 | LOG.debug("'kubernetes' already in list of active profiles");
|
|
0 commit comments