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;
}
Aggregations