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 <raliev@mirantis.com>
Relates-To: #485
Closes: #485
This commit is contained in:
Ruslan Aliev 2021-03-09 19:26:42 -06:00
parent 8bed52b057
commit 395aa537ca
4 changed files with 20 additions and 4 deletions

View File

@ -278,4 +278,3 @@ config:
apiVersion: airshipit.org/v1alpha1
kind: GenericContainer
name: iso-build-image
documentEntryPoint: empty

View File

@ -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
}

View File

@ -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) {