Plugin select deployment using replicaset name
This commit is contained in:
parent
b87cc5a1a6
commit
7c6b2a1566
2 changed files with 21 additions and 1 deletions
|
@ -253,7 +253,7 @@ func getDeploymentPods(flags *genericclioptions.ConfigFlags, deployment string)
|
|||
|
||||
ingressPods := make([]apiv1.Pod, 0)
|
||||
for _, pod := range pods {
|
||||
if pod.Spec.Containers[0].Name == deployment {
|
||||
if util.PodInDeployment(pod, deployment) {
|
||||
ingressPods = append(ingressPods, pod)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
|
@ -101,6 +102,25 @@ func isVersionLessThan(a, b string) bool {
|
|||
return aPatch < bPatch
|
||||
}
|
||||
|
||||
// PodInDeployment returns whether a pod is part of a deployment with the given name
|
||||
// a pod is considered to be in {deployment} if it is owned by a replicaset with a name of format {deployment}-otherchars
|
||||
func PodInDeployment(pod apiv1.Pod, deployment string) bool {
|
||||
for _, owner := range pod.OwnerReferences {
|
||||
if owner.Controller == nil || !*owner.Controller || owner.Kind != "ReplicaSet" {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.Count(owner.Name, "-") != strings.Count(deployment, "-")+1 {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasPrefix(owner.Name, deployment+"-") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// AddPodFlag adds a --pod flag to a cobra command
|
||||
func AddPodFlag(cmd *cobra.Command) *string {
|
||||
v := ""
|
||||
|
|
Loading…
Reference in a new issue