本文整理汇总了Java中io.fabric8.kubernetes.client.Config类的典型用法代码示例。如果您正苦于以下问题:Java Config类的具体用法?Java Config怎么用?Java Config使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Config类属于io.fabric8.kubernetes.client包,在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setup
import io.fabric8.kubernetes.client.Config; //导入依赖的package包/类
@Before
public void setup() throws IOException {
executeTask(TEST_CONFIG_DIR, "deleteAll");
Map<String, String> environmentVariables = TestEnvironmentUtil.loadEnvironmentVariables(
KUBERNETES_URL_ENV,
KUBERNETES_USERNAME_ENV,
KUBERNETES_PASSWORD_ENV,
KUBERNETES_NAMESPACE_PREFIX_ENV
);
namespaceEnvironmentOne = environmentVariables.get(KUBERNETES_NAMESPACE_PREFIX_ENV) + "-" + ENVIRONMENT_ONE;
namespaceEnvironmentTwo = environmentVariables.get(KUBERNETES_NAMESPACE_PREFIX_ENV) + "-" + ENVIRONMENT_TWO;
Config config = new ConfigBuilder()
.withMasterUrl(environmentVariables.get(KUBERNETES_URL_ENV))
.withTrustCerts(true)
.withUsername(environmentVariables.get(KUBERNETES_USERNAME_ENV))
.withPassword(environmentVariables.get(KUBERNETES_PASSWORD_ENV))
.build();
kubernetesClient = new DefaultKubernetesClient(config);
}
示例2: updateKubeConfig
import io.fabric8.kubernetes.client.Config; //导入依赖的package包/类
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());
}
示例3: resolveBeanAnnotations
import io.fabric8.kubernetes.client.Config; //导入依赖的package包/类
/**
* Resolves discovery annotation in AbstractVerticles
*
* @param service the service where to resolve the annotations
* @param kubeConfig the kubernetes config
*/
public static void resolveBeanAnnotations(AbstractVerticle service, Config kubeConfig) {
final JsonObject env = service.config();
final List<Field> serviceNameFields = findServiceFields(service);
if (!env.getBoolean("kube.offline", false)) { // online
final DefaultKubernetesClient client =
new DefaultKubernetesClient(kubeConfig); // TODO be aware of OpenShiftClient
if (!serviceNameFields.isEmpty()) {
findServiceEntryAndSetValue(service, serviceNameFields, env, client);
} else {
// TODO check and handle Endpoints & Pods
}
} else {
// resolve properties offline
if (!serviceNameFields.isEmpty()) {
resolveServicesOffline(service, serviceNameFields, env);
} else {
// TODO check and handle Endpoints & Pods
}
}
}
示例4: createClient
import io.fabric8.kubernetes.client.Config; //导入依赖的package包/类
private static KubernetesClient createClient(PluginSettings pluginSettings) throws Exception {
ConfigBuilder configBuilder = new ConfigBuilder().withMasterUrl(pluginSettings.getKubernetesClusterUrl());
if (StringUtils.isNotBlank(pluginSettings.getKubernetesClusterUsername())) {
configBuilder.withUsername(pluginSettings.getKubernetesClusterUsername());
}
if (StringUtils.isNotBlank(pluginSettings.getKubernetesClusterPassword())) {
configBuilder.withPassword(pluginSettings.getKubernetesClusterPassword());
}
if (StringUtils.isNotBlank(pluginSettings.getKubernetesClusterCACert())) {
configBuilder.withCaCertData(pluginSettings.getKubernetesClusterCACert());
}
Config build = configBuilder.build();
return new DefaultKubernetesClient(build);
}
示例5: createKubernetesClientForSSO
import io.fabric8.kubernetes.client.Config; //导入依赖的package包/类
/**
* Creates the kubernetes client for the SSO signed in user
*/
private KubernetesClient createKubernetesClientForSSO(UIContext context) {
String authHeader = TokenHelper.getMandatoryAuthHeader(context);
String openshiftToken = TokenHelper.getMandatoryTokenFor(KeycloakEndpoint.GET_OPENSHIFT_TOKEN, authHeader);
String openShiftApiUrl = System.getenv(EnvironmentVariables.OPENSHIFT_API_URL);
if (Strings.isNullOrBlank(openShiftApiUrl)) {
throw new WebApplicationException("No environment variable defined: "
+ EnvironmentVariables.OPENSHIFT_API_URL + " so cannot connect to OpenShift Online!");
}
Config config = new ConfigBuilder().withMasterUrl(openShiftApiUrl).withOauthToken(openshiftToken).
// TODO until we figure out the trust thing lets ignore warnings
withTrustCerts(true).
build();
return new DefaultKubernetesClient(config);
}
示例6: get
import io.fabric8.kubernetes.client.Config; //导入依赖的package包/类
/**
* Gets OpenShift client. When using, you are responsible for closing it.
* @param masterUrl URL of OpenShift master
* @param token authorization token
* @return OpenShift client
*/
public OpenShiftClient get(String masterUrl, String token) {
if (fabric8PlatformDevMode) {
LOG.info("Using default OpenShift Client for 'fabric8-platform' deployment on minishift");
return new DefaultOpenShiftClient();
}
LOG.info("Certificate file: {}", caCertFile);
Config config = (StringUtils.isBlank(caCertFile))
? new ConfigBuilder().withMasterUrl(masterUrl).withOauthToken(token).build()
: new ConfigBuilder().withMasterUrl(masterUrl).withOauthToken(token).withCaCertFile(caCertFile).build();
return new DefaultOpenShiftClient(config);
}
示例7: Fabric8MavenWrapper
import io.fabric8.kubernetes.client.Config; //导入依赖的package包/类
public Fabric8MavenWrapper(Path projectPath, Path settingsPath) throws VerificationException {
this.maven = MavenUtil.forProject(projectPath, settingsPath).forkJvm();
this.maven.addCliOptions("-Dfabric8.imagePullPolicy=Always");
// These should no longer be needed (https://issues.jboss.org/browse/OSFUSE-316 )
//this.maven.addCliOptions("-Dfabric8.mode=openshift");
//this.maven.addCliOptions("-Dfabric8.build.strategy=s2i");
this.maven.addCliOptions("-D" + Config.KUBERNETES_KUBECONFIG_FILE + "=" + IOUtils.TMP_DIRECTORY.resolve("oc").resolve("oc.config"));
this.maven.disableAutoclean();
this.overrideOptions = new HashMap<>();
this.projectPath = projectPath;
}
示例8: initializeOpenShiftClient
import io.fabric8.kubernetes.client.Config; //导入依赖的package包/类
/**
* Initializes an {@link OpenShiftClient}
*
* @param serverUrl
* the optional URL of where the OpenShift cluster API server is
* running
*/
public synchronized static void initializeOpenShiftClient(String serverUrl) {
OpenShiftConfigBuilder configBuilder = new OpenShiftConfigBuilder();
if (serverUrl != null && !serverUrl.isEmpty()) {
configBuilder.withMasterUrl(serverUrl);
}
Config config = configBuilder.build();
config.setUserAgent("openshift-sync-plugin-"
+ Jenkins.getInstance().getPluginManager().getPlugin("openshift-sync").getVersion() + "/fabric8-"
+ Version.clientVersion());
openShiftClient = new DefaultOpenShiftClient(config);
}
示例9: kubernetesClientConfig
import io.fabric8.kubernetes.client.Config; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(Config.class)
public Config kubernetesClientConfig(KubernetesClientProperties kubernetesClientProperties) {
Config base = new Config();
Config properties = new ConfigBuilder(base)
//Only set values that have been explicitly specified
.withMasterUrl(or(kubernetesClientProperties.getMasterUrl(), base.getMasterUrl()))
.withApiVersion(or(kubernetesClientProperties.getApiVersion(), base.getApiVersion()))
.withNamespace(or(kubernetesClientProperties.getNamespace(), base.getNamespace()))
.withUsername(or(kubernetesClientProperties.getUsername(), base.getUsername()))
.withPassword(or(kubernetesClientProperties.getPassword(), base.getPassword()))
.withCaCertFile(or(kubernetesClientProperties.getCaCertFile(), base.getCaCertFile()))
.withCaCertData(or(kubernetesClientProperties.getCaCertData(), base.getCaCertData()))
.withClientKeyFile(or(kubernetesClientProperties.getClientKeyFile(), base.getClientKeyFile()))
.withClientKeyData(or(kubernetesClientProperties.getClientKeyData(), base.getClientKeyData()))
.withClientCertFile(or(kubernetesClientProperties.getClientCertFile(), base.getClientCertFile()))
.withClientCertData(or(kubernetesClientProperties.getClientCertData(), base.getClientCertData()))
//No magic is done for the properties below so we leave them as is.
.withClientKeyAlgo(or(kubernetesClientProperties.getClientKeyAlgo(), base.getClientKeyAlgo()))
.withClientKeyPassphrase(or(kubernetesClientProperties.getClientKeyPassphrase(), base.getClientKeyPassphrase()))
.withConnectionTimeout(or(kubernetesClientProperties.getConnectionTimeout(), base.getConnectionTimeout()))
.withRequestTimeout(or(kubernetesClientProperties.getRequestTimeout(), base.getRequestTimeout()))
.withRollingTimeout(or(kubernetesClientProperties.getRollingTimeout(), base.getRollingTimeout()))
.withTrustCerts(or(kubernetesClientProperties.isTrustCerts(), base.isTrustCerts()))
.build();
if (properties.getNamespace() == null || properties.getNamespace().isEmpty()) {
LOG.warn("No namespace has been detected. Please specify KUBERNETES_NAMESPACE env var, or use a later kubernetes version (1.3 or later)");
}
return properties;
}
示例10: createKubernetesClient
import io.fabric8.kubernetes.client.Config; //导入依赖的package包/类
private static KubernetesClient createKubernetesClient(EnvironmentConfig environmentConfig) {
Config config = new ConfigBuilder()
.withMasterUrl(environmentConfig.getBaseUrl())
.withTrustCerts(true)
.withUsername(environmentConfig.getAuthConfig().getUsername())
.withPassword(environmentConfig.getAuthConfig().getPassword())
.build();
return new DefaultKubernetesClient(config);
}
示例11: getClient
import io.fabric8.kubernetes.client.Config; //导入依赖的package包/类
static KubernetesClient getClient(AccountDeploymentDetails<KubernetesAccount> details) {
KubernetesAccount account = details.getAccount();
Config config = KubernetesConfigParser.parse(account.getKubeconfigFile(),
account.getContext(),
account.getCluster(),
account.getUser(),
account.getNamespaces(),
false);
return new DefaultKubernetesClient(config);
}
示例12: main
import io.fabric8.kubernetes.client.Config; //导入依赖的package包/类
public static void main(String [] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
Map<String, String> env = System.getenv();
String openshiftUri = String.format("https://%s:%s", getEnvOrThrow(env, "KUBERNETES_SERVICE_HOST"), getEnvOrThrow(env, "KUBERNETES_SERVICE_PORT"));
Config config = new ConfigBuilder().withMasterUrl(openshiftUri).withOauthToken(getAuthenticationToken()).withNamespace(getNamespace()).build();
OpenShiftClient openShiftClient = new DefaultOpenShiftClient(config);
AddressSpaceApi addressSpaceApi = new ConfigMapAddressSpaceApi(openShiftClient);
KeycloakManager keycloakManager = new KeycloakManager(new Keycloak(KeycloakParams.fromEnv(System.getenv())));
addressSpaceApi.watchAddressSpaces(keycloakManager);
}
示例13: givenUserHasProjects
import io.fabric8.kubernetes.client.Config; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void givenUserHasProjects() {
OpenShiftClient client = mock(OpenShiftClient.class);
ClientNonNamespaceOperation<Project, ProjectList, DoneableProject, ClientResource<Project, DoneableProject>> projects = mock(
ClientNonNamespaceOperation.class);
ProjectList projectList = new ProjectListBuilder(false)
.addToItems(new ProjectBuilder(false).withNewMetadata().withName("foo").endMetadata().build()).build();
when(projects.list()).thenReturn(projectList);
when(client.projects()).thenReturn(projects);
when(clientFactory.create(any(Config.class))).thenReturn(client);
}
开发者ID:fabric8io,项目名称:openshift-elasticsearch-plugin,代码行数:12,代码来源:OpenshiftRequestContextFactoryTest.java
示例14: initDiscovery
import io.fabric8.kubernetes.client.Config; //导入依赖的package包/类
@Override
public void initDiscovery(AbstractVerticle service) {
final JsonObject config = service.config();
final Vertx vertx = service.getVertx();
if (!service.getClass().isAnnotationPresent(K8SDiscovery.class))
return;
final K8SDiscovery annotation = service.getClass().getAnnotation(K8SDiscovery.class);
final String customClientClassName =
ConfigurationUtil.getStringConfiguration(
config,
CUSTOM_CLIENT_CONFIGURATION,
annotation.customClientConfiguration().getCanonicalName());
final CustomClientConfig custConf = getCustomConfiguration(customClientClassName);
final Config customConfiguration = custConf.createCustomConfiguration(vertx);
if (customConfiguration == null) {
final String master_url =
ConfigurationUtil.getStringConfiguration(config, MASTER_URL, annotation.master_url());
final String namespace =
ConfigurationUtil.getStringConfiguration(config, NAMESPACE, annotation.namespace());
final Config kubeConfig =
new ConfigBuilder().withMasterUrl(master_url).withNamespace(namespace).build();
updateKubeConfig(kubeConfig, config, annotation);
// 1.) Check from K8SDiscovery Annotation
// 1.1) read properties and from Annotation or from configuration
// 2.) init KubernetesClient
KubeDiscovery.resolveBeanAnnotations(service, kubeConfig);
} else {
updateKubeConfig(customConfiguration, config, annotation);
KubeDiscovery.resolveBeanAnnotations(service, customConfiguration);
}
}
示例15: buildKubernetesClient
import io.fabric8.kubernetes.client.Config; //导入依赖的package包/类
private KubernetesClient buildKubernetesClient(String token, String kubernetesMaster) {
if (StringUtil.isNullOrEmpty(token)) {
token = getAccountToken();
}
logger.info("Kubernetes Discovery: Bearer Token { " + token + " }");
Config config = new ConfigBuilder().withOauthToken(token).withMasterUrl(kubernetesMaster).build();
return new DefaultKubernetesClient(config);
}