Merge "Move clusterctl phase executor to a separate package"

This commit is contained in:
Zuul 2020-12-15 17:40:35 +00:00 committed by Gerrit Code Review
commit 09f8b6cdf3
5 changed files with 45 additions and 25 deletions

@ -36,13 +36,3 @@ type ErrProviderRepoNotFound struct {
func (e ErrProviderRepoNotFound) Error() string {
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/bootstrap/isogen"
clusterctl "opendev.org/airship/airshipctl/pkg/clusterctl/client"
"opendev.org/airship/airshipctl/pkg/container"
"opendev.org/airship/airshipctl/pkg/document"
"opendev.org/airship/airshipctl/pkg/events"
@ -30,6 +29,7 @@ import (
"opendev.org/airship/airshipctl/pkg/k8s/kubeconfig"
"opendev.org/airship/airshipctl/pkg/k8s/utils"
"opendev.org/airship/airshipctl/pkg/log"
"opendev.org/airship/airshipctl/pkg/phase/executors"
"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 {
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})
}
if err := applier.RegisterExecutor(execMap); err != nil {

@ -12,7 +12,7 @@
limitations under the License.
*/
package client
package executors
import (
"io"
@ -21,6 +21,7 @@ import (
airshipv1 "opendev.org/airship/airshipctl/pkg/api/v1alpha1"
"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/events"
"opendev.org/airship/airshipctl/pkg/k8s/kubeconfig"
@ -34,7 +35,7 @@ var _ ifc.Executor = &ClusterctlExecutor{}
type ClusterctlExecutor struct {
clusterName string
Interface
client.Interface
clusterMap clustermap.ClusterMap
options *airshipv1.Clusterctl
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 {
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 {
return nil, err
}

@ -12,7 +12,7 @@
limitations under the License.
*/
package client_test
package executors_test
import (
"bytes"
@ -23,12 +23,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/runtime/schema"
"opendev.org/airship/airshipctl/pkg/api/v1alpha1"
"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/document"
airerrors "opendev.org/airship/airshipctl/pkg/errors"
@ -36,6 +34,7 @@ import (
"opendev.org/airship/airshipctl/pkg/fs"
"opendev.org/airship/airshipctl/pkg/k8s/kubeconfig"
"opendev.org/airship/airshipctl/pkg/phase"
"opendev.org/airship/airshipctl/pkg/phase/executors"
"opendev.org/airship/airshipctl/pkg/phase/ifc"
testfs "opendev.org/airship/airshipctl/testutil/fs"
)
@ -67,7 +66,7 @@ func TestRegisterExecutor(t *testing.T) {
Version: "v1alpha1",
Kind: "Clusterctl",
}
err := cctlclient.RegisterExecutor(registry)
err := executors.RegisterExecutor(registry)
require.NoError(t, err)
_, found := registry[expectedGVK]
@ -89,7 +88,7 @@ func TestNewExecutor(t *testing.T) {
for _, test := range testCases {
tt := test
t.Run(tt.name, func(t *testing.T) {
_, actualErr := cctlclient.NewExecutor(ifc.ExecutorConfig{
_, actualErr := executors.NewExecutor(ifc.ExecutorConfig{
ExecutorDocument: sampleCfgDoc,
Helper: tt.helper,
})
@ -114,7 +113,7 @@ func TestExecutorRun(t *testing.T) {
cfgDoc: executorDoc(t, "someAction"),
bundlePath: "testdata/executor_init",
expectedEvt: []events.Event{
wrapError(cctlclient.ErrUnknownExecutorAction{Action: "someAction"}),
wrapError(executors.ErrUnknownExecutorAction{Action: "someAction"}),
},
clusterMap: clustermap.NewClusterMap(v1alpha1.DefaultClusterMap()),
},
@ -168,7 +167,7 @@ func TestExecutorRun(t *testing.T) {
kubeconfig.FromByte([]byte("someKubeConfig")),
kubeconfig.InjectFileSystem(tt.fs),
)
executor, err := cctlclient.NewExecutor(
executor, err := executors.NewExecutor(
ifc.ExecutorConfig{
ExecutorDocument: tt.cfgDoc,
Helper: makeDefaultHelper(t),
@ -199,7 +198,7 @@ func TestExecutorRun(t *testing.T) {
func TestExecutorValidate(t *testing.T) {
sampleCfgDoc := executorDoc(t, "init")
executor, err := cctlclient.NewExecutor(
executor, err := executors.NewExecutor(
ifc.ExecutorConfig{
ExecutorDocument: sampleCfgDoc,
Helper: makeDefaultHelper(t),
@ -209,9 +208,10 @@ func TestExecutorValidate(t *testing.T) {
actualErr := executor.Validate()
assert.Equal(t, expectedErr, actualErr)
}
func TestExecutorRender(t *testing.T) {
sampleCfgDoc := executorDoc(t, "init")
executor, err := cctlclient.NewExecutor(
executor, err := executors.NewExecutor(
ifc.ExecutorConfig{
ExecutorDocument: sampleCfgDoc,
Helper: makeDefaultHelper(t),
@ -226,7 +226,7 @@ func TestExecutorRender(t *testing.T) {
func makeDefaultHelper(t *testing.T) ifc.Helper {
t.Helper()
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].Repositories[config.DefaultTestPhaseRepo].URLString = ""
cfg.SetLoadedConfigPath(".")

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