mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-10-30 21:30:16 +00:00 
			
		
		
		
	cloudcfg working locally now
This commit is contained in:
		| @@ -20,6 +20,7 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"log" | 	"log" | ||||||
| 	"net/http" | 	"net/http" | ||||||
|  | 	"net/url" | ||||||
| 	"os" | 	"os" | ||||||
| 	"strconv" | 	"strconv" | ||||||
| 	"time" | 	"time" | ||||||
| @@ -39,7 +40,7 @@ var ( | |||||||
| 	updatePeriod = flag.Duration("u", 60*time.Second, "Update interarrival period") | 	updatePeriod = flag.Duration("u", 60*time.Second, "Update interarrival period") | ||||||
| 	portSpec     = flag.String("p", "", "The port spec, comma-separated list of <external>:<internal>,...") | 	portSpec     = flag.String("p", "", "The port spec, comma-separated list of <external>:<internal>,...") | ||||||
| 	servicePort  = flag.Int("s", -1, "If positive, create and run a corresponding service on this port, only used with 'run'") | 	servicePort  = flag.Int("s", -1, "If positive, create and run a corresponding service on this port, only used with 'run'") | ||||||
| 	authConfig   = flag.String("auth", os.Getenv("HOME")+"/.kubernetes_auth", "Path to the auth info file.  If missing, prompt the user") | 	authConfig   = flag.String("auth", os.Getenv("HOME")+"/.kubernetes_auth", "Path to the auth info file.  If missing, prompt the user.  Only used if doing https.") | ||||||
| 	json         = flag.Bool("json", false, "If true, print raw JSON for responses") | 	json         = flag.Bool("json", false, "If true, print raw JSON for responses") | ||||||
| 	yaml         = flag.Bool("yaml", false, "If true, print raw YAML for responses") | 	yaml         = flag.Bool("yaml", false, "If true, print raw YAML for responses") | ||||||
| ) | ) | ||||||
| @@ -61,9 +62,16 @@ func main() { | |||||||
| 		usage() | 		usage() | ||||||
| 	} | 	} | ||||||
| 	method := flag.Arg(0) | 	method := flag.Arg(0) | ||||||
|  | 	secure := true | ||||||
|  | 	parsedUrl, err := url.Parse(*httpServer) | ||||||
|  | 	if err != nil { | ||||||
|  | 		log.Fatalf("Unable to parse %v as a URL\n", err) | ||||||
|  | 	} | ||||||
|  | 	if parsedUrl.Scheme != "" && parsedUrl.Scheme != "https" { | ||||||
|  | 		secure = false | ||||||
|  | 	} | ||||||
| 	url := *httpServer + "/api/v1beta1" + flag.Arg(1) | 	url := *httpServer + "/api/v1beta1" + flag.Arg(1) | ||||||
| 	var request *http.Request | 	var request *http.Request | ||||||
| 	var err error |  | ||||||
|  |  | ||||||
| 	var printer cloudcfg.ResourcePrinter | 	var printer cloudcfg.ResourcePrinter | ||||||
| 	if *json { | 	if *json { | ||||||
| @@ -74,10 +82,13 @@ func main() { | |||||||
| 		printer = &cloudcfg.HumanReadablePrinter{} | 		printer = &cloudcfg.HumanReadablePrinter{} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	auth, err := cloudcfg.LoadAuthInfo(*authConfig) | 	var auth kube_client.AuthInfo | ||||||
|  | 	if secure { | ||||||
|  | 		auth, err = cloudcfg.LoadAuthInfo(*authConfig) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			log.Fatalf("Error loading auth: %#v", err) | 			log.Fatalf("Error loading auth: %#v", err) | ||||||
| 		} | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	switch method { | 	switch method { | ||||||
| 	case "get", "list": | 	case "get", "list": | ||||||
| @@ -132,7 +143,11 @@ func main() { | |||||||
| 		log.Fatalf("Error: %#v", err) | 		log.Fatalf("Error: %#v", err) | ||||||
| 	} | 	} | ||||||
| 	var body string | 	var body string | ||||||
| 	body, err = cloudcfg.DoRequest(request, auth.User, auth.Password) | 	if secure { | ||||||
|  | 		body, err = cloudcfg.DoSecureRequest(request, auth.User, auth.Password) | ||||||
|  | 	} else { | ||||||
|  | 		body, err = cloudcfg.DoInsecureRequest(request) | ||||||
|  | 	} | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Fatalf("Error: %#v", err) | 		log.Fatalf("Error: %#v", err) | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -35,9 +35,6 @@ set -e | |||||||
|   done |   done | ||||||
| ) | ) | ||||||
|  |  | ||||||
| source "$(dirname 0)/../cluster/util.sh" |  | ||||||
| get-password |  | ||||||
|  |  | ||||||
| echo "Starting etcd" | echo "Starting etcd" | ||||||
|  |  | ||||||
| ETCD_DIR=$(mktemp -d -t kube-integration.XXXXXX) | ETCD_DIR=$(mktemp -d -t kube-integration.XXXXXX) | ||||||
|   | |||||||
| @@ -24,4 +24,4 @@ if [ ! -x $CLOUDCFG ]; then | |||||||
| fi | fi | ||||||
|  |  | ||||||
| # 8080 is the default port for the master | # 8080 is the default port for the master | ||||||
| $CLOUDCFG -h https://localhost:8080 $@ | $CLOUDCFG -h http://localhost:8080 $@ | ||||||
|   | |||||||
| @@ -99,13 +99,13 @@ func RequestWithBody(configFile, url, method string) (*http.Request, error) { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	return RequestWithBodyData(data, url, method) | 	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 | // and body data | ||||||
| // FIXME: need to be public API? | // FIXME: need to be public API? | ||||||
| func RequestWithBodyData(data []byte, url, method string) (*http.Request, error) { | func requestWithBodyData(data []byte, url, method string) (*http.Request, error) { | ||||||
| 	request, err := http.NewRequest(method, url, bytes.NewBuffer(data)) | 	request, err := http.NewRequest(method, url, bytes.NewBuffer(data)) | ||||||
| 	request.ContentLength = int64(len(data)) | 	request.ContentLength = int64(len(data)) | ||||||
| 	return request, err | 	return request, err | ||||||
| @@ -113,8 +113,7 @@ func RequestWithBodyData(data []byte, url, method string) (*http.Request, error) | |||||||
|  |  | ||||||
| // Execute a request, adds authentication, and HTTPS cert ignoring. | // Execute a request, adds authentication, and HTTPS cert ignoring. | ||||||
| // TODO: Make this stuff optional | // TODO: Make this stuff optional | ||||||
| // FIXME: need to be public API? | func DoSecureRequest(request *http.Request, user, password string) (string, error) { | ||||||
| func DoRequest(request *http.Request, user, password string) (string, error) { |  | ||||||
| 	request.SetBasicAuth(user, password) | 	request.SetBasicAuth(user, password) | ||||||
| 	tr := &http.Transport{ | 	tr := &http.Transport{ | ||||||
| 		TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | 		TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | ||||||
| @@ -129,6 +128,17 @@ func DoRequest(request *http.Request, user, password string) (string, error) { | |||||||
| 	return string(body), err | 	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 | // StopController stops a controller named 'name' by setting replicas to zero | ||||||
| func StopController(name string, client client.ClientInterface) error { | func StopController(name string, client client.ClientInterface) error { | ||||||
| 	controller, err := client.GetReplicationController(name) | 	controller, err := client.GetReplicationController(name) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user