io.fabric8.kubernetes.client.dsl.ServiceResource Java Examples

The following examples show how to use io.fabric8.kubernetes.client.dsl.ServiceResource. 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: ServiceOperator.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the Service already has assigned node ports.
 *
 * @param namespace The namespace.
 * @param name The route name.
 * @return Whether the Service already has assigned node ports.
 */
public boolean isNodePortReady(String namespace, String name) {
    ServiceResource<Service, DoneableService> resourceOp = operation().inNamespace(namespace).withName(name);
    Service resource = resourceOp.get();

    if (resource != null && resource.getSpec() != null && resource.getSpec().getPorts() != null) {
        boolean ready = true;

        for (ServicePort port : resource.getSpec().getPorts())  {
            if (port.getNodePort() == null) {
                ready = false;
            }
        }
        return ready;
    }

    return false;
}
 
Example #2
Source File: WebServerController.java    From java-operator-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public boolean deleteResource(WebServer nginx) {
    log.info("Execution deleteResource for: {}", nginx.getMetadata().getName());

    log.info("Deleting ConfigMap {}", configMapName(nginx));
    Resource<ConfigMap, DoneableConfigMap> configMap = kubernetesClient.configMaps()
            .inNamespace(nginx.getMetadata().getNamespace())
            .withName(configMapName(nginx));
    if (configMap.get() != null) {
        configMap.delete();
    }

    log.info("Deleting Deployment {}", deploymentName(nginx));
    RollableScalableResource<Deployment, DoneableDeployment> deployment = kubernetesClient.apps().deployments()
            .inNamespace(nginx.getMetadata().getNamespace())
            .withName(deploymentName(nginx));
    if (deployment.get() != null) {
        deployment.cascading(true).delete();
    }

    log.info("Deleting Service {}", serviceName(nginx));
    ServiceResource<Service, DoneableService> service = kubernetesClient.services()
            .inNamespace(nginx.getMetadata().getNamespace())
            .withName(serviceName(nginx));
    if (service.get() != null) {
        service.delete();
    }
    return true;
}
 
Example #3
Source File: BaseKubernetesDiscoveredServiceTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
/**
 * Enables Istio in the test environment.
 */
private void createsIstioIngressGateway() {
    final ServiceResource<Service, ?> serviceResource =
            this.server.getClient()
                       .inNamespace(KogitoKubeConfig.KNATIVE_ISTIO_NAMESPACE)
                       .services()
                       .load(this.getClass().getResource("/mock/responses/ocp4.x/istio/services-istio-ingressgateway.json"));
    this.server.getClient()
               .inNamespace(KogitoKubeConfig.KNATIVE_ISTIO_NAMESPACE)
               .services().create(serviceResource.get());
    this.istioEnabled = true;
}
 
Example #4
Source File: ServiceOperator.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the Service already has assigned ingress address.
 *
 * @param namespace The namespace.
 * @param name The route name.
 * @return Whether the Service already has assigned ingress address.
 */
public boolean isIngressAddressReady(String namespace, String name) {
    ServiceResource<Service, DoneableService> resourceOp = operation().inNamespace(namespace).withName(name);
    Service resource = resourceOp.get();

    if (resource != null && resource.getStatus() != null && resource.getStatus().getLoadBalancer() != null && resource.getStatus().getLoadBalancer().getIngress() != null && resource.getStatus().getLoadBalancer().getIngress().size() > 0) {
        if (resource.getStatus().getLoadBalancer().getIngress().get(0).getHostname() != null || resource.getStatus().getLoadBalancer().getIngress().get(0).getIp() != null) {
            return true;
        }
    }

    return false;
}
 
Example #5
Source File: ServiceMockBuilder.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
/** Override Service creation to also create Endpoints */
@Override
protected void mockCreate(String resourceName, ServiceResource<Service, DoneableService> resource) {
    when(resource.create(any())).thenAnswer(i -> {
        Service argument = i.getArgument(0);
        db.put(resourceName, copyResource(argument));
        LOGGER.debug("create {} (and endpoint) {} ", resourceType, resourceName);
        endpointsDb.put(resourceName, new Endpoints());
        return argument;
    });
}
 
Example #6
Source File: ServicesController.java    From rabbitmq-operator with Apache License 2.0 4 votes vote down vote up
@Override
protected MixedOperation<Service, ServiceList, DoneableService, ServiceResource<Service, DoneableService>> operation() {
    return getClient().services();
}
 
Example #7
Source File: ServiceOperator.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Override
protected MixedOperation<Service, ServiceList, DoneableService, ServiceResource<Service, DoneableService>> operation() {
    return client.services();
}
 
Example #8
Source File: ServiceOperatorTest.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Override
protected Class<ServiceResource> resourceType() {
    return ServiceResource.class;
}
 
Example #9
Source File: ServiceMockBuilder.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public ServiceMockBuilder(Map<String, Service> svcDb, Map<String, Endpoints> endpointsDb) {
    super(Service.class, ServiceList.class, DoneableService.class, castClass(ServiceResource.class), svcDb);
    this.endpointsDb = endpointsDb;
}
 
Example #10
Source File: ManagedKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
public MixedOperation<io.fabric8.kubernetes.api.model.Service, ServiceList, DoneableService, ServiceResource<io.fabric8.kubernetes.api.model.Service, DoneableService>> services() {
  return delegate.services();
}
 
Example #11
Source File: MockKubernetesServerSupport.java    From kogito-runtimes with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a service based on an {@link InputStream} of a json service response.
 * 
 * @param mockJsonResponse
 */
protected void createMockService(final InputStream mockJsonResponse, final String namespace) {
    final ServiceResource<Service, ?> serviceResource = this.server.getClient().inNamespace(namespace).services().load(mockJsonResponse);
    this.server.getClient().inNamespace(namespace).services().create(serviceResource.get());
}