mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #80764 from liyanhui1228/auth
Determine system model to get credentials for windows nodes
This commit is contained in:
commit
56d7920e8f
@ -20,6 +20,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -115,12 +117,27 @@ func init() {
|
|||||||
// Returns true if it finds a local GCE VM.
|
// Returns true if it finds a local GCE VM.
|
||||||
// Looks at a product file that is an undocumented API.
|
// Looks at a product file that is an undocumented API.
|
||||||
func onGCEVM() bool {
|
func onGCEVM() bool {
|
||||||
data, err := ioutil.ReadFile(gceProductNameFile)
|
var name string
|
||||||
if err != nil {
|
|
||||||
klog.V(2).Infof("Error while reading product_name: %v", err)
|
if runtime.GOOS == "windows" {
|
||||||
return false
|
data, err := exec.Command("wmic", "computersystem", "get", "model").Output()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
fields := strings.Split(strings.TrimSpace(string(data)), "\r\n")
|
||||||
|
if len(fields) != 2 {
|
||||||
|
klog.V(2).Infof("Received unexpected value retrieving system model: %q", string(data))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
name = fields[1]
|
||||||
|
} else {
|
||||||
|
data, err := ioutil.ReadFile(gceProductNameFile)
|
||||||
|
if err != nil {
|
||||||
|
klog.V(2).Infof("Error while reading product_name: %v", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
name = strings.TrimSpace(string(data))
|
||||||
}
|
}
|
||||||
name := strings.TrimSpace(string(data))
|
|
||||||
return name == "Google" || name == "Google Compute Engine"
|
return name == "Google" || name == "Google Compute Engine"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user