Skip to content

Commit

Permalink
Feat: Support search pods by pod ip (kubesphere#5921)
Browse files Browse the repository at this point in the history
feat: support search pods by pod ip

Signed-off-by: wenhaozhou <[email protected]>
  • Loading branch information
zhou1203 authored Sep 21, 2023
1 parent a81d22c commit 925f309
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/models/resources/v1alpha3/pod/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
fieldServiceName = "serviceName"
fieldPhase = "phase"
fieldStatus = "status"
fieldPodIP = "podIP"

statusTypeWaitting = "Waiting"
statusTypeRunning = "Running"
Expand Down Expand Up @@ -103,11 +104,22 @@ func (p *podsGetter) filter(object runtime.Object, filter query.Filter) bool {
return statusType == string(filter.Value)
case fieldPhase:
return string(pod.Status.Phase) == string(filter.Value)
case fieldPodIP:
return p.podWithIP(pod, string(filter.Value))
default:
return v1alpha3.DefaultObjectMetaFilter(pod.ObjectMeta, filter)
}
}

func (p *podsGetter) podWithIP(item *corev1.Pod, ipAddress string) bool {
for _, ip := range item.Status.PodIPs {
if strings.Contains(ip.String(), ipAddress) {
return true
}
}
return false
}

func (p *podsGetter) podBindPVC(item *corev1.Pod, pvcName string) bool {
for _, v := range item.Spec.Volumes {
if v.VolumeSource.PersistentVolumeClaim != nil &&
Expand Down

0 comments on commit 925f309

Please sign in to comment.