Java Code Examples for io.fabric8.kubernetes.api.model.ServicePort#getProtocol()
The following examples show how to use
io.fabric8.kubernetes.api.model.ServicePort#getProtocol() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: URLFromOpenshiftRouteImpl.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Override public String getURL(Service service, String portName, String namespace, KubernetesClient client) { String serviceName = service.getMetadata().getName(); ServicePort port = URLFromServiceUtil.getServicePortByName(service, portName); if(port != null && port.getName() != null && isOpenShift(client)) { try { String serviceProtocol = port.getProtocol(); OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class); Route route = openShiftClient.routes().inNamespace(namespace).withName(service.getMetadata().getName()).get(); if (route != null) { return (serviceProtocol + "://" + route.getSpec().getHost()).toLowerCase(Locale.ROOT); } } catch (KubernetesClientException e) { if(e.getCode() == HttpURLConnection.HTTP_FORBIDDEN) { logger.warn("Could not lookup route:" + serviceName + " in namespace:"+ namespace +", due to: " + e.getMessage()); } } } return null; }
Example 2
Source File: DefaultServiceEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private String ensureProtocol(ServicePort port) { String protocol = port.getProtocol(); if (protocol != null && !protocol.isEmpty()) { port.setProtocol("TCP"); return "TCP"; } return protocol; }
Example 3
Source File: KubeDiscovery.java From vxms with Apache License 2.0 | 5 votes |
private static String resolveServiceWithPortName( JsonObject env, Field serviceNameField, String clusterIP, List<ServicePort> ports) { String hostString = null; final PortName portNameAnnotation = serviceNameField.getAnnotation(PortName.class); final String portName = resolveProperty(env, portNameAnnotation.value()); final Optional<ServicePort> portMatch = findPortByName(ports, portName); if (portMatch.isPresent()) { final ServicePort port = portMatch.get(); final String protocol = port.getProtocol(); // TODO check out how http can get resolved hostString = buildServiceHostString(clusterIP, port, null); } return hostString; }
Example 4
Source File: K8sNodePortHandler.java From onos with Apache License 2.0 | 5 votes |
private void setExtToIngrRules(K8sNode k8sNode, ServicePort servicePort, boolean install) { String protocol = servicePort.getProtocol(); int nodePort = servicePort.getNodePort(); DeviceId deviceId = k8sNode.extBridge(); TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder() .matchEthType(Ethernet.TYPE_IPV4) .matchIPDst(IpPrefix.valueOf(k8sNode.extBridgeIp(), HOST_CIDR)); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder() .setOutput(PortNumber.LOCAL); if (TCP.equals(protocol)) { sBuilder.matchIPProtocol(IPv4.PROTOCOL_TCP) .matchTcpSrc(TpPort.tpPort(nodePort)); } else if (UDP.equals(protocol)) { sBuilder.matchIPProtocol(IPv4.PROTOCOL_UDP) .matchUdpSrc(TpPort.tpPort(nodePort)); } k8sFlowRuleService.setRule( appId, deviceId, sBuilder.build(), tBuilder.build(), PRIORITY_NODE_PORT_RULE, EXT_ENTRY_TABLE, install); }
Example 5
Source File: K8sNodePortHandler.java From onos with Apache License 2.0 | 4 votes |
private void setNodeToServiceRules(K8sNode k8sNode, String clusterIp, ServicePort servicePort, boolean install) { String protocol = servicePort.getProtocol(); int nodePort = servicePort.getNodePort(); int svcPort = servicePort.getPort(); DeviceId deviceId = k8sNode.extBridge(); TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder() .matchEthType(Ethernet.TYPE_IPV4) .matchIPDst(IpPrefix.valueOf(k8sNode.extBridgeIp(), HOST_CIDR)); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder() .setIpDst(IpAddress.valueOf(clusterIp)); if (TCP.equals(protocol)) { sBuilder.matchIPProtocol(IPv4.PROTOCOL_TCP) .matchTcpDst(TpPort.tpPort(nodePort)); tBuilder.setTcpDst(TpPort.tpPort(svcPort)); } else if (UDP.equals(protocol)) { sBuilder.matchIPProtocol(IPv4.PROTOCOL_UDP) .matchUdpDst(TpPort.tpPort(nodePort)); tBuilder.setUdpDst(TpPort.tpPort(svcPort)); } String podCidr = k8sNetworkService.network(k8sNode.hostname()).cidr(); String prefix = NODE_IP_PREFIX + "." + podCidr.split("\\.")[2]; ExtensionTreatment loadTreatment = buildLoadExtension( deviceService.getDevice(deviceId), B_CLASS, SRC, prefix); tBuilder.extension(loadTreatment, deviceId) .setOutput(k8sNode.extToIntgPatchPortNum()); k8sFlowRuleService.setRule( appId, k8sNode.extBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_NODE_PORT_RULE, EXT_ENTRY_TABLE, install); }
Example 6
Source File: K8sNodePortHandler.java From onos with Apache License 2.0 | 4 votes |
private void setServiceToNodeLocalRules(K8sNode k8sNode, String clusterIp, ServicePort servicePort, boolean install) { String protocol = servicePort.getProtocol(); int nodePort = servicePort.getNodePort(); int svcPort = servicePort.getPort(); DeviceId deviceId = k8sNode.extBridge(); String extBridgeIp = k8sNode.extBridgeIp().toString(); String extBridgePrefix = getBclassIpPrefixFromCidr(extBridgeIp); String podCidr = k8sNetworkService.network(k8sNode.hostname()).cidr(); String nodePrefix = NODE_IP_PREFIX + "." + podCidr.split("\\.")[2]; if (extBridgePrefix == null) { return; } String shiftedIp = unshiftIpDomain(extBridgeIp, extBridgePrefix, nodePrefix); TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder() .matchEthType(Ethernet.TYPE_IPV4) .matchInPort(k8sNode.extToIntgPatchPortNum()) .matchIPSrc(IpPrefix.valueOf(IpAddress.valueOf(clusterIp), HOST_CIDR)) .matchIPDst(IpPrefix.valueOf(IpAddress.valueOf(shiftedIp), HOST_CIDR)); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder() .setIpSrc(k8sNode.extBridgeIp()) .setEthSrc(k8sNode.extBridgeMac()); if (TCP.equals(protocol)) { sBuilder.matchIPProtocol(IPv4.PROTOCOL_TCP) .matchTcpSrc(TpPort.tpPort(svcPort)); tBuilder.setTcpSrc(TpPort.tpPort(nodePort)); } else if (UDP.equals(protocol)) { sBuilder.matchIPProtocol(IPv4.PROTOCOL_UDP) .matchUdpSrc(TpPort.tpPort(svcPort)); tBuilder.setUdpSrc(TpPort.tpPort(nodePort)); } String gatewayIp = k8sNode.extGatewayIp().toString(); String gatewayPrefix = getBclassIpPrefixFromCidr(gatewayIp); if (gatewayPrefix == null) { return; } ExtensionTreatment loadTreatment = buildLoadExtension( deviceService.getDevice(deviceId), B_CLASS, DST, gatewayPrefix); tBuilder.extension(loadTreatment, deviceId) .setOutput(PortNumber.LOCAL); k8sFlowRuleService.setRule( appId, deviceId, sBuilder.build(), tBuilder.build(), PRIORITY_NODE_PORT_RULE, EXT_ENTRY_TABLE, install); }
Example 7
Source File: K8sNodePortHandler.java From onos with Apache License 2.0 | 4 votes |
private void setServiceToNodeRemoteRules(K8sNode k8sNode, String clusterIp, ServicePort servicePort, boolean install) { String protocol = servicePort.getProtocol(); int nodePort = servicePort.getNodePort(); int svcPort = servicePort.getPort(); DeviceId deviceId = k8sNode.extBridge(); TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder() .matchEthType(Ethernet.TYPE_IPV4) .matchInPort(k8sNode.extToIntgPatchPortNum()) .matchIPSrc(IpPrefix.valueOf(IpAddress.valueOf(clusterIp), HOST_CIDR)); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder() .setIpSrc(k8sNode.extBridgeIp()) .setEthSrc(k8sNode.extBridgeMac()); if (TCP.equals(protocol)) { sBuilder.matchIPProtocol(IPv4.PROTOCOL_TCP) .matchTcpSrc(TpPort.tpPort(svcPort)); tBuilder.setTcpSrc(TpPort.tpPort(nodePort)); } else if (UDP.equals(protocol)) { sBuilder.matchIPProtocol(IPv4.PROTOCOL_UDP) .matchUdpSrc(TpPort.tpPort(svcPort)); tBuilder.setUdpSrc(TpPort.tpPort(nodePort)); } String gatewayIp = k8sNode.extGatewayIp().toString(); String prefix = getBclassIpPrefixFromCidr(gatewayIp); if (prefix == null) { return; } ExtensionTreatment loadTreatment = buildLoadExtension( deviceService.getDevice(deviceId), B_CLASS, DST, prefix); tBuilder.extension(loadTreatment, deviceId) .setOutput(k8sNode.extBridgePortNum()); k8sFlowRuleService.setRule( appId, deviceId, sBuilder.build(), tBuilder.build(), PRIORITY_NODE_PORT_REMOTE_RULE, EXT_ENTRY_TABLE, install); }