diff --git a/cmd/document/document.go b/cmd/document/document.go index fb56e841c..234ec00e0 100644 --- a/cmd/document/document.go +++ b/cmd/document/document.go @@ -34,7 +34,7 @@ func NewDocumentCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Com } documentRootCmd.AddCommand(NewPullCommand(rootSettings)) - documentRootCmd.AddCommand(NewPluginCommand(rootSettings)) + documentRootCmd.AddCommand(NewPluginCommand()) return documentRootCmd } diff --git a/cmd/document/document_test.go b/cmd/document/document_test.go index 1642cc8a9..62e98b959 100644 --- a/cmd/document/document_test.go +++ b/cmd/document/document_test.go @@ -31,12 +31,12 @@ func TestDocument(t *testing.T) { { Name: "document-plugin-with-help", CmdLine: "-h", - Cmd: document.NewPluginCommand(nil), + Cmd: document.NewPluginCommand(), }, { Name: "document-pull-with-help", CmdLine: "-h", - Cmd: document.NewPluginCommand(nil), + Cmd: document.NewPluginCommand(), }, } for _, tt := range tests { diff --git a/cmd/document/plugin.go b/cmd/document/plugin.go index 23d3d2886..aabf74bac 100644 --- a/cmd/document/plugin.go +++ b/cmd/document/plugin.go @@ -20,7 +20,6 @@ import ( "github.com/spf13/cobra" "opendev.org/airship/airshipctl/pkg/document/plugin" - "opendev.org/airship/airshipctl/pkg/environment" ) const ( @@ -60,7 +59,7 @@ airshipctl document plugin /tmp/replacement.yaml // NewPluginCommand creates a new command which can act as kustomize // exec plugin. -func NewPluginCommand(rootSetting *environment.AirshipCTLSettings) *cobra.Command { +func NewPluginCommand() *cobra.Command { pluginCmd := &cobra.Command{ Use: "plugin CONFIG [ARGS]", Short: "Run as a kustomize exec plugin", @@ -72,7 +71,7 @@ func NewPluginCommand(rootSetting *environment.AirshipCTLSettings) *cobra.Comman if err != nil { return err } - return plugin.ConfigureAndRun(rootSetting, cfg, cmd.InOrStdin(), cmd.OutOrStdout()) + return plugin.ConfigureAndRun(cfg, cmd.InOrStdin(), cmd.OutOrStdout()) }, } return pluginCmd diff --git a/cmd/document/plugin_test.go b/cmd/document/plugin_test.go index 540e54f34..e75335e9c 100644 --- a/cmd/document/plugin_test.go +++ b/cmd/document/plugin_test.go @@ -27,13 +27,13 @@ func TestPlugin(t *testing.T) { Name: "document-plugin-cmd-with-empty-args", CmdLine: "", Error: fmt.Errorf("requires at least 1 arg(s), only received 0"), - Cmd: NewPluginCommand(nil), + Cmd: NewPluginCommand(), }, { Name: "document-plugin-cmd-with-nonexistent-config", CmdLine: "/some/random/path.yaml", Error: fmt.Errorf("open /some/random/path.yaml: no such file or directory"), - Cmd: NewPluginCommand(nil), + Cmd: NewPluginCommand(), }, } diff --git a/pkg/document/plugin/replacement/v1alpha1/transformer.go b/pkg/document/plugin/replacement/v1alpha1/transformer.go index 6d12a3852..e9ac1b9e3 100644 --- a/pkg/document/plugin/replacement/v1alpha1/transformer.go +++ b/pkg/document/plugin/replacement/v1alpha1/transformer.go @@ -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 diff --git a/pkg/document/plugin/replacement/v1alpha1/transformer_test.go b/pkg/document/plugin/replacement/v1alpha1/transformer_test.go index f4fd2c577..6bc5f37b5 100644 --- a/pkg/document/plugin/replacement/v1alpha1/transformer_test.go +++ b/pkg/document/plugin/replacement/v1alpha1/transformer_test.go @@ -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{} diff --git a/pkg/document/plugin/run.go b/pkg/document/plugin/run.go index 1a38bee0e..3c548c6ed 100644 --- a/pkg/document/plugin/run.go +++ b/pkg/document/plugin/run.go @@ -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 } diff --git a/pkg/document/plugin/run_test.go b/pkg/document/plugin/run_test.go index b48543898..94423b7be 100644 --- a/pkg/document/plugin/run_test.go +++ b/pkg/document/plugin/run_test.go @@ -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) } } diff --git a/pkg/document/plugin/templater/v1alpha1/templater.go b/pkg/document/plugin/templater/v1alpha1/templater.go index add8f0bb8..c65c26dd4 100644 --- a/pkg/document/plugin/templater/v1alpha1/templater.go +++ b/pkg/document/plugin/templater/v1alpha1/templater.go @@ -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 diff --git a/pkg/document/plugin/templater/v1alpha1/templater_test.go b/pkg/document/plugin/templater/v1alpha1/templater_test.go index 19d83053d..d82d12df7 100644 --- a/pkg/document/plugin/templater/v1alpha1/templater_test.go +++ b/pkg/document/plugin/templater/v1alpha1/templater_test.go @@ -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) diff --git a/pkg/document/plugin/types/plugin.go b/pkg/document/plugin/types/plugin.go index 1d24a4bcc..e9a092eae 100644 --- a/pkg/document/plugin/types/plugin.go +++ b/pkg/document/plugin/types/plugin.go @@ -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)