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

KubernetesAutoConfiguration ignores client properties #78

Open
asarkar opened this issue Feb 2, 2017 · 3 comments
Open

KubernetesAutoConfiguration ignores client properties #78

asarkar opened this issue Feb 2, 2017 · 3 comments

Comments

@asarkar
Copy link

asarkar commented Feb 2, 2017

KubernetesAutoConfiguration depends on the injected KubernetesClientProperties but it seems that none of the properties are picked up and defaults are used. Thus the KubernetesClient is always created with default properties.
The workaround I'm doing right now is as follows but this is flies in the face of auto configuration.

@SpringBootApplication
@EnableConfigServer
@RestController
public class ConfigServerApp {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApp.class, args);
    }

    @Autowired
    KubernetesClientProperties k8sClientProperties;

    @Autowired
    Config k8sClientConfig;

    @RequestMapping(path = "/pods", produces = APPLICATION_JSON_UTF8_VALUE)
    public Collection<Pod> pods() {
        Config config = new Config();
        config.configFromSysPropsOrEnvVars(k8sClientConfig);
        config.setMasterUrl(k8sClientProperties.getMasterUrl());
        config.setNamespace(k8sClientProperties.getNamespace());

        KubernetesClient k8sClient = new DefaultKubernetesClient(config);

        return k8sClient.pods().list().getItems();
    }
}

In the application.yml:

server.port: 8888
spring.application.name: config
spring.cloud.config.server.git.uri: git@...

spring.cloud.kubernetes:
  client:
    masterUrl: http://x.x.x.x:8080
    namespace: whatever
@asarkar asarkar changed the title KubernetesAutoConfiguration ignores properties KubernetesAutoConfiguration ignores client properties Feb 2, 2017
@helpermethod
Copy link

Hi, another way to fix this is to set this value via a System property, e.g. in main

    public static void main(String[] args) {
        if (System.getProperty("kubernetes.master") == null) {
            System.setProperty("kubernetes.master", "INSERT-MASTER-URL-HERE");
        }

        SpringApplication.run(Application.class, args);
    }

@phoenix2x
Copy link

Run into the same issue.
KubernetesClientProperties is instantiated after KubernetesAutoConfiguration.

@pabloubal
Copy link

Same issue here, as @phoenix2x indicates, KubernetesClientProperties is getting instantiated after KubernetesAutoConfiguration, which prevents DefaultKubernetesClient from getting configured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants