Skip to content

Commit 0476348

Browse files
authored
Remove tap status being explicitly set in config (#838)
This is required as part of linkerd/linkerd2#5326 because the tap env variables will no longer always be set. There is a dependency on identity being enabled for tap to work. The status of tap is determined by the `ENV_TAP_SVC_NAME` env variable being set or not set. - If identity is disabled, tap is disabled, but a warning is issued if `ENV_TAP_SVC_NAME` is set. - If identity is enabled, the status of tap is determined by `ENV_TAP_SVC_NAME`. Signed-off-by: Kevin Leimkuhler <[email protected]>
1 parent 2ec0b36 commit 0476348

File tree

3 files changed

+33
-57
lines changed

3 files changed

+33
-57
lines changed

linkerd/app/integration/src/proxy.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,9 @@ async fn run(proxy: Proxy, mut env: TestEnv, random_ports: bool) -> Listening {
244244
Some(identity.addr)
245245
} else {
246246
env.put(app::env::ENV_IDENTITY_DISABLED, "test".to_owned());
247-
env.put(app::env::ENV_TAP_DISABLED, "test".to_owned());
248247
None
249248
};
250249

251-
// If identity is enabled but the test is not concerned with tap, ensure
252-
// there is a tap service name set
253-
if !env.contains_key(app::env::ENV_TAP_DISABLED)
254-
&& !env.contains_key(app::env::ENV_TAP_SVC_NAME)
255-
{
256-
env.put(app::env::ENV_TAP_SVC_NAME, "test-identity".to_owned())
257-
}
258-
259250
if let Some(ports) = proxy.inbound_disable_ports_protocol_detection {
260251
let ports = ports
261252
.into_iter()

linkerd/app/integration/src/tests/tap.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ use crate::*;
33
use std::time::SystemTime;
44

55
#[tokio::test]
6-
async fn tap_enabled_when_identity_enabled() {
6+
async fn tap_enabled_when_tap_svc_name_set() {
77
let _trace = trace_init();
88

99
let identity = "foo.ns1.serviceaccount.identity.linkerd.cluster.local";
10-
let identity_env = identity::Identity::new("foo-ns1", identity.to_string());
10+
let mut identity_env = identity::Identity::new("foo-ns1", identity.to_string());
11+
identity_env
12+
.env
13+
.put("LINKERD2_PROXY_TAP_SVC_NAME", "test-identity".to_string());
1114

1215
let proxy = proxy::new()
1316
.identity(identity_env.service().run().await)
@@ -26,13 +29,14 @@ async fn tap_disabled_when_identity_disabled() {
2629
}
2730

2831
#[tokio::test]
29-
async fn can_disable_tap() {
32+
async fn tap_disabled_when_tap_svc_name_not_set() {
3033
let _trace = trace_init();
31-
let mut env = TestEnv::default();
32-
env.put(app::env::ENV_TAP_DISABLED, "true".to_owned());
33-
34-
let proxy = proxy::new().run_with_test_env(env).await;
35-
34+
let identity = "foo.ns1.serviceaccount.identity.linkerd.cluster.local";
35+
let identity_env = identity::Identity::new("foo-ns1", identity.to_string());
36+
let proxy = proxy::new()
37+
.identity(identity_env.service().run().await)
38+
.run_with_test_env(identity_env.env)
39+
.await;
3640
assert!(proxy.tap.is_none())
3741
}
3842

linkerd/app/src/env.rs

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ pub const ENV_DESTINATION_CONTEXT: &str = "LINKERD2_PROXY_DESTINATION_CONTEXT";
148148
pub const ENV_DESTINATION_PROFILE_INITIAL_TIMEOUT: &str =
149149
"LINKERD2_PROXY_DESTINATION_PROFILE_INITIAL_TIMEOUT";
150150

151-
pub const ENV_TAP_DISABLED: &str = "LINKERD2_PROXY_TAP_DISABLED";
152151
pub const ENV_TAP_SVC_NAME: &str = "LINKERD2_PROXY_TAP_SVC_NAME";
153152
const ENV_RESOLV_CONF: &str = "LINKERD2_PROXY_RESOLV_CONF";
154153

@@ -702,52 +701,34 @@ impl Env {
702701

703702
// ===== Parsing =====
704703

705-
/// There is a dependency on identity being enabled for tap to properly work.
706-
/// Depending on the setting of both, a user could end up in an improperly
707-
/// configured proxy environment.
704+
/// There is a dependency on identity being enabled for tap to work. The
705+
/// status of tap is determined by the ENV_TAP_SVC_NAME env variable being set
706+
/// or not set.
708707
///
709-
/// ```plain
710-
/// E = Enabled; D = Disabled
711-
/// +----------+-----+--------------+
712-
/// | Identity | Tap | Result |
713-
/// +----------+-----+--------------+
714-
/// | E | E | Ok(Some(..)) |
715-
/// +----------+-----+--------------+
716-
/// | E | D | Ok(None) |
717-
/// +----------+-----+--------------+
718-
/// | D | E | Err(..) |
719-
/// +----------+-----+--------------+
720-
/// | D | D | Ok(None) |
721-
/// +----------+-----+--------------+
722-
/// ```
708+
/// - If identity is disabled, tap is disabled, but a warning is issued if
709+
/// ENV_TAP_SVC_NAME is set.
710+
/// - If identity is enabled, the status of tap is determined by
711+
/// ENV_TAP_SVC_NAME.
723712
fn parse_tap_config(
724713
strings: &dyn Strings,
725714
id_disabled: bool,
726715
) -> Result<Option<(SocketAddr, IndexSet<identity::Name>)>, EnvError> {
727-
let tap_disabled = strings
728-
.get(ENV_TAP_DISABLED)?
729-
.map(|d| !d.is_empty())
730-
.unwrap_or(false);
731-
match (id_disabled, tap_disabled) {
732-
(_, true) => Ok(None),
733-
(true, false) => {
734-
error!("{} must be set if identity is disabled", ENV_TAP_DISABLED);
735-
Err(EnvError::InvalidEnvVar)
716+
let tap_identity = parse(strings, ENV_TAP_SVC_NAME, parse_identity)?;
717+
if id_disabled {
718+
if tap_identity.is_some() {
719+
warn!(
720+
"{} should not be set if identity is disabled; continuing with tap disabled",
721+
ENV_TAP_SVC_NAME
722+
);
736723
}
737-
(false, false) => {
738-
let addr = parse(strings, ENV_CONTROL_LISTEN_ADDR, parse_socket_addr)?
739-
.unwrap_or_else(|| parse_socket_addr(DEFAULT_CONTROL_LISTEN_ADDR).unwrap());
740-
let peer_identity = parse(strings, ENV_TAP_SVC_NAME, parse_identity);
741-
742-
match peer_identity? {
743-
Some(peer_identity) => Ok(Some((addr, vec![peer_identity].into_iter().collect()))),
744-
None => {
745-
error!("{} must be set or tap must be disabled", ENV_TAP_SVC_NAME);
746-
Err(EnvError::InvalidEnvVar)
747-
}
748-
}
724+
} else {
725+
let addr = parse(strings, ENV_CONTROL_LISTEN_ADDR, parse_socket_addr)?
726+
.unwrap_or_else(|| parse_socket_addr(DEFAULT_CONTROL_LISTEN_ADDR).unwrap());
727+
if let Some(id) = tap_identity {
728+
return Ok(Some((addr, vec![id].into_iter().collect())));
749729
}
750-
}
730+
};
731+
Ok(None)
751732
}
752733

753734
fn parse_bool(s: &str) -> Result<bool, ParseError> {

0 commit comments

Comments
 (0)