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

PDB selector diff fix #43

Closed pepov closed 3 years ago

pepov commented 3 years ago
Q A
Bug fix? yes
New feature? no
API breaks? no
Deprecations? no
License Apache 2.0

What's in this PR?

Adds a new CalculateOption that can be used with PodDisruptionBudget resources against k8s 1.21 and higher where the patchStrategy:"replace" is used on the Selector field.

Selector *metav1.LabelSelector `json:"selector,omitempty" patchStrategy:"replace" protobuf:"bytes,2,opt,name=selector"`

This strategy will cause a constant diff, because the library in apimachinery doesn't check for equality in this case.

    switch patchStrategy {
    // The patch strategic from metadata tells us to replace the entire object instead of diffing it
    case replaceDirective:
        if !diffOptions.IgnoreChangesAndAdditions {
            patch[key] = modifiedValue
        }