func updatePod(t *testing.T, s storage.Interface, obj, old *api.Pod) *api.Pod { key := etcdtest.AddPrefix("pods/ns/" + obj.Name) result := &api.Pod{} if old == nil { if err := s.Create(context.TODO(), key, obj, result, 0); err != nil { t.Errorf("unexpected error: %v", err) } } else { // To force "update" behavior of Set() we need to set ResourceVersion of // previous version of object. obj.ResourceVersion = old.ResourceVersion if err := s.Set(context.TODO(), key, obj, result, 0); err != nil { t.Errorf("unexpected error: %v", err) } obj.ResourceVersion = "" } return result }
func updatePod(t *testing.T, s storage.Interface, obj, old *api.Pod) *api.Pod { updateFn := func(input runtime.Object, res storage.ResponseMeta) (runtime.Object, *uint64, error) { newObj, err := api.Scheme.DeepCopy(obj) if err != nil { t.Errorf("unexpected error: %v", err) return nil, nil, err } return newObj.(*api.Pod), nil, nil } key := etcdtest.AddPrefix("pods/ns/" + obj.Name) if err := s.GuaranteedUpdate(context.TODO(), key, &api.Pod{}, old == nil, nil, updateFn); err != nil { t.Errorf("unexpected error: %v", err) } obj.ResourceVersion = "" result := &api.Pod{} if err := s.Get(context.TODO(), key, result, false); err != nil { t.Errorf("unexpected error: %v", err) } return result }
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)) }