Code Monkey home page Code Monkey logo

Comments (4)

khash avatar khash commented on September 24, 2024

In a multi-part yaml file like this one, each part is treated as a single yaml so the filter is applied to each part individually and can return a value or not depending on the content. For example, to fetch only kind: Service you might want to use fetch("$[?(@['kind'] == 'Service')]"). This returns [] for all parts except for the one with kind: Service.

Your condition inside of the rule then can decide to ignore this if the returned array is empty.

Having said that, I think we can improve the filtering further but this should be done in a way that doesn't compromise the best practices Copper is trying to enforce. In this case, having all resources defined in one file is not a good idea so allowing to filter by type will firstly make writing of the rules more complicated and secondly encourages not following best practices.

from copper.

khash avatar khash commented on September 24, 2024

@towolf did you manage to use the suggested filter to get around your problem?

from copper.

towolf avatar towolf commented on September 24, 2024

Sorry, i haven't looked into this tool much more and have been fully occupied with other things. Feel free to close this if you like. @khash

from copper.

eyalzek avatar eyalzek commented on September 24, 2024

How would one filter empty arrays? I tried many different ways but in most cases copper just complains for invalid syntax.

fetch("$[?(@['kind'] == 'Deployment')].apiVersion") == []

edit: I managed to get it to pass with:

rule DeploymentApiVersion ensure {
    fetch("$[?(@['kind'] == 'Deployment')].apiVersion").count == 0 or
    fetch("$[?(@['kind'] == 'Deployment')].apiVersion").first == "apps/v1"
}

though skipping would actually be better than making unmatching resources pass...

from copper.

Related Issues (17)

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.