-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Pavol Loffay <[email protected]>
- Loading branch information
1 parent
712bda4
commit 61df808
Showing
3 changed files
with
64 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package e2e | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"k8s.io/api/core/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"strings" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// GetPod returns pod name | ||
func GetPod(namespace, namePrefix, ownerNamePrefix string, kubeclient kubernetes.Interface) (v1.Pod, error) { | ||
pods, err := kubeclient.CoreV1().Pods(namespace).List(metav1.ListOptions{IncludeUninitialized:true}) | ||
if err != nil { | ||
return v1.Pod{}, err | ||
} | ||
for _, pod := range pods.Items { | ||
if strings.HasPrefix(pod.Name, namePrefix) { | ||
for _, or := range pod.OwnerReferences { | ||
if strings.HasPrefix(or.Name, ownerNamePrefix) { | ||
return pod, nil | ||
} | ||
} | ||
} | ||
} | ||
return v1.Pod{}, errors.New(fmt.Sprintf("could not find pod of owner %s", ownerNamePrefix)) | ||
} |