mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Merge branch 'master' into builtins
This commit is contained in:
@@ -21,8 +21,7 @@ import (
|
||||
"fmt"
|
||||
"unicode/utf8"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/api/core/v1"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
@@ -40,8 +39,8 @@ func NewFactory(
|
||||
}
|
||||
|
||||
func makeFreshConfigMap(
|
||||
args *types.ConfigMapArgs) *corev1.ConfigMap {
|
||||
cm := &corev1.ConfigMap{}
|
||||
args *types.ConfigMapArgs) *v1.ConfigMap {
|
||||
cm := &v1.ConfigMap{}
|
||||
cm.APIVersion = "v1"
|
||||
cm.Kind = "ConfigMap"
|
||||
cm.Name = args.Name
|
||||
@@ -52,7 +51,7 @@ func makeFreshConfigMap(
|
||||
|
||||
// MakeConfigMap returns a new ConfigMap, or nil and an error.
|
||||
func (f *Factory) MakeConfigMap(
|
||||
args *types.ConfigMapArgs) (*corev1.ConfigMap, error) {
|
||||
args *types.ConfigMapArgs) (*v1.ConfigMap, error) {
|
||||
all, err := f.loadKvPairs(args.GeneratorArgs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
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
|
||||
|
||||
http://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 k8sdeps provides kustomize factory with k8s dependencies
|
||||
package k8sdeps
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/transformer"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/validator"
|
||||
"sigs.k8s.io/kustomize/pkg/factory"
|
||||
)
|
||||
|
||||
// NewFactory creates an instance of KustFactory using k8sdeps factories
|
||||
func NewFactory() *factory.KustFactory {
|
||||
return factory.NewKustFactory(
|
||||
kunstruct.NewKunstructuredFactoryImpl(),
|
||||
validator.NewKustValidator(),
|
||||
transformer.NewFactoryImpl(),
|
||||
)
|
||||
}
|
||||
@@ -32,13 +32,21 @@ import (
|
||||
|
||||
// KunstructuredFactoryImpl hides construction using apimachinery types.
|
||||
type KunstructuredFactoryImpl struct {
|
||||
generatorMetaArgs *types.GeneratorMetaArgs
|
||||
}
|
||||
|
||||
var _ ifc.KunstructuredFactory = &KunstructuredFactoryImpl{}
|
||||
|
||||
// NewKunstructuredFactoryImpl returns a factory.
|
||||
func NewKunstructuredFactoryImpl() ifc.KunstructuredFactory {
|
||||
return &KunstructuredFactoryImpl{}
|
||||
return NewKunstructuredFactoryWithGeneratorArgs(
|
||||
&types.GeneratorMetaArgs{})
|
||||
}
|
||||
|
||||
// NewKunstructuredFactoryWithGeneratorArgs returns a factory.
|
||||
func NewKunstructuredFactoryWithGeneratorArgs(
|
||||
gma *types.GeneratorMetaArgs) ifc.KunstructuredFactory {
|
||||
return &KunstructuredFactoryImpl{gma}
|
||||
}
|
||||
|
||||
// SliceFromBytes returns a slice of Kunstructured.
|
||||
@@ -82,7 +90,10 @@ func (kf *KunstructuredFactoryImpl) MakeConfigMap(
|
||||
ldr ifc.Loader,
|
||||
options *types.GeneratorOptions,
|
||||
args *types.ConfigMapArgs) (ifc.Kunstructured, error) {
|
||||
o, err := configmapandsecret.NewFactory(ldr, options, plugin.NewRegistry(ldr)).MakeConfigMap(args)
|
||||
o, err := configmapandsecret.NewFactory(
|
||||
ldr, options,
|
||||
plugin.NewConfiguredRegistry(
|
||||
ldr, &kf.generatorMetaArgs.PluginConfig)).MakeConfigMap(args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -94,7 +105,10 @@ func (kf *KunstructuredFactoryImpl) MakeSecret(
|
||||
ldr ifc.Loader,
|
||||
options *types.GeneratorOptions,
|
||||
args *types.SecretArgs) (ifc.Kunstructured, error) {
|
||||
o, err := configmapandsecret.NewFactory(ldr, options, plugin.NewRegistry(ldr)).MakeSecret(args)
|
||||
o, err := configmapandsecret.NewFactory(
|
||||
ldr, options,
|
||||
plugin.NewConfiguredRegistry(
|
||||
ldr, &kf.generatorMetaArgs.PluginConfig)).MakeSecret(args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -18,23 +18,45 @@ package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"plugin"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
)
|
||||
|
||||
var _ Factory = &goFactory{}
|
||||
|
||||
const (
|
||||
dir = "$HOME/.config/kustomize/plugins/kvsource"
|
||||
kvSourcesDir = "kvSources"
|
||||
EnableGoPluginsFlagName = "enable_alpha_goplugins_accept_panic_risk"
|
||||
EnableGoPluginsFlagHelp = `
|
||||
Warning: the main program may panic and exit on an
|
||||
attempt to use a goplugin that was compiled under
|
||||
conditions differing from the those in effect when
|
||||
main was compiled. It's safest to use this flag in
|
||||
the context of a container image holding both the
|
||||
main and the goplugins it needs, all built on the
|
||||
same machine, with the same transitive libs and
|
||||
the same compiler version.
|
||||
`
|
||||
errorFmt = `
|
||||
enable go plugins by specifying flag
|
||||
--%s
|
||||
Place .so files in
|
||||
%s
|
||||
%s
|
||||
`
|
||||
)
|
||||
|
||||
func newGoFactory() *goFactory {
|
||||
func newGoFactory(c *types.PluginConfig) *goFactory {
|
||||
return &goFactory{
|
||||
config: c,
|
||||
plugins: make(map[string]KVSource),
|
||||
}
|
||||
}
|
||||
|
||||
type goFactory struct {
|
||||
config *types.PluginConfig
|
||||
plugins map[string]KVSource
|
||||
}
|
||||
|
||||
@@ -43,7 +65,19 @@ func (p *goFactory) load(name string) (KVSource, error) {
|
||||
return plug, nil
|
||||
}
|
||||
|
||||
goPlugin, err := plugin.Open(fmt.Sprintf("%s/kustomize-%s.so", os.ExpandEnv(dir), name))
|
||||
dir := filepath.Join(
|
||||
p.config.DirectoryPath,
|
||||
kvSourcesDir)
|
||||
if !p.config.GoEnabled {
|
||||
return nil, fmt.Errorf(
|
||||
errorFmt,
|
||||
EnableGoPluginsFlagName,
|
||||
dir,
|
||||
EnableGoPluginsFlagHelp)
|
||||
}
|
||||
|
||||
goPlugin, err := plugin.Open(
|
||||
filepath.Join(dir, name+".so"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -18,8 +18,10 @@ package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"path/filepath"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
)
|
||||
|
||||
// Registry holds all the plugin factories.
|
||||
@@ -28,17 +30,36 @@ type Registry struct {
|
||||
ldr ifc.Loader
|
||||
}
|
||||
|
||||
// NewRegistry returns a new Registry loaded with all the factories.
|
||||
func NewRegistry(ldr ifc.Loader) Registry {
|
||||
const (
|
||||
PluginsDir = "plugins"
|
||||
)
|
||||
|
||||
func DefaultPluginConfig() types.PluginConfig {
|
||||
return types.PluginConfig{
|
||||
GoEnabled: false,
|
||||
DirectoryPath: filepath.Join(
|
||||
pgmconfig.ConfigRoot(), PluginsDir),
|
||||
}
|
||||
}
|
||||
|
||||
// NewConfiguredRegistry returns a new Registry loaded
|
||||
// with all the factories and a custom PluginConfig.
|
||||
func NewConfiguredRegistry(
|
||||
ldr ifc.Loader, pc *types.PluginConfig) Registry {
|
||||
return Registry{
|
||||
ldr: ldr,
|
||||
factories: map[string]Factory{
|
||||
"go": newGoFactory(),
|
||||
"go": newGoFactory(pc),
|
||||
"builtin": newBuiltinFactory(ldr),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// NewRegistry returns a new Registry with default config.
|
||||
func NewRegistry(ldr ifc.Loader) Registry {
|
||||
return NewConfiguredRegistry(ldr, &types.PluginConfig{})
|
||||
}
|
||||
|
||||
// Load returns a plugin by type and name,
|
||||
func (r *Registry) Load(pluginType, name string) (KVSource, error) {
|
||||
factory, exists := r.factories[pluginType]
|
||||
|
||||
Reference in New Issue
Block a user