本文整理了Java中io.fabric8.kubernetes.api.model.Service
类的一些代码示例,展示了Service
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Service
类的具体详情如下:
包路径:io.fabric8.kubernetes.api.model.Service
类名称:Service
暂无
代码示例来源:origin: spring-cloud/spring-cloud-kubernetes
public List<String> getServices(Predicate<Service> filter) {
return kubernetesClientServicesFunction.apply(client).list()
.getItems()
.stream()
.filter(filter)
.map(s -> s.getMetadata().getName())
.collect(Collectors.toList());
}
代码示例来源:origin: fabric8io/kubernetes-client
@Override
public String getURL(Service service, String portName, String namespace, KubernetesClient client) {
String serviceHost = URLFromServiceUtil.resolveHostFromEnvVarOrSystemProperty(service.getMetadata().getName());
String servicePort = URLFromServiceUtil.resolvePortFromEnvVarOrSystemProperty(service.getMetadata().getName(), "");
String serviceProtocol = URLFromServiceUtil.resolveProtocolFromEnvVarOrSystemProperty(service.getSpec().getPorts().iterator().next().getProtocol(), "");
if(!serviceHost.isEmpty() && !servicePort.isEmpty() && !serviceProtocol.isEmpty()) {
return serviceProtocol + "://" + serviceHost + ":" + servicePort;
} else {
String answer = URLFromServiceUtil.getOrCreateAnnotations(service).get(ANNOTATION_EXPOSE_URL);
if(answer != null && !answer.isEmpty()) {
return answer;
}
}
return null;
}
代码示例来源:origin: fabric8io/kubernetes-client
public String getURL(String portName) {
String clusterIP = getMandatory().getSpec().getClusterIP();
if("None".equals(clusterIP)) {
throw new IllegalStateException("Service: " + getMandatory().getMetadata().getName() + " in namespace " +
namespace + " is head-less. Search for endpoints instead");
}
return getUrlHelper(portName);
}
代码示例来源:origin: io.vertx/vertx-service-discovery-bridge-kubernetes
private Service getExternalService(int port) {
ObjectMeta metadata = new ObjectMeta();
metadata.setName("my-service");
metadata.setUid("uuid");
metadata.setNamespace("my-project");
ServiceSpec serviceSpec = new ServiceSpec();
ServicePort servicePort = new ServicePort();
servicePort.setPort(port);
serviceSpec.setType("ExternalName");
serviceSpec.setExternalName("my-external-service");
serviceSpec.setPorts(Collections.singletonList(servicePort));
Service service = new Service();
service.setMetadata(metadata);
service.setSpec(serviceSpec);
return service;
}
代码示例来源:origin: spring-cloud/spring-cloud-kubernetes
if(metadataProps.isAddLabels()) {
Map<String, String> labelMetadata = getMapWithPrefixedKeys(
service.getMetadata().getLabels(), metadataProps.getLabelsPrefix());
if (log.isDebugEnabled()) {
log.debug("Adding label metadata: "+labelMetadata);
service.getMetadata().getAnnotations(), metadataProps.getAnnotationsPrefix());
if (log.isDebugEnabled()) {
log.debug("Adding annotation metadata: "+annotationMetadata);
new DefaultIsServicePortSecureResolver.Input(
endpointPort.getPort(),
service.getMetadata().getName(),
service.getMetadata().getLabels(),
service.getMetadata().getAnnotations()
代码示例来源:origin: spring-cloud/spring-cloud-deployer-kubernetes
result.put("pod.name", pod.getMetadata().getName());
result.put("pod.startTime", pod.getStatus().getStartTime());
result.put("pod.ip", pod.getStatus().getPodIP());
result.put("phase", pod.getStatus().getPhase());
result.put(AbstractKubernetesDeployer.SPRING_APP_KEY.replace('-', '.'),
pod.getMetadata().getLabels().get(AbstractKubernetesDeployer.SPRING_APP_KEY));
result.put(AbstractKubernetesDeployer.SPRING_DEPLOYMENT_KEY.replace('-', '.'),
pod.getMetadata().getLabels().get(AbstractKubernetesDeployer.SPRING_DEPLOYMENT_KEY));
result.put("guid", pod.getMetadata().getUid());
result.put("service.name", service.getMetadata().getName());
if ("LoadBalancer".equals(service.getSpec().getType())) {
if (service.getStatus() != null && service.getStatus().getLoadBalancer() != null
&& service.getStatus().getLoadBalancer().getIngress() != null && !service.getStatus()
.getLoadBalancer().getIngress().isEmpty()) {
String externalIp = service.getStatus().getLoadBalancer().getIngress().get(0).getIp();
result.put("service.external.ip", externalIp);
List<ServicePort> ports = service.getSpec().getPorts();
int port = 0;
if (ports != null && ports.size() > 0) {
代码示例来源:origin: org.domeos/kubernetes-model
public ServiceBuilder(ServiceFluent<?> fluent,Service instance,Boolean validationEnabled){
this.fluent = fluent;
fluent.withApiVersion(instance.getApiVersion());
fluent.withKind(instance.getKind());
fluent.withMetadata(instance.getMetadata());
fluent.withSpec(instance.getSpec());
fluent.withStatus(instance.getStatus());
this.validationEnabled = validationEnabled;
}
public ServiceBuilder(Service instance){
代码示例来源:origin: io.fabric8.pipeline/kubernetes-pipeline-devops-steps
private Service sanitizeServiceName(Service service) {
String serviceName = service.getMetadata().getName();
service.getMetadata().setName(SERVICE_NAME_PREFIX + truncate(serviceName).toLowerCase());
return service;
}
代码示例来源:origin: io.fabric8.ipaas.apps/apiman
Map<String,String> descriptions = new HashMap<String,String>();
for(Template template : templateList.getItems()) {
String name = template.getMetadata().getName();
for (String annotation : template.getMetadata().getAnnotations().keySet()) {
if (annotation.contains("summary")) {
String description = template.getMetadata().getAnnotations().get(annotation);
descriptions.put(name, description);
Map<String, Service> serviceMap = KubernetesHelper.getServiceMap(kubernetes, kubernetesNamespace);
Map<String,String> annotations = service.getMetadata().getAnnotations();
String scheme = "http";
String port = KubernetesHelper.serviceToPort(service.getMetadata().getName());
if (port!=null && port.endsWith("443")) scheme = "https";
if (annotations!=null && annotations.containsKey("servicescheme")) scheme = annotations.get("servicescheme");
String serviceUrl = KubernetesHelper.getServiceURL(kubernetes, service.getMetadata().getName(),kubernetesNamespace, scheme, true);
List<ServiceContract> serviceContracts = createServiceContract(annotations, serviceUrl);
bean.setName(service.getMetadata().getName() + serviceContract.getName());
bean.setDescription(descriptions.get(service.getMetadata().getName()));
bean.setEndpoint(serviceContract.getServiceUrl());
if (serviceContract.getProtocol()!=null) {
代码示例来源:origin: spring-cloud/spring-cloud-deployer-kubernetes
if (apps != null) {
for (Service app : apps) {
String appIdToDelete = app.getMetadata().getName();
logger.debug(String.format("Deleting Resources for: %s", appIdToDelete));
if (svc != null && "LoadBalancer".equals(svc.getSpec().getType())) {
int tries = 0;
int maxWait = properties.getMinutesToWaitForLoadBalancer() * 6; // we check 6 times per minute
while (tries++ < maxWait) {
if (svc.getStatus() != null && svc.getStatus().getLoadBalancer() != null
&& svc.getStatus().getLoadBalancer().getIngress() != null && svc.getStatus()
.getLoadBalancer().getIngress().isEmpty()) {
if (tries % 6 == 0) {
svc.getStatus().getLoadBalancer().getIngress().toString()));
代码示例来源:origin: arquillian/arquillian-cube
@Test
public void testServicesInjection() {
assertNotNull(serviceList);
assertEquals(1, serviceList.getItems().size());
assertEquals("test-service", serviceList.getItems().get(0).getMetadata().getName());
assertNotNull(service);
assertEquals("test-service", service.getMetadata().getName());
assertNotNull(serviceInSecondaryNamespace);
assertEquals("test-service-second", serviceInSecondaryNamespace.getMetadata().getName());
assertEquals("test-secondary-namespace", serviceInSecondaryNamespace.getMetadata().getNamespace());
}
}
代码示例来源:origin: fabric8io/kubernetes-client
public static ServicePort getServicePortByName(Service service, String portName) {
if (portName.isEmpty()) {
return service.getSpec().getPorts().iterator().next();
}
for (ServicePort servicePort : service.getSpec().getPorts()) {
if (Objects.equals(servicePort.getName(), portName)) {
return servicePort;
}
}
return null;
}
}
代码示例来源:origin: io.vertx/vertx-service-discovery-bridge-kubernetes
private KubernetesResource getUpdatedHttpService() {
Service service = getHttpService();
service.getMetadata().getLabels().put("foo", "bar");
return service;
}
代码示例来源:origin: io.fabric8/fabric8-maven-enricher-expose
private void enrichService(Service service) {
if (hasWebPort(service)) {
ObjectMeta metadata = service.getMetadata();
if (metadata == null) {
metadata = new ObjectMeta();
service.setMetadata(metadata);
}
Map<String, String> labels = getOrCreateLabels(service);
if (!labels.containsKey(EXPOSE_LABEL)) {
labels.put(EXPOSE_LABEL, "true");
log.info("Adding Service label `" + EXPOSE_LABEL + ":true` on service " +
KubernetesHelper.getName(service) +
" so that it is exposed by the exposecontroller microservice. To disable use the maven argument: `-Dfabric8.profile=internal-microservice`");
}
}
}
代码示例来源:origin: org.microbean/microbean-helm
protected Service createService(final String namespace,
final String serviceName,
Map<String, String> labels) {
labels = normalizeLabels(labels);
final Service service = new Service();
final ObjectMeta metadata = new ObjectMeta();
metadata.setNamespace(normalizeNamespace(namespace));
metadata.setName(normalizeServiceName(serviceName));
metadata.setLabels(labels);
service.setMetadata(metadata);
service.setSpec(this.createServiceSpec(labels));
return service;
}
代码示例来源:origin: io.fabric8/kubernetes-jolokia
/**
* Returns all the clients the first working pod for the given service
*/
public List<J4pClient> clientsForService(Service service) {
List<Pod> pods = KubernetesHelper.getPodsForService(service, kubernetes.pods().inNamespace(service.getMetadata().getNamespace()).list().getItems());
return clientsForPod(pods);
}
代码示例来源:origin: org.guvnor/guvnor-ala-openshift-provider
private DeployableScalableResource<DeploymentConfig, DoneableDeploymentConfig> getDeploymentConfigResource(Service service) {
if (service != null) {
String prjName = service.getMetadata().getNamespace();
Map<String, String> selector = service.getSpec().getSelector();
String dcName = selector.get("deploymentconfig");
if (dcName == null) {
dcName = selector.get("deploymentConfig");
}
if (dcName != null) {
return delegate.deploymentConfigs().inNamespace(prjName).withName(dcName);
}
}
return null;
}
代码示例来源:origin: jenkinsci/kubernetes-ci-plugin
@Override
public void create(String kubeName, String namespace, Service service, Map<String, String> labels)
throws RepositoryException {
if (labels != null) {
final Map<String, String> currentLabels = service.getMetadata().getLabels();
currentLabels.putAll(labels);
service.getMetadata().setLabels(currentLabels);
}
this.create(kubeName, namespace, service);
}
代码示例来源:origin: fabric8io/jube
protected void serviceChanged(Service entity, boolean remove) {
if (remove) {
String id = getName(entity);
if (Strings.isNotBlank(id)) {
memoryModel.deleteService(id, KubernetesHelper.getNamespace(entity));
serviceListeners.entityDeleted(id, entity);
}
} else {
String id = memoryModel.getOrCreateId(getName(entity), NodeHelper.KIND_SERVICE);
if (entity.getMetadata().getUid() == null) {
entity.getMetadata().setUid(getNamespace() + '/' + id);
}
memoryModel.updateService(id, entity);
serviceListeners.entityChanged(id, entity);
}
}
}
代码示例来源:origin: fabric8io/jube
return null;
ServiceSpec serviceSpec = service.getSpec();
if (serviceSpec == null) {
return null;
String namespace = KubernetesHelper.getNamespace(service);
String serviceName = getName(service);
String qualifiedServiceName = namespace + ":" + serviceName;
List<ServicePort> ports = serviceSpec.getPorts();
for (ServicePort servicePort : ports) {
IntOrString targetPort = servicePort.getTargetPort();
Integer portNumber = KubernetesHelper.intOrStringToInteger(targetPort, qualifiedServiceName);
if (portNumber != null) {
List<Pod> podsForService = KubernetesHelper.getPodsForService(service, pods);
内容来源于网络,如有侵权,请联系作者删除!