Skip to content

match in GenericKubernetesResourceMatcher.java doesn't seem to calculate the DiffJsonPatch correctly. #2997

@gnfpt

Description

@gnfpt

Bug Report

I believe there's an issue with the way JsonDiff.asJson() is being used in GenericKubernetesResourceMatcher.java

What did you do?

I have a CR being updated with an EnvVar deleted from the list. That's the only change. The dependent resource isn't reconciled.

In GenericKubernetesResourceMatcher.java match() (L:163) it's being called JsonDiff.asJson(desiredNode, actualNode). The outcome is to add the missing element instead of remove.

Image

What did you expect to see?

I expected to see the missing element in desired EnvVars to be removed from actual EnvVars.

What did you see instead? Under which circumstances?

The outcome is to add the element missing in desired EnvVars.

Environment

AWS EKS v1.32.7-eks-ace6451
JOSDK operator-framework-spring-boot-starter:6.1.1
amazoncorretto:17.0.5
openjdk 17.0.5 2022-10-18 LTS
OpenJDK Runtime Environment Corretto-17.0.5.8.1 (build 17.0.5+8-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.5.8.1 (build 17.0.5+8-LTS, mixed mode, sharing)

Client Version: v1.32.1
Kustomize Version: v5.5.0
Server Version: v1.33.1

Possible Solution

swap the parameters in the call to JsonDiff.asJson() but this is going to catch "metadata" and "status" missing in "desired". Might have some side effects.

Additional context

Example of using JsonDiff.asJson() to calculate the patch and applying it to "actual" in order to get "desired" result.

public static void main(String[] args) {
    int[] desired = {0, 2, 3};
    int[] actual  = {0, 1, 2, 3};

    var desiredNode = new ObjectMapper().convertValue(desired, JsonNode.class);
    var actualNode = new ObjectMapper().convertValue(actual, JsonNode.class);

    var patch = JsonDiff.asJson(actualNode, desiredNode);  
    var result = JsonPatch.apply(patch, actualNode);

    System.out.println("desired -> " + Arrays.toString(desired));
    System.out.println("actual -> " + Arrays.toString(actual));
    System.out.println("patch -> " + patch);
    System.out.println("result -> " + result);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions