Skip to content

Commit

Permalink
Merge pull request #79 from TheBeatles1994/patch-pods
Browse files Browse the repository at this point in the history
support adding custom PatchPods functions
  • Loading branch information
TheBeatles1994 authored Jul 23, 2022
2 parents 05eb69c + 61a90e8 commit 5f30a0a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
1 change: 0 additions & 1 deletion changelogs/unreleased/feature/76

This file was deleted.

1 change: 1 addition & 0 deletions changelogs/unreleased/feature/79
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
support adding custom PatchPods functions
21 changes: 9 additions & 12 deletions pkg/simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Simulator struct {
cancelFunc context.CancelFunc

writeToFile bool
patchPodFuncMap PatchPodFuncMap
patchPodFuncMap PatchPodsFuncMap

status status
}
Expand All @@ -55,16 +55,16 @@ type status struct {
stopReason string
}

type PatchPodFunc = func(pod *corev1.Pod, client externalclientset.Interface) error
type PatchPodFunc = func(pods []*corev1.Pod, client externalclientset.Interface) error

type PatchPodFuncMap map[string]PatchPodFunc
type PatchPodsFuncMap map[string]PatchPodFunc

type simulatorOptions struct {
kubeconfig string
schedulerConfig string
writeToFile bool
extraRegistry frameworkruntime.Registry
patchPodFuncMap PatchPodFuncMap
patchPodFuncMap PatchPodsFuncMap
}

// Option configures a Simulator
Expand Down Expand Up @@ -203,13 +203,10 @@ func (sim *Simulator) ScheduleApp(app AppResource) (*SimulateResult, error) {
tolerationPriority := algo.NewTolerationQueue(appPods)
sort.Sort(tolerationPriority)

for i, pod := range appPods {
for _, patchPod := range sim.patchPodFuncMap {
if err := patchPod(pod, sim.kubeclient); err != nil {
return nil, err
}
for _, patchPods := range sim.patchPodFuncMap {
if err := patchPods(appPods, sim.kubeclient); err != nil {
return nil, err
}
appPods[i] = pod
}

failedPod, err := sim.schedulePods(appPods)
Expand Down Expand Up @@ -427,9 +424,9 @@ func WithExtraRegistry(extraRegistry frameworkruntime.Registry) Option {
}
}

func WithPatchPodFuncMap(patchPodFuncMap PatchPodFuncMap) Option {
func WithPatchPodsFuncMap(patchPodsFuncMap PatchPodsFuncMap) Option {
return func(o *simulatorOptions) {
o.patchPodFuncMap = patchPodFuncMap
o.patchPodFuncMap = patchPodsFuncMap
}
}

Expand Down

0 comments on commit 5f30a0a

Please sign in to comment.