Refine search
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; } }
public static ServiceSpec getOrCreateSpec(Service entity) { ServiceSpec spec = entity.getSpec(); if (spec == null) { spec = new ServiceSpec(); entity.setSpec(spec); } return spec; }
public ServiceSpecFluentImpl(ServiceSpec instance){ this.withClusterIP(instance.getClusterIP()); this.withDeprecatedPublicIPs(instance.getDeprecatedPublicIPs()); this.withExternalIPs(instance.getExternalIPs()); this.withLoadBalancerIP(instance.getLoadBalancerIP()); this.withLoadBalancerSourceRanges(instance.getLoadBalancerSourceRanges()); this.withPortalIP(instance.getPortalIP()); this.withPorts(instance.getPorts()); this.withSelector(instance.getSelector()); this.withSessionAffinity(instance.getSessionAffinity()); this.withType(instance.getType()); }
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 ServiceSpecBuilder( ServiceSpecFluent<?> fluent , ServiceSpec instance ){ this.fluent = fluent; fluent.withDeprecatedPublicIPs(instance.getDeprecatedPublicIPs()); fluent.withPortalIP(instance.getPortalIP()); fluent.withPorts(instance.getPorts()); fluent.withSelector(instance.getSelector()); fluent.withSessionAffinity(instance.getSessionAffinity()); fluent.withType(instance.getType()); } public ServiceSpecBuilder( ServiceSpec instance ){
private Service getSimpleService() { ObjectMeta metadata = new ObjectMeta(); metadata.setName("my-service"); metadata.setUid("uuid-2"); metadata.setNamespace("my-project"); ServiceSpec spec = new ServiceSpec(); ServicePort port = new ServicePort(); port.setTargetPort(new IntOrString(8080)); port.setPort(1524); spec.setPorts(Collections.singletonList(port)); Service service = new Service(); service.setMetadata(metadata); service.setSpec(spec); return service; }
@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; }
for (Service service : serviceList) { String serviceName = service.getMetadata().getName(); String namespace = service.getMetadata().getNamespace(); Map<String, String> labelsMap = service.getMetadata().getLabels(); String labels = (labelsMap != null) ? labelsMap.toString() : ""; ServiceSpec serviceSpec = service.getSpec(); String serviceType = serviceSpec.getType(); addExternalNameEndpoint(serviceName, serviceSpec.getExternalName(), namespace, labels, endpointList); for (ServicePort servicePort : serviceSpec.getPorts()) { String protocol = servicePort.getName(); if (APIMgtConstants.HTTP.equals(protocol) || APIMgtConstants.HTTPS.equals(protocol)) { addClusterIPEndpoint(serviceName, serviceSpec.getClusterIP(), port, protocol, namespace, labels, endpointList); addExternalIPEndpoint(serviceName, serviceSpec.getExternalIPs(), port, protocol, namespace, labels, endpointList); } else if (log.isDebugEnabled()) {
if (apps != null) { for (Service app : apps) { String appIdToDelete = app.getMetadata().getName(); logger.debug(String.format("Deleting Resources for: %s", appIdToDelete)); if (svc != null && "LoadBalancer".equals(svc.getSpec().getType())) { int tries = 0; int maxWait = properties.getMinutesToWaitForLoadBalancer() * 6; // we check 6 times per minute while (tries++ < maxWait) { if (svc.getStatus() != null && svc.getStatus().getLoadBalancer() != null && svc.getStatus().getLoadBalancer().getIngress() != null && svc.getStatus() .getLoadBalancer().getIngress().isEmpty()) {
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); }
return null; ServiceSpec serviceSpec = service.getSpec(); if (serviceSpec == null) { return null; String namespace = KubernetesHelper.getNamespace(service); String serviceName = getName(service); String qualifiedServiceName = namespace + ":" + serviceName; List<ServicePort> ports = serviceSpec.getPorts(); for (ServicePort servicePort : ports) { IntOrString targetPort = servicePort.getTargetPort(); Integer portNumber = KubernetesHelper.intOrStringToInteger(targetPort, qualifiedServiceName); if (portNumber != null) { List<Pod> podsForService = KubernetesHelper.getPodsForService(service, pods);
@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); } }
String serviceStatus = null; boolean result = false; String sid = getName(s); String namespace = session.getNamespace(); Endpoints endpoints = kubernetesClient.endpoints().inNamespace(namespace).withName(sid).get(); ServiceSpec spec = s.getSpec(); if (endpoints != null && spec != null) { List<EndpointSubset> subsets = endpoints.getSubsets(); List<ServicePort> ports = spec.getPorts(); for (ServicePort port : ports) { Integer portNumber = port.getPort();
private DeployableScalableResource<DeploymentConfig, DoneableDeploymentConfig> getDeploymentConfigResource(Service service) { if (service != null) { String prjName = service.getMetadata().getNamespace(); Map<String, String> selector = service.getSpec().getSelector(); String dcName = selector.get("deploymentconfig"); if (dcName == null) { dcName = selector.get("deploymentConfig"); } if (dcName != null) { return delegate.deploymentConfigs().inNamespace(prjName).withName(dcName); } } return null; }
public ServiceSpecBuilder( ServiceSpecFluent<?> fluent , ServiceSpec instance ){ this.fluent = fluent; fluent.withCreateExternalLoadBalancer(instance.getCreateExternalLoadBalancer()); fluent.withPortalIP(instance.getPortalIP()); fluent.withPorts(instance.getPorts()); fluent.withPublicIPs(instance.getPublicIPs()); fluent.withSelector(instance.getSelector()); fluent.withSessionAffinity(instance.getSessionAffinity()); fluent.withType(instance.getType()); } public ServiceSpecBuilder( ServiceSpec instance ){
public ServiceInstance(Service service) { this.service = service; this.id = getName(service); ServiceSpec spec = KubernetesHelper.getOrCreateSpec(service); List<ServicePort> ports = spec.getPorts(); if (spec.getPortalIP().equals(HEADLESS_PORTAL_IP)) { //do nothing service is headless } else if (ports != null && !ports.isEmpty()) { for (ServicePort servicePort : ports) { servicePorts.add(toNamedServicePort(id, servicePort)); } } else { throw new IllegalArgumentException("Service: " + id + " doesn't have a valid port configuration."); } this.selector = KubernetesHelper.getSelector(service); Objects.notNull(this.selector, "No selector for service " + id); if (selector.isEmpty()) { throw new IllegalArgumentException("Empty selector for service " + id); } this.filter = KubernetesHelper.createPodFilter(selector); // TODO should we use some service metadata to choose the load balancer? this.loadBalancer = new RoundRobinLoadBalancer(); }
public String updateService(@NotNull String id, Service entity) throws Exception { // lets set the IP ServiceSpec spec = entity.getSpec(); if (spec == null) { spec = new ServiceSpec(); entity.setSpec(spec); } if (!HEADLESS_PORTAL_IP.equals(spec.getPortalIP())) { spec.setPortalIP(getHostName()); } // lets ensure there's a default namespace set String namespace = KubernetesHelper.getNamespace(entity); if (Strings.isBlank(namespace)) { getOrCreateMetadata(entity).setNamespace(DEFAULT_NAMESPACE); } model.updateService(id, entity); return null; }
for (ServicePort port : service.getSpec().getPorts()) { for (String portName : exposeSpec.getLoadBalancerPorts()) { if (port.getName().equals(portName)) { .editOrNewSpec() .withPorts(servicePorts) .withSelector(service.getSpec().getSelector()) .withLoadBalancerSourceRanges(exposeSpec.getLoadBalancerSourceRanges() != null ? exposeSpec.getLoadBalancerSourceRanges() : Collections.emptyList()) .withType("LoadBalancer")
case loadbalancer: Service service = ensureExternalServiceExists(addressSpace, endpointInfo.endpointSpec, exposeSpec); if (service != null && service.getSpec().getPorts().size() > 0) { statusBuilder.withExternalHost(service.getSpec().getLoadBalancerIP()); statusBuilder.withExternalPorts(endpointInfo.endpointStatus.getServicePorts());