Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Provide helpers to combine few callbacks for body-/meta-filters #345

Merged
merged 2 commits into from
Apr 8, 2020

Conversation

nolar
Copy link
Contributor

@nolar nolar commented Apr 7, 2020

What do these changes do?

Little helpers to combined few callbacks for when= or labels/annotations filters.

Description

Nothing more that a little bit of syntax sugar with kopf.all_() and kopf.any_():

import kopf

def whole_fn1(name, **_): return name.startswith('kopf-')
def whole_fn2(spec, **_): return spec.get('field') == 'value'
def value_fn1(value, **_): return value.startswith('some')
def value_fn2(value, **_): return value.endswith('label')

@kopf.on.create('zalando.org', 'v1', 'kopfexamples',
                when=kopf.all_([whole_fn1, whole_fn2]),
                labels={'somelabel': kopf.all_([value_fn1, value_fn2])})
def create_fn1(**_):
    pass

@kopf.on.create('zalando.org', 'v1', 'kopfexamples',
                when=kopf.any_([whole_fn1, whole_fn2]),
                labels={'somelabel': kopf.any_([value_fn1, value_fn2])})
def create_fn2(**_):
    pass

Based on the experience when few arbitrary criteria should be combined onto one criterion, but it looks ugly to add too many one-liner single-use functions that call real meaningful functions with and/or operators.

Issues/PRs

Issues: #123 #98

Type of changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • The code addresses only the mentioned problem, and this problem only
  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt

@nolar nolar added the enhancement New feature or request label Apr 7, 2020
@zincr
Copy link

zincr bot commented Apr 7, 2020

🤖 zincr found 0 problems , 1 warning

ℹ️ Large Commits
✅ Approvals
✅ Specification
✅ Dependency Licensing

Details on how to resolve are provided below


Large Commits

Checks all commits for large additions to a single file. Large commits should be reviewed more carefully for potential copyright and licensing issues

This file contains a substantial change, please review to determine if the change comes from an external source and if there are any copyright or licensing issues to be aware of

  • ℹ️ tests/test_filtering_helpers.py had +100 lines of code changed in a single commit
    Please review this file to determine the source of this change
     

@zincr
Copy link

zincr bot commented Apr 7, 2020

🤖 zincr found 1 problem , 0 warnings

❌ Approvals
✅ Large Commits
✅ Specification
✅ Dependency Licensing

Details on how to resolve are provided below


Approvals

All proposed changes must be reviewed by project maintainers before they can be merged

Not enough people have approved this pull request - please ensure that 1 additional user, who have not contributed to this pull request approve the changes.

  • ✅ Approved by PR author @nolar
  • ❌ 1 additional approval needed
     

@nolar nolar requested a review from mnarodovitch April 7, 2020 18:57
@nolar nolar merged commit 698171a into zalando-incubator:master Apr 8, 2020
@nolar nolar deleted the multi-callbacks branch April 8, 2020 14:52
@nolar nolar added this to the 0.27 milestone May 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants