Giter Site home page Giter Site logo

Comments (2)

Arnavion avatar Arnavion commented on July 4, 2024 1

When we compare them using the crate, the comparison returns false. Is that expected?

Well, it's a Vec because the spec says it's an array. It does have "x-kubernetes-patch-strategy": "merge", "x-kubernetes-patch-merge-key": "name" so it functions like a map keyed by .name when merged, but the representation is an array regardless.

This should be the behavior of every client library. Eg both Python and C# also represent V1Container::env as an array. With Python:

import kubernetes

c1 = kubernetes.client.V1Container(name='foo', env=[kubernetes.client.V1EnvVar('a', 'x'), kubernetes.client.V1EnvVar('b', 'y')])
c2 = kubernetes.client.V1Container(name='foo', env=[kubernetes.client.V1EnvVar('b', 'y'), kubernetes.client.V1EnvVar('a', 'x')])
print(c1 == c2) # False

c1.env = sorted(c1.env, key=lambda e: e.name)
c2.env = sorted(c2.env, key=lambda e: e.name)
print(c1 == c2) # True

Is there a way of comparing and ignoring the order of the elements?

We could have a custom PartialEq impl for "x-kubernetes-patch-strategy": "merge" fields to do a sorted comparison, but that would not be in the spirit of PartialEq.

It would be better for you who owns the Container to sort its .env if you intend to compare it for equality without caring about order.

from k8s-openapi.

anagno avatar anagno commented on July 4, 2024

It would be better for you who owns the Container to sort its .env if you intend to compare it for equality without caring about order.

Thanks for the info ! Makes sense. I will just sort the environmental variables then!

from k8s-openapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.