Search in sources :

Example 1 with BridgeIngress

use of com.redhat.service.bridge.shard.operator.resources.BridgeIngress in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeIngressSteps method deployBridgeIngressWithDefaultSecret.

@When("^deploy BridgeIngress with default secret:$")
public void deployBridgeIngressWithDefaultSecret(String bridgeIngressYaml) {
    InputStream resourceStream = new ByteArrayInputStream(bridgeIngressYaml.getBytes(StandardCharsets.UTF_8));
    BridgeIngress bridgeIngress = context.getClient().resources(BridgeIngress.class).inNamespace(context.getNamespace()).load(resourceStream).createOrReplace();
    Secret secret = new SecretBuilder().withMetadata(new ObjectMetaBuilder().withNamespace(bridgeIngress.getMetadata().getNamespace()).withName(bridgeIngress.getMetadata().getName()).build()).build();
    context.getClient().secrets().inNamespace(bridgeIngress.getMetadata().getNamespace()).withName(bridgeIngress.getMetadata().getName()).createOrReplace(secret);
}
Also used : BridgeIngress(com.redhat.service.bridge.shard.operator.resources.BridgeIngress) Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) When(io.cucumber.java.en.When)

Example 2 with BridgeIngress

use of com.redhat.service.bridge.shard.operator.resources.BridgeIngress in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeIngressControllerTest method testBridgeIngressDeployment_deploymentTimeoutFailure.

@Test
void testBridgeIngressDeployment_deploymentTimeoutFailure() throws Exception {
    // Given
    BridgeIngress bridgeIngress = buildBridgeIngress();
    deployBridgeIngressSecret(bridgeIngress);
    // When
    bridgeIngressController.reconcile(bridgeIngress, null);
    Deployment deployment = getDeploymentFor(bridgeIngress);
    // Then
    kubernetesResourcePatcher.patchDeploymentAsTimeoutFailed(deployment.getMetadata().getName(), deployment.getMetadata().getNamespace());
    UpdateControl<BridgeIngress> updateControl = bridgeIngressController.reconcile(bridgeIngress, null);
    assertThat(updateControl.isUpdateStatus()).isTrue();
    assertThat(updateControl.getResource().getStatus().getConditionByType(ConditionType.Ready).get().getReason()).isEqualTo(ConditionReason.DeploymentFailed);
    assertThat(updateControl.getResource().getStatus().getConditionByType(ConditionType.Augmentation).get().getStatus()).isEqualTo(ConditionStatus.False);
}
Also used : BridgeIngress(com.redhat.service.bridge.shard.operator.resources.BridgeIngress) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 3 with BridgeIngress

use of com.redhat.service.bridge.shard.operator.resources.BridgeIngress in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeIngressControllerTest method testCreateNewBridgeIngress.

@Test
void testCreateNewBridgeIngress() {
    // Given
    BridgeIngress bridgeIngress = buildBridgeIngress();
    deployBridgeIngressSecret(bridgeIngress);
    // When
    UpdateControl<BridgeIngress> updateControl = bridgeIngressController.reconcile(bridgeIngress, null);
    // Then
    assertThat(updateControl.isUpdateStatus()).isTrue();
    assertThat(bridgeIngress.getStatus()).isNotNull();
    assertThat(bridgeIngress.getStatus().isReady()).isFalse();
    assertThat(bridgeIngress.getStatus().getConditionByType(ConditionType.Augmentation)).isPresent().hasValueSatisfying(c -> {
        assertThat(c.getStatus()).isEqualTo(ConditionStatus.False);
    });
    assertThat(bridgeIngress.getStatus().getConditionByType(ConditionType.Ready)).isPresent().hasValueSatisfying(c -> {
        assertThat(c.getStatus()).isEqualTo(ConditionStatus.False);
        assertThat(c.getReason()).isEqualTo(ConditionReason.DeploymentNotAvailable);
    });
}
Also used : BridgeIngress(com.redhat.service.bridge.shard.operator.resources.BridgeIngress) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 4 with BridgeIngress

use of com.redhat.service.bridge.shard.operator.resources.BridgeIngress in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ServiceMonitorServiceTest method fetchOrCreateServiceMonitor.

@Test
@WithPrometheus
void fetchOrCreateServiceMonitor() {
    // Given
    final BridgeDTO bridge = TestSupport.newAvailableBridgeDTO();
    final BridgeIngress bridgeIngress = BridgeIngress.fromDTO(bridge, "default", TestSupport.INGRESS_IMAGE);
    final Secret secretMock = new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName(bridgeIngress.getMetadata().getName()).build()).build();
    final Deployment deployment = bridgeIngressService.fetchOrCreateBridgeIngressDeployment(bridgeIngress, secretMock);
    final Service service = bridgeIngressService.fetchOrCreateBridgeIngressService(bridgeIngress, deployment);
    // When
    final Optional<ServiceMonitor> serviceMonitor = serviceMonitorService.fetchOrCreateServiceMonitor(bridgeIngress, service, "ingress");
    // Then
    assertThat(serviceMonitor).isPresent();
    // check: https://prometheus-operator.dev/docs/operator/troubleshooting/#overview-of-servicemonitor-tagging-and-related-elements
    assertThat(serviceMonitor.get().getSpec().getSelector().getMatchLabels()).containsEntry(LabelsBuilder.INSTANCE_LABEL, deployment.getMetadata().getName());
    assertThat(serviceMonitor.get().getMetadata().getLabels()).containsEntry(LabelsBuilder.INSTANCE_LABEL, deployment.getMetadata().getName());
    assertThat(serviceMonitor.get().getMetadata().getLabels()).containsEntry(LabelsBuilder.MANAGED_BY_LABEL, LabelsBuilder.OPERATOR_NAME);
    assertThat(serviceMonitor.get().getMetadata().getLabels()).containsEntry(LabelsBuilder.CREATED_BY_LABEL, LabelsBuilder.OPERATOR_NAME);
    assertThat(serviceMonitor.get().getMetadata().getLabels()).containsEntry(LabelsBuilder.COMPONENT_LABEL, "ingress");
    assertThat(service.getMetadata().getLabels()).containsEntry(LabelsBuilder.INSTANCE_LABEL, deployment.getMetadata().getName());
}
Also used : BridgeIngress(com.redhat.service.bridge.shard.operator.resources.BridgeIngress) Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) ServiceMonitor(io.fabric8.openshift.api.model.monitoring.v1.ServiceMonitor) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) BridgeIngressService(com.redhat.service.bridge.shard.operator.BridgeIngressService) Service(io.fabric8.kubernetes.api.model.Service) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) WithPrometheus(com.redhat.service.bridge.shard.operator.WithPrometheus)

Example 5 with BridgeIngress

use of com.redhat.service.bridge.shard.operator.resources.BridgeIngress in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class CustomerNamespaceProviderImplTest method testNamespaceDeletedWhenEmpty.

@Test
void testNamespaceDeletedWhenEmpty() {
    final BridgeDTO dto = TestSupport.newRequestedBridgeDTO();
    dto.setCustomerId("hofstadter");
    bridgeIngressService.createBridgeIngress(dto);
    // Wait until BridgeIngress is really created, can take some time due to client caching - https://issues.redhat.com/browse/MGDOBR-308
    Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> kubernetesClient.resources(BridgeIngress.class).inNamespace(customerNamespaceProvider.resolveName(dto.getCustomerId())).withName(BridgeIngress.resolveResourceName(dto.getId())).get() != null);
    // there's only one bridge there
    bridgeIngressService.deleteBridgeIngress(dto);
    Awaitility.await().atMost(Duration.ofSeconds(60)).until(() -> kubernetesClient.resources(BridgeIngress.class).withName(BridgeIngress.resolveResourceName(dto.getId())).get() == null);
    customerNamespaceProvider.cleanUpEmptyNamespaces();
    Awaitility.await().atMost(Duration.ofSeconds(60)).until(() -> kubernetesClient.namespaces().withName(customerNamespaceProvider.resolveName(dto.getCustomerId())).get() == null);
}
Also used : BridgeIngress(com.redhat.service.bridge.shard.operator.resources.BridgeIngress) BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

BridgeIngress (com.redhat.service.bridge.shard.operator.resources.BridgeIngress)16 QuarkusTest (io.quarkus.test.junit.QuarkusTest)11 Test (org.junit.jupiter.api.Test)11 BridgeDTO (com.redhat.service.bridge.infra.models.dto.BridgeDTO)6 Secret (io.fabric8.kubernetes.api.model.Secret)4 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)4 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)3 Namespace (io.fabric8.kubernetes.api.model.Namespace)2 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)2 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)2 BridgeIngressService (com.redhat.service.bridge.shard.operator.BridgeIngressService)1 WithPrometheus (com.redhat.service.bridge.shard.operator.WithPrometheus)1 When (io.cucumber.java.en.When)1 Service (io.fabric8.kubernetes.api.model.Service)1 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)1 HTTPIngressPathBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder)1 HTTPIngressRuleValueBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder)1 IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)1 IngressBackendBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder)1 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)1