fix: improve pod instance ID matching logic in AutoScaler and HealthMonitor
Build & Test (NowChessSystems) TeamCity build finished
Build & Test (NowChessSystems) TeamCity build finished
This commit is contained in:
@@ -51,7 +51,7 @@ class AutoScaler:
|
|||||||
drainingForScaleDown.remove(instanceId)
|
drainingForScaleDown.remove(instanceId)
|
||||||
|
|
||||||
def clearDrainingByPodName(podName: String): Unit =
|
def clearDrainingByPodName(podName: String): Unit =
|
||||||
drainingForScaleDown.asScala.find(podName.contains).foreach(drainingForScaleDown.remove)
|
drainingForScaleDown.asScala.find(id => id.contains(podName)).foreach(drainingForScaleDown.remove)
|
||||||
|
|
||||||
private def kubeClientOpt: Option[KubernetesClient] =
|
private def kubeClientOpt: Option[KubernetesClient] =
|
||||||
if kubeClientInstance.isUnsatisfied then None
|
if kubeClientInstance.isUnsatisfied then None
|
||||||
@@ -124,7 +124,7 @@ class AutoScaler:
|
|||||||
try
|
try
|
||||||
val pods =
|
val pods =
|
||||||
kube.pods().inNamespace(config.k8sNamespace).withLabel(config.k8sRolloutLabelSelector).list().getItems.asScala
|
kube.pods().inNamespace(config.k8sNamespace).withLabel(config.k8sRolloutLabelSelector).list().getItems.asScala
|
||||||
pods.find(_.getMetadata.getName.contains(instanceId)).exists { pod =>
|
pods.find(pod => instanceId.contains(pod.getMetadata.getName)).exists { pod =>
|
||||||
try
|
try
|
||||||
val requests = Option(pod.getSpec)
|
val requests = Option(pod.getSpec)
|
||||||
.flatMap(s => Option(s.getContainers))
|
.flatMap(s => Option(s.getContainers))
|
||||||
@@ -302,7 +302,7 @@ class AutoScaler:
|
|||||||
.list()
|
.list()
|
||||||
.getItems
|
.getItems
|
||||||
.asScala
|
.asScala
|
||||||
pods.find(_.getMetadata.getName.contains(instanceId)) match
|
pods.find(pod => instanceId.contains(pod.getMetadata.getName)) match
|
||||||
case Some(pod) =>
|
case Some(pod) =>
|
||||||
kube.pods().inNamespace(config.k8sNamespace).withName(pod.getMetadata.getName).withGracePeriod(0L).delete()
|
kube.pods().inNamespace(config.k8sNamespace).withName(pod.getMetadata.getName).withGracePeriod(0L).delete()
|
||||||
log.infof("Force-deleted pod for drained instance %s", instanceId)
|
log.infof("Force-deleted pod for drained instance %s", instanceId)
|
||||||
|
|||||||
+3
-3
@@ -130,7 +130,7 @@ class HealthMonitor:
|
|||||||
|
|
||||||
pods.exists { pod =>
|
pods.exists { pod =>
|
||||||
val podName = pod.getMetadata.getName
|
val podName = pod.getMetadata.getName
|
||||||
podName.contains(instanceId) && isPodReady(pod)
|
instanceId.contains(podName) && isPodReady(pod)
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
case ex: Exception =>
|
case ex: Exception =>
|
||||||
@@ -184,7 +184,7 @@ class HealthMonitor:
|
|||||||
.getItems
|
.getItems
|
||||||
.asScala
|
.asScala
|
||||||
|
|
||||||
pods.find(pod => pod.getMetadata.getName.contains(instanceId)) match
|
pods.find(pod => instanceId.contains(pod.getMetadata.getName)) match
|
||||||
case Some(pod) =>
|
case Some(pod) =>
|
||||||
val podName = pod.getMetadata.getName
|
val podName = pod.getMetadata.getName
|
||||||
kube.pods().inNamespace(config.k8sNamespace).withName(podName).withGracePeriod(0L).delete()
|
kube.pods().inNamespace(config.k8sNamespace).withName(podName).withGracePeriod(0L).delete()
|
||||||
@@ -244,4 +244,4 @@ class HealthMonitor:
|
|||||||
|
|
||||||
private def findRegisteredInstance(pod: Pod): Option[InstanceMetadata] =
|
private def findRegisteredInstance(pod: Pod): Option[InstanceMetadata] =
|
||||||
val podName = pod.getMetadata.getName
|
val podName = pod.getMetadata.getName
|
||||||
instanceRegistry.getAllInstances.find(inst => podName.contains(inst.instanceId))
|
instanceRegistry.getAllInstances.find(inst => inst.instanceId.contains(podName))
|
||||||
|
|||||||
Reference in New Issue
Block a user