Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for field exemptions for std.prune #1167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

raynix
Copy link

@raynix raynix commented Aug 14, 2024

This is to add support for fields which will be exempted and will not be pruned in an object. For example

{
  prune(a, ex=[])::
    local isContent(b) =
      if b == null then
        false
      else if std.isArray(b) then
        std.length(b) > 0
      else if std.isObject(b) then
        std.length(b) > 0
      else
        true;
    if std.isArray(a) then
      [$.prune(x, ex) for x in a if isContent($.prune(x, ex))]
    else if std.isObject(a) then {
      [x]: $.prune(a[x], ex)
      for x in std.objectFields(a)
      if std.member(ex, x) || isContent($.prune(a[x], ex))
    } else
      a,
  containers: {
    local container = {
      image: 'nginx:latest',
      env: [],
      args: [],
      volumeMounts: [
        {
          name: 'test',
          emptyDir: {},
          rubbish: {}
        }
      ],
      resources: {
        requests: {
          cpu: '0.5',
          rubbish: []
        },
        rubbish: [],
      }
    },
    test: $.prune(container, ['emptyDir']),
  },
}

the emptyDir will be preserved as a preferred result.

{
  "containers": {
    "test": {
      "image": "nginx:latest",
      "resources": {
        "requests": {
          "cpu": "0.5"
        }
      },
      "volumeMounts": [
        {
          "emptyDir": {},
          "name": "test"
        }
      ]
    }
  }
}

Fully compatible with existing usage without the exemption list.

Copy link

google-cla bot commented Aug 14, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@raynix
Copy link
Author

raynix commented Sep 19, 2024

Can someone take a look? It's been there for a while :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants