Skip to content

Commit

Permalink
fix: fix pv no node affinity
Browse files Browse the repository at this point in the history
Signed-off-by: renxiangyu_yewu <[email protected]>
(cherry picked from commit 7f35848)
  • Loading branch information
renxiangyu_yewu committed Jan 6, 2025
1 parent f9f77f7 commit 52e80e3
Showing 1 changed file with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,13 @@ func (pl *VolumeBinding) Filter(_ context.Context, cs *framework.CycleState, pod
}
} else {
// the node is real node
podVolumes, reasons, err = pl.Binder.FindPodVolumes(pod, state.boundClaims, state.claimsToBind, node)
if hasKosmosOwnerPVC(state) {
// the pod is bound to kosmos node
// in order to avoid where pv has no node affinity
reasons = append(reasons, scheduling.ErrReasonNodeConflict)
} else {
podVolumes, reasons, err = pl.Binder.FindPodVolumes(pod, state.boundClaims, state.claimsToBind, node)
}
}

if err != nil {
Expand All @@ -268,6 +274,33 @@ func (pl *VolumeBinding) Filter(_ context.Context, cs *framework.CycleState, pod
return nil
}

func hasKosmosOwnerPVC(state *stateData) bool {
isKosmosOwnerPVC := false

if len(state.boundClaims) > 0 {
for _, claim := range state.boundClaims {
if pvcHasKosmosAnnotations(claim) {
isKosmosOwnerPVC = true
break
}
}
}
if len(state.claimsToBind) > 0 {
for _, claim := range state.claimsToBind {
if pvcHasKosmosAnnotations(claim) {
isKosmosOwnerPVC = true
break
}
}
}
return isKosmosOwnerPVC
}

func pvcHasKosmosAnnotations(claim *corev1.PersistentVolumeClaim) bool {
_, ok := claim.Annotations[utils.KosmosResourceOwnersAnnotations]
return ok
}

// FindPodKosmosVolumes finds the matching PVs for PVCs and kosmos nodes to provision PVs
// for the given pod and node. If the kosmos node does not fit, confilict reasons are
// returned.
Expand Down

0 comments on commit 52e80e3

Please sign in to comment.