Move clusterctl phase executor to a separate package
Having an executor within clusterctl.client package creates potential import cycling. This patch moves it to a separate package which can be used to conveniently store all the executors at one place. Change-Id: Ib0a6072a393e68885d9ef911aa2894a0de055668 Signed-off-by: Ruslan Aliev <raliev@mirantis.com> Relates-To: #374
This commit is contained in:
parent
b799edc0a7
commit
71dc1d4703
@ -36,13 +36,3 @@ type ErrProviderRepoNotFound struct {
|
|||||||
func (e ErrProviderRepoNotFound) Error() string {
|
func (e ErrProviderRepoNotFound) Error() string {
|
||||||
return fmt.Sprintf("failed to find repository for provider %s of type %s", e.ProviderName, e.ProviderType)
|
return fmt.Sprintf("failed to find repository for provider %s of type %s", e.ProviderName, e.ProviderType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrUnknownExecutorAction is returned for unknown action parameter
|
|
||||||
// in clusterctl configuration document
|
|
||||||
type ErrUnknownExecutorAction struct {
|
|
||||||
Action string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e ErrUnknownExecutorAction) Error() string {
|
|
||||||
return fmt.Sprintf("unknown action type '%s'", e.Action)
|
|
||||||
}
|
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
|
|
||||||
"opendev.org/airship/airshipctl/pkg/api/v1alpha1"
|
"opendev.org/airship/airshipctl/pkg/api/v1alpha1"
|
||||||
"opendev.org/airship/airshipctl/pkg/bootstrap/isogen"
|
"opendev.org/airship/airshipctl/pkg/bootstrap/isogen"
|
||||||
clusterctl "opendev.org/airship/airshipctl/pkg/clusterctl/client"
|
|
||||||
"opendev.org/airship/airshipctl/pkg/container"
|
"opendev.org/airship/airshipctl/pkg/container"
|
||||||
"opendev.org/airship/airshipctl/pkg/document"
|
"opendev.org/airship/airshipctl/pkg/document"
|
||||||
"opendev.org/airship/airshipctl/pkg/events"
|
"opendev.org/airship/airshipctl/pkg/events"
|
||||||
@ -30,6 +29,7 @@ import (
|
|||||||
"opendev.org/airship/airshipctl/pkg/k8s/kubeconfig"
|
"opendev.org/airship/airshipctl/pkg/k8s/kubeconfig"
|
||||||
"opendev.org/airship/airshipctl/pkg/k8s/utils"
|
"opendev.org/airship/airshipctl/pkg/k8s/utils"
|
||||||
"opendev.org/airship/airshipctl/pkg/log"
|
"opendev.org/airship/airshipctl/pkg/log"
|
||||||
|
"opendev.org/airship/airshipctl/pkg/phase/executors"
|
||||||
"opendev.org/airship/airshipctl/pkg/phase/ifc"
|
"opendev.org/airship/airshipctl/pkg/phase/ifc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ type ExecutorRegistry func() map[schema.GroupVersionKind]ifc.ExecutorFactory
|
|||||||
func DefaultExecutorRegistry() map[schema.GroupVersionKind]ifc.ExecutorFactory {
|
func DefaultExecutorRegistry() map[schema.GroupVersionKind]ifc.ExecutorFactory {
|
||||||
execMap := make(map[schema.GroupVersionKind]ifc.ExecutorFactory)
|
execMap := make(map[schema.GroupVersionKind]ifc.ExecutorFactory)
|
||||||
|
|
||||||
if err := clusterctl.RegisterExecutor(execMap); err != nil {
|
if err := executors.RegisterExecutor(execMap); err != nil {
|
||||||
log.Fatal(ErrExecutorRegistration{ExecutorName: "clusterctl", Err: err})
|
log.Fatal(ErrExecutorRegistration{ExecutorName: "clusterctl", Err: err})
|
||||||
}
|
}
|
||||||
if err := applier.RegisterExecutor(execMap); err != nil {
|
if err := applier.RegisterExecutor(execMap); err != nil {
|
||||||
|
7
pkg/clusterctl/client/executor.go → pkg/phase/executors/clusterctl.go
Normal file → Executable file
7
pkg/clusterctl/client/executor.go → pkg/phase/executors/clusterctl.go
Normal file → Executable file
@ -12,7 +12,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package client
|
package executors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
@ -21,6 +21,7 @@ import (
|
|||||||
|
|
||||||
airshipv1 "opendev.org/airship/airshipctl/pkg/api/v1alpha1"
|
airshipv1 "opendev.org/airship/airshipctl/pkg/api/v1alpha1"
|
||||||
"opendev.org/airship/airshipctl/pkg/cluster/clustermap"
|
"opendev.org/airship/airshipctl/pkg/cluster/clustermap"
|
||||||
|
"opendev.org/airship/airshipctl/pkg/clusterctl/client"
|
||||||
"opendev.org/airship/airshipctl/pkg/errors"
|
"opendev.org/airship/airshipctl/pkg/errors"
|
||||||
"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"
|
||||||
@ -34,7 +35,7 @@ var _ ifc.Executor = &ClusterctlExecutor{}
|
|||||||
type ClusterctlExecutor struct {
|
type ClusterctlExecutor struct {
|
||||||
clusterName string
|
clusterName string
|
||||||
|
|
||||||
Interface
|
client.Interface
|
||||||
clusterMap clustermap.ClusterMap
|
clusterMap clustermap.ClusterMap
|
||||||
options *airshipv1.Clusterctl
|
options *airshipv1.Clusterctl
|
||||||
kubecfg kubeconfig.Interface
|
kubecfg kubeconfig.Interface
|
||||||
@ -57,7 +58,7 @@ func NewExecutor(cfg ifc.ExecutorConfig) (ifc.Executor, error) {
|
|||||||
if err := cfg.ExecutorDocument.ToAPIObject(options, airshipv1.Scheme); err != nil {
|
if err := cfg.ExecutorDocument.ToAPIObject(options, airshipv1.Scheme); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
client, err := NewClient(cfg.Helper.TargetPath(), log.DebugEnabled(), options)
|
client, err := client.NewClient(cfg.Helper.TargetPath(), log.DebugEnabled(), options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
20
pkg/clusterctl/client/executor_test.go → pkg/phase/executors/clusterctl_test.go
Normal file → Executable file
20
pkg/clusterctl/client/executor_test.go → pkg/phase/executors/clusterctl_test.go
Normal file → Executable file
@ -12,7 +12,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package client_test
|
package executors_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -23,12 +23,10 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
|
||||||
"opendev.org/airship/airshipctl/pkg/api/v1alpha1"
|
"opendev.org/airship/airshipctl/pkg/api/v1alpha1"
|
||||||
"opendev.org/airship/airshipctl/pkg/cluster/clustermap"
|
"opendev.org/airship/airshipctl/pkg/cluster/clustermap"
|
||||||
cctlclient "opendev.org/airship/airshipctl/pkg/clusterctl/client"
|
|
||||||
"opendev.org/airship/airshipctl/pkg/config"
|
"opendev.org/airship/airshipctl/pkg/config"
|
||||||
"opendev.org/airship/airshipctl/pkg/document"
|
"opendev.org/airship/airshipctl/pkg/document"
|
||||||
airerrors "opendev.org/airship/airshipctl/pkg/errors"
|
airerrors "opendev.org/airship/airshipctl/pkg/errors"
|
||||||
@ -36,6 +34,7 @@ import (
|
|||||||
"opendev.org/airship/airshipctl/pkg/fs"
|
"opendev.org/airship/airshipctl/pkg/fs"
|
||||||
"opendev.org/airship/airshipctl/pkg/k8s/kubeconfig"
|
"opendev.org/airship/airshipctl/pkg/k8s/kubeconfig"
|
||||||
"opendev.org/airship/airshipctl/pkg/phase"
|
"opendev.org/airship/airshipctl/pkg/phase"
|
||||||
|
"opendev.org/airship/airshipctl/pkg/phase/executors"
|
||||||
"opendev.org/airship/airshipctl/pkg/phase/ifc"
|
"opendev.org/airship/airshipctl/pkg/phase/ifc"
|
||||||
testfs "opendev.org/airship/airshipctl/testutil/fs"
|
testfs "opendev.org/airship/airshipctl/testutil/fs"
|
||||||
)
|
)
|
||||||
@ -67,7 +66,7 @@ func TestRegisterExecutor(t *testing.T) {
|
|||||||
Version: "v1alpha1",
|
Version: "v1alpha1",
|
||||||
Kind: "Clusterctl",
|
Kind: "Clusterctl",
|
||||||
}
|
}
|
||||||
err := cctlclient.RegisterExecutor(registry)
|
err := executors.RegisterExecutor(registry)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, found := registry[expectedGVK]
|
_, found := registry[expectedGVK]
|
||||||
@ -89,7 +88,7 @@ func TestNewExecutor(t *testing.T) {
|
|||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
tt := test
|
tt := test
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
_, actualErr := cctlclient.NewExecutor(ifc.ExecutorConfig{
|
_, actualErr := executors.NewExecutor(ifc.ExecutorConfig{
|
||||||
ExecutorDocument: sampleCfgDoc,
|
ExecutorDocument: sampleCfgDoc,
|
||||||
Helper: tt.helper,
|
Helper: tt.helper,
|
||||||
})
|
})
|
||||||
@ -114,7 +113,7 @@ func TestExecutorRun(t *testing.T) {
|
|||||||
cfgDoc: executorDoc(t, "someAction"),
|
cfgDoc: executorDoc(t, "someAction"),
|
||||||
bundlePath: "testdata/executor_init",
|
bundlePath: "testdata/executor_init",
|
||||||
expectedEvt: []events.Event{
|
expectedEvt: []events.Event{
|
||||||
wrapError(cctlclient.ErrUnknownExecutorAction{Action: "someAction"}),
|
wrapError(executors.ErrUnknownExecutorAction{Action: "someAction"}),
|
||||||
},
|
},
|
||||||
clusterMap: clustermap.NewClusterMap(v1alpha1.DefaultClusterMap()),
|
clusterMap: clustermap.NewClusterMap(v1alpha1.DefaultClusterMap()),
|
||||||
},
|
},
|
||||||
@ -168,7 +167,7 @@ func TestExecutorRun(t *testing.T) {
|
|||||||
kubeconfig.FromByte([]byte("someKubeConfig")),
|
kubeconfig.FromByte([]byte("someKubeConfig")),
|
||||||
kubeconfig.InjectFileSystem(tt.fs),
|
kubeconfig.InjectFileSystem(tt.fs),
|
||||||
)
|
)
|
||||||
executor, err := cctlclient.NewExecutor(
|
executor, err := executors.NewExecutor(
|
||||||
ifc.ExecutorConfig{
|
ifc.ExecutorConfig{
|
||||||
ExecutorDocument: tt.cfgDoc,
|
ExecutorDocument: tt.cfgDoc,
|
||||||
Helper: makeDefaultHelper(t),
|
Helper: makeDefaultHelper(t),
|
||||||
@ -199,7 +198,7 @@ func TestExecutorRun(t *testing.T) {
|
|||||||
|
|
||||||
func TestExecutorValidate(t *testing.T) {
|
func TestExecutorValidate(t *testing.T) {
|
||||||
sampleCfgDoc := executorDoc(t, "init")
|
sampleCfgDoc := executorDoc(t, "init")
|
||||||
executor, err := cctlclient.NewExecutor(
|
executor, err := executors.NewExecutor(
|
||||||
ifc.ExecutorConfig{
|
ifc.ExecutorConfig{
|
||||||
ExecutorDocument: sampleCfgDoc,
|
ExecutorDocument: sampleCfgDoc,
|
||||||
Helper: makeDefaultHelper(t),
|
Helper: makeDefaultHelper(t),
|
||||||
@ -209,9 +208,10 @@ func TestExecutorValidate(t *testing.T) {
|
|||||||
actualErr := executor.Validate()
|
actualErr := executor.Validate()
|
||||||
assert.Equal(t, expectedErr, actualErr)
|
assert.Equal(t, expectedErr, actualErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExecutorRender(t *testing.T) {
|
func TestExecutorRender(t *testing.T) {
|
||||||
sampleCfgDoc := executorDoc(t, "init")
|
sampleCfgDoc := executorDoc(t, "init")
|
||||||
executor, err := cctlclient.NewExecutor(
|
executor, err := executors.NewExecutor(
|
||||||
ifc.ExecutorConfig{
|
ifc.ExecutorConfig{
|
||||||
ExecutorDocument: sampleCfgDoc,
|
ExecutorDocument: sampleCfgDoc,
|
||||||
Helper: makeDefaultHelper(t),
|
Helper: makeDefaultHelper(t),
|
||||||
@ -226,7 +226,7 @@ func TestExecutorRender(t *testing.T) {
|
|||||||
func makeDefaultHelper(t *testing.T) ifc.Helper {
|
func makeDefaultHelper(t *testing.T) ifc.Helper {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
cfg := config.NewConfig()
|
cfg := config.NewConfig()
|
||||||
cfg.Manifests[config.AirshipDefaultManifest].TargetPath = "./testdata"
|
cfg.Manifests[config.AirshipDefaultManifest].TargetPath = "../../clusterctl/client/testdata"
|
||||||
cfg.Manifests[config.AirshipDefaultManifest].MetadataPath = "metadata.yaml"
|
cfg.Manifests[config.AirshipDefaultManifest].MetadataPath = "metadata.yaml"
|
||||||
cfg.Manifests[config.AirshipDefaultManifest].Repositories[config.DefaultTestPhaseRepo].URLString = ""
|
cfg.Manifests[config.AirshipDefaultManifest].Repositories[config.DefaultTestPhaseRepo].URLString = ""
|
||||||
cfg.SetLoadedConfigPath(".")
|
cfg.SetLoadedConfigPath(".")
|
29
pkg/phase/executors/errors.go
Executable file
29
pkg/phase/executors/errors.go
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package executors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ErrUnknownExecutorAction is returned for unknown action parameter
|
||||||
|
// in clusterctl configuration document
|
||||||
|
type ErrUnknownExecutorAction struct {
|
||||||
|
Action string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e ErrUnknownExecutorAction) Error() string {
|
||||||
|
return fmt.Sprintf("unknown action type '%s'", e.Action)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user