operator-framework / java-operator-sdk

Java SDK for building Kubernetes Operators
https://javaoperatorsdk.io/
Apache License 2.0
788 stars 212 forks source link

[Suggestion] Resource Diff Printer #2492

Open 10000-ki opened 1 month ago

10000-ki commented 1 month ago

Idea

I'd like to propose an idea. How about providing a utility function that outputs the diff information to show which fields have changed between the actual resource and the desired resource?

Currently, it seems that such a feature doesn't exist, so when unintended events are generated, we have to log both the actual and desired resources as text and manually compare them field by field to find the differences. This process takes too much time.

Example

    override fun match(
        actualResource: StatefulSet,
        desired: StatefulSet,
        primary: OpenSearch,
        context: Context<OpenSearch>,
    ): Matcher.Result<StatefulSet> {
        println(ResourceDiffPrinter.printDiff(actualResource, desired))
    }

"""
Diff : 
(actual) -> (desired)
annotations.last-modification-timestamp: "2024-08-13T11:07:04+09:00" -> annotations.last-modification-timestamp: "2024-08-13T12:07:04+09:00" 
spec.replicas: "3" -> spec.replicas: "4"
"""
csviri commented 1 month ago

Would make sense IMO, I can imagine that as part of SSABasedGenericKubernetesResourceMatcher, that could also log this information.

Do you plan to also create a PR?

10000-ki commented 1 month ago

Do you plan to also create a PR?

@csviri Of course! In that case, would it be okay if I work on it and then submit a PR?

csviri commented 1 month ago

sure, pls do! thx!

10000-ki commented 1 month ago

@csviri the PR should be created based on the next branch right??

metacosm commented 1 month ago

@csviri the PR should be created based on the next branch right??

Yes, please.