use of com.redhat.service.smartevents.shard.operator.resources.BridgeIngress in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class BridgeIngressControllerTest method testBridgeIngressDeployment.
@Test
void testBridgeIngressDeployment() {
// Given
BridgeIngress bridgeIngress = buildBridgeIngress();
deployBridgeIngressSecret(bridgeIngress);
// When
bridgeIngressController.reconcile(bridgeIngress, null);
// Then
Deployment deployment = kubernetesClient.apps().deployments().inNamespace(bridgeIngress.getMetadata().getNamespace()).withName(bridgeIngress.getMetadata().getName()).get();
assertThat(deployment).isNotNull();
assertThat(deployment.getMetadata().getOwnerReferences().size()).isEqualTo(1);
assertThat(deployment.getMetadata().getLabels()).isNotNull();
assertThat(deployment.getSpec().getSelector().getMatchLabels().size()).isEqualTo(1);
assertThat(deployment.getSpec().getTemplate().getMetadata().getLabels()).isNotNull();
assertThat(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage()).isNotNull();
assertThat(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getName()).isNotNull();
}
use of com.redhat.service.smartevents.shard.operator.resources.BridgeIngress in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class BridgeIngressControllerTest method testCreateNewBridgeIngressWithoutSecrets.
@Test
void testCreateNewBridgeIngressWithoutSecrets() {
// Given
BridgeIngress bridgeIngress = buildBridgeIngress();
// When
UpdateControl<BridgeIngress> updateControl = bridgeIngressController.reconcile(bridgeIngress, null);
// Then
assertThat(updateControl.isNoUpdate()).isTrue();
}
use of com.redhat.service.smartevents.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());
}
use of com.redhat.service.smartevents.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);
}
use of com.redhat.service.smartevents.shard.operator.resources.BridgeIngress in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class CustomerNamespaceProviderImplTest method testNamespaceNotDeletedWithBridges.
@Test
void testNamespaceNotDeletedWithBridges() {
final BridgeDTO dto = TestSupport.newRequestedBridgeDTO();
dto.setCustomerId("cooper");
bridgeIngressService.createBridgeIngress(dto);
// Wait until BridgeIngress is really created, can take some time due to client caching
Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> kubernetesClient.resources(BridgeIngress.class).inNamespace(customerNamespaceProvider.resolveName(dto.getCustomerId())).withName(BridgeIngress.resolveResourceName(dto.getId())).get() != null);
// try to delete the namespace...
customerNamespaceProvider.deleteNamespaceIfEmpty(kubernetesClient.namespaces().withName("ob-cooper").get());
final Namespace namespace = kubernetesClient.namespaces().withName(customerNamespaceProvider.resolveName(dto.getCustomerId())).get();
assertThat(namespace).isNotNull();
}
Aggregations