Skip to content

Commit d25bda1

Browse files
authored
misc fixes and code improvements (#60)
Fixed a typo. Added some checks and code improvements.
1 parent 9c0cfdd commit d25bda1

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name = "Kuber"
22
uuid = "87e52247-8a1b-5e01-9430-8fbcac83a23a"
3-
authors = ["Tanmay Mohapatra <[email protected]>"]
3+
authors = ["JuliaHub Inc."]
44
keywords = ["kubernetes", "client"]
55
license = "MIT"
66
desc = "Julia Kubernetes Client"
7-
version = "0.7.3"
7+
version = "0.7.4"
88

99
[deps]
1010
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/helpers.jl

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Keyword Args:
126126
- count: how many times to retry (default 5)
127127
- all_apis: whether to retry even mutating APIs e.g. `put!` (default false)
128128
"""
129-
function set_retries(ctx::KuberContext; count::Int=ctx.default_retries, all_apis::Bool=ctx.all_apis)
129+
function set_retries(ctx::KuberContext; count::Int=ctx.default_retries, all_apis::Bool=ctx.retry_all_apis)
130130
ctx.default_retries = count
131131
ctx.retry_all_apis = all_apis
132132
ctx
@@ -185,12 +185,6 @@ function header(resp::Downloads.Response, name::AbstractString, defaultval::Abst
185185
return defaultval
186186
end
187187

188-
function kuber_type(ctx::KuberContext, T, resp::Downloads.Response)
189-
ctype = header(resp, "Content-Type", "application/json")
190-
!is_json_mime(ctype) && return T
191-
kuber_type(ctx, T, String(copy(resp.body)))
192-
end
193-
194188
function kuber_type(ctx::KuberContext, T, j::Dict{String,Any})
195189
if haskey(j, "kind") && !isempty(ctx.apis)
196190
kind = j["kind"]
@@ -340,7 +334,7 @@ function fetch_all_apis_versions(ctx::KuberContext; override=nothing, verbose::B
340334
name = apigrp.name
341335
pref_vers_type = apigrp.preferredVersion
342336
pref_vers_version = override_pref(name, pref_vers_type.version, override)
343-
pref_vers = name * "/" * pref_vers_version
337+
pref_vers = string(name, "/", pref_vers_version)
344338
supported = String[]
345339

346340
try
@@ -356,17 +350,22 @@ function fetch_all_apis_versions(ctx::KuberContext; override=nothing, verbose::B
356350
end
357351

358352
for api_vers in apigrp.versions
353+
group_version = api_vers.groupVersion
359354
try
360-
gt = api_group_type(ctx, api_vers.groupVersion)
361-
td = api_typedefs(ctx, api_vers.groupVersion)
355+
if !isa(group_version, AbstractString)
356+
@error("unexpected missing group version, ignoring")
357+
continue
358+
end
359+
gt = api_group_type(ctx, group_version)
360+
td = api_typedefs(ctx, group_version)
362361
ka = KApi(gt, td)
363362
kalist = apis[Symbol(api_group(name))]
364363
if (ka != kalist[1])
365364
push!(kalist, ka)
366365
push!(supported, api_vers.version)
367366
end
368367
catch
369-
@info("unsupported $(api_vers.groupVersion)")
368+
@info("unsupported $(group_version)")
370369
end
371370
end
372371

@@ -392,13 +391,13 @@ function fetch_core_version(ctx::KuberContext; override=nothing, verbose::Bool=f
392391
supported = String[]
393392
pref_vers = override_pref(name, api_vers.versions[1], override)
394393

395-
apis[:Core] = [KApi(getfield(apimodule(ctx), Symbol("Core" * camel(pref_vers) * "Api")), getfield(getfield(apimodule(ctx), :Typedefs), Symbol("Core" * camel(pref_vers))))]
394+
apis[:Core] = [KApi(getfield(apimodule(ctx), Symbol(string("Core", camel(pref_vers), "Api"))), getfield(getfield(apimodule(ctx), :Typedefs), Symbol(string("Core", camel(pref_vers)))))]
396395
push!(supported, pref_vers)
397396

398397
for api_vers in api_vers.versions
399398
try
400-
gt = getfield(apimodule(ctx), Symbol("Core" * camel(api_vers) * "Api"))
401-
td = getfield(getfield(apimodule(ctx), :Typedefs), Symbol("Core" * camel(api_vers)))
399+
gt = getfield(apimodule(ctx), Symbol(string("Core", camel(api_vers), "Api")))
400+
td = getfield(getfield(apimodule(ctx), :Typedefs), Symbol(string("Core", camel(api_vers))))
402401
ka = KApi(gt, td)
403402
kalist = apis[:Core]
404403
if (ka != kalist[1])

src/simpleapi.jl

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ function list(ctx::Union{KuberContext,KuberWatchContext}, O::Symbol, name::Strin
8080
if result !== nothing
8181
resource_version = result.metadata.resourceVersion
8282
# push the first Event consisting of existing data
83-
put!(eventstream, result)
83+
if isnothing(eventstream)
84+
throw(ArgumentError("Event stream not provided in watch mode"))
85+
else
86+
put!(eventstream, result)
87+
end
8488
end
8589

8690
# start watch and return the HTTP response object on completion
@@ -127,7 +131,11 @@ function list(ctx::Union{KuberContext,KuberWatchContext}, O::Symbol;
127131
if result !== nothing
128132
resource_version = result.metadata.resourceVersion
129133
# push the first Event consisting of existing data
130-
put!(eventstream, result)
134+
if isnothing(eventstream)
135+
throw(ArgumentError("Event stream not provided in watch mode"))
136+
else
137+
put!(eventstream, result)
138+
end
131139
end
132140

133141
# start watch and return the HTTP response object on completion
@@ -172,7 +180,11 @@ function get(ctx::Union{KuberContext,KuberWatchContext}, O::Symbol, name::String
172180
if result !== nothing
173181
resource_version = result.metadata.resourceVersion
174182
# push the first Event consisting of existing data
175-
put!(eventstream, result)
183+
if isnothing(eventstream)
184+
throw(ArgumentError("Event stream not provided in watch mode"))
185+
else
186+
put!(eventstream, result)
187+
end
176188
end
177189

178190
# start watch and return the HTTP response object on completion
@@ -223,7 +235,11 @@ function get(ctx::Union{KuberContext,KuberWatchContext}, O::Symbol;
223235
if result !== nothing
224236
resource_version = result.metadata.resourceVersion
225237
# push the first Event consisting of existing data
226-
put!(eventstream, result)
238+
if isnothing(eventstream)
239+
throw(ArgumentError("Event stream not provided in watch mode"))
240+
else
241+
put!(eventstream, result)
242+
end
227243
end
228244

229245
# start watch and return the HTTP response object on completion

0 commit comments

Comments
 (0)