• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DeploymentBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: build

import io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder; //导入依赖的package包/类
public ResourceDeployment build() {
    ArrayList<Container> containers = new ArrayList<>();

    pod.getContainers().forEach(e -> {
        Container container = new ContainerBuilder()
            .withImage(e.getDockerImageTag().get())
            .withName(e.getCleanStackName())
            .addAllToPorts(e.getOpenPorts().stream().map(Port::toContainerPort).collect(Collectors.toList()))
            .build();
        
        containers.add(container);
    });

    deployment = new DeploymentBuilder()
        .withNewMetadata()
        .withName(name + "-deployment")
        .addToLabels("app", name)
        .endMetadata()
        .withNewSpec()
        .withNewSelector()
        .addToMatchLabels("app", name)
        .endSelector()
        .withNewTemplate()
        .withNewMetadata()
        .withName(name)
        .addToLabels("app", name)
        .endMetadata()
        .withNewSpec()
        .addAllToContainers(containers)
        .endSpec()
        .endTemplate()
        .endSpec().build();
    return this;
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:35,代码来源:ResourceDeployment.java


示例2: createDeployment

import io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder; //导入依赖的package包/类
/**
 * Creates a Kubernetes deployment.
 *
 * @param deployment  the deployment to be created
 * @return  the unique identifier of the deployment
 * @throws VmidcException  if a K8s SDK specific exception is caught
 */
public String createDeployment(KubernetesDeployment deployment) throws VmidcException {
    if (deployment == null) {
        throw new IllegalArgumentException("The deployment should not be null");
    }

    try {
        Deployment newDeployment = new DeploymentBuilder()
                .withKind("Deployment")
                .withNewMetadata()
                .withName(deployment.getName())
                .endMetadata()
                .withNewSpec()
                .withReplicas(deployment.getDesiredReplicaCount())
                .withNewTemplate()
                .withNewMetadata()
                .addToLabels(OSC_DEPLOYMENT_LABEL_NAME, deployment.getName())
                .endMetadata()
                .withNewSpec()
                .addNewContainer()
                .withName(deployment.getName()).withImage(deployment.getContainerImageName())
                .endContainer()
                .endSpec()
                .endTemplate()
                .endSpec()
                .build();

        Deployment result = getKubernetesClient().extensions().deployments().inNamespace(deployment.getNamespace()).create(newDeployment);

        return result.getMetadata().getUid();

    } catch (KubernetesClientException e) {
        throw new VmidcException(String.format("Failed to create a deployment %s", e));
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:42,代码来源:KubernetesDeploymentApi.java


示例3: testGetPodTemplate

import io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder; //导入依赖的package包/类
@Test
public void testGetPodTemplate() throws Exception {
    CloudInstanceUserData instanceTag = createInstanceTag();
    KubeCloudClientParameters clientParams = m.mock(KubeCloudClientParameters.class);
    KubeCloudImage image = m.mock(KubeCloudImage.class);
    Deployment deployment = new DeploymentBuilder()
            .withMetadata(new ObjectMetaBuilder()
                    .withLabels(CollectionsUtil.asMap("app", "nginx"))
                    .build())
            .withSpec(new DeploymentSpecBuilder()
                    .withTemplate(new PodTemplateSpecBuilder()
                            .withMetadata(new ObjectMeta())
                            .withSpec(new PodSpecBuilder()
                                    .withContainers(new ContainerBuilder()
                                            .withName("nginx")
                                            .withImage("nginx:1.7.9")
                                            .withPorts(new ContainerPortBuilder()
                                                    .withHostPort(80)
                                                    .build())
                                            .build())
                                    .build())
                            .build())
                    .build())
            .build();
    m.checking(new Expectations(){{
        allowing(clientParams).getNamespace(); will(returnValue("custom namespace"));
        allowing(clientParams).getAuthStrategy(); will(returnValue(UnauthorizedAccessStrategy.ID));
        allowing(image).getId(); will(returnValue("my image id"));
        allowing(image).getName(); will(returnValue("my image name"));
        allowing(image).getSourceDeploymentName(); will(returnValue("deploymentFoo"));
        allowing(image).getAgentName(with("agent name")); will(returnValue("prefix agent name"));
        allowing(myDeploymentContentProvider).findDeployment(with(any(String.class)), with(any(KubeCloudClientParameters.class))); will(returnValue(deployment));
    }});
    Pod podTemplate = myPodTemplateProvider.getPodTemplate(instanceTag, image, clientParams);
    assertNotNull(podTemplate);
    assertNotNull(podTemplate.getMetadata());
    assertNotNull(podTemplate.getSpec());
}
 
开发者ID:JetBrains,项目名称:teamcity-kubernetes-plugin,代码行数:39,代码来源:DeploymentBuildAgentPodTemplateProviderTest.java


示例4: testShouldNotsetContainerName

import io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder; //导入依赖的package包/类
@Test
public void testShouldNotsetContainerName(){
    CloudInstanceUserData instanceTag = createInstanceTag();
    KubeCloudClientParameters clientParams = m.mock(KubeCloudClientParameters.class);
    KubeCloudImage image = m.mock(KubeCloudImage.class);
    Deployment deployment = new DeploymentBuilder()
            .withMetadata(new ObjectMetaBuilder()
                    .withLabels(CollectionsUtil.asMap("app", "nginx"))
                    .build())
            .withSpec(new DeploymentSpecBuilder()
                    .withTemplate(new PodTemplateSpecBuilder()
                            .withMetadata(new ObjectMeta())
                            .withSpec(new PodSpecBuilder()
                                    .withContainers(new ContainerBuilder()
                                            .withName("nginx")
                                            .withImage("nginx:1.7.9")
                                            .withPorts(new ContainerPortBuilder()
                                                    .withHostPort(80)
                                                    .build())
                                            .build())
                                    .build())
                            .build())
                    .build())
            .build();
    m.checking(new Expectations(){{
        allowing(clientParams).getNamespace(); will(returnValue("custom namespace"));
        allowing(image).getId(); will(returnValue("my image id"));
        allowing(image).getName(); will(returnValue("my image name"));
        allowing(image).getSourceDeploymentName(); will(returnValue("deploymentFoo"));
        allowing(image).getAgentName(with("agent name")); will(returnValue("prefix agent name"));
        allowing(myDeploymentContentProvider).findDeployment(with(any(String.class)), with(any(KubeCloudClientParameters.class))); will(returnValue(deployment));
    }});
    Pod podTemplate = myPodTemplateProvider.getPodTemplate(instanceTag, image, clientParams);
    for(Container container : podTemplate.getSpec().getContainers()){
        assertNotSame(container.getName(), "agent name");
    }
}
 
开发者ID:JetBrains,项目名称:teamcity-kubernetes-plugin,代码行数:38,代码来源:DeploymentBuildAgentPodTemplateProviderTest.java


示例5: createDeployment

import io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder; //导入依赖的package包/类
private Deployment createDeployment(String appId, AppDeploymentRequest request, Map<String, String> idMap,
	int externalPort) {

	int replicas = getCountFromRequest(request);

	Deployment d = new DeploymentBuilder().withNewMetadata().withName(appId).withLabels(idMap)
		.addToLabels(SPRING_MARKER_KEY, SPRING_MARKER_VALUE).endMetadata().withNewSpec().withReplicas(replicas)
		.withNewTemplate().withNewMetadata().withLabels(idMap).addToLabels(SPRING_MARKER_KEY, SPRING_MARKER_VALUE)
		.endMetadata().withSpec(createPodSpec(appId, request, Integer.valueOf(externalPort), false)).endTemplate()
		.endSpec().build();

	return client.extensions().deployments().create(d);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:14,代码来源:KubernetesAppDeployer.java


示例6: testDoNotLoseSpecAdditionalProperties

import io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder; //导入依赖的package包/类
@Test
public void testDoNotLoseSpecAdditionalProperties() throws Exception {
    CloudInstanceUserData instanceTag = createInstanceTag();
    KubeCloudClientParameters clientParams = m.mock(KubeCloudClientParameters.class);
    KubeCloudImage image = m.mock(KubeCloudImage.class);

    Deployment deployment = new DeploymentBuilder()
            .withMetadata(new ObjectMetaBuilder()
                    .withLabels(CollectionsUtil.asMap("app", "nginx"))
                    .build())
            .withSpec(new DeploymentSpecBuilder()
                    .withTemplate(new PodTemplateSpecBuilder()
                            .withMetadata(new ObjectMeta())
                            .withSpec(new PodSpecBuilder()
                                    .withContainers(new ContainerBuilder()
                                            .withName("nginx")
                                            .withImage("nginx:1.7.9")
                                            .withPorts(new ContainerPortBuilder()
                                                    .withHostPort(80)
                                                    .build())
                                            .build())
                                    .build())
                            .build())
                    .build())
            .build();

    deployment.getSpec().getTemplate().getSpec().setAdditionalProperty("affinity", "some value");

    m.checking(new Expectations(){{
        allowing(clientParams).getNamespace(); will(returnValue("custom namespace"));
        allowing(image).getId(); will(returnValue("my image id"));
        allowing(image).getName(); will(returnValue("my image name"));
        allowing(image).getSourceDeploymentName(); will(returnValue("deploymentFoo"));
        allowing(image).getAgentName(with("agent name")); will(returnValue("prefix agent name"));
        allowing(myDeploymentContentProvider).findDeployment(with(any(String.class)), with(any(KubeCloudClientParameters.class))); will(returnValue(deployment));
    }});

    Pod podTemplate = myPodTemplateProvider.getPodTemplate(instanceTag, image, clientParams);

    assertNotEmpty(podTemplate.getSpec().getAdditionalProperties().keySet());
}
 
开发者ID:JetBrains,项目名称:teamcity-kubernetes-plugin,代码行数:42,代码来源:DeploymentBuildAgentPodTemplateProviderTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SQLCreateTableStatement类代码示例发布时间:2022-05-23
下一篇:
Java GCInterface类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap