public static Config fromKubeconfig(String kubeconfigContents) { return fromKubeconfig(null, kubeconfigContents, null); }
/** * Build config from the kubeconfig contents. * <p> * This requires to update the system property. In order to avoid changing the system property at the same time * from multiple running jobs, the method is marked as synchronized. * * @param kubeconfig the kubeconfig contents * @return the config that can be used to build {@link KubernetesClient} */ public static synchronized Config configFromKubeconfig(String kubeconfig) { String originalTryKubeconfig = Utils.getSystemPropertyOrEnvVar(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY); String originalTryServiceAccount = Utils.getSystemPropertyOrEnvVar(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY); String originalTryNamespacePath = Utils.getSystemPropertyOrEnvVar(Config.KUBERNETES_TRYNAMESPACE_PATH_SYSTEM_PROPERTY); try { System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false"); System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false"); System.setProperty(Config.KUBERNETES_TRYNAMESPACE_PATH_SYSTEM_PROPERTY, "false"); return Config.fromKubeconfig(kubeconfig); } finally { restoreProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, originalTryKubeconfig); restoreProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, originalTryServiceAccount); restoreProperty(Config.KUBERNETES_TRYNAMESPACE_PATH_SYSTEM_PROPERTY, originalTryNamespacePath); } }
LOGGER.log(FINE, "Configuring Kubernetes client from kubeconfig file"); try (InputStream is = ((FileCredentials) credentials).getContent()) { Config config = Config.fromKubeconfig(IOUtils.toString(is, StandardCharsets.UTF_8)); builder = new ConfigBuilder(config);