Skip to content

add support for watch APIs #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors = ["Tanmay Mohapatra <tanmaykm@gmail.com>"]
keywords = ["kubernetes", "client"]
license = "MIT"
desc = "Julia Kubernetes Client"
version = "0.4.2"
version = "0.4.3"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,37 @@ Kubernetes APIs are mapped to these easy to use verbs, familiar to Julia users.
- `delete!`: delete existing entities
- `sel`: creates a label selector to use with other verbs

All verbs have the signature: `verb(ctx::KuberContext, T::Symbol, args...; kwargs...)`.
All verbs have the signature:

```julia
verb(ctx::KuberContext, T::Symbol, args...; kwargs...)
```

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.

```julia
watch(ctx::KuberContext, T::Symbol, outstream::Channel, args...; kwargs...)
```

In addition, verbs like `get` and `list` also support watches, and those can be invoked as:

```julia
watch(ctx, verb, args...; kwargs...) do stream
for event in stream
# process event
end
end
```

E.g.:

```julia
watch(ctx, list, :Pod; resourceVersion=19451) do stream
for event in stream
@info("got event", event)
end
end
```

### Helper methods:

Expand Down
7 changes: 5 additions & 2 deletions gen/genapialiases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ function kuberapi(file::String)
# because of the Julia restriction of type being defined before use
fn_expr = ((x.typ === CSTParser.MacroCall) && CSTParser.defines_function(x.args[3])) ? x.args[3] : CSTParser.defines_function(x) ? x : nothing
if fn_expr !== nothing
alias = emit_alias(fn_expr, api_decoration)
(alias === nothing) || push!(aliases, alias)
fn_name = CSTParser.str_value(CSTParser.get_name(fn_expr))
if !startswith(fn_name, "_swaggerinternal_")
alias = emit_alias(fn_expr, api_decoration)
(alias === nothing) || push!(aliases, alias)
end
end
end
x, ps = CSTParser.parse(ps)
Expand Down
1 change: 1 addition & 0 deletions gen/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ ${JULIA} ${DIR}/gentypealiases.jl
# the following models are not generated correctly by Swagger, hand code them for now
cp ${DIR}/model_IoK8sApimachineryPkgApisMetaV1Time.jl ${GENDIR}/src/api/
cp ${DIR}/model_IoK8sApimachineryPkgUtilIntstrIntOrString.jl ${GENDIR}/src/api/
cp ${DIR}/model_IoK8sApimachineryPkgApisMetaV1WatchEvent.jl ${GENDIR}/src/api/
32 changes: 32 additions & 0 deletions gen/model_IoK8sApimachineryPkgApisMetaV1WatchEvent.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file was generated by the Julia Swagger Code Generator
# Do not modify this file directly. Modify the swagger specification instead.


mutable struct IoK8sApimachineryPkgApisMetaV1WatchEvent <: SwaggerModel
object::Any # spec type: Union{ Nothing, IoK8sApimachineryPkgRuntimeRawExtension } # spec name: object
type::Any # spec type: Union{ Nothing, String } # spec name: type

function IoK8sApimachineryPkgApisMetaV1WatchEvent(;object=nothing, type=nothing)
o = new()
validate_property(IoK8sApimachineryPkgApisMetaV1WatchEvent, Symbol("object"), object)
setfield!(o, Symbol("object"), object)
validate_property(IoK8sApimachineryPkgApisMetaV1WatchEvent, Symbol("type"), type)
setfield!(o, Symbol("type"), type)
o
end
end # type IoK8sApimachineryPkgApisMetaV1WatchEvent

const _property_map_IoK8sApimachineryPkgApisMetaV1WatchEvent = Dict{Symbol,Symbol}(Symbol("object")=>Symbol("object"), Symbol("type")=>Symbol("type"))
const _property_types_IoK8sApimachineryPkgApisMetaV1WatchEvent = Dict{Symbol,String}(Symbol("object")=>"Dict{String,Any}", Symbol("type")=>"String")
Base.propertynames(::Type{ IoK8sApimachineryPkgApisMetaV1WatchEvent }) = collect(keys(_property_map_IoK8sApimachineryPkgApisMetaV1WatchEvent))
Swagger.property_type(::Type{ IoK8sApimachineryPkgApisMetaV1WatchEvent }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_IoK8sApimachineryPkgApisMetaV1WatchEvent[name]))}
Swagger.field_name(::Type{ IoK8sApimachineryPkgApisMetaV1WatchEvent }, property_name::Symbol) = _property_map_IoK8sApimachineryPkgApisMetaV1WatchEvent[property_name]

function check_required(o::IoK8sApimachineryPkgApisMetaV1WatchEvent)
(getproperty(o, Symbol("object")) === nothing) && (return false)
(getproperty(o, Symbol("type")) === nothing) && (return false)
true
end

function validate_property(::Type{ IoK8sApimachineryPkgApisMetaV1WatchEvent }, name::Symbol, val)
end
2 changes: 1 addition & 1 deletion src/Kuber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ include("helpers.jl")
include("simpleapi.jl")

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

end # module
12 changes: 11 additions & 1 deletion src/api/api_AdmissionregistrationApi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ end
get information of a group
Return: IoK8sApimachineryPkgApisMetaV1APIGroup
"""
function getAdmissionregistrationAPIGroup(_api::AdmissionregistrationApi; _mediaType=nothing)
function _swaggerinternal_getAdmissionregistrationAPIGroup(_api::AdmissionregistrationApi; _mediaType=nothing)
_ctx = Swagger.Ctx(_api.client, "GET", IoK8sApimachineryPkgApisMetaV1APIGroup, "/apis/admissionregistration.k8s.io/", ["BearerToken"])
Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"] : [_mediaType])
return _ctx
end

function getAdmissionregistrationAPIGroup(_api::AdmissionregistrationApi; _mediaType=nothing)
_ctx = _swaggerinternal_getAdmissionregistrationAPIGroup(_api; _mediaType=_mediaType)
Swagger.exec(_ctx)
end

function getAdmissionregistrationAPIGroup(_api::AdmissionregistrationApi, response_stream::Channel; _mediaType=nothing)
_ctx = _swaggerinternal_getAdmissionregistrationAPIGroup(_api; _mediaType=_mediaType)
Swagger.exec(_ctx, response_stream)
end

export getAdmissionregistrationAPIGroup
Loading