Skip to content

Commit

Permalink
Merge pull request #84 from kkkkun/fix-virtualk8s-update-pod
Browse files Browse the repository at this point in the history
tripped ignore labels before update pod
  • Loading branch information
cwdsuzhou committed Aug 3, 2022
2 parents 162fbf2 + 3f0e0b5 commit 2cc1d68
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion pkg/provider/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ func (v *VirtualK8S) UpdatePod(ctx context.Context, pod *corev1.Pod) error {
klog.Info("Pod is not created by vk, ignore")
return nil
}

//tripped ignore labels which recoverd in currentPod
util.TrimLabels(currentPod.ObjectMeta.Labels, v.ignoreLabels)
podCopy := currentPod.DeepCopy()
// util.GetUpdatedPod update PodCopy container image, annotations, labels.
// recover toleration, affinity, tripped ignore labels.
util.GetUpdatedPod(podCopy, pod, v.ignoreLabels)
if reflect.DeepEqual(currentPod.Spec, podCopy.Spec) &&
reflect.DeepEqual(currentPod.Annotations, podCopy.Annotations) &&
Expand Down
8 changes: 4 additions & 4 deletions pkg/util/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TrimPod(pod *corev1.Pod, ignoreLabels []string) *corev1.Pod {
podCopy.Spec.NodeName = ""
podCopy.Status = corev1.PodStatus{}
// remove labels should be removed, which would influence schedule in client cluster
tripped := trimLabels(podCopy.ObjectMeta.Labels, ignoreLabels)
tripped := TrimLabels(podCopy.ObjectMeta.Labels, ignoreLabels)
if tripped != nil {
trippedStr, err := json.Marshal(tripped)
if err != nil {
Expand Down Expand Up @@ -106,7 +106,7 @@ func GetUpdatedPod(orig, update *corev1.Pod, ignoreLabels []string) {
orig.Annotations = update.Annotations
orig.Spec.ActiveDeadlineSeconds = update.Spec.ActiveDeadlineSeconds
if orig.Labels != nil {
trimLabels(orig.ObjectMeta.Labels, ignoreLabels)
TrimLabels(orig.ObjectMeta.Labels, ignoreLabels)
}
return
}
Expand Down Expand Up @@ -174,8 +174,8 @@ func recoverSelectors(pod *corev1.Pod, cns *ClustersNodeSelection) {
}
}

// trimLabels removes label from labels according to ignoreLabels
func trimLabels(labels map[string]string, ignoreLabels []string) map[string]string {
// TrimLabels removes label from labels according to ignoreLabels
func TrimLabels(labels map[string]string, ignoreLabels []string) map[string]string {
if ignoreLabels == nil {
return nil
}
Expand Down

0 comments on commit 2cc1d68

Please sign in to comment.