cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DQL to get workloads based on parameter cluster and namespace

vchitti
Newcomer

Hi

I have created two variables 

Cluster: 

fetch dt.entity.kubernetes_cluster
| fields entity.name
| sort entity.name asc

Namespace:

fetch dt.entity.cloud_application_namespace
| fields id, name = entity.name
// show only namespaces in the selected cluster
| filter in(id, classicEntitySelector(concat("type(CLOUD_APPLICATION_NAMESPACE),toRelationship.isClusterOfNamespace(type(KUBERNETES_CLUSTER),entityName.equals(", $Cluster, "))")))
| fields name
| sort name asc

 

Based on the above parameters Cluster and Namespace I need to get workloads.

Below query returns all deployments, I need to filter based on above cluster and namespace

fetch dt.entity.cloud_application
| fields entity.name
| dedup entity.name

Can you please guide me. Thanks

 

2 REPLIES 2

p_devulapalli
Leader

@vchitti Please try below

fetch dt.entity.cloud_application
| fieldsAdd
  clusterId = clustered_by[dt.entity.kubernetes_cluster],
  k8s.namespace.name = namespaceName
| lookup [fetch dt.entity.kubernetes_cluster
| fieldsAdd kubernetesClusterId, entity.name
], sourceField:clusterId, lookupField:id, fields:{k8s.cluster.name=entity.name}
|filter  {
  k8s.cluster.name == $Cluster AND
  k8s.namespace.name == $Namespace }
Phani Devulapalli

vchitti
Newcomer

@p_devulapalli Thank you that worked.

Featured Posts