Skip to content

Commit

Permalink
ignore port forward stop errors (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Schrock authored and Derek Smart committed Nov 26, 2019
1 parent 45ffebc commit c368d0f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/kotlin/io/titandata/titan/clients/Kubernetes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import io.kubernetes.client.models.V1VolumeMountBuilder
import io.kubernetes.client.util.ClientBuilder
import io.kubernetes.client.util.Config
import io.titandata.models.Volume
import io.titandata.titan.exceptions.CommandException
import io.titandata.titan.utils.CommandExecutor

class Kubernetes() {
Expand Down Expand Up @@ -210,9 +211,13 @@ class Kubernetes() {
fun stopPortFowarding(repoName: String) {
val service = coreApi.readNamespacedService(repoName, defaultNamespace, null, null, null)
for (port in service.spec.ports) {
val output = executor.exec(listOf("sh", "-c", "ps -ef | grep \"[k]ubectl port-forward svc/$repoName ${port.port}\""))
val pid = output.split("\\s+".toRegex())[2]
executor.exec(listOf("kill", pid))
try {
val output = executor.exec(listOf("sh", "-c", "ps -ef | grep \"[k]ubectl port-forward svc/$repoName ${port.port}\""))
val pid = output.split("\\s+".toRegex())[2]
executor.exec(listOf("kill", pid))
} catch (e: CommandException) {
// Ignore errors in case port forwarding dies
}
}
}

Expand Down

0 comments on commit c368d0f

Please sign in to comment.