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

Fix handling of managedResourceTypes #1851

Merged
merged 5 commits into from
Sep 20, 2021

Conversation

Piojo
Copy link
Contributor

@Piojo Piojo commented Sep 16, 2021

We were silently skipping resource types we weren't managing, making
troubleshooting misconfigurations very hard.

First, we add type hints to openshift_base.init_specs_to_fetch, to
make it easier to understand and to refactor.

Then, we can log skipped managedResourceNames in this method. This PR
refactors the namespace handling path to achieve that. There are unit
tests to confirm the behaviour is the same as it used to be, but
please have a look and feel free to suggest relevant configurations
that need extra tests.

Next, we raise an exception if oc.apply. There is a failure mode in
which an invalid input can be discarded and not raise any exceptions,
we now have a fall-back exception if that happens. I am not sure
unmanaged types can reach the apply phase - probably not - but I
found this bug in my investigation and it's trivial to sort out.

Afterwards, openshift_resources expects
ResourceInventory.add_desired to raise a KeyError if it tries to
add for application a resource of a kind that shouldn't be
managed. However, add_desired was silently dropping that exception
on the floor, a behaviour all remaining callers expected. So, I have
restored the exception and handled or suppressed it where appropriate.

Finally, saasherder also does its own filtering when processing SaaS
files - until now we've only handled namespaces. So we refactor a loop
in there to have more verbose logging. Writing unit tests for this one
is extremely hard, and the expansion of this list comprehension to a
loop should be easy-ish for a human reviewer to critique.

Fixes https://issues.redhat.com/browse/APPSRE-3668

@Piojo Piojo force-pushed the log-managedresourcetypes branch 3 times, most recently from 4dea32c to f296dba Compare September 16, 2021 18:23
Luis Fernando Muñoz Mejías added 4 commits September 17, 2021 01:30
They make following the code a lot easier.
If there is a new kind `Invalid value:` error when running `oc.apply`
the current code ignores it silently.

We add a fallback exception to discover such situations.
We were silently dropping any desired resources on a namespace that
doesn't expect it. This made it terribly difficult for
openshift_resources_base to report to users that it was skipping some
of their resources. And openshift_resources_base was expecting such an
exception to do the reporting.

So, we raise the exception and suppress it in the places that didn't
care about it in the first place.
I've had to refactor the namespaces part of init_specs_to_fetch so
that we can iterate by resources instead of by resource types.

It results in some more loops, but less nesting and logs become
possible. The added unit tests pass both on current master and here.
@Piojo Piojo merged commit b336692 into app-sre:master Sep 20, 2021
maorfr added a commit that referenced this pull request Sep 22, 2021
maorfr added a commit that referenced this pull request Sep 22, 2021
Piojo pushed a commit to Piojo/qontract-reconcile that referenced this pull request Sep 22, 2021
@Piojo Piojo deleted the log-managedresourcetypes branch February 8, 2022 20:00
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.

None yet

2 participants