io.kubernetes.client.models.V1Service Java Examples

The following examples show how to use io.kubernetes.client.models.V1Service. 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: KubernetesNatManager.java    From besu with Apache License 2.0 5 votes vote down vote up
@Override
protected void doStart() throws NatInitializationException {
  LOG.info("Starting kubernetes NAT manager.");
  try {

    KubeConfig.registerAuthenticator(new GCPAuthenticator());

    LOG.debug("Trying to update information using Kubernetes client SDK.");
    final ApiClient client = ClientBuilder.cluster().build();

    // set the global default api-client to the in-cluster one from above
    Configuration.setDefaultApiClient(client);

    // the CoreV1Api loads default api-client from global configuration.
    final CoreV1Api api = new CoreV1Api();
    // invokes the CoreV1Api client
    final V1Service service =
        api.listServiceForAllNamespaces(null, null, null, null, null, null, null, null, null)
            .getItems().stream()
            .filter(v1Service -> v1Service.getMetadata().getName().contains(besuPodNameFilter))
            .findFirst()
            .orElseThrow(() -> new NatInitializationException("Service not found"));
    updateUsingBesuService(service);
  } catch (Exception e) {
    throw new NatInitializationException(e.getMessage(), e);
  }
}
 
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: KubernetesSpyConsumer.java    From HolandaCatalinaFw with Apache License 2.0 5 votes vote down vote up
/**
 * This method is called periodically indicating all the current service instances into the kubernetes cluster.
 * @param serviceList List of the current services.
 */
public final void updateServices(V1ServiceList serviceList) {
    Set<String> ids = new HashSet<>();
    ids.addAll(services.keySet());
    for(V1Service service : serviceList.getItems()) {
        if(!ids.remove(service.getMetadata().getUid())) {
            if(!service.getSpec().getPorts().isEmpty()) {
                services.put(service.getMetadata().getUid(), service);
                if (serviceMatcher.match(service)) {
                    onServiceDiscovery(service);
                }
            } else {
                Log.d(SystemProperties.get(SystemProperties.Net.KubernetesSpy.LOG_TAG),
                        "Service skip because there aren't end points present: %s", service.getMetadata().getName());
            }
        } else {
            if(service.getSpec().getPorts().isEmpty()) {
                Log.d(SystemProperties.get(SystemProperties.Net.KubernetesSpy.LOG_TAG),
                        "Service lost because there aren't end points present: %s", service.getMetadata().getName());
                onServiceLost(services.remove(service.getMetadata().getUid()));
            }
        }
    }

    for(String uid : ids) {
        onServiceLost(services.remove(uid));
    }
}
 
Example #4
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;
}
 
Example #5
Source File: CloudOrchestrator.java    From HolandaCatalinaFw with Apache License 2.0 4 votes vote down vote up
@Override
protected void onServiceLost(V1Service service) {
    ServiceEndPoint serviceEndPoint = new ServiceEndPoint();
    serviceEndPoint.setId(new UUID(service.getMetadata().getNamespace().hashCode(), service.getMetadata().getName().hashCode()));
    unregisterConsumer(serviceEndPoint);
}
 
Example #6
Source File: KubernetesManifestCustomizer.java    From pulsar with Apache License 2.0 4 votes vote down vote up
default V1Service customizeService(Function.FunctionDetails funcDetails, V1Service service) {
    return service;
}
 
Example #7
Source File: KubernetesSpyConsumer.java    From HolandaCatalinaFw with Apache License 2.0 2 votes vote down vote up
/**
 * This method is called when a new service is discovery.
 * @param service Discovery service instance.
 */
protected void onServiceDiscovery(V1Service service) {}
 
Example #8
Source File: KubernetesSpyConsumer.java    From HolandaCatalinaFw with Apache License 2.0 2 votes vote down vote up
/**
 * This method is called when a service is not more into the kubernetes cluster.
 * @param service Lost service instance.
 */
protected void onServiceLost(V1Service service) {}
 
Example #9
Source File: KubernetesSpyConsumer.java    From HolandaCatalinaFw with Apache License 2.0 votes vote down vote up
boolean match(V1Service service);