Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions controller/api/destination/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ status:
phase: Running
podIP: 172.17.0.13`,
`
apiVersion: v1
kind: Pod
metadata:
name: name2-2
namespace: ns
status:
phase: Succeeded
podIP: 172.17.0.13`,
`
apiVersion: v1
kind: Pod
metadata:
name: name2-3
namespace: ns
status:
phase: Failed
podIP: 172.17.0.13`,
`
apiVersion: linkerd.io/v1alpha2
kind: ServiceProfile
metadata:
Expand Down
34 changes: 30 additions & 4 deletions controller/api/destination/watcher/ip_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,23 @@ func (iw *IPWatcher) GetPod(podIP string) (*corev1.Pod, error) {
}

func getResource(ip string, informer cache.SharedIndexInformer) (interface{}, error) {
objs, err := informer.GetIndexer().ByIndex(podIPIndex, ip)
matchingObjs, err := informer.GetIndexer().ByIndex(podIPIndex, ip)
if err != nil {
return nil, status.Error(codes.Unknown, err.Error())
}

objs := make([]interface{}, 0)
for _, obj := range matchingObjs {
// Ignore terminated pods,
// their IPs can be reused for new Running pods
pod, ok := obj.(*corev1.Pod)
if ok && podTerminated(pod) {
continue
}

objs = append(objs, obj)
}

if len(objs) > 1 {
return nil, status.Errorf(codes.FailedPrecondition, "IP address conflict: %v, %v", objs[0], objs[1])
}
Expand All @@ -167,6 +180,11 @@ func getResource(ip string, informer cache.SharedIndexInformer) (interface{}, er
return nil, nil
}

func podTerminated(pod *corev1.Pod) bool {
phase := pod.Status.Phase
return phase == corev1.PodSucceeded || phase == corev1.PodFailed
}

func (iw *IPWatcher) addService(obj interface{}) {
service := obj.(*corev1.Service)
if service.Namespace == kubeSystem || service.Spec.ClusterIP == "None" {
Expand Down Expand Up @@ -285,10 +303,18 @@ func (iw *IPWatcher) getOrNewServiceSubscriptions(clusterIP string) *serviceSubs
pods := []*corev1.Pod{}
for _, obj := range objs {
if pod, ok := obj.(*corev1.Pod); ok {
// Skip pods with HostNetwork.
if !pod.Spec.HostNetwork {
pods = append(pods, pod)
// Skip pods with HostNetwork
if pod.Spec.HostNetwork {
continue
}

// Ignore terminated pods,
// their IPs can be reused for new Running pods
if podTerminated(pod) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure if this change is need. Looking forward to any feedback

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to omit terminated pods any time we are using the pod ip index. So yes, I think this makes sense.

continue
}

pods = append(pods, pod)
}
}
if len(pods) > 1 {
Expand Down