io.kubernetes.client.models.V1ServicePort Java Examples

The following examples show how to use io.kubernetes.client.models.V1ServicePort. 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: KubernetesNatManagerTest.java    From besu with Apache License 2.0 5 votes vote down vote up
@Before
public void initialize() throws IOException {
  final V1ServiceStatus v1ServiceStatus =
      new V1ServiceStatus()
          .loadBalancer(
              new V1LoadBalancerStatusBuilder()
                  .addToIngress(
                      new V1LoadBalancerIngressBuilder().withIp(detectedAdvertisedHost).build())
                  .build());
  when(v1Service.getStatus()).thenReturn(v1ServiceStatus);
  when(v1Service.getSpec())
      .thenReturn(
          new V1ServiceSpec()
              .ports(
                  Arrays.asList(
                      new V1ServicePort()
                          .name(NatServiceType.JSON_RPC.getValue())
                          .port(rpcHttpPort)
                          .targetPort(new IntOrString(rpcHttpPort)),
                      new V1ServicePort()
                          .name(NatServiceType.RLPX.getValue())
                          .port(p2pPort)
                          .targetPort(new IntOrString(p2pPort)),
                      new V1ServicePort()
                          .name(NatServiceType.DISCOVERY.getValue())
                          .port(p2pPort)
                          .targetPort(new IntOrString(p2pPort)))));
  when(v1Service.getMetadata()).thenReturn(new V1ObjectMeta().name(DEFAULT_BESU_POD_NAME_FILTER));
  natManager = new KubernetesNatManager(DEFAULT_BESU_POD_NAME_FILTER);
  try {
    natManager.start();
  } catch (Exception ignored) {
    System.err.println("Ignored missing Kube config file in testing context.");
  }
  natManager.updateUsingBesuService(v1Service);
}
 
Example #2
Source File: CloudOrchestrator.java    From HolandaCatalinaFw with Apache License 2.0 5 votes vote down vote up
@Override
protected void onServiceDiscovery(V1Service service) {
    Log.d(System.getProperty(SystemProperties.Cloud.LOG_TAG), "Kubernetes service discovery: %s", service.getMetadata().getUid());
    ServiceEndPoint serviceEndPoint = new ServiceEndPoint();
    serviceEndPoint.setId(new UUID(service.getMetadata().getNamespace().hashCode(), service.getMetadata().getName().hashCode()));
    serviceEndPoint.setGatewayAddress(service.getMetadata().getName());
    for(V1ServicePort port : service.getSpec().getPorts()) {
        if(port.getName().equals(SystemProperties.get(SystemProperties.Cloud.Orchestrator.Kubernetes.SERVICE_PORT_NAME))) {
            serviceEndPoint.setGatewayPort(port.getPort());
            break;
        }
    }
    registerConsumer(serviceEndPoint);
}
 
Example #3
Source File: KubernetesRuntime.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
V1Service createService() {
    final String jobName = createJobName(instanceConfig.getFunctionDetails());

    final V1Service service = new V1Service();

    // setup stateful set metadata
    final V1ObjectMeta objectMeta = new V1ObjectMeta();
    objectMeta.name(jobName);
    objectMeta.setLabels(getLabels(instanceConfig.getFunctionDetails()));
    // we don't technically need to set this, but it is useful for testing
    objectMeta.setNamespace(jobNamespace);
    service.metadata(objectMeta);

    // create the stateful set spec
    final V1ServiceSpec serviceSpec = new V1ServiceSpec();

    serviceSpec.clusterIP("None");

    final V1ServicePort servicePort = new V1ServicePort();
    servicePort.name("grpc").port(grpcPort).protocol("TCP");
    serviceSpec.addPortsItem(servicePort);

    serviceSpec.selector(getLabels(instanceConfig.getFunctionDetails()));

    service.spec(serviceSpec);

    // let the customizer run but ensure it doesn't change the name so we can find it again
    final V1Service overridden = manifestCustomizer.map((customizer) -> customizer.customizeService(instanceConfig.getFunctionDetails(), service)).orElse(service);
    overridden.getMetadata().name(jobName);

    return overridden;
}