diff --git a/api/v1/checks.go b/api/v1/checks.go index a50bf1d86..a54001188 100644 --- a/api/v1/checks.go +++ b/api/v1/checks.go @@ -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:"-"` @@ -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:"-"` } diff --git a/checks/kubernetes_resource.go b/checks/kubernetes_resource.go index 852b6d386..2f2e95407 100644 --- a/checks/kubernetes_resource.go +++ b/checks/kubernetes_resource.go @@ -6,6 +6,7 @@ import ( "fmt" "strconv" "strings" + "sync" "time" "github.com/flanksource/gomplate/v3" @@ -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" @@ -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) } @@ -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++ @@ -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 { @@ -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{ @@ -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) diff --git a/config/deploy/crd.yaml b/config/deploy/crd.yaml index cc977999c..cf7b24ca2 100644 --- a/config/deploy/crd.yaml +++ b/config/deploy/crd.yaml @@ -4997,8 +4997,6 @@ spec: type: string interval: type: string - maxRetries: - type: integer timeout: type: string type: object @@ -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. diff --git a/config/deploy/manifests.yaml b/config/deploy/manifests.yaml index 80ec33bca..863fc96e9 100644 --- a/config/deploy/manifests.yaml +++ b/config/deploy/manifests.yaml @@ -4996,8 +4996,6 @@ spec: type: string interval: type: string - maxRetries: - type: integer timeout: type: string type: object @@ -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. diff --git a/config/schemas/canary.schema.json b/config/schemas/canary.schema.json index f0a6c9374..916ac88e1 100644 --- a/config/schemas/canary.schema.json +++ b/config/schemas/canary.schema.json @@ -2353,9 +2353,6 @@ }, "interval": { "type": "string" - }, - "maxRetries": { - "type": "integer" } }, "additionalProperties": false, @@ -2377,9 +2374,6 @@ }, "interval": { "type": "string" - }, - "maxRetries": { - "type": "integer" } }, "additionalProperties": false, diff --git a/config/schemas/component.schema.json b/config/schemas/component.schema.json index 2e0bd7e0e..01cfa4579 100644 --- a/config/schemas/component.schema.json +++ b/config/schemas/component.schema.json @@ -2610,9 +2610,6 @@ }, "interval": { "type": "string" - }, - "maxRetries": { - "type": "integer" } }, "additionalProperties": false, @@ -2634,9 +2631,6 @@ }, "interval": { "type": "string" - }, - "maxRetries": { - "type": "integer" } }, "additionalProperties": false, diff --git a/config/schemas/topology.schema.json b/config/schemas/topology.schema.json index 061803f1f..91fb1ad03 100644 --- a/config/schemas/topology.schema.json +++ b/config/schemas/topology.schema.json @@ -2580,9 +2580,6 @@ }, "interval": { "type": "string" - }, - "maxRetries": { - "type": "integer" } }, "additionalProperties": false, @@ -2604,9 +2601,6 @@ }, "interval": { "type": "string" - }, - "maxRetries": { - "type": "integer" } }, "additionalProperties": false, diff --git a/fixtures/k8s/kubernetes_resource_ingress_pass.yaml b/fixtures/k8s/kubernetes_resource_ingress_pass.yaml index 31bb57c17..1ed344993 100644 --- a/fixtures/k8s/kubernetes_resource_ingress_pass.yaml +++ b/fixtures/k8s/kubernetes_resource_ingress_pass.yaml @@ -72,4 +72,4 @@ spec: checkRetries: delay: 3s interval: 2s - maxRetries: 5 + timeout: 5m diff --git a/fixtures/k8s/kubernetes_resource_pod_exit_code_pass.yaml b/fixtures/k8s/kubernetes_resource_pod_exit_code_pass.yaml index de662ab4d..6f05cfd7c 100644 --- a/fixtures/k8s/kubernetes_resource_pod_exit_code_pass.yaml +++ b/fixtures/k8s/kubernetes_resource_pod_exit_code_pass.yaml @@ -29,7 +29,7 @@ spec: timeout: "20s" checkRetries: delay: 2s - maxRetries: 3 + timeout: 5m checks: - kubernetes: - name: exit-code-check diff --git a/fixtures/k8s/kubernetes_resource_service_pass.yaml b/fixtures/k8s/kubernetes_resource_service_pass.yaml index 6e406dad2..693811227 100644 --- a/fixtures/k8s/kubernetes_resource_service_pass.yaml +++ b/fixtures/k8s/kubernetes_resource_service_pass.yaml @@ -43,5 +43,4 @@ spec: url: "http://httpbin-svc.default.svc" checkRetries: delay: 2s - maxRetries: 5 interval: 3s