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 }
// 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 }
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 }
// 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 }
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)