From 395aa537ca8c87ec048c4fb007fa888870f66ba8 Mon Sep 17 00:00:00 2001 From: Ruslan Aliev Date: Tue, 9 Mar 2021 19:26:42 -0600 Subject: [PATCH] Don't fail if docEntryPoint isn't defined for Container exec Input for this executor could be empty, so we have to handle ErrDocumentEntrypointNotDefined error more intelligently. Change-Id: I73e0f770e64cead7dbbbce2af2b7a2ebd323b83b Signed-off-by: Ruslan Aliev Relates-To: #485 Closes: #485 --- manifests/phases/phases.yaml | 1 - manifests/site/test-site/empty/kustomization.yaml | 0 pkg/phase/executors/container.go | 10 +++++++--- pkg/phase/executors/container_test.go | 13 +++++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) delete mode 100644 manifests/site/test-site/empty/kustomization.yaml diff --git a/manifests/phases/phases.yaml b/manifests/phases/phases.yaml index 144d56531..2b336cf23 100644 --- a/manifests/phases/phases.yaml +++ b/manifests/phases/phases.yaml @@ -278,4 +278,3 @@ config: apiVersion: airshipit.org/v1alpha1 kind: GenericContainer name: iso-build-image - documentEntryPoint: empty diff --git a/manifests/site/test-site/empty/kustomization.yaml b/manifests/site/test-site/empty/kustomization.yaml deleted file mode 100644 index e69de29bb..000000000 diff --git a/pkg/phase/executors/container.go b/pkg/phase/executors/container.go index abfc0add7..7fa20019e 100644 --- a/pkg/phase/executors/container.go +++ b/pkg/phase/executors/container.go @@ -16,6 +16,7 @@ package executors import ( "bytes" + goerrors "errors" "io" "os" "path/filepath" @@ -27,6 +28,7 @@ import ( "opendev.org/airship/airshipctl/pkg/events" "opendev.org/airship/airshipctl/pkg/k8s/kubeconfig" "opendev.org/airship/airshipctl/pkg/log" + "opendev.org/airship/airshipctl/pkg/phase/errors" "opendev.org/airship/airshipctl/pkg/phase/ifc" ) @@ -46,9 +48,12 @@ type ContainerExecutor struct { // NewContainerExecutor creates instance of phase executor func NewContainerExecutor(cfg ifc.ExecutorConfig) (ifc.Executor, error) { - // TODO add logic that checks if the path was not defined, and if so, we are fine - // and bundle should be either nil or empty, consider ContinueOnEmptyInput option to container client bundle, err := cfg.BundleFactory() + // ErrDocumentEntrypointNotDefined error should not cause Container executor to fail, so filter it + if err != nil && goerrors.As(err, &errors.ErrDocumentEntrypointNotDefined{}) { + // if docEntryPoint isn't defined initialize empty bundle instead to safely use it without nil checks + bundle, err = document.NewBundleFromBytes([]byte{}) + } if err != nil { return nil, err } @@ -95,7 +100,6 @@ func (c *ContainerExecutor) Run(evtCh chan events.Event, opts ifc.RunOptions) { input, err := bundleReader(c.ExecutorBundle) if err != nil { - // TODO move bundleFactory here, and make sure that if executorDoc is not defined, we dont fail handleError(evtCh, err) return } diff --git a/pkg/phase/executors/container_test.go b/pkg/phase/executors/container_test.go index a24d825d2..be7ffa438 100644 --- a/pkg/phase/executors/container_test.go +++ b/pkg/phase/executors/container_test.go @@ -26,6 +26,7 @@ import ( "opendev.org/airship/airshipctl/pkg/document" "opendev.org/airship/airshipctl/pkg/events" "opendev.org/airship/airshipctl/pkg/k8s/kubeconfig" + "opendev.org/airship/airshipctl/pkg/phase/errors" "opendev.org/airship/airshipctl/pkg/phase/executors" "opendev.org/airship/airshipctl/pkg/phase/ifc" ) @@ -84,6 +85,18 @@ func TestNewContainerExecutor(t *testing.T) { assert.Error(t, err) assert.Nil(t, e) }) + + t.Run("bundle factory - empty documentEntryPoint", func(t *testing.T) { + e, err := executors.NewContainerExecutor(ifc.ExecutorConfig{ + ExecutorDocument: execDoc, + BundleFactory: func() (document.Bundle, error) { + return nil, errors.ErrDocumentEntrypointNotDefined{} + }, + Helper: makeDefaultHelper(t, "../../container/testdata", "metadata.yaml"), + }) + assert.NoError(t, err) + assert.NotNil(t, e) + }) } func TestGenericContainer(t *testing.T) {