public static ServicePort getServicePortByName(Service service, String portName) { if (portName.isEmpty()) { return service.getSpec().getPorts().iterator().next(); } for (ServicePort servicePort : service.getSpec().getPorts()) { if (Objects.equals(servicePort.getName(), portName)) { return servicePort; } } return null; } }
@Override public String getURL(Service service, String portName, String namespace, KubernetesClient client) { String serviceHost = URLFromServiceUtil.resolveHostFromEnvVarOrSystemProperty(service.getMetadata().getName()); String servicePort = URLFromServiceUtil.resolvePortFromEnvVarOrSystemProperty(service.getMetadata().getName(), ""); String serviceProtocol = URLFromServiceUtil.resolveProtocolFromEnvVarOrSystemProperty(service.getSpec().getPorts().iterator().next().getProtocol(), ""); if(!serviceHost.isEmpty() && !servicePort.isEmpty() && !serviceProtocol.isEmpty()) { return serviceProtocol + "://" + serviceHost + ":" + servicePort; } else { String answer = URLFromServiceUtil.getOrCreateAnnotations(service).get(ANNOTATION_EXPOSE_URL); if(answer != null && !answer.isEmpty()) { return answer; } } return null; }
public String getURL(String portName) { String clusterIP = getMandatory().getSpec().getClusterIP(); if("None".equals(clusterIP)) { throw new IllegalStateException("Service: " + getMandatory().getMetadata().getName() + " in namespace " + namespace + " is head-less. Search for endpoints instead"); } return getUrlHelper(portName); }
@Override public Service replace(Service item) { try { Service old = getMandatory(); return super.replace(new ServiceBuilder(item) .editSpec() .withClusterIP(old.getSpec().getClusterIP()) .endSpec() .build()); } catch (Exception e) { throw KubernetesClientException.launderThrowable(forOperationType("replace"), e); } }
@Override public Service patch(Service item) { try { Service old = getMandatory(); return super.patch(new ServiceBuilder(item) .editSpec() .withClusterIP(old.getSpec().getClusterIP()) .endSpec() .build()); } catch (Exception e) { throw KubernetesClientException.launderThrowable(forOperationType("patch"), e); } }
private List<ServicePort> tryToFindAtLeastOnePort(List<ServicePort> ports, Service defaultService) { List<ServicePort> defaultPorts = defaultService.getSpec().getPorts(); if (!ports.isEmpty() || defaultPorts == null || defaultPorts.isEmpty()) { return ports; } return Collections.singletonList(defaultPorts.get(0)); }
private List<ServicePort> tryToFindAtLeastOnePort(List<ServicePort> ports, Service defaultService) { List<ServicePort> defaultPorts = defaultService.getSpec().getPorts(); if (!ports.isEmpty() || defaultPorts == null || defaultPorts.isEmpty()) { return ports; } return Collections.singletonList(defaultPorts.get(0)); }
private static ServicePort findServicePortByName(Service service, String portName) { if (StringUtils.isBlank(portName)) { return service.getSpec().getPorts().iterator().next(); } for (ServicePort servicePort : service.getSpec().getPorts()) { if (Objects.equal(servicePort.getName(), portName)) { return servicePort; } } return null; }
private static String getHostString( Service serviceEntry, JsonObject env, Field serviceNameField) { final String clusterIP = serviceEntry.getSpec().getClusterIP(); final List<ServicePort> ports = serviceEntry.getSpec().getPorts(); return serviceNameField.isAnnotationPresent(PortName.class) ? resolveServiceWithPortName(env, serviceNameField, clusterIP, ports) : resolveService("", clusterIP, ports); }
public static ServiceSpec getOrCreateSpec(Service entity) { ServiceSpec spec = entity.getSpec(); if (spec == null) { spec = new ServiceSpec(); entity.setSpec(spec); } return spec; }
private static int getPort(Service service, String portName) { List<ServicePort> ports = service.getSpec().getPorts(); for (ServicePort port : ports) { if (port.getName().equals(portName)) { return port.getPort(); } } throw new IllegalArgumentException( "Unable to find port " + portName + " for service " + service.getMetadata().getName()); }
@Override public Service transform(Service service, Deployment apolloDeployment, io.logz.apollo.models.Service apolloService, Environment apolloEnvironment, DeployableVersion apolloDeployableVersion) { service.getSpec().getPorts().forEach(servicePort -> { if (servicePort.getNodePort() != null) { servicePort.setNodePort(servicePort.getNodePort() + apolloEnvironment.getServicePortCoefficient()); } }); return service; } }
public Endpoint getEndpoint(String serviceName, String namespace, String port) { Service service = client.services().inNamespace(namespace).withName(serviceName).get(); return new Endpoint(service.getSpec().getClusterIP(), getPort(service, port)); }
public ServiceBuilder(ServiceFluent<?> fluent,Service instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); fluent.withSpec(instance.getSpec()); fluent.withStatus(instance.getStatus()); this.validationEnabled = validationEnabled; } public ServiceBuilder(Service instance){
public ServiceBuilder(Service instance,Boolean validationEnabled){ this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); this.validationEnabled = validationEnabled; }
public ServiceFluentImpl(Service instance){ this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); }
@Override public Service patch(Service item) { try { Service old = getMandatory(); return super.patch(new ServiceBuilder(item) .editSpec() .withClusterIP(old.getSpec().getClusterIP()) .endSpec() .build()); } catch (Exception e) { throw KubernetesClientException.launderThrowable(e); } }
public ServiceBuilder( ServiceFluent<?> fluent , Service instance ){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); fluent.withSpec(instance.getSpec()); fluent.withStatus(instance.getStatus()); } public ServiceBuilder( Service instance ){
public ServiceBuilder( ServiceFluent<?> fluent , Service instance ){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); fluent.withSpec(instance.getSpec()); fluent.withStatus(instance.getStatus()); } public ServiceBuilder( Service instance ){
@Override public Service replace(Service item) { try { Service old = getMandatory(); return super.replace(new ServiceBuilder(item) .editSpec() .withClusterIP(old.getSpec().getClusterIP()) .endSpec() .build()); } catch (Exception e) { throw KubernetesClientException.launderThrowable(e); } }