1
- use std:: { sync:: LazyLock , time:: Instant } ;
2
-
3
1
use futures:: TryStreamExt ;
4
2
use k8s_openapi:: api:: core:: v1:: Namespace ;
5
3
use kube:: Client ;
@@ -12,10 +10,15 @@ use mirrord_kube::{
12
10
use mirrord_operator:: client:: OperatorApi ;
13
11
use semver:: VersionReq ;
14
12
use serde:: { ser:: SerializeSeq , Serialize , Serializer } ;
13
+ use serde_json:: Value ;
14
+ use std:: str:: FromStr ;
15
+ use std:: { sync:: LazyLock , time:: Instant } ;
15
16
use tracing:: Level ;
16
17
17
18
use crate :: { util, CliError , CliResult , Format , ListTargetArgs } ;
18
19
20
+ const LS_TARGET_TYPES_ENV : & str = "MIRRORD_LS_TARGET_TYPES" ;
21
+
19
22
/// A mirrord target found in the cluster.
20
23
#[ derive( Serialize ) ]
21
24
struct FoundTarget {
@@ -69,7 +72,7 @@ impl FoundTargets {
69
72
async fn resolve (
70
73
config : LayerConfig ,
71
74
rich_output : bool ,
72
- target_type : Option < TargetType > ,
75
+ target_types : Option < Vec < TargetType > > ,
73
76
) -> CliResult < Self > {
74
77
let client = create_kube_config (
75
78
config. accept_invalid_certificates ,
@@ -111,8 +114,10 @@ impl FoundTargets {
111
114
112
115
let ( targets, namespaces) = tokio:: try_join!(
113
116
async {
114
- let paths = match ( operator_api, target_type) {
115
- ( None , _) if config. operator == Some ( true ) => Err ( CliError :: OperatorNotInstalled ) ,
117
+ let paths = match ( operator_api, target_types) {
118
+ ( None , _) if config. operator == Some ( true ) => {
119
+ Err ( CliError :: OperatorNotInstalled )
120
+ }
116
121
117
122
( Some ( api) , None )
118
123
if !rich_output
@@ -124,19 +129,27 @@ impl FoundTargets {
124
129
} )
125
130
}
126
131
127
- ( Some ( api) , Some ( target_type ) )
132
+ ( Some ( api) , Some ( target_types ) )
128
133
if !rich_output
129
134
&& ALL_TARGETS_SUPPORTED_OPERATOR_VERSION
130
135
. matches( & api. operator( ) . spec. operator_version) =>
131
136
{
132
- seeker. filtered( target_type, true ) . await . map_err( |error| {
133
- CliError :: friendlier_error_or_else( error, CliError :: ListTargetsFailed )
137
+ seeker. filtered( target_types, true ) . await . map_err( |error| {
138
+ CliError :: friendlier_error_or_else(
139
+ error,
140
+ CliError :: ListTargetsFailed ,
141
+ )
134
142
} )
135
143
}
136
144
137
- ( None , Some ( target_type) ) => seeker. filtered( target_type, false ) . await . map_err( |error| {
138
- CliError :: friendlier_error_or_else( error, CliError :: ListTargetsFailed )
139
- } ) ,
145
+ ( None , Some ( target_types) ) => {
146
+ seeker. filtered( target_types, false ) . await . map_err( |error| {
147
+ CliError :: friendlier_error_or_else(
148
+ error,
149
+ CliError :: ListTargetsFailed ,
150
+ )
151
+ } )
152
+ }
140
153
141
154
_ => seeker. all_open_source( ) . await . map_err( |error| {
142
155
CliError :: friendlier_error_or_else( error, CliError :: ListTargetsFailed )
@@ -237,7 +250,24 @@ pub(super) async fn print_targets(args: ListTargetArgs, rich_output: bool) -> Cl
237
250
util:: remove_proxy_env ( ) ;
238
251
}
239
252
240
- let targets = FoundTargets :: resolve ( layer_config, rich_output, args. target_type ) . await ?;
253
+ let target_types = if let Some ( target_type) = args. target_type {
254
+ Some ( vec ! [ target_type] )
255
+ } else {
256
+ match std:: env:: var ( LS_TARGET_TYPES_ENV )
257
+ . ok ( )
258
+ . map ( |val| serde_json:: from_str :: < Vec < Value > > ( val. as_ref ( ) ) )
259
+ . transpose ( ) ?
260
+ . unwrap_or_default ( )
261
+ . into_iter ( )
262
+ . filter_map ( |value| value. as_str ( ) . map ( |str| str. to_string ( ) ) )
263
+ . filter_map ( |string| TargetType :: from_str ( & string) . ok ( ) )
264
+ . collect :: < Vec < TargetType > > ( ) {
265
+ vec if vec. is_empty ( ) => None ,
266
+ vec => Some ( vec)
267
+ }
268
+ } ;
269
+
270
+ let targets = FoundTargets :: resolve ( layer_config, rich_output, target_types) . await ?;
241
271
242
272
match args. output {
243
273
Format :: Json => {
0 commit comments