Refactor document plugin command

AirshipCTLSettings are not used here, so it was removed.

Change-Id: If4bf64b9991b4ac05898632c79bacbacd7872635
Signed-off-by: Ruslan Aliev <raliev@mirantis.com>
Relates-To: #327
This commit is contained in:
Ruslan Aliev
2020-08-27 17:45:22 -05:00
parent 95d6536df2
commit 78364d7d44
11 changed files with 18 additions and 26 deletions

View File

@@ -19,7 +19,6 @@ import (
"sigs.k8s.io/yaml"
plugtypes "opendev.org/airship/airshipctl/pkg/document/plugin/types"
"opendev.org/airship/airshipctl/pkg/environment"
)
var (
@@ -43,7 +42,7 @@ func GetGVK() schema.GroupVersionKind {
}
// New creates new instance of the plugin
func New(_ *environment.AirshipCTLSettings, cfg []byte) (plugtypes.Plugin, error) {
func New(cfg []byte) (plugtypes.Plugin, error) {
p := &plugin{}
if err := p.Config(nil, cfg); err != nil {
return nil, err

View File

@@ -16,7 +16,7 @@ import (
)
func samplePlugin(t *testing.T) plugtypes.Plugin {
plugin, err := replv1alpha1.New(nil, []byte(`
plugin, err := replv1alpha1.New([]byte(`
apiVersion: airshipit.org/v1alpha1
kind: ReplacementTransformer
metadata:
@@ -35,7 +35,7 @@ replacements:
}
func TestMalformedConfig(t *testing.T) {
_, err := replv1alpha1.New(nil, []byte("--"))
_, err := replv1alpha1.New([]byte("--"))
assert.Error(t, err)
}
@@ -909,7 +909,7 @@ spec:
}
for _, tc := range testCases {
plugin, err := replv1alpha1.New(nil, []byte(tc.cfg))
plugin, err := replv1alpha1.New([]byte(tc.cfg))
require.NoError(t, err)
buf := &bytes.Buffer{}

View File

@@ -25,7 +25,6 @@ import (
"opendev.org/airship/airshipctl/pkg/document/plugin/replacement"
"opendev.org/airship/airshipctl/pkg/document/plugin/templater"
"opendev.org/airship/airshipctl/pkg/document/plugin/types"
"opendev.org/airship/airshipctl/pkg/environment"
)
// Registry contains factory functions for the available plugins
@@ -39,7 +38,7 @@ func init() {
// ConfigureAndRun executes particular plugin based on group, version, kind
// which have been specified in configuration file. Config file should be
// supplied as a first element of args slice
func ConfigureAndRun(settings *environment.AirshipCTLSettings, pluginCfg []byte, in io.Reader, out io.Writer) error {
func ConfigureAndRun(pluginCfg []byte, in io.Reader, out io.Writer) error {
var cfg unstructured.Unstructured
if err := yaml.Unmarshal(pluginCfg, &cfg); err != nil {
return err
@@ -49,7 +48,7 @@ func ConfigureAndRun(settings *environment.AirshipCTLSettings, pluginCfg []byte,
return ErrPluginNotFound{PluginID: cfg.GroupVersionKind()}
}
plugin, err := pluginFactory(settings, pluginCfg)
plugin, err := pluginFactory(pluginCfg)
if err != nil {
return err
}

View File

@@ -21,13 +21,11 @@ import (
"github.com/stretchr/testify/assert"
"opendev.org/airship/airshipctl/pkg/document/plugin"
"opendev.org/airship/airshipctl/pkg/environment"
)
func TestConfigureAndRun(t *testing.T) {
testCases := []struct {
pluginCfg []byte
settings *environment.AirshipCTLSettings
expectedError string
in io.Reader
out io.Writer
@@ -55,7 +53,7 @@ spec: -
}
for _, tc := range testCases {
err := plugin.ConfigureAndRun(tc.settings, tc.pluginCfg, tc.in, tc.out)
err := plugin.ConfigureAndRun(tc.pluginCfg, tc.in, tc.out)
assert.EqualError(t, err, tc.expectedError)
}
}

View File

@@ -24,7 +24,6 @@ import (
"sigs.k8s.io/yaml"
plugtypes "opendev.org/airship/airshipctl/pkg/document/plugin/types"
"opendev.org/airship/airshipctl/pkg/environment"
)
// GetGVK returns group, version, kind object used to register version
@@ -38,7 +37,7 @@ func GetGVK() schema.GroupVersionKind {
}
// New creates new instance of the plugin
func New(_ *environment.AirshipCTLSettings, cfg []byte) (plugtypes.Plugin, error) {
func New(cfg []byte) (plugtypes.Plugin, error) {
t := &Templater{}
if err := yaml.Unmarshal(cfg, t); err != nil {
return nil, err

View File

@@ -25,7 +25,7 @@ import (
)
func TestMalformedConfig(t *testing.T) {
_, err := tmplv1alpha1.New(nil, []byte("--"))
_, err := tmplv1alpha1.New([]byte("--"))
assert.Error(t, err)
}
@@ -119,7 +119,7 @@ template: |
}
for _, tc := range testCases {
plugin, err := tmplv1alpha1.New(nil, []byte(tc.cfg))
plugin, err := tmplv1alpha1.New([]byte(tc.cfg))
require.NoError(t, err)
buf := &bytes.Buffer{}
err = plugin.Run(nil, buf)

View File

@@ -16,8 +16,6 @@ package types
import (
"io"
"opendev.org/airship/airshipctl/pkg/environment"
)
// Plugin interface for airship document plugins
@@ -27,4 +25,4 @@ type Plugin interface {
// Factory function for plugins. Functions of such type are used in the plugin
// registry to instantiate a plugin object
type Factory func(*environment.AirshipCTLSettings, []byte) (Plugin, error)
type Factory func([]byte) (Plugin, error)