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