io.fabric8.kubernetes.api.model.Service.setMetadata()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(14.9k)|赞(0)|评价(0)|浏览(110)

本文整理了Java中io.fabric8.kubernetes.api.model.Service.setMetadata()方法的一些代码示例,展示了Service.setMetadata()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Service.setMetadata()方法的具体详情如下:
包路径:io.fabric8.kubernetes.api.model.Service
类名称:Service
方法名:setMetadata

Service.setMetadata介绍

暂无

代码示例

代码示例来源: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: io.fabric8/fabric8-maven-enricher-fabric8

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.verbose("Adding Service label '%s:true' on service %s" +
            " so that it is exposed by the exposecontroller microservice." +
            " To disable use the maven argument: '-Dfabric8.profile=internal-microservice'",
            EXPOSE_LABEL, KubernetesHelper.getName(service));
    }
  }
}

代码示例来源:origin: fabric8io/fabric8-maven-plugin

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 = KubernetesHelper.getOrCreateLabels(service);
    if (!labels.containsKey(EXPOSE_LABEL)) {
      labels.put(EXPOSE_LABEL, "true");
      log.verbose("Adding Service label '%s:true' on service %s" +
            " so that it is exposed by the exposecontroller microservice." +
            " To disable use the maven argument: '-Dfabric8.profile=internal-microservice'",
            EXPOSE_LABEL, KubernetesHelper.getName(service));
    }
  }
}

代码示例来源:origin: io.vertx/vertx-service-discovery-bridge-kubernetes

@Test
public void testRecordCreation() {
 ObjectMeta metadata = new ObjectMeta();
 metadata.setName("my-service");
 metadata.setUid("uuid");
 metadata.setNamespace("my-project");
 ServiceSpec spec = new ServiceSpec();
 ServicePort port = new ServicePort();
 port.setTargetPort(new IntOrString(8080));
 port.setPort(1524);
 spec.setPorts(Collections.singletonList(port));
 Service service = new Service();
 service.setMetadata(metadata);
 service.setSpec(spec);
 Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service)));
 assertThat(record).isNotNull();
 assertThat(record.getName()).isEqualTo("my-service");
 assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
 assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
 assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
 assertThat(record.getType()).isEqualTo(ServiceType.UNKNOWN);
 assertThat(record.getLocation().getInteger("port")).isEqualTo(1524);
}

代码示例来源:origin: vert-x3/vertx-service-discovery

@Test
public void testRecordCreation() {
 ObjectMeta metadata = new ObjectMeta();
 metadata.setName("my-service");
 metadata.setUid("uuid");
 metadata.setNamespace("my-project");
 ServiceSpec spec = new ServiceSpec();
 ServicePort port = new ServicePort();
 port.setTargetPort(new IntOrString(8080));
 port.setPort(1524);
 spec.setPorts(Collections.singletonList(port));
 Service service = new Service();
 service.setMetadata(metadata);
 service.setSpec(spec);
 Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service)));
 assertThat(record).isNotNull();
 assertThat(record.getName()).isEqualTo("my-service");
 assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
 assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
 assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
 assertThat(record.getType()).isEqualTo(ServiceType.UNKNOWN);
 assertThat(record.getLocation().getInteger("port")).isEqualTo(1524);
}

代码示例来源:origin: io.vertx/vertx-service-discovery-bridge-kubernetes

@Test
public void testHttpWithSSLRecordCreation() {
 Map<String, String> labels = new LinkedHashMap<>();
 labels.put("service-type", "http-endpoint");
 labels.put("ssl", "true");
 ObjectMeta metadata = new ObjectMeta();
 metadata.setName("my-service");
 metadata.setUid("uuid");
 metadata.setNamespace("my-project");
 metadata.setLabels(labels);
 ServiceSpec spec = new ServiceSpec();
 ServicePort port = new ServicePort();
 port.setTargetPort(new IntOrString(8080));
 port.setPort(8080);
 spec.setPorts(Collections.singletonList(port));
 Service service = new Service();
 service.setMetadata(metadata);
 service.setSpec(spec);
 Record record = KubernetesServiceImporter.createRecord(Json.encodeToBuffer(service).toJsonObject());
 assertThat(record).isNotNull();
 assertThat(record.getName()).isEqualTo("my-service");
 assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
 assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
 assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
 assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE);
 assertThat(record.getLocation().getInteger("port")).isEqualTo(8080);
 assertThat(record.getLocation().getBoolean("ssl")).isTrue();
}

代码示例来源:origin: vert-x3/vertx-service-discovery

@Test
public void testHttpWithSSLRecordCreation() {
 Map<String, String> labels = new LinkedHashMap<>();
 labels.put("service-type", "http-endpoint");
 labels.put("ssl", "true");
 ObjectMeta metadata = new ObjectMeta();
 metadata.setName("my-service");
 metadata.setUid("uuid");
 metadata.setNamespace("my-project");
 metadata.setLabels(labels);
 ServiceSpec spec = new ServiceSpec();
 ServicePort port = new ServicePort();
 port.setTargetPort(new IntOrString(8080));
 port.setPort(8080);
 spec.setPorts(Collections.singletonList(port));
 Service service = new Service();
 service.setMetadata(metadata);
 service.setSpec(spec);
 Record record = KubernetesServiceImporter.createRecord(Json.encodeToBuffer(service).toJsonObject());
 assertThat(record).isNotNull();
 assertThat(record.getName()).isEqualTo("my-service");
 assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
 assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
 assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
 assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE);
 assertThat(record.getLocation().getInteger("port")).isEqualTo(8080);
 assertThat(record.getLocation().getBoolean("ssl")).isTrue();
}

代码示例来源: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: 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.vertx/vertx-service-discovery-bridge-kubernetes

private Service getService96() {
 Map<String, String> labels = new LinkedHashMap<>();
 labels.put("service-type", "http-endpoint");
 ObjectMeta metadata = new ObjectMeta();
 metadata.setName("hello-minikube");
 metadata.setUid("37c57c1e-deb0-11e8-a8ee-0800274f8294");
 metadata.setNamespace("issue96");
 metadata.setLabels(labels);
 metadata.getAdditionalProperties().put("run", "hello-minikube");
 ServiceSpec spec = new ServiceSpec();
 ServicePort port = new ServicePort();
 port.setTargetPort(new IntOrString(80));
 port.setPort(8080);
 spec.setPorts(Collections.singletonList(port));
 Service service = new Service();
 service.setMetadata(metadata);
 service.setSpec(spec);
 return service;
}

代码示例来源:origin: vert-x3/vertx-service-discovery

private Service getService96() {
 Map<String, String> labels = new LinkedHashMap<>();
 labels.put("service-type", "http-endpoint");
 ObjectMeta metadata = new ObjectMeta();
 metadata.setName("hello-minikube");
 metadata.setUid("37c57c1e-deb0-11e8-a8ee-0800274f8294");
 metadata.setNamespace("issue96");
 metadata.setLabels(labels);
 metadata.getAdditionalProperties().put("run", "hello-minikube");
 ServiceSpec spec = new ServiceSpec();
 ServicePort port = new ServicePort();
 port.setTargetPort(new IntOrString(80));
 port.setPort(8080);
 spec.setPorts(Collections.singletonList(port));
 Service service = new Service();
 service.setMetadata(metadata);
 service.setSpec(spec);
 return service;
}

代码示例来源:origin: io.vertx/vertx-service-discovery-bridge-kubernetes

private Service getHttpService() {
 Map<String, String> labels = new LinkedHashMap<>();
 labels.put("service-type", "http-endpoint");
 ObjectMeta metadata = new ObjectMeta();
 metadata.setName("my-service");
 metadata.setUid("uuid");
 metadata.setNamespace("my-project");
 metadata.setLabels(labels);
 ServiceSpec spec = new ServiceSpec();
 ServicePort port = new ServicePort();
 port.setTargetPort(new IntOrString(80));
 port.setPort(8080);
 spec.setPorts(Collections.singletonList(port));
 Service service = new Service();
 service.setMetadata(metadata);
 service.setSpec(spec);
 return service;
}

代码示例来源:origin: io.vertx/vertx-service-discovery-bridge-kubernetes

private Service getHttpService() {
 Map<String, String> labels = new LinkedHashMap<>();
 labels.put("service-type", "http-endpoint");
 ObjectMeta metadata = new ObjectMeta();
 metadata.setName("my-http-service");
 metadata.setUid("uuid-1");
 metadata.setNamespace("my-project");
 metadata.setLabels(labels);
 ServiceSpec spec = new ServiceSpec();
 ServicePort port = new ServicePort();
 port.setTargetPort(new IntOrString(80));
 port.setPort(8080);
 spec.setPorts(Collections.singletonList(port));
 Service service = new Service();
 service.setMetadata(metadata);
 service.setSpec(spec);
 return service;
}

代码示例来源:origin: io.vertx/vertx-service-discovery-bridge-kubernetes

service.setMetadata(metadata);
service.setSpec(spec);

代码示例来源:origin: vert-x3/vertx-service-discovery

private Service getHttpService() {
 Map<String, String> labels = new LinkedHashMap<>();
 labels.put("service-type", "http-endpoint");
 ObjectMeta metadata = new ObjectMeta();
 metadata.setName("my-service");
 metadata.setUid("uuid");
 metadata.setNamespace("my-project");
 metadata.setLabels(labels);
 ServiceSpec spec = new ServiceSpec();
 ServicePort port = new ServicePort();
 port.setTargetPort(new IntOrString(80));
 port.setPort(8080);
 spec.setPorts(Collections.singletonList(port));
 Service service = new Service();
 service.setMetadata(metadata);
 service.setSpec(spec);
 return service;
}

代码示例来源:origin: vert-x3/vertx-service-discovery

private Service getHttpService() {
 Map<String, String> labels = new LinkedHashMap<>();
 labels.put("service-type", "http-endpoint");
 ObjectMeta metadata = new ObjectMeta();
 metadata.setName("my-http-service");
 metadata.setUid("uuid-1");
 metadata.setNamespace("my-project");
 metadata.setLabels(labels);
 ServiceSpec spec = new ServiceSpec();
 ServicePort port = new ServicePort();
 port.setTargetPort(new IntOrString(80));
 port.setPort(8080);
 spec.setPorts(Collections.singletonList(port));
 Service service = new Service();
 service.setMetadata(metadata);
 service.setSpec(spec);
 return service;
}

代码示例来源:origin: io.vertx/vertx-service-discovery-bridge-kubernetes

private Service getSimpleService() {
 ObjectMeta metadata = new ObjectMeta();
 metadata.setName("my-service");
 metadata.setUid("uuid-2");
 metadata.setNamespace("my-project");
 ServiceSpec spec = new ServiceSpec();
 ServicePort port = new ServicePort();
 port.setTargetPort(new IntOrString(8080));
 port.setPort(1524);
 spec.setPorts(Collections.singletonList(port));
 Service service = new Service();
 service.setMetadata(metadata);
 service.setSpec(spec);
 return service;
}

代码示例来源:origin: vert-x3/vertx-service-discovery

private Service getSimpleService() {
 ObjectMeta metadata = new ObjectMeta();
 metadata.setName("my-service");
 metadata.setUid("uuid-2");
 metadata.setNamespace("my-project");
 ServiceSpec spec = new ServiceSpec();
 ServicePort port = new ServicePort();
 port.setTargetPort(new IntOrString(8080));
 port.setPort(1524);
 spec.setPorts(Collections.singletonList(port));
 Service service = new Service();
 service.setMetadata(metadata);
 service.setSpec(spec);
 return service;
}

代码示例来源: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: vert-x3/vertx-service-discovery

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;
}

相关文章