@@ -20,6 +20,9 @@ function _get_apictx(ctx::KuberContext, O::Symbol, apiversion::Union{String,Noth
20
20
apictx
21
21
end
22
22
23
+ _api_function (name:: Symbol ) = isdefined (@__MODULE__ , name) ? eval (name) : nothing
24
+ _api_function (name) = _api_function (Symbol (name))
25
+
23
26
function list (ctx:: KuberContext , O:: Symbol , name:: String , apiversion:: Union{String,Nothing} = nothing ; namespace:: Union{String,Nothing} = ctx. namespace, kwargs... )
24
27
isempty (ctx. apis) && set_api_versions! (ctx)
25
28
@@ -62,58 +65,55 @@ function get(ctx::KuberContext, O::Symbol, name::String, apiversion::Union{Strin
62
65
isempty (ctx. apis) && set_api_versions! (ctx; max_tries= max_tries)
63
66
64
67
apictx = _get_apictx (ctx, O, apiversion)
65
- try
66
- apicall = eval (Symbol (" read$O " ))
68
+ if (apicall = _api_function (" read$O " )) != = nothing
67
69
@repeat max_tries try
68
70
return apicall (apictx, name; kwargs... )
69
71
catch e
70
72
@retry if isa (e, IOError)
71
- @debug (" Retrying " , " read $O " )
73
+ @debug (" Retrying " , nameof (apicall) )
72
74
sleep (2 )
73
75
end
74
76
end
75
- catch ex
76
- isa (ex, UndefVarError) || rethrow ()
77
- apicall = eval (Symbol (" readNamespaced$O " ))
77
+ elseif (apicall = _api_function (" readNamespaced$O " )) != = nothing
78
78
@repeat max_tries try
79
79
return apicall (apictx, name, ctx. namespace; kwargs... )
80
80
catch e
81
81
@retry if isa (e, IOError)
82
- @debug (" Retrying " , " readNamespaced $O " )
82
+ @debug (" Retrying " , nameof (apicall) )
83
83
sleep (2 )
84
84
end
85
85
end
86
+ else
87
+ throw (ArgumentError (" No API functions could be located using :$O " ))
86
88
end
87
89
end
88
90
89
91
function get (ctx:: KuberContext , O:: Symbol , apiversion:: Union{String,Nothing} = nothing ; label_selector= nothing , namespace:: Union{String,Nothing} = ctx. namespace, max_tries:: Integer = 1 )
90
92
isempty (ctx. apis) && set_api_versions! (ctx; max_tries= max_tries)
91
93
92
94
apictx = _get_apictx (ctx, O, apiversion)
93
- try
94
- apiname = " list$O "
95
- (namespace === nothing ) && (apiname *= " ForAllNamespaces" )
96
- apicall = eval (Symbol (apiname))
95
+ apiname = " list$O "
96
+ namespace === nothing && (apiname *= " ForAllNamespaces" )
97
+ if (apicall = _api_function (apiname)) != = nothing
97
98
@repeat max_tries try
98
99
return apicall (apictx; labelSelector= label_selector)
99
100
catch e
100
101
@retry if isa (e, IOError)
101
- @debug (" Retrying " , apiname )
102
+ @debug (" Retrying " , nameof (apicall) )
102
103
sleep (2 )
103
104
end
104
105
end
105
- catch ex
106
- isa (ex, UndefVarError) || rethrow ()
107
- (namespace === nothing ) && rethrow ()
108
- apicall = eval (Symbol (" listNamespaced$O " ))
106
+ elseif (apicall = _api_function (" listNamespaced$O " )) != = nothing
109
107
@repeat max_tries try
110
108
return apicall (apictx, namespace; labelSelector= label_selector)
111
109
catch e
112
110
@retry if isa (e, IOError)
113
- @debug (" Retrying " , " listNamespaced $O " )
111
+ @debug (" Retrying " , nameof (apicall) )
114
112
sleep (2 )
115
113
end
116
114
end
115
+ else
116
+ throw (ArgumentError (" No API functions could be located using :$O " ))
117
117
end
118
118
end
119
119
@@ -126,13 +126,12 @@ function put!(ctx::KuberContext, O::Symbol, d::Dict{String,Any})
126
126
isempty (ctx. apis) && set_api_versions! (ctx)
127
127
128
128
apictx = _get_apictx (ctx, O, get (d, " apiVersion" , nothing ))
129
- try
130
- apicall = eval (Symbol (" create$O " ))
129
+ if (apicall = _api_function (" create$O " )) != = nothing
131
130
return apicall (apictx, d)
132
- catch ex
133
- isa (ex, UndefVarError) || rethrow ()
134
- apicall = eval (Symbol (" createNamespaced$O " ))
131
+ elseif (apicall = _api_function (" createNamespaced$O " )) != = nothing
135
132
return apicall (apictx, ctx. namespace, d)
133
+ else
134
+ throw (ArgumentError (" No API functions could be located using :$O " ))
136
135
end
137
136
end
138
137
@@ -149,14 +148,13 @@ function delete!(ctx::KuberContext, O::Symbol, name::String, apiversion::Union{S
149
148
150
149
params = [apictx, name]
151
150
152
- try
153
- apicall = eval (Symbol (" delete$O " ))
151
+ if (apicall = _api_function (" delete$O " )) != = nothing
154
152
return apicall (params... ; kwargs... )
155
- catch ex
156
- isa (ex, UndefVarError) || rethrow ()
157
- apicall = eval (Symbol (" deleteNamespaced$O " ))
153
+ elseif (apicall = _api_function (" deleteNamespaced$O " )) != = nothing
158
154
push! (params, ctx. namespace)
159
155
return apicall (params... ; kwargs... )
156
+ else
157
+ throw (ArgumentError (" No API functions could be located using :$O " ))
160
158
end
161
159
end
162
160
@@ -172,13 +170,12 @@ function update!(ctx::KuberContext, O::Symbol, name::String, patch, patch_type,
172
170
173
171
apictx = _get_apictx (ctx, O, apiversion)
174
172
175
- try
176
- apicall = eval (Symbol (" patch$O " ))
173
+ if (apicall = _api_function (" patch$O " )) != = nothing
177
174
return apicall (apictx, name, patch; _mediaType= patch_type)
178
- catch ex
179
- isa (ex, UndefVarError) || rethrow ()
180
- apicall = eval (Symbol (" patchNamespaced$O " ))
175
+ elseif (apicall = _api_function (" patchNamespaced$O " )) != = nothing
181
176
return apicall (apictx, name, ctx. namespace, patch; _mediaType= patch_type)
177
+ else
178
+ throw (ArgumentError (" No API functions could be located using :$O " ))
182
179
end
183
180
end
184
181
0 commit comments