public async Task GetMyPodAsync()

in src/ApplicationInsights.Kubernetes/K8sQueryClient.cs [54:78]


        public async Task<K8sPod> GetMyPodAsync()
        {
            EnsureNotDisposed();

            var allPods = await GetPodsAsync().ConfigureAwait(false);
            K8sPod targetPod = null;
            string podName = Environment.GetEnvironmentVariable(@"APPINSIGHTS_KUBERNETES_POD_NAME");
            string myContainerId = KubeHttpClient.Settings.ContainerId;
            if (!string.IsNullOrEmpty(podName))
            {
                targetPod = allPods.FirstOrDefault(p => p.Metadata.Name.Equals(podName, StringComparison.Ordinal));
            }
            else if (!string.IsNullOrEmpty(myContainerId))
            {
                targetPod = allPods.FirstOrDefault(pod => pod.Status != null &&
                                    pod.Status.ContainerStatuses != null &&
                                    pod.Status.ContainerStatuses.Any(
                                        cs => !string.IsNullOrEmpty(cs.ContainerID) && cs.ContainerID.EndsWith(myContainerId, StringComparison.Ordinal)));
            }
            else
            {
                _logger.LogError("Neither container id nor %APPINSIGHTS_KUBERNETES_POD_NAME% could be fetched.");
            }
            return targetPod;
        }