@@ -287,29 +287,27 @@ func (o *ProxyRunOptions) Validate() error {
287287 if o .EnableContentionProfiling && ! o .EnableProfiling {
288288 return fmt .Errorf ("if --enable-contention-profiling is set, --enable-profiling must also be set" )
289289 }
290-
291- // validate agent authentication params
292- // all 4 parameters must be empty or must have value (except KubeconfigPath that might be empty)
293- if o .AgentNamespace != "" || o .AgentServiceAccount != "" || o .AuthenticationAudience != "" || o .KubeconfigPath != "" {
290+ usingServiceAccountAuth := o .AgentNamespace != "" || o .AgentServiceAccount != "" || o .AuthenticationAudience != ""
291+ if usingServiceAccountAuth {
294292 if o .ClusterCaCert != "" {
295- return fmt .Errorf ("ClusterCaCert can not be used when service account authentication is enabled" )
293+ return fmt .Errorf ("--cluster-ca-cert can not be used when service account authentication is enabled" )
296294 }
297295 if o .AgentNamespace == "" {
298- return fmt .Errorf ("AgentNamespace cannot be empty when agent authentication is enabled" )
296+ return fmt .Errorf ("--agent-namespace cannot be empty when service account authentication is enabled" )
299297 }
300298 if o .AgentServiceAccount == "" {
301- return fmt .Errorf ("AgentServiceAccount cannot be empty when agent authentication is enabled" )
299+ return fmt .Errorf ("--agent-service-account cannot be empty when service account authentication is enabled" )
302300 }
303301 if o .AuthenticationAudience == "" {
304- return fmt .Errorf ("AuthenticationAudience cannot be empty when agent authentication is enabled" )
302+ return fmt .Errorf ("AuthenticationAudience cannot be empty when service account authentication is enabled" )
305303 }
306- if o .KubeconfigPath != "" {
307- if _ , err := os .Stat (o .KubeconfigPath ); os .IsNotExist (err ) {
308- return fmt .Errorf ("error checking KubeconfigPath %q, got %v" , o .KubeconfigPath , err )
309- }
304+ }
305+ // Validate kubeconfig path if provided
306+ if o .KubeconfigPath != "" {
307+ if _ , err := os .Stat (o .KubeconfigPath ); os .IsNotExist (err ) {
308+ return fmt .Errorf ("checking KubeconfigPath %q, got %v" , o .KubeconfigPath , err )
310309 }
311310 }
312-
313311 // validate the proxy strategies
314312 if len (o .ProxyStrategies ) == 0 {
315313 return fmt .Errorf ("ProxyStrategies cannot be empty" )
0 commit comments