- Common ways to obtain Config
private void myMethod () {Config c =
String str;new ConfigBuilder().withMasterUrl(str).build()
new Config()
new ConfigBuilder().build()
- Smart code suggestions by Codota
}
private static boolean tryKubeConfig(Config config, String context) { LOGGER.debug("Trying to configure client from Kubernetes config..."); if (Utils.getSystemPropertyOrEnvVar(KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, true)) { String fileName = Utils.getSystemPropertyOrEnvVar(KUBERNETES_KUBECONFIG_FILE, new File(getHomeDir(), ".kube" + File.separator + "config").toString()); // if system property/env var contains multiple files take the first one based on the environment // we are running in (eg. : for Linux, ; for Windows) String[] fileNames = fileName.split(File.pathSeparator); if (fileNames.length > 1) { LOGGER.debug("Found multiple Kubernetes config files [{}], using the first one: [{}].", fileNames, fileNames[0]); fileName = fileNames[0]; } File kubeConfigFile = new File(fileName); boolean kubeConfigFileExists = Files.isRegularFile(kubeConfigFile.toPath()); if (kubeConfigFileExists) { LOGGER.debug("Found for Kubernetes config at: ["+kubeConfigFile.getPath()+"]."); String kubeconfigContents; try { kubeconfigContents = new String(Files.readAllBytes(kubeConfigFile.toPath()), StandardCharsets.UTF_8); } catch(IOException e) { LOGGER.error("Could not load Kubernetes config file from {}", kubeConfigFile.getPath(), e); return false; } Config.loadFromKubeconfig(config, context, kubeconfigContents, kubeConfigFile.getPath()); return true; } else { LOGGER.debug("Did not find Kubernetes config at: ["+kubeConfigFile.getPath()+"]. Ignoring."); } } return false; }
if (Utils.getSystemPropertyOrEnvVar(KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, true)) { File kubeConfigFile = new File( Utils.getSystemPropertyOrEnvVar(KUBERNETES_KUBECONFIG_FILE, new File(getHomeDir(), ".kube" + File.separator + "config").toString())); boolean kubeConfigFileExists = Files.isRegularFile(kubeConfigFile.toPath()); if (kubeConfigFileExists) {