mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 02:20:53 +00:00
Merge branch 'master' into transformer-no-create-arrays
This commit is contained in:
161
pkg/accumulator/resaccumulator.go
Normal file
161
pkg/accumulator/resaccumulator.go
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
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 accumulator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/resid"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/transformers"
|
||||
"sigs.k8s.io/kustomize/pkg/transformers/config"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
)
|
||||
|
||||
// ResAccumulator accumulates resources and the rules
|
||||
// used to customize those resources.
|
||||
type ResAccumulator struct {
|
||||
resMap resmap.ResMap
|
||||
tConfig *config.TransformerConfig
|
||||
varSet types.VarSet
|
||||
}
|
||||
|
||||
func MakeEmptyAccumulator() *ResAccumulator {
|
||||
ra := &ResAccumulator{}
|
||||
ra.resMap = make(resmap.ResMap)
|
||||
ra.tConfig = &config.TransformerConfig{}
|
||||
ra.varSet = types.VarSet{}
|
||||
return ra
|
||||
}
|
||||
|
||||
// ResMap returns a copy of the internal resMap.
|
||||
func (ra *ResAccumulator) ResMap() resmap.ResMap {
|
||||
result := make(resmap.ResMap)
|
||||
for k, v := range ra.resMap {
|
||||
result[k] = v
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Vars returns a copy of underlying vars.
|
||||
func (ra *ResAccumulator) Vars() []types.Var {
|
||||
return ra.varSet.Set()
|
||||
}
|
||||
|
||||
func (ra *ResAccumulator) MergeResourcesWithErrorOnIdCollision(
|
||||
resources resmap.ResMap) (err error) {
|
||||
ra.resMap, err = resmap.MergeWithErrorOnIdCollision(
|
||||
resources, ra.resMap)
|
||||
return err
|
||||
}
|
||||
|
||||
func (ra *ResAccumulator) MergeResourcesWithOverride(
|
||||
resources resmap.ResMap) (err error) {
|
||||
ra.resMap, err = resmap.MergeWithOverride(
|
||||
ra.resMap, resources)
|
||||
return err
|
||||
}
|
||||
|
||||
func (ra *ResAccumulator) MergeConfig(
|
||||
tConfig *config.TransformerConfig) (err error) {
|
||||
ra.tConfig, err = ra.tConfig.Merge(tConfig)
|
||||
return err
|
||||
}
|
||||
|
||||
func (ra *ResAccumulator) GetTransformerConfig() *config.TransformerConfig {
|
||||
return ra.tConfig
|
||||
}
|
||||
|
||||
func (ra *ResAccumulator) MergeVars(incoming []types.Var) error {
|
||||
return ra.varSet.MergeSlice(incoming)
|
||||
}
|
||||
|
||||
func (ra *ResAccumulator) MergeAccumulator(other *ResAccumulator) (err error) {
|
||||
err = ra.MergeResourcesWithErrorOnIdCollision(other.resMap)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ra.MergeConfig(other.tConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ra.varSet.MergeSet(&other.varSet)
|
||||
}
|
||||
|
||||
// makeVarReplacementMap returns a map of Var names to
|
||||
// their final values. The values are strings intended
|
||||
// for substitution wherever the $(var.Name) occurs.
|
||||
func (ra *ResAccumulator) makeVarReplacementMap() (map[string]string, error) {
|
||||
result := map[string]string{}
|
||||
for _, v := range ra.Vars() {
|
||||
matched := ra.resMap.GetMatchingIds(
|
||||
resid.NewResId(v.ObjRef.GVK(), v.ObjRef.Name).GvknEquals)
|
||||
if len(matched) > 1 {
|
||||
return nil, fmt.Errorf(
|
||||
"found %d resId matches for var %s "+
|
||||
"(unable to disambiguate)",
|
||||
len(matched), v)
|
||||
}
|
||||
if len(matched) == 1 {
|
||||
s, err := ra.resMap[matched[0]].GetFieldValue(v.FieldRef.FieldPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"field specified in var '%v' "+
|
||||
"not found in corresponding resource", v)
|
||||
}
|
||||
result[v.Name] = s
|
||||
} else {
|
||||
return nil, fmt.Errorf(
|
||||
"var '%v' cannot be mapped to a field "+
|
||||
"in the set of known resources", v)
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (ra *ResAccumulator) Transform(t transformers.Transformer) error {
|
||||
return t.Transform(ra.resMap)
|
||||
}
|
||||
|
||||
func (ra *ResAccumulator) ResolveVars() error {
|
||||
replacementMap, err := ra.makeVarReplacementMap()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(replacementMap) == 0 {
|
||||
return nil
|
||||
}
|
||||
t := transformers.NewRefVarTransformer(
|
||||
replacementMap, ra.tConfig.VarReference)
|
||||
err = ra.Transform(t)
|
||||
if len(t.UnusedVars()) > 0 {
|
||||
log.Printf(
|
||||
"well-defined vars that were never replaced: %s\n",
|
||||
strings.Join(t.UnusedVars(), ","))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (ra *ResAccumulator) FixBackReferences() (err error) {
|
||||
if ra.tConfig.NameReference == nil {
|
||||
return nil
|
||||
}
|
||||
return ra.Transform(transformers.NewNameReferenceTransformer(
|
||||
ra.tConfig.NameReference))
|
||||
}
|
||||
284
pkg/accumulator/resaccumulator_test.go
Normal file
284
pkg/accumulator/resaccumulator_test.go
Normal file
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
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 accumulator_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
||||
. "sigs.k8s.io/kustomize/pkg/accumulator"
|
||||
"sigs.k8s.io/kustomize/pkg/gvk"
|
||||
"sigs.k8s.io/kustomize/pkg/resid"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/pkg/transformers/config"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
)
|
||||
|
||||
func makeResAccumulator() (*ResAccumulator, *resource.Factory, error) {
|
||||
ra := MakeEmptyAccumulator()
|
||||
err := ra.MergeConfig(config.MakeDefaultConfig())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
rf := resource.NewFactory(
|
||||
kunstruct.NewKunstructuredFactoryImpl())
|
||||
ra.MergeResourcesWithErrorOnIdCollision(resmap.ResMap{
|
||||
resid.NewResId(
|
||||
gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"},
|
||||
"deploy1"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "deploy1",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"template": map[string]interface{}{
|
||||
"spec": map[string]interface{}{
|
||||
"containers": []interface{}{
|
||||
map[string]interface{}{
|
||||
"command": []interface{}{
|
||||
"myserver",
|
||||
"--somebackendService $(SERVICE_ONE)",
|
||||
"--yetAnother $(SERVICE_TWO)",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
resid.NewResId(
|
||||
gvk.Gvk{Version: "v1", Kind: "Service"},
|
||||
"backendOne"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Service",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "backendOne",
|
||||
},
|
||||
}),
|
||||
resid.NewResId(
|
||||
gvk.Gvk{Version: "v1", Kind: "Service"},
|
||||
"backendTwo"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Service",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "backendTwo",
|
||||
},
|
||||
}),
|
||||
})
|
||||
return ra, rf, nil
|
||||
}
|
||||
|
||||
func TestResolveVarsHappy(t *testing.T) {
|
||||
ra, _, err := makeResAccumulator()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
err = ra.MergeVars([]types.Var{
|
||||
{
|
||||
Name: "SERVICE_ONE",
|
||||
ObjRef: types.Target{
|
||||
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
|
||||
Name: "backendOne"},
|
||||
},
|
||||
{
|
||||
Name: "SERVICE_TWO",
|
||||
ObjRef: types.Target{
|
||||
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
|
||||
Name: "backendTwo"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
err = ra.ResolveVars()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
c := getCommand(find("deploy1", ra.ResMap()))
|
||||
if c != "myserver --somebackendService backendOne --yetAnother backendTwo" {
|
||||
t.Fatalf("unexpected command: %s", c)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveVarsOneUnused(t *testing.T) {
|
||||
ra, _, err := makeResAccumulator()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
err = ra.MergeVars([]types.Var{
|
||||
{
|
||||
Name: "SERVICE_ONE",
|
||||
ObjRef: types.Target{
|
||||
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
|
||||
Name: "backendOne"},
|
||||
},
|
||||
{
|
||||
Name: "SERVICE_UNUSED",
|
||||
ObjRef: types.Target{
|
||||
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
|
||||
Name: "backendTwo"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
log.SetOutput(&buf)
|
||||
defer func() {
|
||||
log.SetOutput(os.Stderr)
|
||||
}()
|
||||
err = ra.ResolveVars()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
expectLog(t, buf, "well-defined vars that were never replaced: SERVICE_UNUSED")
|
||||
c := getCommand(find("deploy1", ra.ResMap()))
|
||||
if c != "myserver --somebackendService backendOne --yetAnother $(SERVICE_TWO)" {
|
||||
t.Fatalf("unexpected command: %s", c)
|
||||
}
|
||||
}
|
||||
|
||||
func expectLog(t *testing.T, log bytes.Buffer, expect string) {
|
||||
if !strings.Contains(log.String(), expect) {
|
||||
t.Fatalf("expected log containing '%s', got '%s'", expect, log.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveVarsVarNeedsDisambiguation(t *testing.T) {
|
||||
ra, rf, err := makeResAccumulator()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
ra.MergeResourcesWithErrorOnIdCollision(resmap.ResMap{
|
||||
resid.NewResIdWithPrefixNamespace(
|
||||
gvk.Gvk{Version: "v1", Kind: "Service"},
|
||||
"backendOne", "", "fooNamespace"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Service",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "backendOne",
|
||||
},
|
||||
}),
|
||||
})
|
||||
|
||||
err = ra.MergeVars([]types.Var{
|
||||
{
|
||||
Name: "SERVICE_ONE",
|
||||
ObjRef: types.Target{
|
||||
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
|
||||
Name: "backendOne",
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
err = ra.ResolveVars()
|
||||
if err == nil {
|
||||
t.Fatalf("expected error")
|
||||
}
|
||||
if !strings.Contains(
|
||||
err.Error(), "unable to disambiguate") {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveVarsGoodResIdBadField(t *testing.T) {
|
||||
ra, _, err := makeResAccumulator()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
err = ra.MergeVars([]types.Var{
|
||||
{
|
||||
Name: "SERVICE_ONE",
|
||||
ObjRef: types.Target{
|
||||
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
|
||||
Name: "backendOne"},
|
||||
FieldRef: types.FieldSelector{FieldPath: "nope_nope_nope"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
err = ra.ResolveVars()
|
||||
if err == nil {
|
||||
t.Fatalf("expected error")
|
||||
}
|
||||
if !strings.Contains(
|
||||
err.Error(),
|
||||
"not found in corresponding resource") {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveVarsUnmappableVar(t *testing.T) {
|
||||
ra, _, err := makeResAccumulator()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
err = ra.MergeVars([]types.Var{
|
||||
{
|
||||
Name: "SERVICE_THREE",
|
||||
ObjRef: types.Target{
|
||||
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
|
||||
Name: "doesNotExist"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
err = ra.ResolveVars()
|
||||
if err == nil {
|
||||
t.Fatalf("expected error")
|
||||
}
|
||||
if !strings.Contains(
|
||||
err.Error(),
|
||||
"cannot be mapped to a field in the set of known resources") {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func find(name string, resMap resmap.ResMap) *resource.Resource {
|
||||
for k, v := range resMap {
|
||||
if k.Name() == name {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Assumes arg is a deployment, returns the command of first container.
|
||||
func getCommand(r *resource.Resource) string {
|
||||
var m map[string]interface{}
|
||||
var c []interface{}
|
||||
m, _ = r.Map()["spec"].(map[string]interface{})
|
||||
m, _ = m["template"].(map[string]interface{})
|
||||
m, _ = m["spec"].(map[string]interface{})
|
||||
c, _ = m["containers"].([]interface{})
|
||||
m, _ = c[0].(map[string]interface{})
|
||||
return strings.Join(m["command"].([]string), " ")
|
||||
}
|
||||
@@ -1,37 +1,42 @@
|
||||
/*
|
||||
Copyright 2017 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.
|
||||
*/
|
||||
/// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/constants"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc/transformer"
|
||||
"sigs.k8s.io/kustomize/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/pkg/plugins"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/target"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
type buildOptions struct {
|
||||
// Options contain the options for running a build
|
||||
type Options struct {
|
||||
kustomizationPath string
|
||||
outputPath string
|
||||
loadRestrictor loader.LoadRestrictorFunc
|
||||
}
|
||||
|
||||
// NewOptions creates a Options object
|
||||
func NewOptions(p, o string) *Options {
|
||||
return &Options{
|
||||
kustomizationPath: p,
|
||||
outputPath: o,
|
||||
loadRestrictor: loader.RestrictionRootOnly,
|
||||
}
|
||||
}
|
||||
|
||||
var examples = `
|
||||
@@ -51,14 +56,17 @@ url examples:
|
||||
|
||||
// NewCmdBuild creates a new build command.
|
||||
func NewCmdBuild(
|
||||
out io.Writer, fs fs.FileSystem,
|
||||
rf *resmap.Factory,
|
||||
out io.Writer, fSys fs.FileSystem,
|
||||
v ifc.Validator, rf *resmap.Factory,
|
||||
ptf transformer.Factory) *cobra.Command {
|
||||
var o buildOptions
|
||||
var o Options
|
||||
|
||||
pluginConfig := plugins.DefaultPluginConfig()
|
||||
pl := plugins.NewLoader(pluginConfig, rf)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "build [path]",
|
||||
Short: "Print current configuration per contents of " + constants.KustomizationFileName,
|
||||
Short: "Print current configuration per contents of " + pgmconfig.KustomizationFileNames[0],
|
||||
Example: examples,
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
@@ -66,49 +74,86 @@ func NewCmdBuild(
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return o.RunBuild(out, fs, rf, ptf)
|
||||
return o.RunBuild(out, v, fSys, rf, ptf, pl)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringVarP(
|
||||
&o.outputPath,
|
||||
"output", "o", "",
|
||||
"If specified, write the build output to this path.")
|
||||
loader.AddLoadRestrictionsFlag(cmd.Flags())
|
||||
plugins.AddEnablePluginsFlag(
|
||||
cmd.Flags(), &pluginConfig.Enabled)
|
||||
|
||||
cmd.AddCommand(NewCmdBuildPrune(out, v, fSys, rf, ptf, pl))
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Validate validates build command.
|
||||
func (o *buildOptions) Validate(args []string) error {
|
||||
func (o *Options) Validate(args []string) (err error) {
|
||||
if len(args) > 1 {
|
||||
return errors.New("specify one path to " + constants.KustomizationFileName)
|
||||
return errors.New(
|
||||
"specify one path to " + pgmconfig.KustomizationFileNames[0])
|
||||
}
|
||||
if len(args) == 0 {
|
||||
o.kustomizationPath = "./"
|
||||
o.kustomizationPath = loader.CWD
|
||||
} else {
|
||||
o.kustomizationPath = args[0]
|
||||
}
|
||||
|
||||
return nil
|
||||
o.loadRestrictor, err = loader.ValidateLoadRestrictorFlag()
|
||||
return
|
||||
}
|
||||
|
||||
// RunBuild runs build command.
|
||||
func (o *buildOptions) RunBuild(
|
||||
out io.Writer, fSys fs.FileSystem,
|
||||
rf *resmap.Factory, ptf transformer.Factory) error {
|
||||
ldr, err := loader.NewLoader(o.kustomizationPath, fSys)
|
||||
func (o *Options) RunBuild(
|
||||
out io.Writer, v ifc.Validator, fSys fs.FileSystem,
|
||||
rf *resmap.Factory, ptf transformer.Factory,
|
||||
pl *plugins.Loader) error {
|
||||
ldr, err := loader.NewLoader(
|
||||
o.loadRestrictor, v, o.kustomizationPath, fSys)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer ldr.Cleanup()
|
||||
kt, err := target.NewKustTarget(ldr, fSys, rf, ptf)
|
||||
kt, err := target.NewKustTarget(ldr, rf, ptf, pl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
allResources, err := kt.MakeCustomizedResMap()
|
||||
m, err := kt.MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Output the objects.
|
||||
res, err := allResources.EncodeAsYaml()
|
||||
return o.emitResources(out, fSys, m)
|
||||
}
|
||||
|
||||
func (o *Options) RunBuildPrune(
|
||||
out io.Writer, v ifc.Validator, fSys fs.FileSystem,
|
||||
rf *resmap.Factory, ptf transformer.Factory,
|
||||
pl *plugins.Loader) error {
|
||||
ldr, err := loader.NewLoader(
|
||||
o.loadRestrictor, v, o.kustomizationPath, fSys)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer ldr.Cleanup()
|
||||
kt, err := target.NewKustTarget(ldr, rf, ptf, pl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m, err := kt.MakePruneConfigMap()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return o.emitResources(out, fSys, m)
|
||||
}
|
||||
|
||||
func (o *Options) emitResources(
|
||||
out io.Writer, fSys fs.FileSystem, m resmap.ResMap) error {
|
||||
if o.outputPath != "" && fSys.IsDir(o.outputPath) {
|
||||
return writeIndividualFiles(fSys, o.outputPath, m)
|
||||
}
|
||||
res, err := m.EncodeAsYaml()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -118,3 +163,48 @@ func (o *buildOptions) RunBuild(
|
||||
_, err = out.Write(res)
|
||||
return err
|
||||
}
|
||||
|
||||
func NewCmdBuildPrune(
|
||||
out io.Writer, v ifc.Validator, fSys fs.FileSystem,
|
||||
rf *resmap.Factory, ptf transformer.Factory,
|
||||
pl *plugins.Loader) *cobra.Command {
|
||||
var o Options
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "alpha-inventory [path]",
|
||||
Short: "Print the inventory object which contains a list of all other objects",
|
||||
Example: examples,
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
err := o.Validate(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return o.RunBuildPrune(out, v, fSys, rf, ptf, pl)
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func writeIndividualFiles(
|
||||
fSys fs.FileSystem, folderPath string, m resmap.ResMap) error {
|
||||
for _, res := range m {
|
||||
filename := filepath.Join(
|
||||
folderPath,
|
||||
fmt.Sprintf(
|
||||
"%s_%s.yaml",
|
||||
strings.ToLower(res.GetGvk().String()),
|
||||
strings.ToLower(res.GetName()),
|
||||
),
|
||||
)
|
||||
out, err := yaml.Marshal(res.Map())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = fSys.WriteFile(filename, out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -17,28 +17,15 @@ limitations under the License.
|
||||
package build
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"sigs.k8s.io/kustomize/k8sdeps"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/constants"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
)
|
||||
|
||||
type buildTestCase struct {
|
||||
Description string `yaml:"description"`
|
||||
Args []string `yaml:"args"`
|
||||
Filename string `yaml:"filename"`
|
||||
// path to the file that contains the expected output
|
||||
ExpectedStdout string `yaml:"expectedStdout"`
|
||||
ExpectedError string `yaml:"expectedError"`
|
||||
func TestNewOptionsToSilenceCodeInspectionError(t *testing.T) {
|
||||
if NewOptions("foo", "bar") == nil {
|
||||
t.Fatal("could not make new options")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildValidate(t *testing.T) {
|
||||
@@ -48,14 +35,14 @@ func TestBuildValidate(t *testing.T) {
|
||||
path string
|
||||
erMsg string
|
||||
}{
|
||||
{"noargs", []string{}, "./", ""},
|
||||
{"noargs", []string{}, ".", ""},
|
||||
{"file", []string{"beans"}, "beans", ""},
|
||||
{"path", []string{"a/b/c"}, "a/b/c", ""},
|
||||
{"path", []string{"too", "many"},
|
||||
"", "specify one path to " + constants.KustomizationFileName},
|
||||
"", "specify one path to " + pgmconfig.KustomizationFileNames[0]},
|
||||
}
|
||||
for _, mycase := range cases {
|
||||
opts := buildOptions{}
|
||||
opts := Options{}
|
||||
e := opts.Validate(mycase.args)
|
||||
if len(mycase.erMsg) > 0 {
|
||||
if e == nil {
|
||||
@@ -67,7 +54,7 @@ func TestBuildValidate(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
if e != nil {
|
||||
t.Errorf("%s: unknown error %v", mycase.name, e)
|
||||
t.Errorf("%s: unknown error: %v", mycase.name, e)
|
||||
continue
|
||||
}
|
||||
if opts.kustomizationPath != mycase.path {
|
||||
@@ -75,87 +62,3 @@ func TestBuildValidate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuild(t *testing.T) {
|
||||
const updateEnvVar = "UPDATE_KUSTOMIZE_EXPECTED_DATA"
|
||||
updateKustomizeExpected := os.Getenv(updateEnvVar) == "true"
|
||||
fSys := fs.MakeRealFS()
|
||||
|
||||
var testcases []string
|
||||
filepath.Walk("testdata", func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if path == "testdata" {
|
||||
return nil
|
||||
}
|
||||
name := filepath.Base(path)
|
||||
if info.IsDir() {
|
||||
if strings.HasPrefix(name, "testcase-") {
|
||||
testcases = append(testcases, strings.TrimPrefix(name, "testcase-"))
|
||||
}
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
})
|
||||
// sanity check that we found the right folder
|
||||
if !kustfile.StringInSlice("simple", testcases) {
|
||||
t.Fatalf("Error locating testcases")
|
||||
}
|
||||
|
||||
for _, testcaseName := range testcases {
|
||||
t.Run(testcaseName,
|
||||
func(t *testing.T) {
|
||||
runBuildTestCase(t, testcaseName, updateKustomizeExpected, fSys)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected bool, fSys fs.FileSystem) {
|
||||
name := testcaseName
|
||||
testcase := buildTestCase{}
|
||||
testcaseDir := filepath.Join("testdata", "testcase-"+name)
|
||||
testcaseData, err := ioutil.ReadFile(filepath.Join(testcaseDir, "test.yaml"))
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %v", name, err)
|
||||
}
|
||||
if err := yaml.Unmarshal(testcaseData, &testcase); err != nil {
|
||||
t.Fatalf("%s: %v", name, err)
|
||||
}
|
||||
|
||||
ops := &buildOptions{
|
||||
kustomizationPath: testcase.Filename,
|
||||
}
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
f := k8sdeps.NewFactory()
|
||||
err = ops.RunBuild(
|
||||
buf, fSys,
|
||||
f.ResmapF,
|
||||
f.TransformerF)
|
||||
switch {
|
||||
case err != nil && len(testcase.ExpectedError) == 0:
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
case err != nil && len(testcase.ExpectedError) != 0:
|
||||
if !strings.Contains(err.Error(), testcase.ExpectedError) {
|
||||
t.Errorf("expected error to contain %q but got: %v", testcase.ExpectedError, err)
|
||||
}
|
||||
return
|
||||
case err == nil && len(testcase.ExpectedError) != 0:
|
||||
t.Errorf("unexpected no error")
|
||||
}
|
||||
|
||||
actualBytes := buf.Bytes()
|
||||
if !updateKustomizeExpected {
|
||||
expectedBytes, err := ioutil.ReadFile(testcase.ExpectedStdout)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(actualBytes, expectedBytes) {
|
||||
t.Errorf("\n**** Actual:\n\n%s\n\n**** doesn't equal expected:\n\n%s\n\n", actualBytes, expectedBytes)
|
||||
}
|
||||
} else {
|
||||
ioutil.WriteFile(testcase.ExpectedStdout, actualBytes, 0644)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
diff -u -N /tmp/noop/apps_v1beta2_Deployment_nginx.yaml /tmp/transformed/apps_v1beta2_Deployment_nginx.yaml
|
||||
--- /tmp/noop/apps_v1beta2_Deployment_nginx.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/apps_v1beta2_Deployment_nginx.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -1,14 +1,27 @@
|
||||
apiVersion: apps/v1beta2
|
||||
kind: Deployment
|
||||
metadata:
|
||||
+ annotations:
|
||||
+ note: This is a test annotation
|
||||
labels:
|
||||
- app: nginx
|
||||
- name: nginx
|
||||
+ app: mynginx
|
||||
+ org: example.com
|
||||
+ team: foo
|
||||
+ name: team-foo-nginx
|
||||
spec:
|
||||
+ selector:
|
||||
+ matchLabels:
|
||||
+ app: mynginx
|
||||
+ org: example.com
|
||||
+ team: foo
|
||||
template:
|
||||
metadata:
|
||||
+ annotations:
|
||||
+ note: This is a test annotation
|
||||
labels:
|
||||
- app: nginx
|
||||
+ app: mynginx
|
||||
+ org: example.com
|
||||
+ team: foo
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx
|
||||
diff -u -N /tmp/noop/networking.k8s.io_v1_NetworkPolicy_nginx.yaml /tmp/transformed/networking.k8s.io_v1_NetworkPolicy_nginx.yaml
|
||||
--- /tmp/noop/networking.k8s.io_v1_NetworkPolicy_nginx.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/networking.k8s.io_v1_NetworkPolicy_nginx.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -1,13 +1,21 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
- name: nginx
|
||||
+ annotations:
|
||||
+ note: This is a test annotation
|
||||
+ labels:
|
||||
+ app: mynginx
|
||||
+ org: example.com
|
||||
+ team: foo
|
||||
+ name: team-foo-nginx
|
||||
spec:
|
||||
ingress:
|
||||
- from:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
- app: nginx
|
||||
+ app: mynginx
|
||||
+ org: example.com
|
||||
+ team: foo
|
||||
podSelector:
|
||||
matchExpressions:
|
||||
- key: app
|
||||
diff -u -N /tmp/noop/v1_Service_nginx.yaml /tmp/transformed/v1_Service_nginx.yaml
|
||||
--- /tmp/noop/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -1,11 +1,17 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
+ annotations:
|
||||
+ note: This is a test annotation
|
||||
labels:
|
||||
- app: nginx
|
||||
- name: nginx
|
||||
+ app: mynginx
|
||||
+ org: example.com
|
||||
+ team: foo
|
||||
+ name: team-foo-nginx
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
selector:
|
||||
- app: nginx
|
||||
+ app: mynginx
|
||||
+ org: example.com
|
||||
+ team: foo
|
||||
@@ -1,71 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
org: example.com
|
||||
team: foo
|
||||
name: team-foo-nginx
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
selector:
|
||||
app: mynginx
|
||||
org: example.com
|
||||
team: foo
|
||||
---
|
||||
apiVersion: apps/v1beta2
|
||||
kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
org: example.com
|
||||
team: foo
|
||||
name: team-foo-nginx
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mynginx
|
||||
org: example.com
|
||||
team: foo
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
org: example.com
|
||||
team: foo
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx
|
||||
name: nginx
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
org: example.com
|
||||
team: foo
|
||||
name: team-foo-nginx
|
||||
spec:
|
||||
ingress:
|
||||
- from:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: mynginx
|
||||
org: example.com
|
||||
team: foo
|
||||
podSelector:
|
||||
matchExpressions:
|
||||
- key: app
|
||||
operator: In
|
||||
values:
|
||||
- test
|
||||
@@ -1,11 +0,0 @@
|
||||
namePrefix: team-foo-
|
||||
commonLabels:
|
||||
app: mynginx
|
||||
org: example.com
|
||||
team: foo
|
||||
commonAnnotations:
|
||||
note: This is a test annotation
|
||||
resources:
|
||||
- resources/deployment.yaml
|
||||
- resources/networkpolicy.yaml
|
||||
- resources/service.yaml
|
||||
@@ -1,15 +0,0 @@
|
||||
apiVersion: apps/v1beta2
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx
|
||||
@@ -1,13 +0,0 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: nginx
|
||||
spec:
|
||||
podSelector:
|
||||
matchExpressions:
|
||||
- {key: app, operator: In, values: [test]}
|
||||
ingress:
|
||||
- from:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
@@ -1,11 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
selector:
|
||||
app: nginx
|
||||
@@ -1,5 +0,0 @@
|
||||
description: base only
|
||||
args: []
|
||||
filename: testdata/testcase-base-only/in
|
||||
expectedStdout: testdata/testcase-base-only/expected.yaml
|
||||
expectedDiff: testdata/testcase-base-only/expected.diff
|
||||
@@ -1,6 +0,0 @@
|
||||
namePrefix: p1-
|
||||
configMapGenerator:
|
||||
- name: com1
|
||||
behavior: create
|
||||
literals:
|
||||
- from=base
|
||||
@@ -1,6 +0,0 @@
|
||||
namePrefix: p2-
|
||||
configMapGenerator:
|
||||
- name: com2
|
||||
behavior: create
|
||||
literals:
|
||||
- from=base
|
||||
@@ -1,16 +0,0 @@
|
||||
diff -u -N /tmp/noop/v1_ConfigMap_com1.yaml /tmp/transformed/v1_ConfigMap_com1.yaml
|
||||
--- /tmp/noop/v1_ConfigMap_com1.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_ConfigMap_com1.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -1,9 +1,11 @@
|
||||
apiVersion: v1
|
||||
data:
|
||||
+ baz: qux
|
||||
+ foo: bar
|
||||
from: overlay
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations: {}
|
||||
creationTimestamp: null
|
||||
labels: {}
|
||||
- name: p1-com1-cmdb776d5b
|
||||
+ name: p1-com1-dhbbm922gd
|
||||
@@ -1,19 +0,0 @@
|
||||
apiVersion: v1
|
||||
data:
|
||||
baz: qux
|
||||
foo: bar
|
||||
from: overlay
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations: {}
|
||||
labels: {}
|
||||
name: p1-com1-dhbbm922gd
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
from: overlay
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations: {}
|
||||
labels: {}
|
||||
name: p2-com2-c4b8md75k9
|
||||
@@ -1,9 +0,0 @@
|
||||
bases:
|
||||
- myapp/mycomponent
|
||||
- myapp/mycomponent2
|
||||
configMapGenerator:
|
||||
- name: com1
|
||||
behavior: merge
|
||||
literals:
|
||||
- foo=bar
|
||||
- baz=qux
|
||||
@@ -1,7 +0,0 @@
|
||||
bases:
|
||||
- ../../../../base/myapp/mycomponent
|
||||
configMapGenerator:
|
||||
- name: com1
|
||||
behavior: merge
|
||||
literals:
|
||||
- from=overlay
|
||||
@@ -1,7 +0,0 @@
|
||||
bases:
|
||||
- ../../../../base/myapp/mycomponent2
|
||||
configMapGenerator:
|
||||
- name: com2
|
||||
behavior: merge
|
||||
literals:
|
||||
- from=overlay
|
||||
@@ -1,5 +0,0 @@
|
||||
description: configmap generator overlay
|
||||
args: []
|
||||
filename: testdata/testcase-configmaps/overlay/dev
|
||||
expectedStdout: testdata/testcase-configmaps/expected.yaml
|
||||
expectedDiff: testdata/testcase-configmaps/expected.diff
|
||||
@@ -1,6 +0,0 @@
|
||||
apiVersion: v1beta1
|
||||
kind: Bee
|
||||
metadata:
|
||||
name: bee
|
||||
spec:
|
||||
action: fly
|
||||
@@ -1,9 +0,0 @@
|
||||
crds:
|
||||
- mycrd.json
|
||||
|
||||
resources:
|
||||
- secret.yaml
|
||||
- mykind.yaml
|
||||
- bee.yaml
|
||||
|
||||
namePrefix: test-
|
||||
@@ -1,9 +0,0 @@
|
||||
apiVersion: jingfang.example.com/v1beta1
|
||||
kind: MyKind
|
||||
metadata:
|
||||
name: mykind
|
||||
spec:
|
||||
secretRef:
|
||||
name: crdsecret
|
||||
beeRef:
|
||||
name: bee
|
||||
@@ -1,6 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: crdsecret
|
||||
data:
|
||||
PATH: YmJiYmJiYmIK
|
||||
@@ -1,36 +0,0 @@
|
||||
diff -u -N /tmp/noop/jingfang.example.com_v1beta1_MyKind_mykind.yaml /tmp/transformed/jingfang.example.com_v1beta1_MyKind_mykind.yaml
|
||||
--- /tmp/noop/jingfang.example.com_v1beta1_MyKind_mykind.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/jingfang.example.com_v1beta1_MyKind_mykind.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -1,9 +1,9 @@
|
||||
apiVersion: jingfang.example.com/v1beta1
|
||||
kind: MyKind
|
||||
metadata:
|
||||
- name: mykind
|
||||
+ name: test-mykind
|
||||
spec:
|
||||
beeRef:
|
||||
- name: bee
|
||||
+ name: test-bee
|
||||
secretRef:
|
||||
- name: crdsecret
|
||||
+ name: test-crdsecret
|
||||
diff -u -N /tmp/noop/v1beta1_Bee_bee.yaml /tmp/transformed/v1beta1_Bee_bee.yaml
|
||||
--- /tmp/noop/v1beta1_Bee_bee.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1beta1_Bee_bee.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -1,6 +1,6 @@
|
||||
apiVersion: v1beta1
|
||||
kind: Bee
|
||||
metadata:
|
||||
- name: bee
|
||||
+ name: test-bee
|
||||
spec:
|
||||
action: fly
|
||||
diff -u -N /tmp/noop/v1_Secret_crdsecret.yaml /tmp/transformed/v1_Secret_crdsecret.yaml
|
||||
--- /tmp/noop/v1_Secret_crdsecret.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_Secret_crdsecret.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -3,4 +3,4 @@
|
||||
PATH: YmJiYmJiYmIK
|
||||
kind: Secret
|
||||
metadata:
|
||||
- name: crdsecret
|
||||
+ name: test-crdsecret
|
||||
@@ -1,23 +0,0 @@
|
||||
apiVersion: v1
|
||||
data:
|
||||
PATH: YmJiYmJiYmIK
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: test-crdsecret
|
||||
---
|
||||
apiVersion: jingfang.example.com/v1beta1
|
||||
kind: MyKind
|
||||
metadata:
|
||||
name: test-mykind
|
||||
spec:
|
||||
beeRef:
|
||||
name: test-bee
|
||||
secretRef:
|
||||
name: test-crdsecret
|
||||
---
|
||||
apiVersion: v1beta1
|
||||
kind: Bee
|
||||
metadata:
|
||||
name: test-bee
|
||||
spec:
|
||||
action: fly
|
||||
@@ -1,5 +0,0 @@
|
||||
description: name reference in CRDs
|
||||
args: []
|
||||
filename: testdata/testcase-crds/crd
|
||||
expectedStdout: testdata/testcase-crds/expected.yaml
|
||||
expectedDiff: testdata/testcase-crds/expected.diff
|
||||
@@ -1,33 +0,0 @@
|
||||
apiVersion: v1
|
||||
data:
|
||||
altGreeting: Good Morning from default namespace!
|
||||
enableRisky: "false"
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: the-map-4959m5tm6c
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
altGreeting: Good Morning from non-default namespace!
|
||||
enableRisky: "false"
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: the-non-default-namespace-map-b6h49k7mt8
|
||||
namespace: non-default
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
password.txt: dmVyeSRlY3JldA==
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: the-secret-cfbmct72tb
|
||||
type: Opaque
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
password.txt: dmVyeSRlY3JldA==
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: the-non-default-namespace-secret-255294gd9d
|
||||
namespace: non-default
|
||||
type: Opaque
|
||||
@@ -1,19 +0,0 @@
|
||||
configMapGenerator:
|
||||
- name: the-non-default-namespace-map
|
||||
namespace: non-default
|
||||
literals:
|
||||
- altGreeting=Good Morning from non-default namespace!
|
||||
- enableRisky="false"
|
||||
- name: the-map
|
||||
literals:
|
||||
- altGreeting=Good Morning from default namespace!
|
||||
- enableRisky="false"
|
||||
|
||||
secretGenerator:
|
||||
- name: the-non-default-namespace-secret
|
||||
namespace: non-default
|
||||
commands:
|
||||
password.txt: "cat password.txt"
|
||||
- name: the-secret
|
||||
commands:
|
||||
password.txt: "cat password.txt"
|
||||
@@ -1 +0,0 @@
|
||||
very$ecret
|
||||
@@ -1,4 +0,0 @@
|
||||
description: generators-namespace
|
||||
args: []
|
||||
filename: testdata/testcase-generators-namespace/in
|
||||
expectedStdout: testdata/testcase-generators-namespace/expected.yaml
|
||||
@@ -1,5 +0,0 @@
|
||||
resources:
|
||||
- serviceaccount.yaml
|
||||
- rolebinding.yaml
|
||||
namePrefix: base-
|
||||
nameSuffix: -suffix
|
||||
@@ -1,11 +0,0 @@
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: rolebinding
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: Role
|
||||
name: role
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: serviceaccount
|
||||
@@ -1,4 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: serviceaccount
|
||||
@@ -1,3 +0,0 @@
|
||||
bases:
|
||||
- ../overlays/a
|
||||
- ../overlays/b
|
||||
@@ -1,8 +0,0 @@
|
||||
bases:
|
||||
- ../../base/
|
||||
|
||||
namePrefix: a-
|
||||
nameSuffix: -suffixA
|
||||
|
||||
resources:
|
||||
- serviceaccount.yaml
|
||||
@@ -1,4 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: serviceaccount
|
||||
@@ -1,5 +0,0 @@
|
||||
bases:
|
||||
- ../../base/
|
||||
|
||||
namePrefix: b-
|
||||
nameSuffix: -suffixB
|
||||
@@ -1,4 +0,0 @@
|
||||
description: multibases with name reference
|
||||
args: []
|
||||
filename: testdata/testcase-multibases-conflict/combined
|
||||
expectedError: Multiple matches for name noGroup_v1_ServiceAccount
|
||||
@@ -1,5 +0,0 @@
|
||||
resources:
|
||||
- serviceaccount.yaml
|
||||
- rolebinding.yaml
|
||||
namePrefix: base-
|
||||
nameSuffix: -suffix
|
||||
@@ -1,11 +0,0 @@
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: rolebinding
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: Role
|
||||
name: role
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: serviceaccount
|
||||
@@ -1,4 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: serviceaccount
|
||||
@@ -1,3 +0,0 @@
|
||||
bases:
|
||||
- ../overlays/a
|
||||
- ../overlays/b
|
||||
@@ -1,33 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: a-base-serviceaccount-suffix-suffixA
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: b-base-serviceaccount-suffix-suffixB
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: a-base-rolebinding-suffix-suffixA
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: Role
|
||||
name: role
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: a-base-serviceaccount-suffix-suffixA
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: b-base-rolebinding-suffix-suffixB
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: Role
|
||||
name: role
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: b-base-serviceaccount-suffix-suffixB
|
||||
@@ -1,5 +0,0 @@
|
||||
bases:
|
||||
- ../../base/
|
||||
|
||||
namePrefix: a-
|
||||
nameSuffix: -suffixA
|
||||
@@ -1,5 +0,0 @@
|
||||
bases:
|
||||
- ../../base/
|
||||
|
||||
namePrefix: b-
|
||||
nameSuffix: -suffixB
|
||||
@@ -1,4 +0,0 @@
|
||||
description: multibases with name reference
|
||||
args: []
|
||||
filename: testdata/testcase-multibases-nonconflict/combined
|
||||
expectedStdout: testdata/testcase-multibases-nonconflict/expected.yaml
|
||||
@@ -1,20 +0,0 @@
|
||||
apiVersion: apps/v1beta2
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
env:
|
||||
- name: ENABLE_FEATURE_FOO
|
||||
value: TRUE
|
||||
volumes:
|
||||
- name: nginx-persistent-storage
|
||||
emptyDir: null
|
||||
gcePersistentDisk:
|
||||
pdName: nginx-persistent-storage
|
||||
- configMap:
|
||||
name: configmap-in-overlay
|
||||
name: configmap-in-overlay
|
||||
@@ -1,12 +0,0 @@
|
||||
apiVersion: apps/v1beta2
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
env:
|
||||
- name: ENABLE_FEATURE_FOO
|
||||
value: FALSE
|
||||
@@ -1,12 +0,0 @@
|
||||
namePrefix: staging-
|
||||
commonLabels:
|
||||
env: staging
|
||||
patchesStrategicMerge:
|
||||
- deployment-patch2.yaml
|
||||
- deployment-patch1.yaml
|
||||
bases:
|
||||
- ../package/
|
||||
configMapGenerator:
|
||||
- name: configmap-in-overlay
|
||||
literals:
|
||||
- hello=world
|
||||
@@ -1,24 +0,0 @@
|
||||
apiVersion: apps/v1beta2
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx
|
||||
volumeMounts:
|
||||
- name: nginx-persistent-storage
|
||||
mountPath: /tmp/ps
|
||||
volumes:
|
||||
- name: nginx-persistent-storage
|
||||
emptyDir: {}
|
||||
- configMap:
|
||||
name: configmap-in-base
|
||||
name: configmap-in-base
|
||||
@@ -1,14 +0,0 @@
|
||||
namePrefix: team-foo-
|
||||
commonLabels:
|
||||
app: mynginx
|
||||
org: example.com
|
||||
team: foo
|
||||
commonAnnotations:
|
||||
note: This is a test annotation
|
||||
resources:
|
||||
- deployment.yaml
|
||||
- service.yaml
|
||||
configMapGenerator:
|
||||
- name: configmap-in-base
|
||||
literals:
|
||||
- foo=bar
|
||||
@@ -1,11 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
selector:
|
||||
app: nginx
|
||||
@@ -1,4 +0,0 @@
|
||||
description: conflict between multiple patches
|
||||
args: []
|
||||
filename: testdata/testcase-multiple-patches-conflict/in/overlay/
|
||||
expectedError: conflict
|
||||
@@ -1,99 +0,0 @@
|
||||
diff -u -N /tmp/noop/apps_v1beta2_Deployment_nginx.yaml /tmp/transformed/apps_v1beta2_Deployment_nginx.yaml
|
||||
--- /tmp/noop/apps_v1beta2_Deployment_nginx.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/apps_v1beta2_Deployment_nginx.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -5,13 +5,15 @@
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
+ env: staging
|
||||
org: example.com
|
||||
team: foo
|
||||
- name: team-foo-nginx
|
||||
+ name: staging-team-foo-nginx
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mynginx
|
||||
+ env: staging
|
||||
org: example.com
|
||||
team: foo
|
||||
template:
|
||||
@@ -20,18 +22,30 @@
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
+ env: staging
|
||||
org: example.com
|
||||
team: foo
|
||||
spec:
|
||||
containers:
|
||||
- - image: nginx
|
||||
+ - env:
|
||||
+ - name: ANOTHERENV
|
||||
+ value: FOO
|
||||
+ - name: ENVKEY
|
||||
+ value: ENVVALUE
|
||||
+ image: nginx:latest
|
||||
name: nginx
|
||||
volumeMounts:
|
||||
- mountPath: /tmp/ps
|
||||
name: nginx-persistent-storage
|
||||
+ - image: sidecar
|
||||
+ name: sidecar
|
||||
volumes:
|
||||
- - emptyDir: {}
|
||||
+ - gcePersistentDisk:
|
||||
+ pdName: nginx-persistent-storage
|
||||
name: nginx-persistent-storage
|
||||
- configMap:
|
||||
- name: team-foo-configmap-in-base-bbdmdh7m8t
|
||||
+ name: staging-configmap-in-overlay-k7cbc75tg8
|
||||
+ name: configmap-in-overlay
|
||||
+ - configMap:
|
||||
+ name: staging-team-foo-configmap-in-base-g7k6gt2889
|
||||
name: configmap-in-base
|
||||
diff -u -N /tmp/noop/v1_ConfigMap_configmap-in-base.yaml /tmp/transformed/v1_ConfigMap_configmap-in-base.yaml
|
||||
--- /tmp/noop/v1_ConfigMap_configmap-in-base.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_ConfigMap_configmap-in-base.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -8,6 +8,7 @@
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
app: mynginx
|
||||
+ env: staging
|
||||
org: example.com
|
||||
team: foo
|
||||
- name: team-foo-configmap-in-base-bbdmdh7m8t
|
||||
+ name: staging-team-foo-configmap-in-base-g7k6gt2889
|
||||
diff -u -N /tmp/noop/v1_ConfigMap_configmap-in-overlay.yaml /tmp/transformed/v1_ConfigMap_configmap-in-overlay.yaml
|
||||
--- /tmp/noop/v1_ConfigMap_configmap-in-overlay.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_ConfigMap_configmap-in-overlay.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -0,0 +1,9 @@
|
||||
+apiVersion: v1
|
||||
+data:
|
||||
+ hello: world
|
||||
+kind: ConfigMap
|
||||
+metadata:
|
||||
+ creationTimestamp: null
|
||||
+ labels:
|
||||
+ env: staging
|
||||
+ name: staging-configmap-in-overlay-k7cbc75tg8
|
||||
diff -u -N /tmp/noop/v1_Service_nginx.yaml /tmp/transformed/v1_Service_nginx.yaml
|
||||
--- /tmp/noop/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -5,13 +5,15 @@
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
+ env: staging
|
||||
org: example.com
|
||||
team: foo
|
||||
- name: team-foo-nginx
|
||||
+ name: staging-team-foo-nginx
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
selector:
|
||||
app: mynginx
|
||||
+ env: staging
|
||||
org: example.com
|
||||
team: foo
|
||||
@@ -1,94 +0,0 @@
|
||||
apiVersion: v1
|
||||
data:
|
||||
foo: bar
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
env: staging
|
||||
org: example.com
|
||||
team: foo
|
||||
name: staging-team-foo-configmap-in-base-g7k6gt2889
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
hello: world
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
labels:
|
||||
env: staging
|
||||
name: staging-configmap-in-overlay-k7cbc75tg8
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
env: staging
|
||||
org: example.com
|
||||
team: foo
|
||||
name: staging-team-foo-nginx
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
selector:
|
||||
app: mynginx
|
||||
env: staging
|
||||
org: example.com
|
||||
team: foo
|
||||
---
|
||||
apiVersion: apps/v1beta2
|
||||
kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
env: staging
|
||||
org: example.com
|
||||
team: foo
|
||||
name: staging-team-foo-nginx
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mynginx
|
||||
env: staging
|
||||
org: example.com
|
||||
team: foo
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
env: staging
|
||||
org: example.com
|
||||
team: foo
|
||||
spec:
|
||||
containers:
|
||||
- env:
|
||||
- name: ANOTHERENV
|
||||
value: FOO
|
||||
- name: ENVKEY
|
||||
value: ENVVALUE
|
||||
image: nginx:latest
|
||||
name: nginx
|
||||
volumeMounts:
|
||||
- mountPath: /tmp/ps
|
||||
name: nginx-persistent-storage
|
||||
- image: sidecar
|
||||
name: sidecar
|
||||
volumes:
|
||||
- gcePersistentDisk:
|
||||
pdName: nginx-persistent-storage
|
||||
name: nginx-persistent-storage
|
||||
- configMap:
|
||||
name: staging-configmap-in-overlay-k7cbc75tg8
|
||||
name: configmap-in-overlay
|
||||
- configMap:
|
||||
name: staging-team-foo-configmap-in-base-g7k6gt2889
|
||||
name: configmap-in-base
|
||||
@@ -1,12 +0,0 @@
|
||||
namePrefix: staging-
|
||||
commonLabels:
|
||||
env: staging
|
||||
patchesStrategicMerge:
|
||||
- patches/deployment-patch1.yaml
|
||||
- patches/deployment-patch2.yaml
|
||||
bases:
|
||||
- ../package/
|
||||
configMapGenerator:
|
||||
- name: configmap-in-overlay
|
||||
literals:
|
||||
- hello=world
|
||||
@@ -1,21 +0,0 @@
|
||||
apiVersion: apps/v1beta2
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:latest
|
||||
env:
|
||||
- name: ENVKEY
|
||||
value: ENVVALUE
|
||||
volumes:
|
||||
- name: nginx-persistent-storage
|
||||
emptyDir: null
|
||||
gcePersistentDisk:
|
||||
pdName: nginx-persistent-storage
|
||||
- configMap:
|
||||
name: configmap-in-overlay
|
||||
name: configmap-in-overlay
|
||||
@@ -1,16 +0,0 @@
|
||||
apiVersion: apps/v1beta2
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
env:
|
||||
- name: ANOTHERENV
|
||||
value: FOO
|
||||
- name: sidecar
|
||||
image: sidecar
|
||||
volumes:
|
||||
- name: nginx-persistent-storage
|
||||
@@ -1,24 +0,0 @@
|
||||
apiVersion: apps/v1beta2
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx
|
||||
volumeMounts:
|
||||
- name: nginx-persistent-storage
|
||||
mountPath: /tmp/ps
|
||||
volumes:
|
||||
- name: nginx-persistent-storage
|
||||
emptyDir: {}
|
||||
- configMap:
|
||||
name: configmap-in-base
|
||||
name: configmap-in-base
|
||||
@@ -1,14 +0,0 @@
|
||||
namePrefix: team-foo-
|
||||
commonLabels:
|
||||
app: mynginx
|
||||
org: example.com
|
||||
team: foo
|
||||
commonAnnotations:
|
||||
note: This is a test annotation
|
||||
resources:
|
||||
- deployment.yaml
|
||||
- service.yaml
|
||||
configMapGenerator:
|
||||
- name: configmap-in-base
|
||||
literals:
|
||||
- foo=bar
|
||||
@@ -1,11 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
selector:
|
||||
app: nginx
|
||||
@@ -1,5 +0,0 @@
|
||||
description: multiple patches no conflict
|
||||
args: []
|
||||
filename: testdata/testcase-multiple-patches-noconflict/in/overlay/
|
||||
expectedStdout: testdata/testcase-multiple-patches-noconflict/expected.yaml
|
||||
expectedDiff: testdata/testcase-multiple-patches-noconflict/expected.diff
|
||||
@@ -1,154 +0,0 @@
|
||||
diff -u -N /tmp/noop/extensions_v1beta1_Deployment_mungebot.yaml /tmp/transformed/extensions_v1beta1_Deployment_mungebot.yaml
|
||||
--- /tmp/noop/extensions_v1beta1_Deployment_mungebot.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/extensions_v1beta1_Deployment_mungebot.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -3,28 +3,68 @@
|
||||
metadata:
|
||||
annotations:
|
||||
baseAnno: This is an base annotation
|
||||
+ note: This is a test annotation
|
||||
labels:
|
||||
app: mungebot
|
||||
foo: bar
|
||||
- name: baseprefix-mungebot
|
||||
+ org: kubernetes
|
||||
+ repo: test-infra
|
||||
+ name: test-infra-baseprefix-mungebot
|
||||
spec:
|
||||
- replicas: 1
|
||||
+ replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
+ app: mungebot
|
||||
foo: bar
|
||||
+ org: kubernetes
|
||||
+ repo: test-infra
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
baseAnno: This is an base annotation
|
||||
+ note: This is a test annotation
|
||||
labels:
|
||||
app: mungebot
|
||||
foo: bar
|
||||
+ org: kubernetes
|
||||
+ repo: test-infra
|
||||
spec:
|
||||
containers:
|
||||
- env:
|
||||
+ - name: FOO
|
||||
+ valueFrom:
|
||||
+ configMapKeyRef:
|
||||
+ key: somekey
|
||||
+ name: test-infra-app-env-bh449c299k
|
||||
+ - name: BAR
|
||||
+ valueFrom:
|
||||
+ secretKeyRef:
|
||||
+ key: somekey
|
||||
+ name: test-infra-app-tls-6hkmhf2224
|
||||
- name: foo
|
||||
value: bar
|
||||
- image: nginx
|
||||
+ image: nginx:1.8.0
|
||||
name: nginx
|
||||
ports:
|
||||
- containerPort: 80
|
||||
+ - envFrom:
|
||||
+ - configMapRef:
|
||||
+ name: someConfigMap
|
||||
+ - configMapRef:
|
||||
+ name: test-infra-app-env-bh449c299k
|
||||
+ - secretRef:
|
||||
+ name: test-infra-app-tls-6hkmhf2224
|
||||
+ image: busybox
|
||||
+ name: busybox
|
||||
+ volumeMounts:
|
||||
+ - mountPath: /tmp/env
|
||||
+ name: app-env
|
||||
+ - mountPath: /tmp/tls
|
||||
+ name: app-tls
|
||||
+ volumes:
|
||||
+ - configMap:
|
||||
+ name: test-infra-app-env-bh449c299k
|
||||
+ name: app-env
|
||||
+ - name: app-tls
|
||||
+ secret:
|
||||
+ secretName: test-infra-app-tls-6hkmhf2224
|
||||
diff -u -N /tmp/noop/v1_ConfigMap_app-config.yaml /tmp/transformed/v1_ConfigMap_app-config.yaml
|
||||
--- /tmp/noop/v1_ConfigMap_app-config.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_ConfigMap_app-config.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -0,0 +1,15 @@
|
||||
+apiVersion: v1
|
||||
+data:
|
||||
+ app-init.ini: |
|
||||
+ FOO=bar
|
||||
+ BAR=baz
|
||||
+kind: ConfigMap
|
||||
+metadata:
|
||||
+ annotations:
|
||||
+ note: This is a test annotation
|
||||
+ creationTimestamp: null
|
||||
+ labels:
|
||||
+ app: mungebot
|
||||
+ org: kubernetes
|
||||
+ repo: test-infra
|
||||
+ name: test-infra-app-config-hf5424hg8g
|
||||
diff -u -N /tmp/noop/v1_ConfigMap_app-env.yaml /tmp/transformed/v1_ConfigMap_app-env.yaml
|
||||
--- /tmp/noop/v1_ConfigMap_app-env.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_ConfigMap_app-env.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -0,0 +1,14 @@
|
||||
+apiVersion: v1
|
||||
+data:
|
||||
+ DB_PASSWORD: somepw
|
||||
+ DB_USERNAME: admin
|
||||
+kind: ConfigMap
|
||||
+metadata:
|
||||
+ annotations:
|
||||
+ note: This is a test annotation
|
||||
+ creationTimestamp: null
|
||||
+ labels:
|
||||
+ app: mungebot
|
||||
+ org: kubernetes
|
||||
+ repo: test-infra
|
||||
+ name: test-infra-app-env-bh449c299k
|
||||
diff -u -N /tmp/noop/v1_Secret_app-tls.yaml /tmp/transformed/v1_Secret_app-tls.yaml
|
||||
--- /tmp/noop/v1_Secret_app-tls.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_Secret_app-tls.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -0,0 +1,15 @@
|
||||
+apiVersion: v1
|
||||
+data:
|
||||
+ tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUIwekNDQVgyZ0F3SUJBZ0lKQUkvTTdCWWp3Qit1TUEwR0NTcUdTSWIzRFFFQkJRVUFNRVV4Q3pBSkJnTlYKQkFZVEFrRlZNUk13RVFZRFZRUUlEQXBUYjIxbExWTjBZWFJsTVNFd0h3WURWUVFLREJoSmJuUmxjbTVsZENCWAphV1JuYVhSeklGQjBlU0JNZEdRd0hoY05NVEl3T1RFeU1qRTFNakF5V2hjTk1UVXdPVEV5TWpFMU1qQXlXakJGCk1Rc3dDUVlEVlFRR0V3SkJWVEVUTUJFR0ExVUVDQXdLVTI5dFpTMVRkR0YwWlRFaE1COEdBMVVFQ2d3WVNXNTAKWlhKdVpYUWdWMmxrWjJsMGN5QlFkSGtnVEhSa01Gd3dEUVlKS29aSWh2Y05BUUVCQlFBRFN3QXdTQUpCQU5MSgpoUEhoSVRxUWJQa2xHM2liQ1Z4d0dNUmZwL3Y0WHFoZmRRSGRjVmZIYXA2TlE1V29rLzR4SUErdWkzNS9NbU5hCnJ0TnVDK0JkWjF0TXVWQ1BGWmNDQXdFQUFhTlFNRTR3SFFZRFZSME9CQllFRkp2S3M4UmZKYVhUSDA4VytTR3YKelF5S24wSDhNQjhHQTFVZEl3UVlNQmFBRkp2S3M4UmZKYVhUSDA4VytTR3Z6UXlLbjBIOE1Bd0dBMVVkRXdRRgpNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUZCUUFEUVFCSmxmZkpIeWJqREd4Uk1xYVJtRGhYMCs2djAyVFVLWnNXCnI1UXVWYnBRaEg2dSswVWdjVzBqcDlRd3B4b1BUTFRXR1hFV0JCQnVyeEZ3aUNCaGtRK1YKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
|
||||
+ tls.key: LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlCT3dJQkFBSkJBTkxKaFBIaElUcVFiUGtsRzNpYkNWeHdHTVJmcC92NFhxaGZkUUhkY1ZmSGFwNk5RNVdvCmsvNHhJQSt1aTM1L01tTmFydE51QytCZFoxdE11VkNQRlpjQ0F3RUFBUUpBRUoyTit6c1IwWG44L1E2dHdhNEcKNk9CMU0xV08rayt6dG5YLzFTdk5lV3U4RDZHSW10dXBMVFlnalpjSHVmeWtqMDlqaUhtakh4OHU4WlpCL28xTgpNUUloQVBXK2V5Wm83YXkzbE16MVYwMVdWak5LSzlRU24xTUpsYjA2aC9MdVl2OUZBaUVBMjVXUGVkS2dWeUNXClNtVXdiUHc4Zm5UY3BxRFdFM3lUTzN2S2NlYnFNU3NDSUJGM1VtVnVlOFlVM2p5YkMzTnh1WHEzd05tMzRSOFQKeFZMSHdEWGgvNk5KQWlFQWwyb0hHR0x6NjRCdUFmaktycXd6N3FNWXI5SENMSWUvWXNvV3Evb2x6U2NDSVFEaQpEMmxXdXNvZTIvbkVxZkRWVldHV2x5Sjd5T21xYVZtL2lOVU45QjJOMmc9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=
|
||||
+kind: Secret
|
||||
+metadata:
|
||||
+ annotations:
|
||||
+ note: This is a test annotation
|
||||
+ creationTimestamp: null
|
||||
+ labels:
|
||||
+ app: mungebot
|
||||
+ org: kubernetes
|
||||
+ repo: test-infra
|
||||
+ name: test-infra-app-tls-6hkmhf2224
|
||||
+type: kubernetes.io/tls
|
||||
diff -u -N /tmp/noop/v1_Service_mungebot-service.yaml /tmp/transformed/v1_Service_mungebot-service.yaml
|
||||
--- /tmp/noop/v1_Service_mungebot-service.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_Service_mungebot-service.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -3,13 +3,18 @@
|
||||
metadata:
|
||||
annotations:
|
||||
baseAnno: This is an base annotation
|
||||
+ note: This is a test annotation
|
||||
labels:
|
||||
app: mungebot
|
||||
foo: bar
|
||||
- name: baseprefix-mungebot-service
|
||||
+ org: kubernetes
|
||||
+ repo: test-infra
|
||||
+ name: test-infra-baseprefix-mungebot-service
|
||||
spec:
|
||||
ports:
|
||||
- port: 7002
|
||||
selector:
|
||||
app: mungebot
|
||||
foo: bar
|
||||
+ org: kubernetes
|
||||
+ repo: test-infra
|
||||
@@ -1,135 +0,0 @@
|
||||
apiVersion: v1
|
||||
data:
|
||||
app-init.ini: |
|
||||
FOO=bar
|
||||
BAR=baz
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mungebot
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
name: test-infra-app-config-hf5424hg8g
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
DB_PASSWORD: somepw
|
||||
DB_USERNAME: admin
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mungebot
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
name: test-infra-app-env-bh449c299k
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUIwekNDQVgyZ0F3SUJBZ0lKQUkvTTdCWWp3Qit1TUEwR0NTcUdTSWIzRFFFQkJRVUFNRVV4Q3pBSkJnTlYKQkFZVEFrRlZNUk13RVFZRFZRUUlEQXBUYjIxbExWTjBZWFJsTVNFd0h3WURWUVFLREJoSmJuUmxjbTVsZENCWAphV1JuYVhSeklGQjBlU0JNZEdRd0hoY05NVEl3T1RFeU1qRTFNakF5V2hjTk1UVXdPVEV5TWpFMU1qQXlXakJGCk1Rc3dDUVlEVlFRR0V3SkJWVEVUTUJFR0ExVUVDQXdLVTI5dFpTMVRkR0YwWlRFaE1COEdBMVVFQ2d3WVNXNTAKWlhKdVpYUWdWMmxrWjJsMGN5QlFkSGtnVEhSa01Gd3dEUVlKS29aSWh2Y05BUUVCQlFBRFN3QXdTQUpCQU5MSgpoUEhoSVRxUWJQa2xHM2liQ1Z4d0dNUmZwL3Y0WHFoZmRRSGRjVmZIYXA2TlE1V29rLzR4SUErdWkzNS9NbU5hCnJ0TnVDK0JkWjF0TXVWQ1BGWmNDQXdFQUFhTlFNRTR3SFFZRFZSME9CQllFRkp2S3M4UmZKYVhUSDA4VytTR3YKelF5S24wSDhNQjhHQTFVZEl3UVlNQmFBRkp2S3M4UmZKYVhUSDA4VytTR3Z6UXlLbjBIOE1Bd0dBMVVkRXdRRgpNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUZCUUFEUVFCSmxmZkpIeWJqREd4Uk1xYVJtRGhYMCs2djAyVFVLWnNXCnI1UXVWYnBRaEg2dSswVWdjVzBqcDlRd3B4b1BUTFRXR1hFV0JCQnVyeEZ3aUNCaGtRK1YKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
|
||||
tls.key: LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlCT3dJQkFBSkJBTkxKaFBIaElUcVFiUGtsRzNpYkNWeHdHTVJmcC92NFhxaGZkUUhkY1ZmSGFwNk5RNVdvCmsvNHhJQSt1aTM1L01tTmFydE51QytCZFoxdE11VkNQRlpjQ0F3RUFBUUpBRUoyTit6c1IwWG44L1E2dHdhNEcKNk9CMU0xV08rayt6dG5YLzFTdk5lV3U4RDZHSW10dXBMVFlnalpjSHVmeWtqMDlqaUhtakh4OHU4WlpCL28xTgpNUUloQVBXK2V5Wm83YXkzbE16MVYwMVdWak5LSzlRU24xTUpsYjA2aC9MdVl2OUZBaUVBMjVXUGVkS2dWeUNXClNtVXdiUHc4Zm5UY3BxRFdFM3lUTzN2S2NlYnFNU3NDSUJGM1VtVnVlOFlVM2p5YkMzTnh1WHEzd05tMzRSOFQKeFZMSHdEWGgvNk5KQWlFQWwyb0hHR0x6NjRCdUFmaktycXd6N3FNWXI5SENMSWUvWXNvV3Evb2x6U2NDSVFEaQpEMmxXdXNvZTIvbkVxZkRWVldHV2x5Sjd5T21xYVZtL2lOVU45QjJOMmc9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=
|
||||
kind: Secret
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mungebot
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
name: test-infra-app-tls-6hkmhf2224
|
||||
type: kubernetes.io/tls
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations:
|
||||
baseAnno: This is an base annotation
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mungebot
|
||||
foo: bar
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
name: test-infra-baseprefix-mungebot-service
|
||||
spec:
|
||||
ports:
|
||||
- port: 7002
|
||||
selector:
|
||||
app: mungebot
|
||||
foo: bar
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
---
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
baseAnno: This is an base annotation
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mungebot
|
||||
foo: bar
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
name: test-infra-baseprefix-mungebot
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mungebot
|
||||
foo: bar
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
baseAnno: This is an base annotation
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mungebot
|
||||
foo: bar
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
spec:
|
||||
containers:
|
||||
- env:
|
||||
- name: FOO
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
key: somekey
|
||||
name: test-infra-app-env-bh449c299k
|
||||
- name: BAR
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
key: somekey
|
||||
name: test-infra-app-tls-6hkmhf2224
|
||||
- name: foo
|
||||
value: bar
|
||||
image: nginx:1.8.0
|
||||
name: nginx
|
||||
ports:
|
||||
- containerPort: 80
|
||||
- envFrom:
|
||||
- configMapRef:
|
||||
name: someConfigMap
|
||||
- configMapRef:
|
||||
name: test-infra-app-env-bh449c299k
|
||||
- secretRef:
|
||||
name: test-infra-app-tls-6hkmhf2224
|
||||
image: busybox
|
||||
name: busybox
|
||||
volumeMounts:
|
||||
- mountPath: /tmp/env
|
||||
name: app-env
|
||||
- mountPath: /tmp/tls
|
||||
name: app-tls
|
||||
volumes:
|
||||
- configMap:
|
||||
name: test-infra-app-env-bh449c299k
|
||||
name: app-env
|
||||
- name: app-tls
|
||||
secret:
|
||||
secretName: test-infra-app-tls-6hkmhf2224
|
||||
@@ -1,5 +0,0 @@
|
||||
description: simple
|
||||
args: []
|
||||
filename: ../../examplelayout/simple/instances/exampleinstance/
|
||||
expectedStdout: testdata/testcase-simple/expected.yaml
|
||||
expectedDiff: testdata/testcase-simple/expected.diff
|
||||
@@ -1,128 +0,0 @@
|
||||
diff -u -N /tmp/noop/apps_v1beta2_Deployment_nginx.yaml /tmp/transformed/apps_v1beta2_Deployment_nginx.yaml
|
||||
--- /tmp/noop/apps_v1beta2_Deployment_nginx.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/apps_v1beta2_Deployment_nginx.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -5,23 +5,26 @@
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
+ env: staging
|
||||
org: example.com
|
||||
- team: foo
|
||||
- name: team-foo-nginx
|
||||
+ team: override-foo
|
||||
+ name: staging-team-foo-nginx
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mynginx
|
||||
+ env: staging
|
||||
org: example.com
|
||||
- team: foo
|
||||
+ team: override-foo
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
+ env: staging
|
||||
org: example.com
|
||||
- team: foo
|
||||
+ team: override-foo
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx
|
||||
@@ -30,8 +33,12 @@
|
||||
- mountPath: /tmp/ps
|
||||
name: nginx-persistent-storage
|
||||
volumes:
|
||||
- - emptyDir: {}
|
||||
+ - gcePersistentDisk:
|
||||
+ pdName: nginx-persistent-storage
|
||||
name: nginx-persistent-storage
|
||||
- configMap:
|
||||
- name: team-foo-configmap-in-base-bbdmdh7m8t
|
||||
+ name: staging-configmap-in-overlay-k7cbc75tg8
|
||||
+ name: configmap-in-overlay
|
||||
+ - configMap:
|
||||
+ name: staging-team-foo-configmap-in-base-gh9d7t85gb
|
||||
name: configmap-in-base
|
||||
diff -u -N /tmp/noop/v1_ConfigMap_configmap-in-base.yaml /tmp/transformed/v1_ConfigMap_configmap-in-base.yaml
|
||||
--- /tmp/noop/v1_ConfigMap_configmap-in-base.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_ConfigMap_configmap-in-base.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -1,6 +1,6 @@
|
||||
apiVersion: v1
|
||||
data:
|
||||
- foo: bar
|
||||
+ foo: override-bar
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations:
|
||||
@@ -8,6 +8,7 @@
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
app: mynginx
|
||||
+ env: staging
|
||||
org: example.com
|
||||
- team: foo
|
||||
- name: team-foo-configmap-in-base-bbdmdh7m8t
|
||||
+ team: override-foo
|
||||
+ name: staging-team-foo-configmap-in-base-gh9d7t85gb
|
||||
diff -u -N /tmp/noop/v1_ConfigMap_configmap-in-overlay.yaml /tmp/transformed/v1_ConfigMap_configmap-in-overlay.yaml
|
||||
--- /tmp/noop/v1_ConfigMap_configmap-in-overlay.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_ConfigMap_configmap-in-overlay.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -0,0 +1,10 @@
|
||||
+apiVersion: v1
|
||||
+data:
|
||||
+ hello: world
|
||||
+kind: ConfigMap
|
||||
+metadata:
|
||||
+ creationTimestamp: null
|
||||
+ labels:
|
||||
+ env: staging
|
||||
+ team: override-foo
|
||||
+ name: staging-configmap-in-overlay-k7cbc75tg8
|
||||
diff -u -N /tmp/noop/v1_Secret_secret-in-base.yaml /tmp/transformed/v1_Secret_secret-in-base.yaml
|
||||
--- /tmp/noop/v1_Secret_secret-in-base.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_Secret_secret-in-base.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -1,6 +1,7 @@
|
||||
apiVersion: v1
|
||||
data:
|
||||
password: c29tZXB3
|
||||
+ proxy: aGFwcm94eQ==
|
||||
username: YWRtaW4=
|
||||
kind: Secret
|
||||
metadata:
|
||||
@@ -9,7 +10,8 @@
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
app: mynginx
|
||||
+ env: staging
|
||||
org: example.com
|
||||
- team: foo
|
||||
- name: team-foo-secret-in-base-tkm7hhtf8d
|
||||
+ team: override-foo
|
||||
+ name: staging-team-foo-secret-in-base-c8db7gk2m2
|
||||
type: Opaque
|
||||
diff -u -N /tmp/noop/v1_Service_nginx.yaml /tmp/transformed/v1_Service_nginx.yaml
|
||||
--- /tmp/noop/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -5,13 +5,15 @@
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
+ env: staging
|
||||
org: example.com
|
||||
- team: foo
|
||||
- name: team-foo-nginx
|
||||
+ team: override-foo
|
||||
+ name: staging-team-foo-nginx
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
selector:
|
||||
app: mynginx
|
||||
+ env: staging
|
||||
org: example.com
|
||||
- team: foo
|
||||
+ team: override-foo
|
||||
@@ -1,105 +0,0 @@
|
||||
apiVersion: v1
|
||||
data:
|
||||
foo: override-bar
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
env: staging
|
||||
org: example.com
|
||||
team: override-foo
|
||||
name: staging-team-foo-configmap-in-base-gh9d7t85gb
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
hello: world
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
labels:
|
||||
env: staging
|
||||
team: override-foo
|
||||
name: staging-configmap-in-overlay-k7cbc75tg8
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
password: c29tZXB3
|
||||
proxy: aGFwcm94eQ==
|
||||
username: YWRtaW4=
|
||||
kind: Secret
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
env: staging
|
||||
org: example.com
|
||||
team: override-foo
|
||||
name: staging-team-foo-secret-in-base-c8db7gk2m2
|
||||
type: Opaque
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
env: staging
|
||||
org: example.com
|
||||
team: override-foo
|
||||
name: staging-team-foo-nginx
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
selector:
|
||||
app: mynginx
|
||||
env: staging
|
||||
org: example.com
|
||||
team: override-foo
|
||||
---
|
||||
apiVersion: apps/v1beta2
|
||||
kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
env: staging
|
||||
org: example.com
|
||||
team: override-foo
|
||||
name: staging-team-foo-nginx
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mynginx
|
||||
env: staging
|
||||
org: example.com
|
||||
team: override-foo
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
env: staging
|
||||
org: example.com
|
||||
team: override-foo
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx
|
||||
name: nginx
|
||||
volumeMounts:
|
||||
- mountPath: /tmp/ps
|
||||
name: nginx-persistent-storage
|
||||
volumes:
|
||||
- gcePersistentDisk:
|
||||
pdName: nginx-persistent-storage
|
||||
name: nginx-persistent-storage
|
||||
- configMap:
|
||||
name: staging-configmap-in-overlay-k7cbc75tg8
|
||||
name: configmap-in-overlay
|
||||
- configMap:
|
||||
name: staging-team-foo-configmap-in-base-gh9d7t85gb
|
||||
name: configmap-in-base
|
||||
@@ -1,15 +0,0 @@
|
||||
apiVersion: apps/v1beta2
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
volumes:
|
||||
- name: nginx-persistent-storage
|
||||
emptyDir: null
|
||||
gcePersistentDisk:
|
||||
pdName: nginx-persistent-storage
|
||||
- configMap:
|
||||
name: configmap-in-overlay
|
||||
name: configmap-in-overlay
|
||||
@@ -1,21 +0,0 @@
|
||||
namePrefix: staging-
|
||||
commonLabels:
|
||||
env: staging
|
||||
team: override-foo
|
||||
patchesStrategicMerge:
|
||||
- deployment.yaml
|
||||
bases:
|
||||
- ../package/
|
||||
configMapGenerator:
|
||||
- name: configmap-in-overlay
|
||||
literals:
|
||||
- hello=world
|
||||
- name: configmap-in-base
|
||||
behavior: replace
|
||||
literals:
|
||||
- foo=override-bar
|
||||
secretGenerator:
|
||||
- name: secret-in-base
|
||||
behavior: merge
|
||||
commands:
|
||||
proxy: "printf haproxy"
|
||||
@@ -1,24 +0,0 @@
|
||||
apiVersion: apps/v1beta2
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx
|
||||
volumeMounts:
|
||||
- name: nginx-persistent-storage
|
||||
mountPath: /tmp/ps
|
||||
volumes:
|
||||
- name: nginx-persistent-storage
|
||||
emptyDir: {}
|
||||
- configMap:
|
||||
name: configmap-in-base
|
||||
name: configmap-in-base
|
||||
@@ -1,19 +0,0 @@
|
||||
namePrefix: team-foo-
|
||||
commonLabels:
|
||||
app: mynginx
|
||||
org: example.com
|
||||
team: foo
|
||||
commonAnnotations:
|
||||
note: This is a test annotation
|
||||
resources:
|
||||
- deployment.yaml
|
||||
- service.yaml
|
||||
configMapGenerator:
|
||||
- name: configmap-in-base
|
||||
literals:
|
||||
- foo=bar
|
||||
secretGenerator:
|
||||
- name: secret-in-base
|
||||
commands:
|
||||
username: "printf admin"
|
||||
password: "printf somepw"
|
||||
@@ -1,11 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
selector:
|
||||
app: nginx
|
||||
@@ -1,5 +0,0 @@
|
||||
description: single overlay
|
||||
args: []
|
||||
filename: testdata/testcase-single-overlay/in/overlay/
|
||||
expectedStdout: testdata/testcase-single-overlay/expected.yaml
|
||||
expectedDiff: testdata/testcase-single-overlay/expected.diff
|
||||
@@ -1,53 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/component: nginx
|
||||
name: kustomized-nginx
|
||||
spec:
|
||||
ports:
|
||||
- name: http
|
||||
port: 80
|
||||
protocol: TCP
|
||||
targetPort: http
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/component: nginx
|
||||
name: kustomized-nginx
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/component: nginx
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/component: nginx
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:1.15.7-alpine
|
||||
name: nginx
|
||||
ports:
|
||||
- containerPort: 80
|
||||
name: http
|
||||
---
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/component: nginx
|
||||
name: kustomized-nginx
|
||||
spec:
|
||||
rules:
|
||||
- host: kustomized-nginx.example.com
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
serviceName: kustomized-nginx
|
||||
servicePort: 80
|
||||
path: /
|
||||
tls:
|
||||
- hosts:
|
||||
- kustomized-nginx.example.com
|
||||
@@ -1,21 +0,0 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
app.kubernetes.io/component: nginx
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/component: nginx
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/component: nginx
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.15.7-alpine
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
@@ -1,18 +0,0 @@
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
app.kubernetes.io/component: nginx
|
||||
spec:
|
||||
rules:
|
||||
- host: $(DEPLOYMENT_NAME).example.com
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
serviceName: nginx
|
||||
servicePort: 80
|
||||
path: /
|
||||
tls:
|
||||
- hosts:
|
||||
- $(DEPLOYMENT_NAME).example.com
|
||||
@@ -1,13 +0,0 @@
|
||||
resources:
|
||||
- deployment.yaml
|
||||
- ingress.yaml
|
||||
- service.yaml
|
||||
|
||||
vars:
|
||||
- name: DEPLOYMENT_NAME
|
||||
objref:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
name: nginx
|
||||
fieldref:
|
||||
fieldpath: metadata.name
|
||||
@@ -1,12 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
app.kubernetes.io/component: nginx
|
||||
spec:
|
||||
ports:
|
||||
- name: http
|
||||
port: 80
|
||||
protocol: TCP
|
||||
targetPort: http
|
||||
@@ -1,4 +0,0 @@
|
||||
nameprefix: kustomized-
|
||||
|
||||
bases:
|
||||
- ../base
|
||||
@@ -1,4 +0,0 @@
|
||||
description: variable reference and substitution for ingress resources
|
||||
args: []
|
||||
filename: testdata/testcase-variable-ref-ingress/in/overlay/
|
||||
expectedStdout: testdata/testcase-variable-ref-ingress/expected.yaml
|
||||
@@ -1,186 +0,0 @@
|
||||
diff -u -N /tmp/noop/apps_v1beta1_StatefulSet_cockroachdb.yaml /tmp/transformed/apps_v1beta1_StatefulSet_cockroachdb.yaml
|
||||
--- /tmp/noop/apps_v1beta1_StatefulSet_cockroachdb.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/apps_v1beta1_StatefulSet_cockroachdb.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -1,10 +1,10 @@
|
||||
apiVersion: apps/v1beta1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
- name: base-cockroachdb
|
||||
+ name: dev-base-cockroachdb
|
||||
spec:
|
||||
replicas: 3
|
||||
- serviceName: base-cockroachdb
|
||||
+ serviceName: dev-base-cockroachdb
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
@@ -27,7 +27,7 @@
|
||||
- /bin/bash
|
||||
- -ecx
|
||||
- exec /cockroach/cockroach start --logtostderr --certs-dir /cockroach/cockroach-certs
|
||||
- --host $(hostname -f) --http-host 0.0.0.0 --join base-cockroachdb-0.base-cockroachdb,base-cockroachdb-1.base-cockroachdb,base-cockroachdb-2.base-cockroachdb
|
||||
+ --host $(hostname -f) --http-host 0.0.0.0 --join dev-base-cockroachdb-0.dev-base-cockroachdb,dev-base-cockroachdb-1.dev-base-cockroachdb,dev-base-cockroachdb-2.dev-base-cockroachdb
|
||||
--cache 25% --max-sql-memory 25%
|
||||
image: cockroachdb/cockroach:v1.1.5
|
||||
imagePullPolicy: IfNotPresent
|
||||
@@ -48,7 +48,7 @@
|
||||
- -ecx
|
||||
- /request-cert -namespace=${POD_NAMESPACE} -certs-dir=/cockroach-certs -type=node
|
||||
-addresses=localhost,127.0.0.1,${POD_IP},$(hostname -f),$(hostname -f|cut
|
||||
- -f 1-2 -d '.'),base-cockroachdb-public -symlink-ca-from=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
|
||||
+ -f 1-2 -d '.'),dev-base-cockroachdb-public -symlink-ca-from=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
|
||||
env:
|
||||
- name: POD_IP
|
||||
valueFrom:
|
||||
@@ -64,7 +64,7 @@
|
||||
volumeMounts:
|
||||
- mountPath: /cockroach-certs
|
||||
name: certs
|
||||
- serviceAccountName: base-cockroachdb
|
||||
+ serviceAccountName: dev-base-cockroachdb
|
||||
terminationGracePeriodSeconds: 60
|
||||
volumes:
|
||||
- name: datadir
|
||||
diff -u -N /tmp/noop/batch_v1beta1_CronJob_cronjob-example.yaml /tmp/transformed/batch_v1beta1_CronJob_cronjob-example.yaml
|
||||
--- /tmp/noop/batch_v1beta1_CronJob_cronjob-example.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/batch_v1beta1_CronJob_cronjob-example.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -1,7 +1,7 @@
|
||||
apiVersion: batch/v1beta1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
- name: base-cronjob-example
|
||||
+ name: dev-base-cronjob-example
|
||||
spec:
|
||||
concurrencyPolicy: Forbid
|
||||
jobTemplate:
|
||||
@@ -11,11 +11,11 @@
|
||||
containers:
|
||||
- command:
|
||||
- echo
|
||||
- - base-cockroachdb
|
||||
- - base-test-config-map-259876d7fg
|
||||
+ - dev-base-cockroachdb
|
||||
+ - dev-base-test-config-map-b2g2dmd64b
|
||||
env:
|
||||
- name: CDB_PUBLIC_SVC
|
||||
- value: base-cockroachdb-public
|
||||
+ value: dev-base-cockroachdb-public
|
||||
image: cockroachdb/cockroach:v1.1.5
|
||||
name: cronjob-example
|
||||
schedule: '*/1 * * * *'
|
||||
diff -u -N /tmp/noop/policy_v1beta1_PodDisruptionBudget_cockroachdb-budget.yaml /tmp/transformed/policy_v1beta1_PodDisruptionBudget_cockroachdb-budget.yaml
|
||||
--- /tmp/noop/policy_v1beta1_PodDisruptionBudget_cockroachdb-budget.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/policy_v1beta1_PodDisruptionBudget_cockroachdb-budget.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -3,7 +3,7 @@
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
- name: base-cockroachdb-budget
|
||||
+ name: dev-base-cockroachdb-budget
|
||||
spec:
|
||||
maxUnavailable: 1
|
||||
selector:
|
||||
diff -u -N /tmp/noop/rbac.authorization.k8s.io_v1beta1_ClusterRoleBinding_cockroachdb.yaml /tmp/transformed/rbac.authorization.k8s.io_v1beta1_ClusterRoleBinding_cockroachdb.yaml
|
||||
--- /tmp/noop/rbac.authorization.k8s.io_v1beta1_ClusterRoleBinding_cockroachdb.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/rbac.authorization.k8s.io_v1beta1_ClusterRoleBinding_cockroachdb.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -3,12 +3,12 @@
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
- name: base-cockroachdb
|
||||
+ name: dev-base-cockroachdb
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
- name: base-cockroachdb
|
||||
+ name: dev-base-cockroachdb
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
- name: base-cockroachdb
|
||||
+ name: dev-base-cockroachdb
|
||||
namespace: default
|
||||
diff -u -N /tmp/noop/rbac.authorization.k8s.io_v1beta1_ClusterRole_cockroachdb.yaml /tmp/transformed/rbac.authorization.k8s.io_v1beta1_ClusterRole_cockroachdb.yaml
|
||||
--- /tmp/noop/rbac.authorization.k8s.io_v1beta1_ClusterRole_cockroachdb.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/rbac.authorization.k8s.io_v1beta1_ClusterRole_cockroachdb.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -3,7 +3,7 @@
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
- name: base-cockroachdb
|
||||
+ name: dev-base-cockroachdb
|
||||
rules:
|
||||
- apiGroups:
|
||||
- certificates.k8s.io
|
||||
diff -u -N /tmp/noop/rbac.authorization.k8s.io_v1beta1_RoleBinding_cockroachdb.yaml /tmp/transformed/rbac.authorization.k8s.io_v1beta1_RoleBinding_cockroachdb.yaml
|
||||
--- /tmp/noop/rbac.authorization.k8s.io_v1beta1_RoleBinding_cockroachdb.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/rbac.authorization.k8s.io_v1beta1_RoleBinding_cockroachdb.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -3,12 +3,12 @@
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
- name: base-cockroachdb
|
||||
+ name: dev-base-cockroachdb
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: Role
|
||||
- name: base-cockroachdb
|
||||
+ name: dev-base-cockroachdb
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
- name: base-cockroachdb
|
||||
+ name: dev-base-cockroachdb
|
||||
namespace: default
|
||||
diff -u -N /tmp/noop/rbac.authorization.k8s.io_v1beta1_Role_cockroachdb.yaml /tmp/transformed/rbac.authorization.k8s.io_v1beta1_Role_cockroachdb.yaml
|
||||
--- /tmp/noop/rbac.authorization.k8s.io_v1beta1_Role_cockroachdb.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/rbac.authorization.k8s.io_v1beta1_Role_cockroachdb.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -3,7 +3,7 @@
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
- name: base-cockroachdb
|
||||
+ name: dev-base-cockroachdb
|
||||
rules:
|
||||
- apiGroups:
|
||||
- ""
|
||||
diff -u -N /tmp/noop/v1_ConfigMap_test-config-map.yaml /tmp/transformed/v1_ConfigMap_test-config-map.yaml
|
||||
--- /tmp/noop/v1_ConfigMap_test-config-map.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_ConfigMap_test-config-map.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -5,4 +5,4 @@
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
- name: base-test-config-map-259876d7fg
|
||||
+ name: dev-base-test-config-map-b2g2dmd64b
|
||||
diff -u -N /tmp/noop/v1_ServiceAccount_cockroachdb.yaml /tmp/transformed/v1_ServiceAccount_cockroachdb.yaml
|
||||
--- /tmp/noop/v1_ServiceAccount_cockroachdb.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_ServiceAccount_cockroachdb.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -3,4 +3,4 @@
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
- name: base-cockroachdb
|
||||
+ name: dev-base-cockroachdb
|
||||
diff -u -N /tmp/noop/v1_Service_cockroachdb-public.yaml /tmp/transformed/v1_Service_cockroachdb-public.yaml
|
||||
--- /tmp/noop/v1_Service_cockroachdb-public.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_Service_cockroachdb-public.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -3,7 +3,7 @@
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
- name: base-cockroachdb-public
|
||||
+ name: dev-base-cockroachdb-public
|
||||
spec:
|
||||
ports:
|
||||
- name: grpc
|
||||
diff -u -N /tmp/noop/v1_Service_cockroachdb.yaml /tmp/transformed/v1_Service_cockroachdb.yaml
|
||||
--- /tmp/noop/v1_Service_cockroachdb.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_Service_cockroachdb.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -8,7 +8,7 @@
|
||||
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
|
||||
labels:
|
||||
app: cockroachdb
|
||||
- name: base-cockroachdb
|
||||
+ name: dev-base-cockroachdb
|
||||
spec:
|
||||
clusterIP: None
|
||||
ports:
|
||||
@@ -1,235 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
name: dev-base-cockroachdb
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: Role
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
name: dev-base-cockroachdb
|
||||
rules:
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- secrets
|
||||
verbs:
|
||||
- create
|
||||
- get
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
name: dev-base-cockroachdb
|
||||
rules:
|
||||
- apiGroups:
|
||||
- certificates.k8s.io
|
||||
resources:
|
||||
- certificatesigningrequests
|
||||
verbs:
|
||||
- create
|
||||
- get
|
||||
- watch
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
name: dev-base-cockroachdb
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: Role
|
||||
name: dev-base-cockroachdb
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: dev-base-cockroachdb
|
||||
namespace: default
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
name: dev-base-cockroachdb
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: dev-base-cockroachdb
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: dev-base-cockroachdb
|
||||
namespace: default
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
baz: qux
|
||||
foo: bar
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: dev-base-test-config-map-b2g2dmd64b
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
name: dev-base-cockroachdb-public
|
||||
spec:
|
||||
ports:
|
||||
- name: grpc
|
||||
port: 26257
|
||||
targetPort: 26257
|
||||
- name: http
|
||||
port: 8080
|
||||
targetPort: 8080
|
||||
selector:
|
||||
app: cockroachdb
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations:
|
||||
prometheus.io/path: _status/vars
|
||||
prometheus.io/port: "8080"
|
||||
prometheus.io/scrape: "true"
|
||||
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
|
||||
labels:
|
||||
app: cockroachdb
|
||||
name: dev-base-cockroachdb
|
||||
spec:
|
||||
clusterIP: None
|
||||
ports:
|
||||
- name: grpc
|
||||
port: 26257
|
||||
targetPort: 26257
|
||||
- name: http
|
||||
port: 8080
|
||||
targetPort: 8080
|
||||
selector:
|
||||
app: cockroachdb
|
||||
---
|
||||
apiVersion: apps/v1beta1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: dev-base-cockroachdb
|
||||
spec:
|
||||
replicas: 3
|
||||
serviceName: dev-base-cockroachdb
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
spec:
|
||||
affinity:
|
||||
podAntiAffinity:
|
||||
preferredDuringSchedulingIgnoredDuringExecution:
|
||||
- podAffinityTerm:
|
||||
labelSelector:
|
||||
matchExpressions:
|
||||
- key: app
|
||||
operator: In
|
||||
values:
|
||||
- cockroachdb
|
||||
topologyKey: kubernetes.io/hostname
|
||||
weight: 100
|
||||
containers:
|
||||
- command:
|
||||
- /bin/bash
|
||||
- -ecx
|
||||
- exec /cockroach/cockroach start --logtostderr --certs-dir /cockroach/cockroach-certs
|
||||
--host $(hostname -f) --http-host 0.0.0.0 --join dev-base-cockroachdb-0.dev-base-cockroachdb,dev-base-cockroachdb-1.dev-base-cockroachdb,dev-base-cockroachdb-2.dev-base-cockroachdb
|
||||
--cache 25% --max-sql-memory 25%
|
||||
image: cockroachdb/cockroach:v1.1.5
|
||||
imagePullPolicy: IfNotPresent
|
||||
name: cockroachdb
|
||||
ports:
|
||||
- containerPort: 26257
|
||||
name: grpc
|
||||
- containerPort: 8080
|
||||
name: http
|
||||
volumeMounts:
|
||||
- mountPath: /cockroach/cockroach-data
|
||||
name: datadir
|
||||
- mountPath: /cockroach/cockroach-certs
|
||||
name: certs
|
||||
initContainers:
|
||||
- command:
|
||||
- /bin/ash
|
||||
- -ecx
|
||||
- /request-cert -namespace=${POD_NAMESPACE} -certs-dir=/cockroach-certs -type=node
|
||||
-addresses=localhost,127.0.0.1,${POD_IP},$(hostname -f),$(hostname -f|cut
|
||||
-f 1-2 -d '.'),dev-base-cockroachdb-public -symlink-ca-from=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
|
||||
env:
|
||||
- name: POD_IP
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: status.podIP
|
||||
- name: POD_NAMESPACE
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.namespace
|
||||
image: cockroachdb/cockroach-k8s-request-cert:0.2
|
||||
imagePullPolicy: IfNotPresent
|
||||
name: init-certs
|
||||
volumeMounts:
|
||||
- mountPath: /cockroach-certs
|
||||
name: certs
|
||||
serviceAccountName: dev-base-cockroachdb
|
||||
terminationGracePeriodSeconds: 60
|
||||
volumes:
|
||||
- name: datadir
|
||||
persistentVolumeClaim:
|
||||
claimName: datadir
|
||||
- emptyDir: {}
|
||||
name: certs
|
||||
updateStrategy:
|
||||
type: RollingUpdate
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: datadir
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
---
|
||||
apiVersion: batch/v1beta1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: dev-base-cronjob-example
|
||||
spec:
|
||||
concurrencyPolicy: Forbid
|
||||
jobTemplate:
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- command:
|
||||
- echo
|
||||
- dev-base-cockroachdb
|
||||
- dev-base-test-config-map-b2g2dmd64b
|
||||
env:
|
||||
- name: CDB_PUBLIC_SVC
|
||||
value: dev-base-cockroachdb-public
|
||||
image: cockroachdb/cockroach:v1.1.5
|
||||
name: cronjob-example
|
||||
schedule: '*/1 * * * *'
|
||||
---
|
||||
apiVersion: policy/v1beta1
|
||||
kind: PodDisruptionBudget
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
name: dev-base-cockroachdb-budget
|
||||
spec:
|
||||
maxUnavailable: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: cockroachdb
|
||||
@@ -1,4 +0,0 @@
|
||||
namePrefix: dev-
|
||||
bases:
|
||||
- ../package
|
||||
|
||||
@@ -1,235 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: cockroachdb
|
||||
labels:
|
||||
app: cockroachdb
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: Role
|
||||
metadata:
|
||||
name: cockroachdb
|
||||
labels:
|
||||
app: cockroachdb
|
||||
rules:
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- secrets
|
||||
verbs:
|
||||
- create
|
||||
- get
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: cockroachdb
|
||||
labels:
|
||||
app: cockroachdb
|
||||
rules:
|
||||
- apiGroups:
|
||||
- certificates.k8s.io
|
||||
resources:
|
||||
- certificatesigningrequests
|
||||
verbs:
|
||||
- create
|
||||
- get
|
||||
- watch
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: cockroachdb
|
||||
labels:
|
||||
app: cockroachdb
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: Role
|
||||
name: cockroachdb
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: cockroachdb
|
||||
namespace: default
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: cockroachdb
|
||||
labels:
|
||||
app: cockroachdb
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: cockroachdb
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: cockroachdb
|
||||
namespace: default
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
# This service is meant to be used by clients of the database. It exposes a ClusterIP that will
|
||||
# automatically load balance connections to the different database pods.
|
||||
name: cockroachdb-public
|
||||
labels:
|
||||
app: cockroachdb
|
||||
spec:
|
||||
ports:
|
||||
# The main port, served by gRPC, serves Postgres-flavor SQL, internode
|
||||
# traffic and the cli.
|
||||
- port: 26257
|
||||
targetPort: 26257
|
||||
name: grpc
|
||||
# The secondary port serves the UI as well as health and debug endpoints.
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
name: http
|
||||
selector:
|
||||
app: cockroachdb
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
# This service only exists to create DNS entries for each pod in the stateful
|
||||
# set such that they can resolve each other's IP addresses. It does not
|
||||
# create a load-balanced ClusterIP and should not be used directly by clients
|
||||
# in most circumstances.
|
||||
name: cockroachdb
|
||||
labels:
|
||||
app: cockroachdb
|
||||
annotations:
|
||||
# This is needed to make the peer-finder work properly and to help avoid
|
||||
# edge cases where instance 0 comes up after losing its data and needs to
|
||||
# decide whether it should create a new cluster or try to join an existing
|
||||
# one. If it creates a new cluster when it should have joined an existing
|
||||
# one, we'd end up with two separate clusters listening at the same service
|
||||
# endpoint, which would be very bad.
|
||||
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
|
||||
# Enable automatic monitoring of all instances when Prometheus is running in the cluster.
|
||||
prometheus.io/scrape: "true"
|
||||
prometheus.io/path: "_status/vars"
|
||||
prometheus.io/port: "8080"
|
||||
spec:
|
||||
ports:
|
||||
- port: 26257
|
||||
targetPort: 26257
|
||||
name: grpc
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
name: http
|
||||
clusterIP: None
|
||||
selector:
|
||||
app: cockroachdb
|
||||
---
|
||||
apiVersion: policy/v1beta1
|
||||
kind: PodDisruptionBudget
|
||||
metadata:
|
||||
name: cockroachdb-budget
|
||||
labels:
|
||||
app: cockroachdb
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: cockroachdb
|
||||
maxUnavailable: 1
|
||||
---
|
||||
apiVersion: apps/v1beta1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: cockroachdb
|
||||
spec:
|
||||
serviceName: "cockroachdb"
|
||||
replicas: 3
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: cockroachdb
|
||||
spec:
|
||||
serviceAccountName: cockroachdb
|
||||
# Init containers are run only once in the lifetime of a pod, before
|
||||
# it's started up for the first time. It has to exit successfully
|
||||
# before the pod's main containers are allowed to start.
|
||||
initContainers:
|
||||
# The init-certs container sends a certificate signing request to the
|
||||
# kubernetes cluster.
|
||||
# You can see pending requests using: kubectl get csr
|
||||
# CSRs can be approved using: kubectl certificate approve <csr name>
|
||||
#
|
||||
# All addresses used to contact a node must be specified in the --addresses arg.
|
||||
#
|
||||
# In addition to the node certificate and key, the init-certs entrypoint will symlink
|
||||
# the cluster CA to the certs directory.
|
||||
- name: init-certs
|
||||
image: cockroachdb/cockroach-k8s-request-cert:0.2
|
||||
imagePullPolicy: IfNotPresent
|
||||
command:
|
||||
- "/bin/ash"
|
||||
- "-ecx"
|
||||
- "/request-cert -namespace=${POD_NAMESPACE} -certs-dir=/cockroach-certs -type=node -addresses=localhost,127.0.0.1,${POD_IP},$(hostname -f),$(hostname -f|cut -f 1-2 -d '.'),$(CDB_PUBLIC_SVC) -symlink-ca-from=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
|
||||
env:
|
||||
- name: POD_IP
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: status.podIP
|
||||
- name: POD_NAMESPACE
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.namespace
|
||||
volumeMounts:
|
||||
- name: certs
|
||||
mountPath: /cockroach-certs
|
||||
|
||||
affinity:
|
||||
podAntiAffinity:
|
||||
preferredDuringSchedulingIgnoredDuringExecution:
|
||||
- weight: 100
|
||||
podAffinityTerm:
|
||||
labelSelector:
|
||||
matchExpressions:
|
||||
- key: app
|
||||
operator: In
|
||||
values:
|
||||
- cockroachdb
|
||||
topologyKey: kubernetes.io/hostname
|
||||
containers:
|
||||
- name: cockroachdb
|
||||
image: cockroachdb/cockroach:v1.1.5
|
||||
imagePullPolicy: IfNotPresent
|
||||
ports:
|
||||
- containerPort: 26257
|
||||
name: grpc
|
||||
- containerPort: 8080
|
||||
name: http
|
||||
volumeMounts:
|
||||
- name: datadir
|
||||
mountPath: /cockroach/cockroach-data
|
||||
- name: certs
|
||||
mountPath: /cockroach/cockroach-certs
|
||||
command:
|
||||
- "/bin/bash"
|
||||
- "-ecx"
|
||||
# The use of qualified `hostname -f` is crucial:
|
||||
# Other nodes aren't able to look up the unqualified hostname.
|
||||
# Once 2.0 is out, we should be able to switch from --host to --advertise-host to make port-forwarding work to the main port.
|
||||
- "exec /cockroach/cockroach start --logtostderr --certs-dir /cockroach/cockroach-certs --host $(hostname -f) --http-host 0.0.0.0 --join $(CDB_STATEFULSET_NAME)-0.$(CDB_STATEFULSET_SVC),$(CDB_STATEFULSET_NAME)-1.$(CDB_STATEFULSET_SVC),$(CDB_STATEFULSET_NAME)-2.$(CDB_STATEFULSET_SVC) --cache 25% --max-sql-memory 25%"
|
||||
# No pre-stop hook is required, a SIGTERM plus some time is all that's
|
||||
# needed for graceful shutdown of a node.
|
||||
terminationGracePeriodSeconds: 60
|
||||
volumes:
|
||||
- name: datadir
|
||||
persistentVolumeClaim:
|
||||
claimName: datadir
|
||||
- name: certs
|
||||
emptyDir: {}
|
||||
updateStrategy:
|
||||
type: RollingUpdate
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: datadir
|
||||
spec:
|
||||
accessModes:
|
||||
- "ReadWriteOnce"
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
@@ -1,21 +0,0 @@
|
||||
apiVersion: batch/v1beta1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: cronjob-example
|
||||
spec:
|
||||
schedule: "*/1 * * * *"
|
||||
concurrencyPolicy: Forbid
|
||||
jobTemplate:
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: cronjob-example
|
||||
image: cockroachdb/cockroach:v1.1.5
|
||||
command:
|
||||
- echo
|
||||
- "$(CDB_STATEFULSET_NAME)"
|
||||
- "$(TEST_CONFIG_MAP)"
|
||||
env:
|
||||
- name: CDB_PUBLIC_SVC
|
||||
value: "$(CDB_PUBLIC_SVC)"
|
||||
@@ -1,39 +0,0 @@
|
||||
namePrefix: base-
|
||||
resources:
|
||||
- cockroachdb-statefulset-secure.yaml
|
||||
- cronjob.yaml
|
||||
configMapGenerator:
|
||||
- name: test-config-map
|
||||
literals:
|
||||
- foo=bar
|
||||
- baz=qux
|
||||
vars:
|
||||
- name: CDB_PUBLIC_SVC
|
||||
objref:
|
||||
kind: Service
|
||||
name: cockroachdb-public
|
||||
apiVersion: v1
|
||||
fieldref:
|
||||
fieldpath: metadata.name
|
||||
- name: CDB_STATEFULSET_NAME
|
||||
objref:
|
||||
kind: StatefulSet
|
||||
name: cockroachdb
|
||||
apiVersion: apps/v1beta1
|
||||
fieldref:
|
||||
fieldpath: metadata.name
|
||||
- name: CDB_STATEFULSET_SVC
|
||||
objref:
|
||||
kind: Service
|
||||
name: cockroachdb
|
||||
apiVersion: v1
|
||||
fieldref:
|
||||
fieldpath: metadata.name
|
||||
|
||||
- name: TEST_CONFIG_MAP
|
||||
objref:
|
||||
kind: ConfigMap
|
||||
name: test-config-map
|
||||
apiVersion: v1
|
||||
fieldref:
|
||||
fieldpath: metadata.name
|
||||
@@ -1,5 +0,0 @@
|
||||
description: variable reference and substitution
|
||||
args: []
|
||||
filename: testdata/testcase-variable-ref/in/overlay/
|
||||
expectedStdout: testdata/testcase-variable-ref/expected.yaml
|
||||
expectedDiff: testdata/testcase-variable-ref/expected.diff
|
||||
@@ -1,18 +1,5 @@
|
||||
/*
|
||||
Copyright 2017 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.
|
||||
*/
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package commands holds the CLI glue mapping textual commands/args to method calls.
|
||||
package commands
|
||||
@@ -22,33 +9,41 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/transformer"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/validator"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/build"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/edit"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/misc"
|
||||
"sigs.k8s.io/kustomize/pkg/factory"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/resource"
|
||||
)
|
||||
|
||||
// NewDefaultCommand returns the default (aka root) command for kustomize command.
|
||||
func NewDefaultCommand(f *factory.KustFactory) *cobra.Command {
|
||||
fsys := fs.MakeRealFS()
|
||||
func NewDefaultCommand() *cobra.Command {
|
||||
fSys := fs.MakeRealFS()
|
||||
stdOut := os.Stdout
|
||||
|
||||
c := &cobra.Command{
|
||||
Use: "kustomize",
|
||||
Short: "kustomize manages declarative configuration of Kubernetes",
|
||||
Use: pgmconfig.ProgramName,
|
||||
Short: "Manages declarative configuration of Kubernetes",
|
||||
Long: `
|
||||
kustomize manages declarative configuration of Kubernetes.
|
||||
|
||||
Manages declarative configuration of Kubernetes.
|
||||
See https://sigs.k8s.io/kustomize
|
||||
`,
|
||||
}
|
||||
|
||||
uf := kunstruct.NewKunstructuredFactoryImpl()
|
||||
rf := resmap.NewFactory(resource.NewFactory(uf))
|
||||
v := validator.NewKustValidator()
|
||||
c.AddCommand(
|
||||
// TODO: Make consistent API for newCmd* functions.
|
||||
build.NewCmdBuild(stdOut, fsys, f.ResmapF, f.TransformerF),
|
||||
edit.NewCmdEdit(fsys, f.ValidatorF, f.UnstructF),
|
||||
misc.NewCmdConfig(fsys),
|
||||
build.NewCmdBuild(
|
||||
stdOut, fSys, v,
|
||||
rf, transformer.NewFactoryImpl()),
|
||||
edit.NewCmdEdit(fSys, v, uf),
|
||||
misc.NewCmdConfig(fSys),
|
||||
misc.NewCmdVersion(stdOut),
|
||||
)
|
||||
c.PersistentFlags().AddGoFlagSet(flag.CommandLine)
|
||||
|
||||
@@ -22,8 +22,8 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/constants"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
)
|
||||
|
||||
@@ -47,6 +47,7 @@ func (k kindOfAdd) String() string {
|
||||
}
|
||||
|
||||
type addMetadataOptions struct {
|
||||
force bool
|
||||
metadata map[string]string
|
||||
mapValidator func(map[string]string) error
|
||||
kind kindOfAdd
|
||||
@@ -59,13 +60,16 @@ func newCmdAddAnnotation(fSys fs.FileSystem, v func(map[string]string) error) *c
|
||||
o.mapValidator = v
|
||||
cmd := &cobra.Command{
|
||||
Use: "annotation",
|
||||
Short: "Adds one or more commonAnnotations to " + constants.KustomizationFileName,
|
||||
Short: "Adds one or more commonAnnotations to " + pgmconfig.KustomizationFileNames[0],
|
||||
Example: `
|
||||
add annotation {annotationKey1:annotationValue1},{annotationKey2:annotationValue2}`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return o.runE(args, fSys, o.addAnnotations)
|
||||
},
|
||||
}
|
||||
cmd.Flags().BoolVarP(&o.force, "force", "f", false,
|
||||
"overwrite commonAnnotation if it already exists",
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -76,13 +80,16 @@ func newCmdAddLabel(fSys fs.FileSystem, v func(map[string]string) error) *cobra.
|
||||
o.mapValidator = v
|
||||
cmd := &cobra.Command{
|
||||
Use: "label",
|
||||
Short: "Adds one or more commonLabels to " + constants.KustomizationFileName,
|
||||
Short: "Adds one or more commonLabels to " + pgmconfig.KustomizationFileNames[0],
|
||||
Example: `
|
||||
add label {labelKey1:labelValue1},{labelKey2:labelValue2}`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return o.runE(args, fSys, o.addLabels)
|
||||
},
|
||||
}
|
||||
cmd.Flags().BoolVarP(&o.force, "force", "f", false,
|
||||
"overwrite commonLabel if it already exists",
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -130,17 +137,18 @@ func (o *addMetadataOptions) convertToMap(arg string) (map[string]string, error)
|
||||
result := make(map[string]string)
|
||||
inputs := strings.Split(arg, ",")
|
||||
for _, input := range inputs {
|
||||
kv := strings.Split(input, ":")
|
||||
if len(kv[0]) < 1 {
|
||||
return nil, o.makeError(input, "empty key")
|
||||
}
|
||||
if len(kv) > 2 {
|
||||
return nil, o.makeError(input, "too many colons")
|
||||
}
|
||||
if len(kv) > 1 {
|
||||
result[kv[0]] = kv[1]
|
||||
c := strings.Index(input, ":")
|
||||
if c == 0 {
|
||||
// key is not passed
|
||||
return nil, o.makeError(input, "need k:v pair where v may be quoted")
|
||||
} else if c < 0 {
|
||||
// only key passed
|
||||
result[input] = ""
|
||||
} else {
|
||||
result[kv[0]] = ""
|
||||
// both key and value passed
|
||||
key := input[:c]
|
||||
value := trimQuotes(input[c+1:])
|
||||
result[key] = value
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
@@ -162,7 +170,7 @@ func (o *addMetadataOptions) addLabels(m *types.Kustomization) error {
|
||||
|
||||
func (o *addMetadataOptions) writeToMap(m map[string]string, kind kindOfAdd) error {
|
||||
for k, v := range o.metadata {
|
||||
if _, ok := m[k]; ok {
|
||||
if _, ok := m[k]; ok && !o.force {
|
||||
return fmt.Errorf("%s %s already in kustomization file", kind, k)
|
||||
}
|
||||
m[k] = v
|
||||
@@ -171,5 +179,14 @@ func (o *addMetadataOptions) writeToMap(m map[string]string, kind kindOfAdd) err
|
||||
}
|
||||
|
||||
func (o *addMetadataOptions) makeError(input string, message string) error {
|
||||
return fmt.Errorf("invalid %s: %s (%s)", o.kind, input, message)
|
||||
return fmt.Errorf("invalid %s: '%s' (%s)", o.kind, input, message)
|
||||
}
|
||||
|
||||
func trimQuotes(s string) string {
|
||||
if len(s) >= 2 {
|
||||
if s[0] == '"' && s[len(s)-1] == '"' {
|
||||
return s[1 : len(s)-1]
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package add
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
@@ -103,6 +104,32 @@ func TestAddAnnotationManyArgs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddAnnotationValueQuoted(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.WriteTestKustomization()
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdAddAnnotation(fakeFS, v.Validator)
|
||||
args := []string{"k1:\"v1\""}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddAnnotationValueWithColon(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.WriteTestKustomization()
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdAddAnnotation(fakeFS, v.Validator)
|
||||
args := []string{"k1:\"v1:v2\""}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddAnnotationNoKey(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
@@ -113,23 +140,21 @@ func TestAddAnnotationNoKey(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "invalid annotation: :nokey (empty key)" {
|
||||
if err.Error() != "invalid annotation: ':nokey' (need k:v pair where v may be quoted)" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddAnnotationTooManyColons(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.WriteTestKustomization()
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdAddAnnotation(fakeFS, v.Validator)
|
||||
args := []string{"key:v1:v2"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyNoCall()
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "invalid annotation: key:v1:v2 (too many colons)" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
v.VerifyCall()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +187,40 @@ func TestAddAnnotationMultipleArgs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddAnnotationForce(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.WriteTestKustomization()
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdAddAnnotation(fakeFS, v.Validator)
|
||||
args := []string{"key:foo"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err.Error())
|
||||
}
|
||||
// trying to add the same annotation again should not work
|
||||
args = []string{"key:bar"}
|
||||
v = validators.MakeHappyMapValidator(t)
|
||||
cmd = newCmdAddAnnotation(fakeFS, v.Validator)
|
||||
err = cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "annotation key already in kustomization file" {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
// but trying to add it with --force should
|
||||
v = validators.MakeHappyMapValidator(t)
|
||||
cmd = newCmdAddAnnotation(fakeFS, v.Validator)
|
||||
cmd.Flag("force").Value.Set("true")
|
||||
err = cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunAddLabel(t *testing.T) {
|
||||
var o addMetadataOptions
|
||||
o.metadata = map[string]string{"owls": "cute", "otters": "adorable"}
|
||||
@@ -223,23 +282,21 @@ func TestAddLabelNoKey(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "invalid label: :nokey (empty key)" {
|
||||
if err.Error() != "invalid label: ':nokey' (need k:v pair where v may be quoted)" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddLabelTooManyColons(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.WriteTestKustomization()
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdAddLabel(fakeFS, v.Validator)
|
||||
args := []string{"key:v1:v2"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyNoCall()
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "invalid label: key:v1:v2 (too many colons)" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
v.VerifyCall()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,3 +328,70 @@ func TestAddLabelMultipleArgs(t *testing.T) {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddLabelForce(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.WriteTestKustomization()
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdAddLabel(fakeFS, v.Validator)
|
||||
args := []string{"key:foo"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err.Error())
|
||||
}
|
||||
// trying to add the same label again should not work
|
||||
args = []string{"key:bar"}
|
||||
v = validators.MakeHappyMapValidator(t)
|
||||
cmd = newCmdAddLabel(fakeFS, v.Validator)
|
||||
err = cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "label key already in kustomization file" {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
// but trying to add it with --force should
|
||||
v = validators.MakeHappyMapValidator(t)
|
||||
cmd = newCmdAddLabel(fakeFS, v.Validator)
|
||||
cmd.Flag("force").Value.Set("true")
|
||||
err = cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertToMap(t *testing.T) {
|
||||
var o addMetadataOptions
|
||||
args := "a:b,c:\"d\",e:\"f:g\",g:h:k"
|
||||
expected := make(map[string]string)
|
||||
expected["a"] = "b"
|
||||
expected["c"] = "d"
|
||||
expected["e"] = "f:g"
|
||||
expected["g"] = "h:k"
|
||||
|
||||
result, err := o.convertToMap(args)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err.Error())
|
||||
}
|
||||
|
||||
eq := reflect.DeepEqual(expected, result)
|
||||
if !eq {
|
||||
t.Errorf("Converted map does not match expected, expected: %v, result: %v\n", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertToMapError(t *testing.T) {
|
||||
var o addMetadataOptions
|
||||
args := "a:b,c:\"d\",:f:g"
|
||||
|
||||
_, err := o.convertToMap(args)
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "invalid annotation: ':f:g' (need k:v pair where v may be quoted)" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
/*
|
||||
Copyright 2017 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.
|
||||
*/
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package add
|
||||
|
||||
@@ -23,12 +10,18 @@ import (
|
||||
)
|
||||
|
||||
// NewCmdAdd returns an instance of 'add' subcommand.
|
||||
func NewCmdAdd(fsys fs.FileSystem, v ifc.Validator, kf ifc.KunstructuredFactory) *cobra.Command {
|
||||
func NewCmdAdd(
|
||||
fSys fs.FileSystem,
|
||||
ldr ifc.Loader,
|
||||
kf ifc.KunstructuredFactory) *cobra.Command {
|
||||
c := &cobra.Command{
|
||||
Use: "add",
|
||||
Short: "Adds configmap/resource/patch/base to the kustomization file.",
|
||||
Short: "Adds an item to the kustomization file.",
|
||||
Long: "",
|
||||
Example: `
|
||||
# Adds a secret to the kustomization file
|
||||
kustomize edit add secret NAME --from-literal=k=v
|
||||
|
||||
# Adds a configmap to the kustomization file
|
||||
kustomize edit add configmap NAME --from-literal=k=v
|
||||
|
||||
@@ -51,12 +44,13 @@ func NewCmdAdd(fsys fs.FileSystem, v ifc.Validator, kf ifc.KunstructuredFactory)
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
}
|
||||
c.AddCommand(
|
||||
newCmdAddResource(fsys),
|
||||
newCmdAddPatch(fsys),
|
||||
newCmdAddConfigMap(fsys, kf),
|
||||
newCmdAddBase(fsys),
|
||||
newCmdAddLabel(fsys, v.MakeLabelValidator()),
|
||||
newCmdAddAnnotation(fsys, v.MakeAnnotationValidator()),
|
||||
newCmdAddResource(fSys),
|
||||
newCmdAddPatch(fSys),
|
||||
newCmdAddSecret(fSys, ldr, kf),
|
||||
newCmdAddConfigMap(fSys, ldr, kf),
|
||||
newCmdAddBase(fSys),
|
||||
newCmdAddLabel(fSys, ldr.Validator().MakeLabelValidator()),
|
||||
newCmdAddAnnotation(fSys, ldr.Validator().MakeAnnotationValidator()),
|
||||
)
|
||||
return c
|
||||
}
|
||||
|
||||
@@ -1,61 +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 add
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
)
|
||||
|
||||
// cMapFlagsAndArgs encapsulates the options for add configmap commands.
|
||||
type cMapFlagsAndArgs struct {
|
||||
// Name of configMap/Secret (required)
|
||||
Name string
|
||||
// FileSources to derive the configMap/Secret from (optional)
|
||||
FileSources []string
|
||||
// LiteralSources to derive the configMap/Secret from (optional)
|
||||
LiteralSources []string
|
||||
// EnvFileSource to derive the configMap/Secret from (optional)
|
||||
// TODO: Rationalize this name with Generic.EnvSource
|
||||
EnvFileSource string
|
||||
}
|
||||
|
||||
// Validate validates required fields are set to support structured generation.
|
||||
func (a *cMapFlagsAndArgs) Validate(args []string) error {
|
||||
if len(args) != 1 {
|
||||
return fmt.Errorf("name must be specified once")
|
||||
}
|
||||
a.Name = args[0]
|
||||
if len(a.EnvFileSource) == 0 && len(a.FileSources) == 0 && len(a.LiteralSources) == 0 {
|
||||
return fmt.Errorf("at least from-env-file, or from-file or from-literal must be set")
|
||||
}
|
||||
if len(a.EnvFileSource) > 0 && (len(a.FileSources) > 0 || len(a.LiteralSources) > 0) {
|
||||
return fmt.Errorf("from-env-file cannot be combined with from-file or from-literal")
|
||||
}
|
||||
// TODO: Should we check if the path exists? if it's valid, if it's within the same (sub-)directory?
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *cMapFlagsAndArgs) ExpandFileSource(fSys fs.FileSystem) error {
|
||||
result, err := globPatterns(fSys, a.FileSources)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
a.FileSources = result
|
||||
return nil
|
||||
}
|
||||
@@ -1,104 +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 add
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
)
|
||||
|
||||
func TestDataConfigValidation_NoName(t *testing.T) {
|
||||
config := cMapFlagsAndArgs{}
|
||||
|
||||
if config.Validate([]string{}) == nil {
|
||||
t.Fatal("Validation should fail if no name is specified")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDataConfigValidation_MoreThanOneName(t *testing.T) {
|
||||
config := cMapFlagsAndArgs{}
|
||||
|
||||
if config.Validate([]string{"name", "othername"}) == nil {
|
||||
t.Fatal("Validation should fail if more than one name is specified")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDataConfigValidation_Flags(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
config cMapFlagsAndArgs
|
||||
shouldFail bool
|
||||
}{
|
||||
{
|
||||
name: "env-file-source and literal are both set",
|
||||
config: cMapFlagsAndArgs{
|
||||
LiteralSources: []string{"one", "two"},
|
||||
EnvFileSource: "three",
|
||||
},
|
||||
shouldFail: true,
|
||||
},
|
||||
{
|
||||
name: "env-file-source and from-file are both set",
|
||||
config: cMapFlagsAndArgs{
|
||||
FileSources: []string{"one", "two"},
|
||||
EnvFileSource: "three",
|
||||
},
|
||||
shouldFail: true,
|
||||
},
|
||||
{
|
||||
name: "we don't have any option set",
|
||||
config: cMapFlagsAndArgs{},
|
||||
shouldFail: true,
|
||||
},
|
||||
{
|
||||
name: "we have from-file and literal ",
|
||||
config: cMapFlagsAndArgs{
|
||||
LiteralSources: []string{"one", "two"},
|
||||
FileSources: []string{"three", "four"},
|
||||
},
|
||||
shouldFail: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if test.config.Validate([]string{"name"}) == nil && test.shouldFail {
|
||||
t.Fatalf("Validation should fail if %s", test.name)
|
||||
} else if test.config.Validate([]string{"name"}) != nil && !test.shouldFail {
|
||||
t.Fatalf("Validation should succeed if %s", test.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandFileSource(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.Create("dir/config1")
|
||||
fakeFS.Create("dir/config2")
|
||||
fakeFS.Create("dir/reademe")
|
||||
config := cMapFlagsAndArgs{
|
||||
FileSources: []string{"dir/config*"},
|
||||
}
|
||||
config.ExpandFileSource(fakeFS)
|
||||
expected := []string{
|
||||
"dir/config1",
|
||||
"dir/config2",
|
||||
}
|
||||
if !reflect.DeepEqual(config.FileSources, expected) {
|
||||
t.Fatalf("FileSources is not correctly expanded: %v", config.FileSources)
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,22 @@
|
||||
/*
|
||||
Copyright 2017 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.
|
||||
*/
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package add
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
)
|
||||
|
||||
// newCmdAddConfigMap returns a new command.
|
||||
func newCmdAddConfigMap(fSys fs.FileSystem, kf ifc.KunstructuredFactory) *cobra.Command {
|
||||
var flagsAndArgs cMapFlagsAndArgs
|
||||
func newCmdAddConfigMap(
|
||||
fSys fs.FileSystem,
|
||||
ldr ifc.Loader,
|
||||
kf ifc.KunstructuredFactory) *cobra.Command {
|
||||
var flags flagsAndArgs
|
||||
cmd := &cobra.Command{
|
||||
Use: "configmap NAME [--from-file=[key=]source] [--from-literal=key1=value1]",
|
||||
Short: "Adds a configmap to the kustomization file.",
|
||||
@@ -45,12 +32,12 @@ func newCmdAddConfigMap(fSys fs.FileSystem, kf ifc.KunstructuredFactory) *cobra.
|
||||
kustomize edit add configmap my-configmap --from-env-file=env/path.env
|
||||
`,
|
||||
RunE: func(_ *cobra.Command, args []string) error {
|
||||
err := flagsAndArgs.ExpandFileSource(fSys)
|
||||
err := flags.ExpandFileSource(fSys)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = flagsAndArgs.Validate(args)
|
||||
err = flags.Validate(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -67,8 +54,7 @@ func newCmdAddConfigMap(fSys fs.FileSystem, kf ifc.KunstructuredFactory) *cobra.
|
||||
}
|
||||
|
||||
// Add the flagsAndArgs map to the kustomization file.
|
||||
kf.Set(fSys, loader.NewFileLoaderAtCwd(fSys))
|
||||
err = addConfigMap(kustomization, flagsAndArgs, kf)
|
||||
err = addConfigMap(ldr, kustomization, flags, kf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -79,19 +65,19 @@ func newCmdAddConfigMap(fSys fs.FileSystem, kf ifc.KunstructuredFactory) *cobra.
|
||||
}
|
||||
|
||||
cmd.Flags().StringSliceVar(
|
||||
&flagsAndArgs.FileSources,
|
||||
&flags.FileSources,
|
||||
"from-file",
|
||||
[]string{},
|
||||
"Key file 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.")
|
||||
cmd.Flags().StringArrayVar(
|
||||
&flagsAndArgs.LiteralSources,
|
||||
&flags.LiteralSources,
|
||||
"from-literal",
|
||||
[]string{},
|
||||
"Specify a key and literal value to insert in configmap (i.e. mykey=somevalue)")
|
||||
cmd.Flags().StringVar(
|
||||
&flagsAndArgs.EnvFileSource,
|
||||
&flags.EnvFileSource,
|
||||
"from-env-file",
|
||||
"",
|
||||
"Specify the path to a file to read lines of key=val pairs to create a configmap (i.e. a Docker .env file).")
|
||||
@@ -103,22 +89,20 @@ func newCmdAddConfigMap(fSys fs.FileSystem, kf ifc.KunstructuredFactory) *cobra.
|
||||
// Note: error may leave kustomization file in an undefined state.
|
||||
// Suggest passing a copy of kustomization file.
|
||||
func addConfigMap(
|
||||
ldr ifc.Loader,
|
||||
k *types.Kustomization,
|
||||
flagsAndArgs cMapFlagsAndArgs, kf ifc.KunstructuredFactory) error {
|
||||
cmArgs := makeConfigMapArgs(k, flagsAndArgs.Name)
|
||||
err := mergeFlagsIntoCmArgs(&cmArgs.DataSources, flagsAndArgs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
flags flagsAndArgs, kf ifc.KunstructuredFactory) error {
|
||||
args := findOrMakeConfigMapArgs(k, flags.Name)
|
||||
mergeFlagsIntoCmArgs(args, flags)
|
||||
// Validate by trying to create corev1.configmap.
|
||||
_, err = kf.MakeConfigMap(cmArgs, k.GeneratorOptions)
|
||||
_, err := kf.MakeConfigMap(ldr, k.GeneratorOptions, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
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 {
|
||||
if name == v.Name {
|
||||
return &m.ConfigMapGenerator[i]
|
||||
@@ -130,12 +114,17 @@ func makeConfigMapArgs(m *types.Kustomization, name string) *types.ConfigMapArgs
|
||||
return &m.ConfigMapGenerator[len(m.ConfigMapGenerator)-1]
|
||||
}
|
||||
|
||||
func mergeFlagsIntoCmArgs(src *types.DataSources, flags cMapFlagsAndArgs) error {
|
||||
src.LiteralSources = append(src.LiteralSources, flags.LiteralSources...)
|
||||
src.FileSources = append(src.FileSources, flags.FileSources...)
|
||||
if src.EnvSource != "" && src.EnvSource != flags.EnvFileSource {
|
||||
return fmt.Errorf("updating existing env source '%s' not allowed", src.EnvSource)
|
||||
func mergeFlagsIntoCmArgs(args *types.ConfigMapArgs, flags flagsAndArgs) {
|
||||
if len(flags.LiteralSources) > 0 {
|
||||
args.LiteralSources = append(
|
||||
args.LiteralSources, flags.LiteralSources...)
|
||||
}
|
||||
if len(flags.FileSources) > 0 {
|
||||
args.FileSources = append(
|
||||
args.FileSources, flags.FileSources...)
|
||||
}
|
||||
if flags.EnvFileSource != "" {
|
||||
args.EnvSources = append(
|
||||
args.EnvSources, flags.EnvFileSource)
|
||||
}
|
||||
src.EnvSource = flags.EnvFileSource
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
/*
|
||||
Copyright 2017 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.
|
||||
*/
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package add
|
||||
|
||||
@@ -20,11 +7,15 @@ import (
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/pkg/validators"
|
||||
)
|
||||
|
||||
func TestNewAddConfigMapIsNotNil(t *testing.T) {
|
||||
if newCmdAddConfigMap(fs.MakeFakeFS(), nil) == nil {
|
||||
fSys := fs.MakeFakeFS()
|
||||
ldr := loader.NewFileLoaderAtCwd(validators.MakeFakeValidator(), fSys)
|
||||
if newCmdAddConfigMap(fSys, ldr, nil) == nil {
|
||||
t.Fatal("newCmdAddConfigMap shouldn't be nil")
|
||||
}
|
||||
}
|
||||
@@ -39,7 +30,7 @@ func TestMakeConfigMapArgs(t *testing.T) {
|
||||
if len(kustomization.ConfigMapGenerator) != 0 {
|
||||
t.Fatal("Initial kustomization should not have any configmaps")
|
||||
}
|
||||
args := makeConfigMapArgs(kustomization, cmName)
|
||||
args := findOrMakeConfigMapArgs(kustomization, cmName)
|
||||
|
||||
if args == nil {
|
||||
t.Fatalf("args should always be non-nil")
|
||||
@@ -53,7 +44,7 @@ func TestMakeConfigMapArgs(t *testing.T) {
|
||||
t.Fatalf("Pointer address for newly inserted configmap generator should be same")
|
||||
}
|
||||
|
||||
args2 := makeConfigMapArgs(kustomization, cmName)
|
||||
args2 := findOrMakeConfigMapArgs(kustomization, cmName)
|
||||
|
||||
if args2 != args {
|
||||
t.Fatalf("should have returned an existing args with name: %v", cmName)
|
||||
@@ -64,66 +55,53 @@ func TestMakeConfigMapArgs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeFlagsIntoCmArgs_LiteralSources(t *testing.T) {
|
||||
ds := &types.DataSources{}
|
||||
|
||||
err := mergeFlagsIntoCmArgs(ds, cMapFlagsAndArgs{LiteralSources: []string{"k1=v1"}})
|
||||
if err != nil {
|
||||
t.Fatalf("Merge initial literal source should not return error")
|
||||
func TestMergeFlagsIntoConfigMapArgs_LiteralSources(t *testing.T) {
|
||||
k := &types.Kustomization{}
|
||||
args := findOrMakeConfigMapArgs(k, "foo")
|
||||
mergeFlagsIntoGeneratorArgs(
|
||||
&args.GeneratorArgs,
|
||||
flagsAndArgs{LiteralSources: []string{"k1=v1"}})
|
||||
mergeFlagsIntoGeneratorArgs(
|
||||
&args.GeneratorArgs,
|
||||
flagsAndArgs{LiteralSources: []string{"k2=v2"}})
|
||||
if k.ConfigMapGenerator[0].LiteralSources[0] != "k1=v1" {
|
||||
t.Fatalf("expected v1")
|
||||
}
|
||||
|
||||
if len(ds.LiteralSources) != 1 {
|
||||
t.Fatalf("Initial literal source should have been added")
|
||||
}
|
||||
|
||||
err = mergeFlagsIntoCmArgs(ds, cMapFlagsAndArgs{LiteralSources: []string{"k2=v2"}})
|
||||
if err != nil {
|
||||
t.Fatalf("Merge second literal source should not return error")
|
||||
}
|
||||
|
||||
if len(ds.LiteralSources) != 2 {
|
||||
t.Fatalf("Second literal source should have been added")
|
||||
if k.ConfigMapGenerator[0].LiteralSources[1] != "k2=v2" {
|
||||
t.Fatalf("expected v2")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeFlagsIntoCmArgs_FileSources(t *testing.T) {
|
||||
ds := &types.DataSources{}
|
||||
|
||||
err := mergeFlagsIntoCmArgs(ds, cMapFlagsAndArgs{FileSources: []string{"file1"}})
|
||||
if err != nil {
|
||||
t.Fatalf("Merge initial file source should not return error")
|
||||
func TestMergeFlagsIntoConfigMapArgs_FileSources(t *testing.T) {
|
||||
k := &types.Kustomization{}
|
||||
args := findOrMakeConfigMapArgs(k, "foo")
|
||||
mergeFlagsIntoGeneratorArgs(
|
||||
&args.GeneratorArgs,
|
||||
flagsAndArgs{FileSources: []string{"file1"}})
|
||||
mergeFlagsIntoGeneratorArgs(
|
||||
&args.GeneratorArgs,
|
||||
flagsAndArgs{FileSources: []string{"file2"}})
|
||||
if k.ConfigMapGenerator[0].FileSources[0] != "file1" {
|
||||
t.Fatalf("expected file1")
|
||||
}
|
||||
|
||||
if len(ds.FileSources) != 1 {
|
||||
t.Fatalf("Initial file source should have been added")
|
||||
}
|
||||
|
||||
err = mergeFlagsIntoCmArgs(ds, cMapFlagsAndArgs{FileSources: []string{"file2"}})
|
||||
if err != nil {
|
||||
t.Fatalf("Merge second file source should not return error")
|
||||
}
|
||||
|
||||
if len(ds.FileSources) != 2 {
|
||||
t.Fatalf("Second file source should have been added")
|
||||
if k.ConfigMapGenerator[0].FileSources[1] != "file2" {
|
||||
t.Fatalf("expected file2")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeFlagsIntoCmArgs_EnvSource(t *testing.T) {
|
||||
envFileName := "env1"
|
||||
envFileName2 := "env2"
|
||||
ds := &types.DataSources{}
|
||||
|
||||
err := mergeFlagsIntoCmArgs(ds, cMapFlagsAndArgs{EnvFileSource: envFileName})
|
||||
if err != nil {
|
||||
t.Fatalf("Merge initial env source should not return error")
|
||||
func TestMergeFlagsIntoConfigMapArgs_EnvSource(t *testing.T) {
|
||||
k := &types.Kustomization{}
|
||||
args := findOrMakeConfigMapArgs(k, "foo")
|
||||
mergeFlagsIntoGeneratorArgs(
|
||||
&args.GeneratorArgs,
|
||||
flagsAndArgs{EnvFileSource: "env1"})
|
||||
mergeFlagsIntoGeneratorArgs(
|
||||
&args.GeneratorArgs,
|
||||
flagsAndArgs{EnvFileSource: "env2"})
|
||||
if k.ConfigMapGenerator[0].EnvSources[0] != "env1" {
|
||||
t.Fatalf("expected env1")
|
||||
}
|
||||
|
||||
if ds.EnvSource != envFileName {
|
||||
t.Fatalf("Initial env source filename should have been added")
|
||||
}
|
||||
|
||||
err = mergeFlagsIntoCmArgs(ds, cMapFlagsAndArgs{EnvFileSource: envFileName2})
|
||||
if err == nil {
|
||||
t.Fatalf("Updating env source should return an error")
|
||||
if k.ConfigMapGenerator[0].EnvSources[1] != "env2" {
|
||||
t.Fatalf("expected env2")
|
||||
}
|
||||
}
|
||||
|
||||
107
pkg/commands/edit/add/flagsandargs.go
Normal file
107
pkg/commands/edit/add/flagsandargs.go
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
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 add
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
)
|
||||
|
||||
// flagsAndArgs encapsulates the options for add secret/configmap commands.
|
||||
type flagsAndArgs struct {
|
||||
// Name of configMap/Secret (required)
|
||||
Name string
|
||||
// FileSources to derive the configMap/Secret from (optional)
|
||||
FileSources []string
|
||||
// LiteralSources to derive the configMap/Secret from (optional)
|
||||
LiteralSources []string
|
||||
// EnvFileSource to derive the configMap/Secret from (optional)
|
||||
// TODO: Rationalize this name with Generic.EnvSource
|
||||
EnvFileSource string
|
||||
// Type of secret to create
|
||||
Type string
|
||||
}
|
||||
|
||||
// Validate validates required fields are set to support structured generation.
|
||||
func (a *flagsAndArgs) Validate(args []string) error {
|
||||
if len(args) != 1 {
|
||||
return fmt.Errorf("name must be specified once")
|
||||
}
|
||||
a.Name = args[0]
|
||||
if len(a.EnvFileSource) == 0 && len(a.FileSources) == 0 && len(a.LiteralSources) == 0 {
|
||||
return fmt.Errorf("at least from-env-file, or from-file or from-literal must be set")
|
||||
}
|
||||
if len(a.EnvFileSource) > 0 && (len(a.FileSources) > 0 || len(a.LiteralSources) > 0) {
|
||||
return fmt.Errorf("from-env-file cannot be combined with from-file or from-literal")
|
||||
}
|
||||
// TODO: Should we check if the path exists? if it's valid, if it's within the same (sub-)directory?
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExpandFileSource normalizes a string list, possibly
|
||||
// containing globs, into a validated, globless list.
|
||||
// For example, this list:
|
||||
// some/path
|
||||
// some/dir/a*
|
||||
// bfile=some/dir/b*
|
||||
// becomes:
|
||||
// some/path
|
||||
// some/dir/airplane
|
||||
// some/dir/ant
|
||||
// some/dir/apple
|
||||
// bfile=some/dir/banana
|
||||
// i.e. everything is converted to a key=value pair,
|
||||
// where the value is always a relative file path,
|
||||
// and the key, if missing, is the same as the value.
|
||||
// In the case where the key is explicitly declared,
|
||||
// the globbing, if present, must have exactly one match.
|
||||
func (a *flagsAndArgs) ExpandFileSource(fSys fs.FileSystem) error {
|
||||
var results []string
|
||||
for _, pattern := range a.FileSources {
|
||||
var patterns []string
|
||||
key := ""
|
||||
// check if the pattern is in `--from-file=[key=]source` format
|
||||
// and if so split it to send only the file-pattern to glob function
|
||||
s := strings.Split(pattern, "=")
|
||||
if len(s) == 2 {
|
||||
patterns = append(patterns, s[1])
|
||||
key = s[0]
|
||||
} else {
|
||||
patterns = append(patterns, s[0])
|
||||
}
|
||||
result, err := globPatterns(fSys, patterns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// if the format is `--from-file=[key=]source` accept only one result
|
||||
// and extend it with the `key=` prefix
|
||||
if key != "" {
|
||||
if len(result) != 1 {
|
||||
return fmt.Errorf(
|
||||
"'pattern '%s' catches files %v, should catch only one", pattern, result)
|
||||
}
|
||||
fileSource := fmt.Sprintf("%s=%s", key, result[0])
|
||||
results = append(results, fileSource)
|
||||
} else {
|
||||
results = append(results, result...)
|
||||
}
|
||||
}
|
||||
a.FileSources = results
|
||||
return nil
|
||||
}
|
||||
138
pkg/commands/edit/add/flagsandargs_test.go
Normal file
138
pkg/commands/edit/add/flagsandargs_test.go
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
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 add
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
)
|
||||
|
||||
func TestDataValidation_NoName(t *testing.T) {
|
||||
fa := flagsAndArgs{}
|
||||
|
||||
if fa.Validate([]string{}) == nil {
|
||||
t.Fatal("Validation should fail if no name is specified")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDataValidation_MoreThanOneName(t *testing.T) {
|
||||
fa := flagsAndArgs{}
|
||||
|
||||
if fa.Validate([]string{"name", "othername"}) == nil {
|
||||
t.Fatal("Validation should fail if more than one name is specified")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDataConfigValidation_Flags(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fa flagsAndArgs
|
||||
shouldFail bool
|
||||
}{
|
||||
{
|
||||
name: "env-file-source and literal are both set",
|
||||
fa: flagsAndArgs{
|
||||
LiteralSources: []string{"one", "two"},
|
||||
EnvFileSource: "three",
|
||||
},
|
||||
shouldFail: true,
|
||||
},
|
||||
{
|
||||
name: "env-file-source and from-file are both set",
|
||||
fa: flagsAndArgs{
|
||||
FileSources: []string{"one", "two"},
|
||||
EnvFileSource: "three",
|
||||
},
|
||||
shouldFail: true,
|
||||
},
|
||||
{
|
||||
name: "we don't have any option set",
|
||||
fa: flagsAndArgs{},
|
||||
shouldFail: true,
|
||||
},
|
||||
{
|
||||
name: "we have from-file and literal ",
|
||||
fa: flagsAndArgs{
|
||||
LiteralSources: []string{"one", "two"},
|
||||
FileSources: []string{"three", "four"},
|
||||
},
|
||||
shouldFail: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if test.fa.Validate([]string{"name"}) == nil && test.shouldFail {
|
||||
t.Fatalf("Validation should fail if %s", test.name)
|
||||
} else if test.fa.Validate([]string{"name"}) != nil && !test.shouldFail {
|
||||
t.Fatalf("Validation should succeed if %s", test.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandFileSource(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.Create("dir/fa1")
|
||||
fakeFS.Create("dir/fa2")
|
||||
fakeFS.Create("dir/readme")
|
||||
fa := flagsAndArgs{
|
||||
FileSources: []string{"dir/fa*"},
|
||||
}
|
||||
fa.ExpandFileSource(fakeFS)
|
||||
expected := []string{
|
||||
"dir/fa1",
|
||||
"dir/fa2",
|
||||
}
|
||||
if !reflect.DeepEqual(fa.FileSources, expected) {
|
||||
t.Fatalf("FileSources is not correctly expanded: %v", fa.FileSources)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandFileSourceWithKey(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.Create("dir/faaaaaaaaaabbbbbbbbbccccccccccccccccc")
|
||||
fakeFS.Create("dir/foobar")
|
||||
fakeFS.Create("dir/simplebar")
|
||||
fakeFS.Create("dir/readme")
|
||||
fa := flagsAndArgs{
|
||||
FileSources: []string{"foo-key=dir/fa*", "bar-key=dir/foobar", "dir/simplebar"},
|
||||
}
|
||||
fa.ExpandFileSource(fakeFS)
|
||||
expected := []string{
|
||||
"foo-key=dir/faaaaaaaaaabbbbbbbbbccccccccccccccccc",
|
||||
"bar-key=dir/foobar",
|
||||
"dir/simplebar",
|
||||
}
|
||||
if !reflect.DeepEqual(fa.FileSources, expected) {
|
||||
t.Fatalf("FileSources is not correctly expanded: %v", fa.FileSources)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandFileSourceWithKeyAndError(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.Create("dir/fa1")
|
||||
fakeFS.Create("dir/fa2")
|
||||
fakeFS.Create("dir/readme")
|
||||
fa := flagsAndArgs{
|
||||
FileSources: []string{"foo-key=dir/fa*"},
|
||||
}
|
||||
err := fa.ExpandFileSource(fakeFS)
|
||||
if err == nil {
|
||||
t.Fatalf("FileSources should not be correctly expanded: %v", fa.FileSources)
|
||||
}
|
||||
}
|
||||
137
pkg/commands/edit/add/secret.go
Normal file
137
pkg/commands/edit/add/secret.go
Normal file
@@ -0,0 +1,137 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package add
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
)
|
||||
|
||||
// newCmdAddSecret returns a new command.
|
||||
func newCmdAddSecret(
|
||||
fSys fs.FileSystem,
|
||||
ldr ifc.Loader,
|
||||
kf ifc.KunstructuredFactory) *cobra.Command {
|
||||
var flags flagsAndArgs
|
||||
cmd := &cobra.Command{
|
||||
Use: "secret NAME [--from-file=[key=]source] [--from-literal=key1=value1] [--type=Opaque|kubernetes.io/tls]",
|
||||
Short: "Adds a secret to the kustomization file.",
|
||||
Long: "",
|
||||
Example: `
|
||||
# Adds a secret to the kustomization file (with a specified key)
|
||||
kustomize edit add secret my-secret --from-file=my-key=file/path --from-literal=my-literal=12345
|
||||
|
||||
# Adds a secret to the kustomization file (key is the filename)
|
||||
kustomize edit add secret my-secret --from-file=file/path
|
||||
|
||||
# Adds a secret from env-file
|
||||
kustomize edit add secret my-secret --from-env-file=env/path.env
|
||||
`,
|
||||
RunE: func(_ *cobra.Command, args []string) error {
|
||||
err := flags.ExpandFileSource(fSys)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = flags.Validate(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Load the kustomization file.
|
||||
mf, err := kustfile.NewKustomizationFile(fSys)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
kustomization, err := mf.Read()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Add the flagsAndArgs map to the kustomization file.
|
||||
err = addSecret(ldr, kustomization, flags, kf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Write out the kustomization file with added secret.
|
||||
return mf.Write(kustomization)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringSliceVar(
|
||||
&flags.FileSources,
|
||||
"from-file",
|
||||
[]string{},
|
||||
"Key file can be specified using its file path, in which case file basename will be used as secret "+
|
||||
"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 secret key.")
|
||||
cmd.Flags().StringArrayVar(
|
||||
&flags.LiteralSources,
|
||||
"from-literal",
|
||||
[]string{},
|
||||
"Specify a key and literal value to insert in secret (i.e. mykey=somevalue)")
|
||||
cmd.Flags().StringVar(
|
||||
&flags.EnvFileSource,
|
||||
"from-env-file",
|
||||
"",
|
||||
"Specify the path to a file to read lines of key=val pairs to create a secret (i.e. a Docker .env file).")
|
||||
cmd.Flags().StringVar(
|
||||
&flags.Type,
|
||||
"type",
|
||||
"Opaque",
|
||||
"Specify the secret type this can be 'Opaque' (default), or 'kubernetes.io/tls'")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// addSecret adds a secret to a kustomization file.
|
||||
// Note: error may leave kustomization file in an undefined state.
|
||||
// Suggest passing a copy of kustomization file.
|
||||
func addSecret(
|
||||
ldr ifc.Loader,
|
||||
k *types.Kustomization,
|
||||
flags flagsAndArgs, kf ifc.KunstructuredFactory) error {
|
||||
args := findOrMakeSecretArgs(k, flags.Name, flags.Type)
|
||||
mergeFlagsIntoGeneratorArgs(&args.GeneratorArgs, flags)
|
||||
// Validate by trying to create corev1.secret.
|
||||
_, err := kf.MakeSecret(ldr, k.GeneratorOptions, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func findOrMakeSecretArgs(m *types.Kustomization, name, secretType string) *types.SecretArgs {
|
||||
for i, v := range m.SecretGenerator {
|
||||
if name == v.Name {
|
||||
return &m.SecretGenerator[i]
|
||||
}
|
||||
}
|
||||
// secret not found, create new one and add it to the kustomization file.
|
||||
secret := &types.SecretArgs{
|
||||
GeneratorArgs: types.GeneratorArgs{Name: name},
|
||||
Type: secretType}
|
||||
m.SecretGenerator = append(m.SecretGenerator, *secret)
|
||||
return &m.SecretGenerator[len(m.SecretGenerator)-1]
|
||||
}
|
||||
|
||||
func mergeFlagsIntoGeneratorArgs(args *types.GeneratorArgs, flags flagsAndArgs) {
|
||||
if len(flags.LiteralSources) > 0 {
|
||||
args.LiteralSources = append(
|
||||
args.LiteralSources, flags.LiteralSources...)
|
||||
}
|
||||
if len(flags.FileSources) > 0 {
|
||||
args.FileSources = append(
|
||||
args.FileSources, flags.FileSources...)
|
||||
}
|
||||
if flags.EnvFileSource != "" {
|
||||
args.EnvSources = append(
|
||||
args.EnvSources, flags.EnvFileSource)
|
||||
}
|
||||
}
|
||||
109
pkg/commands/edit/add/secret_test.go
Normal file
109
pkg/commands/edit/add/secret_test.go
Normal file
@@ -0,0 +1,109 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package add
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/pkg/validators"
|
||||
)
|
||||
|
||||
func TestNewCmdAddSecretIsNotNil(t *testing.T) {
|
||||
fSys := fs.MakeFakeFS()
|
||||
ldr := loader.NewFileLoaderAtCwd(validators.MakeFakeValidator(), fSys)
|
||||
if newCmdAddSecret(fSys, ldr, nil) == nil {
|
||||
t.Fatal("newCmdAddSecret shouldn't be nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakeSecretArgs(t *testing.T) {
|
||||
secretName := "test-secret-name"
|
||||
|
||||
kustomization := &types.Kustomization{
|
||||
NamePrefix: "test-name-prefix",
|
||||
}
|
||||
|
||||
secretType := "Opaque"
|
||||
|
||||
if len(kustomization.SecretGenerator) != 0 {
|
||||
t.Fatal("Initial kustomization should not have any secrets")
|
||||
}
|
||||
args := findOrMakeSecretArgs(kustomization, secretName, secretType)
|
||||
|
||||
if args == nil {
|
||||
t.Fatalf("args should always be non-nil")
|
||||
}
|
||||
|
||||
if len(kustomization.SecretGenerator) != 1 {
|
||||
t.Fatalf("Kustomization should have newly created secret")
|
||||
}
|
||||
|
||||
if &kustomization.SecretGenerator[len(kustomization.SecretGenerator)-1] != args {
|
||||
t.Fatalf("Pointer address for newly inserted secret generator should be same")
|
||||
}
|
||||
|
||||
args2 := findOrMakeSecretArgs(kustomization, secretName, secretType)
|
||||
|
||||
if args2 != args {
|
||||
t.Fatalf("should have returned an existing args with name: %v", secretName)
|
||||
}
|
||||
|
||||
if len(kustomization.SecretGenerator) != 1 {
|
||||
t.Fatalf("Should not insert secret for an existing name: %v", secretName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeFlagsIntoSecretArgs_LiteralSources(t *testing.T) {
|
||||
k := &types.Kustomization{}
|
||||
args := findOrMakeSecretArgs(k, "foo", "forbidden")
|
||||
mergeFlagsIntoGeneratorArgs(
|
||||
&args.GeneratorArgs,
|
||||
flagsAndArgs{LiteralSources: []string{"k1=v1"}})
|
||||
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" {
|
||||
t.Fatalf("expected v2")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeFlagsIntoSecretArgs_FileSources(t *testing.T) {
|
||||
k := &types.Kustomization{}
|
||||
args := findOrMakeSecretArgs(k, "foo", "forbidden")
|
||||
mergeFlagsIntoGeneratorArgs(
|
||||
&args.GeneratorArgs,
|
||||
flagsAndArgs{FileSources: []string{"file1"}})
|
||||
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" {
|
||||
t.Fatalf("expected file2")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeFlagsIntoSecretArgs_EnvSource(t *testing.T) {
|
||||
k := &types.Kustomization{}
|
||||
args := findOrMakeSecretArgs(k, "foo", "forbidden")
|
||||
mergeFlagsIntoGeneratorArgs(
|
||||
&args.GeneratorArgs,
|
||||
flagsAndArgs{EnvFileSource: "env1"})
|
||||
mergeFlagsIntoGeneratorArgs(
|
||||
&args.GeneratorArgs,
|
||||
flagsAndArgs{EnvFileSource: "env2"})
|
||||
if k.SecretGenerator[0].EnvSources[0] != "env1" {
|
||||
t.Fatalf("expected env1")
|
||||
}
|
||||
if k.SecretGenerator[0].EnvSources[1] != "env2" {
|
||||
t.Fatalf("expected env2")
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,22 @@
|
||||
/*
|
||||
Copyright 2017 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.
|
||||
*/
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package edit
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/edit/add"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/edit/fix"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/edit/remove"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/edit/set"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/loader"
|
||||
)
|
||||
|
||||
// NewCmdEdit returns an instance of 'edit' subcommand.
|
||||
func NewCmdEdit(fsys fs.FileSystem, v ifc.Validator, kf ifc.KunstructuredFactory) *cobra.Command {
|
||||
func NewCmdEdit(
|
||||
fSys fs.FileSystem, v ifc.Validator, kf ifc.KunstructuredFactory) *cobra.Command {
|
||||
c := &cobra.Command{
|
||||
Use: "edit",
|
||||
Short: "Edits a kustomization file",
|
||||
@@ -42,9 +33,12 @@ func NewCmdEdit(fsys fs.FileSystem, v ifc.Validator, kf ifc.KunstructuredFactory
|
||||
`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
}
|
||||
|
||||
c.AddCommand(
|
||||
add.NewCmdAdd(fsys, v, kf),
|
||||
set.NewCmdSet(fsys, v),
|
||||
add.NewCmdAdd(fSys, loader.NewFileLoaderAtCwd(v, fSys), kf),
|
||||
set.NewCmdSet(fSys, v),
|
||||
fix.NewCmdFix(fSys),
|
||||
remove.NewCmdRemove(fSys),
|
||||
)
|
||||
return c
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user