Skip to content

fix: incorrect logic by introducing createOrUpdate method#3172

Merged
metacosm merged 1 commit intonextfrom
fix-webpage
Feb 19, 2026
Merged

fix: incorrect logic by introducing createOrUpdate method#3172
metacosm merged 1 commit intonextfrom
fix-webpage

Conversation

@metacosm
Copy link
Collaborator

Signed-off-by: Chris Laprun metacosm@gmail.com

Copilot AI review requested due to automatic review settings February 19, 2026 10:44
@metacosm metacosm self-assigned this Feb 19, 2026
@metacosm metacosm requested review from csviri and xstefank February 19, 2026 10:44
Signed-off-by: Chris Laprun <metacosm@gmail.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the low-level WebPageReconciler reconciliation flow by introducing a shared createOrUpdate helper to reduce duplicated “apply-if-different” logic, and fixes an incorrect resource application in the Ingress reconciliation path.

Changes:

  • Introduces a generic createOrUpdate helper to consolidate create/update logic for secondary resources.
  • Fixes Ingress reconciliation to server-side-apply the desired Ingress (instead of the Deployment).
  • Simplifies desired resource builders to derive namespace/name directly from WebPage and removes StringUtils usage.
Comments suppressed due to low confidence (1)

sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java:110

  • The comment reads "not that this is not necessary" which looks like a typo/grammar issue; it should be "note that this is not necessary" (or similar) to make the intent clear.
    // not that this is not necessary, eventually mounted config map would be updated, just this way
    // is much faster; this is handy for demo purposes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +125 to +137
private <T extends HasMetadata> T createOrUpdate(
Context<WebPage> context, T desired, BiFunction<T, T, Boolean> matcher) {
@SuppressWarnings("unchecked")
final T previous = (T) context.getSecondaryResource(desired.getClass()).orElse(null);
if (!matcher.apply(desired, previous)) {
log.info(
"Creating or updating {} {} in {}",
desired.getKind(),
desired.getMetadata().getName(),
desired.getMetadata().getNamespace());
context.resourceOperations().serverSideApply(desired);
}
return previous;
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI runs spotless:check with google-java-format; this new createOrUpdate block doesn’t appear to be google-java-format output (long method signature on one line, indentation/alignment inside log.info, extra blank line above). Please run Spotless / apply google-java-format so the file matches the enforced formatter and the PR check passes.

Copilot uses AI. Check for mistakes.
Comment on lines +126 to +128
Context<WebPage> context, T desired, BiFunction<T, T, Boolean> matcher) {
@SuppressWarnings("unchecked")
final T previous = (T) context.getSecondaryResource(desired.getClass()).orElse(null);
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createOrUpdate relies on an unchecked cast from getSecondaryResource(desired.getClass()) to T, requiring @SuppressWarnings("unchecked"). To avoid potential ClassCastException and remove the suppression, consider passing the resource Class<T> explicitly (e.g., createOrUpdate(context, Deployment.class, desiredDeployment, this::match)) or otherwise restructuring so the Optional is typed without a cast.

Copilot uses AI. Check for mistakes.
Comment on lines 102 to 106
if (Boolean.TRUE.equals(webPage.getSpec().getExposed())) {
var desiredIngress = makeDesiredIngress(webPage);
if (existingIngress.isEmpty() || !match(desiredIngress, existingIngress.get())) {
context.resourceOperations().serverSideApply(desiredDeployment);
context.resourceOperations().serverSideApply(desiredIngress);
}
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exposed-Ingress reconciliation path was changed (applying desiredIngress instead of desiredDeployment), but there’s no automated coverage for spec.exposed=true in the existing E2E test. Consider extending WebPageOperatorAbstractTest to create a WebPage with spec.setExposed(true) and assert that an Ingress is created/updated; this would prevent regressions of this logic.

Copilot uses AI. Check for mistakes.
@metacosm metacosm merged commit d21cf5f into next Feb 19, 2026
25 checks passed
@metacosm metacosm deleted the fix-webpage branch February 19, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments