Skip to content

Commit

Permalink
Merge pull request #215 from lianghao208/timeduration
Browse files Browse the repository at this point in the history
Units as part of the field name for the duration field
  • Loading branch information
k8s-ci-robot authored Jan 13, 2023
2 parents a31d02d + 01d2ad8 commit 840110b
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 51 deletions.
16 changes: 8 additions & 8 deletions pkg/apis/internalversion/stage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ type StageResourceRef struct {

// StageDelay describes the delay time before going to next.
type StageDelay struct {
// Duration indicates the stage delay time.
// If JitterDuration is less than Duration, then JitterDuration is used.
Duration metav1.Duration
// DurationMilliseconds indicates the stage delay time.
// If JitterDurationMilliseconds is less than DurationMilliseconds, then JitterDurationMilliseconds is used.
DurationMilliseconds *int64
// DurationFrom is the expression used to get the value.
// If it is a time.Time type, getting the value will be minus time.Now() to get Duration
// If it is a time.Time type, getting the value will be minus time.Now() to get DurationMilliseconds
// If it is a string type, the value get will be parsed by time.ParseDuration.
DurationFrom *ExpressionFromSource

// JitterDuration is the duration plus an additional amount chosen uniformly
// at random from the interval between Duration and JitterDuration.
JitterDuration *metav1.Duration
// JitterDurationMilliseconds is the duration plus an additional amount chosen uniformly
// at random from the interval between DurationMilliseconds and JitterDurationMilliseconds.
JitterDurationMilliseconds *int64
// JitterDurationFrom is the expression used to get the value.
// If it is a time.Time type, getting the value will be minus time.Now() to get JitterDuration
// If it is a time.Time type, getting the value will be minus time.Now() to get JitterDurationMilliseconds
// If it is a string type, the value get will be parsed by time.ParseDuration.
JitterDurationFrom *ExpressionFromSource
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/internalversion/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions pkg/apis/internalversion/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions pkg/apis/v1alpha1/stage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ type StageResourceRef struct {

// StageDelay describes the delay time before going to next.
type StageDelay struct {
// Duration indicates the stage delay time.
// If JitterDuration is less than Duration, then JitterDuration is used.
Duration metav1.Duration `json:"duration"`
// DurationMilliseconds indicates the stage delay time.
// If JitterDurationMilliseconds is less than DurationMilliseconds, then JitterDurationMilliseconds is used.
DurationMilliseconds *int64 `json:"durationMilliseconds,omitempty"`
// DurationFrom is the expression used to get the value.
// If it is a time.Time type, getting the value will be minus time.Now() to get Duration
// If it is a time.Time type, getting the value will be minus time.Now() to get DurationMilliseconds
// If it is a string type, the value get will be parsed by time.ParseDuration.
DurationFrom *ExpressionFromSource `json:"durationFrom,omitempty"`

// JitterDuration is the duration plus an additional amount chosen uniformly
// at random from the interval between Duration and JitterDuration.
JitterDuration *metav1.Duration `json:"jitterDuration,omitempty"`
// JitterDurationMilliseconds is the duration plus an additional amount chosen uniformly
// at random from the interval between DurationMilliseconds and JitterDurationMilliseconds.
JitterDurationMilliseconds *int64 `json:"jitterDurationMilliseconds,omitempty"`
// JitterDurationFrom is the expression used to get the value.
// If it is a time.Time type, getting the value will be minus time.Now() to get JitterDuration
// If it is a time.Time type, getting the value will be minus time.Now() to get JitterDurationMilliseconds
// If it is a string type, the value get will be parsed by time.ParseDuration.
JitterDurationFrom *ExpressionFromSource `json:"jitterDurationFrom,omitempty"`
}
Expand Down
13 changes: 8 additions & 5 deletions pkg/apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ func TestConfig(t *testing.T) {
APIVersion: v1alpha1.GroupVersion.String(),
},
},
&internalversion.Stage{
TypeMeta: metav1.TypeMeta{
Kind: v1alpha1.StageKind,
APIVersion: v1alpha1.GroupVersion.String(),
},
},
}
err := Save(ctx, config, data)
if err != nil {
Expand Down
14 changes: 10 additions & 4 deletions pkg/kwok/controllers/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"sigs.k8s.io/kwok/pkg/apis/internalversion"
"sigs.k8s.io/kwok/pkg/utils/expression"
"sigs.k8s.io/kwok/pkg/utils/format"
)

func NewStagesFromYaml(data []byte) ([]*internalversion.Stage, error) {
Expand Down Expand Up @@ -146,19 +147,24 @@ func newLifecycleFromStage(s *internalversion.Stage) (*LifecycleStage, error) {
if delay.DurationFrom != nil {
durationFrom = &delay.DurationFrom.ExpressionFrom
}
duration, err := expression.NewDurationFrom(&delay.Duration.Duration, durationFrom)
var delayDuration time.Duration
if delay.DurationMilliseconds != nil {
delayDuration = time.Duration(*delay.DurationMilliseconds) * time.Millisecond
}
duration, err := expression.NewDurationFrom(&delayDuration, durationFrom)
if err != nil {
return nil, err
}
stage.duration = duration
if delay.JitterDuration != nil || delay.JitterDurationFrom != nil {

if delay.JitterDurationMilliseconds != nil || delay.JitterDurationFrom != nil {
var jitterDurationFrom *string
if delay.JitterDurationFrom != nil {
jitterDurationFrom = &delay.JitterDurationFrom.ExpressionFrom
}
var jitterDuration *time.Duration
if delay.JitterDuration != nil {
jitterDuration = &delay.JitterDuration.Duration
if delay.JitterDurationMilliseconds != nil {
jitterDuration = format.Ptr(time.Duration(*delay.JitterDurationMilliseconds) * time.Millisecond)
}
jitterDurationGetter, err := expression.NewDurationFrom(jitterDuration, jitterDurationFrom)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions site/content/en/docs/user/stages-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ spec:
values:
- <string>
delay:
duration: <duration-string>
durationMilliseconds: <int>
durationFrom:
expressionFrom: <expressions-string>
jitterDuration: <duration-string>
jitterDurationMilliseconds: <int>
jitterDurationFrom:
expressionFrom: <expressions-string>
next:
Expand Down
4 changes: 2 additions & 2 deletions stages/node-fast.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ spec:
values:
- Running
delay:
duration: 20s
jitterDuration: 25s
durationMilliseconds: 20000
jitterDurationMilliseconds: 25000
next:
statusTemplate: |
{{ $now := Now }}
Expand Down
26 changes: 13 additions & 13 deletions stages/pod-general.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ spec:
operator: 'DoesNotExist'
weight: 1
delay:
duration: 1s
jitterDuration: 5s
durationMilliseconds: 1000
jitterDurationMilliseconds: 5000
next:
event:
type: Normal
Expand Down Expand Up @@ -122,8 +122,8 @@ spec:
operator: 'Exists'
weight: 1
delay:
duration: 1s
jitterDuration: 5s
durationMilliseconds: 1000
jitterDurationMilliseconds: 5000
next:
statusTemplate: |
{{ $now := Now }}
Expand Down Expand Up @@ -165,8 +165,8 @@ spec:
operator: 'Exists'
weight: 1
delay:
duration: 1s
jitterDuration: 5s
durationMilliseconds: 1000
jitterDurationMilliseconds: 5000
next:
statusTemplate: |
{{ $now := Now }}
Expand Down Expand Up @@ -229,8 +229,8 @@ spec:
- 'True'
weight: 1
delay:
duration: 1s
jitterDuration: 5s
durationMilliseconds: 1000
jitterDurationMilliseconds: 5000
next:
delete: false
statusTemplate: |
Expand Down Expand Up @@ -289,8 +289,8 @@ spec:
- 'Job'
weight: 1
delay:
duration: 1s
jitterDuration: 5s
durationMilliseconds: 1000
jitterDurationMilliseconds: 5000
next:
delete: false
statusTemplate: |
Expand Down Expand Up @@ -331,8 +331,8 @@ spec:
- 'kwok.x-k8s.io/fake'
weight: 1
delay:
duration: 1s
jitterDuration: 5s
durationMilliseconds: 1000
jitterDurationMilliseconds: 5000
next:
finalizers:
remove:
Expand All @@ -358,7 +358,7 @@ spec:
operator: 'DoesNotExist'
weight: 1
delay:
duration: 1s
durationMilliseconds: 1000
jitterDurationFrom:
expressionFrom: '.metadata.deletionTimestamp'
next:
Expand Down

0 comments on commit 840110b

Please sign in to comment.