cisco-open / k8s-objectmatcher

A Kubernetes object matcher library to avoid unnecessary K8s object updates
Apache License 2.0
157 stars 29 forks source link

How to exclude specific fields for comparison within the statefulset spec ? #40

Open kaushiksrinivas opened 3 years ago

kaushiksrinivas commented 3 years ago

Would like to exclude one specific field within the statefulset spec for the object matcher comparison. Is there a way to exclude specific fields in the statefulset spec for object matcher comparison ?

pepov commented 3 years ago

The way this goes is to remove those fields before the comparison happens. You can see examples here on how to do that: https://github.com/banzaicloud/k8s-objectmatcher/blob/af0ea18f6ccf72e970a35f370ff0a392b3a1ffdc/patch/deletenull.go#L28-L58

And here is how to use it:

    opts := []patch.CalculateOption{
        patch.IgnoreStatusFields(),
        patch.IgnoreVolumeClaimTemplateTypeMetaAndStatus(),
    }

        patchResult, err := patch.DefaultPatchMaker.Calculate(existing.(runtime.Object), newObject.(runtime.Object), opts...)
    if err != nil {
        return err
    }
kaushiksrinivas commented 3 years ago

Hi, The above code samples highlights only about status fields and volumeClainTemplateTypeMetaAndStatus fields. How to exclude for a field which is part of the spec. For example a field within the statefulset spec. Is that exclusion also possible ? I could not see any related functions to do the same.

pepov commented 3 years ago

those are examples, you have to craft the function you need for yourself right now

kaushiksrinivas commented 3 years ago

Got it... Would it be possible to implement such field exclusions as part of a common library within this repository ? Or we could take them as contribution pull requests ?

pepov commented 3 years ago

It's absolutely possible! If you have something we can add it through a pull request of course!

kaushiksrinivas commented 3 years ago

Ok sure.. am currently working on excluding fields in statefulset. i will try to create them in a generic way and come up with a PR. thanks for the info now.