Skip to content

Commit bc67930

Browse files
authored
Merge pull request #38 from JuliaComputing/tan/misc
add support for watch APIs
2 parents 8727bee + b4f0353 commit bc67930

File tree

82 files changed

+14305
-1210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+14305
-1210
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.4.2"
7+
version = "0.4.3"
88

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

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,37 @@ Kubernetes APIs are mapped to these easy to use verbs, familiar to Julia users.
3939
- `delete!`: delete existing entities
4040
- `sel`: creates a label selector to use with other verbs
4141

42-
All verbs have the signature: `verb(ctx::KuberContext, T::Symbol, args...; kwargs...)`.
42+
All verbs have the signature:
43+
44+
```julia
45+
verb(ctx::KuberContext, T::Symbol, args...; kwargs...)
46+
```
47+
48+
Kubernetes also provides efficient change notifications on resources via "watches". Certain entities have the special `watch` APIs defined for them and that can be invoked with the `watch` verb. The `watch` API accepts a `Channel` through which it streams events.
49+
50+
```julia
51+
watch(ctx::KuberContext, T::Symbol, outstream::Channel, args...; kwargs...)
52+
```
53+
54+
In addition, verbs like `get` and `list` also support watches, and those can be invoked as:
55+
56+
```julia
57+
watch(ctx, verb, args...; kwargs...) do stream
58+
for event in stream
59+
# process event
60+
end
61+
end
62+
```
63+
64+
E.g.:
65+
66+
```julia
67+
watch(ctx, list, :Pod; resourceVersion=19451) do stream
68+
for event in stream
69+
@info("got event", event)
70+
end
71+
end
72+
```
4373

4474
### Helper methods:
4575

gen/genapialiases.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ function kuberapi(file::String)
6969
# because of the Julia restriction of type being defined before use
7070
fn_expr = ((x.typ === CSTParser.MacroCall) && CSTParser.defines_function(x.args[3])) ? x.args[3] : CSTParser.defines_function(x) ? x : nothing
7171
if fn_expr !== nothing
72-
alias = emit_alias(fn_expr, api_decoration)
73-
(alias === nothing) || push!(aliases, alias)
72+
fn_name = CSTParser.str_value(CSTParser.get_name(fn_expr))
73+
if !startswith(fn_name, "_swaggerinternal_")
74+
alias = emit_alias(fn_expr, api_decoration)
75+
(alias === nothing) || push!(aliases, alias)
76+
end
7477
end
7578
end
7679
x, ps = CSTParser.parse(ps)

gen/generate.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ ${JULIA} ${DIR}/gentypealiases.jl
5353
# the following models are not generated correctly by Swagger, hand code them for now
5454
cp ${DIR}/model_IoK8sApimachineryPkgApisMetaV1Time.jl ${GENDIR}/src/api/
5555
cp ${DIR}/model_IoK8sApimachineryPkgUtilIntstrIntOrString.jl ${GENDIR}/src/api/
56+
cp ${DIR}/model_IoK8sApimachineryPkgApisMetaV1WatchEvent.jl ${GENDIR}/src/api/
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This file was generated by the Julia Swagger Code Generator
2+
# Do not modify this file directly. Modify the swagger specification instead.
3+
4+
5+
mutable struct IoK8sApimachineryPkgApisMetaV1WatchEvent <: SwaggerModel
6+
object::Any # spec type: Union{ Nothing, IoK8sApimachineryPkgRuntimeRawExtension } # spec name: object
7+
type::Any # spec type: Union{ Nothing, String } # spec name: type
8+
9+
function IoK8sApimachineryPkgApisMetaV1WatchEvent(;object=nothing, type=nothing)
10+
o = new()
11+
validate_property(IoK8sApimachineryPkgApisMetaV1WatchEvent, Symbol("object"), object)
12+
setfield!(o, Symbol("object"), object)
13+
validate_property(IoK8sApimachineryPkgApisMetaV1WatchEvent, Symbol("type"), type)
14+
setfield!(o, Symbol("type"), type)
15+
o
16+
end
17+
end # type IoK8sApimachineryPkgApisMetaV1WatchEvent
18+
19+
const _property_map_IoK8sApimachineryPkgApisMetaV1WatchEvent = Dict{Symbol,Symbol}(Symbol("object")=>Symbol("object"), Symbol("type")=>Symbol("type"))
20+
const _property_types_IoK8sApimachineryPkgApisMetaV1WatchEvent = Dict{Symbol,String}(Symbol("object")=>"Dict{String,Any}", Symbol("type")=>"String")
21+
Base.propertynames(::Type{ IoK8sApimachineryPkgApisMetaV1WatchEvent }) = collect(keys(_property_map_IoK8sApimachineryPkgApisMetaV1WatchEvent))
22+
Swagger.property_type(::Type{ IoK8sApimachineryPkgApisMetaV1WatchEvent }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_IoK8sApimachineryPkgApisMetaV1WatchEvent[name]))}
23+
Swagger.field_name(::Type{ IoK8sApimachineryPkgApisMetaV1WatchEvent }, property_name::Symbol) = _property_map_IoK8sApimachineryPkgApisMetaV1WatchEvent[property_name]
24+
25+
function check_required(o::IoK8sApimachineryPkgApisMetaV1WatchEvent)
26+
(getproperty(o, Symbol("object")) === nothing) && (return false)
27+
(getproperty(o, Symbol("type")) === nothing) && (return false)
28+
true
29+
end
30+
31+
function validate_property(::Type{ IoK8sApimachineryPkgApisMetaV1WatchEvent }, name::Symbol, val)
32+
end

src/Kuber.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ include("helpers.jl")
1818
include("simpleapi.jl")
1919

2020
export KuberContext, set_server, set_ns, get_server, get_ns, kuber_type, kuber_obj, @K_str
21-
export get, list, put!, update!, delete!, sel, get_logs, list_namespaced_custom_metrics, list_custom_metrics
21+
export get, list, watch, put!, update!, delete!, sel, get_logs, list_namespaced_custom_metrics, list_custom_metrics
2222

2323
end # module

src/api/api_AdmissionregistrationApi.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ end
1010
get information of a group
1111
Return: IoK8sApimachineryPkgApisMetaV1APIGroup
1212
"""
13-
function getAdmissionregistrationAPIGroup(_api::AdmissionregistrationApi; _mediaType=nothing)
13+
function _swaggerinternal_getAdmissionregistrationAPIGroup(_api::AdmissionregistrationApi; _mediaType=nothing)
1414
_ctx = Swagger.Ctx(_api.client, "GET", IoK8sApimachineryPkgApisMetaV1APIGroup, "/apis/admissionregistration.k8s.io/", ["BearerToken"])
1515
Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
1616
Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"] : [_mediaType])
17+
return _ctx
18+
end
19+
20+
function getAdmissionregistrationAPIGroup(_api::AdmissionregistrationApi; _mediaType=nothing)
21+
_ctx = _swaggerinternal_getAdmissionregistrationAPIGroup(_api; _mediaType=_mediaType)
1722
Swagger.exec(_ctx)
1823
end
1924

25+
function getAdmissionregistrationAPIGroup(_api::AdmissionregistrationApi, response_stream::Channel; _mediaType=nothing)
26+
_ctx = _swaggerinternal_getAdmissionregistrationAPIGroup(_api; _mediaType=_mediaType)
27+
Swagger.exec(_ctx, response_stream)
28+
end
29+
2030
export getAdmissionregistrationAPIGroup

0 commit comments

Comments
 (0)