KubernetesComponent's function _get_missing_kubernetes_resources() returns desired resources that the Component expects to be present in the Kubernetes cluster but are not. However, it won't be able to verify namespaced K8s resources that are provided without a namespace and thus it will return the the resource is missing while it will have been applied successfully. E.g. if we provide a template with a Role (which is a namespaced resource) but without a namespace in its metadata, Kubernetes will append a (default?) namesapce to it when applying it. As a result, _get_missing_kubernetes_resources() will then not locate the resource applied.
Reproduce
Using a charm that follows Reconcile style (aka Base charm class):
add a namespaced resource in its template but remove its namespace (e.g. remove metadata.namespace from this role)
run a simple integration test (deploying the charm)
watch the charm being in the following state
Unit Workload Agent Address Ports Message
kfp-viewer/0* blocked idle 10.1.4.207 [kubernetes:auth-and-crds] Not all resources found in cluster. This may be transient if we haven't tried to deploy t...
Proposed Solution
We should either:
state explicitly that _get_missing_kubernetes_resources() expects namespaced resources (if present) to always come with a metadata.namespace field in order to be able to validate their existence in the cluster orp
modify _get_missing_kubernetes_resources() to take into account the case of a namespaced resource without a metadata.namespace and then try to locate that resource in any namespace.
Context
KubernetesComponent's function _get_missing_kubernetes_resources() returns desired resources that the Component expects to be present in the Kubernetes cluster but are not. However, it won't be able to verify namespaced K8s resources that are provided without a
namespace
and thus it will return the the resource is missing while it will have been applied successfully. E.g. if we provide a template with aRole
(which is a namespaced resource) but without anamespace
in itsmetadata
, Kubernetes will append a (default?) namesapce to it when applying it. As a result,_get_missing_kubernetes_resources()
will then not locate the resource applied.Reproduce
Using a charm that follows Reconcile style (aka Base charm class):
metadata.namespace
from this role)Proposed Solution
We should either:
_get_missing_kubernetes_resources()
expects namespaced resources (if present) to always come with ametadata.namespace
field in order to be able to validate their existence in the cluster orp_get_missing_kubernetes_resources()
to take into account the case of a namespaced resource without ametadata.namespace
and then try to locate that resource in any namespace.