From 4b8269d714d111637377be7fd2bd4ef069531caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Fri, 2 Aug 2024 23:50:50 +0200 Subject: [PATCH] refactor: more engine package (#1824) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: add unit tests (#1815) Signed-off-by: Charles-Edouard Brétéché * refactor: more engine package Signed-off-by: Charles-Edouard Brétéché --------- Signed-off-by: Charles-Edouard Brétéché --- pkg/client/utils.go | 4 +++- pkg/commands/assert/command.go | 2 +- .../operations/apply/operation.go | 6 ++--- .../operations/apply/operation_test.go | 0 .../operations/assert/operation.go | 8 +++---- .../operations/assert/operation_test.go | 0 .../operations/command/operation.go | 4 ++-- .../operations/command/operation_test.go | 0 .../operations/create/operation.go | 6 ++--- .../operations/create/operation_test.go | 0 .../operations/delete/operation.go | 6 ++--- .../operations/delete/operation_test.go | 0 .../operations/error/operation.go | 6 ++--- .../operations/error/operation_test.go | 0 .../operations/errors/resource.go | 0 .../operations/internal/command_output.go | 0 .../internal/command_output_test.go | 0 .../operations/internal/env.go | 0 .../operations/internal/log.go | 0 .../operations/internal/log_test.go | 0 .../operations/internal/namespace.go | 0 .../operations/internal/namespace_test.go | 0 .../operations/internal/read.go | 0 .../operations/internal/read_test.go | 0 .../operations/operation.go | 0 .../operations/patch/operation.go | 6 ++--- .../operations/patch/operation_test.go | 0 .../operations/script/operation.go | 4 ++-- .../operations/script/operation_test.go | 0 .../operations/sleep/operation.go | 4 ++-- .../operations/sleep/operation_test.go | 0 .../operations/testing/mock.go | 0 .../operations/update/operation.go | 6 ++--- .../operations/update/operation_test.go | 0 pkg/runner/operations/internal/interval.go | 7 ------ pkg/runner/processors/operation.go | 2 +- pkg/runner/processors/operation_test.go | 4 ++-- pkg/runner/processors/step.go | 22 +++++++++---------- 38 files changed, 46 insertions(+), 51 deletions(-) rename pkg/{runner => engine}/operations/apply/operation.go (95%) rename pkg/{runner => engine}/operations/apply/operation_test.go (100%) rename pkg/{runner => engine}/operations/assert/operation.go (91%) rename pkg/{runner => engine}/operations/assert/operation_test.go (100%) rename pkg/{runner => engine}/operations/command/operation.go (97%) rename pkg/{runner => engine}/operations/command/operation_test.go (100%) rename pkg/{runner => engine}/operations/create/operation.go (94%) rename pkg/{runner => engine}/operations/create/operation_test.go (100%) rename pkg/{runner => engine}/operations/delete/operation.go (95%) rename pkg/{runner => engine}/operations/delete/operation_test.go (100%) rename pkg/{runner => engine}/operations/error/operation.go (93%) rename pkg/{runner => engine}/operations/error/operation_test.go (100%) rename pkg/{runner => engine}/operations/errors/resource.go (100%) rename pkg/{runner => engine}/operations/internal/command_output.go (100%) rename pkg/{runner => engine}/operations/internal/command_output_test.go (100%) rename pkg/{runner => engine}/operations/internal/env.go (100%) rename pkg/{runner => engine}/operations/internal/log.go (100%) rename pkg/{runner => engine}/operations/internal/log_test.go (100%) rename pkg/{runner => engine}/operations/internal/namespace.go (100%) rename pkg/{runner => engine}/operations/internal/namespace_test.go (100%) rename pkg/{runner => engine}/operations/internal/read.go (100%) rename pkg/{runner => engine}/operations/internal/read_test.go (100%) rename pkg/{runner => engine}/operations/operation.go (100%) rename pkg/{runner => engine}/operations/patch/operation.go (94%) rename pkg/{runner => engine}/operations/patch/operation_test.go (100%) rename pkg/{runner => engine}/operations/script/operation.go (96%) rename pkg/{runner => engine}/operations/script/operation_test.go (100%) rename pkg/{runner => engine}/operations/sleep/operation.go (87%) rename pkg/{runner => engine}/operations/sleep/operation_test.go (100%) rename pkg/{runner => engine}/operations/testing/mock.go (100%) rename pkg/{runner => engine}/operations/update/operation.go (94%) rename pkg/{runner => engine}/operations/update/operation_test.go (100%) delete mode 100644 pkg/runner/operations/internal/interval.go diff --git a/pkg/client/utils.go b/pkg/client/utils.go index 984d07047..d6242a511 100644 --- a/pkg/client/utils.go +++ b/pkg/client/utils.go @@ -14,6 +14,8 @@ import ( "k8s.io/apimachinery/pkg/util/wait" ) +const PollInterval = 50 * time.Millisecond + func Key(obj metav1.Object) ObjectKey { return ObjectKey{ Name: obj.GetName(), @@ -60,7 +62,7 @@ func PatchObject(actual, expected runtime.Object) (runtime.Object, error) { func WaitForDeletion(ctx context.Context, client Client, object Object) error { key := Key(object) - return wait.PollUntilContextCancel(ctx, 50*time.Millisecond, true, func(ctx context.Context) (bool, error) { + return wait.PollUntilContextCancel(ctx, PollInterval, true, func(ctx context.Context) (bool, error) { if err := client.Get(ctx, key, object); err != nil { if kerrors.IsNotFound(err) { return true, nil diff --git a/pkg/commands/assert/command.go b/pkg/commands/assert/command.go index 94da3d419..cdcb1b015 100644 --- a/pkg/commands/assert/command.go +++ b/pkg/commands/assert/command.go @@ -11,9 +11,9 @@ import ( tclient "github.com/kyverno/chainsaw/pkg/client/testing" engineclient "github.com/kyverno/chainsaw/pkg/engine/client" nspacer "github.com/kyverno/chainsaw/pkg/engine/namespacer" + opassert "github.com/kyverno/chainsaw/pkg/engine/operations/assert" "github.com/kyverno/chainsaw/pkg/loaders/config" "github.com/kyverno/chainsaw/pkg/loaders/resource" - opassert "github.com/kyverno/chainsaw/pkg/runner/operations/assert" restutils "github.com/kyverno/chainsaw/pkg/utils/rest" "github.com/kyverno/pkg/ext/output/color" "github.com/spf13/cobra" diff --git a/pkg/runner/operations/apply/operation.go b/pkg/engine/operations/apply/operation.go similarity index 95% rename from pkg/runner/operations/apply/operation.go rename to pkg/engine/operations/apply/operation.go index 464b1df24..46d542108 100644 --- a/pkg/runner/operations/apply/operation.go +++ b/pkg/engine/operations/apply/operation.go @@ -11,10 +11,10 @@ import ( "github.com/kyverno/chainsaw/pkg/engine/checks" "github.com/kyverno/chainsaw/pkg/engine/logging" "github.com/kyverno/chainsaw/pkg/engine/namespacer" + "github.com/kyverno/chainsaw/pkg/engine/operations" + "github.com/kyverno/chainsaw/pkg/engine/operations/internal" "github.com/kyverno/chainsaw/pkg/engine/outputs" "github.com/kyverno/chainsaw/pkg/engine/templating" - "github.com/kyverno/chainsaw/pkg/runner/operations" - "github.com/kyverno/chainsaw/pkg/runner/operations/internal" kerrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/types" @@ -81,7 +81,7 @@ func (o *operation) Exec(ctx context.Context, tc binding.Bindings) (_ outputs.Ou func (o *operation) execute(ctx context.Context, tc binding.Bindings, obj unstructured.Unstructured) (outputs.Outputs, error) { var lastErr error var outputs outputs.Outputs - err := wait.PollUntilContextCancel(ctx, internal.PollInterval, false, func(ctx context.Context) (bool, error) { + err := wait.PollUntilContextCancel(ctx, client.PollInterval, false, func(ctx context.Context) (bool, error) { outputs, lastErr = o.tryApplyResource(ctx, tc, obj) // TODO: determine if the error can be retried return lastErr == nil, nil diff --git a/pkg/runner/operations/apply/operation_test.go b/pkg/engine/operations/apply/operation_test.go similarity index 100% rename from pkg/runner/operations/apply/operation_test.go rename to pkg/engine/operations/apply/operation_test.go diff --git a/pkg/runner/operations/assert/operation.go b/pkg/engine/operations/assert/operation.go similarity index 91% rename from pkg/runner/operations/assert/operation.go rename to pkg/engine/operations/assert/operation.go index 1fd6acbdb..6d792ee35 100644 --- a/pkg/runner/operations/assert/operation.go +++ b/pkg/engine/operations/assert/operation.go @@ -10,11 +10,11 @@ import ( "github.com/kyverno/chainsaw/pkg/engine/checks" "github.com/kyverno/chainsaw/pkg/engine/logging" "github.com/kyverno/chainsaw/pkg/engine/namespacer" + "github.com/kyverno/chainsaw/pkg/engine/operations" + operrors "github.com/kyverno/chainsaw/pkg/engine/operations/errors" + "github.com/kyverno/chainsaw/pkg/engine/operations/internal" "github.com/kyverno/chainsaw/pkg/engine/outputs" "github.com/kyverno/chainsaw/pkg/engine/templating" - "github.com/kyverno/chainsaw/pkg/runner/operations" - operrors "github.com/kyverno/chainsaw/pkg/runner/operations/errors" - "github.com/kyverno/chainsaw/pkg/runner/operations/internal" "go.uber.org/multierr" kerrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -67,7 +67,7 @@ func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (_ outp func (o *operation) execute(ctx context.Context, bindings binding.Bindings, obj unstructured.Unstructured) error { var lastErrs []error - err := wait.PollUntilContextCancel(ctx, internal.PollInterval, false, func(ctx context.Context) (_ bool, err error) { + err := wait.PollUntilContextCancel(ctx, client.PollInterval, false, func(ctx context.Context) (_ bool, err error) { var errs []error defer func() { // record last errors only if there was no real error diff --git a/pkg/runner/operations/assert/operation_test.go b/pkg/engine/operations/assert/operation_test.go similarity index 100% rename from pkg/runner/operations/assert/operation_test.go rename to pkg/engine/operations/assert/operation_test.go diff --git a/pkg/runner/operations/command/operation.go b/pkg/engine/operations/command/operation.go similarity index 97% rename from pkg/runner/operations/command/operation.go rename to pkg/engine/operations/command/operation.go index 63eb3d9ae..6893d1c9e 100644 --- a/pkg/runner/operations/command/operation.go +++ b/pkg/engine/operations/command/operation.go @@ -11,9 +11,9 @@ import ( apibindings "github.com/kyverno/chainsaw/pkg/engine/bindings" "github.com/kyverno/chainsaw/pkg/engine/checks" "github.com/kyverno/chainsaw/pkg/engine/logging" + "github.com/kyverno/chainsaw/pkg/engine/operations" + "github.com/kyverno/chainsaw/pkg/engine/operations/internal" "github.com/kyverno/chainsaw/pkg/engine/outputs" - "github.com/kyverno/chainsaw/pkg/runner/operations" - "github.com/kyverno/chainsaw/pkg/runner/operations/internal" environment "github.com/kyverno/chainsaw/pkg/utils/env" restutils "github.com/kyverno/chainsaw/pkg/utils/rest" "github.com/kyverno/pkg/ext/output/color" diff --git a/pkg/runner/operations/command/operation_test.go b/pkg/engine/operations/command/operation_test.go similarity index 100% rename from pkg/runner/operations/command/operation_test.go rename to pkg/engine/operations/command/operation_test.go diff --git a/pkg/runner/operations/create/operation.go b/pkg/engine/operations/create/operation.go similarity index 94% rename from pkg/runner/operations/create/operation.go rename to pkg/engine/operations/create/operation.go index 85390e45f..cfac5348d 100644 --- a/pkg/runner/operations/create/operation.go +++ b/pkg/engine/operations/create/operation.go @@ -12,10 +12,10 @@ import ( "github.com/kyverno/chainsaw/pkg/engine/checks" "github.com/kyverno/chainsaw/pkg/engine/logging" "github.com/kyverno/chainsaw/pkg/engine/namespacer" + "github.com/kyverno/chainsaw/pkg/engine/operations" + "github.com/kyverno/chainsaw/pkg/engine/operations/internal" "github.com/kyverno/chainsaw/pkg/engine/outputs" "github.com/kyverno/chainsaw/pkg/engine/templating" - "github.com/kyverno/chainsaw/pkg/runner/operations" - "github.com/kyverno/chainsaw/pkg/runner/operations/internal" kerrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/util/wait" @@ -80,7 +80,7 @@ func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (_ outp func (o *operation) execute(ctx context.Context, bindings binding.Bindings, obj unstructured.Unstructured) (outputs.Outputs, error) { var lastErr error var outputs outputs.Outputs - err := wait.PollUntilContextCancel(ctx, internal.PollInterval, false, func(ctx context.Context) (bool, error) { + err := wait.PollUntilContextCancel(ctx, client.PollInterval, false, func(ctx context.Context) (bool, error) { outputs, lastErr = o.tryCreateResource(ctx, bindings, obj) // TODO: determine if the error can be retried return lastErr == nil, nil diff --git a/pkg/runner/operations/create/operation_test.go b/pkg/engine/operations/create/operation_test.go similarity index 100% rename from pkg/runner/operations/create/operation_test.go rename to pkg/engine/operations/create/operation_test.go diff --git a/pkg/runner/operations/delete/operation.go b/pkg/engine/operations/delete/operation.go similarity index 95% rename from pkg/runner/operations/delete/operation.go rename to pkg/engine/operations/delete/operation.go index cbea32d29..47b742b9f 100644 --- a/pkg/runner/operations/delete/operation.go +++ b/pkg/engine/operations/delete/operation.go @@ -10,10 +10,10 @@ import ( "github.com/kyverno/chainsaw/pkg/engine/checks" "github.com/kyverno/chainsaw/pkg/engine/logging" "github.com/kyverno/chainsaw/pkg/engine/namespacer" + "github.com/kyverno/chainsaw/pkg/engine/operations" + "github.com/kyverno/chainsaw/pkg/engine/operations/internal" "github.com/kyverno/chainsaw/pkg/engine/outputs" "github.com/kyverno/chainsaw/pkg/engine/templating" - "github.com/kyverno/chainsaw/pkg/runner/operations" - "github.com/kyverno/chainsaw/pkg/runner/operations/internal" "go.uber.org/multierr" kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -128,7 +128,7 @@ func (o *operation) deleteResource(ctx context.Context, resource unstructured.Un func (o *operation) waitForDeletion(ctx context.Context, resource unstructured.Unstructured) error { gvk := resource.GetObjectKind().GroupVersionKind() key := client.Key(&resource) - return wait.PollUntilContextCancel(ctx, internal.PollInterval, true, func(ctx context.Context) (bool, error) { + return wait.PollUntilContextCancel(ctx, client.PollInterval, true, func(ctx context.Context) (bool, error) { var actual unstructured.Unstructured actual.SetGroupVersionKind(gvk) if err := o.client.Get(ctx, key, &actual); err != nil { diff --git a/pkg/runner/operations/delete/operation_test.go b/pkg/engine/operations/delete/operation_test.go similarity index 100% rename from pkg/runner/operations/delete/operation_test.go rename to pkg/engine/operations/delete/operation_test.go diff --git a/pkg/runner/operations/error/operation.go b/pkg/engine/operations/error/operation.go similarity index 93% rename from pkg/runner/operations/error/operation.go rename to pkg/engine/operations/error/operation.go index 6aad06f96..88e082266 100644 --- a/pkg/runner/operations/error/operation.go +++ b/pkg/engine/operations/error/operation.go @@ -10,10 +10,10 @@ import ( "github.com/kyverno/chainsaw/pkg/engine/checks" "github.com/kyverno/chainsaw/pkg/engine/logging" "github.com/kyverno/chainsaw/pkg/engine/namespacer" + "github.com/kyverno/chainsaw/pkg/engine/operations" + "github.com/kyverno/chainsaw/pkg/engine/operations/internal" "github.com/kyverno/chainsaw/pkg/engine/outputs" "github.com/kyverno/chainsaw/pkg/engine/templating" - "github.com/kyverno/chainsaw/pkg/runner/operations" - "github.com/kyverno/chainsaw/pkg/runner/operations/internal" "go.uber.org/multierr" kerrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -66,7 +66,7 @@ func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (_ outp func (o *operation) execute(ctx context.Context, bindings binding.Bindings, obj unstructured.Unstructured) error { var lastErrs []error - err := wait.PollUntilContextCancel(ctx, internal.PollInterval, false, func(ctx context.Context) (_ bool, err error) { + err := wait.PollUntilContextCancel(ctx, client.PollInterval, false, func(ctx context.Context) (_ bool, err error) { var errs []error defer func() { // record last errors only if there was no real error diff --git a/pkg/runner/operations/error/operation_test.go b/pkg/engine/operations/error/operation_test.go similarity index 100% rename from pkg/runner/operations/error/operation_test.go rename to pkg/engine/operations/error/operation_test.go diff --git a/pkg/runner/operations/errors/resource.go b/pkg/engine/operations/errors/resource.go similarity index 100% rename from pkg/runner/operations/errors/resource.go rename to pkg/engine/operations/errors/resource.go diff --git a/pkg/runner/operations/internal/command_output.go b/pkg/engine/operations/internal/command_output.go similarity index 100% rename from pkg/runner/operations/internal/command_output.go rename to pkg/engine/operations/internal/command_output.go diff --git a/pkg/runner/operations/internal/command_output_test.go b/pkg/engine/operations/internal/command_output_test.go similarity index 100% rename from pkg/runner/operations/internal/command_output_test.go rename to pkg/engine/operations/internal/command_output_test.go diff --git a/pkg/runner/operations/internal/env.go b/pkg/engine/operations/internal/env.go similarity index 100% rename from pkg/runner/operations/internal/env.go rename to pkg/engine/operations/internal/env.go diff --git a/pkg/runner/operations/internal/log.go b/pkg/engine/operations/internal/log.go similarity index 100% rename from pkg/runner/operations/internal/log.go rename to pkg/engine/operations/internal/log.go diff --git a/pkg/runner/operations/internal/log_test.go b/pkg/engine/operations/internal/log_test.go similarity index 100% rename from pkg/runner/operations/internal/log_test.go rename to pkg/engine/operations/internal/log_test.go diff --git a/pkg/runner/operations/internal/namespace.go b/pkg/engine/operations/internal/namespace.go similarity index 100% rename from pkg/runner/operations/internal/namespace.go rename to pkg/engine/operations/internal/namespace.go diff --git a/pkg/runner/operations/internal/namespace_test.go b/pkg/engine/operations/internal/namespace_test.go similarity index 100% rename from pkg/runner/operations/internal/namespace_test.go rename to pkg/engine/operations/internal/namespace_test.go diff --git a/pkg/runner/operations/internal/read.go b/pkg/engine/operations/internal/read.go similarity index 100% rename from pkg/runner/operations/internal/read.go rename to pkg/engine/operations/internal/read.go diff --git a/pkg/runner/operations/internal/read_test.go b/pkg/engine/operations/internal/read_test.go similarity index 100% rename from pkg/runner/operations/internal/read_test.go rename to pkg/engine/operations/internal/read_test.go diff --git a/pkg/runner/operations/operation.go b/pkg/engine/operations/operation.go similarity index 100% rename from pkg/runner/operations/operation.go rename to pkg/engine/operations/operation.go diff --git a/pkg/runner/operations/patch/operation.go b/pkg/engine/operations/patch/operation.go similarity index 94% rename from pkg/runner/operations/patch/operation.go rename to pkg/engine/operations/patch/operation.go index d8604eef9..5d790d5ef 100644 --- a/pkg/runner/operations/patch/operation.go +++ b/pkg/engine/operations/patch/operation.go @@ -10,10 +10,10 @@ import ( "github.com/kyverno/chainsaw/pkg/engine/checks" "github.com/kyverno/chainsaw/pkg/engine/logging" "github.com/kyverno/chainsaw/pkg/engine/namespacer" + "github.com/kyverno/chainsaw/pkg/engine/operations" + "github.com/kyverno/chainsaw/pkg/engine/operations/internal" "github.com/kyverno/chainsaw/pkg/engine/outputs" "github.com/kyverno/chainsaw/pkg/engine/templating" - "github.com/kyverno/chainsaw/pkg/runner/operations" - "github.com/kyverno/chainsaw/pkg/runner/operations/internal" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/json" @@ -76,7 +76,7 @@ func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (_ outp func (o *operation) execute(ctx context.Context, bindings binding.Bindings, obj unstructured.Unstructured) (outputs.Outputs, error) { var lastErr error var outputs outputs.Outputs - err := wait.PollUntilContextCancel(ctx, internal.PollInterval, false, func(ctx context.Context) (bool, error) { + err := wait.PollUntilContextCancel(ctx, client.PollInterval, false, func(ctx context.Context) (bool, error) { outputs, lastErr = o.tryPatchResource(ctx, bindings, obj) // TODO: determine if the error can be retried return lastErr == nil, nil diff --git a/pkg/runner/operations/patch/operation_test.go b/pkg/engine/operations/patch/operation_test.go similarity index 100% rename from pkg/runner/operations/patch/operation_test.go rename to pkg/engine/operations/patch/operation_test.go diff --git a/pkg/runner/operations/script/operation.go b/pkg/engine/operations/script/operation.go similarity index 96% rename from pkg/runner/operations/script/operation.go rename to pkg/engine/operations/script/operation.go index a860f4bfa..f2c7e15e1 100644 --- a/pkg/runner/operations/script/operation.go +++ b/pkg/engine/operations/script/operation.go @@ -11,9 +11,9 @@ import ( apibindings "github.com/kyverno/chainsaw/pkg/engine/bindings" "github.com/kyverno/chainsaw/pkg/engine/checks" "github.com/kyverno/chainsaw/pkg/engine/logging" + "github.com/kyverno/chainsaw/pkg/engine/operations" + "github.com/kyverno/chainsaw/pkg/engine/operations/internal" "github.com/kyverno/chainsaw/pkg/engine/outputs" - "github.com/kyverno/chainsaw/pkg/runner/operations" - "github.com/kyverno/chainsaw/pkg/runner/operations/internal" restutils "github.com/kyverno/chainsaw/pkg/utils/rest" "github.com/kyverno/pkg/ext/output/color" "k8s.io/client-go/rest" diff --git a/pkg/runner/operations/script/operation_test.go b/pkg/engine/operations/script/operation_test.go similarity index 100% rename from pkg/runner/operations/script/operation_test.go rename to pkg/engine/operations/script/operation_test.go diff --git a/pkg/runner/operations/sleep/operation.go b/pkg/engine/operations/sleep/operation.go similarity index 87% rename from pkg/runner/operations/sleep/operation.go rename to pkg/engine/operations/sleep/operation.go index 0de1061c8..024c77c72 100644 --- a/pkg/runner/operations/sleep/operation.go +++ b/pkg/engine/operations/sleep/operation.go @@ -7,9 +7,9 @@ import ( "github.com/jmespath-community/go-jmespath/pkg/binding" "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" "github.com/kyverno/chainsaw/pkg/engine/logging" + "github.com/kyverno/chainsaw/pkg/engine/operations" + "github.com/kyverno/chainsaw/pkg/engine/operations/internal" "github.com/kyverno/chainsaw/pkg/engine/outputs" - "github.com/kyverno/chainsaw/pkg/runner/operations" - "github.com/kyverno/chainsaw/pkg/runner/operations/internal" ) type operation struct { diff --git a/pkg/runner/operations/sleep/operation_test.go b/pkg/engine/operations/sleep/operation_test.go similarity index 100% rename from pkg/runner/operations/sleep/operation_test.go rename to pkg/engine/operations/sleep/operation_test.go diff --git a/pkg/runner/operations/testing/mock.go b/pkg/engine/operations/testing/mock.go similarity index 100% rename from pkg/runner/operations/testing/mock.go rename to pkg/engine/operations/testing/mock.go diff --git a/pkg/runner/operations/update/operation.go b/pkg/engine/operations/update/operation.go similarity index 94% rename from pkg/runner/operations/update/operation.go rename to pkg/engine/operations/update/operation.go index b2e7af237..8c84bf189 100644 --- a/pkg/runner/operations/update/operation.go +++ b/pkg/engine/operations/update/operation.go @@ -11,10 +11,10 @@ import ( "github.com/kyverno/chainsaw/pkg/engine/checks" "github.com/kyverno/chainsaw/pkg/engine/logging" "github.com/kyverno/chainsaw/pkg/engine/namespacer" + "github.com/kyverno/chainsaw/pkg/engine/operations" + "github.com/kyverno/chainsaw/pkg/engine/operations/internal" "github.com/kyverno/chainsaw/pkg/engine/outputs" "github.com/kyverno/chainsaw/pkg/engine/templating" - "github.com/kyverno/chainsaw/pkg/runner/operations" - "github.com/kyverno/chainsaw/pkg/runner/operations/internal" kerrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/util/wait" @@ -78,7 +78,7 @@ func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (_ outp func (o *operation) execute(ctx context.Context, bindings binding.Bindings, obj unstructured.Unstructured) (outputs.Outputs, error) { var lastErr error var outputs outputs.Outputs - err := wait.PollUntilContextCancel(ctx, internal.PollInterval, false, func(ctx context.Context) (bool, error) { + err := wait.PollUntilContextCancel(ctx, client.PollInterval, false, func(ctx context.Context) (bool, error) { outputs, lastErr = o.tryUpdateResource(ctx, bindings, obj) // TODO: determine if the error can be retried return lastErr == nil, nil diff --git a/pkg/runner/operations/update/operation_test.go b/pkg/engine/operations/update/operation_test.go similarity index 100% rename from pkg/runner/operations/update/operation_test.go rename to pkg/engine/operations/update/operation_test.go diff --git a/pkg/runner/operations/internal/interval.go b/pkg/runner/operations/internal/interval.go deleted file mode 100644 index 0be54e138..000000000 --- a/pkg/runner/operations/internal/interval.go +++ /dev/null @@ -1,7 +0,0 @@ -package internal - -import ( - "time" -) - -const PollInterval = 50 * time.Millisecond diff --git a/pkg/runner/processors/operation.go b/pkg/runner/processors/operation.go index fde9bd078..6aa524944 100644 --- a/pkg/runner/processors/operation.go +++ b/pkg/runner/processors/operation.go @@ -6,10 +6,10 @@ import ( "github.com/kyverno/chainsaw/pkg/engine" "github.com/kyverno/chainsaw/pkg/engine/logging" + "github.com/kyverno/chainsaw/pkg/engine/operations" "github.com/kyverno/chainsaw/pkg/engine/outputs" "github.com/kyverno/chainsaw/pkg/report" "github.com/kyverno/chainsaw/pkg/runner/failer" - "github.com/kyverno/chainsaw/pkg/runner/operations" "github.com/kyverno/pkg/ext/output/color" ) diff --git a/pkg/runner/processors/operation_test.go b/pkg/runner/processors/operation_test.go index be3c66356..bac5d5e68 100644 --- a/pkg/runner/processors/operation_test.go +++ b/pkg/runner/processors/operation_test.go @@ -8,10 +8,10 @@ import ( "github.com/jmespath-community/go-jmespath/pkg/binding" "github.com/kyverno/chainsaw/pkg/engine" enginecontext "github.com/kyverno/chainsaw/pkg/engine/context" + "github.com/kyverno/chainsaw/pkg/engine/operations" + mock "github.com/kyverno/chainsaw/pkg/engine/operations/testing" "github.com/kyverno/chainsaw/pkg/engine/outputs" "github.com/kyverno/chainsaw/pkg/report" - "github.com/kyverno/chainsaw/pkg/runner/operations" - mock "github.com/kyverno/chainsaw/pkg/runner/operations/testing" "github.com/kyverno/chainsaw/pkg/testing" "github.com/stretchr/testify/assert" ) diff --git a/pkg/runner/processors/step.go b/pkg/runner/processors/step.go index adf0b1104..b6aca9345 100644 --- a/pkg/runner/processors/step.go +++ b/pkg/runner/processors/step.go @@ -13,20 +13,20 @@ import ( "github.com/kyverno/chainsaw/pkg/engine/kubectl" "github.com/kyverno/chainsaw/pkg/engine/logging" "github.com/kyverno/chainsaw/pkg/engine/namespacer" + "github.com/kyverno/chainsaw/pkg/engine/operations" + opapply "github.com/kyverno/chainsaw/pkg/engine/operations/apply" + opassert "github.com/kyverno/chainsaw/pkg/engine/operations/assert" + opcommand "github.com/kyverno/chainsaw/pkg/engine/operations/command" + opcreate "github.com/kyverno/chainsaw/pkg/engine/operations/create" + opdelete "github.com/kyverno/chainsaw/pkg/engine/operations/delete" + operror "github.com/kyverno/chainsaw/pkg/engine/operations/error" + oppatch "github.com/kyverno/chainsaw/pkg/engine/operations/patch" + opscript "github.com/kyverno/chainsaw/pkg/engine/operations/script" + opsleep "github.com/kyverno/chainsaw/pkg/engine/operations/sleep" + opupdate "github.com/kyverno/chainsaw/pkg/engine/operations/update" "github.com/kyverno/chainsaw/pkg/loaders/resource" "github.com/kyverno/chainsaw/pkg/report" "github.com/kyverno/chainsaw/pkg/runner/failer" - "github.com/kyverno/chainsaw/pkg/runner/operations" - opapply "github.com/kyverno/chainsaw/pkg/runner/operations/apply" - opassert "github.com/kyverno/chainsaw/pkg/runner/operations/assert" - opcommand "github.com/kyverno/chainsaw/pkg/runner/operations/command" - opcreate "github.com/kyverno/chainsaw/pkg/runner/operations/create" - opdelete "github.com/kyverno/chainsaw/pkg/runner/operations/delete" - operror "github.com/kyverno/chainsaw/pkg/runner/operations/error" - oppatch "github.com/kyverno/chainsaw/pkg/runner/operations/patch" - opscript "github.com/kyverno/chainsaw/pkg/runner/operations/script" - opsleep "github.com/kyverno/chainsaw/pkg/runner/operations/sleep" - opupdate "github.com/kyverno/chainsaw/pkg/runner/operations/update" "github.com/kyverno/chainsaw/pkg/runner/timeout" "github.com/kyverno/chainsaw/pkg/testing" "github.com/kyverno/pkg/ext/output/color"