diff --git a/common-lib/utils/k8s/health/health_pod.go b/common-lib/utils/k8s/health/health_pod.go index d066f20cf..e2670f680 100644 --- a/common-lib/utils/k8s/health/health_pod.go +++ b/common-lib/utils/k8s/health/health_pod.go @@ -61,6 +61,20 @@ func getCorev1PodHealth(pod *corev1.Pod) (*HealthStatus, error) { } } + for i, cs := range pod.Status.InitContainerStatuses { + if i < len(pod.Spec.InitContainers) && + pod.Spec.InitContainers[i].RestartPolicy != nil && + *pod.Spec.InitContainers[i].RestartPolicy == corev1.ContainerRestartPolicyAlways { + waiting := cs.State.Waiting + if waiting != nil && (strings.HasPrefix(waiting.Reason, "Err") || + strings.HasSuffix(waiting.Reason, "Error") || + strings.HasSuffix(waiting.Reason, "BackOff")) { + status = HealthStatusDegraded + messages = append(messages, waiting.Message) + } + } + } + if status != "" { return &HealthStatus{ Status: status, diff --git a/common-lib/utils/k8sObjectsUtil/ResourceTreeUtil.go b/common-lib/utils/k8sObjectsUtil/ResourceTreeUtil.go index c2ce6260a..e27154186 100644 --- a/common-lib/utils/k8sObjectsUtil/ResourceTreeUtil.go +++ b/common-lib/utils/k8sObjectsUtil/ResourceTreeUtil.go @@ -217,6 +217,10 @@ func PopulatePodInfo(un *unstructured.Unstructured) ([]commonBean.InfoItem, erro initializing := false for i := range pod.Status.InitContainerStatuses { + if pod.Spec.InitContainers[i].RestartPolicy != nil && + *pod.Spec.InitContainers[i].RestartPolicy == v1.ContainerRestartPolicyAlways { + continue // native sidecar — not a blocking init container + } container := pod.Status.InitContainerStatuses[i] restarts += int(container.RestartCount) switch { @@ -243,6 +247,16 @@ func PopulatePodInfo(un *unstructured.Unstructured) ([]commonBean.InfoItem, erro } break } + for i, cs := range pod.Status.InitContainerStatuses { + if pod.Spec.InitContainers[i].RestartPolicy != nil && + *pod.Spec.InitContainers[i].RestartPolicy == v1.ContainerRestartPolicyAlways { + totalContainers++ + restarts += int(cs.RestartCount) + if cs.Ready && cs.State.Running != nil { + readyContainers++ + } + } + } if !initializing { restarts = 0 hasRunning := false diff --git a/kubelink/go.mod b/kubelink/go.mod index 52f362a09..3a6adf7e7 100644 --- a/kubelink/go.mod +++ b/kubelink/go.mod @@ -168,4 +168,4 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.7.0 // indirect ) -replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260227055702-7fe9d47354a0 +replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260402084407-a92702e8f0ff diff --git a/kubelink/go.sum b/kubelink/go.sum index d20f6c2a9..3fd233a8a 100644 --- a/kubelink/go.sum +++ b/kubelink/go.sum @@ -65,8 +65,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260227055702-7fe9d47354a0 h1:KnmMU3qEy/QRtEJaUQNnXvCrintij+BYhOJtw+OjxYw= -github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260227055702-7fe9d47354a0/go.mod h1:d6awSGcXQc57s4PJlwcyACovJ4PgBmR9jZJ7h6CScUM= +github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260402084407-a92702e8f0ff h1:bn6Z1AlHMd8+gBZjMCHr0kE7a+QKL3ZPTlsP3rT5vp8= +github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260402084407-a92702e8f0ff/go.mod h1:d6awSGcXQc57s4PJlwcyACovJ4PgBmR9jZJ7h6CScUM= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/distribution/distribution/v3 v3.0.0 h1:q4R8wemdRQDClzoNNStftB2ZAfqOiN6UX90KJc4HjyM= diff --git a/kubelink/vendor/github.com/devtron-labs/common-lib/utils/k8s/health/health_pod.go b/kubelink/vendor/github.com/devtron-labs/common-lib/utils/k8s/health/health_pod.go index d066f20cf..e2670f680 100644 --- a/kubelink/vendor/github.com/devtron-labs/common-lib/utils/k8s/health/health_pod.go +++ b/kubelink/vendor/github.com/devtron-labs/common-lib/utils/k8s/health/health_pod.go @@ -61,6 +61,20 @@ func getCorev1PodHealth(pod *corev1.Pod) (*HealthStatus, error) { } } + for i, cs := range pod.Status.InitContainerStatuses { + if i < len(pod.Spec.InitContainers) && + pod.Spec.InitContainers[i].RestartPolicy != nil && + *pod.Spec.InitContainers[i].RestartPolicy == corev1.ContainerRestartPolicyAlways { + waiting := cs.State.Waiting + if waiting != nil && (strings.HasPrefix(waiting.Reason, "Err") || + strings.HasSuffix(waiting.Reason, "Error") || + strings.HasSuffix(waiting.Reason, "BackOff")) { + status = HealthStatusDegraded + messages = append(messages, waiting.Message) + } + } + } + if status != "" { return &HealthStatus{ Status: status, diff --git a/kubelink/vendor/github.com/devtron-labs/common-lib/utils/k8sObjectsUtil/ResourceTreeUtil.go b/kubelink/vendor/github.com/devtron-labs/common-lib/utils/k8sObjectsUtil/ResourceTreeUtil.go index c2ce6260a..e27154186 100644 --- a/kubelink/vendor/github.com/devtron-labs/common-lib/utils/k8sObjectsUtil/ResourceTreeUtil.go +++ b/kubelink/vendor/github.com/devtron-labs/common-lib/utils/k8sObjectsUtil/ResourceTreeUtil.go @@ -217,6 +217,10 @@ func PopulatePodInfo(un *unstructured.Unstructured) ([]commonBean.InfoItem, erro initializing := false for i := range pod.Status.InitContainerStatuses { + if pod.Spec.InitContainers[i].RestartPolicy != nil && + *pod.Spec.InitContainers[i].RestartPolicy == v1.ContainerRestartPolicyAlways { + continue // native sidecar — not a blocking init container + } container := pod.Status.InitContainerStatuses[i] restarts += int(container.RestartCount) switch { @@ -243,6 +247,16 @@ func PopulatePodInfo(un *unstructured.Unstructured) ([]commonBean.InfoItem, erro } break } + for i, cs := range pod.Status.InitContainerStatuses { + if pod.Spec.InitContainers[i].RestartPolicy != nil && + *pod.Spec.InitContainers[i].RestartPolicy == v1.ContainerRestartPolicyAlways { + totalContainers++ + restarts += int(cs.RestartCount) + if cs.Ready && cs.State.Running != nil { + readyContainers++ + } + } + } if !initializing { restarts = 0 hasRunning := false diff --git a/kubelink/vendor/modules.txt b/kubelink/vendor/modules.txt index 30889b78d..4187acfe3 100644 --- a/kubelink/vendor/modules.txt +++ b/kubelink/vendor/modules.txt @@ -125,7 +125,7 @@ github.com/cyphar/filepath-securejoin # github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc ## explicit github.com/davecgh/go-spew/spew -# github.com/devtron-labs/common-lib v0.0.0 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260227055702-7fe9d47354a0 +# github.com/devtron-labs/common-lib v0.0.0 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260402084407-a92702e8f0ff ## explicit; go 1.24.0 github.com/devtron-labs/common-lib/async github.com/devtron-labs/common-lib/constants @@ -1403,4 +1403,4 @@ sigs.k8s.io/structured-merge-diff/v4/value sigs.k8s.io/yaml sigs.k8s.io/yaml/goyaml.v2 sigs.k8s.io/yaml/goyaml.v3 -# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260227055702-7fe9d47354a0 +# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260402084407-a92702e8f0ff