當前位置: 首頁>>代碼示例>>Golang>>正文


Golang kubeclient.Get函數代碼示例

本文整理匯總了Golang中github.com/aclisp/kubecon/pkg/kubeclient.Get函數的典型用法代碼示例。如果您正苦於以下問題:Golang Get函數的具體用法?Golang Get怎麽用?Golang Get使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Get函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: syncPod

func syncPod(namespace string, podname string) error {
	pod, err := kubeclient.Get().Pods(namespace).Get(podname)
	if err != nil {
		return err
	}
	rcname, ok := pod.Labels["managed-by"]
	if !ok {
		return fmt.Errorf("Need a `managed-by` label")
	}
	rc, err := kubeclient.Get().ReplicationControllers(namespace).Get(rcname)
	if err != nil {
		return err
	}
	nodeName := pod.Spec.NodeName
	pod.Spec = rc.Spec.Template.Spec
	pod.Spec.NodeName = nodeName
	if pod.Annotations == nil {
		pod.Annotations = make(map[string]string)
	}
	pod.Annotations["copied-from"] = rcname
	for k, v := range rc.Spec.Template.Annotations {
		if strings.HasPrefix(k, "config/") {
			pod.Annotations[k] = v
		}
	}
	_, err = kubeclient.Get().Pods(namespace).Update(pod)
	return err
}
開發者ID:aclisp,項目名稱:kubecon,代碼行數:28,代碼來源:main.go

示例2: editEndpoints

func editEndpoints(c *gin.Context) {
	namespace := c.Param("ns")
	epname := c.Param("ep")
	_, delete := c.GetQuery("delete")

	ep, err := kubeclient.Get().Endpoints(namespace).Get(epname)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	b, err := json.Marshal(ep)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	var out bytes.Buffer
	err = json.Indent(&out, b, "", "  ")
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.HTML(http.StatusOK, "endpointsEdit", gin.H{
		"title":     epname,
		"namespace": namespace,
		"objname":   epname,
		"json":      out.String(),
		"delete":    strconv.FormatBool(delete),
	})
}
開發者ID:aclisp,項目名稱:kubecon,代碼行數:32,代碼來源:main.go

示例3: editReplicationController

func editReplicationController(c *gin.Context) {
	namespace := c.Param("ns")
	rcname := c.Param("rc")
	_, delete := c.GetQuery("delete")

	rc, err := kubeclient.Get().ReplicationControllers(namespace).Get(rcname)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	b, err := json.Marshal(rc)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	var out bytes.Buffer
	err = json.Indent(&out, b, "", "  ")
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.HTML(http.StatusOK, "replicationControllerEdit", gin.H{
		"title":     rcname,
		"namespace": namespace,
		"objname":   rcname,
		"json":      out.String(),
		"delete":    strconv.FormatBool(delete),
	})
}
開發者ID:aclisp,項目名稱:kubecon,代碼行數:32,代碼來源:main.go

示例4: editNode

func editNode(c *gin.Context) {
	nodename := c.Param("no")
	_, delete := c.GetQuery("delete")

	node, err := kubeclient.Get().Nodes().Get(nodename)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	b, err := json.Marshal(node)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	var out bytes.Buffer
	err = json.Indent(&out, b, "", "  ")
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.HTML(http.StatusOK, "nodeEdit", gin.H{
		"title":   nodename,
		"objname": nodename,
		"json":    out.String(),
		"delete":  strconv.FormatBool(delete),
	})
}
開發者ID:aclisp,項目名稱:kubecon,代碼行數:30,代碼來源:main.go

示例5: updateReplicationControllerWithPod

func updateReplicationControllerWithPod(c *gin.Context) {
	namespace := c.Param("ns")
	podname := c.Param("po")
	podjson := c.PostForm("json")

	var pod api.Pod
	err := json.Unmarshal([]byte(podjson), &pod)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}
	rcname, ok := pod.Labels["managed-by"]
	if !ok {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": "Need a `managed-by` label"})
		return
	}
	rc, err := kubeclient.Get().ReplicationControllers(namespace).Get(rcname)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}
	nodeName := rc.Spec.Template.Spec.NodeName
	rc.Spec.Template.Spec = pod.Spec
	rc.Spec.Template.Spec.NodeName = nodeName
	if rc.Annotations == nil {
		rc.Annotations = make(map[string]string)
	}
	rc.Annotations["copied-from"] = podname
	if rc.Spec.Template.Annotations == nil {
		rc.Spec.Template.Annotations = make(map[string]string)
	}
	for k, v := range pod.Annotations {
		if strings.HasPrefix(k, "config/") {
			rc.Spec.Template.Annotations[k] = v
		}
	}
	_, err = kubeclient.Get().ReplicationControllers(namespace).Update(rc)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/namespaces/%s/pods/%s/edit", namespace, podname))
}
開發者ID:aclisp,項目名稱:kubecon,代碼行數:44,代碼來源:main.go

示例6: setPodImage

func setPodImage(namespace string, podname string, fullImages []string) error {
	pod, err := kubeclient.Get().Pods(namespace).Get(podname)
	if err != nil {
		return err
	}

	for i, image := range fullImages {
		if image == "" {
			continue
		}
		glog.Infof("Set image of '%s/%s/%d': %s -> %s", namespace, podname, i, pod.Spec.Containers[i].Image, image)
		pod.Spec.Containers[i].Image = image
	}
	_, err = kubeclient.Get().Pods(namespace).Update(pod)
	if err != nil {
		return err
	}
	return nil
}
開發者ID:aclisp,項目名稱:kubecon,代碼行數:19,代碼來源:main.go

示例7: listOthersInNamespace

func listOthersInNamespace(c *gin.Context) {
	namespace := c.Param("ns")

	user := c.MustGet(gin.AuthUserKey).(string)
	if user != "admin" && user != namespace {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": "Unauthorized"})
		return
	}

	rcList, err := kubeclient.Get().ReplicationControllers(namespace).List(labels.Everything())
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}
	svcList, err := kubeclient.Get().Services(namespace).List(labels.Everything())
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}
	epList, err := kubeclient.Get().Endpoints(namespace).List(labels.Everything())
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}
	nodeList, err := kubeclient.Get().Nodes().List(labels.SelectorFromSet(labels.Set{
		"project": namespace,
	}), fields.Everything())
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.HTML(http.StatusOK, "nsInfo", gin.H{
		"refresh": 60,
		"title":   namespace,
		"ns":      namespace,
		"rcs":     genReplicationControllers(rcList),
		"svcs":    genServices(svcList),
		"eps":     genEndpoints(epList),
		"nodes":   genNodes(nodeList),
	})
}
開發者ID:aclisp,項目名稱:kubecon,代碼行數:42,代碼來源:main.go

示例8: deleteNode

func deleteNode(c *gin.Context) {
	nodename := c.Param("no")

	err := kubeclient.Get().Nodes().Delete(nodename)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/nodes"))
}
開發者ID:aclisp,項目名稱:kubecon,代碼行數:11,代碼來源:main.go

示例9: deleteReplicationController

func deleteReplicationController(c *gin.Context) {
	namespace := c.Param("ns")
	rcname := c.Param("rc")

	rc, err := kubeclient.Get().ReplicationControllers(namespace).Get(rcname)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}
	if rc.Spec.Replicas > 0 || rc.Status.Replicas > 0 {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": "Replicas must be 0"})
		return
	}
	err = kubeclient.Get().ReplicationControllers(namespace).Delete(rcname)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/namespaces/%s", namespace))
}
開發者ID:aclisp,項目名稱:kubecon,代碼行數:21,代碼來源:main.go

示例10: deleteEndpoints

func deleteEndpoints(c *gin.Context) {
	namespace := c.Param("ns")
	epname := c.Param("ep")

	err := kubeclient.Get().Endpoints(namespace).Delete(epname)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/namespaces/%s", namespace))
}
開發者ID:aclisp,項目名稱:kubecon,代碼行數:12,代碼來源:main.go

示例11: updateNode

func updateNode(c *gin.Context) {
	nodename := c.Param("no")
	nodejson := c.PostForm("json")

	var node api.Node
	err := json.Unmarshal([]byte(nodejson), &node)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	r, _ := kubeclient.Get().Nodes().Get(node.Name)
	node.ResourceVersion = r.ResourceVersion
	_, err = kubeclient.Get().Nodes().Update(&node)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/nodes/%s/edit", nodename))
}
開發者ID:aclisp,項目名稱:kubecon,代碼行數:21,代碼來源:main.go

示例12: updatePod

func updatePod(c *gin.Context) {
	namespace := c.Param("ns")
	podname := c.Param("po")
	podjson := c.PostForm("json")

	var pod api.Pod
	err := json.Unmarshal([]byte(podjson), &pod)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	r, _ := kubeclient.Get().Pods(namespace).Get(pod.Name)
	pod.ResourceVersion = r.ResourceVersion
	_, err = kubeclient.Get().Pods(namespace).Update(&pod)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/namespaces/%s/pods/%s/edit", namespace, podname))
}
開發者ID:aclisp,項目名稱:kubecon,代碼行數:22,代碼來源:main.go

示例13: overview

func overview(c *gin.Context) {
	namespaces, err := kubeclient.Get().Namespaces().List(labels.Everything(), fields.Everything())
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}
	summary := page.Summary{}
	for i := range namespaces.Items {
		namespace := namespaces.Items[i].Name
		podList, err := kubeclient.Get().Pods(namespace).List(labels.Everything(), fields.Everything())
		if err != nil {
			glog.Errorf("Can not get pods in namespace '%s': %v", namespace, err)
			continue
		}
		eventList, err := kubeclient.Get().Events(namespace).List(labels.Everything(), fields.Everything())
		if err != nil {
			glog.Errorf("Can not get events in namespace '%s': %v", namespace, err)
			eventList = &api.EventList{}
		}
		summary.Namespaces = append(summary.Namespaces, page.Namespace{
			Name:       namespace,
			PodCount:   len(podList.Items),
			EventCount: len(eventList.Items),
		})
	}
	nodeList, err := kubeclient.Get().Nodes().List(labels.Everything(), fields.Everything())
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}
	summary.NodeCount = len(nodeList.Items)

	c.HTML(http.StatusOK, "overview", gin.H{
		"title":   "Sigma Overview",
		"summary": summary,
	})
}
開發者ID:aclisp,項目名稱:kubecon,代碼行數:37,代碼來源:main.go

示例14: startPod

func startPod(namespace string, podname string, checks []bool) error {
	pod, err := kubeclient.Get().Pods(namespace).Get(podname)
	if err != nil {
		return err
	}

	for i, check := range checks {
		if pod.Spec.Containers[i].Image != PauseImage {
			// Already started.
			continue
		}
		if check {
			paused := fmt.Sprintf("paused%d", i)
			pod.Spec.Containers[i].Image = pod.Annotations[paused]
			delete(pod.Annotations, paused)
		}
	}

	_, err = kubeclient.Get().Pods(namespace).Update(pod)
	if err != nil {
		return err
	}
	return nil
}
開發者ID:aclisp,項目名稱:kubecon,代碼行數:24,代碼來源:main.go

示例15: listNodes

func listNodes(c *gin.Context) {
	if c.MustGet(gin.AuthUserKey).(string) != "admin" {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": "Unauthorized"})
		return
	}

	list, err := kubeclient.Get().Nodes().List(labels.Everything(), fields.Everything())
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.HTML(http.StatusOK, "nodeList", gin.H{
		"title": "Sigma Nodes",
		"nodes": genNodes(list),
	})
}
開發者ID:aclisp,項目名稱:kubecon,代碼行數:17,代碼來源:main.go


注:本文中的github.com/aclisp/kubecon/pkg/kubeclient.Get函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。