mirror of https://github.com/k3s-io/k3s
Merge pull request #52899 from wackxu/re9221
Automatic merge from submit-queue (batch tested with PRs 50685, 53050, 52899, 52913, 53067). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Use patch to avoid overwriting potential pending status updates **What this PR does / why we need it**: Fix TODO(bsalamat): change this to patch PodStatus to avoid overwriting potential pending status updates. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Release note**: ```release-note NONE ```pull/6/head
commit
a4b7ab7818
|
@ -29,6 +29,7 @@ go_library(
|
|||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/fields:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
@ -52,6 +53,7 @@ import (
|
|||
"k8s.io/kubernetes/plugin/pkg/scheduler/schedulercache"
|
||||
"k8s.io/kubernetes/plugin/pkg/scheduler/util"
|
||||
|
||||
"encoding/json"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
|
@ -1001,7 +1003,6 @@ func (p *podPreemptor) DeletePod(pod *v1.Pod) error {
|
|||
return p.Client.CoreV1().Pods(pod.Namespace).Delete(pod.Name, &metav1.DeleteOptions{})
|
||||
}
|
||||
|
||||
//TODO(bsalamat): change this to patch PodStatus to avoid overwriting potential pending status updates.
|
||||
func (p *podPreemptor) UpdatePodAnnotations(pod *v1.Pod, annotations map[string]string) error {
|
||||
podCopy := pod.DeepCopy()
|
||||
if podCopy.Annotations == nil {
|
||||
|
@ -1010,6 +1011,12 @@ func (p *podPreemptor) UpdatePodAnnotations(pod *v1.Pod, annotations map[string]
|
|||
for k, v := range annotations {
|
||||
podCopy.Annotations[k] = v
|
||||
}
|
||||
_, err := p.Client.CoreV1().Pods(podCopy.Namespace).UpdateStatus(podCopy)
|
||||
return err
|
||||
ret := &unstructured.Unstructured{}
|
||||
ret.SetAnnotations(podCopy.Annotations)
|
||||
patchData, err := json.Marshal(ret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, error := p.Client.CoreV1().Pods(podCopy.Namespace).Patch(podCopy.Name, types.MergePatchType, patchData)
|
||||
return error
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue