当前位置: 首页>>代码示例>>Java>>正文


Java ObjectReference类代码示例

本文整理汇总了Java中io.fabric8.kubernetes.api.model.ObjectReference的典型用法代码示例。如果您正苦于以下问题:Java ObjectReference类的具体用法?Java ObjectReference怎么用?Java ObjectReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ObjectReference类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了ObjectReference类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: issueRouteCert

import io.fabric8.kubernetes.api.model.ObjectReference; //导入依赖的package包/类
@Override
public void issueRouteCert(String secretName, String namespace, String ... hostnames) throws Exception {
    Secret secret = client.secrets().inNamespace(namespace).withName(secretName).get();
    if (secret == null) {
        String keyKey = "tls.key";
        String certKey = "tls.crt";

        log.info("Creating self-signed certificates for {}", secretName);
        File key = File.createTempFile("tls", "key");
        File cert = File.createTempFile("tls", "crt");

        createSelfSignedCert(key, cert);
        secret = createSecretFromCertAndKeyFiles(secretName, namespace, keyKey, certKey, key, cert, client);
    }

    ServiceAccount defaultAccount = client.serviceAccounts().inNamespace(namespace).withName("default").get();
    for (ObjectReference reference : defaultAccount.getSecrets()) {
        if (reference.getName().equals(secretName)) {
            return;
        }
    }

    client.serviceAccounts().inNamespace(namespace).withName("default").edit()
            .addToSecrets(new ObjectReferenceBuilder()
                    .withKind(secret.getKind())
                    .withName(secret.getMetadata().getName())
                    .withApiVersion(secret.getApiVersion())
                    .build())
            .done();
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:31,代码来源:OpenSSLCertManager.java

示例2: watchContainers

import io.fabric8.kubernetes.api.model.ObjectReference; //导入依赖的package包/类
/**
 * Registers a specified handler for handling events about changes in pods containers.
 *
 * @param handler pod container events handler
 * @throws InfrastructureException if any error occurs while watcher starting
 */
public void watchContainers(ContainerEventHandler handler) throws InfrastructureException {
  if (containerWatch == null) {
    final Watcher<Event> watcher =
        new Watcher<Event>() {
          @Override
          public void eventReceived(Action action, Event event) {
            ObjectReference involvedObject = event.getInvolvedObject();
            String fieldPath = involvedObject.getFieldPath();

            // check that event related to
            if (POD_OBJECT_KIND.equals(involvedObject.getKind()) && fieldPath != null) {
              Matcher containerFieldMatcher = CONTAINER_FIELD_PATH_PATTERN.matcher(fieldPath);
              if (containerFieldMatcher.matches()) {

                String podName = involvedObject.getName();
                String containerName = containerFieldMatcher.group(CONTAINER_NAME_GROUP);

                ContainerEvent containerEvent =
                    new ContainerEvent(
                        podName,
                        containerName,
                        event.getMessage(),
                        event.getMetadata().getCreationTimestamp());
                containerEventsHandlers.forEach(h -> h.handle(containerEvent));
              }
            }
          }

          @Override
          public void onClose(KubernetesClientException ignored) {}
        };
    try {
      containerWatch = clientFactory.create().events().inNamespace(namespace).watch(watcher);
    } catch (KubernetesClientException ex) {
      throw new InfrastructureException(ex.getMessage());
    }
  }
  containerEventsHandlers.add(handler);
}
 
开发者ID:eclipse,项目名称:che,代码行数:46,代码来源:OpenShiftPods.java

示例3: createEndpointsForService

import io.fabric8.kubernetes.api.model.ObjectReference; //导入依赖的package包/类
protected static Endpoints createEndpointsForService(Service service, List<Pod> pods) {
    if (service == null) {
        return null;
    }
    ServiceSpec serviceSpec = service.getSpec();
    if (serviceSpec == null) {
        return null;
    }
    List<EndpointAddress> addresses = new ArrayList<>();
    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);
            for (Pod pod : podsForService) {
                PodStatus currentState = pod.getStatus();
                if (currentState != null) {
                    String podIP = currentState.getPodIP();
                    if (podIP != null) {
                        String url = podIP + ":" + portNumber;
                        EndpointAddress address = new EndpointAddress();
                        address.setIp(podIP);
                        ObjectReference ref = new ObjectReference();
                        ref.setNamespace(namespace);
                        ref.setName(getName(pod));
                        address.setTargetRef(ref);
                        addresses.add(address);
                    }
                }
            }
        }
    }
    EndpointSubset subset = new EndpointSubset();
    subset.setAddresses(addresses);
    return new EndpointsBuilder().
            withNewMetadata().withName(serviceName).withNamespace(namespace).endMetadata().
            addToSubsets(subset).
            build();
}
 
开发者ID:fabric8io,项目名称:jube,代码行数:46,代码来源:ApiMasterService.java


注:本文中的io.fabric8.kubernetes.api.model.ObjectReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。