Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ spec:

### [Boost duration] fixed time

Define the fixed amount of time, the resource boost effect will last for it since the POD's creation.
Define the fixed amount of time, the resource boost effect will last for it since the
**POD's schedule time**.

```yaml
spec:
Expand Down
7 changes: 6 additions & 1 deletion internal/boost/duration/fixed.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,10 @@ func (p *FixedDurationPolicy) Duration() time.Duration {

func (p *FixedDurationPolicy) Valid(pod *v1.Pod) bool {
now := p.timeFunc()
return pod.CreationTimestamp.Add(p.duration).After(now)
for _, condition := range pod.Status.Conditions {
if condition.Type == v1.PodScheduled && condition.Status == v1.ConditionTrue {
return condition.LastTransitionTime.Add(p.duration).After(now)
}
}
return true
}
25 changes: 21 additions & 4 deletions internal/boost/duration/fixed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/google/kube-startup-cpu-boost/internal/boost/duration"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -39,17 +40,33 @@ var _ = Describe("FixedDurationPolicy", func() {
})

Describe("Validates POD", func() {
When("the POD has no status conditions", func() {
It("returns policy is valid", func() {
pod.Status.Conditions = []v1.PodCondition{}
Expect(policy.Valid(pod)).To(BeTrue())
})
})
When("the life time of a POD exceeds the policy duration", func() {
It("returns policy is not valid", func() {
creationTimesamp := now.Add(-1 * timeDuration).Add(-1 * time.Minute)
pod.CreationTimestamp = metav1.NewTime(creationTimesamp)
scheduleTime := now.Add(-1 * timeDuration).Add(-1 * time.Minute)
pod.Status.Conditions = []v1.PodCondition{
{
LastTransitionTime: metav1.NewTime(scheduleTime),
Type: v1.PodScheduled,
Status: v1.ConditionTrue,
}}
Expect(policy.Valid(pod)).To(BeFalse())
})
})
When("the life time of a POD is within policy duration", func() {
It("returns policy is valid", func() {
creationTimesamp := now.Add(-1 * timeDuration).Add(1 * time.Minute)
pod.CreationTimestamp = metav1.NewTime(creationTimesamp)
scheduleTime := now.Add(-1 * timeDuration).Add(1 * time.Minute)
pod.Status.Conditions = []v1.PodCondition{
{
LastTransitionTime: metav1.NewTime(scheduleTime),
Type: v1.PodScheduled,
Status: v1.ConditionTrue,
}}
Expect(policy.Valid(pod)).To(BeTrue())
})
})
Expand Down
9 changes: 7 additions & 2 deletions internal/boost/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,15 @@ var _ = Describe("Manager", func() {
durationSeconds = 60

pod = podTemplate.DeepCopy()
creationTimestamp := time.Now().
scheduledTimestamp := time.Now().
Add(-1 * time.Duration(durationSeconds) * time.Second).
Add(-1 * time.Minute)
pod.CreationTimestamp = metav1.NewTime(creationTimestamp)
pod.Status.Conditions = []corev1.PodCondition{
{
LastTransitionTime: metav1.NewTime(scheduledTimestamp),
Type: corev1.PodScheduled,
Status: corev1.ConditionTrue,
}}
mockClient = mock.NewMockClient(mockCtrl)
mockReconciler = mock.NewMockReconciler(mockCtrl)

Expand Down