This is an automated email from the ASF dual-hosted git repository.

liuhan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-rover.git


The following commit(s) were added to refs/heads/main by this push:
     new a2c3693  Add `HasOwnerName` to judgement pod has owner name (#99)
a2c3693 is described below

commit a2c369331c0b0f56b464429ca2e6d18d310ec571
Author: mrproliu <[email protected]>
AuthorDate: Wed Aug 30 16:15:59 2023 +0800

    Add `HasOwnerName` to judgement pod has owner name (#99)
---
 CHANGES.md                                         |  1 +
 .../configuration/process_discovery/kubernetes.md  | 38 ++++++++++++----------
 pkg/process/finders/kubernetes/template.go         |  5 +++
 3 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index dfb6eca..97baef8 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -7,6 +7,7 @@ Release Notes.
 #### Features
 * Enhance compatibility when profiling with SSL.
 * Update `LabelValue` obtain pod information function to add default value 
parameter.
+* Add `HasOwnerName` to judgement pod has owner name.
 
 #### Bug Fixes
 
diff --git a/docs/en/setup/configuration/process_discovery/kubernetes.md 
b/docs/en/setup/configuration/process_discovery/kubernetes.md
index 2640427..1291948 100644
--- a/docs/en/setup/configuration/process_discovery/kubernetes.md
+++ b/docs/en/setup/configuration/process_discovery/kubernetes.md
@@ -39,16 +39,17 @@ Is the same with the [process context in 
scanner](./scanner.md#process), but doe
 
 Provide current pod information and judgments.
 
-| Name           | Argument       | Example                              | 
Description                                                                     
                                                                                
                                                 |
-|----------------|----------------|--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| Name           | None           | `eq .Pod.Name "test-pod-name"`       | The 
name of the current pod. The example shows the pod name is equal to 
`test-pod-name`.                                                                
                                                         |
-| Namespace      | None           | `eq .Pod.Namespace "test-namesapce"` | The 
name of the current pod namespace. The example shows the pod namespace name is 
equal to `test-namespace`.                                                      
                                              |
-| Node           | None           | `eq .Pod.Node "test-node"`           | The 
name of the node deployed. The example shows the pod node name is equal to 
`test-node`.                                                                    
                                                  |
-| LabelValue     | KeyNames       | `eq .Pod.LavelValue "a,b" "v"`       | The 
label value of the label keys, If provide multiple keys, if any key has value, 
then don't need to get other values. The example shows the pod has anyone `a` 
or `b` label key, and the value matches to `v`. |
-| ServiceName    | None           | `eq .Pod.ServiceName "test-service"` | The 
service name of the pod. The example shows current pods matched service name is 
`test-service`.                                                                 
                                             |
-| HasContainer   | Container name | `.Pod.HasContainer "istio-proxy"`    | The 
pod has the appointed container name.                                           
                                                                                
                                             |
-| LabelSelector  | selector       | `.Pod.LabelSelector`                 | The 
pod is matches the label selector. For more details, please read the [official 
documentation](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors).
                    |
-| HasServiceName | None           | `.Pod.HasServiceName`                | The 
pod has the matched service.                                                    
                                                                                
                                             |
+| Name           | Argument       | Example                                  | 
Description                                                                     
                                                                                
                                                 |
+|----------------|----------------|------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| Name           | None           | `eq .Pod.Name "test-pod-name"`           | 
The name of the current pod. The example shows the pod name is equal to 
`test-pod-name`.                                                                
                                                         |
+| Namespace      | None           | `eq .Pod.Namespace "test-namesapce"`     | 
The name of the current pod namespace. The example shows the pod namespace name 
is equal to `test-namespace`.                                                   
                                                 |
+| Node           | None           | `eq .Pod.Node "test-node"`               | 
The name of the node deployed. The example shows the pod node name is equal to 
`test-node`.                                                                    
                                                  |
+| LabelValue     | KeyNames       | `eq .Pod.LavelValue "a,b" "v"`           | 
The label value of the label keys, If provide multiple keys, if any key has 
value, then don't need to get other values. The example shows the pod has 
anyone `a` or `b` label key, and the value matches to `v`. |
+| ServiceName    | None           | `eq .Pod.ServiceName "test-service"`     | 
The service name of the pod. The example shows current pods matched service 
name is `test-service`.                                                         
                                                     |
+| HasContainer   | Container name | `.Pod.HasContainer "istio-proxy"`        | 
The pod has the appointed container name.                                       
                                                                                
                                                 |
+| LabelSelector  | selector       | `.Pod.LabelSelector`                     | 
The pod is matches the label selector. For more details, please read the 
[official 
documentation](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors).
                    |
+| HasServiceName | None           | `.Pod.HasServiceName`                    | 
The pod has the matched service.                                                
                                                                                
                                                 |
+| HasOwnerName   | kindNames      | `.Pod.HasOwnerName "Service,Deployment"` | 
The pod has the matched owner name.                                             
                                                                                
                                                 |
 
 #### Container Context
 
@@ -75,14 +76,15 @@ Same with the [process context in the 
scanner](./scanner.md#process).
 
 The information on the current pod.
 
-| Name          | Argument          | Example                           | 
Description                                                                     
                                                                                
                     |
-|---------------|-------------------|-----------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| Name          | None              | `{{.Pod.Name}}`                   | The 
name of current pod.                                                            
                                                                                
                 |
-| Namespace     | None              | `{{.Pod.Namespace}}`              | The 
name of current pod namespace.                                                  
                                                                                
                 |
-| Node          | None              | `{{.Pod.Node}}`                   | The 
name of the node deployed.                                                      
                                                                                
                 |
-| LabelValue    | KeyNames, Default | `{{.Pod.LabelValue "a,b" "v"}}`   | The 
label value of the label keys, If provide multiple keys, if any key has value, 
then don't need to get other values. If all keys don't have value, then return 
the default value. |
-| ServiceName   | None              | `{{.Pod.ServiceName}}`            | The 
service name of the pod. If the pod hasn't matched service, then return an 
empty string.                                                                   
                      |
-| FindContainer | ContainerName     | `{{.Pod.FindContainer "test"}}`   | Find 
the Container context by container name.                                        
                                                                                
                |
+| Name          | Argument          | Example                                  
 | Description                                                                  
                                                                                
                        |
+|---------------|-------------------|-------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| Name          | None              | `{{.Pod.Name}}`                          
 | The name of current pod.                                                     
                                                                                
                        |
+| Namespace     | None              | `{{.Pod.Namespace}}`                     
 | The name of current pod namespace.                                           
                                                                                
                        |
+| Node          | None              | `{{.Pod.Node}}`                          
 | The name of the node deployed.                                               
                                                                                
                        |
+| LabelValue    | KeyNames, Default | `{{.Pod.LabelValue "a,b" "v"}}`          
 | The label value of the label keys, If provide multiple keys, if any key has 
value, then don't need to get other values. If all keys don't have value, then 
return the default value. |
+| ServiceName   | None              | `{{.Pod.ServiceName}}`                   
 | The service name of the pod. If the pod hasn't matched service, then return 
an empty string.                                                                
                         |
+| FindContainer | ContainerName     | `{{.Pod.FindContainer "test"}}`          
 | Find the Container context by container name.                                
                                                                                
                        |
+| OwnerName     | KindNames         | `{{.Pod.OwnerName 
"Service,Deployment"}}` | Find the Owner name by owner kind name.               
                                                                                
                                               |
 
 #### Container
 
diff --git a/pkg/process/finders/kubernetes/template.go 
b/pkg/process/finders/kubernetes/template.go
index d54e3c5..cea08f9 100644
--- a/pkg/process/finders/kubernetes/template.go
+++ b/pkg/process/finders/kubernetes/template.go
@@ -166,6 +166,11 @@ func (t *TemplatePodJudgment) HasServiceName() bool {
        return t.ServiceName() != ""
 }
 
+func (t *TemplatePodJudgment) HasOwnerName(names string) bool {
+       name, err := t.OwnerName(names)
+       return err == nil && name != ""
+}
+
 type TemplateContainer struct {
        pc *PodContainer
 }

Reply via email to