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

Filter labels/annotations by callbacks with arbitrary logic #328

Merged
merged 6 commits into from
Mar 13, 2020

Conversation

nolar
Copy link
Contributor

@nolar nolar commented Mar 12, 2020

What do these changes do?

Add filtering callbacks for individual labels/annotations, similar to the whole-object when= filtering callback.

Description

This is a little separate follow-up for #327:

  • We have labels/annotations filters with values & markers for present/absent values.
  • We have callback filters with arbitrary logic for the whole objects.

Why not make callback filters with arbitrary logic for specific labels/annotations?

Just a little feature, which combines the two already existing features:

import kopf


def check_marker(value, spec, **_):
    return value is not None and value == spec.get('field')


@kopf.on.create('zalando.org', 'v1', 'kopfexamples',  
                annotations={'some-marker': check_marker})
def kex_created(**_):
    pass

The value is either a str, or None for an absent label/annotation. The callback is called always.

The kwargs are the same as for the handler or a when= callback.

Issues/PRs

Issues: #98

Related: #258

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 added 6 commits March 12, 2020 09:38
It is applied not only to handlers now, but also for boolean callbacks,
such as when= filters, and labels/annotations per-key filters.
So, it is just a result of a callback: `callbacks.Result`.
Can be implemented for criteria like "not value X", which includes
the situation when the value is just absent (it is also "not X").
With the previous logic, the key was expected to exist to match.
@zincr
Copy link

zincr bot commented Mar 12, 2020

🤖 zincr found 0 problems , 0 warnings

✅ Large Commits
✅ Approvals
✅ Specification
✅ Dependency Licensing

@nolar nolar requested review from 3abdelazim and haikoschol March 12, 2020 08:47
@nolar nolar added the enhancement New feature or request label Mar 12, 2020
@nolar nolar merged commit f70e556 into zalando-incubator:master Mar 13, 2020
@nolar nolar deleted the filter-labels-by-callbacks branch March 13, 2020 08:33
@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