diff --git a/pkg/bootstrap/isogen/command.go b/pkg/bootstrap/isogen/command.go index 819ceaa7c..10b2ff1ce 100644 --- a/pkg/bootstrap/isogen/command.go +++ b/pkg/bootstrap/isogen/command.go @@ -105,13 +105,6 @@ func getContainerCfg( return fls } -func verifyArtifacts(cfg *v1alpha1.ImageConfiguration) error { - hostVol := strings.Split(cfg.Container.Volume, ":")[0] - metadataPath := filepath.Join(hostVol, cfg.Builder.OutputMetadataFileName) - _, err := os.Stat(metadataPath) - return err -} - // CreateBootstrapIso prepares and runs appropriate container to create a bootstrap ISO func (opts BootstrapIsoOptions) CreateBootstrapIso() error { cntVol := strings.Split(opts.Cfg.Container.Volume, ":")[1] diff --git a/pkg/bootstrap/isogen/errors.go b/pkg/bootstrap/isogen/errors.go index ab037bc9f..9c2adc29c 100644 --- a/pkg/bootstrap/isogen/errors.go +++ b/pkg/bootstrap/isogen/errors.go @@ -14,14 +14,6 @@ package isogen -// ErrIsoGenNilBundle is returned when isogen executor is not provided with bundle -type ErrIsoGenNilBundle struct { -} - -func (e ErrIsoGenNilBundle) Error() string { - return "Cannot build iso with empty bundle, no data source is available" -} - // ErrNoParsedNumPkgs is returned when it's unable to find number of packages to install type ErrNoParsedNumPkgs struct { } diff --git a/pkg/phase/client.go b/pkg/phase/client.go index df3d13ab6..88cbe0ee5 100644 --- a/pkg/phase/client.go +++ b/pkg/phase/client.go @@ -21,7 +21,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "opendev.org/airship/airshipctl/pkg/api/v1alpha1" - "opendev.org/airship/airshipctl/pkg/bootstrap/isogen" "opendev.org/airship/airshipctl/pkg/container" "opendev.org/airship/airshipctl/pkg/document" "opendev.org/airship/airshipctl/pkg/events" @@ -46,7 +45,7 @@ func DefaultExecutorRegistry() map[schema.GroupVersionKind]ifc.ExecutorFactory { if err := applier.RegisterExecutor(execMap); err != nil { log.Fatal(ErrExecutorRegistration{ExecutorName: "kubernetes-apply", Err: err}) } - if err := isogen.RegisterExecutor(execMap); err != nil { + if err := executors.RegisterIsogenExecutor(execMap); err != nil { log.Fatal(ErrExecutorRegistration{ExecutorName: "isogen", Err: err}) } if err := container.RegisterExecutor(execMap); err != nil { diff --git a/pkg/phase/executors/errors.go b/pkg/phase/executors/errors.go index ca49e5977..a17da11ba 100755 --- a/pkg/phase/executors/errors.go +++ b/pkg/phase/executors/errors.go @@ -27,3 +27,11 @@ type ErrUnknownExecutorAction struct { func (e ErrUnknownExecutorAction) Error() string { return fmt.Sprintf("unknown action type '%s'", e.Action) } + +// ErrIsoGenNilBundle is returned when isogen executor is not provided with bundle +type ErrIsoGenNilBundle struct { +} + +func (e ErrIsoGenNilBundle) Error() string { + return "Cannot build iso with empty bundle, no data source is available" +} diff --git a/pkg/bootstrap/isogen/executor.go b/pkg/phase/executors/isogen.go similarity index 76% rename from pkg/bootstrap/isogen/executor.go rename to pkg/phase/executors/isogen.go index 683080885..8f15d407a 100644 --- a/pkg/bootstrap/isogen/executor.go +++ b/pkg/phase/executors/isogen.go @@ -12,15 +12,19 @@ limitations under the License. */ -package isogen +package executors import ( "context" "io" + "os" + "path/filepath" + "strings" "k8s.io/apimachinery/pkg/runtime/schema" "opendev.org/airship/airshipctl/pkg/api/v1alpha1" + "opendev.org/airship/airshipctl/pkg/bootstrap/isogen" "opendev.org/airship/airshipctl/pkg/container" "opendev.org/airship/airshipctl/pkg/document" "opendev.org/airship/airshipctl/pkg/errors" @@ -29,10 +33,10 @@ import ( "opendev.org/airship/airshipctl/pkg/phase/ifc" ) -var _ ifc.Executor = &Executor{} +var _ ifc.Executor = &IsogenExecutor{} -// Executor contains resources for isogen executor -type Executor struct { +// IsogenExecutor contains resources for isogen executor +type IsogenExecutor struct { ExecutorBundle document.Bundle ExecutorDocument document.Document @@ -40,19 +44,19 @@ type Executor struct { Builder container.Container } -// RegisterExecutor adds executor to phase executor registry -func RegisterExecutor(registry map[schema.GroupVersionKind]ifc.ExecutorFactory) error { +// RegisterIsogenExecutor adds executor to phase executor registry +func RegisterIsogenExecutor(registry map[schema.GroupVersionKind]ifc.ExecutorFactory) error { obj := v1alpha1.DefaultImageConfiguration() gvks, _, err := v1alpha1.Scheme.ObjectKinds(obj) if err != nil { return err } - registry[gvks[0]] = NewExecutor + registry[gvks[0]] = NewIsogenExecutor return nil } -// NewExecutor creates instance of phase executor -func NewExecutor(cfg ifc.ExecutorConfig) (ifc.Executor, error) { +// NewIsogenExecutor creates instance of phase executor +func NewIsogenExecutor(cfg ifc.ExecutorConfig) (ifc.Executor, error) { apiObj := &v1alpha1.ImageConfiguration{ Container: &v1alpha1.Container{}, Builder: &v1alpha1.Builder{}, @@ -67,7 +71,7 @@ func NewExecutor(cfg ifc.ExecutorConfig) (ifc.Executor, error) { return nil, err } - return &Executor{ + return &IsogenExecutor{ ExecutorBundle: bundle, ExecutorDocument: cfg.ExecutorDocument, ImgConf: apiObj, @@ -75,7 +79,7 @@ func NewExecutor(cfg ifc.ExecutorConfig) (ifc.Executor, error) { } // Run isogen as a phase runner -func (c *Executor) Run(evtCh chan events.Event, opts ifc.RunOptions) { +func (c *IsogenExecutor) Run(evtCh chan events.Event, opts ifc.RunOptions) { defer close(evtCh) if c.ExecutorBundle == nil { @@ -109,7 +113,7 @@ func (c *Executor) Run(evtCh chan events.Event, opts ifc.RunOptions) { } } - bootstrapOpts := BootstrapIsoOptions{ + bootstrapOpts := isogen.BootstrapIsoOptions{ DocBundle: c.ExecutorBundle, Builder: c.Builder, Doc: c.ExecutorDocument, @@ -141,13 +145,20 @@ func (c *Executor) Run(evtCh chan events.Event, opts ifc.RunOptions) { }) } +func verifyArtifacts(cfg *v1alpha1.ImageConfiguration) error { + hostVol := strings.Split(cfg.Container.Volume, ":")[0] + metadataPath := filepath.Join(hostVol, cfg.Builder.OutputMetadataFileName) + _, err := os.Stat(metadataPath) + return err +} + // Validate executor configuration and documents -func (c *Executor) Validate() error { +func (c *IsogenExecutor) Validate() error { return errors.ErrNotImplemented{} } // Render executor documents -func (c *Executor) Render(w io.Writer, _ ifc.RenderOptions) error { +func (c *IsogenExecutor) Render(w io.Writer, _ ifc.RenderOptions) error { // will be implemented later _, err := w.Write([]byte{}) return err diff --git a/pkg/bootstrap/isogen/executor_test.go b/pkg/phase/executors/isogen_test.go similarity index 88% rename from pkg/bootstrap/isogen/executor_test.go rename to pkg/phase/executors/isogen_test.go index 62c3e21f6..3f242ce7f 100644 --- a/pkg/bootstrap/isogen/executor_test.go +++ b/pkg/phase/executors/isogen_test.go @@ -12,7 +12,7 @@ limitations under the License. */ -package isogen_test +package executors_test import ( "testing" @@ -23,10 +23,10 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "opendev.org/airship/airshipctl/pkg/api/v1alpha1" - "opendev.org/airship/airshipctl/pkg/bootstrap/isogen" "opendev.org/airship/airshipctl/pkg/container" "opendev.org/airship/airshipctl/pkg/document" "opendev.org/airship/airshipctl/pkg/events" + "opendev.org/airship/airshipctl/pkg/phase/executors" "opendev.org/airship/airshipctl/pkg/phase/ifc" "opendev.org/airship/airshipctl/testutil" testcontainer "opendev.org/airship/airshipctl/testutil/container" @@ -34,7 +34,7 @@ import ( ) var ( - executorDoc = ` + isogenExecutorDoc = ` apiVersion: airshipit.org/v1alpha1 kind: ImageConfiguration metadata: @@ -49,33 +49,33 @@ container: containerRuntime: docker image: quay.io/airshipit/isogen:latest-ubuntu_focal volume: /srv/iso:/config` - executorBundlePath = "testdata/primary/site/test-site/ephemeral/bootstrap" + executorBundlePath = "../../bootstrap/isogen/testdata/primary/site/test-site/ephemeral/bootstrap" ) -func TestRegisterExecutor(t *testing.T) { +func TestRegisterIsogenExecutor(t *testing.T) { registry := make(map[schema.GroupVersionKind]ifc.ExecutorFactory) expectedGVK := schema.GroupVersionKind{ Group: "airshipit.org", Version: "v1alpha1", Kind: "ImageConfiguration", } - err := isogen.RegisterExecutor(registry) + err := executors.RegisterIsogenExecutor(registry) require.NoError(t, err) _, found := registry[expectedGVK] assert.True(t, found) } -func TestNewExecutor(t *testing.T) { - execDoc, err := document.NewDocumentFromBytes([]byte(executorDoc)) +func TestNewIsogenExecutor(t *testing.T) { + execDoc, err := document.NewDocumentFromBytes([]byte(isogenExecutorDoc)) require.NoError(t, err) - _, err = isogen.NewExecutor(ifc.ExecutorConfig{ + _, err = executors.NewIsogenExecutor(ifc.ExecutorConfig{ ExecutorDocument: execDoc, BundleFactory: testBundleFactory(executorBundlePath)}) require.NoError(t, err) } -func TestExecutorRun(t *testing.T) { +func TestIsogenExecutorRun(t *testing.T) { bundle, err := document.NewBundleByPath(executorBundlePath) require.NoError(t, err) require.NotNil(t, bundle) @@ -144,7 +144,7 @@ func TestExecutorRun(t *testing.T) { for _, test := range testCases { tt := test t.Run(tt.name, func(t *testing.T) { - executor := &isogen.Executor{ + executor := &executors.IsogenExecutor{ ExecutorDocument: testDoc, ExecutorBundle: bundle, ImgConf: testCfg, @@ -171,12 +171,6 @@ func TestExecutorRun(t *testing.T) { } } -func wrapError(err error) events.Event { - return events.NewEvent().WithErrorEvent(events.ErrorEvent{ - Error: err, - }) -} - func testBundleFactory(path string) document.BundleFactoryFunc { return func() (document.Bundle, error) { return document.NewBundleByPath(path)