Changed kubectl config set-cluster and set-credentials to support process substitution for filenames

Kubernetes-commit: 84d5e664afb809b92c31a4c36acb2baa1fc8649e
This commit is contained in:
Brian Pursley 2020-05-15 09:22:59 -04:00 committed by Kubernetes Publisher
parent b3d1e6e06f
commit 7ed1bb5485
2 changed files with 9 additions and 7 deletions

View File

@ -21,6 +21,7 @@ import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -421,13 +422,13 @@ func (o createAuthInfoOptions) validate() error {
return fmt.Errorf("you must specify a --%s or --%s to embed", clientcmd.FlagCertFile, clientcmd.FlagKeyFile)
}
if certPath != "" {
if _, err := ioutil.ReadFile(certPath); err != nil {
return fmt.Errorf("error reading %s data from %s: %v", clientcmd.FlagCertFile, certPath, err)
if _, err := os.Stat(certPath); err != nil {
return fmt.Errorf("could not stat %s file %s: %v", clientcmd.FlagCertFile, certPath, err)
}
}
if keyPath != "" {
if _, err := ioutil.ReadFile(keyPath); err != nil {
return fmt.Errorf("error reading %s data from %s: %v", clientcmd.FlagKeyFile, keyPath, err)
if _, err := os.Stat(keyPath); err != nil {
return fmt.Errorf("could not stat %s file %s: %v", clientcmd.FlagKeyFile, keyPath, err)
}
}
}

View File

@ -21,6 +21,7 @@ import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"github.com/spf13/cobra"
@ -53,7 +54,7 @@ var (
kubectl config set-cluster e2e --server=https://1.2.3.4
# Embed certificate authority data for the e2e cluster entry
kubectl config set-cluster e2e --certificate-authority=~/.kube/e2e/kubernetes.ca.crt
kubectl config set-cluster e2e --embed-certs --certificate-authority=~/.kube/e2e/kubernetes.ca.crt
# Disable cert checking for the dev cluster entry
kubectl config set-cluster e2e --insecure-skip-tls-verify=true
@ -181,8 +182,8 @@ func (o createClusterOptions) validate() error {
if caPath == "" {
return fmt.Errorf("you must specify a --%s to embed", clientcmd.FlagCAFile)
}
if _, err := ioutil.ReadFile(caPath); err != nil {
return fmt.Errorf("could not read %s data from %s: %v", clientcmd.FlagCAFile, caPath, err)
if _, err := os.Stat(caPath); err != nil {
return fmt.Errorf("could not stat %s file %s: %v", clientcmd.FlagCAFile, caPath, err)
}
}