Search in sources :

Example 36 with V1ObjectMeta

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

the class KubernetesUtils method createServiceObject.

public static V1Service createServiceObject(String serviceName, String serviceLabel, int port, int targetPort) {
    V1Service service = new V1Service();
    service.setKind("Service");
    service.setApiVersion("v1");
    // construct and set metadata
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(serviceName);
    service.setMetadata(meta);
    // construct and set service spec
    V1ServiceSpec serviceSpec = new V1ServiceSpec();
    // ClusterIP needs to be None for headless service
    serviceSpec.setClusterIP("None");
    // set selector
    HashMap<String, String> selectors = new HashMap<String, String>();
    selectors.put("app", serviceLabel);
    serviceSpec.setSelector(selectors);
    ArrayList<V1ServicePort> ports = new ArrayList<V1ServicePort>();
    V1ServicePort servicePort = new V1ServicePort();
    servicePort.setPort(port);
    servicePort.setTargetPort(new IntOrString(targetPort));
    servicePort.setProtocol("TCP");
    ports.add(servicePort);
    serviceSpec.setPorts(ports);
    service.setSpec(serviceSpec);
    return service;
}
Also used : V1ServicePort(io.kubernetes.client.models.V1ServicePort) HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) IntOrString(io.kubernetes.client.custom.IntOrString) V1ServiceSpec(io.kubernetes.client.models.V1ServiceSpec) ArrayList(java.util.ArrayList) V1Service(io.kubernetes.client.models.V1Service) IntOrString(io.kubernetes.client.custom.IntOrString)

Aggregations

V1ObjectMeta (io.kubernetes.client.models.V1ObjectMeta)36 Test (org.junit.Test)12 V1Service (io.kubernetes.client.models.V1Service)10 ApiException (io.kubernetes.client.ApiException)7 CallBuilderFactory (oracle.kubernetes.operator.helpers.CallBuilderFactory)6 V1beta1Ingress (io.kubernetes.client.models.V1beta1Ingress)5 DomainPresenceInfo (oracle.kubernetes.operator.helpers.DomainPresenceInfo)4 IntOrString (io.kubernetes.client.custom.IntOrString)3 V1PodTemplateSpec (io.kubernetes.client.models.V1PodTemplateSpec)3 HashMap (java.util.HashMap)3 Domain (oracle.kubernetes.weblogic.domain.v1.Domain)3 DomainSpec (oracle.kubernetes.weblogic.domain.v1.DomainSpec)3 V1LabelSelector (io.kubernetes.client.models.V1LabelSelector)2 V1Namespace (io.kubernetes.client.models.V1Namespace)2 V1Secret (io.kubernetes.client.models.V1Secret)2 V1ServicePort (io.kubernetes.client.models.V1ServicePort)2 V1ServiceSpec (io.kubernetes.client.models.V1ServiceSpec)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 ServerKubernetesObjects (oracle.kubernetes.operator.helpers.ServerKubernetesObjects)2