use of io.fabric8.kubernetes.client.Client in project kie-wb-common by kiegroup.
the class OpenShiftNameServiceClientListener method trigger.
@Override
public void trigger(OpenShiftClient client, OpenShiftRuntimeConfig runtimeConfig) {
String prjName = runtimeConfig.getProjectName();
RouteList routeList = client.getDelegate().routes().inNamespace(prjName).list();
String routerHost = System.getProperty(OpenShiftNameServiceClientListener.class.getName() + ".routerHost", "10.34.75.115");
OpenShiftNameService.setRoutes(routeList, routerHost);
}
use of io.fabric8.kubernetes.client.Client in project syndesis-qe by syndesisio.
the class FtpTemplate method deploy.
public static void deploy() {
List<ContainerPort> ports = new LinkedList<>();
ports.add(new ContainerPortBuilder().withName("ftp-cmd").withContainerPort(2121).withProtocol("TCP").build());
for (int i = 0; i < 10; i++) {
ContainerPort dataPort = new ContainerPortBuilder().withName("ftp-data-" + i).withContainerPort(2300 + i).withProtocol("TCP").build();
ports.add(dataPort);
}
OpenShiftUtils.client().deploymentConfigs().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addToSelector(LABEL_NAME, APP_NAME).withReplicas(1).editOrNewTemplate().editOrNewMetadata().addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addNewContainer().withName(APP_NAME).withImage("dsimansk/ftpd:latest").addAllToPorts(ports).endContainer().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
ServiceSpecBuilder serviceSpecBuilder = new ServiceSpecBuilder().addToSelector(LABEL_NAME, APP_NAME);
serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName("ftp-cmd").withPort(2121).withTargetPort(new IntOrString(2121)).build());
for (int i = 0; i < 10; i++) {
serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName("ftp-data-" + i).withPort(2300 + i).withTargetPort(new IntOrString(2300 + i)).build());
}
OpenShiftUtils.getInstance().client().services().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpecLike(serviceSpecBuilder.build()).endSpec().done();
try {
OpenShiftWaitUtils.waitFor(OpenShiftWaitUtils.areExactlyNPodsReady(LABEL_NAME, APP_NAME, 1));
Thread.sleep(20 * 1000);
} catch (InterruptedException | TimeoutException e) {
log.error("Wait for {} deployment failed ", APP_NAME, e);
}
Account ftpAccount = new Account();
ftpAccount.setService("ftp");
Map<String, String> accountParameters = new HashMap<>();
accountParameters.put("host", "ftpd");
accountParameters.put("port", "2121");
ftpAccount.setProperties(accountParameters);
AccountsDirectory.getInstance().addAccount("FTP", ftpAccount);
}
use of io.fabric8.kubernetes.client.Client in project syndesis-qe by syndesisio.
the class SyndesisTemplate method deploy.
public static void deploy() {
OpenShiftUtils.getInstance().cleanAndAssert();
// get & create restricted SA
OpenShiftUtils.getInstance().createServiceAccount(getSupportSA());
// get token from SA `oc secrets get-token` && wait until created to prevent 404
TestUtils.waitForEvent(Optional::isPresent, () -> OpenShiftUtils.getInstance().getSecrets().stream().filter(s -> s.getMetadata().getName().startsWith("syndesis-oauth-client-token")).findFirst(), TimeUnit.MINUTES, 2, TimeUnit.SECONDS, 5);
Secret secret = OpenShiftUtils.getInstance().getSecrets().stream().filter(s -> s.getMetadata().getName().startsWith("syndesis-oauth-client-token")).findFirst().get();
// token is Base64 encoded by default
String oauthTokenEncoded = secret.getData().get("token");
byte[] oauthTokenBytes = Base64.decodeBase64(oauthTokenEncoded);
String oauthToken = new String(oauthTokenBytes);
// get the template
Template template = getTemplate();
// set params
Map<String, String> templateParams = new HashMap<>();
templateParams.put("ROUTE_HOSTNAME", TestConfiguration.openShiftNamespace() + "." + TestConfiguration.syndesisUrlSuffix());
templateParams.put("OPENSHIFT_MASTER", TestConfiguration.openShiftUrl());
templateParams.put("OPENSHIFT_PROJECT", TestConfiguration.openShiftNamespace());
templateParams.put("OPENSHIFT_OAUTH_CLIENT_SECRET", oauthToken);
templateParams.put("TEST_SUPPORT_ENABLED", "true");
// process & create
KubernetesList processedTemplate = OpenShiftUtils.getInstance().recreateAndProcessTemplate(template, templateParams);
OpenShiftUtils.getInstance().createResources(processedTemplate);
OpenShiftUtils.createRestRoute(TestConfiguration.openShiftNamespace(), TestConfiguration.syndesisUrlSuffix());
// TODO: there's a bug in openshift-client, we need to initialize manually
OpenShiftUtils.client().roleBindings().createOrReplaceWithNew().withNewMetadata().withName("syndesis:editors").endMetadata().withNewRoleRef().withName("edit").endRoleRef().addNewSubject().withKind("ServiceAccount").withName(Component.SERVER.getName()).withNamespace(TestConfiguration.openShiftNamespace()).endSubject().addToUserNames(String.format("system:serviceaccount:%s:%s", TestConfiguration.openShiftNamespace(), Component.SERVER.getName())).done();
}
use of io.fabric8.kubernetes.client.Client in project carbon-apimgt by wso2.
the class KubernetesGatewayImpl method buildConfig.
/**
* Build configurations for Openshift client
*
* @throws ContainerBasedGatewayException if failed to configure Openshift client
*/
private Config buildConfig() throws ContainerBasedGatewayException {
System.setProperty(TRY_KUBE_CONFIG, "false");
System.setProperty(TRY_SERVICE_ACCOUNT, "true");
ConfigBuilder configBuilder;
if (masterURL != null) {
configBuilder = new ConfigBuilder().withMasterUrl(masterURL);
} else {
throw new ContainerBasedGatewayException("Kubernetes Master URL is not provided!", ExceptionCodes.ERROR_INITIALIZING_DEDICATED_CONTAINER_BASED_GATEWAY);
}
if (!StringUtils.isEmpty(saTokenFileName)) {
configBuilder.withOauthToken(resolveToken("encrypted" + saTokenFileName));
}
return configBuilder.build();
}
use of io.fabric8.kubernetes.client.Client in project carbon-apimgt by wso2.
the class KubernetesGatewayImpl method initImpl.
/**
* @see ContainerBasedGatewayGenerator#initImpl(Map)
*/
@Override
void initImpl(Map<String, String> implParameters) throws ContainerBasedGatewayException {
try {
setValues(implParameters);
setClient(new DefaultOpenShiftClient(buildConfig()));
} catch (KubernetesClientException e) {
String msg = "Error occurred while creating Default Openshift Client";
throw new ContainerBasedGatewayException(msg, e, ExceptionCodes.ERROR_INITIALIZING_DEDICATED_CONTAINER_BASED_GATEWAY);
}
}
Aggregations