Skip to content

Commit

Permalink
migrate webpage (#43)
Browse files Browse the repository at this point in the history
Signed-off-by: csviri <[email protected]>
  • Loading branch information
csviri authored Mar 29, 2024
1 parent ca83e64 commit dd29a99
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 66 deletions.
6 changes: 6 additions & 0 deletions src/test/java/io/csviri/operator/resourceglue/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.fabric8.kubernetes.api.model.NamespaceBuilder;
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.NonDeletingOperation;
import io.fabric8.kubernetes.client.utils.KubernetesResourceUtil;

import jakarta.inject.Inject;
Expand Down Expand Up @@ -54,6 +55,11 @@ protected <T extends HasMetadata> T create(T resource) {
return client.resource(resource).inNamespace(testNamespace).create();
}

protected <T extends HasMetadata> T createOrUpdate(T resource) {
return client.resource(resource).inNamespace(testNamespace)
.createOr(NonDeletingOperation::update);
}

protected <T extends HasMetadata> T get(Class<T> clazz, String name) {
return client.resources(clazz).inNamespace(testNamespace).withName(name).get();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,69 +1,78 @@
package io.csviri.operator.resourceglue.sample.webpage;

public class WebPageSampleTest {

// todo

// @RegisterExtension
// LocallyRunOperatorExtension extension =
// LocallyRunOperatorExtension.builder()
// .withReconciler(new GlueReconciler())
// .withReconciler(new GlueOperatorReconciler())
// .build();
//
// @Test
// void webPageCRUD() {
// TestUtils.createOrUpdate(extension, "/sample/webpage/webpage.crd.yml");
// TestUtils.createOrUpdate(extension, "/sample/webpage/webpage.operator.yaml");
// var webPage = TestUtils.createOrUpdate(extension, "/sample/webpage/webpage.sample.yaml");
//
// await().untilAsserted(() -> {
// var deployment = extension.get(Deployment.class, webPage.getMetadata().getName());
// var configMap = extension.get(ConfigMap.class, webPage.getMetadata().getName());
// var service = extension.get(Service.class, webPage.getMetadata().getName());
// var ingress = extension.get(Ingress.class, webPage.getMetadata().getName());
//
// assertThat(ingress).isNull();
// assertThat(deployment).isNotNull();
// assertThat(service).isNotNull();
// assertThat(configMap).isNotNull();
// assertThat(configMap.getData().get("index.html")).contains("Hello World!");
// });
//
// setExposed(webPage);
// setNewHtml(webPage);
// extension.replace(webPage);
//
// await().untilAsserted(() -> {
// var ingress = extension.get(Ingress.class, webPage.getMetadata().getName());
// var configMap = extension.get(ConfigMap.class, webPage.getMetadata().getName());
//
// assertThat(configMap.getData().get("index.html")).contains("Hello World 2!");
// assertThat(ingress).isNotNull();
// });
//
// extension.delete(webPage);
//
// await().untilAsserted(() -> {
// var deployment = extension.get(Deployment.class, webPage.getMetadata().getName());
// assertThat(deployment).isNull();
// });
// }
//
// private void setNewHtml(GenericKubernetesResource webPage) {
// ((HashMap<String, Object>) webPage.getAdditionalProperties().get("spec")).put("html", """
// <html>
// <head>
// <title>Hello Operator World</title>
// </head>
// <body>
// Hello World 2!
// </body>
// </html>
// """);
// }
//
// private void setExposed(GenericKubernetesResource webPage) {
// ((HashMap<String, Object>) webPage.getAdditionalProperties().get("spec")).put("exposed", true);
// }
import java.util.HashMap;

import org.junit.jupiter.api.Test;

import io.csviri.operator.resourceglue.TestBase;
import io.csviri.operator.resourceglue.TestUtils;
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
import io.quarkus.test.junit.QuarkusTest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

@QuarkusTest
public class WebPageSampleTest extends TestBase {

@Test
void webPageCRUD() {

createOrUpdate(TestUtils.load("/sample/webpage/webpage.crd.yml"));
createOrUpdate(TestUtils.load("/sample/webpage/webpage.operator.yaml"));
var webPage = createOrUpdate(TestUtils.load("/sample/webpage/webpage.sample.yaml"));

await().untilAsserted(() -> {
var deployment = get(Deployment.class, webPage.getMetadata().getName());
var configMap = get(ConfigMap.class, webPage.getMetadata().getName());
var service = get(Service.class, webPage.getMetadata().getName());
var ingress = get(Ingress.class, webPage.getMetadata().getName());

assertThat(ingress).isNull();
assertThat(deployment).isNotNull();
assertThat(service).isNotNull();
assertThat(configMap).isNotNull();
assertThat(configMap.getData().get("index.html")).contains("Hello World!");
});

setExposed(webPage);
setNewHtml(webPage);
update(webPage);

await().untilAsserted(() -> {
var ingress = get(Ingress.class, webPage.getMetadata().getName());
var configMap = get(ConfigMap.class, webPage.getMetadata().getName());

assertThat(configMap.getData().get("index.html")).contains("Hello World 2!");
assertThat(ingress).isNotNull();
});

delete(webPage);

await().untilAsserted(() -> {
var deployment = get(Deployment.class, webPage.getMetadata().getName());
assertThat(deployment).isNull();
});
}

private void setNewHtml(GenericKubernetesResource webPage) {
((HashMap<String, Object>) webPage.getAdditionalProperties().get("spec")).put("html", """
<html>
<head>
<title>Hello Operator World</title>
</head>
<body>
Hello World 2!
</body>
</html>
""");
}

private void setExposed(GenericKubernetesResource webPage) {
((HashMap<String, Object>) webPage.getAdditionalProperties().get("spec")).put("exposed", true);
}
}

0 comments on commit dd29a99

Please sign in to comment.