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

Look into why unnecessary setElementOrder directives are generated for Volumes and VolumeMounts in case of pods #9

Open pepov opened 5 years ago

pepov commented 5 years ago

Description of the problem

When matching pods (and possibly other types of objects) a typical issue is that the patch will contain unnecessary $setElementOrder directives, most probably caused by the automatically generated Volumes and VolumeMounts of the service account token.

Current mitigation

Right now this is mitigated by actually applying the patch locally and checking it against the current version to see if it is a false positive or not.

It is possibly a bug or a limitation in the package k8s.io/apimachinery/pkg/util/strategicpatch but would need more investigation to find out.

How to reproduce

Remove the code responsible for double checking the patch and run the integration tests go test -integration -v to see pod matches with original to fail with the following unwanted patch:

 {"spec":{"$setElementOrder/volumes":[{"name":"empty"}]}}

The original pod spec:

&v1.Pod{
                ObjectMeta: standardObjectMeta(),
                Spec: v1.PodSpec{
                    Containers: []v1.Container{
                        {
                            Name: "test-container", Image: "test-image",
                        },
                    },
                    Volumes: []v1.Volume{
                        {
                            Name: "empty",
                            VolumeSource: v1.VolumeSource{
                                EmptyDir: &v1.EmptyDirVolumeSource{},
                            },
                        },
                    },
                },
            })
fernandesnikhil commented 2 years ago

Ran into this as well - is anyone else also experiencing this?

cannonpalms commented 2 years ago

This is broader than just volumes/volumeMounts. It affects imagePullSecrets in https://github.com/konpyutaika/nifikop

caigy commented 1 year ago

I ran into a same problem, any ways to solve it?