mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-17 17:52:12 +00:00
Some kustomization field renaming.
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.ObjectLabels)
|
lt, err := transformers.NewDefaultingLabelsMapTransformer(a.kustomization.LabelsToAdd)
|
||||||
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.ObjectAnnotations)
|
at, err := transformers.NewDefaultingAnnotationsMapTransformer(a.kustomization.AnnotationsToAdd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func setupTest(t *testing.T) loader.Loader {
|
func setupTest(t *testing.T) loader.Loader {
|
||||||
kustomizationContent := []byte(`kustomizationName: nginx-app
|
kustomizationContent := []byte(`
|
||||||
namePrefix: foo-
|
namePrefix: foo-
|
||||||
objectLabels:
|
labelsToAdd:
|
||||||
app: nginx
|
app: nginx
|
||||||
objectAnnotations:
|
annotationsToAdd:
|
||||||
note: This is a test annotation
|
note: This is a test annotation
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
|
|||||||
96
commands/init.go
Normal file
96
commands/init.go
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"k8s.io/kubectl/pkg/kustomize/constants"
|
||||||
|
"k8s.io/kubectl/pkg/kustomize/util/fs"
|
||||||
|
)
|
||||||
|
|
||||||
|
const kustomizationTemplate = `
|
||||||
|
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:
|
||||||
|
app: helloworld
|
||||||
|
annotationsToAdd:
|
||||||
|
note: This is an example annotation
|
||||||
|
resources: []
|
||||||
|
#- service.yaml
|
||||||
|
#- ../some-dir/
|
||||||
|
# There could also be configmaps in Base, which would make these overlays
|
||||||
|
configMapGenerator: []
|
||||||
|
# There could be secrets in Base, if just using a fork/rebase workflow
|
||||||
|
secretGenerator: []
|
||||||
|
`
|
||||||
|
|
||||||
|
type initOptions struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCmdInit makes the init command.
|
||||||
|
func newCmdInit(out, errOut io.Writer, fs fs.FileSystem) *cobra.Command {
|
||||||
|
var o initOptions
|
||||||
|
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "init",
|
||||||
|
Short: "Creates a file called \"" + constants.KustomizationFileName + "\" in the current directory",
|
||||||
|
Long: "Creates a file called \"" +
|
||||||
|
constants.KustomizationFileName + "\" in the current directory with example values.",
|
||||||
|
Example: `init`,
|
||||||
|
SilenceUsage: true,
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
err := o.Validate(cmd, args)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = o.Complete(cmd, args)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return o.RunInit(out, errOut, fs)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate validates init command.
|
||||||
|
func (o *initOptions) Validate(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) > 0 {
|
||||||
|
return errors.New("The init command takes no arguments.")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Complete completes init command.
|
||||||
|
func (o *initOptions) Complete(cmd *cobra.Command, args []string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunInit writes a kustomization file.
|
||||||
|
func (o *initOptions) RunInit(out, errOut io.Writer, fs fs.FileSystem) error {
|
||||||
|
if _, err := fs.Stat(constants.KustomizationFileName); err == nil {
|
||||||
|
return fmt.Errorf("%q already exists", constants.KustomizationFileName)
|
||||||
|
}
|
||||||
|
return fs.WriteFile(constants.KustomizationFileName, []byte(kustomizationTemplate))
|
||||||
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
kustomizationName: nginx-app
|
|
||||||
namePrefix: team-foo-
|
namePrefix: team-foo-
|
||||||
objectLabels:
|
labelsToAdd:
|
||||||
app: mynginx
|
app: mynginx
|
||||||
org: example.com
|
org: example.com
|
||||||
team: foo
|
team: foo
|
||||||
objectAnnotations:
|
annotationsToAdd:
|
||||||
note: This is a test annotation
|
note: This is a test annotation
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
kustomizationName: nginx-app
|
|
||||||
namePrefix: staging-
|
namePrefix: staging-
|
||||||
objectLabels:
|
labelsToAdd:
|
||||||
env: staging
|
env: staging
|
||||||
patches:
|
patches:
|
||||||
- deployment-patch2.yaml
|
- deployment-patch2.yaml
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
kustomizationName: nginx-app
|
|
||||||
namePrefix: team-foo-
|
namePrefix: team-foo-
|
||||||
objectLabels:
|
labelsToAdd:
|
||||||
app: mynginx
|
app: mynginx
|
||||||
org: example.com
|
org: example.com
|
||||||
team: foo
|
team: foo
|
||||||
objectAnnotations:
|
annotationsToAdd:
|
||||||
note: This is a test annotation
|
note: This is a test annotation
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
kustomizationName: nginx-app
|
|
||||||
namePrefix: staging-
|
namePrefix: staging-
|
||||||
objectLabels:
|
labelsToAdd:
|
||||||
env: staging
|
env: staging
|
||||||
patches:
|
patches:
|
||||||
- deployment-patch1.yaml
|
- deployment-patch1.yaml
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
kustomizationName: nginx-app
|
|
||||||
namePrefix: team-foo-
|
namePrefix: team-foo-
|
||||||
objectLabels:
|
labelsToAdd:
|
||||||
app: mynginx
|
app: mynginx
|
||||||
org: example.com
|
org: example.com
|
||||||
team: foo
|
team: foo
|
||||||
objectAnnotations:
|
annotationsToAdd:
|
||||||
note: This is a test annotation
|
note: This is a test annotation
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
kustomizationName: nginx-app
|
|
||||||
namePrefix: staging-
|
namePrefix: staging-
|
||||||
objectLabels:
|
labelsToAdd:
|
||||||
env: staging
|
env: staging
|
||||||
team: override-foo
|
team: override-foo
|
||||||
patches:
|
patches:
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
kustomizationName: nginx-app
|
|
||||||
namePrefix: team-foo-
|
namePrefix: team-foo-
|
||||||
objectLabels:
|
labelsToAdd:
|
||||||
app: mynginx
|
app: mynginx
|
||||||
org: example.com
|
org: example.com
|
||||||
team: foo
|
team: foo
|
||||||
objectAnnotations:
|
annotationsToAdd:
|
||||||
note: This is a test annotation
|
note: This is a test annotation
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
|
|||||||
@@ -1,27 +1,20 @@
|
|||||||
kustomizationName: test-infra-mungebot
|
|
||||||
namePrefix: test-infra-
|
namePrefix: test-infra-
|
||||||
# Labels to add to all objects and selectors.
|
labelsToAdd:
|
||||||
# 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
|
|
||||||
objectLabels:
|
|
||||||
app: mungebot
|
app: mungebot
|
||||||
org: kubernetes
|
org: kubernetes
|
||||||
repo: test-infra
|
repo: test-infra
|
||||||
objectAnnotations:
|
annotationsToAdd:
|
||||||
note: This is a test annotation
|
note: This is a test annotation
|
||||||
bases:
|
bases:
|
||||||
- ../../package/
|
- ../../package/
|
||||||
#These are strategic merge patch overlays in the form of API resources
|
|
||||||
patches:
|
patches:
|
||||||
- deployment/deployment.yaml
|
- deployment/deployment.yaml
|
||||||
#There could also be configmaps in Base, which would make these overlays
|
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
- name: app-env
|
- name: app-env
|
||||||
env: configmap/app.env
|
env: configmap/app.env
|
||||||
- name: app-config
|
- name: app-config
|
||||||
files:
|
files:
|
||||||
- configmap/app-init.ini
|
- configmap/app-init.ini
|
||||||
#There could be secrets in Base, if just using a fork/rebase workflow
|
|
||||||
secretGenerator:
|
secretGenerator:
|
||||||
- name: app-tls
|
- name: app-tls
|
||||||
commands:
|
commands:
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
kustomizationName: mungebot
|
|
||||||
namePrefix: baseprefix-
|
namePrefix: baseprefix-
|
||||||
# Labels to add to all objects and selectors.
|
labelsToAdd:
|
||||||
# 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
|
|
||||||
objectLabels:
|
|
||||||
foo: bar
|
foo: bar
|
||||||
objectAnnotations:
|
annotationsToAdd:
|
||||||
baseAnno: This is an base annotation
|
baseAnno: This is an base annotation
|
||||||
resources:
|
resources:
|
||||||
- deployment/deployment.yaml
|
- deployment/deployment.yaml
|
||||||
|
|||||||
@@ -18,11 +18,6 @@ package types
|
|||||||
|
|
||||||
// Kustomization holds the information needed to generate customized k8s api resources.
|
// Kustomization holds the information needed to generate customized k8s api resources.
|
||||||
type Kustomization struct {
|
type Kustomization struct {
|
||||||
// KustomizationName is a documentation field - a name for the customizations
|
|
||||||
// in a marshalled version of this struct, that survives YAML unmarshalling
|
|
||||||
// that discards comments.
|
|
||||||
KustomizationName string `json:"kustomizationName,omitempty" yaml:"kustomizationName,omitempty"`
|
|
||||||
|
|
||||||
// NamePrefix will prefix the names of all resources mentioned in the kustomization
|
// NamePrefix will prefix the names of all resources mentioned in the kustomization
|
||||||
// file including generated configmaps and secrets.
|
// file including generated configmaps and secrets.
|
||||||
NamePrefix string `json:"namePrefix,omitempty" yaml:"namePrefix,omitempty"`
|
NamePrefix string `json:"namePrefix,omitempty" yaml:"namePrefix,omitempty"`
|
||||||
@@ -31,10 +26,10 @@ 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
|
||||||
ObjectLabels map[string]string `json:"objectLabels,omitempty" yaml:"objectLabels,omitempty"`
|
LabelsToAdd map[string]string `json:"labelsToAdd,omitempty" yaml:"labelsToAdd,omitempty"`
|
||||||
|
|
||||||
// Annotations to add to all objects.
|
// Annotations to add to all objects.
|
||||||
ObjectAnnotations map[string]string `json:"objectAnnotations,omitempty" yaml:"objectAnnotations,omitempty"`
|
AnnotationsToAdd map[string]string `json:"annotationsToAdd,omitempty" yaml:"annotationsToAdd,omitempty"`
|
||||||
|
|
||||||
// Bases contain the paths to other packages that this kustomization depends on.
|
// 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
|
// Each path should be either a path to a kustomize.yaml or a path of
|
||||||
|
|||||||
Reference in New Issue
Block a user