use of io.kubernetes.client.ApiException in project weblogic-kubernetes-operator by oracle.
the class CRDHelper method checkAndCreateCustomResourceDefinition.
/**
* Validates and, if necessary, created domains.weblogic.oracle CRD. No need
* to be async as operator can not begin processing until CRD exists
*/
public static void checkAndCreateCustomResourceDefinition() {
LOGGER.entering();
V1beta1CustomResourceDefinition crd = new V1beta1CustomResourceDefinition();
crd.setApiVersion("apiextensions.k8s.io/v1beta1");
crd.setKind("CustomResourceDefinition");
V1ObjectMeta om = new V1ObjectMeta();
om.setName("domains.weblogic.oracle");
crd.setMetadata(om);
V1beta1CustomResourceDefinitionSpec crds = new V1beta1CustomResourceDefinitionSpec();
crds.setGroup(KubernetesConstants.DOMAIN_GROUP);
crds.setVersion(KubernetesConstants.DOMAIN_VERSION);
crds.setScope("Namespaced");
V1beta1CustomResourceDefinitionNames crdn = new V1beta1CustomResourceDefinitionNames();
crdn.setPlural(KubernetesConstants.DOMAIN_PLURAL);
crdn.setSingular(KubernetesConstants.DOMAIN_SINGULAR);
crdn.setKind("Domain");
crdn.setShortNames(Collections.singletonList(KubernetesConstants.DOMAIN_SHORT));
crds.setNames(crdn);
crd.setSpec(crds);
CallBuilderFactory factory = ContainerResolver.getInstance().getContainer().getSPI(CallBuilderFactory.class);
V1beta1CustomResourceDefinition existingCRD = null;
try {
existingCRD = factory.create().readCustomResourceDefinition(crd.getMetadata().getName());
} catch (ApiException e) {
if (e.getCode() != CallBuilder.NOT_FOUND) {
LOGGER.warning(MessageKeys.EXCEPTION, e);
}
}
try {
if (existingCRD == null) {
LOGGER.info(MessageKeys.CREATING_CRD, crd.toString());
factory.create().createCustomResourceDefinition(crd);
}
} catch (ApiException e) {
LOGGER.warning(MessageKeys.EXCEPTION, e);
}
LOGGER.exiting();
}
use of io.kubernetes.client.ApiException in project weblogic-kubernetes-operator by oracle.
the class SecretHelperTest method createInvalidSecret.
// Create a named secret with no username / password in specified namespace
private V1Secret createInvalidSecret(String name, String namespace) throws Exception {
CallBuilderFactory factory = new CallBuilderFactory(null);
try {
V1Secret existing = factory.create().readSecret(name, namespace);
if (existing != null)
return existing;
} catch (ApiException ignore) {
// Just ignore and try to create it
}
if (isVersion18)
return null;
V1Secret body = new V1Secret();
// Set the required api version and kind of resource
body.setApiVersion("v1");
body.setKind("Secret");
// Setup the standard object metadata
V1ObjectMeta meta = new V1ObjectMeta();
meta.setName(name);
meta.setNamespace(namespace);
body.setMetadata(meta);
return factory.create().createSecret(namespace, body);
}
use of io.kubernetes.client.ApiException in project weblogic-kubernetes-operator by oracle.
the class ServiceHelperTest method startClean.
@Before
public void startClean() throws Exception {
CallBuilderFactory factory = new CallBuilderFactory(null);
// Delete the service if left around.
System.out.println("Deleting service pre-test");
try {
factory.create().deleteService("domain-uid-admin", "tests");
} catch (ApiException e) {
if (e.getCode() != CallBuilder.NOT_FOUND) {
throw e;
}
}
}
use of io.kubernetes.client.ApiException in project twister2 by DSC-SPIDAL.
the class WorkerController method buildWorkerList.
/**
* build worker list by getting the pod list from the kubernetes master
*/
private void buildWorkerList() {
String namespace = KubernetesContext.namespace(config);
String servicelabel = KubernetesUtils.createServiceLabelWithApp(jobName);
int basePort = KubernetesContext.workerBasePort(config);
V1PodList list = null;
try {
list = coreApi.listNamespacedPod(namespace, null, null, null, null, servicelabel, null, null, null, null);
} catch (ApiException e) {
String logMessage = "Exception when getting the pod list for the job: " + jobName + "\n" + "exCode: " + e.getCode() + "\n" + "responseBody: " + e.getResponseBody();
LOG.log(Level.SEVERE, logMessage, e);
throw new RuntimeException(e);
}
workerList.clear();
for (V1Pod pod : list.getItems()) {
String podName = pod.getMetadata().getName();
if (!podName.startsWith(jobName)) {
LOG.warning("A pod received that does not belong to this job. PodName: " + podName);
continue;
}
InetAddress podIP = convertStringToIP(pod.getStatus().getPodIP());
for (int i = 0; i < workersPerPod; i++) {
int containerIndex = i;
int workerID = calculateWorkerID(podName, containerIndex);
WorkerNetworkInfo workerNetworkInfo = new WorkerNetworkInfo(podIP, basePort + containerIndex, workerID);
workerList.add(workerNetworkInfo);
}
}
}
Aggregations