Skip to content

Commit 084471e

Browse files
authored
Gangams/fix pod ready for completed jobs (#933)
* fix issue pod ready condition for job ready pods * fix issue pod ready condition for job ready pods * fix issue pod ready condition for job ready pods * fix issue pod ready condition for job ready pods * fix pr feedback
1 parent d7b012b commit 084471e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

source/plugins/ruby/KubernetesApiClient.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,13 +1382,13 @@ def getHpaOptimizedItem(resourceItem)
13821382
return item
13831383
end
13841384

1385-
def getPodReadyCondition(podStatusConditions)
1385+
def getPodReadyCondition(podStatusConditions, controllerKind, podStatus)
13861386
podReadyCondition = false
13871387
begin
13881388
if !podStatusConditions.nil? && !podStatusConditions.empty?
13891389
podStatusConditions.each do |condition|
13901390
if condition["type"] == "Ready"
1391-
if condition["status"].downcase == "true"
1391+
if condition["status"].downcase == "true" || isCompletedJobPod(controllerKind, podStatus)
13921392
podReadyCondition = true
13931393
end
13941394
break #Exit the for loop since we found the ready condition
@@ -1401,6 +1401,20 @@ def getPodReadyCondition(podStatusConditions)
14011401
return podReadyCondition
14021402
end
14031403

1404+
def isCompletedJobPod(controllerKind, podStatus)
1405+
isCompletedPod = false
1406+
begin
1407+
if !controllerKind.nil? & !controllerKind.empty? &&
1408+
!podStatus.nil? && !podStatus.empty? &&
1409+
controllerKind.downcase == Constants::CONTROLLER_KIND_JOB && podStatus == "Succeeded"
1410+
isCompletedPod = true
1411+
end
1412+
rescue => error
1413+
@Log.warn "in_kube_podinventory::isCompletedJobPod failed with an error: #{err}"
1414+
end
1415+
return isCompletedPod
1416+
end
1417+
14041418
def isEmitCacheTelemetry
14051419
isEmitCacheTelemtryEnabled = false
14061420
if !ENV["EMIT_CACHE_TELEMETRY"].nil? && !ENV["EMIT_CACHE_TELEMETRY"].empty? && ENV["EMIT_CACHE_TELEMETRY"].downcase == "true"

source/plugins/ruby/in_kube_podinventory.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ def getPodInventoryRecords(item, serviceRecords, batchTime = Time.utc.iso8601)
563563
mdmPodRecord["ControllerName"] = record["ControllerName"]
564564
mdmPodRecord["Namespace"] = record["Namespace"]
565565
mdmPodRecord["PodStatus"] = record["PodStatus"]
566-
mdmPodRecord["PodReadyCondition"] = KubernetesApiClient.getPodReadyCondition(item["status"]["conditions"])
567566
mdmPodRecord["ControllerKind"] = record["ControllerKind"]
567+
mdmPodRecord["PodReadyCondition"] = KubernetesApiClient.getPodReadyCondition(item["status"]["conditions"], record["ControllerKind"], record["PodStatus"])
568568
mdmPodRecord["containerRecords"] = []
569569

570570
podContainers = []

0 commit comments

Comments
 (0)