下面列出了io.fabric8.kubernetes.api.model.EnvVarBuilder#io.fabric8.kubernetes.api.model.apps.DeploymentBuilder 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private KubernetesListBuilder addDeployment(KubernetesListBuilder list, String name) {
return list.addToItems(new DeploymentBuilder()
.withNewMetadata()
.withName(name)
.endMetadata()
.withNewSpec()
.withNewTemplate()
.withNewSpec()
.addNewContainer()
.withName(name)
.endContainer()
.endSpec()
.endTemplate()
.endSpec()
.build());
}
@Override
public void visit(DeploymentBuilder deploymentBuilder) {
deploymentBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
mergeDeploymentSpec(deploymentBuilder, spec);
}
});
if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
final PodSpec podSpec = spec.getTemplate().getSpec();
builder.accept(new TypedVisitor<PodSpecBuilder>() {
@Override
public void visit(PodSpecBuilder builder) {
String defaultApplicationContainerName = KubernetesResourceUtil.mergePodSpec(builder, podSpec, name, getValueFromConfig(SIDECAR, false));
if(defaultApplicationContainerName != null) {
setProcessingInstruction(NEED_IMAGECHANGE_TRIGGERS, Collections.singletonList(defaultApplicationContainerName));
}
}
});
}
@Test
public void testGeneratedResources() {
ProjectLabelEnricher projectEnricher = new ProjectLabelEnricher(context);
KubernetesListBuilder builder = createListWithDeploymentConfig();
projectEnricher.enrich(PlatformMode.kubernetes, builder);
KubernetesList list = builder.build();
Map<String, String> labels = list.getItems().get(0).getMetadata().getLabels();
assertNotNull(labels);
assertEquals("groupId", labels.get("group"));
assertEquals("artifactId", labels.get("app"));
assertEquals("version", labels.get("version"));
assertNull(labels.get("project"));
builder = new KubernetesListBuilder().withItems(new DeploymentBuilder().build());
projectEnricher.create(PlatformMode.kubernetes, builder);
Deployment deployment = (Deployment)builder.buildFirstItem();
Map<String, String> selectors = deployment.getSpec().getSelector().getMatchLabels();
assertEquals("groupId", selectors.get("group"));
assertEquals("artifactId", selectors.get("app"));
assertNull(selectors.get("version"));
assertNull(selectors.get("project"));
}
@Test
public void shouldContainServiceInstanceAndBinding() {
KubernetesList list = Serialization.unmarshalAsList(ServiceCatalogExampleTest.class.getClassLoader().getResourceAsStream("META-INF/dekorate/kubernetes.yml"));
assertNotNull(list);
assertTrue(findFirst(list, ServiceInstance.class).isPresent());
assertTrue(findFirst(list, ServiceBinding.class).isPresent());
Optional<Deployment> deployment = findFirst(list, Deployment.class);
assertTrue(deployment.isPresent());
AtomicBoolean hasBindingEnv = new AtomicBoolean(false);
new DeploymentBuilder(deployment.get()).accept(new TypedVisitor<EnvFromSourceFluent>() {
@Override
public void visit(EnvFromSourceFluent env) {
if (env.hasSecretRef()) {
hasBindingEnv.set(true);
}
}
});
assertTrue(hasBindingEnv.get());
}
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);
}
@Test
public void shouldUseDeploymentNameAsPodTemplateNameIfItIsMissing() throws Exception {
// given
PodTemplateSpec podTemplate = new PodTemplateSpecBuilder().withNewSpec().endSpec().build();
Deployment deployment =
new DeploymentBuilder()
.withNewMetadata()
.withName("deployment-test")
.endMetadata()
.withNewSpec()
.withTemplate(podTemplate)
.endSpec()
.build();
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(deployment));
// when
final KubernetesEnvironment k8sEnv =
osEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
// then
Deployment deploymentTest = k8sEnv.getDeploymentsCopy().get("deployment-test");
assertNotNull(deploymentTest);
PodTemplateSpec resultPodTemplate = deploymentTest.getSpec().getTemplate();
assertEquals(resultPodTemplate.getMetadata().getName(), "deployment-test");
}
private static Deployment mockDeployment(List<Container> containers) {
final Deployment deployment =
new DeploymentBuilder()
.withNewMetadata()
.withName(WORKSPACE_POD_NAME)
.withLabels(
ImmutableMap.of(
POD_SELECTOR, WORKSPACE_POD_NAME, CHE_ORIGINAL_NAME_LABEL, WORKSPACE_POD_NAME))
.endMetadata()
.withNewSpec()
.withNewTemplate()
.withNewSpec()
.withContainers(containers)
.endSpec()
.withNewMetadata()
.withName(WORKSPACE_POD_NAME)
.withLabels(
ImmutableMap.of(
POD_SELECTOR, WORKSPACE_POD_NAME, CHE_ORIGINAL_NAME_LABEL, WORKSPACE_POD_NAME))
.endMetadata()
.endTemplate()
.endSpec()
.build();
return deployment;
}
@Test
public void shouldUseDeploymentNameAsPodTemplateNameIfItIsMissing() throws Exception {
// given
PodTemplateSpec podTemplate = new PodTemplateSpecBuilder().withNewSpec().endSpec().build();
Deployment deployment =
new DeploymentBuilder()
.withNewMetadata()
.withName("deployment-test")
.endMetadata()
.withNewSpec()
.withTemplate(podTemplate)
.endSpec()
.build();
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(deployment));
// when
final KubernetesEnvironment k8sEnv =
k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
// then
Deployment deploymentTest = k8sEnv.getDeploymentsCopy().get("deployment-test");
assertNotNull(deploymentTest);
PodTemplateSpec resultPodTemplate = deploymentTest.getSpec().getTemplate();
assertEquals(resultPodTemplate.getMetadata().getName(), "deployment-test");
}
@Test
@DisplayName("Should delete a Deployment with PropagationPolicy=Background")
void testDeleteDeployment() throws InterruptedException {
// Given
server.expect().delete().withPath("/apis/apps/v1/namespaces/ns1/deployments/mydeployment")
.andReturn(HttpURLConnection.HTTP_OK, new DeploymentBuilder().build())
.once();
KubernetesClient client = server.getClient();
// When
Boolean isDeleted = client.apps().deployments().inNamespace("ns1").withName("mydeployment").delete();
// Then
assertTrue(isDeleted);
assertDeleteOptionsInLastRecordedRequest(DeletionPropagation.BACKGROUND.toString(), server.getLastRequest());
}
@Test
@DisplayName("Should delete a Deployment with explicitly set PropagationPolicy")
void testDeleteDeploymentWithExplicitPropagationPolicy() throws InterruptedException {
// Given
server.expect().delete().withPath("/apis/apps/v1/namespaces/ns1/deployments/mydeployment")
.andReturn(HttpURLConnection.HTTP_OK, new DeploymentBuilder().build())
.once();
KubernetesClient client = server.getClient();
// When
Boolean isDeleted = client.apps().deployments().inNamespace("ns1").withName("mydeployment").withPropagationPolicy(DeletionPropagation.FOREGROUND).delete();
// Then
assertTrue(isDeleted);
assertDeleteOptionsInLastRecordedRequest(DeletionPropagation.FOREGROUND.toString(), server.getLastRequest());
}
@Test
public void testGet() {
server.expect().withPath("/apis/apps/v1/namespaces/test/deployments/deployment1").andReturn(200, new DeploymentBuilder().build()).once();
server.expect().withPath("/apis/apps/v1/namespaces/ns1/deployments/deployment2").andReturn(200, new DeploymentBuilder().build()).once();
KubernetesClient client = server.getClient();
Deployment deployment = client.apps().deployments().withName("deployment1").get();
assertNotNull(deployment);
deployment = client.apps().deployments().withName("deployment2").get();
assertNull(deployment);
deployment = client.apps().deployments().inNamespace("ns1").withName("deployment2").get();
assertNotNull(deployment);
}
@Test
public void testCreate() {
Deployment deployment1 = new DeploymentBuilder().withNewMetadata().withName("deployment1").withNamespace("test").endMetadata()
.withNewSpec()
.withReplicas(1)
.endSpec()
.build();
server.expect().post().withPath("/apis/apps/v1/namespaces/test/deployments")
.andReturn(200, deployment1)
.once();
KubernetesClient client = server.getClient();
Deployment result = client.apps().deployments().inNamespace("test").create(deployment1);
assertNotNull(result);
assertEquals("deployment1", result.getMetadata().getName());
}
@Test
public void testCreateMulti() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
Deployment deployment1 = new DeploymentBuilder().withNewMetadata().withName("deployment1").withNamespace("test").endMetadata()
.withNewSpec()
.withReplicas(1)
.endSpec()
.build();
Deployment deployment2 = new DeploymentBuilder().withNewMetadata().withName("deployment1").withNamespace("test").endMetadata()
.withNewSpec()
.withReplicas(1)
.endSpec()
.build();
server.expect().post().withPath("/apis/apps/v1/namespaces/test/deployments")
.andReturn(200, deployment1)
.once();
KubernetesClient client = server.getClient();
// Will throw exception
client.apps().deployments().inNamespace("test").create(deployment1, deployment2);
});
assertEquals("Too many items to create.", exception.getMessage());
}
private DeploymentBuilder getDeploymentBuilder() {
return new DeploymentBuilder()
.withNewMetadata()
.withName("deploy1")
.addToLabels("app", "nginx")
.addToAnnotations("app", "nginx")
.endMetadata()
.withNewSpec()
.withReplicas(1)
.withNewSelector()
.addToMatchLabels("app", "nginx")
.endSelector()
.withNewTemplate()
.withNewMetadata().addToLabels("app", "nginx").endMetadata()
.withNewSpec()
.addNewContainer()
.withName("nginx")
.withImage("nginx:1.7.9")
.addNewPort().withContainerPort(80).endPort()
.endContainer()
.endSpec()
.endTemplate()
.endSpec();
}
@Test
public void enrichSingleContainer() {
KubernetesListBuilder list = new KubernetesListBuilder().addToItems(new DeploymentBuilder()
.withNewSpec()
.withNewTemplate()
.withNewSpec()
.addNewContainer()
.withName("app")
.withImage("app:latest")
.endContainer()
.endSpec()
.endTemplate()
.endSpec()
.build());
createEnricher(new Properties(), Collections.emptyMap()).create(PlatformMode.kubernetes, list);
final AtomicInteger containerFound = new AtomicInteger(0);
list.accept(new TypedVisitor<ContainerBuilder>() {
@Override
public void visit(ContainerBuilder container) {
assertNotNull(container.build().getLivenessProbe());
assertNotNull(container.build().getReadinessProbe());
containerFound.incrementAndGet();
}
});
assertEquals(1, containerFound.get());
}
@Test
public void enrichContainerWithSidecar() {
KubernetesListBuilder list = new KubernetesListBuilder().addToItems(new DeploymentBuilder()
.withNewSpec()
.withNewTemplate()
.withNewSpec()
.addNewContainer()
.withName("app")
.withImage("app:latest")
.endContainer()
.addNewContainer()
.withName("sidecar")
.withImage("sidecar:latest")
.endContainer()
.endSpec()
.endTemplate()
.endSpec()
.build());
createEnricher(new Properties(), Collections.singletonMap("FABRIC8_GENERATED_CONTAINERS", "app")).create(PlatformMode.kubernetes, list);
final AtomicInteger containerFound = new AtomicInteger(0);
list.accept(new TypedVisitor<ContainerBuilder>() {
@Override
public void visit(ContainerBuilder container) {
if (container.getName().equals("app")) {
assertNotNull(container.build().getLivenessProbe());
assertNotNull(container.build().getReadinessProbe());
containerFound.incrementAndGet();
} else if (container.getName().equals("sidecar")) {
assertNull(container.build().getLivenessProbe());
assertNull(container.build().getReadinessProbe());
containerFound.incrementAndGet();
}
}
});
assertEquals(2, containerFound.get());
}
public Deployment getDeployment(ResourceConfig config,
List<ImageConfiguration> images) {
Deployment deployment = new DeploymentBuilder()
.withMetadata(createDeploymentMetaData(config))
.withSpec(createDeploymentSpec(config, images))
.build();
return deployment;
}
private String getServiceAccountNameFromSpec(DeploymentBuilder builder) {
if(builder.buildSpec().getTemplate().getSpec().getServiceAccountName() != null) {
return builder.buildSpec().getTemplate().getSpec().getServiceAccountName();
}
if(builder.buildSpec().getTemplate().getSpec().getServiceAccount() != null) {
return builder.buildSpec().getTemplate().getSpec().getServiceAccount();
}
return null;
}
private void ensureTemplateSpecsInDeployments(KubernetesListBuilder builder) {
builder.accept(new TypedVisitor<DeploymentBuilder>() {
@Override
public void visit(DeploymentBuilder item) {
DeploymentFluent.SpecNested<DeploymentBuilder> spec =
item.buildSpec() == null ? item.withNewSpec() : item.editSpec();
DeploymentSpecFluent.TemplateNested<DeploymentFluent.SpecNested<DeploymentBuilder>> template =
spec.buildTemplate() == null ? spec.withNewTemplate() : spec.editTemplate();
template.endTemplate().endSpec();
}
});
}
@Test
public void testServiceAccountCreationFromFragment() {
final KubernetesListBuilder builder = new KubernetesListBuilder()
.withItems(new DeploymentBuilder().withNewMetadata().withName("cheese").endMetadata()
.withNewSpec().withNewTemplate().withNewSpec()
.addNewContainer().withImage("cheese-image").endContainer()
.withServiceAccount("ribbon")
.endSpec().endTemplate().endSpec().build());
enrichAndAssert(builder);
}
@Test
public void testDefaultRevisionHistoryLimit() throws JsonProcessingException {
// Given
KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new DeploymentBuilder().build());
RevisionHistoryEnricher enricher = new RevisionHistoryEnricher(context);
// When
enricher.create(PlatformMode.kubernetes, builder);
// Then
assertRevisionHistory(builder.build(), Configs.asInt(RevisionHistoryEnricher.Config.limit.def()));
}
@Test
public void checkEnrichDeployment() throws Exception {
KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new DeploymentBuilder().build());
imageEnricher.create(PlatformMode.kubernetes, builder);
assertCorrectlyGeneratedResources(builder.build(), "Deployment");
}
private Deployment getDeployment(SparkHistoryServer hs, Map<String, String> labels) {
String volumeName = "history-server-volume";
ContainerBuilder containerBuilder = new ContainerBuilder().withName("history-server")
.withImage(Optional.ofNullable(hs.getCustomImage()).orElse(getDefaultSparkImage()))
.withCommand(Arrays.asList("/bin/sh", "-xc"))
.withArgs("mkdir /tmp/spark-events || true ; /entrypoint ls ; /opt/spark/bin/spark-class org.apache.spark.deploy.history.HistoryServer")
.withEnv(env("SPARK_HISTORY_OPTS", getHistoryOpts(hs)))
.withPorts(new ContainerPortBuilder().withName("web-ui").withContainerPort(hs.getInternalPort()).build());
if (HistoryServerHelper.needsVolume(hs) && null != hs.getSharedVolume()) {
containerBuilder = containerBuilder.withVolumeMounts(new VolumeMountBuilder().withName(volumeName).withMountPath(hs.getSharedVolume().getMountPath()).build());
}
Container historyServerContainer = containerBuilder.build();
PodTemplateSpecFluent.SpecNested<DeploymentSpecFluent.TemplateNested<DeploymentFluent.SpecNested<DeploymentBuilder>>> deploymentBuilder = new DeploymentBuilder()
.withNewMetadata().withName(hs.getName()).withLabels(labels).endMetadata()
.withNewSpec().withReplicas(1).withNewSelector().withMatchLabels(labels).endSelector()
.withNewStrategy().withType("Recreate").endStrategy()
.withNewTemplate().withNewMetadata().withLabels(labels).endMetadata()
.withNewSpec().withServiceAccountName("spark-operator")
.withContainers(historyServerContainer);
if (HistoryServerHelper.needsVolume(hs) && null != hs.getSharedVolume()) {
deploymentBuilder = deploymentBuilder.withVolumes(new VolumeBuilder().withName(volumeName).withNewPersistentVolumeClaim()
.withReadOnly(false).withClaimName(hs.getName() + "-claim").endPersistentVolumeClaim().build());
}
Deployment deployment = deploymentBuilder.endSpec().endTemplate().endSpec().build();
return deployment;
}
/**
* Creates a {@link Deployment} for the {@link KubernetesConfig}.
* @param appConfig The session.
* @return The deployment.
*/
public Deployment createDeployment(KubernetesConfig appConfig, ImageConfiguration imageConfig) {
return new DeploymentBuilder()
.withNewMetadata()
.withName(appConfig.getName())
.withLabels(Labels.createLabels(appConfig))
.endMetadata()
.withNewSpec()
.withReplicas(1)
.withTemplate(createPodTemplateSpec(appConfig, imageConfig))
.withSelector(createSelector(appConfig))
.endSpec()
.build();
}
@Override
public void visit(DeploymentBuilder deployment) {
if (name.equals(deployment.getMetadata().getName())) {
deployment.accept(new Decorator<ContainerFluent>() {
@Override
public void visit(ContainerFluent container) {
if (container.getName().equals(name)) {
String image = Images.getImage(registry, group, name, version);
container.withImage(image);
}
}
});
}
}
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).getAgentNamePrefix(); will(returnValue("agent-name-prefix"));
allowing(image).findInstanceById(with("agent-name-prefix-1")); will(returnValue(null));
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(myNameGenerator.generateNewVmName(image), instanceTag, image, clientParams);
assertNotNull(podTemplate);
assertNotNull(podTemplate.getMetadata());
assertNotNull(podTemplate.getSpec());
}
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).getAgentNamePrefix(); will(returnValue("agent-name-prefix"));
allowing(image).findInstanceById(with("agent-name-prefix-1")); will(returnValue(null));
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(myNameGenerator.generateNewVmName(image), instanceTag, image, clientParams);
for(Container container : podTemplate.getSpec().getContainers()){
assertNotSame(container.getName(), "agent name");
}
}
private static Deployment getMessagingAppDeploymentResource() {
return new DeploymentBuilder()
.withNewMetadata()
.withName(MESSAGING_CLIENTS)
.endMetadata()
.withNewSpec()
.withNewSelector()
.addToMatchLabels("app", MESSAGING_CLIENTS)
.endSelector()
.withReplicas(1)
.withNewTemplate()
.withNewMetadata()
.addToLabels("app", MESSAGING_CLIENTS)
.endMetadata()
.withNewSpec()
.addNewContainer()
.withName(MESSAGING_CLIENTS)
.withImage("quay.io/enmasse/systemtests-clients:latest")
.withImagePullPolicy(env.getImagePullPolicy())
.withCommand("sleep")
.withArgs("infinity")
.withEnv(new EnvVarBuilder().withName("PN_TRACE_FRM").withValue("true").build())
.endContainer()
.endSpec()
.endTemplate()
.endSpec()
.build();
}
private static Deployment getMessagingAppDeploymentResource(String namespace) {
return new DeploymentBuilder(getMessagingAppDeploymentResource())
.editMetadata()
.withName(namespace)
.endMetadata()
.editSpec()
.withNewSelector()
.addToMatchLabels("app", namespace)
.endSelector()
.editTemplate()
.withNewMetadata()
.addToLabels("app", namespace)
.endMetadata()
.endTemplate()
.endSpec()
.build();
/*
* return new DoneableDeployment(getMessagingAppDeploymentResource())
* .editMetadata()
* .withName(namespace)
* .endMetadata()
* .editSpec()
* .withNewSelector()
* .addToMatchLabels("app", namespace)
* .endSelector()
* .editTemplate()
* .withNewMetadata()
* .addToLabels("app", namespace)
* .endMetadata()
* .endTemplate()
* .endSpec()
* .done();
*/
}
private static Deployment getProxyApiAppDeploymentResource() {
return new DeploymentBuilder()
.withNewMetadata()
.withName(API_PROXY)
.addToLabels("app", API_PROXY)
.endMetadata()
.withNewSpec()
.withNewSelector()
.addToMatchLabels("app", API_PROXY)
.endSelector()
.withReplicas(1)
.withNewTemplate()
.withNewMetadata()
.addToLabels("app", API_PROXY)
.endMetadata()
.withNewSpec()
.addNewContainer()
.withName(API_PROXY)
.withImage("quay.io/enmasse/api-proxy:latest")
.withPorts(new ContainerPortBuilder().withContainerPort(8443).withName("https").withProtocol("TCP").build())
.withVolumeMounts(new VolumeMountBuilder().withMountPath("/etc/tls/private").withName("api-proxy-tls").withReadOnly(true).build())
.endContainer()
.withVolumes(Collections.singletonList(new VolumeBuilder().withName("api-proxy-tls").withSecret(new SecretVolumeSourceBuilder().withDefaultMode(420).withSecretName("api-proxy-cert").build()).build()))
.endSpec()
.endTemplate()
.endSpec()
.build();
}