private static boolean tryNamespaceFromPath(Config config) { LOGGER.debug("Trying to configure client namespace from Kubernetes service account namespace path..."); if (Utils.getSystemPropertyOrEnvVar(KUBERNETES_TRYNAMESPACE_PATH_SYSTEM_PROPERTY, true)) { String serviceAccountNamespace = Utils.getSystemPropertyOrEnvVar(KUBERNETES_NAMESPACE_FILE, KUBERNETES_NAMESPACE_PATH); boolean serviceAccountNamespaceExists = Files.isRegularFile(new File(serviceAccountNamespace).toPath()); if (serviceAccountNamespaceExists) { LOGGER.debug("Found service account namespace at: [" + serviceAccountNamespace + "]."); try { String namespace = new String(Files.readAllBytes(new File(serviceAccountNamespace).toPath())); config.setNamespace(namespace.replace(System.lineSeparator(), "")); return true; } catch (IOException e) { LOGGER.error("Error reading service account namespace from: [" + serviceAccountNamespace + "].", e); } } else { LOGGER.debug("Did not find service account namespace at: [" + serviceAccountNamespace + "]. Ignoring."); } } return false; }
if (currentCluster != null) { config.setMasterUrl(currentCluster.getServer()); config.setNamespace(currentContext.getNamespace()); config.setTrustCerts(currentCluster.getInsecureSkipTlsVerify() != null && currentCluster.getInsecureSkipTlsVerify()); config.setDisableHostnameVerification(currentCluster.getInsecureSkipTlsVerify() != null && currentCluster.getInsecureSkipTlsVerify());
config.setMasterUrl(Utils.getSystemPropertyOrEnvVar(KUBERNETES_MASTER_SYSTEM_PROPERTY, config.getMasterUrl())); config.setApiVersion(Utils.getSystemPropertyOrEnvVar(KUBERNETES_API_VERSION_SYSTEM_PROPERTY, config.getApiVersion())); config.setNamespace(Utils.getSystemPropertyOrEnvVar(KUBERNETES_NAMESPACE_SYSTEM_PROPERTY, config.getNamespace())); config.setCaCertFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CA_CERTIFICATE_FILE_SYSTEM_PROPERTY, config.getCaCertFile())); config.setCaCertData(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CA_CERTIFICATE_DATA_SYSTEM_PROPERTY, config.getCaCertData()));
private boolean tryNamespaceFromPath(Config config) { LOGGER.debug("Trying to configure client namespace from Kubernetes service account namespace path..."); if (Utils.getSystemPropertyOrEnvVar(KUBERNETES_TRYNAMESPACE_PATH_SYSTEM_PROPERTY, true)) { String serviceAccountNamespace = Utils.getSystemPropertyOrEnvVar(KUBERNETES_NAMESPACE_FILE, KUBERNETES_NAMESPACE_PATH); boolean serviceAccountNamespaceExists = Files.isRegularFile(new File(serviceAccountNamespace).toPath()); if (serviceAccountNamespaceExists) { LOGGER.debug("Found service account namespace at: [" + serviceAccountNamespace + "]."); try { String namespace = new String(Files.readAllBytes(new File(serviceAccountNamespace).toPath())); config.setNamespace(namespace.replace(System.lineSeparator(), "")); return true; } catch (IOException e) { LOGGER.error("Error reading service account namespace from: [" + serviceAccountNamespace + "].", e); } } else { LOGGER.debug("Did not find service account namespace at: [" + serviceAccountNamespace + "]. Ignoring."); } } return false; }
public static KubernetesClient getKubernetesClient(KubernetesDeployerProperties kubernetesDeployerProperties) { Config config = kubernetesDeployerProperties.getFabric8(); // Since namespace is used as a deployer as well as a client property, merging it from the deployer if it is not // already set in the client properties. if (config.getNamespace() == null) { config.setNamespace(kubernetesDeployerProperties.getNamespace()); } return new DefaultKubernetesClient(config); }
if (currentCluster != null) { config.setMasterUrl(currentCluster.getServer()); config.setNamespace(currentContext.getNamespace()); config.setTrustCerts(currentCluster.getInsecureSkipTlsVerify() != null && currentCluster.getInsecureSkipTlsVerify()); config.setCaCertFile(absolutify(kubeConfigFile, currentCluster.getCertificateAuthority()));
config.setMasterUrl(Utils.getSystemPropertyOrEnvVar(KUBERNETES_MASTER_SYSTEM_PROPERTY, config.getMasterUrl())); config.setApiVersion(Utils.getSystemPropertyOrEnvVar(KUBERNETES_API_VERSION_SYSTEM_PROPERTY, config.getApiVersion())); config.setNamespace(Utils.getSystemPropertyOrEnvVar(KUBERNETES_NAMESPACE_SYSTEM_PROPERTY, config.getNamespace())); config.setCaCertFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CA_CERTIFICATE_FILE_SYSTEM_PROPERTY, config.getCaCertFile())); config.setCaCertData(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CA_CERTIFICATE_DATA_SYSTEM_PROPERTY, config.getCaCertData()));
private void updateKubeConfig(Config kubeConfig, JsonObject config, K8SDiscovery annotation) { final String user = ConfigurationUtil.getStringConfiguration(config, USER, annotation.user()); final String password = ConfigurationUtil.getStringConfiguration(config, PASSWORD, annotation.password()); final String api_token = ConfigurationUtil.getStringConfiguration(config, API_TOKEN, annotation.api_token()); final String master_url = ConfigurationUtil.getStringConfiguration(config, MASTER_URL, annotation.master_url()); final String namespace = ConfigurationUtil.getStringConfiguration(config, NAMESPACE, annotation.namespace()); if (StringUtil.isNullOrEmpty(kubeConfig.getUsername())) kubeConfig.setUsername(user); if (StringUtil.isNullOrEmpty(kubeConfig.getPassword())) kubeConfig.setPassword(password); if (StringUtil.isNullOrEmpty(kubeConfig.getOauthToken())) kubeConfig.setOauthToken(api_token); if (StringUtil.isNullOrEmpty(kubeConfig.getMasterUrl())) kubeConfig.setMasterUrl(master_url); if (StringUtil.isNullOrEmpty(kubeConfig.getNamespace())) kubeConfig.setNamespace(namespace); // check oauthToken if (StringUtil.isNullOrEmpty(kubeConfig.getOauthToken())) kubeConfig.setOauthToken(TokenUtil.getAccountToken()); } }