Skip to content

Commit a254414

Browse files
authored
app: Move the admin server into a subcrate (#1028)
The proxy's admin server is split across `linkerd/app` and `linkerd/app/core/` -- with the former implementing the stack and the latter implementing the HTTP server. This change unifies these modules into `linkerd/app/admin`, which is no longer needed to compile the inbound and outbound proxies. The admin crate has a dependency on the inbound crate, as they currently share target types.
1 parent bc98cde commit a254414

File tree

14 files changed

+82
-43
lines changed

14 files changed

+82
-43
lines changed

Cargo.lock

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ dependencies = [
629629
"futures",
630630
"indexmap",
631631
"ipnet",
632+
"linkerd-app-admin",
632633
"linkerd-app-core",
633634
"linkerd-app-gateway",
634635
"linkerd-app-inbound",
@@ -644,14 +645,30 @@ dependencies = [
644645
"tracing",
645646
]
646647

648+
[[package]]
649+
name = "linkerd-app-admin"
650+
version = "0.1.0"
651+
dependencies = [
652+
"futures",
653+
"html-escape",
654+
"http",
655+
"hyper",
656+
"linkerd-app-core",
657+
"linkerd-app-inbound",
658+
"serde_json",
659+
"thiserror",
660+
"tokio",
661+
"tower",
662+
"tracing",
663+
]
664+
647665
[[package]]
648666
name = "linkerd-app-core"
649667
version = "0.1.0"
650668
dependencies = [
651669
"bytes",
652670
"drain",
653671
"futures",
654-
"html-escape",
655672
"http",
656673
"http-body",
657674
"hyper",

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ resolver = "2"
66
members = [
77
"hyper-balance",
88
"linkerd/addr",
9+
"linkerd/app/admin",
910
"linkerd/app/core",
1011
"linkerd/app/gateway",
1112
"linkerd/app/inbound",

linkerd/app/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ allow-loopback = ["linkerd-app-outbound/allow-loopback"]
1818
futures = "0.3.15"
1919
indexmap = "1.0"
2020
ipnet = "2.0"
21+
linkerd-app-admin = { path = "./admin" }
2122
linkerd-app-core = { path = "./core" }
2223
linkerd-app-gateway = { path = "./gateway" }
2324
linkerd-app-inbound = { path = "./inbound" }

linkerd/app/admin/Cargo.toml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[package]
2+
name = "linkerd-app-admin"
3+
version = "0.1.0"
4+
authors = ["Linkerd Developers <cncf-linkerd-dev@lists.cncf.io>"]
5+
license = "Apache-2.0"
6+
edition = "2018"
7+
publish = false
8+
description = """
9+
The linkerd proxy's admin server.
10+
"""
11+
12+
[dependencies]
13+
html-escape = "0.2"
14+
http = "0.2"
15+
hyper = { version = "0.14", features = ["http1", "http2"] }
16+
futures = "0.3"
17+
linkerd-app-core = { path = "../core" }
18+
linkerd-app-inbound = { path = "../inbound" }
19+
serde_json = "1"
20+
thiserror = "1"
21+
tokio = { version = "1", features = ["macros", "sync", "parking_lot"]}
22+
tracing = "0.1"
23+
24+
[dependencies.tower]
25+
version = "0.4"
26+
default-features = false
27+
features = [
28+
"buffer",
29+
"make",
30+
"spawn-ready",
31+
"timeout",
32+
"util",
33+
]
34+

linkerd/app/admin/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![deny(warnings, rust_2018_idioms)]
2+
#![forbid(unsafe_code)]
3+
4+
mod server;
5+
mod stack;
6+
7+
pub use self::server::{Admin, Latch, Readiness};
8+
pub use self::stack::{Config, Task};

linkerd/app/core/src/admin/level.rs renamed to linkerd/app/admin/src/server/level.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use hyper::{
22
body::{Buf, HttpBody},
33
Body,
44
};
5-
use linkerd_error::Error;
6-
use linkerd_tracing::level::Handle;
5+
use linkerd_app_core::{trace::level::Handle, Error};
76
use std::io;
87

98
pub(super) async fn serve<B>(

linkerd/app/core/src/admin/mod.rs renamed to linkerd/app/admin/src/server/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
//! tracing configuration).
1111
//! * `POST /shutdown` -- shuts down the proxy.
1212
13-
use crate::{proxy::http::ClientHandle, svc, trace};
1413
use futures::future;
1514
use http::StatusCode;
1615
use hyper::{
1716
body::{Body, HttpBody},
1817
Request, Response,
1918
};
20-
use linkerd_error::Error;
21-
use linkerd_metrics::{self as metrics, FmtMetrics};
19+
use linkerd_app_core::{
20+
metrics::{self as metrics, FmtMetrics},
21+
proxy::http::ClientHandle,
22+
svc, trace, Error,
23+
};
2224
use std::{
2325
future::Future,
2426
net::SocketAddr,

linkerd/app/core/src/admin/tasks.rs renamed to linkerd/app/admin/src/server/tasks.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use hyper::Body;
2-
use linkerd_error::Error;
3-
use linkerd_tracing::TaskList;
2+
use linkerd_app_core::{trace::TaskList, Error};
43
use std::fmt::Write;
54

65
pub(super) fn serve<B>(

linkerd/app/src/admin.rs renamed to linkerd/app/admin/src/stack.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
use crate::core::{
2-
admin, classify,
1+
use linkerd_app_core::{
2+
classify,
33
config::ServerConfig,
44
detect, drain, errors,
55
metrics::{self, FmtMetrics},
6+
proxy::{http, identity::LocalCrtKey},
67
serve,
78
svc::{self, Param},
89
tls, trace,
910
transport::{listen::Bind, ClientAddr, Local, Remote, ServerAddr},
1011
Error,
1112
};
12-
use crate::{
13-
http,
14-
identity::LocalCrtKey,
15-
inbound::target::{HttpAccept, Target, TcpAccept},
16-
};
13+
use linkerd_app_inbound::target::{HttpAccept, Target, TcpAccept};
1714
use std::{pin::Pin, time::Duration};
1815
use thiserror::Error;
1916
use tokio::sync::mpsc;
@@ -25,9 +22,9 @@ pub struct Config {
2522
pub metrics_retain_idle: Duration,
2623
}
2724

28-
pub struct Admin {
25+
pub struct Task {
2926
pub listen_addr: Local<ServerAddr>,
30-
pub latch: admin::Latch,
27+
pub latch: crate::Latch,
3128
pub serve: Pin<Box<dyn std::future::Future<Output = ()> + Send + 'static>>,
3229
}
3330

@@ -42,7 +39,7 @@ struct UnexpectedSni(tls::ServerId, Remote<ClientAddr>);
4239
// === impl Config ===
4340

4441
impl Config {
45-
#[allow(clippy::clippy::too_many_arguments)]
42+
#[allow(clippy::too_many_arguments)]
4643
pub fn build<B, R>(
4744
self,
4845
bind: B,
@@ -52,7 +49,7 @@ impl Config {
5249
trace: trace::Handle,
5350
drain: drain::Watch,
5451
shutdown: mpsc::UnboundedSender<()>,
55-
) -> Result<Admin, Error>
52+
) -> Result<Task, Error>
5653
where
5754
R: FmtMetrics + Clone + Send + Sync + Unpin + 'static,
5855
B: Bind<ServerConfig>,
@@ -62,8 +59,8 @@ impl Config {
6259

6360
let (listen_addr, listen) = bind.bind(&self.server)?;
6461

65-
let (ready, latch) = admin::Readiness::new();
66-
let admin = admin::Admin::new(report, ready, shutdown, trace);
62+
let (ready, latch) = crate::server::Readiness::new();
63+
let admin = crate::server::Admin::new(report, ready, shutdown, trace);
6764
let admin = svc::stack(admin)
6865
.push(metrics.http_endpoint.to_layer::<classify::Response, _>())
6966
.push_on_response(
@@ -137,7 +134,7 @@ impl Config {
137134
.into_inner();
138135

139136
let serve = Box::pin(serve::serve(listen, admin, drain.signaled()));
140-
Ok(Admin {
137+
Ok(Task {
141138
listen_addr,
142139
latch,
143140
serve,

0 commit comments

Comments
 (0)