Java源码示例:io.fabric8.kubernetes.api.model.DoneableService
示例1
private static EntityPatcher<Service> servicePatcher() {
return (KubernetesClient client, String namespace, Service newObj, Service oldObj) -> {
if (UserConfigurationCompare.configEqual(newObj, oldObj)) {
return oldObj;
}
DoneableService entity =
client.services()
.inNamespace(namespace)
.withName(newObj.getMetadata().getName())
.edit();
if (!UserConfigurationCompare.configEqual(newObj.getMetadata(), oldObj.getMetadata())) {
entity.withMetadata(newObj.getMetadata());
}
if(!UserConfigurationCompare.configEqual(newObj.getSpec(), oldObj.getSpec())) {
entity.withSpec(newObj.getSpec());
}
return entity.done();
};
}
示例2
/**
* 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;
}
示例3
private String getServiceExposeUrl(KubernetesClient kubernetes, Set<HasMetadata> resources) throws InterruptedException {
long serviceUrlWaitTimeSeconds = Configs.asInt(getConfig(Config.serviceUrlWaitTimeSeconds));
for (HasMetadata entity : resources) {
if (entity instanceof Service) {
Service service = (Service) entity;
String name = KubernetesHelper.getName(service);
Resource<Service, DoneableService> serviceResource = kubernetes.services()
.inNamespace(getContext().getJKubeServiceHub().getClusterAccess().getNamespace())
.withName(name);
String url = null;
// lets wait a little while until there is a service URL in case the exposecontroller is running slow
for (int i = 0; i < serviceUrlWaitTimeSeconds; i++) {
if (i > 0) {
Thread.sleep(1000);
}
Service s = serviceResource.get();
if (s != null) {
url = KubernetesHelper.getOrCreateAnnotations(s).get(JKubeAnnotations.SERVICE_EXPOSE_URL.value());
if (StringUtils.isNotBlank(url)) {
break;
}
}
if (!isExposeService(service)) {
break;
}
}
// lets not wait for other services
serviceUrlWaitTimeSeconds = 1;
if (StringUtils.isNotBlank(url) && url.startsWith("http")) {
return url;
}
}
}
log.info("No exposed service found for connecting the dev tools");
return null;
}
示例4
/**
* 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;
}
示例5
/** 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;
});
}
示例6
public static DoneableService createServiceResource(String appName, int port, String clientNamespace, String transportProtocol) {
Service service = getSystemtestsServiceResource(appName, port, clientNamespace, transportProtocol).build();
LOGGER.info("Creating Service {} in namespace {}", service.getMetadata().getName(), clientNamespace);
ResourceManager.kubeClient().createService(service);
deleteLater(service);
return new DoneableService(service);
}
示例7
private static ServiceList getServicesByLabel(Map<String, String> labels, KubernetesClient client)
throws KubernetesClientException {
Objects.requireNonNull(client, "no client available");
final MixedOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>>
services = client.services();
final FilterWatchListDeletable<Service, ServiceList, Boolean, Watch, Watcher<Service>>
listable = createLabelFilterQuery(labels, services);
return listable.list();
}
示例8
private static FilterWatchListDeletable<Service, ServiceList, Boolean, Watch, Watcher<Service>>
createLabelFilterQuery(
Map<String, String> labels,
MixedOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>>
services) {
FilterWatchListDeletable<Service, ServiceList, Boolean, Watch, Watcher<Service>> listable =
null;
for (Entry<String, String> entry : labels.entrySet()) {
listable =
listable == null
? services.withLabel(entry.getKey(), entry.getValue())
: listable.withLabel(entry.getKey(), entry.getValue());
}
return listable;
}
示例9
@Override
protected MixedOperation<Service, ServiceList, DoneableService, ServiceResource<Service, DoneableService>> operation() {
return getClient().services();
}
示例10
private Service createService(OpenShiftClient client, String namespace, String openShiftName) {
String serviceName = openShiftName;
debug(openShiftName, "Creating the Service for VDB "+openShiftName);
Service service = client.services().inNamespace(namespace).withName(serviceName).get();
if (service == null) {
//TODO: this does not check if odata is enabled
TreeMap<String, String> labels = new TreeMap<String, String>();
labels.put("application", openShiftName);
TreeMap<String, String> annotations = new TreeMap<String, String>();
annotations.put(DESCRIPTION_ANNOTATION_LABEL, SERVICE_DESCRIPTION);
if (this.config.isExposeVia3scale()) {
labels.put("discovery.3scale.net", "true");
annotations.put("discovery.3scale.net/scheme", "http");
annotations.put("discovery.3scale.net/port", Integer.toString(ProtocolType.ODATA.getTargetPort()));
annotations.put("discovery.3scale.net/description-path", "/openapi.json");
}
SpecNested<DoneableService> donable = client.services().inNamespace(namespace).createNew()
.withNewMetadata()
.withName(serviceName)
.addToLabels(labels)
.addToAnnotations(annotations)
.endMetadata()
.withNewSpec()
.withSessionAffinity("ClientIP")
.addToSelector("application", openShiftName);
for (ProtocolType type : ProtocolType.values()) {
donable.addNewPort()
.withName(type.id())
.withPort(type.getTargetPort())
.withNewTargetPort()
.withStrVal(type.id())
.endTargetPort()
.endPort();
}
service = donable.endSpec().done();
}
return service;
}
示例11
@Override
protected MixedOperation<Service, ServiceList, DoneableService, ServiceResource<Service, DoneableService>> operation() {
return client.services();
}
示例12
public ServiceMockBuilder(Map<String, Service> svcDb, Map<String, Endpoints> endpointsDb) {
super(Service.class, ServiceList.class, DoneableService.class, castClass(ServiceResource.class), svcDb);
this.endpointsDb = endpointsDb;
}
示例13
public static DoneableService createServiceResource(Service service, String clientNamespace) {
LOGGER.info("Creating Service {} in namespace {}", service.getMetadata().getName(), clientNamespace);
ResourceManager.kubeClient().createService(service);
deleteLater(service);
return new DoneableService(service);
}
示例14
public ServiceOperationsImpl(OperationContext context) {
super(context.withPlural("services"));
this.type = Service.class;
this.listType = ServiceList.class;
this.doneableType = DoneableService.class;
}
示例15
@Override
public MixedOperation<Service, ServiceList, DoneableService, ServiceResource<Service, DoneableService>> services() {
return delegate.services();
}
示例16
@Override
public MixedOperation<Service, ServiceList, DoneableService, ServiceResource<Service, DoneableService>> services() {
return new ServiceOperationsImpl(httpClient, getConfiguration());
}
示例17
public MixedOperation<io.fabric8.kubernetes.api.model.Service, ServiceList, DoneableService, ServiceResource<io.fabric8.kubernetes.api.model.Service, DoneableService>> services() {
return delegate.services();
}
示例18
@Override
public MixedOperation<Service, ServiceList, DoneableService, ServiceResource<Service, DoneableService>> services() {
return delegate.services();
}
示例19
/**
* API entrypoint for Service related operations. Service (core/v1)
*
* @return MixedOperation object for Service related operations.
*/
MixedOperation<Service, ServiceList, DoneableService, ServiceResource<Service, DoneableService>> services();