mirror of https://github.com/k3s-io/k3s
Address comments
parent
69acbf5a74
commit
ac65cc7094
|
@ -22,6 +22,7 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -70,7 +71,7 @@ func main() {
|
|||
if parsedUrl.Scheme != "" && parsedUrl.Scheme != "https" {
|
||||
secure = false
|
||||
}
|
||||
url := *httpServer + "/api/v1beta1" + flag.Arg(1)
|
||||
url := *httpServer + path.Join("/api/v1beta1", flag.Arg(1))
|
||||
var request *http.Request
|
||||
|
||||
var printer cloudcfg.ResourcePrinter
|
||||
|
@ -82,7 +83,7 @@ func main() {
|
|||
printer = &cloudcfg.HumanReadablePrinter{}
|
||||
}
|
||||
|
||||
var auth kube_client.AuthInfo
|
||||
var auth *kube_client.AuthInfo
|
||||
if secure {
|
||||
auth, err = cloudcfg.LoadAuthInfo(*authConfig)
|
||||
if err != nil {
|
||||
|
@ -105,7 +106,7 @@ func main() {
|
|||
case "rollingupdate":
|
||||
client := &kube_client.Client{
|
||||
Host: *httpServer,
|
||||
Auth: &auth,
|
||||
Auth: auth,
|
||||
}
|
||||
cloudcfg.Update(flag.Arg(1), client, *updatePeriod)
|
||||
case "run":
|
||||
|
@ -119,19 +120,19 @@ func main() {
|
|||
if err != nil {
|
||||
log.Fatalf("Error parsing replicas: %#v", err)
|
||||
}
|
||||
err = cloudcfg.RunController(image, name, replicas, kube_client.Client{Host: *httpServer, Auth: &auth}, *portSpec, *servicePort)
|
||||
err = cloudcfg.RunController(image, name, replicas, kube_client.Client{Host: *httpServer, Auth: auth}, *portSpec, *servicePort)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: %#v", err)
|
||||
}
|
||||
return
|
||||
case "stop":
|
||||
err = cloudcfg.StopController(flag.Arg(1), kube_client.Client{Host: *httpServer, Auth: &auth})
|
||||
err = cloudcfg.StopController(flag.Arg(1), kube_client.Client{Host: *httpServer, Auth: auth})
|
||||
if err != nil {
|
||||
log.Fatalf("Error: %#v", err)
|
||||
}
|
||||
return
|
||||
case "rm":
|
||||
err = cloudcfg.DeleteController(flag.Arg(1), kube_client.Client{Host: *httpServer, Auth: &auth})
|
||||
err = cloudcfg.DeleteController(flag.Arg(1), kube_client.Client{Host: *httpServer, Auth: auth})
|
||||
if err != nil {
|
||||
log.Fatalf("Error: %#v", err)
|
||||
}
|
||||
|
@ -142,12 +143,7 @@ func main() {
|
|||
if err != nil {
|
||||
log.Fatalf("Error: %#v", err)
|
||||
}
|
||||
var body string
|
||||
if secure {
|
||||
body, err = cloudcfg.DoSecureRequest(request, auth.User, auth.Password)
|
||||
} else {
|
||||
body, err = cloudcfg.DoInsecureRequest(request)
|
||||
}
|
||||
body, err := cloudcfg.DoRequest(request, auth)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: %#v", err)
|
||||
}
|
||||
|
|
|
@ -79,7 +79,6 @@ func fake_kubelet() {
|
|||
|
||||
// Starts api services (the master). Never returns.
|
||||
func api_server() {
|
||||
//machineList := util.StringList{fmt.Sprintf("%s:%v", *kubelet_address, *kubelet_port)}
|
||||
machineList := util.StringList{*kubelet_address}
|
||||
|
||||
etcdClient := etcd.NewClient([]string{*etcd_server})
|
||||
|
|
|
@ -42,25 +42,28 @@ func promptForString(field string) string {
|
|||
return result
|
||||
}
|
||||
|
||||
// Parse an AuthInfo object from a file path
|
||||
func LoadAuthInfo(path string) (client.AuthInfo, error) {
|
||||
// Parse an AuthInfo object from a file path. Prompt user and create file if it doesn't exist.
|
||||
func LoadAuthInfo(path string) (*client.AuthInfo, error) {
|
||||
var auth client.AuthInfo
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
auth.User = promptForString("Username")
|
||||
auth.Password = promptForString("Password")
|
||||
data, err := json.Marshal(auth)
|
||||
if err != nil {
|
||||
return auth, err
|
||||
return &auth, err
|
||||
}
|
||||
err = ioutil.WriteFile(path, data, 0600)
|
||||
return auth, err
|
||||
return &auth, err
|
||||
}
|
||||
data, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return auth, err
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(data, &auth)
|
||||
return auth, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &auth, err
|
||||
}
|
||||
|
||||
// Perform a rolling update of a collection of pods.
|
||||
|
@ -102,19 +105,19 @@ func RequestWithBody(configFile, url, method string) (*http.Request, error) {
|
|||
return requestWithBodyData(data, url, method)
|
||||
}
|
||||
|
||||
// RequestWithBodyData is a helper method that creates an HTTP request with the specified url, method
|
||||
// requestWithBodyData is a helper method that creates an HTTP request with the specified url, method
|
||||
// and body data
|
||||
// FIXME: need to be public API?
|
||||
func requestWithBodyData(data []byte, url, method string) (*http.Request, error) {
|
||||
request, err := http.NewRequest(method, url, bytes.NewBuffer(data))
|
||||
request.ContentLength = int64(len(data))
|
||||
return request, err
|
||||
}
|
||||
|
||||
// Execute a request, adds authentication, and HTTPS cert ignoring.
|
||||
// TODO: Make this stuff optional
|
||||
func DoSecureRequest(request *http.Request, user, password string) (string, error) {
|
||||
request.SetBasicAuth(user, password)
|
||||
// Execute a request, adds authentication (if auth != nil), and HTTPS cert ignoring.
|
||||
func DoRequest(request *http.Request, auth *client.AuthInfo) (string, error) {
|
||||
if auth != nil {
|
||||
request.SetBasicAuth(auth.User, auth.Password)
|
||||
}
|
||||
tr := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
|
@ -128,17 +131,6 @@ func DoSecureRequest(request *http.Request, user, password string) (string, erro
|
|||
return string(body), err
|
||||
}
|
||||
|
||||
// Execute a request.
|
||||
func DoInsecureRequest(request *http.Request) (string, error) {
|
||||
response, err := http.DefaultClient.Do(request)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
body, err := ioutil.ReadAll(response.Body)
|
||||
return string(body), err
|
||||
}
|
||||
|
||||
// StopController stops a controller named 'name' by setting replicas to zero
|
||||
func StopController(name string, client client.ClientInterface) error {
|
||||
controller, err := client.GetReplicationController(name)
|
||||
|
|
|
@ -26,7 +26,7 @@ import (
|
|||
func HandleCrash() {
|
||||
r := recover()
|
||||
if r != nil {
|
||||
log.Printf("Recovered from panic: %v", r)
|
||||
log.Printf("Recovered from panic: %#v", r)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue