本文整理了Java中io.fabric8.kubernetes.api.model.Service.getMetadata()
方法的一些代码示例,展示了Service.getMetadata()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Service.getMetadata()
方法的具体详情如下:
包路径:io.fabric8.kubernetes.api.model.Service
类名称:Service
方法名:getMetadata
暂无
代码示例来源: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: 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: fabric8io/spring-cloud-kubernetes
@Override
public List<String> getServices() {
return client.services().list()
.getItems()
.stream().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: fabric8io/kubernetes-client
@Override
public String getURL(Service service, String portName, String namespace, KubernetesClient client) {
ServicePort port = URLFromServiceUtil.getServicePortByName(service, portName);
String serviceName = service.getMetadata().getName();
if(port == null) {
throw new RuntimeException("Couldn't find port: " + portName + " for service " + service.getMetadata().getName());
}
IngressList ingresses = client.extensions().ingresses().inNamespace(namespace).list();
if(ingresses != null && !ingresses.getItems().isEmpty()) {
return URLFromServiceUtil.getURLFromIngressList(ingresses.getItems(), namespace, serviceName, port);
}
return null;
}
代码示例来源:origin: fabric8io/kubernetes-client
@Override
public String getURL(Service service, String portName, String namespace, KubernetesClient client) {
String serviceName = service.getMetadata().getName();
ServicePort port = URLFromServiceUtil.getServicePortByName(service, portName);
if(port != null && port.getName() != null && isOpenShift(client)) {
try {
String serviceProtocol = port.getProtocol();
OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class);
Route route = openShiftClient.routes().inNamespace(namespace).withName(service.getMetadata().getName()).get();
if (route != null) {
return (serviceProtocol + "://" + route.getSpec().getHost()).toLowerCase();
}
} catch (KubernetesClientException e) {
if(e.getCode() == HttpURLConnection.HTTP_FORBIDDEN) {
logger.warn("Could not lookup route:" + serviceName + " in namespace:"+ namespace +", due to: " + e.getMessage());
}
}
}
return null;
}
代码示例来源:origin: io.fabric8.pipeline/kubernetes-pipeline-devops-steps
public boolean hasInvalidDNS(Service service) {
if (service.getMetadata() != null && service.getMetadata().getName() != null)
return !(Pattern.matches(SERVICE_NAME_REGEX, service.getMetadata().getName()));
else
return false;
}
代码示例来源:origin: fabric8io/kubernetes-client
public static void main(String args[]) {
try (final KubernetesClient client = new DefaultKubernetesClient()) {
Service service = new ServiceBuilder()
.withNewMetadata()
.withName("my-service")
.endMetadata()
.withNewSpec()
.withSelector(Collections.singletonMap("app", "MyApp"))
.addNewPort()
.withName("test-port")
.withProtocol("TCP")
.withPort(80)
.withTargetPort(new IntOrString(9376))
.endPort()
.withType("LoadBalancer")
.endSpec()
.withNewStatus()
.withNewLoadBalancer()
.addNewIngress()
.withIp("146.148.47.155")
.endIngress()
.endLoadBalancer()
.endStatus()
.build();
service = client.services().inNamespace(client.getNamespace()).create(service);
log("Created service with name ", service.getMetadata().getName());
String serviceURL = client.services().inNamespace(client.getNamespace()).withName(service.getMetadata().getName()).getURL("test-port");
log("Service URL", serviceURL);
}
}
代码示例来源:origin: EnMasseProject/enmasse
/***
* Creates service from resource
* @param resources
* @return endpoint of service
*/
public Endpoint createServiceFromResource(String namespace, Service resources) {
Service serRes = client.services().inNamespace(namespace).create(resources);
log.info("Service {} created", serRes.getMetadata().getName());
return getEndpoint(serRes.getMetadata().getName(), namespace, "http");
}
代码示例来源:origin: jenkinsci/kubernetes-ci-plugin
@Override
public void create(String kubeName, String namespace, Service service) throws RepositoryException {
if (LOGGER.isLoggable(Level.CONFIG) ) {
LOGGER.config("Creating Service: " + service.getMetadata().getName() );
}
kubeRepository.getClient(kubeName).services().inNamespace(namespace).create(service);
}
代码示例来源:origin: jenkinsci/kubernetes-ci-plugin
@Override
public void delete(String kubeName, String namespace, Service service) throws RepositoryException {
if (LOGGER.isLoggable(Level.CONFIG) ) {
LOGGER.config("Deleting Service: " + service.getMetadata().getName() );
}
kubeRepository.getClient(kubeName).services().inNamespace(namespace).delete(service);
}
}
代码示例来源:origin: EnMasseProject/enmasse
private static int getPort(Service service, String portName) {
List<ServicePort> ports = service.getSpec().getPorts();
for (ServicePort port : ports) {
if (port.getName().equals(portName)) {
return port.getPort();
}
}
throw new IllegalArgumentException(
"Unable to find port " + portName + " for service " + service.getMetadata().getName());
}
代码示例来源:origin: fabric8io/fabric8-maven-plugin
private ObjectMeta ensureServiceMetadata(ServiceBuilder service, Service defaultService) {
if (!service.hasMetadata() && defaultService != null) {
service.withNewMetadataLike(defaultService.getMetadata()).endMetadata();
}
return service.buildMetadata();
}
代码示例来源:origin: io.fabric8/fabric8-maven-enricher-standard
private ObjectMeta ensureServiceMetadata(ServiceBuilder service, Service defaultService) {
if (!service.hasMetadata() && defaultService != null) {
service.withNewMetadataLike(defaultService.getMetadata()).endMetadata();
}
return service.buildMetadata();
}
代码示例来源: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/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: 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: org.domeos/kubernetes-model
public ServiceBuilder(Service instance,Boolean validationEnabled){
this.fluent = this;
this.withApiVersion(instance.getApiVersion());
this.withKind(instance.getKind());
this.withMetadata(instance.getMetadata());
this.withSpec(instance.getSpec());
this.withStatus(instance.getStatus());
this.validationEnabled = validationEnabled;
}
代码示例来源: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){
内容来源于网络,如有侵权,请联系作者删除!