Skip to content

Commit b48a331

Browse files
committed
refactor(io): Refactor network types into net::io modules
1 parent 5eaf096 commit b48a331

File tree

36 files changed

+1466
-1735
lines changed

36 files changed

+1466
-1735
lines changed

benches/shared.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl QuilkinLoop {
319319
}
320320

321321
fn spinup_inner(port: u16, endpoint: SocketAddr) -> Self {
322-
let (shutdown_tx, shutdown_rx) =
322+
let (shutdown_tx, mut shutdown_rx) =
323323
quilkin::signal::channel(quilkin::signal::ShutdownKind::Benching);
324324

325325
let thread = spawn("quilkin", move || {
@@ -331,21 +331,15 @@ impl QuilkinLoop {
331331
);
332332
});
333333

334-
let proxy = quilkin::cli::Proxy {
335-
port,
336-
qcmp_port: runtime
337-
.block_on(quilkin::test::available_addr(
338-
quilkin::test::AddressType::Random,
339-
))
340-
.port(),
341-
..<_>::default()
342-
};
343-
344334
runtime.block_on(async move {
345-
proxy
346-
.run(config, Default::default(), None, shutdown_rx)
347-
.await
335+
quilkin::cli::Service::default()
336+
.udp()
337+
.udp_port(port)
338+
.qcmp()
339+
.qcmp_port(quilkin::test::available_port())
340+
.spawn_services(&config, &shutdown_rx)
348341
.unwrap();
342+
let _ = shutdown_rx.changed().await;
349343
});
350344
});
351345

docs/src/SUMMARY.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@
3030

3131
---
3232

33+
- [Providers]()
34+
- [Agones](./config/providers/agones.md)
35+
- [Filesystem](./config/providers/filesystem.md)
36+
37+
---
38+
3339
- [Control Plane](./services/xds.md)
3440
- [Metrics](./services/xds/metrics.md)
35-
- [Providers]()
36-
- [Agones](./services/xds/providers/agones.md)
37-
- [Filesystem](./services/xds/providers/filesystem.md)
3841
- [Protobuf Reference](./services/xds/proto/index.md)
3942
---
4043

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Agones xDS Provider
2+
3+
The [Agones] xDS Provider is built to simplify Quilkin integration with Agones
4+
game server hosting on top of [Kubernetes](https://kubernetes.io).
5+
6+
This provider watches for changes in Agones
7+
[`GameServer` resources](https://agones.dev/site/docs/getting-started/create-gameserver/) in a cluster, and
8+
utilises that information to provide [Endpoint][Endpoints] information to connected Quilkin proxies.
9+
10+
To view all the options for the agones provider subcommand, run:
11+
```shell
12+
$ quilkin manage agones --help
13+
{{#include ../../../../../target/quilkin.manage.agones.commands}}
14+
```
15+
16+
> Currently, the Agones provider can only discover resources within the cluster it is running in.
17+
18+
## Endpoint Configuration
19+
20+
This provider watches the Kubernetes clusters for `Allocated`
21+
[Agones GameServers](https://agones.dev/site/docs/reference/gameserver/#gameserver-state-diagram)
22+
and exposes their IP address and Port as [Endpoints] to any connected Quilkin proxies.
23+
24+
> Since an Agones GameServer can have multiple ports exposed, if multiple ports are in
25+
> use, the server will pick the first port in the port list.
26+
27+
By default the Agones xDS provider will look in the `default` namespace for any `GameServer` resources, but it can be
28+
configured via the `--gameservers-namespace` argument.
29+
30+
### Access Tokens
31+
32+
The set of [access tokens](../../proxy.md#specialist-endpoint-metadata) for the associated Endpoint can be
33+
set by adding a comma separated standard base64 encoded strings. This must be added under an annotation
34+
`quilkin.dev/tokens` in the
35+
[GameServer](https://agones.dev/site/docs/reference/agones_crd_api_reference/#agones.dev/v1.GameServer)'s metadata.
36+
37+
For example:
38+
39+
```yaml
40+
annotations:
41+
# Sets two tokens for the corresponding endpoint with values 1x7ijy6 and 8gj3v2i respectively.
42+
quilkin.dev/tokens: MXg3aWp5Ng==,OGdqM3YyaQ==
43+
```
44+
45+
## Filter Configuration
46+
47+
The Agones provider watches for a singular [`ConfigMap`](https://kubernetes.io/docs/concepts/configuration/configmap/)
48+
that has the label of `quilkin.dev/configmap: "true"`, and any changes that happen to it, and use its contents to
49+
send [Filter] configuration to any connected Quilkin proxies.
50+
51+
The `ConfigMap` contents should be a valid Quilkin [file configuration][configuration], but with no
52+
Endpoint data.
53+
54+
For example:
55+
56+
```yaml
57+
{{#include ../../../../../examples/agones-xonotic-xds/xds-control-plane.yaml:config-map}}
58+
```
59+
60+
By default the Agones xDS provider will look in the `default` namespace for this `ConfigMap`, but it can be
61+
configured via the `--config-namespace` argument.
62+
63+
## Usage
64+
65+
As an example, the following runs the server with subcommnad `manage agones` against a cluster (using default
66+
kubeconfig authentication) where Quilkin pods run in the `quilkin` namespace and `GameServer` pods run in the
67+
`gameservers` namespace:
68+
69+
```sh
70+
quilkin manage agones --config-namespace quilkin --gameservers-namespace gameservers
71+
```
72+
73+
For a full referenmce of deploying this provider in a Kubernetes cluster, with appropriate [Deployments], [Services],
74+
and [RBAC] Rules, there is an [Agones, xDS and Xonotic example][example].
75+
76+
[Agones]: https://agones.dev
77+
[Endpoints]: ../../proxy.md#endpoints
78+
[Deployments]: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
79+
[Services]: https://kubernetes.io/docs/concepts/services-networking/service/
80+
[RBAC]: https://kubernetes.io/docs/reference/access-authn-authz/rbac/
81+
[example]: https://github.com/googleforgames/quilkin/tree/{{GITHUB_REF_NAME}}/examples/agones-xonotic-xds
82+
[Filter]: ../../../services/proxy/filters.md
83+
[configuration]: ../../../services/proxy/configuration.md
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Filesystem xDS Provider
2+
3+
The filesystem provider watches a configuration file on disk and sends updates to proxies whenever that file changes.
4+
5+
To view all the options for the file provider subcommand, run:
6+
```shell
7+
$ quilkin manage agones --help
8+
{{#include ../../../../../target/quilkin.manage.file.commands}}
9+
```
10+
11+
For example:
12+
```sh
13+
quilkin manage file quilkin.yaml
14+
```
15+
16+
We run this on port 1800, in this example, in case you are running this locally, and the
17+
default port is taken up by an existing Quilkin proxy.
18+
19+
After running this command, any proxy that connects to port 18000 will receive updates as configured in `config.yaml`
20+
file.
21+
22+
You can find the configuration file schema in [Configuration File][configuration].
23+
24+
Example:
25+
26+
```rust
27+
# let yaml = "
28+
version: v1alpha1
29+
filters:
30+
- name: quilkin.filters.debug.v1alpha1.Debug
31+
config:
32+
id: hello
33+
clusters:
34+
- endpoints:
35+
- address: 123.0.0.1:29
36+
metadata:
37+
'quilkin.dev':
38+
tokens:
39+
- 'MXg3aWp5Ng=='
40+
# ";
41+
# let config = quilkin::config::Config::from_reader(yaml.as_bytes()).unwrap();
42+
# assert_eq!(config.filters().unwrap().load().len(), 1);
43+
```
44+
45+
[configuration]: ../../../services/proxy/configuration.md

src/cli.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ pub use self::{
2626
agent::Agent,
2727
generate_config_schema::GenerateConfigSchema,
2828
manage::Manage,
29-
proxy::Proxy,
3029
qcmp::Qcmp,
3130
relay::Relay,
32-
service::{Finalizer, Service},
31+
service::{Finalizer, Service, XdpOptions},
3332
};
3433

3534
macro_rules! define_port {
@@ -45,7 +44,6 @@ macro_rules! define_port {
4544
pub mod agent;
4645
pub mod generate_config_schema;
4746
pub mod manage;
48-
pub mod proxy;
4947
pub mod qcmp;
5048
pub mod relay;
5149
mod service;
@@ -191,7 +189,6 @@ pub enum Commands {
191189
Manage(Manage),
192190
#[clap(subcommand)]
193191
Qcmp(Qcmp),
194-
Proxy(Proxy),
195192
Relay(Relay),
196193
}
197194

@@ -261,14 +258,6 @@ impl Cli {
261258
agent.run(locality, config, old_ready, shutdown_rx).await
262259
}
263260

264-
Some(Commands::Proxy(runner)) => {
265-
let old_ready = proxy::Ready {
266-
xds_is_healthy: parking_lot::RwLock::from(Some(ready.clone())).into(),
267-
..<_>::default()
268-
};
269-
runner.run(config, old_ready, None, shutdown_rx).await
270-
}
271-
272261
Some(Commands::Manage(manager)) => {
273262
let old_ready = agent::Ready {
274263
provider_is_healthy: ready.clone(),

src/cli/proxy.rs

Lines changed: 0 additions & 147 deletions
This file was deleted.

0 commit comments

Comments
 (0)