Search in sources :

Example 36 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta in project twister2 by DSC-SPIDAL.

the class JobMasterRequestObject method createStatefulSetObject.

/**
 * create StatefulSet object for a job
 */
public static V1StatefulSet createStatefulSetObject() {
    if (config == null) {
        LOG.severe("JobMasterRequestObject.init method has not been called.");
        return null;
    }
    V1StatefulSet statefulSet = new V1StatefulSet();
    String statefulSetName = KubernetesUtils.createJobMasterStatefulSetName(jobID);
    // set labels for the jm stateful set
    HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
    // job master statefulset
    labels.put("t2-mss", jobID);
    // construct metadata and set for jobID setting
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(statefulSetName);
    meta.setLabels(labels);
    statefulSet.setMetadata(meta);
    // construct JobSpec and set
    V1StatefulSetSpec setSpec = new V1StatefulSetSpec();
    setSpec.serviceName(KubernetesUtils.createJobMasterServiceName(jobID));
    setSpec.setReplicas(1);
    // add selector for the job
    V1LabelSelector selector = new V1LabelSelector();
    selector.putMatchLabelsItem("t2-mp", jobID);
    setSpec.setSelector(selector);
    // construct the pod template
    V1PodTemplateSpec template = constructPodTemplate();
    setSpec.setTemplate(template);
    statefulSet.setSpec(setSpec);
    return statefulSet;
}
Also used : V1StatefulSet(io.kubernetes.client.openapi.models.V1StatefulSet) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1StatefulSetSpec(io.kubernetes.client.openapi.models.V1StatefulSetSpec) IntOrString(io.kubernetes.client.custom.IntOrString) V1PodTemplateSpec(io.kubernetes.client.openapi.models.V1PodTemplateSpec) V1LabelSelector(io.kubernetes.client.openapi.models.V1LabelSelector)

Example 37 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta in project twister2 by DSC-SPIDAL.

the class RequestObjectBuilder method createPersistentVolumeObject.

/**
 * we initially used this method to create PersistentVolumes
 * we no longer use this method
 * it is just here in case we may need it for some reason at one point
 */
public static V1PersistentVolume createPersistentVolumeObject(String pvName) {
    V1PersistentVolume pv = new V1PersistentVolume();
    pv.setApiVersion("v1");
    // set pv name
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(pvName);
    pv.setMetadata(meta);
    // double volumeSize = SchedulerContext.persistentVolumeTotal(config);
    V1PersistentVolumeSpec pvSpec = new V1PersistentVolumeSpec();
    HashMap<String, Quantity> capacity = new HashMap<>();
    // capacity.put("storage", new Quantity(volumeSize + "Gi"));
    pvSpec.setCapacity(capacity);
    String storageClass = KubernetesContext.persistentStorageClass(config);
    String accessMode = KubernetesContext.storageAccessMode(config);
    // String reclaimPolicy = KubernetesContext.storageReclaimPolicy(config);
    pvSpec.setStorageClassName(storageClass);
    pvSpec.setAccessModes(Arrays.asList(accessMode));
    // pvSpec.setPersistentVolumeReclaimPolicy(reclaimPolicy);
    // pvSpec.setMountOptions(Arrays.asList("hard", "nfsvers=4.1"));
    V1NFSVolumeSource nfsVolumeSource = new V1NFSVolumeSource();
    nfsVolumeSource.setServer(SchedulerContext.nfsServerAddress(config));
    nfsVolumeSource.setPath(SchedulerContext.nfsServerPath(config));
    pvSpec.setNfs(nfsVolumeSource);
    pv.setSpec(pvSpec);
    return pv;
}
Also used : V1PersistentVolumeSpec(io.kubernetes.client.openapi.models.V1PersistentVolumeSpec) V1PersistentVolume(io.kubernetes.client.openapi.models.V1PersistentVolume) HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) Quantity(io.kubernetes.client.custom.Quantity) V1NFSVolumeSource(io.kubernetes.client.openapi.models.V1NFSVolumeSource)

Example 38 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta in project twister2 by DSC-SPIDAL.

the class RequestObjectBuilder method createNodePortServiceObject.

/**
 * create service for NodePort
 * @return
 */
public static V1Service createNodePortServiceObject() {
    String serviceName = KubernetesUtils.createServiceName(jobID);
    int workerPort = KubernetesContext.workerBasePort(config);
    int nodePort = KubernetesContext.serviceNodePort(config);
    String protocol = KubernetesContext.workerTransportProtocol(config);
    V1Service service = new V1Service();
    service.setKind("Service");
    service.setApiVersion("v1");
    // set labels for the worker services
    HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
    // construct and set metadata
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(serviceName);
    meta.setLabels(labels);
    service.setMetadata(meta);
    // construct and set service spec
    V1ServiceSpec serviceSpec = new V1ServiceSpec();
    // ClusterIP needs to be None for headless service
    serviceSpec.setType("NodePort");
    // set selector
    HashMap<String, String> selectors = new HashMap<String, String>();
    selectors.put("t2-wp", jobID);
    serviceSpec.setSelector(selectors);
    ArrayList<V1ServicePort> ports = new ArrayList<V1ServicePort>();
    V1ServicePort servicePort = new V1ServicePort();
    servicePort.setPort(workerPort);
    servicePort.setProtocol(protocol);
    // servicePort.setTargetPort(new IntOrString("port11"));
    if (nodePort != 0) {
        servicePort.nodePort(nodePort);
    }
    ports.add(servicePort);
    serviceSpec.setPorts(ports);
    service.setSpec(serviceSpec);
    return service;
}
Also used : V1ServicePort(io.kubernetes.client.openapi.models.V1ServicePort) HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1ServiceSpec(io.kubernetes.client.openapi.models.V1ServiceSpec) ArrayList(java.util.ArrayList) V1Service(io.kubernetes.client.openapi.models.V1Service)

Example 39 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 40 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta in project pravega by pravega.

the class AbstractService method authSecret.

private V1Secret authSecret() {
    Map<String, String> dataMap = new HashMap<>();
    dataMap.put("password.txt", "YWRtaW46MzUzMDMwMzAzYTM4MzYzNTM0MzE2MTYxNjQ2NDMyMzE2MTM4MzkzMjM4NjQzNzYxMzgzMTMxMzQzOTYxMzA2MTM4NjQ2NDM3MzQ2MjM2NjU2MjM0NjIzMTMwMzgzNTYzNjIzMDMyMzE2NjY2NjQzNzY0NjMzMjM1NjMzMDM0MzA2MzM0NjE2MjY1M2E2MTY1MzEzNDM4MzkzNDM5MzQzMzMyMzczOTMyMzgzNzMyNjU2MTYxNjQ2NjMyNjEzNDM5NjQzMzY2NjM2MTY0MzkzNDY2NjU2MjY1NjE2NTY0MzA2NDYxMzMzNDM2NjIzNzMxMzE2MzM5MzIzOTM1MzQzMzM1NjI2MzY2NjY2NTY1MzUzNjMzNjM2NjM1NjEzNzM0MzQ2MTY2MzczMzYxMzEzMTMxNjYzMDM4MzAzNjM1MzkzMDM0MzQ2NjM0Mzc2NDMyMzYzOTM5MzA2NDM5Mzk2NTM4NjUzMTYyMzMzNDM4MzU2NDY1MzE2MzMxMzgzMjYzMzMzMTY2NjQ2MTMxOiosUkVBRF9VUERBVEUKdGVzdHJlYWQ6MzUzMDMwMzAzYTYxMzM2MTM2NjYzOTMwMzg2NjMxMzg2MjMxMzIzOTY1NjMzMTM5NjMzNjMyNjM2MzMxMzYzNzM5MzQ2MTY1NjUzNzYzNjQzOTYzNjUzNjYzMzMzNDMwNjIzNjMxMzM2NjM0NjIzNDMxNjIzNTMxNjQzNTY0MzY2NDY1NjY2MzYyM2E2NTYzNjYzNzY1NjE2MjM4NjYzMzY2NjQzMDMzMzI2NjMwNjQ2NDM1NjQzOTYyMzczNjM3Mzg2NTYyMzY2MzY2NjUzMDM4MzgzNDYxMzAzMDM2NjMzODMzNjUzMjYxMzc2MTYzMzIzODMyNjMzNDMzMzc2NjMyNjIzNTY2NjMzNjMyMzc2NDYyNjUzODM4MzEzMjM5MzAzNzM2MzgzOTM1MzAzMjM2NjE2NjYzMzczNzMwMzk2NjMwMzAzNDM4MzMzMDMxNjQzOTYyMzk2NTM5NjMzMjY1NjQzODM4MzY2MTYxMzAzNjMxMzU2MTM1NjIzNDMxMzIzOTM1NjUzMDY1OiosUkVBRAoK");
    return new V1SecretBuilder().withStringData(dataMap).withApiVersion("v1").withKind("Secret").withMetadata(new V1ObjectMeta().name(SECRET_NAME_USED_FOR_AUTH)).withType("Opaque").withStringData(dataMap).build();
}
Also used : V1SecretBuilder(io.kubernetes.client.openapi.models.V1SecretBuilder) HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta)

Aggregations

V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)78 Test (org.junit.Test)49 V1Pod (io.kubernetes.client.openapi.models.V1Pod)37 HashMap (java.util.HashMap)14 ApiException (io.kubernetes.client.openapi.ApiException)11 V1PodList (io.kubernetes.client.openapi.models.V1PodList)11 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)10 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)8 V1Container (io.kubernetes.client.openapi.models.V1Container)7 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 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)6 V1Patch (io.kubernetes.client.custom.V1Patch)5 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)5 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)5 V1Service (io.kubernetes.client.openapi.models.V1Service)5 V1ServiceSpec (io.kubernetes.client.openapi.models.V1ServiceSpec)5 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)5