Skip to content

Commit

Permalink
chore: remove max retries
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Apr 18, 2024
1 parent 77c8f2a commit 25c4266
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 49 deletions.
11 changes: 4 additions & 7 deletions api/v1/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,10 +790,9 @@ type KubernetesResourceChecks struct {

type KubernetesResourceCheckRetries struct {
// Delay is the initial delay
Delay string `json:"delay,omitempty"`
Timeout string `json:"timeout,omitempty"`
Interval string `json:"interval,omitempty"`
MaxRetries int `json:"maxRetries,omitempty"`
Delay string `json:"delay,omitempty"`
Timeout string `json:"timeout,omitempty"`
Interval string `json:"interval,omitempty"`

parsedDelay *time.Duration `json:"-"`
parsedTimeout *time.Duration `json:"-"`
Expand Down Expand Up @@ -871,11 +870,9 @@ type KubernetesResourceCheckWaitFor struct {
Timeout string `json:"timeout,omitempty"`

// Interval to check if all static & non-static resources are ready.
// Default: 30s
// Default: 5s
Interval string `json:"interval,omitempty"`

MaxRetries int `json:"maxRetries,omitempty"`

parsedTimeout *time.Duration `json:"-"`
parsedInterval *time.Duration `json:"-"`
}
Expand Down
17 changes: 6 additions & 11 deletions checks/kubernetes_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"strconv"
"strings"
"sync"
"time"

"github.com/flanksource/gomplate/v3"
Expand All @@ -15,7 +16,6 @@ import (
apiErrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
cliresource "k8s.io/cli-runtime/pkg/resource"

"github.com/flanksource/canary-checker/api/context"
Expand Down Expand Up @@ -145,10 +145,6 @@ func (c *KubernetesResourceChecker) Check(ctx *context.Context, check v1.Kuberne
backoff = retry.NewConstant(retryInterval)
}

if check.CheckRetries.MaxRetries > 0 {
backoff = retry.WithMaxRetries(uint64(check.CheckRetries.MaxRetries), backoff)
}

if maxRetryTimeout, _ := check.CheckRetries.GetTimeout(); maxRetryTimeout > 0 {
backoff = retry.WithMaxDuration(maxRetryTimeout, backoff)
}
Expand Down Expand Up @@ -198,9 +194,6 @@ func (c *KubernetesResourceChecker) evalWaitFor(ctx *context.Context, check v1.K

var attempts int
backoff := retry.WithMaxDuration(waitTimeout, retry.NewConstant(waitInterval))
if check.WaitFor.MaxRetries > 0 {
backoff = retry.WithMaxRetries(uint64(check.WaitFor.MaxRetries), backoff)
}
retryErr := retry.Do(ctx, backoff, func(_ctx gocontext.Context) error {
ctx = _ctx.(*context.Context)
attempts++
Expand Down Expand Up @@ -299,7 +292,7 @@ func deleteResources(ctx *context.Context, waitForDelete bool, resources ...unst
ctx.Logger.V(4).Infof("deleting %d resources", len(resources))

// cache dynamic clients
clients := map[schema.GroupVersionKind]*cliresource.Helper{}
clients := sync.Map{}

eg, _ := errgroup.WithContext(ctx)
for i := range resources {
Expand All @@ -311,7 +304,7 @@ func deleteResources(ctx *context.Context, waitForDelete bool, resources ...unst
return fmt.Errorf("failed to get rest client for (%s/%s/%s): %w", resource.GetKind(), resource.GetNamespace(), resource.GetName(), err)
}
gvk := resource.GetObjectKind().GroupVersionKind()
clients[gvk] = rc
clients.Store(gvk, rc)

namespace := utils.Coalesce(resource.GetNamespace(), ctx.Namespace)
deleteOpt := &metav1.DeleteOptions{
Expand Down Expand Up @@ -354,7 +347,9 @@ func deleteResources(ctx *context.Context, waitForDelete bool, resources ...unst

deleted := make(map[string]struct{})
for _, resource := range resources {
rc := clients[resource.GetObjectKind().GroupVersionKind()]
cachedClient, _ := clients.Load(resource.GetObjectKind().GroupVersionKind())
rc := cachedClient.(*cliresource.Helper)

if _, err := rc.Get(resource.GetNamespace(), resource.GetName()); err != nil {
if !apiErrors.IsNotFound(err) {
return fmt.Errorf("error getting resource (%s/%s/%s) while polling: %w", resource.GetKind(), resource.GetNamespace(), resource.GetName(), err)
Expand Down
6 changes: 1 addition & 5 deletions config/deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4997,8 +4997,6 @@ spec:
type: string
interval:
type: string
maxRetries:
type: integer
timeout:
type: string
type: object
Expand Down Expand Up @@ -5163,10 +5161,8 @@ spec:
interval:
description: |-
Interval to check if all static & non-static resources are ready.
Default: 30s
Default: 5s
type: string
maxRetries:
type: integer
timeout:
description: |-
Timeout to wait for all static & non-static resources to be ready.
Expand Down
6 changes: 1 addition & 5 deletions config/deploy/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4996,8 +4996,6 @@ spec:
type: string
interval:
type: string
maxRetries:
type: integer
timeout:
type: string
type: object
Expand Down Expand Up @@ -5162,10 +5160,8 @@ spec:
interval:
description: |-
Interval to check if all static & non-static resources are ready.
Default: 30s
Default: 5s
type: string
maxRetries:
type: integer
timeout:
description: |-
Timeout to wait for all static & non-static resources to be ready.
Expand Down
6 changes: 0 additions & 6 deletions config/schemas/canary.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2353,9 +2353,6 @@
},
"interval": {
"type": "string"
},
"maxRetries": {
"type": "integer"
}
},
"additionalProperties": false,
Expand All @@ -2377,9 +2374,6 @@
},
"interval": {
"type": "string"
},
"maxRetries": {
"type": "integer"
}
},
"additionalProperties": false,
Expand Down
6 changes: 0 additions & 6 deletions config/schemas/component.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2610,9 +2610,6 @@
},
"interval": {
"type": "string"
},
"maxRetries": {
"type": "integer"
}
},
"additionalProperties": false,
Expand All @@ -2634,9 +2631,6 @@
},
"interval": {
"type": "string"
},
"maxRetries": {
"type": "integer"
}
},
"additionalProperties": false,
Expand Down
6 changes: 0 additions & 6 deletions config/schemas/topology.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2580,9 +2580,6 @@
},
"interval": {
"type": "string"
},
"maxRetries": {
"type": "integer"
}
},
"additionalProperties": false,
Expand All @@ -2604,9 +2601,6 @@
},
"interval": {
"type": "string"
},
"maxRetries": {
"type": "integer"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion fixtures/k8s/kubernetes_resource_ingress_pass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ spec:
checkRetries:
delay: 3s
interval: 2s
maxRetries: 5
timeout: 5m
2 changes: 1 addition & 1 deletion fixtures/k8s/kubernetes_resource_pod_exit_code_pass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
timeout: "20s"
checkRetries:
delay: 2s
maxRetries: 3
timeout: 5m
checks:
- kubernetes:
- name: exit-code-check
Expand Down
1 change: 0 additions & 1 deletion fixtures/k8s/kubernetes_resource_service_pass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ spec:
url: "http://httpbin-svc.default.svc"
checkRetries:
delay: 2s
maxRetries: 5
interval: 3s

0 comments on commit 25c4266

Please sign in to comment.