• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang kubeclient.Get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/aclisp/kubecon/pkg/kubeclient.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: createService

func createService(c *gin.Context) {
	namespace := c.Param("ns")
	svcjson := c.PostForm("json")

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

	_, err = kubeclient.Get().Services(namespace).Create(&svc)
	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,代码行数:19,代码来源:main.go


示例17: listEventsInNamespace

func listEventsInNamespace(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
	}

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

	c.HTML(http.StatusOK, "eventList", gin.H{
		"title":  "Sigma Events",
		"events": genEvents(list),
	})
}
开发者ID:aclisp,项目名称:kubecon,代码行数:20,代码来源:main.go


示例18: updateEndpoints

func updateEndpoints(c *gin.Context) {
	namespace := c.Param("ns")
	epname := c.Param("ep")
	epjson := c.PostForm("json")

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

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

	c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/namespaces/%s/endpoints/%s/edit", namespace, epname))
}
开发者ID:aclisp,项目名称:kubecon,代码行数:20,代码来源:main.go


示例19: updateReplicationController

func updateReplicationController(c *gin.Context) {
	namespace := c.Param("ns")
	rcname := c.Param("rc")
	rcjson := c.PostForm("json")

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

	_, 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/replicationcontrollers/%s/edit", namespace, rcname))
}
开发者ID:aclisp,项目名称:kubecon,代码行数:20,代码来源:main.go


示例20: createReplicationController

func createReplicationController(c *gin.Context) {
	namespace := c.Param("ns")
	rcjson := c.PostForm("json")

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

	if rc.Spec.Selector == nil {
		rc.Spec.Selector = make(map[string]string)
	}
	rc.Spec.Selector["managed-by"] = rc.Name
	if rc.Spec.Template.Labels == nil {
		rc.Spec.Template.Labels = make(map[string]string)
	}
	rc.Spec.Template.Labels["managed-by"] = rc.Name
	rc.Spec.Template.Spec.Containers[0].Name = rc.Name

	var meta api.ObjectMeta // clean metadata
	meta.Name = rc.Name
	meta.GenerateName = rc.GenerateName
	meta.Labels = rc.Labels
	meta.Annotations = rc.Annotations
	if meta.Labels != nil {
		meta.Labels["managed-by"] = rc.Name
	}
	rc.ObjectMeta = meta

	_, err = kubeclient.Get().ReplicationControllers(namespace).Create(&rc)
	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,代码行数:39,代码来源:main.go



注:本文中的github.com/aclisp/kubecon/pkg/kubeclient.Get函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang webm.IdToName函数代码示例发布时间:2022-05-24
下一篇:
Golang asink.Event类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap