use of io.kubernetes.client.openapi.models.V1ObjectMeta in project heron by twitter.
the class V1Controller method createTopologyService.
/**
* Creates a headless <code>Service</code> to facilitate communication between Pods in a <code>topology</code>.
* @return A fully configured <code>Service</code> to be used by a <code>topology</code>.
*/
private V1Service createTopologyService() {
final String topologyName = getTopologyName();
final V1Service service = new V1Service();
// Setup service metadata.
final V1ObjectMeta objectMeta = new V1ObjectMeta().name(topologyName).annotations(getServiceAnnotations()).labels(getServiceLabels());
service.setMetadata(objectMeta);
// Create the headless service.
final V1ServiceSpec serviceSpec = new V1ServiceSpec().clusterIP("None").selector(getPodMatchLabels(topologyName));
service.setSpec(serviceSpec);
return service;
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project pravega by pravega.
the class AbstractService method getBookkeeperOperatorConfigMap.
private V1ConfigMap getBookkeeperOperatorConfigMap() {
Map<String, String> dataMap = new HashMap<>();
dataMap.put("PRAVEGA_CLUSTER_NAME", PRAVEGA_ID);
dataMap.put("WAIT_FOR", ZK_SERVICE_NAME);
return new V1ConfigMapBuilder().withApiVersion("v1").withKind("ConfigMap").withMetadata(new V1ObjectMeta().name(CONFIG_MAP_BOOKKEEPER)).withData(dataMap).build();
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project pravega by pravega.
the class K8sClient method createNamespace.
/**
* Method used to create a namespace. This blocks until the namespace is created.
* @param namespace Namespace to be created.
* @return V1Namespace.
*/
@SneakyThrows(ApiException.class)
public V1Namespace createNamespace(final String namespace) {
CoreV1Api api = new CoreV1Api();
try {
V1Namespace existing = api.readNamespace(namespace, PRETTY_PRINT, Boolean.FALSE, Boolean.FALSE);
if (existing != null) {
log.info("Namespace {} already exists, ignoring namespace create operation.", namespace);
return existing;
}
} catch (ApiException ignore) {
// ignore exception and proceed with Namespace creation.
}
V1Namespace body = new V1Namespace();
// Set the required api version and kind of resource
body.setApiVersion("v1");
body.setKind("Namespace");
// Setup the standard object metadata
V1ObjectMeta meta = new V1ObjectMeta();
meta.setName(namespace);
body.setMetadata(meta);
return api.createNamespace(body, PRETTY_PRINT, DRY_RUN, FIELD_MANAGER);
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class ConfigMapLock method create.
@Override
public boolean create(LeaderElectionRecord record) {
try {
V1ConfigMap configMap = new V1ConfigMap();
V1ObjectMeta objectMeta = new V1ObjectMeta();
objectMeta.setName(name);
objectMeta.setNamespace(namespace);
Map<String, String> annotations = new HashMap<>();
annotations.put(LeaderElectionRecordAnnotationKey, coreV1Client.getApiClient().getJSON().serialize(record));
objectMeta.setAnnotations(annotations);
if (record.getOwnerReference() != null) {
objectMeta.setOwnerReferences(Collections.singletonList(record.getOwnerReference()));
}
configMap.setMetadata(objectMeta);
V1ConfigMap createdConfigMap = coreV1Client.createNamespacedConfigMap(namespace, configMap, null, null, null, null);
configMapRefer.set(createdConfigMap);
return true;
} catch (ApiException e) {
if (e.getCode() == HttpURLConnection.HTTP_CONFLICT) {
log.debug("received {} when creating configmap lock", e.getCode(), e);
} else {
log.error("received {} when creating configmap lock", e.getCode(), e);
}
return false;
}
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class EventLoggerTest method testPatchComputing.
@Test
public void testPatchComputing() {
CoreV1Event event1 = new CoreV1EventBuilder().withSource(new V1EventSourceBuilder().build()).withMetadata(new V1ObjectMeta()).withInvolvedObject(new V1ObjectReferenceBuilder().build()).withCount(1).withMessage("foo1").build();
CoreV1Event event2 = new CoreV1EventBuilder().withSource(new V1EventSourceBuilder().build()).withMetadata(new V1ObjectMeta()).withInvolvedObject(new V1ObjectReferenceBuilder().build()).withCount(2).withMessage("foo2").build();
String aggregatedKey = EventUtils.getAggregatedAndLocalKeyByReason(event1).getRight();
EventLogger eventLogger = new EventLogger(100, EventUtils::getEventKey);
MutablePair<CoreV1Event, V1Patch> result1 = eventLogger.observe(event1, aggregatedKey);
assertEquals(event1, result1.getLeft());
assertNull(result1.getRight());
MutablePair<CoreV1Event, V1Patch> result2 = eventLogger.observe(event2, aggregatedKey);
assertEquals(event2, result2.getLeft());
assertNotNull(result2.getRight());
}
Aggregations