@@ -54,12 +54,10 @@ const (
5454 Latest = ">0.0.0-0"
5555)
5656
57- var (
58- // downloadLocaton is the location where downloaded helm charts
59- // will be stored. os.TempDir will ensure that the path is cross
60- // platform
61- downloadLocation = os .TempDir ()
62- )
57+ // downloadLocaton is the location where downloaded helm charts
58+ // will be stored. os.TempDir will ensure that the path is cross
59+ // platform
60+ var downloadLocation = os .TempDir ()
6361
6462// HelmIndex holds the index.yaml data in the struct format
6563type HelmIndex struct {
@@ -421,57 +419,64 @@ func createHelmActionConfig(c *Client, cfg ApplyHelmChartConfig) (*action.Config
421419
422420 // KubeConfig setup
423421 kubeConfig := genericclioptions .NewConfigFlags (false )
424- // Set KubeConfig to DevNull to prevent read from local kubeconfig
425- // to prevent conflicts between "data" and "files" properties (CAFile, CAData and KeyFile, KeyData)
426- // ConfigFlags only allows setting CAFile, KeyFile but not CAData, KeyData.
427- // When the library reads the original kubeconfig containing cert data / key data AND we specify cert file / key file, these configurations conflict
428- devNull := os .DevNull
429- kubeConfig .KubeConfig = & devNull
430- kubeConfig .APIServer = & c .RestConfig .Host
431- kubeConfig .BearerToken = & c .RestConfig .BearerToken
432- kubeConfig .Insecure = & c .RestConfig .Insecure
433-
434- // Set username and password for basic auth if available
435- if c .RestConfig .Username != "" {
436- kubeConfig .Username = & c .RestConfig .Username
437- }
438- if c .RestConfig .Password != "" {
439- kubeConfig .Password = & c .RestConfig .Password
440- }
441-
442- // Only set CA file if not running in insecure mode
443- if ! c .RestConfig .Insecure {
444- if len (c .RestConfig .CAData ) > 0 {
445- caFileName , err := setDataAndReturnFilename (c .RestConfig .CAData )
446- if err != nil {
447- cleanup () // Clean up any files created so far
448- return nil , nil , err
422+
423+ // Exec-auth kubeconfigs (eg: aws eks get-token) typically do not have a static bearer token.
424+ // In that case, do not force /dev/null; let client-go load kubeconfig and execute the auth plugin.
425+ useKubeconfigAuth := c .RestConfig .ExecProvider != nil && c .RestConfig .BearerToken == ""
426+
427+ if ! useKubeconfigAuth {
428+ // Set KubeConfig to DevNull to prevent read from local kubeconfig
429+ // to prevent conflicts between "data" and "files" properties (CAFile, CAData and KeyFile, KeyData)
430+ // ConfigFlags only allows setting CAFile, KeyFile but not CAData, KeyData.
431+ // When the library reads the original kubeconfig containing cert data / key data AND we specify cert file / key file, these configurations conflict
432+ devNull := os .DevNull
433+ kubeConfig .KubeConfig = & devNull
434+ kubeConfig .APIServer = & c .RestConfig .Host
435+ kubeConfig .BearerToken = & c .RestConfig .BearerToken
436+ kubeConfig .Insecure = & c .RestConfig .Insecure
437+
438+ // Set username and password for basic auth if available
439+ if c .RestConfig .Username != "" {
440+ kubeConfig .Username = & c .RestConfig .Username
441+ }
442+ if c .RestConfig .Password != "" {
443+ kubeConfig .Password = & c .RestConfig .Password
444+ }
445+
446+ // Only set CA file if not running in insecure mode
447+ if ! c .RestConfig .Insecure {
448+ if len (c .RestConfig .CAData ) > 0 {
449+ caFileName , err := setDataAndReturnFilename (c .RestConfig .CAData )
450+ if err != nil {
451+ cleanup () // Clean up any files created so far
452+ return nil , nil , err
453+ }
454+ tempFiles = append (tempFiles , caFileName )
455+ kubeConfig .CAFile = & caFileName
449456 }
450- tempFiles = append (tempFiles , caFileName )
451- kubeConfig .CAFile = & caFileName
452457 }
453- }
454458
455- // Set client certificate data if available
456- if len (c .RestConfig .CertData ) > 0 {
457- certFileName , err := setDataAndReturnFilename (c .RestConfig .CertData )
458- if err != nil {
459- cleanup ()
460- return nil , nil , err
459+ // Set client certificate data if available
460+ if len (c .RestConfig .CertData ) > 0 {
461+ certFileName , err := setDataAndReturnFilename (c .RestConfig .CertData )
462+ if err != nil {
463+ cleanup ()
464+ return nil , nil , err
465+ }
466+ tempFiles = append (tempFiles , certFileName )
467+ kubeConfig .CertFile = & certFileName
461468 }
462- tempFiles = append (tempFiles , certFileName )
463- kubeConfig .CertFile = & certFileName
464- }
465469
466- // Set client key data if available
467- if len (c .RestConfig .KeyData ) > 0 {
468- keyFileName , err := setDataAndReturnFilename (c .RestConfig .KeyData )
469- if err != nil {
470- cleanup () // Clean up any files created so far
471- return nil , nil , err
470+ // Set client key data if available
471+ if len (c .RestConfig .KeyData ) > 0 {
472+ keyFileName , err := setDataAndReturnFilename (c .RestConfig .KeyData )
473+ if err != nil {
474+ cleanup () // Clean up any files created so far
475+ return nil , nil , err
476+ }
477+ tempFiles = append (tempFiles , keyFileName )
478+ kubeConfig .KeyFile = & keyFileName
472479 }
473- tempFiles = append (tempFiles , keyFileName )
474- kubeConfig .KeyFile = & keyFileName
475480 }
476481
477482 actionConfig := new (action.Configuration )
@@ -554,7 +559,8 @@ func createHelmPathFromHelmChartLocation(loc HelmChartLocation) (string, error)
554559 getter.Provider {
555560 Schemes : []string {"http" , "https" },
556561 New : getter .NewHTTPGetter ,
557- }},
562+ },
563+ },
558564 )
559565 if err != nil {
560566 return "" , ErrApplyHelmChart (err )
0 commit comments