
AirshipCTLSettings are not used here, so it was removed. Change-Id: If4bf64b9991b4ac05898632c79bacbacd7872635 Signed-off-by: Ruslan Aliev <raliev@mirantis.com> Relates-To: #327
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
/*
|
|
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 plugin
|
|
|
|
import (
|
|
"io"
|
|
|
|
"sigs.k8s.io/yaml"
|
|
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
|
|
"opendev.org/airship/airshipctl/pkg/document/plugin/replacement"
|
|
"opendev.org/airship/airshipctl/pkg/document/plugin/templater"
|
|
"opendev.org/airship/airshipctl/pkg/document/plugin/types"
|
|
)
|
|
|
|
// Registry contains factory functions for the available plugins
|
|
var Registry = make(map[schema.GroupVersionKind]types.Factory)
|
|
|
|
func init() {
|
|
replacement.RegisterPlugin(Registry)
|
|
templater.RegisterPlugin(Registry)
|
|
}
|
|
|
|
// 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(pluginCfg []byte, in io.Reader, out io.Writer) error {
|
|
var cfg unstructured.Unstructured
|
|
if err := yaml.Unmarshal(pluginCfg, &cfg); err != nil {
|
|
return err
|
|
}
|
|
pluginFactory, ok := Registry[cfg.GroupVersionKind()]
|
|
if !ok {
|
|
return ErrPluginNotFound{PluginID: cfg.GroupVersionKind()}
|
|
}
|
|
|
|
plugin, err := pluginFactory(pluginCfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return plugin.Run(in, out)
|
|
}
|