mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Fixes golint errors in pkg/client
This commit is contained in:
parent
5cfbed4453
commit
325c5cd47e
@ -75,7 +75,7 @@ type Client struct {
|
|||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new client object.
|
// New creates a new client object.
|
||||||
func New(host string, auth *AuthInfo) *Client {
|
func New(host string, auth *AuthInfo) *Client {
|
||||||
return &Client{
|
return &Client{
|
||||||
auth: auth,
|
auth: auth,
|
||||||
@ -159,79 +159,81 @@ func (c *Client) rawRequest(method, path string, requestBody io.Reader, target i
|
|||||||
return body, err
|
return body, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) makeURL(path string) string {
|
func (c *Client) makeURL(path string) string {
|
||||||
return client.host + "/api/v1beta1/" + path
|
return c.host + "/api/v1beta1/" + path
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListPods takes a selector, and returns the list of pods that match that selector
|
// ListPods takes a selector, and returns the list of pods that match that selector
|
||||||
func (client *Client) ListPods(selector labels.Selector) (result api.PodList, err error) {
|
func (c *Client) ListPods(selector labels.Selector) (result api.PodList, err error) {
|
||||||
err = client.Get().Path("pods").Selector(selector).Do().Into(&result)
|
err = c.Get().Path("pods").Selector(selector).Do().Into(&result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPod takes the name of the pod, and returns the corresponding Pod object, and an error if it occurs
|
// GetPod takes the name of the pod, and returns the corresponding Pod object, and an error if it occurs
|
||||||
func (client *Client) GetPod(name string) (result api.Pod, err error) {
|
func (c *Client) GetPod(name string) (result api.Pod, err error) {
|
||||||
err = client.Get().Path("pods").Path(name).Do().Into(&result)
|
err = c.Get().Path("pods").Path(name).Do().Into(&result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletePod takes the name of the pod, and returns an error if one occurs
|
// DeletePod takes the name of the pod, and returns an error if one occurs
|
||||||
func (client *Client) DeletePod(name string) error {
|
func (c *Client) DeletePod(name string) error {
|
||||||
return client.Delete().Path("pods").Path(name).Do().Error()
|
return c.Delete().Path("pods").Path(name).Do().Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreatePod takes the representation of a pod. Returns the server's representation of the pod, and an error, if it occurs
|
// CreatePod takes the representation of a pod. Returns the server's representation of the pod, and an error, if it occurs
|
||||||
func (client *Client) CreatePod(pod api.Pod) (result api.Pod, err error) {
|
func (c *Client) CreatePod(pod api.Pod) (result api.Pod, err error) {
|
||||||
err = client.Post().Path("pods").Body(pod).Do().Into(&result)
|
err = c.Post().Path("pods").Body(pod).Do().Into(&result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdatePod takes the representation of a pod to update. Returns the server's representation of the pod, and an error, if it occurs
|
// UpdatePod takes the representation of a pod to update. Returns the server's representation of the pod, and an error, if it occurs
|
||||||
func (client *Client) UpdatePod(pod api.Pod) (result api.Pod, err error) {
|
func (c *Client) UpdatePod(pod api.Pod) (result api.Pod, err error) {
|
||||||
err = client.Put().Path("pods").Path(pod.ID).Body(pod).Do().Into(&result)
|
err = c.Put().Path("pods").Path(pod.ID).Body(pod).Do().Into(&result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetReplicationController returns information about a particular replication controller
|
// GetReplicationController returns information about a particular replication controller
|
||||||
func (client *Client) GetReplicationController(name string) (result api.ReplicationController, err error) {
|
func (c *Client) GetReplicationController(name string) (result api.ReplicationController, err error) {
|
||||||
err = client.Get().Path("replicationControllers").Path(name).Do().Into(&result)
|
err = c.Get().Path("replicationControllers").Path(name).Do().Into(&result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateReplicationController creates a new replication controller
|
// CreateReplicationController creates a new replication controller
|
||||||
func (client *Client) CreateReplicationController(controller api.ReplicationController) (result api.ReplicationController, err error) {
|
func (c *Client) CreateReplicationController(controller api.ReplicationController) (result api.ReplicationController, err error) {
|
||||||
err = client.Post().Path("replicationControllers").Body(controller).Do().Into(&result)
|
err = c.Post().Path("replicationControllers").Body(controller).Do().Into(&result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateReplicationController updates an existing replication controller
|
// UpdateReplicationController updates an existing replication controller
|
||||||
func (client *Client) UpdateReplicationController(controller api.ReplicationController) (result api.ReplicationController, err error) {
|
func (c *Client) UpdateReplicationController(controller api.ReplicationController) (result api.ReplicationController, err error) {
|
||||||
err = client.Put().Path("replicationControllers").Path(controller.ID).Body(controller).Do().Into(&result)
|
err = c.Put().Path("replicationControllers").Path(controller.ID).Body(controller).Do().Into(&result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) DeleteReplicationController(name string) error {
|
// DeleteReplicationController deletes an existing replication controller.
|
||||||
return client.Delete().Path("replicationControllers").Path(name).Do().Error()
|
func (c *Client) DeleteReplicationController(name string) error {
|
||||||
|
return c.Delete().Path("replicationControllers").Path(name).Do().Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetReplicationController returns information about a particular replication controller
|
// GetService returns information about a particular service.
|
||||||
func (client *Client) GetService(name string) (result api.Service, err error) {
|
func (c *Client) GetService(name string) (result api.Service, err error) {
|
||||||
err = client.Get().Path("services").Path(name).Do().Into(&result)
|
err = c.Get().Path("services").Path(name).Do().Into(&result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateReplicationController creates a new replication controller
|
// CreateService creates a new service.
|
||||||
func (client *Client) CreateService(svc api.Service) (result api.Service, err error) {
|
func (c *Client) CreateService(svc api.Service) (result api.Service, err error) {
|
||||||
err = client.Post().Path("services").Body(svc).Do().Into(&result)
|
err = c.Post().Path("services").Body(svc).Do().Into(&result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateReplicationController updates an existing replication controller
|
// UpdateService updates an existing service.
|
||||||
func (client *Client) UpdateService(svc api.Service) (result api.Service, err error) {
|
func (c *Client) UpdateService(svc api.Service) (result api.Service, err error) {
|
||||||
err = client.Put().Path("services").Path(svc.ID).Body(svc).Do().Into(&result)
|
err = c.Put().Path("services").Path(svc.ID).Body(svc).Do().Into(&result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) DeleteService(name string) error {
|
// DeleteService deletes an existing service.
|
||||||
return client.Delete().Path("services").Path(name).Do().Error()
|
func (c *Client) DeleteService(name string) error {
|
||||||
|
return c.Delete().Path("services").Path(name).Do().Error()
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ import (
|
|||||||
// TODO: Move this to a common place, it's needed in multiple tests.
|
// TODO: Move this to a common place, it's needed in multiple tests.
|
||||||
var apiPath = "/api/v1beta1"
|
var apiPath = "/api/v1beta1"
|
||||||
|
|
||||||
func makeUrl(suffix string) string {
|
func makeURL(suffix string) string {
|
||||||
return apiPath + suffix
|
return apiPath + suffix
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +326,7 @@ func (c *testClient) Validate(t *testing.T, received interface{}, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
requestBody := body(c.Request.Body, c.Request.RawBody)
|
requestBody := body(c.Request.Body, c.Request.RawBody)
|
||||||
c.handler.ValidateRequest(t, makeUrl(c.Request.Path), c.Request.Method, requestBody)
|
c.handler.ValidateRequest(t, makeURL(c.Request.Path), c.Request.Method, requestBody)
|
||||||
for key, values := range c.Request.Query {
|
for key, values := range c.Request.Query {
|
||||||
validator, ok := c.QueryValidator[key]
|
validator, ok := c.QueryValidator[key]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -35,12 +35,13 @@ type PodInfoGetter interface {
|
|||||||
GetPodInfo(host, podID string) (api.PodInfo, error)
|
GetPodInfo(host, podID string) (api.PodInfo, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default implementation, accesses the kubelet over HTTP
|
// HTTPPodInfoGetter is the default implementation of PodInfoGetter, accesses the kubelet over HTTP
|
||||||
type HTTPPodInfoGetter struct {
|
type HTTPPodInfoGetter struct {
|
||||||
Client *http.Client
|
Client *http.Client
|
||||||
Port uint
|
Port uint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPodInfo gets information about the specified pod.
|
||||||
func (c *HTTPPodInfoGetter) GetPodInfo(host, podID string) (api.PodInfo, error) {
|
func (c *HTTPPodInfoGetter) GetPodInfo(host, podID string) (api.PodInfo, error) {
|
||||||
request, err := http.NewRequest(
|
request, err := http.NewRequest(
|
||||||
"GET",
|
"GET",
|
||||||
@ -70,12 +71,13 @@ func (c *HTTPPodInfoGetter) GetPodInfo(host, podID string) (api.PodInfo, error)
|
|||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Useful for testing.
|
// FakePodInfoGetter is a fake implementation of PodInfoGetter. It is useful for testing.
|
||||||
type FakePodInfoGetter struct {
|
type FakePodInfoGetter struct {
|
||||||
data api.PodInfo
|
data api.PodInfo
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPodInfo is a fake implementation of PodInfoGetter.GetPodInfo.
|
||||||
func (c *FakePodInfoGetter) GetPodInfo(host, podID string) (api.PodInfo, error) {
|
func (c *FakePodInfoGetter) GetPodInfo(host, podID string) (api.PodInfo, error) {
|
||||||
return c.data, c.err
|
return c.data, c.err
|
||||||
}
|
}
|
||||||
|
@ -49,9 +49,9 @@ func TestHTTPPodInfoGetter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
testServer := httptest.NewServer(&fakeHandler)
|
testServer := httptest.NewServer(&fakeHandler)
|
||||||
|
|
||||||
hostUrl, err := url.Parse(testServer.URL)
|
hostURL, err := url.Parse(testServer.URL)
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
parts := strings.Split(hostUrl.Host, ":")
|
parts := strings.Split(hostURL.Host, ":")
|
||||||
|
|
||||||
port, err := strconv.Atoi(parts[1])
|
port, err := strconv.Atoi(parts[1])
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
|
@ -40,7 +40,7 @@ import (
|
|||||||
// Do()
|
// Do()
|
||||||
// list, ok := resp.(api.PodList)
|
// list, ok := resp.(api.PodList)
|
||||||
|
|
||||||
// Begin a request with a verb (GET, POST, PUT, DELETE)
|
// Verb begins a request with a verb (GET, POST, PUT, DELETE)
|
||||||
func (c *Client) Verb(verb string) *Request {
|
func (c *Client) Verb(verb string) *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
verb: verb,
|
verb: verb,
|
||||||
@ -52,29 +52,29 @@ func (c *Client) Verb(verb string) *Request {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin a POST request.
|
// Post begins a POST request.
|
||||||
func (c *Client) Post() *Request {
|
func (c *Client) Post() *Request {
|
||||||
return c.Verb("POST")
|
return c.Verb("POST")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin a PUT request.
|
// Put begins a PUT request.
|
||||||
func (c *Client) Put() *Request {
|
func (c *Client) Put() *Request {
|
||||||
return c.Verb("PUT")
|
return c.Verb("PUT")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin a GET request.
|
// Get begins a GET request.
|
||||||
func (c *Client) Get() *Request {
|
func (c *Client) Get() *Request {
|
||||||
return c.Verb("GET")
|
return c.Verb("GET")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin a DELETE request.
|
// Delete begins a DELETE request.
|
||||||
func (c *Client) Delete() *Request {
|
func (c *Client) Delete() *Request {
|
||||||
return c.Verb("DELETE")
|
return c.Verb("DELETE")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a request to do a single poll of the completion of the given operation.
|
// PollFor makes a request to do a single poll of the completion of the given operation.
|
||||||
func (c *Client) PollFor(operationId string) *Request {
|
func (c *Client) PollFor(operationID string) *Request {
|
||||||
return c.Get().Path("operations").Path(operationId).Sync(false).PollPeriod(0)
|
return c.Get().Path("operations").Path(operationID).Sync(false).PollPeriod(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request allows for building up a request to a server in a chained fashion.
|
// Request allows for building up a request to a server in a chained fashion.
|
||||||
@ -92,7 +92,7 @@ type Request struct {
|
|||||||
pollPeriod time.Duration
|
pollPeriod time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append an item to the request path. You must call Path at least once.
|
// Path appends an item to the request path. You must call Path at least once.
|
||||||
func (r *Request) Path(item string) *Request {
|
func (r *Request) Path(item string) *Request {
|
||||||
if r.err != nil {
|
if r.err != nil {
|
||||||
return r
|
return r
|
||||||
@ -101,7 +101,7 @@ func (r *Request) Path(item string) *Request {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set sync/async call status.
|
// Sync sets sync/async call status.
|
||||||
func (r *Request) Sync(sync bool) *Request {
|
func (r *Request) Sync(sync bool) *Request {
|
||||||
if r.err != nil {
|
if r.err != nil {
|
||||||
return r
|
return r
|
||||||
@ -110,7 +110,7 @@ func (r *Request) Sync(sync bool) *Request {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overwrite an existing path with the path parameter.
|
// AbsPath overwrites an existing path with the path parameter.
|
||||||
func (r *Request) AbsPath(path string) *Request {
|
func (r *Request) AbsPath(path string) *Request {
|
||||||
if r.err != nil {
|
if r.err != nil {
|
||||||
return r
|
return r
|
||||||
@ -119,7 +119,7 @@ func (r *Request) AbsPath(path string) *Request {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the given string as a resource label selector. Optional.
|
// ParseSelector parses the given string as a resource label selector. Optional.
|
||||||
func (r *Request) ParseSelector(item string) *Request {
|
func (r *Request) ParseSelector(item string) *Request {
|
||||||
if r.err != nil {
|
if r.err != nil {
|
||||||
return r
|
return r
|
||||||
@ -128,7 +128,7 @@ func (r *Request) ParseSelector(item string) *Request {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the given selector.
|
// Selector makes the request use the given selector.
|
||||||
func (r *Request) Selector(s labels.Selector) *Request {
|
func (r *Request) Selector(s labels.Selector) *Request {
|
||||||
if r.err != nil {
|
if r.err != nil {
|
||||||
return r
|
return r
|
||||||
@ -137,7 +137,7 @@ func (r *Request) Selector(s labels.Selector) *Request {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the given duration as a timeout. Optional.
|
// Timeout makes the request use the given duration as a timeout. Optional.
|
||||||
func (r *Request) Timeout(d time.Duration) *Request {
|
func (r *Request) Timeout(d time.Duration) *Request {
|
||||||
if r.err != nil {
|
if r.err != nil {
|
||||||
return r
|
return r
|
||||||
@ -146,7 +146,7 @@ func (r *Request) Timeout(d time.Duration) *Request {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use obj as the body of the request. Optional.
|
// Body makes the request use obj as the body. Optional.
|
||||||
// If obj is a string, try to read a file of that name.
|
// If obj is a string, try to read a file of that name.
|
||||||
// If obj is a []byte, send it directly.
|
// If obj is a []byte, send it directly.
|
||||||
// Otherwise, assume obj is an api type and marshall it correctly.
|
// Otherwise, assume obj is an api type and marshall it correctly.
|
||||||
@ -190,13 +190,13 @@ func (r *Request) PollPeriod(d time.Duration) *Request {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format and execute the request. Returns the API object received, or an error.
|
// Do formats and executes the request. Returns the API object received, or an error.
|
||||||
func (r *Request) Do() Result {
|
func (r *Request) Do() Result {
|
||||||
for {
|
for {
|
||||||
if r.err != nil {
|
if r.err != nil {
|
||||||
return Result{err: r.err}
|
return Result{err: r.err}
|
||||||
}
|
}
|
||||||
finalUrl := r.c.host + r.path
|
finalURL := r.c.host + r.path
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
if r.selector != nil {
|
if r.selector != nil {
|
||||||
query.Add("labels", r.selector.String())
|
query.Add("labels", r.selector.String())
|
||||||
@ -207,8 +207,8 @@ func (r *Request) Do() Result {
|
|||||||
query.Add("timeout", r.timeout.String())
|
query.Add("timeout", r.timeout.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finalUrl += "?" + query.Encode()
|
finalURL += "?" + query.Encode()
|
||||||
req, err := http.NewRequest(r.verb, finalUrl, r.body)
|
req, err := http.NewRequest(r.verb, finalURL, r.body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Result{err: err}
|
return Result{err: err}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user