@@ -159,7 +159,7 @@ func (config *DirectClientConfig) ClientConfig() (*restclient.Config, error) {
159
159
clientConfig .Proxy = http .ProxyURL (u )
160
160
}
161
161
162
- if len (config .overrides .Timeout ) > 0 {
162
+ if config . overrides != nil && len (config .overrides .Timeout ) > 0 {
163
163
timeout , err := ParseTimeout (config .overrides .Timeout )
164
164
if err != nil {
165
165
return nil , err
@@ -381,7 +381,7 @@ func (config *DirectClientConfig) ConfirmUsable() error {
381
381
// getContextName returns the default, or user-set context name, and a boolean that indicates
382
382
// whether the default context name has been overwritten by a user-set flag, or left as its default value
383
383
func (config * DirectClientConfig ) getContextName () (string , bool ) {
384
- if len (config .overrides .CurrentContext ) != 0 {
384
+ if config . overrides != nil && len (config .overrides .CurrentContext ) != 0 {
385
385
return config .overrides .CurrentContext , true
386
386
}
387
387
if len (config .contextName ) != 0 {
@@ -395,7 +395,7 @@ func (config *DirectClientConfig) getContextName() (string, bool) {
395
395
// and a boolean indicating whether the default authInfo name is overwritten by a user-set flag, or
396
396
// left as its default value
397
397
func (config * DirectClientConfig ) getAuthInfoName () (string , bool ) {
398
- if len (config .overrides .Context .AuthInfo ) != 0 {
398
+ if config . overrides != nil && len (config .overrides .Context .AuthInfo ) != 0 {
399
399
return config .overrides .Context .AuthInfo , true
400
400
}
401
401
context , _ := config .getContext ()
@@ -406,7 +406,7 @@ func (config *DirectClientConfig) getAuthInfoName() (string, bool) {
406
406
// indicating whether the default clusterName has been overwritten by a user-set flag, or left as
407
407
// its default value
408
408
func (config * DirectClientConfig ) getClusterName () (string , bool ) {
409
- if len (config .overrides .Context .Cluster ) != 0 {
409
+ if config . overrides != nil && len (config .overrides .Context .Cluster ) != 0 {
410
410
return config .overrides .Context .Cluster , true
411
411
}
412
412
context , _ := config .getContext ()
@@ -424,7 +424,9 @@ func (config *DirectClientConfig) getContext() (clientcmdapi.Context, error) {
424
424
} else if required {
425
425
return clientcmdapi.Context {}, fmt .Errorf ("context %q does not exist" , contextName )
426
426
}
427
- mergo .MergeWithOverwrite (mergedContext , config .overrides .Context )
427
+ if config .overrides != nil {
428
+ mergo .MergeWithOverwrite (mergedContext , config .overrides .Context )
429
+ }
428
430
429
431
return * mergedContext , nil
430
432
}
@@ -440,7 +442,9 @@ func (config *DirectClientConfig) getAuthInfo() (clientcmdapi.AuthInfo, error) {
440
442
} else if required {
441
443
return clientcmdapi.AuthInfo {}, fmt .Errorf ("auth info %q does not exist" , authInfoName )
442
444
}
443
- mergo .MergeWithOverwrite (mergedAuthInfo , config .overrides .AuthInfo )
445
+ if config .overrides != nil {
446
+ mergo .MergeWithOverwrite (mergedAuthInfo , config .overrides .AuthInfo )
447
+ }
444
448
445
449
return * mergedAuthInfo , nil
446
450
}
@@ -451,30 +455,37 @@ func (config *DirectClientConfig) getCluster() (clientcmdapi.Cluster, error) {
451
455
clusterInfoName , required := config .getClusterName ()
452
456
453
457
mergedClusterInfo := clientcmdapi .NewCluster ()
454
- mergo .MergeWithOverwrite (mergedClusterInfo , config .overrides .ClusterDefaults )
458
+ if config .overrides != nil {
459
+ mergo .MergeWithOverwrite (mergedClusterInfo , config .overrides .ClusterDefaults )
460
+ }
455
461
if configClusterInfo , exists := clusterInfos [clusterInfoName ]; exists {
456
462
mergo .MergeWithOverwrite (mergedClusterInfo , configClusterInfo )
457
463
} else if required {
458
464
return clientcmdapi.Cluster {}, fmt .Errorf ("cluster %q does not exist" , clusterInfoName )
459
465
}
460
- mergo .MergeWithOverwrite (mergedClusterInfo , config .overrides .ClusterInfo )
466
+ if config .overrides != nil {
467
+ mergo .MergeWithOverwrite (mergedClusterInfo , config .overrides .ClusterInfo )
468
+ }
469
+
461
470
// * An override of --insecure-skip-tls-verify=true and no accompanying CA/CA data should clear already-set CA/CA data
462
471
// otherwise, a kubeconfig containing a CA reference would return an error that "CA and insecure-skip-tls-verify couldn't both be set".
463
472
// * An override of --certificate-authority should also override TLS skip settings and CA data, otherwise existing CA data will take precedence.
464
- caLen := len (config .overrides .ClusterInfo .CertificateAuthority )
465
- caDataLen := len (config .overrides .ClusterInfo .CertificateAuthorityData )
466
- if config .overrides .ClusterInfo .InsecureSkipTLSVerify || caLen > 0 || caDataLen > 0 {
467
- mergedClusterInfo .InsecureSkipTLSVerify = config .overrides .ClusterInfo .InsecureSkipTLSVerify
468
- mergedClusterInfo .CertificateAuthority = config .overrides .ClusterInfo .CertificateAuthority
469
- mergedClusterInfo .CertificateAuthorityData = config .overrides .ClusterInfo .CertificateAuthorityData
470
- }
471
-
472
- // if the --tls-server-name has been set in overrides, use that value.
473
- // if the --server has been set in overrides, then use the value of --tls-server-name specified on the CLI too. This gives the property
474
- // that setting a --server will effectively clear the KUBECONFIG value of tls-server-name if it is specified on the command line which is
475
- // usually correct.
476
- if config .overrides .ClusterInfo .TLSServerName != "" || config .overrides .ClusterInfo .Server != "" {
477
- mergedClusterInfo .TLSServerName = config .overrides .ClusterInfo .TLSServerName
473
+ if config .overrides != nil {
474
+ caLen := len (config .overrides .ClusterInfo .CertificateAuthority )
475
+ caDataLen := len (config .overrides .ClusterInfo .CertificateAuthorityData )
476
+ if config .overrides .ClusterInfo .InsecureSkipTLSVerify || caLen > 0 || caDataLen > 0 {
477
+ mergedClusterInfo .InsecureSkipTLSVerify = config .overrides .ClusterInfo .InsecureSkipTLSVerify
478
+ mergedClusterInfo .CertificateAuthority = config .overrides .ClusterInfo .CertificateAuthority
479
+ mergedClusterInfo .CertificateAuthorityData = config .overrides .ClusterInfo .CertificateAuthorityData
480
+ }
481
+
482
+ // if the --tls-server-name has been set in overrides, use that value.
483
+ // if the --server has been set in overrides, then use the value of --tls-server-name specified on the CLI too. This gives the property
484
+ // that setting a --server will effectively clear the KUBECONFIG value of tls-server-name if it is specified on the command line which is
485
+ // usually correct.
486
+ if config .overrides .ClusterInfo .TLSServerName != "" || config .overrides .ClusterInfo .Server != "" {
487
+ mergedClusterInfo .TLSServerName = config .overrides .ClusterInfo .TLSServerName
488
+ }
478
489
}
479
490
480
491
return * mergedClusterInfo , nil
0 commit comments