mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-18 02:45:17 +00:00
kustomize.yaml becomes kustomization.yaml
This commit is contained in:
@@ -213,13 +213,13 @@ func (a *applicationImpl) getTransformer(patches []*resource.Resource) (transfor
|
||||
}
|
||||
ts = append(ts, npt)
|
||||
|
||||
lt, err := transformers.NewDefaultingLabelsMapTransformer(a.kustomization.LabelsToAdd)
|
||||
lt, err := transformers.NewDefaultingLabelsMapTransformer(a.kustomization.CommonLabels)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ts = append(ts, lt)
|
||||
|
||||
at, err := transformers.NewDefaultingAnnotationsMapTransformer(a.kustomization.AnnotationsToAdd)
|
||||
at, err := transformers.NewDefaultingAnnotationsMapTransformer(a.kustomization.CommonAnnotations)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/kubectl/pkg/kustomize/constants"
|
||||
"k8s.io/kubectl/pkg/kustomize/resource"
|
||||
"k8s.io/kubectl/pkg/kustomize/types"
|
||||
"k8s.io/kubectl/pkg/loader"
|
||||
@@ -34,9 +35,9 @@ import (
|
||||
func setupTest(t *testing.T) loader.Loader {
|
||||
kustomizationContent := []byte(`
|
||||
namePrefix: foo-
|
||||
labelsToAdd:
|
||||
commonLabels:
|
||||
app: nginx
|
||||
annotationsToAdd:
|
||||
commonAnnotations:
|
||||
note: This is a test annotation
|
||||
resources:
|
||||
- deployment.yaml
|
||||
@@ -59,7 +60,7 @@ metadata:
|
||||
`)
|
||||
|
||||
loader := loadertest.NewFakeLoader("/testpath")
|
||||
err := loader.AddFile("/testpath/kustomize.yaml", kustomizationContent)
|
||||
err := loader.AddFile("/testpath/"+constants.KustomizationFileName, kustomizationContent)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to setup fake loader.")
|
||||
}
|
||||
|
||||
@@ -44,9 +44,8 @@ func newCmdBuild(out, errOut io.Writer, fs fs.FileSystem) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "build [path]",
|
||||
Short: "Print current configuration per contents of " + constants.KustomizationFileName,
|
||||
Example: `
|
||||
# Use the kustomize.yaml file under somedir/ to generate a set of api resources.
|
||||
build somedir/`,
|
||||
Example: "Use the file somedir/" + constants.KustomizationFileName +
|
||||
" to generate a set of api resources:\nbuild somedir/",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
err := o.Validate(args)
|
||||
if err != nil {
|
||||
@@ -66,7 +65,7 @@ func newCmdBuild(out, errOut io.Writer, fs fs.FileSystem) *cobra.Command {
|
||||
// Validate validates build command.
|
||||
func (o *buildOptions) Validate(args []string) error {
|
||||
if len(args) > 1 {
|
||||
return errors.New("specify one path to kustomization file")
|
||||
return errors.New("specify one path to " + constants.KustomizationFileName)
|
||||
}
|
||||
if len(args) == 0 {
|
||||
o.kustomizationPath = "./"
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"github.com/ghodss/yaml"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/kubectl/pkg/kustomize/constants"
|
||||
"k8s.io/kubectl/pkg/kustomize/util/fs"
|
||||
)
|
||||
|
||||
@@ -50,7 +51,8 @@ func TestBuildValidate(t *testing.T) {
|
||||
{"noargs", []string{}, "./", ""},
|
||||
{"file", []string{"beans"}, "beans", ""},
|
||||
{"path", []string{"a/b/c"}, "a/b/c", ""},
|
||||
{"path", []string{"too", "many"}, "", "specify one path to kustomization file"},
|
||||
{"path", []string{"too", "many"},
|
||||
"", "specify one path to " + constants.KustomizationFileName},
|
||||
}
|
||||
for _, mycase := range cases {
|
||||
opts := buildOptions{}
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/kubectl/pkg/kustomize/app"
|
||||
"k8s.io/kubectl/pkg/kustomize/constants"
|
||||
"k8s.io/kubectl/pkg/kustomize/util"
|
||||
"k8s.io/kubectl/pkg/kustomize/util/fs"
|
||||
"k8s.io/kubectl/pkg/loader"
|
||||
@@ -56,7 +57,12 @@ func newCmdDiff(out, errOut io.Writer, fs fs.FileSystem) *cobra.Command {
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringVarP(&o.kustomizationPath, "filename", "f", "", "Pass in a kustomize.yaml file or a directory that contains the file.")
|
||||
cmd.Flags().StringVarP(
|
||||
&o.kustomizationPath,
|
||||
"filename",
|
||||
"f",
|
||||
"",
|
||||
"Specify a directory containing "+constants.KustomizationFileName)
|
||||
cmd.MarkFlagRequired("filename")
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -32,9 +32,9 @@ namePrefix: some-prefix
|
||||
# Labels to add to all objects and selectors.
|
||||
# These labels would also be used to form the selector for apply --prune
|
||||
# Named differently than “labels” to avoid confusion with metadata for this object
|
||||
labelsToAdd:
|
||||
commonLabels:
|
||||
app: helloworld
|
||||
annotationsToAdd:
|
||||
commonAnnotations:
|
||||
note: This is an example annotation
|
||||
resources: []
|
||||
#- service.yaml
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
namePrefix: team-foo-
|
||||
labelsToAdd:
|
||||
commonLabels:
|
||||
app: mynginx
|
||||
org: example.com
|
||||
team: foo
|
||||
annotationsToAdd:
|
||||
commonAnnotations:
|
||||
note: This is a test annotation
|
||||
resources:
|
||||
- deployment.yaml
|
||||
@@ -1,5 +1,5 @@
|
||||
namePrefix: staging-
|
||||
labelsToAdd:
|
||||
commonLabels:
|
||||
env: staging
|
||||
patches:
|
||||
- deployment-patch2.yaml
|
||||
@@ -1,9 +1,9 @@
|
||||
namePrefix: team-foo-
|
||||
labelsToAdd:
|
||||
commonLabels:
|
||||
app: mynginx
|
||||
org: example.com
|
||||
team: foo
|
||||
annotationsToAdd:
|
||||
commonAnnotations:
|
||||
note: This is a test annotation
|
||||
resources:
|
||||
- deployment.yaml
|
||||
@@ -1,5 +1,5 @@
|
||||
namePrefix: staging-
|
||||
labelsToAdd:
|
||||
commonLabels:
|
||||
env: staging
|
||||
patches:
|
||||
- deployment-patch1.yaml
|
||||
@@ -1,9 +1,9 @@
|
||||
namePrefix: team-foo-
|
||||
labelsToAdd:
|
||||
commonLabels:
|
||||
app: mynginx
|
||||
org: example.com
|
||||
team: foo
|
||||
annotationsToAdd:
|
||||
commonAnnotations:
|
||||
note: This is a test annotation
|
||||
resources:
|
||||
- deployment.yaml
|
||||
@@ -1,5 +1,5 @@
|
||||
namePrefix: staging-
|
||||
labelsToAdd:
|
||||
commonLabels:
|
||||
env: staging
|
||||
team: override-foo
|
||||
patches:
|
||||
@@ -1,9 +1,9 @@
|
||||
namePrefix: team-foo-
|
||||
labelsToAdd:
|
||||
commonLabels:
|
||||
app: mynginx
|
||||
org: example.com
|
||||
team: foo
|
||||
annotationsToAdd:
|
||||
commonAnnotations:
|
||||
note: This is a test annotation
|
||||
resources:
|
||||
- deployment.yaml
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubectl/pkg/kustomize/constants"
|
||||
"k8s.io/kubectl/pkg/kustomize/types"
|
||||
"k8s.io/kubectl/pkg/kustomize/util/fs"
|
||||
)
|
||||
@@ -31,8 +32,8 @@ func TestWriteAndRead(t *testing.T) {
|
||||
}
|
||||
|
||||
fsys := fs.MakeFakeFS()
|
||||
fsys.Create("kustomize.yaml")
|
||||
mf, err := newKustomizationFile("kustomize.yaml", fsys)
|
||||
fsys.Create(constants.KustomizationFileName)
|
||||
mf, err := newKustomizationFile(constants.KustomizationFileName, fsys)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected Error: %v", err)
|
||||
}
|
||||
@@ -63,7 +64,7 @@ func TestNewNotExist(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.Mkdir(".", 0644)
|
||||
fakeFS.Create(badSuffix)
|
||||
_, err := newKustomizationFile("kustomize.yaml", fakeFS)
|
||||
_, err := newKustomizationFile(constants.KustomizationFileName, fakeFS)
|
||||
if err == nil {
|
||||
t.Fatalf("expect an error")
|
||||
}
|
||||
@@ -71,7 +72,7 @@ func TestNewNotExist(t *testing.T) {
|
||||
if !strings.Contains(err.Error(), contained) {
|
||||
t.Fatalf("expect an error contains %q, but got %v", contained, err)
|
||||
}
|
||||
_, err = newKustomizationFile("kustomize.yaml", fakeFS)
|
||||
_, err = newKustomizationFile(constants.KustomizationFileName, fakeFS)
|
||||
if err == nil {
|
||||
t.Fatalf("expect an error")
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package constants
|
||||
|
||||
const KustomizationSuffix = ".yaml"
|
||||
|
||||
// KustomizationFileName is the Well-Known File Name for a kustomize configuration file
|
||||
const KustomizationFileName = "kustomize" + KustomizationSuffix
|
||||
// KustomizationFileName is the Well-Known File Name for a kustomize configuration file.
|
||||
const KustomizationFileName = "kustomization" + KustomizationSuffix
|
||||
|
||||
// Configmap behaviors
|
||||
const CreateBehavior = "create"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
namePrefix: test-infra-
|
||||
labelsToAdd:
|
||||
commonLabels:
|
||||
app: mungebot
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
annotationsToAdd:
|
||||
commonAnnotations:
|
||||
note: This is a test annotation
|
||||
bases:
|
||||
- ../../package/
|
||||
@@ -1,7 +1,7 @@
|
||||
namePrefix: baseprefix-
|
||||
labelsToAdd:
|
||||
commonLabels:
|
||||
foo: bar
|
||||
annotationsToAdd:
|
||||
commonAnnotations:
|
||||
baseAnno: This is an base annotation
|
||||
resources:
|
||||
- deployment/deployment.yaml
|
||||
@@ -19,10 +19,12 @@ package error
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubectl/pkg/kustomize/constants"
|
||||
)
|
||||
|
||||
func TestConfigmapError_Error(t *testing.T) {
|
||||
filepath := "/path/to/kustomize.yaml"
|
||||
filepath := "/path/to/" + constants.KustomizationFileName
|
||||
errorMsg := "configmap name is missing"
|
||||
me := ConfigmapError{Path: filepath, ErrorMsg: errorMsg}
|
||||
|
||||
|
||||
@@ -20,10 +20,12 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubectl/pkg/kustomize/constants"
|
||||
)
|
||||
|
||||
func TestKustomizationError_Error(t *testing.T) {
|
||||
filepath := "/path/to/kustomize.yaml"
|
||||
filepath := "/path/to/" + constants.KustomizationFileName
|
||||
errorMsg := "Kustomization not found"
|
||||
|
||||
me := KustomizationError{KustomizationPath: filepath, ErrorMsg: errorMsg}
|
||||
|
||||
@@ -19,10 +19,12 @@ package error
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubectl/pkg/kustomize/constants"
|
||||
)
|
||||
|
||||
func TestPatchError_Error(t *testing.T) {
|
||||
filepath := "/path/to/kustomize.yaml"
|
||||
filepath := "/path/to/" + constants.KustomizationFileName
|
||||
patchfilepath := "/path/to/patch/patch.yaml"
|
||||
errorMsg := "file not found"
|
||||
me := PatchError{KustomizationPath: filepath, PatchFilepath: patchfilepath, ErrorMsg: errorMsg}
|
||||
|
||||
@@ -19,10 +19,12 @@ package error
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubectl/pkg/kustomize/constants"
|
||||
)
|
||||
|
||||
func TestResourceError_Error(t *testing.T) {
|
||||
filepath := "/path/to/kustomize.yaml"
|
||||
filepath := "/path/to/" + constants.KustomizationFileName
|
||||
resourcefilepath := "/path/to/resource/deployment.yaml"
|
||||
errorMsg := "file not found"
|
||||
me := ResourceError{KustomizationPath: filepath, ResourceFilepath: resourcefilepath, ErrorMsg: errorMsg}
|
||||
|
||||
@@ -26,14 +26,13 @@ type Kustomization struct {
|
||||
// These labels would also be used to form the selector for apply --prune
|
||||
// Named differently than “labels” to avoid confusion with metadata for
|
||||
// this object
|
||||
LabelsToAdd map[string]string `json:"labelsToAdd,omitempty" yaml:"labelsToAdd,omitempty"`
|
||||
CommonLabels map[string]string `json:"commonLabels,omitempty" yaml:"commonLabels,omitempty"`
|
||||
|
||||
// Annotations to add to all objects.
|
||||
AnnotationsToAdd map[string]string `json:"annotationsToAdd,omitempty" yaml:"annotationsToAdd,omitempty"`
|
||||
CommonAnnotations map[string]string `json:"commonAnnotations,omitempty" yaml:"commonAnnotations,omitempty"`
|
||||
|
||||
// Bases contain the paths to other packages that this kustomization depends on.
|
||||
// Each path should be either a path to a kustomize.yaml or a path of
|
||||
// a directory that contains a kustomize.yaml file.
|
||||
// Each entry should be either a path to a file with a name matching the value of
|
||||
// constants.KustomizationFileName, or a path to a directory containing a file with that name.
|
||||
Bases []string `json:"bases,omitempty" yaml:"bases,omitempty"`
|
||||
|
||||
// Resources specifies the relative paths within the package.
|
||||
|
||||
Reference in New Issue
Block a user