private static boolean loadFromKubeconfig(Config config, String context, String kubeconfigContents, String kubeconfigPath) { try { io.fabric8.kubernetes.api.model.Config kubeConfig = KubeConfigUtils.parseConfigFromString(kubeconfigContents); if (context != null) { kubeConfig.setCurrentContext(context); Context currentContext = KubeConfigUtils.getCurrentContext(kubeConfig); Cluster currentCluster = KubeConfigUtils.getCluster(kubeConfig, currentContext); if (currentCluster != null) { config.setMasterUrl(currentCluster.getServer()); config.setDisableHostnameVerification(currentCluster.getInsecureSkipTlsVerify() != null && currentCluster.getInsecureSkipTlsVerify()); config.setCaCertData(currentCluster.getCertificateAuthorityData()); AuthInfo currentAuthInfo = KubeConfigUtils.getUserAuthInfo(kubeConfig, currentContext); if (currentAuthInfo != null) {
LOGGER.debug("Found for Kubernetes config at: ["+kubeConfigFile.getPath()+"]."); try { io.fabric8.kubernetes.api.model.Config kubeConfig = KubeConfigUtils.parseConfig(kubeConfigFile); Context currentContext = KubeConfigUtils.getCurrentContext(kubeConfig); Cluster currentCluster = KubeConfigUtils.getCluster(kubeConfig, currentContext); if (currentCluster != null) { config.setMasterUrl(currentCluster.getServer()); config.setCaCertFile(absolutify(kubeConfigFile, currentCluster.getCertificateAuthority())); config.setCaCertData(currentCluster.getCertificateAuthorityData()); AuthInfo currentAuthInfo = KubeConfigUtils.getUserAuthInfo(kubeConfig, currentContext); if (currentAuthInfo != null) { config.setClientCertFile(absolutify(kubeConfigFile, currentAuthInfo.getClientCertificate()));
protected List<String> contextOptions(ConfigProblemSetBuilder psBuilder) { Config kubeconfig; try { File kubeconfigFileOpen = new File(getKubeconfigFile()); kubeconfig = KubeConfigUtils.parseConfig(kubeconfigFileOpen); } catch (IOException e) { psBuilder.addProblem(ERROR, e.getMessage()); return null; } return kubeconfig.getContexts() .stream() .map(NamedContext::getName) .collect(Collectors.toList()); }
/** * Returns the current user token for the config and current context */ public static String getUserToken(Config config, Context context) { AuthInfo authInfo = getUserAuthInfo(config, context); if (authInfo != null) { return authInfo.getToken(); } return null; }
protected List<String> contextOptions(ConfigProblemSetBuilder psBuilder) { Config kubeconfig; try { File kubeconfigFileOpen = new File(getKubeconfigFile()); kubeconfig = KubeConfigUtils.parseConfig(kubeconfigFileOpen); } catch (IOException e) { psBuilder.addProblem(ERROR, e.getMessage()); return null; } return kubeconfig.getContexts() .stream() .map(NamedContext::getName) .collect(Collectors.toList()); }
/** * Returns the current user token for the config and current context */ public static String getUserToken(Config config, Context context) { AuthInfo authInfo = getUserAuthInfo(config, context); if (authInfo != null) { return authInfo.getToken(); } return null; }
kubeconfig = KubeConfigUtils.parseConfig(kubeconfigFileOpen); } catch (IOException e) { psBuilder.addProblem(ERROR, e.getMessage());
kubeconfig = KubeConfigUtils.parseConfig(kubeconfigFileOpen); } catch (IOException e) { psBuilder.addProblem(ERROR, e.getMessage());
Path configPath = Paths.get(configFile); Path configFolder = configPath.normalize().getParent(); Config kubeconfig = KubeConfigUtils.parseConfig(configPath.toFile()); String currentContext = Optional.fromNullable(conf.get(KubernetesLocationConfig.KUBECONFIG_CONTEXT)).or(kubeconfig.getCurrentContext()); Optional<NamedContext> foundContext = Iterables.tryFind(kubeconfig.getContexts(), c -> c.getName().equals(currentContext));