mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-29 08:57:44 +08:00

Tested with `kind` and GKE. Note: "nodes" shown in `docker buildx ls` are unrelated to Kubernetes "nodes". Probably buildx should come up with an alternative term. Usage: $ kind create cluster $ export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" $ docker buildx create --driver kubernetes --driver-opt replicas=3 --use $ docker buildx build -t foo --load . `--load` loads the image into the local Docker. Driver opts: - `image=IMAGE` - Sets the container image to be used for running buildkit. - `namespace=NS` - Sets the Kubernetes namespace. Defaults to the current namespace. - `replicas=N` - Sets the number of `Pod` replicas. Defaults to 1. - `rootless=(true|false)` - Run the container as a non-root user without `securityContext.privileged`. Defaults to false. - `loadbalance=(sticky|random)` - Load-balancing strategy. If set to "sticky", the pod is chosen using the hash of the context path. Defaults to "sticky" Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package pagination
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/gophercloud/gophercloud"
|
|
)
|
|
|
|
// PageResult stores the HTTP response that returned the current page of results.
|
|
type PageResult struct {
|
|
gophercloud.Result
|
|
url.URL
|
|
}
|
|
|
|
// PageResultFrom parses an HTTP response as JSON and returns a PageResult containing the
|
|
// results, interpreting it as JSON if the content type indicates.
|
|
func PageResultFrom(resp *http.Response) (PageResult, error) {
|
|
var parsedBody interface{}
|
|
|
|
defer resp.Body.Close()
|
|
rawBody, err := ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return PageResult{}, err
|
|
}
|
|
|
|
if strings.HasPrefix(resp.Header.Get("Content-Type"), "application/json") {
|
|
err = json.Unmarshal(rawBody, &parsedBody)
|
|
if err != nil {
|
|
return PageResult{}, err
|
|
}
|
|
} else {
|
|
parsedBody = rawBody
|
|
}
|
|
|
|
return PageResultFromParsed(resp, parsedBody), err
|
|
}
|
|
|
|
// PageResultFromParsed constructs a PageResult from an HTTP response that has already had its
|
|
// body parsed as JSON (and closed).
|
|
func PageResultFromParsed(resp *http.Response, body interface{}) PageResult {
|
|
return PageResult{
|
|
Result: gophercloud.Result{
|
|
Body: body,
|
|
Header: resp.Header,
|
|
},
|
|
URL: *resp.Request.URL,
|
|
}
|
|
}
|
|
|
|
// Request performs an HTTP request and extracts the http.Response from the result.
|
|
func Request(client *gophercloud.ServiceClient, headers map[string]string, url string) (*http.Response, error) {
|
|
return client.Get(url, nil, &gophercloud.RequestOpts{
|
|
MoreHeaders: headers,
|
|
OkCodes: []int{200, 204, 300},
|
|
})
|
|
}
|