fabric8io / kubernetes-client

Java client for Kubernetes & OpenShift
http://fabric8.io
Apache License 2.0
3.38k stars 1.46k forks source link

ConfigBuilder.withAutoConfigure is not working #6137

Closed ttbadr closed 1 month ago

ttbadr commented 1 month ago

Describe the bug

I create a kube config in code with ConfigBuilder, and I don't want to load the default kube config file, so I use the withAutoConfig method of the ConfigBuilder to set the autoConfig to false, but it's not working, the default kube config file still loaded.

after inverstigate, I found the default constructor of the ConfigBuilder will create a new Config

  public ConfigBuilder() {
    this(new Config());
  }

below is the default constructor of the Config, It will get the autoConfig value from system properties or env, not from the configBuilder

@Deprecated
  public Config() {
    this(!disableAutoConfig());
  }

  private static boolean disableAutoConfig() {
    return Utils.getSystemPropertyOrEnvVar(KUBERNETES_DISABLE_AUTO_CONFIG_SYSTEM_PROPERTY, false);
  }

Fabric8 Kubernetes Client version

6.12.1

Steps to reproduce

  1. make sure the default kubeConfig file exist and have some cluster configurations
  2. create a config with ConfigBuilder, set the autoConfig to false
  3. check the config object, it have configurations from the default kubeConfig file

Expected behavior

no default kubeConfig file loaded if autoConfig is false

Runtime

Kubernetes (vanilla)

Kubernetes API Server version

1.23

Environment

Windows

Fabric8 Kubernetes Client Logs

No response

Additional context

No response

rohanKanojia commented 1 month ago

@ttbadr : Does it work if you provide Config.empty() inside ConfigBuilder like this?

https://github.com/fabric8io/kubernetes-client/blob/d73b220b6c52b241d9f46fa386e0516b2ff93b73/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMockServer.java#L218

ttbadr commented 1 month ago

@ttbadr : Does it work if you provide Config.empty() inside ConfigBuilder like this?

https://github.com/fabric8io/kubernetes-client/blob/d73b220b6c52b241d9f46fa386e0516b2ff93b73/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMockServer.java#L218

great, It’s works for me