I cannot find a way to check if a specific namespace exists or not, while printing a helpful error message (without using “run” collector).
Any ideas?
P.S. I tried the following, which works well for the positive case (namespace exists), but for the negative case (namespace doesn’t exist), it will return an inaccurate message “YAML path provided is invalid”, even if the resource doesn’t exist at all. I would rather expect “Resource doesn’t exist” or something.
---
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
metadata:
name: namespace-check
spec:
collectors:
- clusterResources: {}
- clusterInfo:
exclude: true
analyzers:
- clusterResource:
checkName: "Namespace check"
kind: namespace
name: foobar
yamlPath: "status.phase"
regex: Active
clusterScoped: true
outcomes:
- pass:
when: "true"
message: "Namespace 'foobar' exists"
- warn:
when: "false"
message: "Namespace 'foobar' doesn't exist"