Skip to content

Commit 9c0cfdd

Browse files
authored
Fix Kuber.get: Handle non-namespaced and all-namespaced queries (#59)
* Fix Kuber.get: Handle non-namespaced and all-namespaced queries * Fix * Fix * Update version in Project.toml
1 parent 63a8dce commit 9c0cfdd

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors = ["Tanmay Mohapatra <[email protected]>"]
44
keywords = ["kubernetes", "client"]
55
license = "MIT"
66
desc = "Julia Kubernetes Client"
7-
version = "0.7.2"
7+
version = "0.7.3"
88

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

src/simpleapi.jl

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,20 @@ function get(ctx::Union{KuberContext,KuberWatchContext}, O::Symbol, name::String
143143
max_tries::Integer=retries(ctx),
144144
watch=isa(ctx, KuberWatchContext),
145145
resource_version=nothing,
146+
namespace::Union{String,Nothing}=_kubectx(ctx).namespace,
146147
kwargs...)
147148
apictx = _get_apictx(ctx, O, apiversion; max_tries=max_tries)
149+
namespaced = (namespace !== nothing) && !isempty(namespace)
150+
allnamespaces = namespaced && (namespace == "*")
148151

149152
eventstream = isa(ctx, KuberWatchContext) ? ctx.stream : nothing
150153
result = nothing
151154
args = Any[name]
152155
_O_ = to_snake_case(string(O))
153-
if (apicall = _api_function(ctx, "read_$(_O_)")) !== nothing
156+
if namespaced && !allnamespaces && (apicall = _api_function(ctx, "read_namespaced_$(_O_)")) !== nothing
157+
push!(args, namespace)
158+
elseif (apicall = _api_function(ctx, "read_$(_O_)")) !== nothing
154159
# nothing
155-
elseif (apicall = _api_function(ctx, "read_namespaced_$(_O_)")) !== nothing
156-
push!(args, _kubectx(ctx).namespace)
157160
else
158161
throw(ArgumentError("No API functions could be located using $O"))
159162
end
@@ -189,17 +192,22 @@ function get(ctx::Union{KuberContext,KuberWatchContext}, O::Symbol;
189192
resource_version=nothing,
190193
kwargs...)
191194
apictx = _get_apictx(ctx, O, apiversion; max_tries=max_tries)
195+
namespaced = (namespace !== nothing) && !isempty(namespace)
196+
allnamespaces = namespaced && (namespace == "*")
192197

193198
eventstream = isa(ctx, KuberWatchContext) ? ctx.stream : nothing
194199
result = nothing
195200
args = Any[]
196201
_O_ = to_snake_case(string(O))
197202
apiname = "list_$(_O_)"
198-
namespace === nothing && (apiname *= "_for_all_namespaces")
199-
if (apicall = _api_function(ctx, apiname)) !== nothing
200-
# nothing
201-
elseif (apicall = _api_function(ctx, "list_namespaced_$(_O_)")) !== nothing
203+
if allnamespaces && (apicall = _api_function(ctx, apiname * "_for_all_namespaces")) !== nothing
204+
#nothing
205+
elseif namespaced && (apicall = _api_function(ctx, "list_namespaced_$(_O_)")) !== nothing
202206
push!(args, namespace)
207+
elseif (apicall = _api_function(ctx, apiname)) !== nothing
208+
#nothing
209+
elseif (apicall = _api_function(ctx, apiname * "_for_all_namespaces")) !== nothing
210+
#nothing
203211
else
204212
throw(ArgumentError("No API functions could be located using $O"))
205213
end

0 commit comments

Comments
 (0)