mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #20095 from liggitt/load_tls_files
Auto commit by PR queue bot
This commit is contained in:
commit
f915ca55d0
@ -582,3 +582,41 @@ func DefaultKubernetesUserAgent() string {
|
|||||||
version = seg[0]
|
version = seg[0]
|
||||||
return fmt.Sprintf("%s/%s (%s/%s) kubernetes/%s", path.Base(os.Args[0]), version, gruntime.GOOS, gruntime.GOARCH, commit)
|
return fmt.Sprintf("%s/%s (%s/%s) kubernetes/%s", path.Base(os.Args[0]), version, gruntime.GOOS, gruntime.GOARCH, commit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadTLSFiles copies the data from the CertFile, KeyFile, and CAFile fields into the CertData,
|
||||||
|
// KeyData, and CAFile fields, or returns an error. If no error is returned, all three fields are
|
||||||
|
// either populated or were empty to start.
|
||||||
|
func LoadTLSFiles(c *Config) error {
|
||||||
|
var err error
|
||||||
|
c.CAData, err = dataFromSliceOrFile(c.CAData, c.CAFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.CertData, err = dataFromSliceOrFile(c.CertData, c.CertFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.KeyData, err = dataFromSliceOrFile(c.KeyData, c.KeyFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// dataFromSliceOrFile returns data from the slice (if non-empty), or from the file,
|
||||||
|
// or an error if an error occurred reading the file
|
||||||
|
func dataFromSliceOrFile(data []byte, file string) ([]byte, error) {
|
||||||
|
if len(data) > 0 {
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
if len(file) > 0 {
|
||||||
|
fileData, err := ioutil.ReadFile(file)
|
||||||
|
if err != nil {
|
||||||
|
return []byte{}, err
|
||||||
|
}
|
||||||
|
return fileData, nil
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user