kubernetesgoogle-cloud-platformkubectlkubernetes-operatorgcp-config-connector

Is there a way to list all resources created by a specific operator and their status?


I use config connector https://cloud.google.com/config-connector/docs/overview

I create gcp resources with CRDs that config connector provides:

kind: IAMServiceAccount
kind: StorageBucket
etc

Now what I'd really like is to be able to get a simple list of each resource and its status (if it was created successfully or not). Where each resource is a single line that's something like: kind, name, status, etc

Is there a way with kubectl to get a list of all resources that were created by an operator like this? I suppose I could manually label all these resources and try to select with a label but I really don't want to do that

Edit

Per the comment I could do this, but curious if there is a less unwieldy command

kubectl get crds --selector cnrm.cloud.google.com/managed-by-kcc=true \
    -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | xargs -n 1 \
    kubectl get -Ao jsonpath='{range .items[*]}{" Kind: "}{@.kind}{"Name: "}{@.metadata.name}{" Status: "}{@.status.conditions[].status}{" Reason: "}{@.status.conditions[].reason}{"\n"}{end}' --ignore-not-found

Solution

  • I've made a bit of research on this topic and I found 2 possible solutions to retrieve all the resources that were created by config-connector:

    The discussion that is referencing similar issue can be found here:


    $ kubectl api-resources

    As pointed in the comment I made you can use the following expression:

    kubectl get crds --selector cnrm.cloud.google.com/managed-by-kcc=true -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | xargs -n 1 kubectl get --ignore-not-found
    

    Dissecting this solution:

    This command could also be altered to suit the specific needs as it's shown in the question.

    A side note!

    Similar command is referenced in the github link I pasted above:


    $ kubectl get-all/ketall

    Above commands can be used to retrieve all of the resources in the cluster. They are not available in default kubectl and they need additional configuration.

    More reference about the installation can be found in this github page:

    Using the approach described in the official Kubernetes documentation:

    Labels are intended to be used to specify identifying attributes of objects

    Kubernetes.io: Docs: Concepts: Overview: Working with objects: Labels

    You can label those resources created by config connector (I know that you would like to avoid it) and look for this resources like:

    NAME                                                                      NAMESPACE         AGE
    storagebucket.storage.cnrm.cloud.google.com/config-connector-bucket       config-connector  135m
    storagebucket.storage.cnrm.cloud.google.com/config-connector-bucket-test  config-connector  13s
    

    This resources have the .metadata.labels.look=here added to it's definitions.


    Additional resources: