Search in sources :

Example 1 with V1ObjectMeta

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;
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1ServiceSpec(io.kubernetes.client.openapi.models.V1ServiceSpec) V1Service(io.kubernetes.client.openapi.models.V1Service)

Example 2 with V1ObjectMeta

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();
}
Also used : V1ConfigMapBuilder(io.kubernetes.client.openapi.models.V1ConfigMapBuilder) HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta)

Example 3 with V1ObjectMeta

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);
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Namespace(io.kubernetes.client.openapi.models.V1Namespace) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) ApiException(io.kubernetes.client.openapi.ApiException) SneakyThrows(lombok.SneakyThrows)

Example 4 with V1ObjectMeta

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;
    }
}
Also used : HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) ApiException(io.kubernetes.client.openapi.ApiException)

Example 5 with V1ObjectMeta

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());
}
Also used : V1EventSourceBuilder(io.kubernetes.client.openapi.models.V1EventSourceBuilder) V1ObjectReferenceBuilder(io.kubernetes.client.openapi.models.V1ObjectReferenceBuilder) EventLogger(io.kubernetes.client.extended.event.legacy.EventLogger) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) EventUtils(io.kubernetes.client.extended.event.legacy.EventUtils) V1Patch(io.kubernetes.client.custom.V1Patch) CoreV1EventBuilder(io.kubernetes.client.openapi.models.CoreV1EventBuilder) CoreV1Event(io.kubernetes.client.openapi.models.CoreV1Event) Test(org.junit.Test)

Aggregations

V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)69 Test (org.junit.Test)49 V1Pod (io.kubernetes.client.openapi.models.V1Pod)37 ApiException (io.kubernetes.client.openapi.ApiException)11 V1PodList (io.kubernetes.client.openapi.models.V1PodList)11 HashMap (java.util.HashMap)9 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)8 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)8 V1Patch (io.kubernetes.client.custom.V1Patch)6 ApiClient (io.kubernetes.client.openapi.ApiClient)6 JSON (io.kubernetes.client.openapi.JSON)6 V1Job (io.kubernetes.client.openapi.models.V1Job)6 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)6 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)5 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)5 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)5 V1Container (io.kubernetes.client.openapi.models.V1Container)4 Watch (io.kubernetes.client.util.Watch)4 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)3 V1Namespace (io.kubernetes.client.openapi.models.V1Namespace)3