use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project devspaces-images by redhat-developer.
the class KubernetesDeploymentsTest method deploymentShouldHavePullSecretsOnlyOfSelfWithNonexistentSA.
@Test
public void deploymentShouldHavePullSecretsOnlyOfSelfWithNonexistentSA() throws InfrastructureException {
doReturn(serverMock.getClient()).when(clientFactory).create(anyString());
LocalObjectReference pullSecretOfPod = new LocalObjectReferenceBuilder().withName("pullsecret-pod").build();
ObjectMeta objectMeta = new ObjectMetaBuilder().withName("test-pod").withNamespace(kubernetesDeployments.namespace).build();
Deployment deployment = new DeploymentBuilder().withMetadata(objectMeta).withSpec(new DeploymentSpecBuilder().withNewTemplate().withMetadata(objectMeta).withNewSpec().withImagePullSecrets(pullSecretOfPod).withServiceAccountName("nonexistent-sa").endSpec().endTemplate().build()).build();
kubernetesDeployments.addPullSecretsOfSA(deployment);
assertTrue(deployment.getSpec().getTemplate().getSpec().getImagePullSecrets().contains(pullSecretOfPod));
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project kubernetes-client by fabric8io.
the class AppsV1ControllerPodOperationTest method testDeploymentSelectorLabels.
@Test
void testDeploymentSelectorLabels() {
// Given
Deployment deployment = new DeploymentBuilder().withNewSpec().withNewTemplate().withNewMetadata().addToLabels("foo", "bar").addToLabels("one", "two").endMetadata().endTemplate().endSpec().build();
// When
Map<String, String> labels = DeploymentOperationsImpl.getDeploymentSelectorLabels(deployment);
// Then
assertNotNull(labels);
assertEquals(deployment.getSpec().getTemplate().getMetadata().getLabels().size(), labels.size());
assertEquals("bar", labels.get("foo"));
assertEquals("two", labels.get("one"));
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project kubernetes-client by fabric8io.
the class PropagationPolicyTest method testDeleteDeployment.
@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();
// When
Boolean isDeleted = client.apps().deployments().inNamespace("ns1").withName("mydeployment").delete();
// Then
assertTrue(isDeleted);
assertDeleteOptionsInLastRecordedRequest(DeletionPropagation.BACKGROUND.toString(), server.getLastRequest());
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project kubernetes-client by fabric8io.
the class DeploymentRollingUpdater method updateDeploymentKey.
@Override
protected Deployment updateDeploymentKey(String name, String hash) {
Deployment old = resources().inNamespace(namespace).withName(name).get();
Deployment updated = new DeploymentBuilder(old).editSpec().editSelector().addToMatchLabels(DEPLOYMENT_KEY, hash).endSelector().editTemplate().editMetadata().addToLabels(DEPLOYMENT_KEY, hash).endMetadata().endTemplate().endSpec().build();
return resources().inNamespace(namespace).withName(name).replace(updated);
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project kubernetes-client by fabric8io.
the class KubernetesAttributesExtractorTest method getDeploymentsWithAndWithoutLabels.
@Test
void getDeploymentsWithAndWithoutLabels() {
KubernetesServer kubernetesServer = new KubernetesServer(false, true);
kubernetesServer.before();
KubernetesClient kubernetesClient = kubernetesServer.getClient();
Map<String, String> labels = new HashMap<>();
labels.put("app", "core");
labels.put("apiVersion", "1.7.1");
labels.put("keepUntil", "12000");
Deployment deployment1 = new DeploymentBuilder().withNewMetadata().withName("withKeepUntil").addToLabels(labels).endMetadata().withNewStatus().withReadyReplicas(2).endStatus().build();
kubernetesClient.apps().deployments().create(deployment1);
labels.remove("keepUntil");
Deployment deployment2 = new DeploymentBuilder().withNewMetadata().withName("withoutKeepUntil").addToLabels(labels).endMetadata().withNewStatus().withReadyReplicas(2).endStatus().build();
kubernetesClient.apps().deployments().create(deployment2);
List<Deployment> deployments = kubernetesClient.apps().deployments().withLabel("app", "core").withoutLabel("keepUntil", "12000").list().getItems();
assertFalse(deployments.stream().filter(d -> d.getMetadata().getName().equals("withKeepUntil")).findFirst().isPresent());
assertTrue(deployments.stream().filter(d -> d.getMetadata().getName().equals("withoutKeepUntil")).findFirst().isPresent());
}
Aggregations