io.fabric8.kubernetes.api.model.extensions.Deployment.getMetadata()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(219)

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

Deployment.getMetadata介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

DeploymentList list = client.extensions().deployments().inNamespace(namespace).list();
for (Deployment d : list.getItems()) {
  System.out.println(d.getMetadata().getName());
}

代码示例来源:origin: logzio/apollo

@Override
  public Deployment transform(Deployment deployment,
                io.logz.apollo.models.Deployment apolloDeployment,
                Service apolloService,
                Environment apolloEnvironment,
                DeployableVersion apolloDeployableVersion,
                Group apolloGroup) {

    if (apolloGroup != null) {
      deployment.getMetadata().setName(deployment.getMetadata().getName() + "-" + apolloGroup.getName());
    }
    return deployment;
  }
}

代码示例来源:origin: nbogojevic/kafka-operator

@Override
public void eventReceived(Action action, Deployment resource) {
 if (resource != null) {
  log.debug("Got event {} for {} {}", action, resourceKind(), resource.getMetadata().getName());
  switch (action) {
   case ADDED:
   case MODIFIED:
    onNeedSecret(resource);
    break;
   case DELETED:
    onRemoved(resource);
    break;
   case ERROR:
    log.error("Error event received for {}: {}", resourceKind(), resource);
    break;
  }
 } else {
  log.warn("Event {} received for null {}", action, resourceKind());
 }
}

代码示例来源:origin: jenkinsci/kubernetes-cd-plugin

@Override
Deployment applyResource(Deployment original, Deployment current) {
  return client
      .extensions()
      .deployments()
      .inNamespace(getNamespace())
      .withName(current.getMetadata().getName())
      .edit()
      .withMetadata(current.getMetadata())
      .withSpec(current.getSpec())
      .done();
}

代码示例来源:origin: org.domeos/kubernetes-client

public void run() {
  try {
   Deployment deployment = get();
   //If the deployment is gone, we shouldn't wait.
   if (deployment == null) {
    if (count == 0) {
     queue.put(true);
     return;
    } else {
     queue.put(new IllegalStateException("Can't wait for Deployment: " + checkName(getItem()) + " in namespace: " + checkName(getItem()) + " to scale. Resource is no longer available."));
     return;
    }
   }
   replicasRef.set(deployment.getStatus().getReplicas());
   int currentReplicas = deployment.getStatus().getReplicas() != null ? deployment.getStatus().getReplicas() : 0;
   long generation = deployment.getMetadata().getGeneration() != null ? deployment.getMetadata().getGeneration() : 0;
   long observedGeneration = deployment.getStatus() != null && deployment.getStatus().getObservedGeneration() != null ? deployment.getStatus().getObservedGeneration() : -1;
   if (observedGeneration >= generation && Objects.equals(deployment.getSpec().getReplicas(), currentReplicas)) {
    queue.put(true);
   } else {
    LOG.debug("Only {}/{} pods scheduled for Deployment: {} in namespace: {} seconds so waiting...",
     deployment.getStatus().getReplicas(), deployment.getSpec().getReplicas(), deployment.getMetadata().getName(), namespace);
   }
  } catch (Throwable t) {
   LOG.error("Error while waiting for Deployment to be scaled.", t);
  }
 }
};

代码示例来源:origin: logzio/apollo

Map<String, String> labelsFromDeployment = deployment.getMetadata().getLabels();
deployment.getMetadata().setLabels(labelsFromDeployment);

代码示例来源:origin: org.wso2.carbon.apimgt/org.wso2.carbon.apimgt.core

Deployment deployment = (Deployment) resource;
  Deployment result = client.extensions().deployments().inNamespace(namespace).create(deployment);
  log.info("Created Deployment : " + result.getMetadata().getName() + " in Namespace : "
      + result.getMetadata().getNamespace() + " in " + cmsType);
} else {
  log.info("There exist a deployment with the same name in " + cmsType + ". Deployment name : "

代码示例来源:origin: wso2/carbon-apimgt

Deployment deployment = (Deployment) resource;
  Deployment result = client.extensions().deployments().inNamespace(namespace).create(deployment);
  log.info("Created Deployment : " + result.getMetadata().getName() + " in Namespace : "
      + result.getMetadata().getNamespace() + " in " + cmsType);
} else {
  log.info("There exist a deployment with the same name in " + cmsType + ". Deployment name : "

代码示例来源:origin: logzio/apollo

public void setScalingFactor(Service service, String groupName, int scalingFactor) throws ApolloNotFoundException {
  io.fabric8.kubernetes.api.model.extensions.Deployment kubernetesDeployment = getKubernetesDeployment(service, Optional.of(groupName));
  if (kubernetesDeployment == null) {
    throw new ApolloNotFoundException("Could not find deployment for environment " + environment.getId() + ", service "
        + service.getId() + " and group " + groupName + ", can't return the status!");
  }
  kubernetesClient
      .extensions()
      .deployments()
      .inNamespace(environment.getKubernetesNamespace())
      .withName(kubernetesDeployment.getMetadata().getName())
      .scale(scalingFactor);
}

代码示例来源:origin: org.domeos/kubernetes-model

public DeploymentFluentImpl(Deployment instance){
    this.withApiVersion(instance.getApiVersion()); 
    this.withKind(instance.getKind()); 
    this.withMetadata(instance.getMetadata()); 
    this.withSpec(instance.getSpec()); 
    this.withStatus(instance.getStatus()); 
}

代码示例来源:origin: org.domeos/kubernetes-model

public DeploymentBuilder(DeploymentFluent<?> fluent,Deployment 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 DeploymentBuilder(Deployment instance){

代码示例来源:origin: org.domeos/kubernetes-model

public DeploymentBuilder(Deployment 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: logzio/apollo

public void restartAllPods(Service service, Optional<String> groupName) throws ApolloKubernetesException, ApolloNotFoundException {
  try {
    io.fabric8.kubernetes.api.model.extensions.Deployment deployment = getKubernetesDeployment(service, groupName);
    if (deployment == null) {
      throw new ApolloNotFoundException("Deployment not found!");
    }
    // There's no option to force kubernetes deployment to restart all pods gradually, so we have to edit an innocuous field of the deployment
    kubernetesClient
        .extensions()
        .deployments()
        .inNamespace(environment.getKubernetesNamespace())
        .withName(deployment.getMetadata().getName())
        .edit()
        .editSpec()
        .editTemplate()
        .editMetadata()
        .addToLabels("date", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss")))
        .endMetadata()
        .endTemplate()
        .endSpec()
        .done();
  } catch (KubernetesClientException e) {
    throw new ApolloKubernetesException();
  }
}

代码示例来源:origin: logzio/apollo

public KubernetesDeploymentStatus getCurrentStatus(Service service, Optional<String> groupName) {
  io.fabric8.kubernetes.api.model.extensions.Deployment deployment = getKubernetesDeployment(service, groupName);
  if (deployment == null) {
    logger.warn("Could not find deployment for environment {} and service {}, can't return the status!", environment.getId(), service.getId());
    return null;
  }
  List<PodStatus> podStatusList = kubernetesClient
      .pods()
      .inNamespace(environment.getKubernetesNamespace())
      .withLabel(ApolloToKubernetes.getApolloDeploymentUniqueIdentifierKey(),
          ApolloToKubernetes.getApolloPodUniqueIdentifier(environment, service, groupName))
      .list()
      .getItems()
      .stream()
      .map(pod -> pod.getMetadata().getName())
      .map(this::getPodStatus)
      .collect(Collectors.toList());
  KubernetesDeploymentStatus kubernetesDeploymentStatus = new KubernetesDeploymentStatus();
  kubernetesDeploymentStatus.setServiceId(service.getId());
  kubernetesDeploymentStatus.setEnvironmentId(environment.getId());
  kubernetesDeploymentStatus.setGitCommitSha(deployment.getMetadata().getLabels().get(ApolloToKubernetes.getApolloCommitShaKey()));
  kubernetesDeploymentStatus.setReplicas(deployment.getStatus().getReplicas());
  kubernetesDeploymentStatus.setAvailableReplicas(deployment.getStatus().getAvailableReplicas());
  kubernetesDeploymentStatus.setUpdatedReplicas(deployment.getStatus().getUpdatedReplicas());
  kubernetesDeploymentStatus.setUnavailableReplicas(deployment.getStatus().getUnavailableReplicas());
  kubernetesDeploymentStatus.setPodStatuses(podStatusList);
  groupName.ifPresent(kubernetesDeploymentStatus::setGroupName);
  return kubernetesDeploymentStatus;
}

代码示例来源:origin: io.fabric8/fabric8-maven-enricher-standard

@Override
  public void adapt(KubernetesListBuilder builder) {
    super.adapt(builder);

    List<HasMetadata> items = builder.getItems();
    for (HasMetadata item : items) {
      if (item instanceof Deployment) {
        Deployment deployment = (Deployment) item;
        ObjectMeta metadata = deployment.getMetadata();
        DeploymentSpec spec = deployment.getSpec();
        if (metadata != null && spec != null) {
          PodTemplateSpec template = spec.getTemplate();
          if (template != null) {
            ObjectMeta templateMetadata = template.getMetadata();
            if (templateMetadata == null) {
              templateMetadata = new ObjectMeta();
              template.setMetadata(templateMetadata);
            }
            templateMetadata.setAnnotations(MapUtil.mergeMaps(templateMetadata.getAnnotations(), metadata.getAnnotations()));
          }
        }
      }
    }
    builder.withItems(items);
  }
}

相关文章