Skip to content

Commit

Permalink
don't use float in CRDs.
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Feb 26, 2025
1 parent baa52fc commit a93aea8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ gen-schemas:

.PHONY: manifests
manifests: controller-gen generate gen-schemas ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) crd:allowDangerousTypes=true paths="./api/..." output:crd:artifacts:config=config/crds
$(CONTROLLER_GEN) crd paths="./api/..." output:crd:artifacts:config=config/crds

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down
8 changes: 4 additions & 4 deletions api/v1/playbook_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ func (t *AWSConnection) Populate(ctx connectionContext, k8s kubernetes.Interface
}

type RetryExponent struct {
Multiplier float64 `json:"multiplier"`
Multiplier int `json:"multiplier"`
}

type PlaybookActionRetry struct {
Expand All @@ -527,7 +527,7 @@ type PlaybookActionRetry struct {
// Ranges from 0 to 100.
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=100
Jitter float64 `json:"jitter,omitempty"`
Jitter int `json:"jitter,omitempty"`

// Exponent is the exponential backoff configuration.
Exponent RetryExponent `json:"exponent"`
Expand All @@ -539,9 +539,9 @@ func (t PlaybookActionRetry) NextRetryWait(retryNumber int) (time.Duration, erro
return 0, fmt.Errorf("failed to parse duration(%s): %w", t.Duration, err)
}

nextWaitDuration := float64(interval) * math.Pow(t.Exponent.Multiplier, float64(retryNumber))
nextWaitDuration := float64(interval) * math.Pow(float64(t.Exponent.Multiplier), float64(retryNumber))

jitterFactor := 1 + ((rand.Float64()*2 - 1) * t.Jitter * 0.01) // Scales jitter within [-Jitter, +Jitter]
jitterFactor := 1 + ((rand.Float64()*2 - 1) * float64(t.Jitter) * 0.01) // Scales jitter within [-Jitter, +Jitter]
nextWaitDurationWithJitter := nextWaitDuration * jitterFactor

return time.Duration(nextWaitDurationWithJitter), nil
Expand Down
12 changes: 6 additions & 6 deletions api/v1/playbook_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@ func TestNextRetryWait(t *testing.T) {
{
name: "no jitter",
RetryCount: 1,
ExpectedRange: []float64{45, 45},
ExpectedRange: []float64{60, 60},
Retry: PlaybookActionRetry{
Limit: 1,
Duration: "30s",
Exponent: RetryExponent{
Multiplier: 1.5,
Multiplier: 2,
},
Jitter: 0,
},
},
{
name: "no jitter second iteration",
RetryCount: 2,
ExpectedRange: []float64{67.5, 67.5},
ExpectedRange: []float64{120, 120},
Retry: PlaybookActionRetry{
Limit: 1,
Duration: "30s",
Exponent: RetryExponent{
Multiplier: 1.5,
Multiplier: 2,
},
Jitter: 0,
},
},
{
name: "with jitter second iteration",
RetryCount: 2,
ExpectedRange: []float64{60, 75},
ExpectedRange: []float64{108, 132},
Retry: PlaybookActionRetry{
Limit: 1,
Duration: "30s",
Exponent: RetryExponent{
Multiplier: 1.5,
Multiplier: 2,
},
Jitter: 10,
},
Expand Down
4 changes: 2 additions & 2 deletions config/crds/mission-control.flanksource.com_playbooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,7 @@ spec:
description: Exponent is the exponential backoff configuration.
properties:
multiplier:
type: number
type: integer
required:
- multiplier
type: object
Expand All @@ -1738,7 +1738,7 @@ spec:
Ranges from 0 to 100.
maximum: 100
minimum: 0
type: number
type: integer
limit:
description: |-
Limit is the number of times to retry the action.
Expand Down
4 changes: 2 additions & 2 deletions config/schemas/playbook-spec.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@
"type": "string"
},
"jitter": {
"type": "number"
"type": "integer"
},
"exponent": {
"$ref": "#/$defs/RetryExponent"
Expand Down Expand Up @@ -1191,7 +1191,7 @@
"RetryExponent": {
"properties": {
"multiplier": {
"type": "number"
"type": "integer"
}
},
"additionalProperties": false,
Expand Down
4 changes: 2 additions & 2 deletions config/schemas/playbook.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@
"type": "string"
},
"jitter": {
"type": "number"
"type": "integer"
},
"exponent": {
"$ref": "#/$defs/RetryExponent"
Expand Down Expand Up @@ -1345,7 +1345,7 @@
"RetryExponent": {
"properties": {
"multiplier": {
"type": "number"
"type": "integer"
}
},
"additionalProperties": false,
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ github.com/flanksource/artifacts v1.0.14 h1:Vv70bccsae0MwGaf/uSPp34J5V1/PyKfct9z
github.com/flanksource/artifacts v1.0.14/go.mod h1:qHVCnQu5k50aWNJ5UhpcAKEl7pAzqUrFFKGSm147G70=
github.com/flanksource/commons v1.36.1 h1:SDppXOYO6vk06d12SPOYVZJX+8gV72FmK1l9ar5fkjc=
github.com/flanksource/commons v1.36.1/go.mod h1:nsYCn6JOhENXNLR5pz4zNco70DQV+bGObQ8NbOrUeuQ=
github.com/flanksource/duty v1.0.853 h1:0lvwYXeRk2fJGuF/1BvvYR629LYmEtwJgS6SFvh+VKg=
github.com/flanksource/duty v1.0.853/go.mod h1:hoCee0pTczWCMqgUsjhecE6+rkR+yhia7JzD4gqCeaE=
github.com/flanksource/duty v1.0.862 h1:VsqkaEKjxezMordMu3YZNd64sWH0/GWvE4uD98ScPWY=
github.com/flanksource/duty v1.0.862/go.mod h1:5NmEw4b/vz08vXNR4WPuHWNtD6YB2pGu2RrX1HrDT8E=
github.com/flanksource/gomplate/v3 v3.24.55 h1:BW+KeMcggCkNawb4VTbY+Zn3s9eYIhwqb5/myiyJRb8=
github.com/flanksource/gomplate/v3 v3.24.55/go.mod h1:hGEObNtnOQs8rNUX8sM8aJTAhnt4ehjyOw1MvDhl6AU=
github.com/flanksource/is-healthy v1.0.62 h1:wa4Eq3YR1+Ku3UhKlVpos0CqieGeWWVF5gZeOsmDAIg=
Expand Down

0 comments on commit a93aea8

Please sign in to comment.