Merge "Don't fail if docEntryPoint isn't defined for Container exec"
This commit is contained in:
commit
4e296dacab
@ -278,4 +278,3 @@ config:
|
|||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
kind: GenericContainer
|
kind: GenericContainer
|
||||||
name: iso-build-image
|
name: iso-build-image
|
||||||
documentEntryPoint: empty
|
|
||||||
|
@ -16,6 +16,7 @@ package executors
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
goerrors "errors"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -27,6 +28,7 @@ import (
|
|||||||
"opendev.org/airship/airshipctl/pkg/events"
|
"opendev.org/airship/airshipctl/pkg/events"
|
||||||
"opendev.org/airship/airshipctl/pkg/k8s/kubeconfig"
|
"opendev.org/airship/airshipctl/pkg/k8s/kubeconfig"
|
||||||
"opendev.org/airship/airshipctl/pkg/log"
|
"opendev.org/airship/airshipctl/pkg/log"
|
||||||
|
"opendev.org/airship/airshipctl/pkg/phase/errors"
|
||||||
"opendev.org/airship/airshipctl/pkg/phase/ifc"
|
"opendev.org/airship/airshipctl/pkg/phase/ifc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,9 +48,12 @@ type ContainerExecutor struct {
|
|||||||
|
|
||||||
// NewContainerExecutor creates instance of phase executor
|
// NewContainerExecutor creates instance of phase executor
|
||||||
func NewContainerExecutor(cfg ifc.ExecutorConfig) (ifc.Executor, error) {
|
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()
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -95,7 +100,6 @@ func (c *ContainerExecutor) Run(evtCh chan events.Event, opts ifc.RunOptions) {
|
|||||||
|
|
||||||
input, err := bundleReader(c.ExecutorBundle)
|
input, err := bundleReader(c.ExecutorBundle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO move bundleFactory here, and make sure that if executorDoc is not defined, we dont fail
|
|
||||||
handleError(evtCh, err)
|
handleError(evtCh, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"opendev.org/airship/airshipctl/pkg/document"
|
"opendev.org/airship/airshipctl/pkg/document"
|
||||||
"opendev.org/airship/airshipctl/pkg/events"
|
"opendev.org/airship/airshipctl/pkg/events"
|
||||||
"opendev.org/airship/airshipctl/pkg/k8s/kubeconfig"
|
"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/executors"
|
||||||
"opendev.org/airship/airshipctl/pkg/phase/ifc"
|
"opendev.org/airship/airshipctl/pkg/phase/ifc"
|
||||||
)
|
)
|
||||||
@ -84,6 +85,18 @@ func TestNewContainerExecutor(t *testing.T) {
|
|||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Nil(t, e)
|
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) {
|
func TestGenericContainer(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user