mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
Delete the KV plugin code.
This commit is contained in:
@@ -173,13 +173,10 @@ transformers cannot be expected to be commutative.
|
|||||||
A `kustomize build` that tries to use plugins but
|
A `kustomize build` that tries to use plugins but
|
||||||
omits the flag
|
omits the flag
|
||||||
|
|
||||||
_TODO: Change flag_
|
> `--enable_alpha_plugins`
|
||||||
|
|
||||||
> `--enable_alpha_goplugins_accept_panic_risk`
|
|
||||||
|
|
||||||
will fail with a warning about plugin use.
|
will fail with a warning about plugin use.
|
||||||
|
|
||||||
|
|
||||||
Flag use is an opt-in acknowledging the absence of
|
Flag use is an opt-in acknowledging the absence of
|
||||||
plugin provenance. It's meant to give pause to
|
plugin provenance. It's meant to give pause to
|
||||||
someone who blindly downloads a kustomization from
|
someone who blindly downloads a kustomization from
|
||||||
|
|||||||
@@ -150,8 +150,7 @@ correct environment and flags for plugins:
|
|||||||
```
|
```
|
||||||
function kustomizeIt {
|
function kustomizeIt {
|
||||||
XDG_CONFIG_HOME=$DEMO_HOME \
|
XDG_CONFIG_HOME=$DEMO_HOME \
|
||||||
kustomize build \
|
kustomize build --enable_alpha_plugins \
|
||||||
--enable_alpha_goplugins_accept_panic_risk \
|
|
||||||
$DEMO_HOME/$1
|
$DEMO_HOME/$1
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -201,9 +201,7 @@ can be found under `$DEMO_HOME`:
|
|||||||
```
|
```
|
||||||
result=$( \
|
result=$( \
|
||||||
XDG_CONFIG_HOME=$DEMO_HOME \
|
XDG_CONFIG_HOME=$DEMO_HOME \
|
||||||
kustomize \
|
kustomize build --enable_alpha_plugins $DEMO_HOME )
|
||||||
--enable_alpha_goplugins_accept_panic_risk \
|
|
||||||
build $DEMO_HOME )
|
|
||||||
echo "$result"
|
echo "$result"
|
||||||
# Spot check the result:
|
# Spot check the result:
|
||||||
test 1 == $(echo "$result" | grep -c "FRUIT: YXBwbGU=")
|
test 1 == $(echo "$result" | grep -c "FRUIT: YXBwbGU=")
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2018 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
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 configmapandsecret
|
package configmapandsecret
|
||||||
|
|
||||||
@@ -22,7 +9,6 @@ import (
|
|||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
|
||||||
"sigs.k8s.io/kustomize/pkg/fs"
|
"sigs.k8s.io/kustomize/pkg/fs"
|
||||||
"sigs.k8s.io/kustomize/pkg/loader"
|
"sigs.k8s.io/kustomize/pkg/loader"
|
||||||
"sigs.k8s.io/kustomize/pkg/types"
|
"sigs.k8s.io/kustomize/pkg/types"
|
||||||
@@ -143,9 +129,8 @@ func TestConstructConfigMap(t *testing.T) {
|
|||||||
fSys.WriteFile("/configmap/app-init.ini", []byte("FOO=bar\nBAR=baz\n"))
|
fSys.WriteFile("/configmap/app-init.ini", []byte("FOO=bar\nBAR=baz\n"))
|
||||||
fSys.WriteFile("/configmap/app.bin", []byte{0xff, 0xfd})
|
fSys.WriteFile("/configmap/app.bin", []byte{0xff, 0xfd})
|
||||||
ldr := loader.NewFileLoaderAtRoot(fSys)
|
ldr := loader.NewFileLoaderAtRoot(fSys)
|
||||||
reg := plugin.NewRegistry(ldr)
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
f := NewFactory(ldr, tc.options, reg)
|
f := NewFactory(ldr, tc.options)
|
||||||
cm, err := f.MakeConfigMap(&tc.input)
|
cm, err := f.MakeConfigMap(&tc.input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
|||||||
@@ -1,30 +1,15 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2019 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
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 configmapandsecret
|
package configmapandsecret
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"k8s.io/apimachinery/pkg/util/validation"
|
"k8s.io/apimachinery/pkg/util/validation"
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv"
|
"sigs.k8s.io/kustomize/k8sdeps/kv"
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
|
||||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||||
"sigs.k8s.io/kustomize/pkg/types"
|
"sigs.k8s.io/kustomize/pkg/types"
|
||||||
)
|
)
|
||||||
@@ -33,25 +18,17 @@ import (
|
|||||||
type Factory struct {
|
type Factory struct {
|
||||||
ldr ifc.Loader
|
ldr ifc.Loader
|
||||||
options *types.GeneratorOptions
|
options *types.GeneratorOptions
|
||||||
reg plugin.Registry
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFactory returns a new Factory.
|
// NewFactory returns a new Factory.
|
||||||
func NewFactory(
|
func NewFactory(
|
||||||
l ifc.Loader, o *types.GeneratorOptions, reg plugin.Registry) *Factory {
|
l ifc.Loader, o *types.GeneratorOptions) *Factory {
|
||||||
return &Factory{ldr: l, options: o, reg: reg}
|
return &Factory{ldr: l, options: o}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Factory) loadKvPairs(
|
func (f *Factory) loadKvPairs(
|
||||||
args types.GeneratorArgs) (all []kv.Pair, err error) {
|
args types.GeneratorArgs) (all []kv.Pair, err error) {
|
||||||
pairs, err := f.keyValuesFromPlugins(args.KVSources)
|
pairs, err := f.keyValuesFromEnvFiles(args.EnvSources)
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, fmt.Sprintf(
|
|
||||||
"plugins: %s",
|
|
||||||
args.KVSources))
|
|
||||||
}
|
|
||||||
all = append(all, pairs...)
|
|
||||||
pairs, err = f.keyValuesFromEnvFiles(args.EnvSources)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, fmt.Sprintf(
|
return nil, errors.Wrap(err, fmt.Sprintf(
|
||||||
"env source files: %v",
|
"env source files: %v",
|
||||||
@@ -96,35 +73,6 @@ func keyValuesFromLiteralSources(sources []string) ([]kv.Pair, error) {
|
|||||||
return kvs, nil
|
return kvs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Factory) keyValuesFromPlugins(sources []types.KVSource) ([]kv.Pair, error) {
|
|
||||||
var result []kv.Pair
|
|
||||||
for _, s := range sources {
|
|
||||||
plug, err := f.reg.Load(s.PluginType, s.Name)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
kvs, err := plug.Get(f.reg.Root(), s.Args)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for _, k := range sortedKeys(kvs) {
|
|
||||||
result = append(result, kv.Pair{Key: k, Value: kvs[k]})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func sortedKeys(m map[string]string) []string {
|
|
||||||
keys := make([]string, len(m))
|
|
||||||
i := 0
|
|
||||||
for k := range m {
|
|
||||||
keys[i] = k
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
sort.Strings(keys)
|
|
||||||
return keys
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Factory) keyValuesFromFileSources(sources []string) ([]kv.Pair, error) {
|
func (f *Factory) keyValuesFromFileSources(sources []string) ([]kv.Pair, error) {
|
||||||
var kvs []kv.Pair
|
var kvs []kv.Pair
|
||||||
for _, s := range sources {
|
for _, s := range sources {
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2019 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
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 configmapandsecret
|
package configmapandsecret
|
||||||
|
|
||||||
@@ -21,10 +8,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv"
|
"sigs.k8s.io/kustomize/k8sdeps/kv"
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
|
||||||
"sigs.k8s.io/kustomize/pkg/fs"
|
"sigs.k8s.io/kustomize/pkg/fs"
|
||||||
"sigs.k8s.io/kustomize/pkg/loader"
|
"sigs.k8s.io/kustomize/pkg/loader"
|
||||||
"sigs.k8s.io/kustomize/pkg/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestKeyValuesFromFileSources(t *testing.T) {
|
func TestKeyValuesFromFileSources(t *testing.T) {
|
||||||
@@ -47,9 +32,7 @@ func TestKeyValuesFromFileSources(t *testing.T) {
|
|||||||
|
|
||||||
fSys := fs.MakeFakeFS()
|
fSys := fs.MakeFakeFS()
|
||||||
fSys.WriteFile("/files/app-init.ini", []byte("FOO=bar"))
|
fSys.WriteFile("/files/app-init.ini", []byte("FOO=bar"))
|
||||||
ldr := loader.NewFileLoaderAtRoot(fSys)
|
bf := NewFactory(loader.NewFileLoaderAtRoot(fSys), nil)
|
||||||
reg := plugin.NewRegistry(ldr)
|
|
||||||
bf := NewFactory(loader.NewFileLoaderAtRoot(fSys), nil, reg)
|
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
kvs, err := bf.keyValuesFromFileSources(tc.sources)
|
kvs, err := bf.keyValuesFromFileSources(tc.sources)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -60,80 +43,3 @@ func TestKeyValuesFromFileSources(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestKeyValuesFromPlugins(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
description string
|
|
||||||
sources []types.KVSource
|
|
||||||
expected []kv.Pair
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
description: "Create kv.Pairs from builtin literals plugin",
|
|
||||||
sources: []types.KVSource{
|
|
||||||
{
|
|
||||||
PluginType: "builtin",
|
|
||||||
Name: "literals",
|
|
||||||
Args: []string{"FOO=bar", "BAR=baz"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expected: []kv.Pair{
|
|
||||||
{
|
|
||||||
Key: "BAR",
|
|
||||||
Value: "baz",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Key: "FOO",
|
|
||||||
Value: "bar",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
description: "Create kv.Pairs from builtin files plugin",
|
|
||||||
sources: []types.KVSource{
|
|
||||||
{
|
|
||||||
PluginType: "builtin",
|
|
||||||
Name: "files",
|
|
||||||
Args: []string{"files/app-init.ini"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expected: []kv.Pair{
|
|
||||||
{
|
|
||||||
Key: "app-init.ini",
|
|
||||||
Value: "FOO=bar",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
description: "Create kv.Pairs from builtin envfiles plugin",
|
|
||||||
sources: []types.KVSource{
|
|
||||||
{
|
|
||||||
PluginType: "builtin",
|
|
||||||
Name: "envfiles",
|
|
||||||
Args: []string{"files/app-init.ini"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expected: []kv.Pair{
|
|
||||||
{
|
|
||||||
Key: "FOO",
|
|
||||||
Value: "bar",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
fSys := fs.MakeFakeFS()
|
|
||||||
fSys.WriteFile("/files/app-init.ini", []byte("FOO=bar"))
|
|
||||||
ldr := loader.NewFileLoaderAtRoot(fSys)
|
|
||||||
reg := plugin.NewRegistry(ldr)
|
|
||||||
bf := NewFactory(ldr, nil, reg)
|
|
||||||
|
|
||||||
for _, tc := range tests {
|
|
||||||
kvs, err := bf.keyValuesFromPlugins(tc.sources)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(kvs, tc.expected) {
|
|
||||||
t.Fatalf("in testcase: %q updated:\n%#v\ndoesn't match expected:\n%#v\n", tc.description, kvs, tc.expected)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2018 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
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 configmapandsecret
|
package configmapandsecret
|
||||||
|
|
||||||
@@ -22,7 +9,6 @@ import (
|
|||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
|
||||||
"sigs.k8s.io/kustomize/pkg/fs"
|
"sigs.k8s.io/kustomize/pkg/fs"
|
||||||
"sigs.k8s.io/kustomize/pkg/loader"
|
"sigs.k8s.io/kustomize/pkg/loader"
|
||||||
"sigs.k8s.io/kustomize/pkg/types"
|
"sigs.k8s.io/kustomize/pkg/types"
|
||||||
@@ -140,9 +126,8 @@ func TestConstructSecret(t *testing.T) {
|
|||||||
fSys.WriteFile("/secret/app.env", []byte("DB_USERNAME=admin\nDB_PASSWORD=somepw\n"))
|
fSys.WriteFile("/secret/app.env", []byte("DB_USERNAME=admin\nDB_PASSWORD=somepw\n"))
|
||||||
fSys.WriteFile("/secret/app-init.ini", []byte("FOO=bar\nBAR=baz\n"))
|
fSys.WriteFile("/secret/app-init.ini", []byte("FOO=bar\nBAR=baz\n"))
|
||||||
ldr := loader.NewFileLoaderAtRoot(fSys)
|
ldr := loader.NewFileLoaderAtRoot(fSys)
|
||||||
reg := plugin.NewRegistry(ldr)
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
f := NewFactory(ldr, tc.options, reg)
|
f := NewFactory(ldr, tc.options)
|
||||||
cm, err := f.MakeSecret(&tc.input)
|
cm, err := f.MakeSecret(&tc.input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2018 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
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 kunstruct
|
package kunstruct
|
||||||
|
|
||||||
@@ -25,28 +12,19 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
"k8s.io/apimachinery/pkg/util/yaml"
|
"k8s.io/apimachinery/pkg/util/yaml"
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/configmapandsecret"
|
"sigs.k8s.io/kustomize/k8sdeps/configmapandsecret"
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
|
||||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||||
"sigs.k8s.io/kustomize/pkg/types"
|
"sigs.k8s.io/kustomize/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KunstructuredFactoryImpl hides construction using apimachinery types.
|
// KunstructuredFactoryImpl hides construction using apimachinery types.
|
||||||
type KunstructuredFactoryImpl struct {
|
type KunstructuredFactoryImpl struct {
|
||||||
generatorMetaArgs *types.GeneratorMetaArgs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ ifc.KunstructuredFactory = &KunstructuredFactoryImpl{}
|
var _ ifc.KunstructuredFactory = &KunstructuredFactoryImpl{}
|
||||||
|
|
||||||
// NewKunstructuredFactoryImpl returns a factory.
|
// NewKunstructuredFactoryImpl returns a factory.
|
||||||
func NewKunstructuredFactoryImpl() ifc.KunstructuredFactory {
|
func NewKunstructuredFactoryImpl() ifc.KunstructuredFactory {
|
||||||
return NewKunstructuredFactoryWithGeneratorArgs(
|
return &KunstructuredFactoryImpl{}
|
||||||
&types.GeneratorMetaArgs{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewKunstructuredFactoryWithGeneratorArgs returns a factory.
|
|
||||||
func NewKunstructuredFactoryWithGeneratorArgs(
|
|
||||||
gma *types.GeneratorMetaArgs) ifc.KunstructuredFactory {
|
|
||||||
return &KunstructuredFactoryImpl{gma}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SliceFromBytes returns a slice of Kunstructured.
|
// SliceFromBytes returns a slice of Kunstructured.
|
||||||
@@ -91,9 +69,7 @@ func (kf *KunstructuredFactoryImpl) MakeConfigMap(
|
|||||||
options *types.GeneratorOptions,
|
options *types.GeneratorOptions,
|
||||||
args *types.ConfigMapArgs) (ifc.Kunstructured, error) {
|
args *types.ConfigMapArgs) (ifc.Kunstructured, error) {
|
||||||
o, err := configmapandsecret.NewFactory(
|
o, err := configmapandsecret.NewFactory(
|
||||||
ldr, options,
|
ldr, options).MakeConfigMap(args)
|
||||||
plugin.NewConfiguredRegistry(
|
|
||||||
ldr, kf.generatorMetaArgs.PluginConfig)).MakeConfigMap(args)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -106,9 +82,7 @@ func (kf *KunstructuredFactoryImpl) MakeSecret(
|
|||||||
options *types.GeneratorOptions,
|
options *types.GeneratorOptions,
|
||||||
args *types.SecretArgs) (ifc.Kunstructured, error) {
|
args *types.SecretArgs) (ifc.Kunstructured, error) {
|
||||||
o, err := configmapandsecret.NewFactory(
|
o, err := configmapandsecret.NewFactory(
|
||||||
ldr, options,
|
ldr, options).MakeSecret(args)
|
||||||
plugin.NewConfiguredRegistry(
|
|
||||||
ldr, kf.generatorMetaArgs.PluginConfig)).MakeSecret(args)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2019 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 builtin
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv"
|
|
||||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
|
||||||
)
|
|
||||||
|
|
||||||
// EnvFiles format should be a path to a file to read lines of key=val
|
|
||||||
// pairs to create a configmap.
|
|
||||||
// i.e. a Docker .env file or a .ini file.
|
|
||||||
type EnvFiles struct {
|
|
||||||
Ldr ifc.Loader
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get implements the interface for kv plugins.
|
|
||||||
func (p EnvFiles) Get(root string, args []string) (map[string]string, error) {
|
|
||||||
all := make(map[string]string)
|
|
||||||
for _, path := range args {
|
|
||||||
if path == "" {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
content, err := p.Ldr.Load(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
kvs, err := kv.KeyValuesFromLines(content)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for _, pair := range kvs {
|
|
||||||
all[pair.Key] = pair.Value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return all, nil
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2019 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 builtin
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv"
|
|
||||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Files is a list of file sources.
|
|
||||||
// Each file source can be specified using its file path, in which case file
|
|
||||||
// basename will be used as configmap key, or optionally with a key and file
|
|
||||||
// path, in which case the given key will be used.
|
|
||||||
// Specifying a directory will iterate each named file in the directory
|
|
||||||
// whose basename is a valid configmap key.
|
|
||||||
type Files struct {
|
|
||||||
Ldr ifc.Loader
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get implements the interface for kv plugins.
|
|
||||||
func (p Files) Get(root string, args []string) (map[string]string, error) {
|
|
||||||
kvs := make(map[string]string)
|
|
||||||
for _, s := range args {
|
|
||||||
k, fPath, err := kv.ParseFileSource(s)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
content, err := p.Ldr.Load(fPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
kvs[k] = string(content)
|
|
||||||
}
|
|
||||||
return kvs, nil
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2019 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 builtin
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Literals takes a list of literals.
|
|
||||||
// Each literal source should be a key and literal value,
|
|
||||||
// e.g. `somekey=somevalue`
|
|
||||||
type Literals struct{}
|
|
||||||
|
|
||||||
// Get implements the interface for kv plugins.
|
|
||||||
func (p Literals) Get(root string, args []string) (map[string]string, error) {
|
|
||||||
kvs := make(map[string]string)
|
|
||||||
for _, s := range args {
|
|
||||||
k, v, err := kv.ParseLiteralSource(s)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
kvs[k] = v
|
|
||||||
}
|
|
||||||
return kvs, nil
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2019 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 plugin
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin/builtin"
|
|
||||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ Factory = &builtinFactory{}
|
|
||||||
|
|
||||||
type builtinFactory struct {
|
|
||||||
plugins map[string]KVSource
|
|
||||||
}
|
|
||||||
|
|
||||||
func newBuiltinFactory(ldr ifc.Loader) *builtinFactory {
|
|
||||||
return &builtinFactory{
|
|
||||||
plugins: map[string]KVSource{
|
|
||||||
"literals": builtin.Literals{},
|
|
||||||
"files": builtin.Files{Ldr: ldr},
|
|
||||||
"envfiles": builtin.EnvFiles{Ldr: ldr},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *builtinFactory) load(name string) (KVSource, error) {
|
|
||||||
if plug, ok := p.plugins[name]; ok {
|
|
||||||
return plug, nil
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("plugin %s not found", name)
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2019 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 plugin
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"path/filepath"
|
|
||||||
"plugin"
|
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/pkg/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ Factory = &goFactory{}
|
|
||||||
|
|
||||||
const (
|
|
||||||
kvSourcesDir = "kvSources"
|
|
||||||
EnableGoPluginsFlagName = "enable_alpha_goplugins_accept_panic_risk"
|
|
||||||
EnableGoPluginsFlagHelp = `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(c *types.PluginConfig) *goFactory {
|
|
||||||
return &goFactory{
|
|
||||||
config: c,
|
|
||||||
plugins: make(map[string]KVSource),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type goFactory struct {
|
|
||||||
config *types.PluginConfig
|
|
||||||
plugins map[string]KVSource
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *goFactory) load(name string) (KVSource, error) {
|
|
||||||
if plug, ok := p.plugins[name]; ok {
|
|
||||||
return plug, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
symbol, err := goPlugin.Lookup("KVSource")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
plug, ok := symbol.(KVSource)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("plugin %s not found", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
p.plugins[name] = plug
|
|
||||||
return plug, nil
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2019 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 plugin provides a plugin abstraction layer.
|
|
||||||
package plugin
|
|
||||||
|
|
||||||
// KVSource is the interface for kv source plugins.
|
|
||||||
type KVSource interface {
|
|
||||||
Get(root string, args []string) (map[string]string, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Factory is the interface for new kv source plugin implementations.
|
|
||||||
type Factory interface {
|
|
||||||
load(string) (KVSource, error)
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2019 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 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.
|
|
||||||
type Registry struct {
|
|
||||||
factories map[types.PluginType]Factory
|
|
||||||
ldr ifc.Loader
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
pluginTypeGo = types.PluginType("go")
|
|
||||||
pluginTypeBuiltIn = types.PluginType("builtin")
|
|
||||||
)
|
|
||||||
|
|
||||||
func ActivePluginConfig() *types.PluginConfig {
|
|
||||||
pc := DefaultPluginConfig()
|
|
||||||
pc.GoEnabled = true
|
|
||||||
return pc
|
|
||||||
}
|
|
||||||
|
|
||||||
func DefaultPluginConfig() *types.PluginConfig {
|
|
||||||
return &types.PluginConfig{
|
|
||||||
GoEnabled: false,
|
|
||||||
DirectoryPath: filepath.Join(
|
|
||||||
pgmconfig.ConfigRoot(), pgmconfig.PluginRoot),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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[types.PluginType]Factory{
|
|
||||||
pluginTypeGo: newGoFactory(pc),
|
|
||||||
pluginTypeBuiltIn: 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(
|
|
||||||
pt types.PluginType, name string) (KVSource, error) {
|
|
||||||
if pt.IsUndefined() {
|
|
||||||
pt = pluginTypeBuiltIn
|
|
||||||
}
|
|
||||||
factory, exists := r.factories[pt]
|
|
||||||
if !exists {
|
|
||||||
return nil, fmt.Errorf("%s is not a valid plugin type", pt)
|
|
||||||
}
|
|
||||||
return factory.load(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Root returns the root of the plugins kustomization file.
|
|
||||||
func (r *Registry) Root() string {
|
|
||||||
return r.ldr.Root()
|
|
||||||
}
|
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
/// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2017 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
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 build
|
package build
|
||||||
|
|
||||||
@@ -69,10 +56,12 @@ url examples:
|
|||||||
func NewCmdBuild(
|
func NewCmdBuild(
|
||||||
out io.Writer, fs fs.FileSystem,
|
out io.Writer, fs fs.FileSystem,
|
||||||
rf *resmap.Factory,
|
rf *resmap.Factory,
|
||||||
ptf transformer.Factory,
|
ptf transformer.Factory) *cobra.Command {
|
||||||
pl *plugins.Loader) *cobra.Command {
|
|
||||||
var o Options
|
var o Options
|
||||||
|
|
||||||
|
pluginConfig := plugins.DefaultPluginConfig()
|
||||||
|
pl := plugins.NewLoader(pluginConfig, rf)
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "build [path]",
|
Use: "build [path]",
|
||||||
Short: "Print current configuration per contents of " + pgmconfig.KustomizationFileNames[0],
|
Short: "Print current configuration per contents of " + pgmconfig.KustomizationFileNames[0],
|
||||||
@@ -86,11 +75,14 @@ func NewCmdBuild(
|
|||||||
return o.RunBuild(out, fs, rf, ptf, pl)
|
return o.RunBuild(out, fs, rf, ptf, pl)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().StringVarP(
|
cmd.Flags().StringVarP(
|
||||||
&o.outputPath,
|
&o.outputPath,
|
||||||
"output", "o", "",
|
"output", "o", "",
|
||||||
"If specified, write the build output to this path.")
|
"If specified, write the build output to this path.")
|
||||||
loader.AddLoadRestrictionsFlag(cmd.Flags())
|
loader.AddLoadRestrictionsFlag(cmd.Flags())
|
||||||
|
plugins.AddEnablePluginsFlag(
|
||||||
|
cmd.Flags(), &pluginConfig.Enabled)
|
||||||
|
|
||||||
cmd.AddCommand(NewCmdBuildPrune(out, fs, rf, ptf, pl))
|
cmd.AddCommand(NewCmdBuildPrune(out, fs, rf, ptf, pl))
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2017 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
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 commands holds the CLI glue mapping textual commands/args to method calls.
|
// Package commands holds the CLI glue mapping textual commands/args to method calls.
|
||||||
package commands
|
package commands
|
||||||
@@ -23,7 +10,6 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/transformer"
|
"sigs.k8s.io/kustomize/k8sdeps/transformer"
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/validator"
|
"sigs.k8s.io/kustomize/k8sdeps/validator"
|
||||||
"sigs.k8s.io/kustomize/pkg/commands/build"
|
"sigs.k8s.io/kustomize/pkg/commands/build"
|
||||||
@@ -31,10 +17,8 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/pkg/commands/misc"
|
"sigs.k8s.io/kustomize/pkg/commands/misc"
|
||||||
"sigs.k8s.io/kustomize/pkg/fs"
|
"sigs.k8s.io/kustomize/pkg/fs"
|
||||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||||
"sigs.k8s.io/kustomize/pkg/plugins"
|
|
||||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/pkg/resource"
|
"sigs.k8s.io/kustomize/pkg/resource"
|
||||||
"sigs.k8s.io/kustomize/pkg/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewDefaultCommand returns the default (aka root) command for kustomize command.
|
// NewDefaultCommand returns the default (aka root) command for kustomize command.
|
||||||
@@ -51,27 +35,12 @@ See https://sigs.k8s.io/kustomize
|
|||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginConfig := plugin.DefaultPluginConfig()
|
uf := kunstruct.NewKunstructuredFactoryImpl()
|
||||||
|
|
||||||
c.PersistentFlags().BoolVar(
|
|
||||||
&pluginConfig.GoEnabled,
|
|
||||||
plugin.EnableGoPluginsFlagName,
|
|
||||||
false, plugin.EnableGoPluginsFlagHelp)
|
|
||||||
// Not advertising this alpha feature.
|
|
||||||
c.PersistentFlags().MarkHidden(plugin.EnableGoPluginsFlagName)
|
|
||||||
|
|
||||||
// Configuration for ConfigMap and Secret generators.
|
|
||||||
genMetaArgs := types.GeneratorMetaArgs{
|
|
||||||
PluginConfig: pluginConfig,
|
|
||||||
}
|
|
||||||
uf := kunstruct.NewKunstructuredFactoryWithGeneratorArgs(&genMetaArgs)
|
|
||||||
rf := resmap.NewFactory(resource.NewFactory(uf))
|
rf := resmap.NewFactory(resource.NewFactory(uf))
|
||||||
c.AddCommand(
|
c.AddCommand(
|
||||||
build.NewCmdBuild(
|
build.NewCmdBuild(
|
||||||
stdOut, fSys,
|
stdOut, fSys,
|
||||||
rf,
|
rf, transformer.NewFactoryImpl()),
|
||||||
transformer.NewFactoryImpl(),
|
|
||||||
plugins.NewLoader(pluginConfig, rf)),
|
|
||||||
edit.NewCmdEdit(fSys, validator.NewKustValidator(), uf),
|
edit.NewCmdEdit(fSys, validator.NewKustValidator(), uf),
|
||||||
misc.NewCmdConfig(fSys),
|
misc.NewCmdConfig(fSys),
|
||||||
misc.NewCmdVersion(stdOut),
|
misc.NewCmdVersion(stdOut),
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2017 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
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 add
|
package add
|
||||||
|
|
||||||
@@ -104,17 +91,17 @@ func addConfigMap(
|
|||||||
ldr ifc.Loader,
|
ldr ifc.Loader,
|
||||||
k *types.Kustomization,
|
k *types.Kustomization,
|
||||||
flags flagsAndArgs, kf ifc.KunstructuredFactory) error {
|
flags flagsAndArgs, kf ifc.KunstructuredFactory) error {
|
||||||
cmArgs := makeConfigMapArgs(k, flags.Name)
|
args := findOrMakeConfigMapArgs(k, flags.Name)
|
||||||
mergeFlagsIntoCmArgs(&cmArgs.KVSources, flags)
|
mergeFlagsIntoCmArgs(args, flags)
|
||||||
// Validate by trying to create corev1.configmap.
|
// Validate by trying to create corev1.configmap.
|
||||||
_, err := kf.MakeConfigMap(ldr, k.GeneratorOptions, cmArgs)
|
_, err := kf.MakeConfigMap(ldr, k.GeneratorOptions, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeConfigMapArgs(m *types.Kustomization, name string) *types.ConfigMapArgs {
|
func findOrMakeConfigMapArgs(m *types.Kustomization, name string) *types.ConfigMapArgs {
|
||||||
for i, v := range m.ConfigMapGenerator {
|
for i, v := range m.ConfigMapGenerator {
|
||||||
if name == v.Name {
|
if name == v.Name {
|
||||||
return &m.ConfigMapGenerator[i]
|
return &m.ConfigMapGenerator[i]
|
||||||
@@ -126,23 +113,17 @@ func makeConfigMapArgs(m *types.Kustomization, name string) *types.ConfigMapArgs
|
|||||||
return &m.ConfigMapGenerator[len(m.ConfigMapGenerator)-1]
|
return &m.ConfigMapGenerator[len(m.ConfigMapGenerator)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeFlagsIntoCmArgs(src *[]types.KVSource, flags flagsAndArgs) {
|
func mergeFlagsIntoCmArgs(args *types.ConfigMapArgs, flags flagsAndArgs) {
|
||||||
if len(flags.LiteralSources) > 0 {
|
if len(flags.LiteralSources) > 0 {
|
||||||
*src = append(*src, types.KVSource{
|
args.LiteralSources = append(
|
||||||
Name: "literals",
|
args.LiteralSources, flags.LiteralSources...)
|
||||||
Args: flags.LiteralSources,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if len(flags.FileSources) > 0 {
|
if len(flags.FileSources) > 0 {
|
||||||
*src = append(*src, types.KVSource{
|
args.FileSources = append(
|
||||||
Name: "files",
|
args.FileSources, flags.FileSources...)
|
||||||
Args: flags.FileSources,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if flags.EnvFileSource != "" {
|
if flags.EnvFileSource != "" {
|
||||||
*src = append(*src, types.KVSource{
|
args.EnvSources = append(
|
||||||
Name: "envfiles",
|
args.EnvSources, flags.EnvFileSource)
|
||||||
Args: []string{flags.EnvFileSource},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2017 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
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 add
|
package add
|
||||||
|
|
||||||
@@ -39,7 +26,7 @@ func TestMakeConfigMapArgs(t *testing.T) {
|
|||||||
if len(kustomization.ConfigMapGenerator) != 0 {
|
if len(kustomization.ConfigMapGenerator) != 0 {
|
||||||
t.Fatal("Initial kustomization should not have any configmaps")
|
t.Fatal("Initial kustomization should not have any configmaps")
|
||||||
}
|
}
|
||||||
args := makeConfigMapArgs(kustomization, cmName)
|
args := findOrMakeConfigMapArgs(kustomization, cmName)
|
||||||
|
|
||||||
if args == nil {
|
if args == nil {
|
||||||
t.Fatalf("args should always be non-nil")
|
t.Fatalf("args should always be non-nil")
|
||||||
@@ -53,7 +40,7 @@ func TestMakeConfigMapArgs(t *testing.T) {
|
|||||||
t.Fatalf("Pointer address for newly inserted configmap generator should be same")
|
t.Fatalf("Pointer address for newly inserted configmap generator should be same")
|
||||||
}
|
}
|
||||||
|
|
||||||
args2 := makeConfigMapArgs(kustomization, cmName)
|
args2 := findOrMakeConfigMapArgs(kustomization, cmName)
|
||||||
|
|
||||||
if args2 != args {
|
if args2 != args {
|
||||||
t.Fatalf("should have returned an existing args with name: %v", cmName)
|
t.Fatalf("should have returned an existing args with name: %v", cmName)
|
||||||
@@ -64,51 +51,53 @@ func TestMakeConfigMapArgs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMergeFlagsIntoCmArgs_LiteralSources(t *testing.T) {
|
func TestMergeFlagsIntoConfigMapArgs_LiteralSources(t *testing.T) {
|
||||||
var kv []types.KVSource
|
k := &types.Kustomization{}
|
||||||
|
args := findOrMakeConfigMapArgs(k, "foo")
|
||||||
mergeFlagsIntoCmArgs(&kv, flagsAndArgs{LiteralSources: []string{"k1=v1"}})
|
mergeFlagsIntoGeneratorArgs(
|
||||||
|
&args.GeneratorArgs,
|
||||||
if len(kv) != 1 {
|
flagsAndArgs{LiteralSources: []string{"k1=v1"}})
|
||||||
t.Fatalf("Initial literal source should have been added")
|
mergeFlagsIntoGeneratorArgs(
|
||||||
|
&args.GeneratorArgs,
|
||||||
|
flagsAndArgs{LiteralSources: []string{"k2=v2"}})
|
||||||
|
if k.ConfigMapGenerator[0].LiteralSources[0] != "k1=v1" {
|
||||||
|
t.Fatalf("expected v1")
|
||||||
}
|
}
|
||||||
|
if k.ConfigMapGenerator[0].LiteralSources[1] != "k2=v2" {
|
||||||
mergeFlagsIntoCmArgs(&kv, flagsAndArgs{LiteralSources: []string{"k2=v2"}})
|
t.Fatalf("expected v2")
|
||||||
|
|
||||||
if len(kv) != 2 {
|
|
||||||
t.Fatalf("Second literal source should have been added")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMergeFlagsIntoCmArgs_FileSources(t *testing.T) {
|
func TestMergeFlagsIntoConfigMapArgs_FileSources(t *testing.T) {
|
||||||
var kv []types.KVSource
|
k := &types.Kustomization{}
|
||||||
|
args := findOrMakeConfigMapArgs(k, "foo")
|
||||||
mergeFlagsIntoCmArgs(&kv, flagsAndArgs{FileSources: []string{"file1"}})
|
mergeFlagsIntoGeneratorArgs(
|
||||||
|
&args.GeneratorArgs,
|
||||||
if len(kv) != 1 {
|
flagsAndArgs{FileSources: []string{"file1"}})
|
||||||
t.Fatalf("Initial file source should have been added")
|
mergeFlagsIntoGeneratorArgs(
|
||||||
|
&args.GeneratorArgs,
|
||||||
|
flagsAndArgs{FileSources: []string{"file2"}})
|
||||||
|
if k.ConfigMapGenerator[0].FileSources[0] != "file1" {
|
||||||
|
t.Fatalf("expected file1")
|
||||||
}
|
}
|
||||||
|
if k.ConfigMapGenerator[0].FileSources[1] != "file2" {
|
||||||
mergeFlagsIntoCmArgs(&kv, flagsAndArgs{FileSources: []string{"file2"}})
|
t.Fatalf("expected file2")
|
||||||
|
|
||||||
if len(kv) != 2 {
|
|
||||||
t.Fatalf("Second file source should have been added")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMergeFlagsIntoCmArgs_EnvSource(t *testing.T) {
|
func TestMergeFlagsIntoConfigMapArgs_EnvSource(t *testing.T) {
|
||||||
envFileName := "env1"
|
k := &types.Kustomization{}
|
||||||
envFileName2 := "env2"
|
args := findOrMakeConfigMapArgs(k, "foo")
|
||||||
var kv []types.KVSource
|
mergeFlagsIntoGeneratorArgs(
|
||||||
|
&args.GeneratorArgs,
|
||||||
mergeFlagsIntoCmArgs(&kv, flagsAndArgs{EnvFileSource: envFileName})
|
flagsAndArgs{EnvFileSource: "env1"})
|
||||||
|
mergeFlagsIntoGeneratorArgs(
|
||||||
if len(kv) != 1 {
|
&args.GeneratorArgs,
|
||||||
t.Fatalf("Initial env source should have been added")
|
flagsAndArgs{EnvFileSource: "env2"})
|
||||||
|
if k.ConfigMapGenerator[0].EnvSources[0] != "env1" {
|
||||||
|
t.Fatalf("expected env1")
|
||||||
}
|
}
|
||||||
|
if k.ConfigMapGenerator[0].EnvSources[1] != "env2" {
|
||||||
mergeFlagsIntoCmArgs(&kv, flagsAndArgs{EnvFileSource: envFileName2})
|
t.Fatalf("expected env2")
|
||||||
if len(kv) != 2 {
|
|
||||||
t.Fatalf("Second env source should have been added")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2019 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
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 add
|
package add
|
||||||
|
|
||||||
@@ -109,45 +96,41 @@ func addSecret(
|
|||||||
ldr ifc.Loader,
|
ldr ifc.Loader,
|
||||||
k *types.Kustomization,
|
k *types.Kustomization,
|
||||||
flags flagsAndArgs, kf ifc.KunstructuredFactory) error {
|
flags flagsAndArgs, kf ifc.KunstructuredFactory) error {
|
||||||
secretArgs := makeSecretArgs(k, flags.Name, flags.Type)
|
args := findOrMakeSecretArgs(k, flags.Name, flags.Type)
|
||||||
mergeFlagsIntoSecretArgs(&secretArgs.KVSources, flags)
|
mergeFlagsIntoGeneratorArgs(&args.GeneratorArgs, flags)
|
||||||
// Validate by trying to create corev1.secret.
|
// Validate by trying to create corev1.secret.
|
||||||
_, err := kf.MakeSecret(ldr, k.GeneratorOptions, secretArgs)
|
_, err := kf.MakeSecret(ldr, k.GeneratorOptions, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeSecretArgs(m *types.Kustomization, name, secretType string) *types.SecretArgs {
|
func findOrMakeSecretArgs(m *types.Kustomization, name, secretType string) *types.SecretArgs {
|
||||||
for i, v := range m.SecretGenerator {
|
for i, v := range m.SecretGenerator {
|
||||||
if name == v.Name {
|
if name == v.Name {
|
||||||
return &m.SecretGenerator[i]
|
return &m.SecretGenerator[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// secret not found, create new one and add it to the kustomization file.
|
// secret not found, create new one and add it to the kustomization file.
|
||||||
secret := &types.SecretArgs{GeneratorArgs: types.GeneratorArgs{Name: name}, Type: secretType}
|
secret := &types.SecretArgs{
|
||||||
|
GeneratorArgs: types.GeneratorArgs{Name: name},
|
||||||
|
Type: secretType}
|
||||||
m.SecretGenerator = append(m.SecretGenerator, *secret)
|
m.SecretGenerator = append(m.SecretGenerator, *secret)
|
||||||
return &m.SecretGenerator[len(m.SecretGenerator)-1]
|
return &m.SecretGenerator[len(m.SecretGenerator)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeFlagsIntoSecretArgs(src *[]types.KVSource, flags flagsAndArgs) {
|
func mergeFlagsIntoGeneratorArgs(args *types.GeneratorArgs, flags flagsAndArgs) {
|
||||||
if len(flags.LiteralSources) > 0 {
|
if len(flags.LiteralSources) > 0 {
|
||||||
*src = append(*src, types.KVSource{
|
args.LiteralSources = append(
|
||||||
Name: "literals",
|
args.LiteralSources, flags.LiteralSources...)
|
||||||
Args: flags.LiteralSources,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if len(flags.FileSources) > 0 {
|
if len(flags.FileSources) > 0 {
|
||||||
*src = append(*src, types.KVSource{
|
args.FileSources = append(
|
||||||
Name: "files",
|
args.FileSources, flags.FileSources...)
|
||||||
Args: flags.FileSources,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if flags.EnvFileSource != "" {
|
if flags.EnvFileSource != "" {
|
||||||
*src = append(*src, types.KVSource{
|
args.EnvSources = append(
|
||||||
Name: "envfiles",
|
args.EnvSources, flags.EnvFileSource)
|
||||||
Args: []string{flags.EnvFileSource},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2019 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
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 add
|
package add
|
||||||
|
|
||||||
@@ -41,7 +28,7 @@ func TestMakeSecretArgs(t *testing.T) {
|
|||||||
if len(kustomization.SecretGenerator) != 0 {
|
if len(kustomization.SecretGenerator) != 0 {
|
||||||
t.Fatal("Initial kustomization should not have any secrets")
|
t.Fatal("Initial kustomization should not have any secrets")
|
||||||
}
|
}
|
||||||
args := makeSecretArgs(kustomization, secretName, secretType)
|
args := findOrMakeSecretArgs(kustomization, secretName, secretType)
|
||||||
|
|
||||||
if args == nil {
|
if args == nil {
|
||||||
t.Fatalf("args should always be non-nil")
|
t.Fatalf("args should always be non-nil")
|
||||||
@@ -55,7 +42,7 @@ func TestMakeSecretArgs(t *testing.T) {
|
|||||||
t.Fatalf("Pointer address for newly inserted secret generator should be same")
|
t.Fatalf("Pointer address for newly inserted secret generator should be same")
|
||||||
}
|
}
|
||||||
|
|
||||||
args2 := makeSecretArgs(kustomization, secretName, secretType)
|
args2 := findOrMakeSecretArgs(kustomization, secretName, secretType)
|
||||||
|
|
||||||
if args2 != args {
|
if args2 != args {
|
||||||
t.Fatalf("should have returned an existing args with name: %v", secretName)
|
t.Fatalf("should have returned an existing args with name: %v", secretName)
|
||||||
@@ -67,50 +54,52 @@ func TestMakeSecretArgs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMergeFlagsIntoSecretArgs_LiteralSources(t *testing.T) {
|
func TestMergeFlagsIntoSecretArgs_LiteralSources(t *testing.T) {
|
||||||
var kv []types.KVSource
|
k := &types.Kustomization{}
|
||||||
|
args := findOrMakeSecretArgs(k, "foo", "forbidden")
|
||||||
mergeFlagsIntoSecretArgs(&kv, flagsAndArgs{LiteralSources: []string{"k1=v1"}})
|
mergeFlagsIntoGeneratorArgs(
|
||||||
|
&args.GeneratorArgs,
|
||||||
if len(kv) != 1 {
|
flagsAndArgs{LiteralSources: []string{"k1=v1"}})
|
||||||
t.Fatalf("Initial literal source should have been added")
|
mergeFlagsIntoGeneratorArgs(
|
||||||
|
&args.GeneratorArgs,
|
||||||
|
flagsAndArgs{LiteralSources: []string{"k2=v2"}})
|
||||||
|
if k.SecretGenerator[0].LiteralSources[0] != "k1=v1" {
|
||||||
|
t.Fatalf("expected v1")
|
||||||
}
|
}
|
||||||
|
if k.SecretGenerator[0].LiteralSources[1] != "k2=v2" {
|
||||||
mergeFlagsIntoSecretArgs(&kv, flagsAndArgs{LiteralSources: []string{"k2=v2"}})
|
t.Fatalf("expected v2")
|
||||||
|
|
||||||
if len(kv) != 2 {
|
|
||||||
t.Fatalf("Second literal source should have been added")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMergeFlagsIntoSecretArgs_FileSources(t *testing.T) {
|
func TestMergeFlagsIntoSecretArgs_FileSources(t *testing.T) {
|
||||||
var kv []types.KVSource
|
k := &types.Kustomization{}
|
||||||
|
args := findOrMakeSecretArgs(k, "foo", "forbidden")
|
||||||
mergeFlagsIntoSecretArgs(&kv, flagsAndArgs{FileSources: []string{"file1"}})
|
mergeFlagsIntoGeneratorArgs(
|
||||||
|
&args.GeneratorArgs,
|
||||||
if len(kv) != 1 {
|
flagsAndArgs{FileSources: []string{"file1"}})
|
||||||
t.Fatalf("Initial file source should have been added")
|
mergeFlagsIntoGeneratorArgs(
|
||||||
|
&args.GeneratorArgs,
|
||||||
|
flagsAndArgs{FileSources: []string{"file2"}})
|
||||||
|
if k.SecretGenerator[0].FileSources[0] != "file1" {
|
||||||
|
t.Fatalf("expected file1")
|
||||||
}
|
}
|
||||||
|
if k.SecretGenerator[0].FileSources[1] != "file2" {
|
||||||
mergeFlagsIntoSecretArgs(&kv, flagsAndArgs{FileSources: []string{"file2"}})
|
t.Fatalf("expected file2")
|
||||||
|
|
||||||
if len(kv) != 2 {
|
|
||||||
t.Fatalf("Second file source should have been added")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMergeFlagsIntoSecretArgs_EnvSource(t *testing.T) {
|
func TestMergeFlagsIntoSecretArgs_EnvSource(t *testing.T) {
|
||||||
envFileName := "env1"
|
k := &types.Kustomization{}
|
||||||
envFileName2 := "env2"
|
args := findOrMakeSecretArgs(k, "foo", "forbidden")
|
||||||
var kv []types.KVSource
|
mergeFlagsIntoGeneratorArgs(
|
||||||
|
&args.GeneratorArgs,
|
||||||
mergeFlagsIntoSecretArgs(&kv, flagsAndArgs{EnvFileSource: envFileName})
|
flagsAndArgs{EnvFileSource: "env1"})
|
||||||
|
mergeFlagsIntoGeneratorArgs(
|
||||||
if len(kv) != 1 {
|
&args.GeneratorArgs,
|
||||||
t.Fatalf("Initial env source should have been added")
|
flagsAndArgs{EnvFileSource: "env2"})
|
||||||
|
if k.SecretGenerator[0].EnvSources[0] != "env1" {
|
||||||
|
t.Fatalf("expected env1")
|
||||||
}
|
}
|
||||||
|
if k.SecretGenerator[0].EnvSources[1] != "env2" {
|
||||||
mergeFlagsIntoSecretArgs(&kv, flagsAndArgs{EnvFileSource: envFileName2})
|
t.Fatalf("expected env2")
|
||||||
if len(kv) != 2 {
|
|
||||||
t.Fatalf("Second env source should have been added")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
|
|
||||||
"sigs.k8s.io/kustomize/internal/loadertest"
|
"sigs.k8s.io/kustomize/internal/loadertest"
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/transformer"
|
"sigs.k8s.io/kustomize/k8sdeps/transformer"
|
||||||
"sigs.k8s.io/kustomize/pkg/loader"
|
"sigs.k8s.io/kustomize/pkg/loader"
|
||||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||||
@@ -33,12 +32,12 @@ type KustTestHarness struct {
|
|||||||
|
|
||||||
func NewKustTestHarness(t *testing.T, path string) *KustTestHarness {
|
func NewKustTestHarness(t *testing.T, path string) *KustTestHarness {
|
||||||
return NewKustTestHarnessWithPluginConfig(
|
return NewKustTestHarnessWithPluginConfig(
|
||||||
t, path, plugin.DefaultPluginConfig())
|
t, path, plugins.DefaultPluginConfig())
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKustTestPluginHarness(t *testing.T, path string) *KustTestHarness {
|
func NewKustTestPluginHarness(t *testing.T, path string) *KustTestHarness {
|
||||||
return NewKustTestHarnessWithPluginConfig(
|
return NewKustTestHarnessWithPluginConfig(
|
||||||
t, path, plugin.ActivePluginConfig())
|
t, path, plugins.ActivePluginConfig())
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKustTestHarnessWithPluginConfig(
|
func NewKustTestHarnessWithPluginConfig(
|
||||||
@@ -51,8 +50,7 @@ func NewKustTestHarnessFull(
|
|||||||
t *testing.T, path string,
|
t *testing.T, path string,
|
||||||
lr loader.LoadRestrictorFunc, pc *types.PluginConfig) *KustTestHarness {
|
lr loader.LoadRestrictorFunc, pc *types.PluginConfig) *KustTestHarness {
|
||||||
rf := resmap.NewFactory(resource.NewFactory(
|
rf := resmap.NewFactory(resource.NewFactory(
|
||||||
kunstruct.NewKunstructuredFactoryWithGeneratorArgs(
|
kunstruct.NewKunstructuredFactoryImpl()))
|
||||||
&types.GeneratorMetaArgs{PluginConfig: pc})))
|
|
||||||
return &KustTestHarness{
|
return &KustTestHarness{
|
||||||
t: t,
|
t: t,
|
||||||
rf: rf,
|
rf: rf,
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
|
||||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -56,7 +55,7 @@ func DefaultSrcRoot() (string, error) {
|
|||||||
}
|
}
|
||||||
nope = append(nope, root)
|
nope = append(nope, root)
|
||||||
|
|
||||||
root = plugin.DefaultPluginConfig().DirectoryPath
|
root = DefaultPluginConfig().DirectoryPath
|
||||||
if FileExists(root) {
|
if FileExists(root) {
|
||||||
return root, nil
|
return root, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,53 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2019 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
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 plugins
|
package plugins
|
||||||
|
|
||||||
const PluginSymbol = "KustomizePlugin"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
"path/filepath"
|
||||||
|
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||||
|
"sigs.k8s.io/kustomize/pkg/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
PluginSymbol = "KustomizePlugin"
|
||||||
|
flagEnablePluginsName = "enable_alpha_plugins"
|
||||||
|
flagEnablePluginsHelp = `enable plugins, an alpha feature.
|
||||||
|
See https://github.com/kubernetes-sigs/kustomize/blob/master/docs/plugins.md
|
||||||
|
`
|
||||||
|
flagErrorFmt = `
|
||||||
|
unable to load plugin %s because plugins disabled
|
||||||
|
specify the flag
|
||||||
|
--%s
|
||||||
|
to %s`
|
||||||
|
)
|
||||||
|
|
||||||
|
func ActivePluginConfig() *types.PluginConfig {
|
||||||
|
pc := DefaultPluginConfig()
|
||||||
|
pc.Enabled = true
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
func DefaultPluginConfig() *types.PluginConfig {
|
||||||
|
return &types.PluginConfig{
|
||||||
|
Enabled: false,
|
||||||
|
DirectoryPath: filepath.Join(
|
||||||
|
pgmconfig.ConfigRoot(), pgmconfig.PluginRoot),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func PluginsNotEnabledErr(name string) error {
|
||||||
|
return fmt.Errorf(
|
||||||
|
flagErrorFmt,
|
||||||
|
name,
|
||||||
|
flagEnablePluginsName,
|
||||||
|
flagEnablePluginsHelp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddEnablePluginsFlag(set *pflag.FlagSet, v *bool) {
|
||||||
|
set.BoolVar(
|
||||||
|
v, flagEnablePluginsName,
|
||||||
|
false, flagEnablePluginsHelp)
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import (
|
|||||||
|
|
||||||
"sigs.k8s.io/kustomize/internal/loadertest"
|
"sigs.k8s.io/kustomize/internal/loadertest"
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
|
||||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/pkg/resource"
|
"sigs.k8s.io/kustomize/pkg/resource"
|
||||||
)
|
)
|
||||||
@@ -52,7 +51,7 @@ s/$BAR/bar/g
|
|||||||
|
|
||||||
p := NewExecPlugin(
|
p := NewExecPlugin(
|
||||||
AbsolutePluginPath(
|
AbsolutePluginPath(
|
||||||
plugin.DefaultPluginConfig(),
|
DefaultPluginConfig(),
|
||||||
pluginConfig.Id()))
|
pluginConfig.Id()))
|
||||||
|
|
||||||
yaml, err := pluginConfig.AsYAML()
|
yaml, err := pluginConfig.AsYAML()
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2019 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
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 plugins
|
package plugins
|
||||||
|
|
||||||
@@ -115,9 +102,8 @@ func (l *Loader) absolutePluginPath(id resid.ResId) string {
|
|||||||
|
|
||||||
func (l *Loader) loadAndConfigurePlugin(
|
func (l *Loader) loadAndConfigurePlugin(
|
||||||
ldr ifc.Loader, res *resource.Resource) (c Configurable, err error) {
|
ldr ifc.Loader, res *resource.Resource) (c Configurable, err error) {
|
||||||
if !l.pc.GoEnabled {
|
if !l.pc.Enabled {
|
||||||
return nil, errors.Errorf(
|
return nil, PluginsNotEnabledErr(res.Id().Gvk().Kind)
|
||||||
"plugins not enabled, but trying to load %s", res.Id())
|
|
||||||
}
|
}
|
||||||
if p := NewExecPlugin(
|
if p := NewExecPlugin(
|
||||||
l.absolutePluginPath(res.Id())); p.isAvailable() {
|
l.absolutePluginPath(res.Id())); p.isAvailable() {
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ import (
|
|||||||
|
|
||||||
"sigs.k8s.io/kustomize/internal/loadertest"
|
"sigs.k8s.io/kustomize/internal/loadertest"
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
||||||
kvplugin "sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
. "sigs.k8s.io/kustomize/pkg/plugins"
|
||||||
"sigs.k8s.io/kustomize/pkg/plugins"
|
|
||||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/pkg/resource"
|
"sigs.k8s.io/kustomize/pkg/resource"
|
||||||
"sigs.k8s.io/kustomize/plugin"
|
"sigs.k8s.io/kustomize/plugin"
|
||||||
@@ -54,7 +53,7 @@ func TestLoader(t *testing.T) {
|
|||||||
rmF := resmap.NewFactory(resource.NewFactory(
|
rmF := resmap.NewFactory(resource.NewFactory(
|
||||||
kunstruct.NewKunstructuredFactoryImpl()))
|
kunstruct.NewKunstructuredFactoryImpl()))
|
||||||
|
|
||||||
l := plugins.NewLoader(kvplugin.ActivePluginConfig(), rmF)
|
l := NewLoader(ActivePluginConfig(), rmF)
|
||||||
if l == nil {
|
if l == nil {
|
||||||
t.Fatal("expect non-nil loader")
|
t.Fatal("expect non-nil loader")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ limitations under the License.
|
|||||||
package target_test
|
package target_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sigs.k8s.io/kustomize/pkg/plugins"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
|
||||||
"sigs.k8s.io/kustomize/pkg/kusttest"
|
"sigs.k8s.io/kustomize/pkg/kusttest"
|
||||||
"sigs.k8s.io/kustomize/pkg/loader"
|
"sigs.k8s.io/kustomize/pkg/loader"
|
||||||
)
|
)
|
||||||
@@ -225,7 +225,7 @@ spec:
|
|||||||
func TestSharedPatchDisAllowed(t *testing.T) {
|
func TestSharedPatchDisAllowed(t *testing.T) {
|
||||||
th := kusttest_test.NewKustTestHarnessFull(
|
th := kusttest_test.NewKustTestHarnessFull(
|
||||||
t, "/app/overlay",
|
t, "/app/overlay",
|
||||||
loader.RestrictionRootOnly, plugin.DefaultPluginConfig())
|
loader.RestrictionRootOnly, plugins.DefaultPluginConfig())
|
||||||
writeSmallBase(th)
|
writeSmallBase(th)
|
||||||
th.WriteK("/app/overlay", `
|
th.WriteK("/app/overlay", `
|
||||||
commonLabels:
|
commonLabels:
|
||||||
@@ -257,7 +257,7 @@ spec:
|
|||||||
func TestSharedPatchAllowed(t *testing.T) {
|
func TestSharedPatchAllowed(t *testing.T) {
|
||||||
th := kusttest_test.NewKustTestHarnessFull(
|
th := kusttest_test.NewKustTestHarnessFull(
|
||||||
t, "/app/overlay",
|
t, "/app/overlay",
|
||||||
loader.RestrictionNone, plugin.DefaultPluginConfig())
|
loader.RestrictionNone, plugins.DefaultPluginConfig())
|
||||||
writeSmallBase(th)
|
writeSmallBase(th)
|
||||||
th.WriteK("/app/overlay", `
|
th.WriteK("/app/overlay", `
|
||||||
commonLabels:
|
commonLabels:
|
||||||
|
|||||||
@@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2019 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 target_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/pkg/kusttest"
|
|
||||||
)
|
|
||||||
|
|
||||||
const result = `
|
|
||||||
apiVersion: v1
|
|
||||||
data:
|
|
||||||
FRUIT: YXBwbGU=
|
|
||||||
MOUNTAIN: ZXZlcmVzdA==
|
|
||||||
OCEAN: cGFjaWZpYw==
|
|
||||||
VEGETABLE: Y2Fycm90
|
|
||||||
foo.env: Ck1PVU5UQUlOPWV2ZXJlc3QKT0NFQU49cGFjaWZpYwo=
|
|
||||||
passphrase: ZGF0IHBocmFzZQ==
|
|
||||||
kind: Secret
|
|
||||||
metadata:
|
|
||||||
name: bob-kf5c9fccbt
|
|
||||||
type: Opaque
|
|
||||||
`
|
|
||||||
|
|
||||||
func writeDataFiles(th *kusttest_test.KustTestHarness) {
|
|
||||||
th.WriteF("/app/foo.env", `
|
|
||||||
MOUNTAIN=everest
|
|
||||||
OCEAN=pacific
|
|
||||||
`)
|
|
||||||
th.WriteF("/app/phrase.dat", "dat phrase")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuiltinPlugins(t *testing.T) {
|
|
||||||
th := kusttest_test.NewKustTestHarness(t, "/app")
|
|
||||||
th.WriteK("/app", `
|
|
||||||
secretGenerator:
|
|
||||||
- name: bob
|
|
||||||
kvSources:
|
|
||||||
- pluginType: builtin
|
|
||||||
name: literals
|
|
||||||
args:
|
|
||||||
- FRUIT=apple
|
|
||||||
- VEGETABLE=carrot
|
|
||||||
- pluginType: builtin
|
|
||||||
name: files
|
|
||||||
args:
|
|
||||||
- foo.env
|
|
||||||
- passphrase=phrase.dat
|
|
||||||
- pluginType: builtin
|
|
||||||
name: envfiles
|
|
||||||
args:
|
|
||||||
- foo.env
|
|
||||||
`)
|
|
||||||
writeDataFiles(th)
|
|
||||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Err: %v", err)
|
|
||||||
}
|
|
||||||
th.AssertActualEqualsExpected(m, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuiltinIsTheDefault(t *testing.T) {
|
|
||||||
th := kusttest_test.NewKustTestHarness(t, "/app")
|
|
||||||
th.WriteK("/app", `
|
|
||||||
secretGenerator:
|
|
||||||
- name: bob
|
|
||||||
kvSources:
|
|
||||||
- name: literals
|
|
||||||
args:
|
|
||||||
- FRUIT=apple
|
|
||||||
- VEGETABLE=carrot
|
|
||||||
- name: files
|
|
||||||
args:
|
|
||||||
- foo.env
|
|
||||||
- passphrase=phrase.dat
|
|
||||||
- name: envfiles
|
|
||||||
args:
|
|
||||||
- foo.env
|
|
||||||
`)
|
|
||||||
writeDataFiles(th)
|
|
||||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Err: %v", err)
|
|
||||||
}
|
|
||||||
th.AssertActualEqualsExpected(m, result)
|
|
||||||
}
|
|
||||||
@@ -17,14 +17,50 @@ limitations under the License.
|
|||||||
package target_test
|
package target_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
|
||||||
"sigs.k8s.io/kustomize/pkg/kusttest"
|
"sigs.k8s.io/kustomize/pkg/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestSecretGenerator(t *testing.T) {
|
||||||
|
th := kusttest_test.NewKustTestHarness(t, "/app")
|
||||||
|
th.WriteK("/app", `
|
||||||
|
secretGenerator:
|
||||||
|
- name: bob
|
||||||
|
literals:
|
||||||
|
- FRUIT=apple
|
||||||
|
- VEGETABLE=carrot
|
||||||
|
files:
|
||||||
|
- foo.env
|
||||||
|
- passphrase=phrase.dat
|
||||||
|
envs:
|
||||||
|
- foo.env
|
||||||
|
`)
|
||||||
|
th.WriteF("/app/foo.env", `
|
||||||
|
MOUNTAIN=everest
|
||||||
|
OCEAN=pacific
|
||||||
|
`)
|
||||||
|
th.WriteF("/app/phrase.dat", "dat phrase")
|
||||||
|
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Err: %v", err)
|
||||||
|
}
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
FRUIT: YXBwbGU=
|
||||||
|
MOUNTAIN: ZXZlcmVzdA==
|
||||||
|
OCEAN: cGFjaWZpYw==
|
||||||
|
VEGETABLE: Y2Fycm90
|
||||||
|
foo.env: Ck1PVU5UQUlOPWV2ZXJlc3QKT0NFQU49cGFjaWZpYwo=
|
||||||
|
passphrase: ZGF0IHBocmFzZQ==
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: bob-kf5c9fccbt
|
||||||
|
type: Opaque
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
func TestGeneratorOptionsWithBases(t *testing.T) {
|
func TestGeneratorOptionsWithBases(t *testing.T) {
|
||||||
th := kusttest_test.NewKustTestHarness(t, "/app/overlay")
|
th := kusttest_test.NewKustTestHarness(t, "/app/overlay")
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
@@ -77,47 +113,3 @@ metadata:
|
|||||||
name: shouldNotHaveHash
|
name: shouldNotHaveHash
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGoPluginNotEnabled(t *testing.T) {
|
|
||||||
th := kusttest_test.NewKustTestHarness(t, "/app")
|
|
||||||
th.WriteK("/app", `
|
|
||||||
secretGenerator:
|
|
||||||
- name: attemptGoPlugin
|
|
||||||
kvSources:
|
|
||||||
- name: foo
|
|
||||||
pluginType: go
|
|
||||||
args:
|
|
||||||
- someArg
|
|
||||||
- someOtherArg
|
|
||||||
`)
|
|
||||||
_, err := th.MakeKustTarget().MakeCustomizedResMap()
|
|
||||||
if err == nil {
|
|
||||||
t.Fatalf("expected error")
|
|
||||||
}
|
|
||||||
if !strings.Contains(err.Error(), "enable go plugins by ") {
|
|
||||||
t.Fatalf("unexpected err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGoPluginDoesNotExist(t *testing.T) {
|
|
||||||
th := kusttest_test.NewKustTestHarnessWithPluginConfig(
|
|
||||||
t, "/app", plugin.ActivePluginConfig())
|
|
||||||
th.WriteK("/app", `
|
|
||||||
secretGenerator:
|
|
||||||
- name: attemptGoPlugin
|
|
||||||
kvSources:
|
|
||||||
- name: foo
|
|
||||||
pluginType: go
|
|
||||||
args:
|
|
||||||
- someArg
|
|
||||||
- someOtherArg
|
|
||||||
`)
|
|
||||||
_, err := th.MakeKustTarget().MakeCustomizedResMap()
|
|
||||||
if err == nil {
|
|
||||||
t.Fatalf("expected error")
|
|
||||||
}
|
|
||||||
if !strings.Contains(err.Error(),
|
|
||||||
filepath.Join("kvSources", "foo.so")) {
|
|
||||||
t.Fatalf("unexpected err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
||||||
kvplugin "sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
|
||||||
"sigs.k8s.io/kustomize/k8sdeps/transformer"
|
"sigs.k8s.io/kustomize/k8sdeps/transformer"
|
||||||
"sigs.k8s.io/kustomize/pkg/fs"
|
"sigs.k8s.io/kustomize/pkg/fs"
|
||||||
"sigs.k8s.io/kustomize/pkg/kusttest"
|
"sigs.k8s.io/kustomize/pkg/kusttest"
|
||||||
@@ -19,7 +18,6 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/pkg/resource"
|
"sigs.k8s.io/kustomize/pkg/resource"
|
||||||
"sigs.k8s.io/kustomize/pkg/target"
|
"sigs.k8s.io/kustomize/pkg/target"
|
||||||
"sigs.k8s.io/kustomize/pkg/types"
|
|
||||||
"sigs.k8s.io/kustomize/plugin"
|
"sigs.k8s.io/kustomize/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -63,12 +61,9 @@ metadata:
|
|||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
}
|
}
|
||||||
rf := resmap.NewFactory(resource.NewFactory(
|
rf := resmap.NewFactory(resource.NewFactory(
|
||||||
kunstruct.NewKunstructuredFactoryWithGeneratorArgs(
|
kunstruct.NewKunstructuredFactoryImpl()))
|
||||||
&types.GeneratorMetaArgs{
|
|
||||||
PluginConfig: kvplugin.ActivePluginConfig(),
|
|
||||||
})))
|
|
||||||
|
|
||||||
pl := plugins.NewLoader(kvplugin.ActivePluginConfig(), rf)
|
pl := plugins.NewLoader(plugins.ActivePluginConfig(), rf)
|
||||||
tg, err := target.NewKustTarget(ldr, rf, transformer.NewFactoryImpl(), pl)
|
tg, err := target.NewKustTarget(ldr, rf, transformer.NewFactoryImpl(), pl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err %v", err)
|
t.Fatalf("err %v", err)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package target_test
|
package target_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/pkg/kusttest"
|
"sigs.k8s.io/kustomize/pkg/kusttest"
|
||||||
@@ -91,6 +92,29 @@ spec:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPluginsNotEnabled(t *testing.T) {
|
||||||
|
tc := plugin.NewEnvForTest(t).Set()
|
||||||
|
defer tc.Reset()
|
||||||
|
|
||||||
|
tc.BuildGoPlugin(
|
||||||
|
"someteam.example.com", "v1", "StringPrefixer")
|
||||||
|
|
||||||
|
th := kusttest_test.NewKustTestHarness(t, "/app")
|
||||||
|
th.WriteK("/app", `
|
||||||
|
transformers:
|
||||||
|
- stringPrefixer.yaml
|
||||||
|
`)
|
||||||
|
writeStringPrefixer(th, "/app/stringPrefixer.yaml")
|
||||||
|
|
||||||
|
_, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("expected error")
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), "unable to load plugin StringPrefixer") {
|
||||||
|
t.Fatalf("unexpected err: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSedTransformer(t *testing.T) {
|
func TestSedTransformer(t *testing.T) {
|
||||||
tc := plugin.NewEnvForTest(t).Set()
|
tc := plugin.NewEnvForTest(t).Set()
|
||||||
defer tc.Reset()
|
defer tc.Reset()
|
||||||
|
|||||||
@@ -222,15 +222,6 @@ type GeneratorArgs struct {
|
|||||||
|
|
||||||
// DataSources for the generator.
|
// DataSources for the generator.
|
||||||
DataSources `json:",inline,omitempty" yaml:",inline,omitempty"`
|
DataSources `json:",inline,omitempty" yaml:",inline,omitempty"`
|
||||||
|
|
||||||
// KVSources for the generator.
|
|
||||||
KVSources []KVSource `json:",inline,omitempty" yaml:",inline,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GeneratorMetaArgs contains arguments common to generators
|
|
||||||
// that come from somewhere other than a kustomization file.
|
|
||||||
type GeneratorMetaArgs struct {
|
|
||||||
PluginConfig *PluginConfig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PluginConfig holds plugin configuration.
|
// PluginConfig holds plugin configuration.
|
||||||
@@ -241,9 +232,8 @@ type PluginConfig struct {
|
|||||||
// further categorizing plugins.
|
// further categorizing plugins.
|
||||||
DirectoryPath string
|
DirectoryPath string
|
||||||
|
|
||||||
// GoEnabled is true if goplugins are enabled.
|
// Enabled is true if plugins are enabled.
|
||||||
// See https://golang.org/pkg/plugin
|
Enabled bool
|
||||||
GoEnabled bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigMapArgs contains the metadata of how to generate a configmap.
|
// ConfigMapArgs contains the metadata of how to generate a configmap.
|
||||||
|
|||||||
Reference in New Issue
Block a user