本文整理汇总了Golang中k8s/io/kubernetes/pkg/client/unversioned.Client.Post方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Post方法的具体用法?Golang Client.Post怎么用?Golang Client.Post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类k8s/io/kubernetes/pkg/client/unversioned.Client
的用法示例。
在下文中一共展示了Client.Post方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: processResource
func processResource(c *k8sclient.Client, b []byte, ns string, kind string) error {
util.Infof("Processing resource kind: %s in namespace %s\n", kind, ns)
req := c.Post().Body(b)
if kind == "Deployment" {
req.AbsPath("apis", "extensions/v1beta1", "namespaces", ns, strings.ToLower(kind+"s"))
} else if kind == "BuildConfig" || kind == "DeploymentConfig" || kind == "Template" || kind == "PolicyBinding" || kind == "Role" || kind == "RoleBinding" {
req.AbsPath("oapi", "v1", "namespaces", ns, strings.ToLower(kind+"s"))
} else if kind == "OAuthClient" || kind == "Project" || kind == "ProjectRequest" {
req.AbsPath("oapi", "v1", strings.ToLower(kind+"s"))
} else if kind == "Namespace" {
req.AbsPath("api", "v1", "namespaces")
} else {
req.Namespace(ns).Resource(strings.ToLower(kind + "s"))
}
res := req.Do()
if res.Error() != nil {
err := res.Error()
if err != nil {
util.Warnf("Failed to create %s: %v", kind, err)
return err
}
}
var statusCode int
res.StatusCode(&statusCode)
if statusCode != http.StatusCreated {
return fmt.Errorf("Failed to create %s: %d", kind, statusCode)
}
return nil
}
示例2: getContainerInfo
// getContainerInfo contacts kubelet for the container information. The "Stats"
// in the returned ContainerInfo is subject to the requirements in statsRequest.
func getContainerInfo(c *client.Client, nodeName string, req *stats.StatsRequest) (map[string]cadvisorapi.ContainerInfo, error) {
reqBody, err := json.Marshal(req)
if err != nil {
return nil, err
}
subResourceProxyAvailable, err := serverVersionGTE(subResourceServiceAndNodeProxyVersion, c)
if err != nil {
return nil, err
}
var data []byte
if subResourceProxyAvailable {
data, err = c.Post().
Resource("nodes").
SubResource("proxy").
Name(fmt.Sprintf("%v:%v", nodeName, ports.KubeletPort)).
Suffix("stats/container").
SetHeader("Content-Type", "application/json").
Body(reqBody).
Do().Raw()
} else {
data, err = c.Post().
Prefix("proxy").
Resource("nodes").
Name(fmt.Sprintf("%v:%v", nodeName, ports.KubeletPort)).
Suffix("stats/container").
SetHeader("Content-Type", "application/json").
Body(reqBody).
Do().Raw()
}
if err != nil {
return nil, err
}
var containers map[string]cadvisorapi.ContainerInfo
err = json.Unmarshal(data, &containers)
if err != nil {
return nil, err
}
return containers, nil
}
示例3: processResource
func processResource(c *k8sclient.Client, b []byte, ns string, kind string) error {
req := c.Post().Body(b)
if kind != "OAuthClient" {
req.Namespace(ns).Resource(strings.ToLower(kind + "s"))
} else {
req.AbsPath("oapi", "v1", strings.ToLower(kind+"s"))
}
res := req.Do()
if res.Error() != nil {
err := res.Error()
if err != nil {
return err
}
}
var statusCode int
res.StatusCode(&statusCode)
if statusCode != http.StatusCreated {
return fmt.Errorf("Failed to create %s: %d", kind, statusCode)
}
return nil
}
示例4: getContainerInfo
// getContainerInfo contacts kubelet for the container information. The "Stats"
// in the returned ContainerInfo is subject to the requirements in statsRequest.
func getContainerInfo(c *client.Client, nodeName string, req *kubelet.StatsRequest) (map[string]cadvisorapi.ContainerInfo, error) {
reqBody, err := json.Marshal(req)
if err != nil {
return nil, err
}
data, err := c.Post().
Prefix("proxy").
Resource("nodes").
Name(fmt.Sprintf("%v:%v", nodeName, ports.KubeletPort)).
Suffix("stats/container").
SetHeader("Content-Type", "application/json").
Body(reqBody).
Do().Raw()
var containers map[string]cadvisorapi.ContainerInfo
err = json.Unmarshal(data, &containers)
if err != nil {
return nil, err
}
return containers, nil
}
示例5:
Output string `json:"output"`
Error string `json:"error"`
}
var uploadConfigOutput NetexecOutput
// Upload the kubeconfig file
By("uploading kubeconfig to netexec")
pipeConfigReader, postConfigBodyWriter, err := newStreamingUpload(kubeConfigFilePath)
if err != nil {
Failf("unable to create streaming upload. Error: %s", err)
}
resp, err := c.Post().
Namespace(ns).
Name("netexec").
Resource("pods").
SubResource("proxy").
Suffix("upload").
SetHeader("Content-Type", postConfigBodyWriter.FormDataContentType()).
Body(pipeConfigReader).
Do().Raw()
if err != nil {
Failf("Unable to upload kubeconfig to the remote exec server due to error: %s", err)
}
if err := json.Unmarshal(resp, &uploadConfigOutput); err != nil {
Failf("Unable to read the result from the netexec server. Error: %s", err)
}
kubecConfigRemotePath := uploadConfigOutput.Output
// Upload
pipeReader, postBodyWriter, err := newStreamingUpload(testStaticKubectlPath)