Skip to content

Commit

Permalink
fix find pod by ip when using cache (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuscscp authored Jul 8, 2024
1 parent 830b439 commit 35fc1b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions helm/gke-metadata-server/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.5.1
version: 0.5.2

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.5.1"
appVersion: "0.5.2"
14 changes: 10 additions & 4 deletions internal/pods/watch/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,22 @@ func (p *Provider) getByIP(ctx context.Context, ipAddr string) (*corev1.Pod, err
if err != nil {
return nil, fmt.Errorf("error getting pod from cache by ip address %q: %w", ipAddr, err)
}
if n := len(v); n != 1 {
var podsMatchingIP []*corev1.Pod
for _, p := range v {
pod := p.(*corev1.Pod)
if pod.Status.PodIP == ipAddr {
podsMatchingIP = append(podsMatchingIP, pod)
}
}
if n := len(podsMatchingIP); n != 1 {
refs := make([]string, n)
for i, p := range v {
pod := p.(*corev1.Pod)
for i, pod := range podsMatchingIP {
refs[i] = fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)
}
return nil, fmt.Errorf("error getting pod from cache by ip address %q: %v pods found instead of 1 [%s]",
ipAddr, n, strings.Join(refs, ", "))
}
return v[0].(*corev1.Pod), nil
return podsMatchingIP[0], nil
}

func (p *Provider) Start(ctx context.Context) {
Expand Down

0 comments on commit 35fc1b0

Please sign in to comment.