You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An implementation of the [Swift Service Discovery API](https://github.com/apple/swift-service-discovery) for Kubernetes based on [SwiftkubeClient](https://github.com/swiftkube/client).
22
+
An implementation of the [Swift Service Discovery API](https://github.com/apple/swift-service-discovery) for
23
+
Kubernetes based on [SwiftkubeClient](https://github.com/swiftkube/client).
19
24
20
25
## Table of contents
21
26
22
27
*[Overview](#overview)
23
28
*[Usage](#usage)
29
+
*[Creating a service discovery](#creating-a-service-discovery)
30
+
*[Configuration](#Configuration)
31
+
*[Lookup resources](#lookup-resources)
32
+
*[Subscribtions](#subscriptions)
33
+
*[Custom Resources](#custom-resources)
34
+
*[Strict Concurrency](#strict-concurrency)
24
35
*[RBAC](#rbac)
25
36
*[Installation](#installation)
26
37
*[License](#license)
27
38
28
39
#Overview
29
40
30
41
-[x] Auto-configuration for different environments
31
-
-[x] Support for all K8s `ListOptions`
42
+
-[x] Support for all Kubernetes `ListOptions`
43
+
-[x] Discovery for any listable Kubernetes resource
32
44
-[x] Support for reconnect and retry
33
-
-[x] Discovery for K8s Pod objects
34
-
-[ ] Discovery for K8s Service objects
35
45
-[ ] Complete documentation
36
46
-[ ] End-to-end tests
37
47
@@ -41,28 +51,50 @@ An implementation of the [Swift Service Discovery API](https://github.com/apple/
41
51
42
52
To use this service discovery import `SwiftkubeServiceDiscovery` and init an instance.
43
53
54
+
`SwiftkubeServiceDiscovery` is generic. Thus, instances must be specialized and are therefore bound to
55
+
a specific `KubernetesResouce` type and its `GroupVersionResource`.
56
+
44
57
```swift
45
58
importSwiftkubeServiceDiscovery
46
59
47
-
let discovery =KubernetesServiceDiscovery()
60
+
let podDiscovery = SwiftkubeServiceDiscovery<core.v1.Pod>()
61
+
let serviceDiscovery = SwiftkubeServiceDiscovery<core.v1.Service>()
48
62
```
49
63
50
-
Underneath, `SwiftkubeServiceDiscovery` uses `SwiftkubeClient` for all Kubernets communication, which configures itself automatically for the environement it runs in.
64
+
Underneath, `SwiftkubeServiceDiscovery` uses `SwiftkubeClient` for all Kubernetes communication, which configures
65
+
itself automatically for the environment it runs in.
51
66
52
-
You can also pass an existing client instance to the service discovery:
67
+
However, you can also pass an existing client instance to the service discovery:
53
68
54
69
```swift
55
-
let client =KubernetesClient()
56
-
let discovery =KubernetesServiceDiscovery(client: client)
let discovery = SwiftkubeServiceDiscovery<core.v1.Service>(client: client)
57
82
```
58
83
59
-
You should shut down the `SwiftkubeServiceDiscovery ` instance, which in turn shuts down the underlying `SwiftkubeClient`. You can shutdown either in a synchronius way or asynchronously by providing a `DispatchQueue` for the completion callback.
84
+
You should shut down the `SwiftkubeServiceDiscovery` instance when you're done using it, which in turn shuts down the
85
+
underlying `SwiftkubeClient`. Thus, you shouldn't call `discovery.shutdown()` before all requests have finished.
86
+
87
+
You can also shut down the client asynchronously in an async/await context or by providing a `DispatchQueue` for the
88
+
completion callback.
60
89
61
90
```swift
62
91
// when finished close the client
63
92
try discovery.syncShutdown()
64
93
65
-
// or asynchronously
94
+
// async/await
95
+
tryawait discovery.shutdown()
96
+
97
+
// DispatchQueue
66
98
let queue: DispatchQueue =...
67
99
discovery.shutdown(queue: queue) { (error: Error?) in
68
100
print(error)
@@ -71,11 +103,12 @@ discovery.shutdown(queue: queue) { (error: Error?) in
71
103
72
104
### Configuration
73
105
74
-
You can configure the service discovery by passing a `Configuration` instance.
106
+
You can configure the service discovery by passing a `SwiftkubeDiscoveryConfiguration` instance.
75
107
76
-
`SwiftkubeServiceDiscovery` supports the following configuration options:
108
+
Currently, the following configuration options are supported:
77
109
78
-
-`RetryStrategy`: A retry strategy to control the reconnect behaviour for the underlying client in case of non-recoverable errors when serving service discovery subsriptions.
110
+
-`RetryStrategy`: A retry strategy to control the reconnect-behaviour for the underlying client in case of
111
+
non-recoverable errors when serving service discovery subscriptions.
79
112
80
113
```swift
81
114
let strategy =RetryStrategy(
@@ -86,17 +119,19 @@ let strategy = RetryStrategy(
86
119
)
87
120
88
121
let config =Configuration(retryStrategy: strategy)
89
-
90
-
let discovery =KubernetesServiceDiscovery(config: config)
122
+
let discovery = SwiftkubeServiceDiscovery<core.v1.Service>(config: config)
91
123
```
92
124
93
-
### Service lookup
125
+
### Lookup resources
94
126
95
-
To lookup Kubernetes "services" you have to pass an instance of `LookupObject`. You can specify the namespaces to search and provide a list of selectors to filter the desired objects.
127
+
To lookup Kubernetes resources you have to pass an instance of `LookupObject`. You can specify the namespaces to
128
+
search and provide a list of selectors to filter the desired objects.
96
129
97
-
`SwiftkubeServiceDiscovery` lookups return a list of `KubernetesPods` describing all of the matching pod objects that have an IP assigned.
130
+
`SwiftkubeServiceDiscovery` lookups return a list of resources of the type specified by the generic specialization:
98
131
99
132
```swift
133
+
let podDiscovery = SwiftkubeServiceDiscovery<core.v1.Pod>()
134
+
100
135
let object =LookupObject(
101
136
namespace: .allNamespaces,
102
137
options: [
@@ -110,25 +145,26 @@ discovery.lookup(object) { result in
@@ -140,18 +176,27 @@ let token = discovery.subscribe(to: object) { result in
140
176
token.cancel()
141
177
```
142
178
143
-
The client will try to reconnect to the API server according to the configured `RetryStrategy` and will serve updates until the subsription token is cancelled.
179
+
The client will try to reconnect to the API server according to the configured `RetryStrategy` and will serve updates
180
+
until the subscription token is cancelled.
181
+
182
+
### Custom Resources
183
+
184
+
TBD
185
+
186
+
## Strict Concurrency
187
+
188
+
TBD
144
189
145
190
## RBAC
146
191
147
192
TBD
148
193
149
194
## Installation
150
195
151
-
To use the `SwiftkubeModel` in a SwiftPM project, add the following line to the dependencies in your `Package.swift` file:
196
+
To use the `SwiftkubeServiceDiscovery` in a SwiftPM project, add the following line to the dependencies in your `Package.swift` file:
Swiftkube project is licensed under version 2.0 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0). See [LICENSE](./LICENSE) for more details.
224
+
Swiftkube project is licensed under version 2.0 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0).
0 commit comments