func()

in network/tools/network-policy-enforcement-latency/pod-creation-reachability-latency/test-client/client.go [181:260]


func (c *TestClient) processNextPodCreationEvent() {
	item, quit := c.podCreationWorkQueue.Get()
	if quit {
		close(c.informerStopChan)
		c.podCreationWorkQueue.ShutDown()
		return
	}
	defer c.podCreationWorkQueue.Done(item)

	startTime := time.Now()
	podEvent, ok := item.(utils.PodEvent)
	if !ok {
		klog.Warningf("Failed to convert work queue item of type %T to string key", item)
		return
	}

	// Skip Update pod events for pods that aren't tracked since their creation.
	// Only new pods should be included as targets.
	if c.skipUpdateForUntrackedPods(&podEvent) {
		return
	}

	// Get pod from informer's cache.
	objList, err := c.podInformer.GetIndexer().ByIndex(utils.NameIndex, podEvent.PodName)
	if err != nil {
		klog.Warningf("Failed to get pod object from the informer's cache, for pod name %q", podEvent.PodName)
		return
	}

	if len(objList) < 1 {
		klog.Warningf("Pod object does not exist in the informer's cache, for pod name %q", podEvent.PodName)
		return
	}

	pod, ok := objList[0].(*corev1.Pod)
	if !ok {
		klog.Warningf("processNextPodCreationEvent() failed to convert obj (%T) to *corev1.Pod", objList[0])
		return
	}

	if len(pod.Status.PodIP) == 0 {
		return
	}
	podName := pod.GetName()
	podCreationTime := pod.GetCreationTimestamp().Time
	haveMaxTargets := false

	c.targetPodsMap.Lock.Lock()
	_, targetUsed := c.targetPodsMap.Mp[podName]
	if !targetUsed {
		c.targetPodsMap.Mp[podName] = startTime
		haveMaxTargets = len(c.targetPodsMap.Mp) > c.TargetConfig.MaxTargets
	}
	c.targetPodsMap.Lock.Unlock()

	// Do the measurements only if it hasn't already been done for this pod.
	if targetUsed {
		return
	}

	// Process only up to the expected number of pods.
	if haveMaxTargets {
		c.stopInformerChan()
		return
	}

	target := &utils.TargetSpec{
		IP:        pod.Status.PodIP,
		Port:      c.TargetConfig.TargetPort,
		Name:      podName,
		Namespace: pod.GetNamespace(),
		StartTime: startTime,
	}
	go utils.RecordFirstSuccessfulRequest(target, c.MainStopChan, c.reportReachedTime)

	podAssignedIPLatency := startTime.Sub(podCreationTime)
	metrics.PodIPAddressAssignedLatency.Observe(podAssignedIPLatency.Seconds())
	klog.Infof("Test client got pod %q with assigned IP %q, %v after pod creation", podName, pod.Status.PodIP, podAssignedIPLatency)

}