Search in sources :

Example 1 with SimpleKubernetesClientDouble

use of org.entando.kubernetes.controller.coordinator.common.SimpleKubernetesClientDouble in project entando-k8s-controller-coordinator by entando-k8s.

the class ConfigListenerTest method shouldKillTheOperator.

@Test
void shouldKillTheOperator() {
    System.setProperty(EntandoOperatorSpiConfigProperty.ENTANDO_CONTROLLER_POD_NAME.getJvmSystemProperty(), "my-pod");
    // Given the operator is alive and listening to K8S resource events
    final File file = Paths.get("/tmp/EntandoControllerCoordinator.ready").toFile();
    Liveness.alive();
    assertTrue(file.exists());
    final ConfigListener configListener = new ConfigListener(new SimpleKubernetesClientDouble());
    // When the Operator loses the connection to the ConfigMap listener
    configListener.onClose(new WatcherException("Something went wrong"));
    // Then the operator has been killed
    assertFalse(file.exists());
}
Also used : SimpleKubernetesClientDouble(org.entando.kubernetes.controller.coordinator.common.SimpleKubernetesClientDouble) File(java.io.File) WatcherException(io.fabric8.kubernetes.client.WatcherException) Test(org.junit.jupiter.api.Test)

Example 2 with SimpleKubernetesClientDouble

use of org.entando.kubernetes.controller.coordinator.common.SimpleKubernetesClientDouble in project entando-k8s-controller-coordinator by entando-k8s.

the class ConfigListenerTest method shoulReflectLatestConfig.

@Test
void shoulReflectLatestConfig() {
    // Given the operator is alive and listening to K8S resource events
    final ConfigListener configListener = new ConfigListener(new SimpleKubernetesClientDouble());
    // When the entando-operator-config configmap is updated
    configListener.eventReceived(Action.MODIFIED, new ConfigMapBuilder().withNewMetadata().withName("some-map").withNamespace("some-namespce").endMetadata().addToData(ControllerCoordinatorProperty.ENTANDO_K8S_CONTROLLER_REMOVAL_DELAY.getJvmSystemProperty(), "400").build());
    // Then the latest property value reflects
    assertThat(EntandoOperatorConfigBase.lookupProperty(ControllerCoordinatorProperty.ENTANDO_K8S_CONTROLLER_REMOVAL_DELAY).get(), is("400"));
}
Also used : ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) SimpleKubernetesClientDouble(org.entando.kubernetes.controller.coordinator.common.SimpleKubernetesClientDouble) Test(org.junit.jupiter.api.Test)

Example 3 with SimpleKubernetesClientDouble

use of org.entando.kubernetes.controller.coordinator.common.SimpleKubernetesClientDouble in project entando-k8s-controller-coordinator by entando-k8s.

the class TrustStoreSecretRegeneratorTest method testRegenerate.

@Test
void testRegenerate() {
    final SimpleKubernetesClientDouble client = new SimpleKubernetesClientDouble();
    Secret oldCaSecret = CertificateSecretHelper.buildCertificateSecretsFromDirectory(client.getControllerNamespace(), Paths.get("src", "test", "resources", "tls", "ampie.dynu.net")).get(0);
    client.overwriteControllerSecret(oldCaSecret);
    TrustStoreSecretRegenerator.regenerateIfNecessary(client);
    Secret oldTrustStoreSecret = client.loadControllerSecret(TrustStoreHelper.DEFAULT_TRUSTSTORE_SECRET);
    assertThat(oldTrustStoreSecret, notNullValue());
    Secret newCaSecret = client.loadControllerSecret(EntandoOperatorSpiConfig.getCertificateAuthoritySecretName().get());
    // add file
    newCaSecret.getData().put("some-other.crt", oldCaSecret.getData().get("ca.crt"));
    client.overwriteControllerSecret(newCaSecret);
    TrustStoreSecretRegenerator.regenerateIfNecessary(client);
    Secret newTrustStoreSecret = client.loadControllerSecret(TrustStoreHelper.DEFAULT_TRUSTSTORE_SECRET);
    assertThat(newTrustStoreSecret, notNullValue());
    assertNotEquals(newTrustStoreSecret.getMetadata().getResourceVersion(), oldTrustStoreSecret.getMetadata().getResourceVersion());
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) SimpleKubernetesClientDouble(org.entando.kubernetes.controller.coordinator.common.SimpleKubernetesClientDouble) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleKubernetesClientDouble (org.entando.kubernetes.controller.coordinator.common.SimpleKubernetesClientDouble)3 Test (org.junit.jupiter.api.Test)3 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)1 Secret (io.fabric8.kubernetes.api.model.Secret)1 WatcherException (io.fabric8.kubernetes.client.WatcherException)1 File (java.io.File)1