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

Hide warnings on fake inconsistencies when patching the nonexistent objects #559

Merged
merged 2 commits into from
Oct 5, 2020

Conversation

nolar
Copy link
Owner

@nolar nolar commented Oct 5, 2020

Suppress the misleading warnings on inconsistencies when patching the object, which was deleted in/during the handling process.

Description

A snippet to reproduce the case:

import kopf
import pykube

class Kex(pykube.objects.NamespacedAPIObject):
    version = "zalando.org/v1"
    endpoint = "kopfexamples"
    kind = "KopfExample"

@kopf.on.create('zalando.org', 'v1', 'kopfexamples')
def create_fn(name, namespace, **_):
    api = pykube.HTTPClient(pykube.KubeConfig.from_env())
    obj = Kex.objects(api, namespace=namespace).get_by_name(name)
    obj.delete()
    return {'message': 'hello world'}  # will be the new status

Before the fix, it logged the following with the WARNING level:

[2020-10-05 19:54:40,612] kopf.objects         [INFO    ] [default/kopf-example-1] Handler 'create_fn' succeeded.
[2020-10-05 19:54:40,613] kopf.objects         [INFO    ] [default/kopf-example-1] Creation event is processed: 1 succeeded; 0 failed.
[2020-10-05 19:54:40,613] kopf.objects         [DEBUG   ] [default/kopf-example-1] Patching with: {'status': {'create_fn': {'message': 'hello world'}}, 'metadata': {'annotations': {'kopf.zalando.org/last-handled-configuration': '{"spec":{"duration":"1m","field":"value","items":["item1","item2"]},"metadata":{"labels":{"somelabel":"somevalue"},"annotations":{"someannotation":"somevalue"}}}\n'}}}
[2020-10-05 19:54:40,627] kopf.objects         [WARNING ] [default/kopf-example-1] Patching failed with inconsistencies: (('remove', ('status',), {'create_fn': {'message': 'hello world'}}, None), ('remove', ('metadata',), {'annotations': {'kopf.zalando.org/last-handled-configuration': '{"spec":{"duration":"1m","field":"value","items":["item1","item2"]},"metadata":{"labels":{"somelabel":"somevalue"},"annotations":{"someannotation":"somevalue"}}}\n'}}, None))
[2020-10-05 19:54:40,737] kopf.objects         [DEBUG   ] [default/kopf-example-1] Deleted, really deleted, and we are notified.

After the fix, the logs look like this, with only the DEBUG level messages:

[2020-10-05 19:50:56,919] kopf.objects         [INFO    ] [default/kopf-example-1] Handler 'create_fn' succeeded.
[2020-10-05 19:50:56,920] kopf.objects         [INFO    ] [default/kopf-example-1] Creation event is processed: 1 succeeded; 0 failed.
[2020-10-05 19:50:56,921] kopf.objects         [DEBUG   ] [default/kopf-example-1] Patching with: {'status': {'create_fn': {'message': 'hello world'}}, 'metadata': {'annotations': {'kopf.zalando.org/last-handled-configuration': '{"spec":{"duration":"1m","field":"value","items":["item1","item2"]},"metadata":{"labels":{"somelabel":"somevalue"},"annotations":{"someannotation":"somevalue"}}}\n'}}}
[2020-10-05 19:50:56,939] kopf.objects         [DEBUG   ] [default/kopf-example-1] Patching was skipped: the object does not exist anymore.
[2020-10-05 19:50:57,045] kopf.objects         [DEBUG   ] [default/kopf-example-1] Deleted, really deleted, and we are notified.

Inconsistency detection was introduced in #527 — to detect if CRDs are configured to lose the fields (e.g. due to "structural schemas" of K8s 1.16+). That case would be misbehaviour.

The object deletion in the handlers or during the handling process is, to some extent, an expected use-case. Instead of WARNING, which implies alerting and reaction, we now log only a DEBUG level message — to not leave the whole situation hidden (which might be needed for other cases of debugging).

Also, remove the frightening "failed" word, and replace it with "skipped" — to show that it was partially expected.

nolar added 2 commits October 5, 2020 19:44
This should improve how different types of mappings are compared to each other,
ignoring their actual types: e.g. when a patch is compared with a raw body for
inconsistencies detection, the actual classes do not matter.

All non-equal non-mappings will be detected as a change of the whole value.
The log level is DEBUG on purpose — this case requires no action or reaction:
it is an expected behaviour when the object is deleted explicitly in the handler
or externally during the processing. We only log a line for debugging purposes,
to avoid surprises. Before inconsistencies detection, this case was silenced.
@nolar nolar added the enhancement New feature or request label Oct 5, 2020
@nolar nolar merged commit 6831c6a into master Oct 5, 2020
@nolar nolar deleted the no-warnings-on-patching-unexistent-objects branch October 5, 2020 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant