本文整理汇总了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
}
示例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),
})
}
示例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),
})
}
示例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),
})
}
示例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))
}
示例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
}
示例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),
})
}
示例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"))
}
示例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))
}
示例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))
}
示例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))
}
示例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))
}
示例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,
})
}
示例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
}
示例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),
})
}