Skip to content

Commit

Permalink
Address reporting duplicate error messages (#18)
Browse files Browse the repository at this point in the history
* Address reporting duplicate error messages
* Add duplicate stack testcase
* Work around readPod exception from Kuber.jl
  • Loading branch information
omus authored Apr 13, 2021
1 parent f865fe9 commit f43f42a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Kuber = "0.4.0"
julia = "1.3"

[extras]
Swagger = "2d69052b-6a58-5cd9-a030-a48559c324ac"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Swagger", "Test"]
13 changes: 11 additions & 2 deletions src/native_driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ const empty_pod = """{
Kuber object representing the pod this julia session is running in.
"""
function self_pod(ctx)
return get(ctx, :Pod, ENV["HOSTNAME"])
# The following code is equivalent to calling Kuber's `get(ctx, :Pod, ENV["HOSTNAME"])`
# but reduces noise by avoiding nested rethrow calls.
# Fixed in Kuber.jl in: https://github.com/JuliaComputing/Kuber.jl/pull/26
isempty(ctx.apis) && Kuber.set_api_versions!(ctx)
api_ctx = Kuber._get_apictx(ctx, :Pod, nothing)
return Kuber.readNamespacedPod(api_ctx, ENV["HOSTNAME"], ctx.namespace)
end


Expand Down Expand Up @@ -64,7 +69,11 @@ function default_pods_and_context(namespace="default"; configure, ports, driver_
ctx = KuberContext()
Kuber.set_api_versions!(ctx; verbose=false)
set_ns(ctx, namespace)
pods = Dict(port => configure(default_pod(ctx, port, cmd, driver_name; kwargs...)) for port in ports)

# Avoid using a generator with `Dict` as any raised exception would be displayed twice:
# https://github.com/JuliaLang/julia/issues/33147
pods = Dict([port => configure(default_pod(ctx, port, cmd, driver_name; kwargs...)) for port in ports])

return pods, ctx
end

Expand Down
35 changes: 33 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
using Test
using K8sClusterManagers
using Distributed
using K8sClusterManagers
using Kuber: KuberContext
using Swagger
using Test


@testset "K8sClusterManagers" begin
@testset "self_pod" begin
@testset "non-nested exceptions" begin
ctx = KuberContext()
withenv("HOSTNAME" => "localhost") do
try
K8sClusterManagers.self_pod(ctx)
catch ex
@test ex isa Swagger.ApiException
@test length(Base.catch_stack()) == 1
end
end
end
end

@testset "addprocs_pod" begin
@testset "pods not found" begin
withenv("HOSTNAME" => "localhost") do
try
K8sClusterManagers.addprocs_pod(1)
catch ex
@test ex isa Swagger.ApiException
@test length(Base.catch_stack()) == 1
end
end
end
end
end

0 comments on commit f43f42a

Please sign in to comment.