Skip to content

fix: webpage e2e test and deprecated API usage #2124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.Replaceable;
import io.javaoperatorsdk.operator.ReconcilerUtils;
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.Context;
Expand Down Expand Up @@ -107,7 +108,7 @@ public UpdateControl<WebPage> reconcile(WebPage webPage, Context<WebPage> contex
desiredHtmlConfigMap.getMetadata().getName(),
ns);
var res = kubernetesClient.configMaps().inNamespace(ns).resource(desiredHtmlConfigMap)
.createOrReplace();
.createOr(Replaceable::update);
log.debug("Updated config map: {}", res);
}

Expand All @@ -118,7 +119,7 @@ public UpdateControl<WebPage> reconcile(WebPage webPage, Context<WebPage> contex
desiredDeployment.getMetadata().getName(),
ns);
kubernetesClient.apps().deployments().inNamespace(ns).resource(desiredDeployment)
.createOrReplace();
.createOr(Replaceable::update);
}

var existingService = context.getSecondaryResource(Service.class).orElse(null);
Expand All @@ -127,14 +128,15 @@ public UpdateControl<WebPage> reconcile(WebPage webPage, Context<WebPage> contex
"Creating or updating Deployment {} in {}",
desiredDeployment.getMetadata().getName(),
ns);
kubernetesClient.services().inNamespace(ns).resource(desiredService).createOrReplace();
kubernetesClient.services().inNamespace(ns).resource(desiredService)
.createOr(Replaceable::update);
}

var existingIngress = context.getSecondaryResource(Ingress.class);
if (Boolean.TRUE.equals(webPage.getSpec().getExposed())) {
var desiredIngress = makeDesiredIngress(webPage);
if (existingIngress.isEmpty() || !match(desiredIngress, existingIngress.get())) {
kubernetesClient.resource(desiredIngress).inNamespace(ns).createOrReplace();
kubernetesClient.resource(desiredIngress).inNamespace(ns).createOr(Replaceable::update);
}
} else
existingIngress.ifPresent(
Expand All @@ -150,7 +152,7 @@ public UpdateControl<WebPage> reconcile(WebPage webPage, Context<WebPage> contex
kubernetesClient.pods().inNamespace(ns).withLabel("app", deploymentName(webPage)).delete();
}
webPage.setStatus(createStatus(desiredHtmlConfigMap.getMetadata().getName()));
return UpdateControl.updateStatus(webPage);
return UpdateControl.patchStatus(webPage);
}

private boolean match(Ingress desiredIngress, Ingress existingIngress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.client.KubernetesClient;
Expand All @@ -23,6 +24,7 @@

import static io.javaoperatorsdk.operator.sample.Utils.deploymentName;
import static io.javaoperatorsdk.operator.sample.Utils.serviceName;
import static io.javaoperatorsdk.operator.sample.WebPageReconciler.INDEX_HTML;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

Expand Down Expand Up @@ -72,7 +74,10 @@ void testAddingWebPage() {
await().atMost(Duration.ofSeconds(LONG_WAIT_SECONDS))
.pollInterval(POLL_INTERVAL)
.untilAsserted(() -> {
String page = httpGetForWebPage(webPage);
String page = operator().get(ConfigMap.class, Utils.configMapName(webPage)).getData()
.get(INDEX_HTML);
// not using portforward here since there were issues with GitHub actions
// String page = httpGetForWebPage(webPage);
assertThat(page).isNotNull().contains(TITLE2);
});

Expand Down