Search in sources :

Example 26 with DeploymentBuilder

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));
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) DeploymentSpecBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentSpecBuilder) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) LocalObjectReferenceBuilder(io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.testng.annotations.Test)

Example 27 with DeploymentBuilder

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"));
}
Also used : Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.jupiter.api.Test)

Example 28 with DeploymentBuilder

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());
}
Also used : DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 29 with DeploymentBuilder

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);
}
Also used : Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)

Example 30 with DeploymentBuilder

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());
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.extensions.IngressBuilder) AttributeSet(io.fabric8.mockwebserver.crud.AttributeSet) Arrays(java.util.Arrays) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) Pod(io.fabric8.kubernetes.api.model.Pod) IOException(java.io.IOException) HashMap(java.util.HashMap) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Attribute(io.fabric8.mockwebserver.crud.Attribute) Test(org.junit.jupiter.api.Test) List(java.util.List) CustomResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Map(java.util.Map) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collections(java.util.Collections) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HashMap(java.util.HashMap) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

DeploymentBuilder (io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)153 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)80 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)60 Test (org.junit.Test)60 Test (org.junit.jupiter.api.Test)32 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)26 Expectations (mockit.Expectations)26 Test (org.testng.annotations.Test)22 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)17 ArrayList (java.util.ArrayList)17 Container (io.fabric8.kubernetes.api.model.Container)16 HashMap (java.util.HashMap)16 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)15 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)15 DeploymentBuilder (io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)14 Properties (java.util.Properties)14 Pod (io.fabric8.kubernetes.api.model.Pod)13 PodTemplateSpecBuilder (io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder)13 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)12 InternalRecipe (org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe)12