-
Notifications
You must be signed in to change notification settings - Fork 1.8k
action: add update #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
action: add update #132
Conversation
Test cases for Update: func main() {
samplePod := getSamplePod("Pod", "v1", "test-pod", "default")
fmt.Printf("Pod template: \n%s\n\n", getFormattedJSON(samplePod))
// Update non-existent pod
logrus.Infof("Test case 1: Update a non-existent pod")
pod := samplePod
// Create pod
err := action.Update(pod)
if err != nil {
logrus.Error(err)
} else {
logrus.Errorf("Updated non-existent pod")
fmt.Printf("Updated Pod: \n%s\n\n", getFormattedJSON(pod))
}
// Update pod with correct resource version
logrus.Infof("Test case 2: Update a pod with correct resource version")
pod = samplePod
err = action.Create(pod)
if err != nil {
logrus.Errorf("Failed to create pod")
logrus.Fatal(err)
} else {
fmt.Printf("Created Pod: \n%s\n\n", getFormattedJSON(pod))
}
// Wait until pod is created and stops changing resource version
time.Sleep(time.Second * 10)
// Get the pod
err = query.Get(pod)
if err != nil {
logrus.Errorf("Failed to get pod")
logrus.Fatal(err)
} else {
fmt.Printf("Got Pod: \n%s\n\n", getFormattedJSON(pod))
}
// Update the pod's label
ls := map[string]string{"app": "v1"}
pod.ObjectMeta.Labels = ls
err = action.Update(pod)
if err != nil {
logrus.Errorf("Failed to update pod's labels with correct resource version(%v)", pod.ResourceVersion)
logrus.Fatal(err)
} else {
fmt.Printf("Updated Pod: \n%s\n\n", getFormattedJSON(pod))
}
// Update again with incorrect resource version
logrus.Infof("Test case 3: Update with incorrect resource version")
ls = map[string]string{"app": "v2"}
pod.ObjectMeta.Labels = ls
pod.ObjectMeta.ResourceVersion = "1"
err = action.Update(pod)
if err != nil {
logrus.Errorf("Failed to update pod's labels with incorrect resource version(%v)", pod.ResourceVersion)
logrus.Error(err)
} else {
logrus.Errorf("Updated pod with incorrect resource version")
fmt.Printf("Updated Pod: \n%s\n\n", getFormattedJSON(pod))
}
} Test logs:
|
@fanminshi PTAL. |
do you know why the created pod's |
Yes so depending on the object it can be updated by other components like the scheduler. So when the pod was first created it's |
@hasbro17 thanks for the clarification. |
Added action for update.