io.fabric8.kubernetes.api.model.apps.DeploymentList#io.fabric8.kubernetes.api.model.apps.DoneableDeployment源码实例Demo

下面列出了io.fabric8.kubernetes.api.model.apps.DeploymentList#io.fabric8.kubernetes.api.model.apps.DoneableDeployment 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public static DoneableDeployment deployKafkaClients(boolean tlsListener, String kafkaClientsName, boolean hostnameVerification, KafkaUser... kafkaUsers) {
    Map<String, String> label = Collections.singletonMap(Constants.KAFKA_CLIENTS_LABEL_KEY, Constants.KAFKA_CLIENTS_LABEL_VALUE);
    Deployment kafkaClient = new DeploymentBuilder()
        .withNewMetadata()
            .withName(kafkaClientsName)
            .withLabels(label)
        .endMetadata()
        .withNewSpec()
            .withNewSelector()
                .addToMatchLabels("app", kafkaClientsName)
                .addToMatchLabels(label)
            .endSelector()
            .withReplicas(1)
            .withNewTemplate()
                .withNewMetadata()
                    .addToLabels("app", kafkaClientsName)
                    .addToLabels(label)
                .endMetadata()
                .withSpec(createClientSpec(tlsListener, kafkaClientsName, hostnameVerification, kafkaUsers))
            .endTemplate()
        .endSpec()
        .build();

    return KubernetesResource.deployNewDeployment(kafkaClient);
}
 
public static DoneableDeployment deployNewDeployment(Deployment deployment) {
    return new DoneableDeployment(deployment, co -> {
        TestUtils.waitFor("Deployment creation", Constants.POLL_INTERVAL_FOR_RESOURCE_CREATION, Constants.TIMEOUT_FOR_CR_CREATION,
            () -> {
                try {
                    ResourceManager.kubeClient().createOrReplaceDeployment(co);
                    return true;
                } catch (KubernetesClientException e) {
                    if (e.getMessage().contains("object is being deleted")) {
                        return false;
                    } else {
                        throw e;
                    }
                }
            }
        );
        return waitFor(deleteLater(co));
    });
}
 
源代码3 项目: java-operator-sdk   文件: WebServerController.java
@Override
public boolean deleteResource(WebServer nginx) {
    log.info("Execution deleteResource for: {}", nginx.getMetadata().getName());

    log.info("Deleting ConfigMap {}", configMapName(nginx));
    Resource<ConfigMap, DoneableConfigMap> configMap = kubernetesClient.configMaps()
            .inNamespace(nginx.getMetadata().getNamespace())
            .withName(configMapName(nginx));
    if (configMap.get() != null) {
        configMap.delete();
    }

    log.info("Deleting Deployment {}", deploymentName(nginx));
    RollableScalableResource<Deployment, DoneableDeployment> deployment = kubernetesClient.apps().deployments()
            .inNamespace(nginx.getMetadata().getNamespace())
            .withName(deploymentName(nginx));
    if (deployment.get() != null) {
        deployment.cascading(true).delete();
    }

    log.info("Deleting Service {}", serviceName(nginx));
    ServiceResource<Service, DoneableService> service = kubernetesClient.services()
            .inNamespace(nginx.getMetadata().getNamespace())
            .withName(serviceName(nginx));
    if (service.get() != null) {
        service.delete();
    }
    return true;
}
 
@Override
protected void mockCreate(String resourceName, RollableScalableResource<Deployment, DoneableDeployment> resource) {
    when(resource.create(any())).thenAnswer(invocation -> {
        checkNotExists(resourceName);
        Deployment deployment = invocation.getArgument(0);
        LOGGER.debug("create {} {} -> {}", resourceType, resourceName, deployment);
        deployment.getMetadata().setGeneration(Long.valueOf(0));
        deployment.setStatus(new DeploymentStatusBuilder().withObservedGeneration(Long.valueOf(0)).build());
        db.put(resourceName, copyResource(deployment));
        for (int i = 0; i < deployment.getSpec().getReplicas(); i++) {
            String uuid = UUID.randomUUID().toString();
            String podName = deployment.getMetadata().getName() + "-" + uuid;
            LOGGER.debug("create Pod {} because it's in Deployment {}", podName, resourceName);
            Pod pod = new PodBuilder()
                    .withNewMetadataLike(deployment.getSpec().getTemplate().getMetadata())
                        .withUid(uuid)
                        .withNamespace(deployment.getMetadata().getNamespace())
                        .withName(podName)
                    .endMetadata()
                    .withNewSpecLike(deployment.getSpec().getTemplate().getSpec()).endSpec()
                    .build();
            mockPods.inNamespace(deployment.getMetadata().getNamespace()).withName(podName).create(pod);
            podsForDeployments.compute(deployment.getMetadata().getName(), (deploymentName, podsInDeployment) -> {
                if (podsInDeployment == null) {
                    podsInDeployment = new ArrayList<>(2);
                }
                podsInDeployment.add(podName);
                return podsInDeployment;
            });
        }
        return deployment;
    });
}
 
public DeploymentOperationsImpl(RollingOperationContext context) {
  super(context.withApiGroupName("apps")
    .withApiGroupVersion("v1")
    .withPlural("deployments"));
  this.type = Deployment .class;
  this.listType = DeploymentList.class;
  this.doneableType = DoneableDeployment.class;
}
 
@Override
public DoneableDeployment edit() {
  if (isCascading()) {
    return cascading(false).edit();
  }
  return super.edit();
}
 
@Override
protected void removeDeploymentKey(DoneableDeployment obj) {
  obj.editSpec()
    .editSelector().removeFromMatchLabels(DEPLOYMENT_KEY).endSelector()
    .editTemplate().editMetadata().removeFromLabels(DEPLOYMENT_KEY).endMetadata().endTemplate()
    .endSpec();
}
 
@Override
protected MixedOperation<Deployment, DeploymentList, DoneableDeployment, RollableScalableResource<Deployment, DoneableDeployment>> operation() {
    return client.apps().deployments();
}
 
public DeploymentMockBuilder(Map<String, Deployment> depDb, MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> mockPods) {
    super(Deployment.class, DeploymentList.class, DoneableDeployment.class, castClass(RollableScalableResource.class), depDb);
    this.mockPods = mockPods;
}
 
public static DoneableDeployment deployKafkaClients(String kafkaClusterName) {
    return deployKafkaClients(false, kafkaClusterName, null);
}
 
public static DoneableDeployment deployKafkaClients(boolean tlsListener, String kafkaClientsName,  KafkaUser... kafkaUsers) {
    return deployKafkaClients(tlsListener, kafkaClientsName, true, kafkaUsers);
}
 
public static DoneableDeployment consumerWithTracing(String bootstrapServer) {
    String consumerName = "hello-world-consumer";

    Map<String, String> consumerLabels = new HashMap<>();
    consumerLabels.put("app", consumerName);

    return KubernetesResource.deployNewDeployment(new DeploymentBuilder()
                .withNewMetadata()
                    .withNamespace(ResourceManager.kubeClient().getNamespace())
                    .withLabels(consumerLabels)
                    .withName(consumerName)
                .endMetadata()
                .withNewSpec()
                    .withNewSelector()
                        .withMatchLabels(consumerLabels)
                    .endSelector()
                    .withReplicas(1)
                    .withNewTemplate()
                        .withNewMetadata()
                            .withLabels(consumerLabels)
                        .endMetadata()
                        .withNewSpec()
                            .withContainers()
                            .addNewContainer()
                                .withName(consumerName)
                                .withImage("strimzi/" + consumerName + ":latest")
                                .addNewEnv()
                                    .withName("BOOTSTRAP_SERVERS")
                                    .withValue(bootstrapServer)
                                  .endEnv()
                                .addNewEnv()
                                    .withName("TOPIC")
                                    .withValue("my-topic")
                                .endEnv()
                                .addNewEnv()
                                    .withName("GROUP_ID")
                                    .withValue("my-" + consumerName)
                                .endEnv()
                                .addNewEnv()
                                    .withName("DELAY_MS")
                                    .withValue("1000")
                                .endEnv()
                                .addNewEnv()
                                    .withName("LOG_LEVEL")
                                    .withValue("INFO")
                                .endEnv()
                                .addNewEnv()
                                    .withName("MESSAGE_COUNT")
                                    .withValue("1000000")
                                .endEnv()
                                .addNewEnv()
                                    .withName("JAEGER_SERVICE_NAME")
                                    .withValue(consumerName)
                                .endEnv()
                                .addNewEnv()
                                    .withName("JAEGER_AGENT_HOST")
                                    .withValue("my-jaeger-agent")
                                .endEnv()
                                .addNewEnv()
                                    .withName("JAEGER_SAMPLER_TYPE")
                                    .withValue("const")
                                .endEnv()
                                .addNewEnv()
                                    .withName("JAEGER_SAMPLER_PARAM")
                                    .withValue("1")
                                .endEnv()
                            .endContainer()
                        .endSpec()
                    .endTemplate()
                .endSpec()
                .build());
}
 
public static DoneableDeployment producerWithTracing(String bootstrapServer) {
    String producerName = "hello-world-producer";

    Map<String, String> producerLabels = new HashMap<>();
    producerLabels.put("app", producerName);

    return KubernetesResource.deployNewDeployment(new DeploymentBuilder()
        .withNewMetadata()
            .withNamespace(ResourceManager.kubeClient().getNamespace())
            .withLabels(producerLabels)
            .withName(producerName)
        .endMetadata()
        .withNewSpec()
            .withNewSelector()
                .withMatchLabels(producerLabels)
            .endSelector()
            .withReplicas(1)
            .withNewTemplate()
                .withNewMetadata()
                    .withLabels(producerLabels)
                .endMetadata()
                .withNewSpec()
                    .withContainers()
                    .addNewContainer()
                        .withName(producerName)
                        .withImage("strimzi/" + producerName + ":latest")
                        .addNewEnv()
                            .withName("BOOTSTRAP_SERVERS")
                            .withValue(bootstrapServer)
                          .endEnv()
                        .addNewEnv()
                            .withName("TOPIC")
                            .withValue("my-topic")
                        .endEnv()
                        .addNewEnv()
                            .withName("DELAY_MS")
                            .withValue("1000")
                        .endEnv()
                        .addNewEnv()
                            .withName("LOG_LEVEL")
                            .withValue("INFO")
                        .endEnv()
                        .addNewEnv()
                            .withName("MESSAGE_COUNT")
                            .withValue("1000000")
                        .endEnv()
                        .addNewEnv()
                            .withName("JAEGER_SERVICE_NAME")
                            .withValue(producerName)
                        .endEnv()
                        .addNewEnv()
                            .withName("JAEGER_AGENT_HOST")
                            .withValue("my-jaeger-agent")
                        .endEnv()
                        .addNewEnv()
                            .withName("JAEGER_SAMPLER_TYPE")
                            .withValue("const")
                        .endEnv()
                        .addNewEnv()
                            .withName("JAEGER_SAMPLER_PARAM")
                            .withValue("1")
                        .endEnv()
                    .endContainer()
                .endSpec()
            .endTemplate()
        .endSpec()
        .build());
}
 
public static DoneableDeployment kafkaStreamsWithTracing(String bootstrapServer) {
    String kafkaStreamsName = "hello-world-streams";

    Map<String, String> kafkaStreamLabels = new HashMap<>();
    kafkaStreamLabels.put("app", kafkaStreamsName);

    return KubernetesResource.deployNewDeployment(new DeploymentBuilder()
        .withNewMetadata()
            .withNamespace(ResourceManager.kubeClient().getNamespace())
            .withLabels(kafkaStreamLabels)
            .withName(kafkaStreamsName)
        .endMetadata()
        .withNewSpec()
            .withNewSelector()
                .withMatchLabels(kafkaStreamLabels)
            .endSelector()
            .withReplicas(1)
            .withNewTemplate()
                .withNewMetadata()
                    .withLabels(kafkaStreamLabels)
                .endMetadata()
                .withNewSpec()
                    .withContainers()
                    .addNewContainer()
                        .withName(kafkaStreamsName)
                        .withImage("strimzi/" + kafkaStreamsName + ":latest")
                        .addNewEnv()
                            .withName("BOOTSTRAP_SERVERS")
                            .withValue(bootstrapServer)
                          .endEnv()
                        .addNewEnv()
                            .withName("APPLICATION_ID")
                            .withValue(kafkaStreamsName)
                        .endEnv()
                        .addNewEnv()
                            .withName("SOURCE_TOPIC")
                            .withValue("my-topic")
                        .endEnv()
                        .addNewEnv()
                            .withName("TARGET_TOPIC")
                            .withValue("cipot-ym")
                        .endEnv()
                          .addNewEnv()
                            .withName("LOG_LEVEL")
                            .withValue("INFO")
                        .endEnv()
                        .addNewEnv()
                            .withName("JAEGER_SERVICE_NAME")
                            .withValue(kafkaStreamsName)
                        .endEnv()
                        .addNewEnv()
                            .withName("JAEGER_AGENT_HOST")
                            .withValue("my-jaeger-agent")
                        .endEnv()
                        .addNewEnv()
                            .withName("JAEGER_SAMPLER_TYPE")
                            .withValue("const")
                        .endEnv()
                        .addNewEnv()
                            .withName("JAEGER_SAMPLER_PARAM")
                            .withValue("1")
                        .endEnv()
                    .endContainer()
                .endSpec()
            .endTemplate()
        .endSpec()
        .build());
}
 
public static DoneableDeployment deployKeycloak() {
    String keycloakName = "keycloak";

    Map<String, String> keycloakLabels = new HashMap<>();
    keycloakLabels.put("app", keycloakName);

    return KubernetesResource.deployNewDeployment(new DeploymentBuilder()
        .withNewMetadata()
            .withNamespace(ResourceManager.kubeClient().getNamespace())
            .withLabels(keycloakLabels)
            .withName(keycloakName)
        .endMetadata()
        .withNewSpec()
            .withNewSelector()
                .withMatchLabels(keycloakLabels)
            .endSelector()
            .withReplicas(1)
            .withNewTemplate()
                .withNewMetadata()
                    .withLabels(keycloakLabels)
                .endMetadata()
                .withNewSpec()
                    .withContainers()
                    .addNewContainer()
                        .withName(keycloakName + "pod")
                        .withImage("jboss/keycloak:8.0.1")
                        .withPorts(
                            new ContainerPortBuilder()
                                .withName("http")
                                .withContainerPort(8080)
                                .build(),
                            new ContainerPortBuilder()
                                .withName("https")
                                .withContainerPort(8443)
                                .build()
                        )
                        .addNewEnv()
                            .withName("KEYCLOAK_USER")
                            .withValue("admin")
                        .endEnv()
                        .addNewEnv()
                            .withName("KEYCLOAK_PASSWORD")
                            .withValue("admin")
                        .endEnv()
                        // for enabling importing authorization script
                        .withArgs("-Dkeycloak.profile.feature.upload_scripts=enabled")
                    .endContainer()
                .endSpec()
            .endTemplate()
        .endSpec()
        .build());
}
 
public static DoneableDeployment clusterOperator(String namespace, long operationTimeout) {
    return deployNewDeployment(defaultCLusterOperator(namespace, operationTimeout, Constants.RECONCILIATION_INTERVAL).build());
}
 
public static DoneableDeployment clusterOperator(String namespace, long operationTimeout, long reconciliationInterval) {
    return deployNewDeployment(defaultCLusterOperator(namespace, operationTimeout, reconciliationInterval).build());
}
 
public static DoneableDeployment clusterOperator(String namespace) {
    return deployNewDeployment(defaultCLusterOperator(namespace, Constants.CO_OPERATION_TIMEOUT_DEFAULT, Constants.RECONCILIATION_INTERVAL).build());
}
 
源代码19 项目: kubernetes-client   文件: ExtensionsAPIGroupDSL.java
@Deprecated
MixedOperation<Deployment, DeploymentList, DoneableDeployment, RollableScalableResource<Deployment, DoneableDeployment>> deployments();
 
@Override
public RollingUpdater<Deployment, DeploymentList, DoneableDeployment> getRollingUpdater(long rollingTimeout, TimeUnit rollingTimeUnit) {
  return new DeploymentRollingUpdater(client, config, getNamespace(), rollingTimeUnit.toMillis(rollingTimeout), config.getLoggingInterval());
}
 
@Override
public ImageEditReplacePatchable<Deployment, Deployment, DoneableDeployment> withTimeoutInMillis(long timeoutInMillis) {
  return new DeploymentOperationsImpl(((RollingOperationContext)context).withRollingTimeout(timeoutInMillis));
}
 
@Override
public ImageEditReplacePatchable<Deployment, Deployment, DoneableDeployment> withTimeout(long timeout, TimeUnit unit) {
  return new DeploymentOperationsImpl(((RollingOperationContext)context).withRollingTimeUnit(unit));
}
 
@Override
protected void updateDeploymentKey(DoneableDeployment obj, String hash) {
  obj.editSpec()
    .editTemplate().editMetadata().addToAnnotations(DEPLOYMENT_KEY, hash).endMetadata().endTemplate()
    .endSpec();
}
 
@Override
protected Operation<Deployment, DeploymentList, DoneableDeployment, RollableScalableResource<Deployment, DoneableDeployment>> resources() {
  return new DeploymentOperationsImpl(client, config);
}
 
@Override
@Deprecated
public MixedOperation<Deployment, DeploymentList, DoneableDeployment, RollableScalableResource<Deployment, DoneableDeployment>> deployments() {
  return new DeploymentOperationsImpl(httpClient, getConfiguration());
}
 
源代码26 项目: kubernetes-client   文件: AppsAPIGroupClient.java
@Override
public MixedOperation<Deployment, DeploymentList, DoneableDeployment, RollableScalableResource<Deployment, DoneableDeployment>> deployments() {
  return new DeploymentOperationsImpl(httpClient, getConfiguration());
}
 
源代码27 项目: kubernetes-client   文件: AppsAPIGroupDSL.java
MixedOperation<Deployment, DeploymentList, DoneableDeployment, RollableScalableResource<Deployment, DoneableDeployment>> deployments();