mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Move FieldSpec to API.
This commit is contained in:
@@ -1,25 +1,13 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2018 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
package types
|
||||||
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 config
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FieldSpec completely specifies a kustomizable field in
|
// FieldSpec completely specifies a kustomizable field in
|
||||||
@@ -89,22 +77,22 @@ func (fs FieldSpec) PathSlice() []string {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
type fsSlice []FieldSpec
|
type FsSlice []FieldSpec
|
||||||
|
|
||||||
func (s fsSlice) Len() int { return len(s) }
|
func (s FsSlice) Len() int { return len(s) }
|
||||||
func (s fsSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
func (s FsSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||||
func (s fsSlice) Less(i, j int) bool {
|
func (s FsSlice) Less(i, j int) bool {
|
||||||
return s[i].Gvk.IsLessThan(s[j].Gvk)
|
return s[i].Gvk.IsLessThan(s[j].Gvk)
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeAll merges the argument into this, returning the result.
|
// MergeAll merges the argument into this, returning the result.
|
||||||
// Items already present are ignored.
|
// Items already present are ignored.
|
||||||
// Items that conflict (primary key matches, but remain data differs)
|
// Items that conflict (primary key matches, but remain data differs)
|
||||||
// result in an error.
|
// result in an error.
|
||||||
func (s fsSlice) mergeAll(incoming fsSlice) (result fsSlice, err error) {
|
func (s FsSlice) MergeAll(incoming FsSlice) (result FsSlice, err error) {
|
||||||
result = s
|
result = s
|
||||||
for _, x := range incoming {
|
for _, x := range incoming {
|
||||||
result, err = result.mergeOne(x)
|
result, err = result.MergeOne(x)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -112,11 +100,11 @@ func (s fsSlice) mergeAll(incoming fsSlice) (result fsSlice, err error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeOne merges the argument into this, returning the result.
|
// MergeOne merges the argument into this, returning the result.
|
||||||
// If the item's primary key is already present, and there are no
|
// If the item's primary key is already present, and there are no
|
||||||
// conflicts, it is ignored (we don't want duplicates).
|
// conflicts, it is ignored (we don't want duplicates).
|
||||||
// If there is a conflict, the merge fails.
|
// If there is a conflict, the merge fails.
|
||||||
func (s fsSlice) mergeOne(x FieldSpec) (fsSlice, error) {
|
func (s FsSlice) MergeOne(x FieldSpec) (FsSlice, error) {
|
||||||
i := s.index(x)
|
i := s.index(x)
|
||||||
if i > -1 {
|
if i > -1 {
|
||||||
// It's already there.
|
// It's already there.
|
||||||
@@ -128,7 +116,7 @@ func (s fsSlice) mergeOne(x FieldSpec) (fsSlice, error) {
|
|||||||
return append(s, x), nil
|
return append(s, x), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s fsSlice) index(fs FieldSpec) int {
|
func (s FsSlice) index(fs FieldSpec) int {
|
||||||
for i, x := range s {
|
for i, x := range s {
|
||||||
if x.effectivelyEquals(fs) {
|
if x.effectivelyEquals(fs) {
|
||||||
return i
|
return i
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright 2019 The Kubernetes Authors.
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package config
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -38,14 +38,14 @@ func TestPathSlice(t *testing.T) {
|
|||||||
|
|
||||||
var mergeTests = []struct {
|
var mergeTests = []struct {
|
||||||
name string
|
name string
|
||||||
original fsSlice
|
original FsSlice
|
||||||
incoming fsSlice
|
incoming FsSlice
|
||||||
err error
|
err error
|
||||||
result fsSlice
|
result FsSlice
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"normal",
|
"normal",
|
||||||
fsSlice{
|
FsSlice{
|
||||||
{
|
{
|
||||||
Path: "whatever",
|
Path: "whatever",
|
||||||
Gvk: resid.Gvk{Group: "apple"},
|
Gvk: resid.Gvk{Group: "apple"},
|
||||||
@@ -57,7 +57,7 @@ var mergeTests = []struct {
|
|||||||
CreateIfNotPresent: false,
|
CreateIfNotPresent: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fsSlice{
|
FsSlice{
|
||||||
{
|
{
|
||||||
Path: "home",
|
Path: "home",
|
||||||
Gvk: resid.Gvk{Group: "beans"},
|
Gvk: resid.Gvk{Group: "beans"},
|
||||||
@@ -65,7 +65,7 @@ var mergeTests = []struct {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
fsSlice{
|
FsSlice{
|
||||||
{
|
{
|
||||||
Path: "whatever",
|
Path: "whatever",
|
||||||
Gvk: resid.Gvk{Group: "apple"},
|
Gvk: resid.Gvk{Group: "apple"},
|
||||||
@@ -85,7 +85,7 @@ var mergeTests = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ignore copy",
|
"ignore copy",
|
||||||
fsSlice{
|
FsSlice{
|
||||||
{
|
{
|
||||||
Path: "whatever",
|
Path: "whatever",
|
||||||
Gvk: resid.Gvk{Group: "apple"},
|
Gvk: resid.Gvk{Group: "apple"},
|
||||||
@@ -97,7 +97,7 @@ var mergeTests = []struct {
|
|||||||
CreateIfNotPresent: false,
|
CreateIfNotPresent: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fsSlice{
|
FsSlice{
|
||||||
{
|
{
|
||||||
Path: "whatever",
|
Path: "whatever",
|
||||||
Gvk: resid.Gvk{Group: "apple"},
|
Gvk: resid.Gvk{Group: "apple"},
|
||||||
@@ -105,7 +105,7 @@ var mergeTests = []struct {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
fsSlice{
|
FsSlice{
|
||||||
{
|
{
|
||||||
Path: "whatever",
|
Path: "whatever",
|
||||||
Gvk: resid.Gvk{Group: "apple"},
|
Gvk: resid.Gvk{Group: "apple"},
|
||||||
@@ -120,7 +120,7 @@ var mergeTests = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"error on conflict",
|
"error on conflict",
|
||||||
fsSlice{
|
FsSlice{
|
||||||
{
|
{
|
||||||
Path: "whatever",
|
Path: "whatever",
|
||||||
Gvk: resid.Gvk{Group: "apple"},
|
Gvk: resid.Gvk{Group: "apple"},
|
||||||
@@ -132,7 +132,7 @@ var mergeTests = []struct {
|
|||||||
CreateIfNotPresent: false,
|
CreateIfNotPresent: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fsSlice{
|
FsSlice{
|
||||||
{
|
{
|
||||||
Path: "whatever",
|
Path: "whatever",
|
||||||
Gvk: resid.Gvk{Group: "apple"},
|
Gvk: resid.Gvk{Group: "apple"},
|
||||||
@@ -140,13 +140,13 @@ var mergeTests = []struct {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
fmt.Errorf("hey"),
|
fmt.Errorf("hey"),
|
||||||
fsSlice{},
|
FsSlice{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFsSlice_MergeAll(t *testing.T) {
|
func TestFsSlice_MergeAll(t *testing.T) {
|
||||||
for _, item := range mergeTests {
|
for _, item := range mergeTests {
|
||||||
result, err := item.original.mergeAll(item.incoming)
|
result, err := item.original.MergeAll(item.incoming)
|
||||||
if item.err == nil {
|
if item.err == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("test %s: unexpected err %v", item.name, err)
|
t.Fatalf("test %s: unexpected err %v", item.name, err)
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
function showDeps {
|
function showDeps {
|
||||||
echo "==== $1 =================================="
|
echo "==== begin $1 =================================="
|
||||||
find $1 -name "*.go" |\
|
find $1 -name "*.go" |\
|
||||||
xargs grep sigs.k8s.io/kustomize/v3 |\
|
xargs grep \"sigs.k8s.io/kustomize/v3 |\
|
||||||
|
grep -v "/api/" |\
|
||||||
sed 's|"sigs.k8s.io/kustomize/v3/||' |\
|
sed 's|"sigs.k8s.io/kustomize/v3/||' |\
|
||||||
awk '{ printf "%40s %s\n", $2, $1 }' |\
|
awk '{ printf "%40s %s\n", $2, $1 }' |\
|
||||||
sed 's|" \./| |' |\
|
sed 's|" \./| |' |\
|
||||||
sed 's|:$||' |\
|
sed 's|:$||' |\
|
||||||
sort | uniq
|
sort | uniq
|
||||||
echo "==== $1 =================================="
|
echo "==== end $1 =================================="
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ var transformerConfigurators = map[plugins.BuiltinPluginType]func(
|
|||||||
result []resmap.Transformer, err error) {
|
result []resmap.Transformer, err error) {
|
||||||
var c struct {
|
var c struct {
|
||||||
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`
|
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`
|
||||||
FieldSpecs []config.FieldSpec
|
FieldSpecs []types.FieldSpec
|
||||||
}
|
}
|
||||||
c.Namespace = kt.kustomization.Namespace
|
c.Namespace = kt.kustomization.Namespace
|
||||||
c.FieldSpecs = tc.NameSpace
|
c.FieldSpecs = tc.NameSpace
|
||||||
@@ -208,7 +208,7 @@ var transformerConfigurators = map[plugins.BuiltinPluginType]func(
|
|||||||
result []resmap.Transformer, err error) {
|
result []resmap.Transformer, err error) {
|
||||||
var c struct {
|
var c struct {
|
||||||
Labels map[string]string
|
Labels map[string]string
|
||||||
FieldSpecs []config.FieldSpec
|
FieldSpecs []types.FieldSpec
|
||||||
}
|
}
|
||||||
c.Labels = kt.kustomization.CommonLabels
|
c.Labels = kt.kustomization.CommonLabels
|
||||||
c.FieldSpecs = tc.CommonLabels
|
c.FieldSpecs = tc.CommonLabels
|
||||||
@@ -225,7 +225,7 @@ var transformerConfigurators = map[plugins.BuiltinPluginType]func(
|
|||||||
result []resmap.Transformer, err error) {
|
result []resmap.Transformer, err error) {
|
||||||
var c struct {
|
var c struct {
|
||||||
Annotations map[string]string
|
Annotations map[string]string
|
||||||
FieldSpecs []config.FieldSpec
|
FieldSpecs []types.FieldSpec
|
||||||
}
|
}
|
||||||
c.Annotations = kt.kustomization.CommonAnnotations
|
c.Annotations = kt.kustomization.CommonAnnotations
|
||||||
c.FieldSpecs = tc.CommonAnnotations
|
c.FieldSpecs = tc.CommonAnnotations
|
||||||
@@ -243,7 +243,7 @@ var transformerConfigurators = map[plugins.BuiltinPluginType]func(
|
|||||||
var c struct {
|
var c struct {
|
||||||
Prefix string
|
Prefix string
|
||||||
Suffix string
|
Suffix string
|
||||||
FieldSpecs []config.FieldSpec
|
FieldSpecs []types.FieldSpec
|
||||||
}
|
}
|
||||||
c.Prefix = kt.kustomization.NamePrefix
|
c.Prefix = kt.kustomization.NamePrefix
|
||||||
c.Suffix = kt.kustomization.NameSuffix
|
c.Suffix = kt.kustomization.NameSuffix
|
||||||
@@ -261,7 +261,7 @@ var transformerConfigurators = map[plugins.BuiltinPluginType]func(
|
|||||||
result []resmap.Transformer, err error) {
|
result []resmap.Transformer, err error) {
|
||||||
var c struct {
|
var c struct {
|
||||||
ImageTag types.Image
|
ImageTag types.Image
|
||||||
FieldSpecs []config.FieldSpec
|
FieldSpecs []types.FieldSpec
|
||||||
}
|
}
|
||||||
for _, args := range kt.kustomization.Images {
|
for _, args := range kt.kustomization.Images {
|
||||||
c.ImageTag = args
|
c.ImageTag = args
|
||||||
@@ -280,7 +280,7 @@ var transformerConfigurators = map[plugins.BuiltinPluginType]func(
|
|||||||
result []resmap.Transformer, err error) {
|
result []resmap.Transformer, err error) {
|
||||||
var c struct {
|
var c struct {
|
||||||
Replica types.Replica
|
Replica types.Replica
|
||||||
FieldSpecs []config.FieldSpec
|
FieldSpecs []types.FieldSpec
|
||||||
}
|
}
|
||||||
for _, args := range kt.kustomization.Replicas {
|
for _, args := range kt.kustomization.Replicas {
|
||||||
c.Replica = args
|
c.Replica = args
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/v3/internal/loadertest"
|
"sigs.k8s.io/kustomize/v3/internal/loadertest"
|
||||||
@@ -29,7 +30,7 @@ namePrefix:
|
|||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
expected := &TransformerConfig{
|
expected := &TransformerConfig{
|
||||||
NamePrefix: []FieldSpec{
|
NamePrefix: []types.FieldSpec{
|
||||||
{
|
{
|
||||||
Gvk: resid.Gvk{Kind: "SomeKind"},
|
Gvk: resid.Gvk{Kind: "SomeKind"},
|
||||||
Path: "nameprefix/path",
|
Path: "nameprefix/path",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-openapi/spec"
|
"github.com/go-openapi/spec"
|
||||||
@@ -175,7 +176,7 @@ func loadCrdIntoConfig(
|
|||||||
err = theConfig.AddNamereferenceFieldSpec(
|
err = theConfig.AddNamereferenceFieldSpec(
|
||||||
NameBackReferences{
|
NameBackReferences{
|
||||||
Gvk: resid.Gvk{Kind: kind, Version: version},
|
Gvk: resid.Gvk{Kind: kind, Version: version},
|
||||||
FieldSpecs: []FieldSpec{
|
FieldSpecs: []types.FieldSpec{
|
||||||
makeFs(theGvk, append(path, propName, nameKey))},
|
makeFs(theGvk, append(path, propName, nameKey))},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -192,8 +193,8 @@ func loadCrdIntoConfig(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeFs(in resid.Gvk, path []string) FieldSpec {
|
func makeFs(in resid.Gvk, path []string) types.FieldSpec {
|
||||||
return FieldSpec{
|
return types.FieldSpec{
|
||||||
CreateIfNotPresent: false,
|
CreateIfNotPresent: false,
|
||||||
Gvk: in,
|
Gvk: in,
|
||||||
Path: strings.Join(path, "/"),
|
Path: strings.Join(path, "/"),
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/v3/internal/loadertest"
|
"sigs.k8s.io/kustomize/v3/internal/loadertest"
|
||||||
@@ -158,7 +159,7 @@ func TestLoadCRDs(t *testing.T) {
|
|||||||
nbrs := []NameBackReferences{
|
nbrs := []NameBackReferences{
|
||||||
{
|
{
|
||||||
Gvk: resid.Gvk{Kind: "Secret", Version: "v1"},
|
Gvk: resid.Gvk{Kind: "Secret", Version: "v1"},
|
||||||
FieldSpecs: []FieldSpec{
|
FieldSpecs: []types.FieldSpec{
|
||||||
{
|
{
|
||||||
CreateIfNotPresent: false,
|
CreateIfNotPresent: false,
|
||||||
Gvk: resid.Gvk{Kind: "MyKind"},
|
Gvk: resid.Gvk{Kind: "MyKind"},
|
||||||
@@ -168,7 +169,7 @@ func TestLoadCRDs(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Gvk: resid.Gvk{Kind: "Bee", Version: "v1beta1"},
|
Gvk: resid.Gvk{Kind: "Bee", Version: "v1beta1"},
|
||||||
FieldSpecs: []FieldSpec{
|
FieldSpecs: []types.FieldSpec{
|
||||||
{
|
{
|
||||||
CreateIfNotPresent: false,
|
CreateIfNotPresent: false,
|
||||||
Gvk: resid.Gvk{Kind: "MyKind"},
|
Gvk: resid.Gvk{Kind: "MyKind"},
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ import (
|
|||||||
// }
|
// }
|
||||||
type NameBackReferences struct {
|
type NameBackReferences struct {
|
||||||
resid.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
|
resid.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
|
||||||
FieldSpecs fsSlice `json:"FieldSpecs,omitempty" yaml:"FieldSpecs,omitempty"`
|
FieldSpecs types.FsSlice `json:"FieldSpecs,omitempty" yaml:"FieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n NameBackReferences) String() string {
|
func (n NameBackReferences) String() string {
|
||||||
@@ -88,7 +89,7 @@ func (s nbrSlice) mergeOne(other NameBackReferences) (nbrSlice, error) {
|
|||||||
found := false
|
found := false
|
||||||
for _, c := range s {
|
for _, c := range s {
|
||||||
if c.Gvk.Equals(other.Gvk) {
|
if c.Gvk.Equals(other.Gvk) {
|
||||||
c.FieldSpecs, err = c.FieldSpecs.mergeAll(other.FieldSpecs)
|
c.FieldSpecs, err = c.FieldSpecs.MergeAll(other.FieldSpecs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,12 @@ package config
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMergeAll(t *testing.T) {
|
func TestMergeAll(t *testing.T) {
|
||||||
fsSlice1 := []FieldSpec{
|
fsSlice1 := []types.FieldSpec{
|
||||||
{
|
{
|
||||||
Gvk: resid.Gvk{
|
Gvk: resid.Gvk{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
@@ -39,7 +40,7 @@ func TestMergeAll(t *testing.T) {
|
|||||||
CreateIfNotPresent: false,
|
CreateIfNotPresent: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
fsSlice2 := []FieldSpec{
|
fsSlice2 := []types.FieldSpec{
|
||||||
{
|
{
|
||||||
Gvk: resid.Gvk{
|
Gvk: resid.Gvk{
|
||||||
Kind: "Job",
|
Kind: "Job",
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config/defaultconfig"
|
"sigs.k8s.io/kustomize/v3/pkg/transformers/config/defaultconfig"
|
||||||
@@ -27,15 +28,15 @@ import (
|
|||||||
|
|
||||||
// TransformerConfig holds the data needed to perform transformations.
|
// TransformerConfig holds the data needed to perform transformations.
|
||||||
type TransformerConfig struct {
|
type TransformerConfig struct {
|
||||||
NamePrefix fsSlice `json:"namePrefix,omitempty" yaml:"namePrefix,omitempty"`
|
NamePrefix types.FsSlice `json:"namePrefix,omitempty" yaml:"namePrefix,omitempty"`
|
||||||
NameSuffix fsSlice `json:"nameSuffix,omitempty" yaml:"nameSuffix,omitempty"`
|
NameSuffix types.FsSlice `json:"nameSuffix,omitempty" yaml:"nameSuffix,omitempty"`
|
||||||
NameSpace fsSlice `json:"namespace,omitempty" yaml:"namespace,omitempty"`
|
NameSpace types.FsSlice `json:"namespace,omitempty" yaml:"namespace,omitempty"`
|
||||||
CommonLabels fsSlice `json:"commonLabels,omitempty" yaml:"commonLabels,omitempty"`
|
CommonLabels types.FsSlice `json:"commonLabels,omitempty" yaml:"commonLabels,omitempty"`
|
||||||
CommonAnnotations fsSlice `json:"commonAnnotations,omitempty" yaml:"commonAnnotations,omitempty"`
|
CommonAnnotations types.FsSlice `json:"commonAnnotations,omitempty" yaml:"commonAnnotations,omitempty"`
|
||||||
NameReference nbrSlice `json:"nameReference,omitempty" yaml:"nameReference,omitempty"`
|
NameReference nbrSlice `json:"nameReference,omitempty" yaml:"nameReference,omitempty"`
|
||||||
VarReference fsSlice `json:"varReference,omitempty" yaml:"varReference,omitempty"`
|
VarReference types.FsSlice `json:"varReference,omitempty" yaml:"varReference,omitempty"`
|
||||||
Images fsSlice `json:"images,omitempty" yaml:"images,omitempty"`
|
Images types.FsSlice `json:"images,omitempty" yaml:"images,omitempty"`
|
||||||
Replicas fsSlice `json:"replicas,omitempty" yaml:"replicas,omitempty"`
|
Replicas types.FsSlice `json:"replicas,omitempty" yaml:"replicas,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeEmptyConfig returns an empty TransformerConfig object
|
// MakeEmptyConfig returns an empty TransformerConfig object
|
||||||
@@ -66,26 +67,26 @@ func (t *TransformerConfig) sortFields() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddPrefixFieldSpec adds a FieldSpec to NamePrefix
|
// AddPrefixFieldSpec adds a FieldSpec to NamePrefix
|
||||||
func (t *TransformerConfig) AddPrefixFieldSpec(fs FieldSpec) (err error) {
|
func (t *TransformerConfig) AddPrefixFieldSpec(fs types.FieldSpec) (err error) {
|
||||||
t.NamePrefix, err = t.NamePrefix.mergeOne(fs)
|
t.NamePrefix, err = t.NamePrefix.MergeOne(fs)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddSuffixFieldSpec adds a FieldSpec to NameSuffix
|
// AddSuffixFieldSpec adds a FieldSpec to NameSuffix
|
||||||
func (t *TransformerConfig) AddSuffixFieldSpec(fs FieldSpec) (err error) {
|
func (t *TransformerConfig) AddSuffixFieldSpec(fs types.FieldSpec) (err error) {
|
||||||
t.NameSuffix, err = t.NameSuffix.mergeOne(fs)
|
t.NameSuffix, err = t.NameSuffix.MergeOne(fs)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddLabelFieldSpec adds a FieldSpec to CommonLabels
|
// AddLabelFieldSpec adds a FieldSpec to CommonLabels
|
||||||
func (t *TransformerConfig) AddLabelFieldSpec(fs FieldSpec) (err error) {
|
func (t *TransformerConfig) AddLabelFieldSpec(fs types.FieldSpec) (err error) {
|
||||||
t.CommonLabels, err = t.CommonLabels.mergeOne(fs)
|
t.CommonLabels, err = t.CommonLabels.MergeOne(fs)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddAnnotationFieldSpec adds a FieldSpec to CommonAnnotations
|
// AddAnnotationFieldSpec adds a FieldSpec to CommonAnnotations
|
||||||
func (t *TransformerConfig) AddAnnotationFieldSpec(fs FieldSpec) (err error) {
|
func (t *TransformerConfig) AddAnnotationFieldSpec(fs types.FieldSpec) (err error) {
|
||||||
t.CommonAnnotations, err = t.CommonAnnotations.mergeOne(fs)
|
t.CommonAnnotations, err = t.CommonAnnotations.MergeOne(fs)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,28 +105,28 @@ func (t *TransformerConfig) Merge(input *TransformerConfig) (
|
|||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
merged = &TransformerConfig{}
|
merged = &TransformerConfig{}
|
||||||
merged.NamePrefix, err = t.NamePrefix.mergeAll(input.NamePrefix)
|
merged.NamePrefix, err = t.NamePrefix.MergeAll(input.NamePrefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
merged.NameSuffix, err = t.NameSuffix.mergeAll(input.NameSuffix)
|
merged.NameSuffix, err = t.NameSuffix.MergeAll(input.NameSuffix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
merged.NameSpace, err = t.NameSpace.mergeAll(input.NameSpace)
|
merged.NameSpace, err = t.NameSpace.MergeAll(input.NameSpace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
merged.CommonAnnotations, err = t.CommonAnnotations.mergeAll(
|
merged.CommonAnnotations, err = t.CommonAnnotations.MergeAll(
|
||||||
input.CommonAnnotations)
|
input.CommonAnnotations)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
merged.CommonLabels, err = t.CommonLabels.mergeAll(input.CommonLabels)
|
merged.CommonLabels, err = t.CommonLabels.MergeAll(input.CommonLabels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
merged.VarReference, err = t.VarReference.mergeAll(input.VarReference)
|
merged.VarReference, err = t.VarReference.MergeAll(input.VarReference)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -133,11 +134,11 @@ func (t *TransformerConfig) Merge(input *TransformerConfig) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
merged.Images, err = t.Images.mergeAll(input.Images)
|
merged.Images, err = t.Images.MergeAll(input.Images)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
merged.Replicas, err = t.Replicas.mergeAll(input.Replicas)
|
merged.Replicas, err = t.Replicas.MergeAll(input.Replicas)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -30,7 +31,7 @@ func TestAddNamereferenceFieldSpec(t *testing.T) {
|
|||||||
Gvk: resid.Gvk{
|
Gvk: resid.Gvk{
|
||||||
Kind: "KindA",
|
Kind: "KindA",
|
||||||
},
|
},
|
||||||
FieldSpecs: []FieldSpec{
|
FieldSpecs: []types.FieldSpec{
|
||||||
{
|
{
|
||||||
Gvk: resid.Gvk{
|
Gvk: resid.Gvk{
|
||||||
Kind: "KindB",
|
Kind: "KindB",
|
||||||
@@ -53,7 +54,7 @@ func TestAddNamereferenceFieldSpec(t *testing.T) {
|
|||||||
func TestAddFieldSpecs(t *testing.T) {
|
func TestAddFieldSpecs(t *testing.T) {
|
||||||
cfg := &TransformerConfig{}
|
cfg := &TransformerConfig{}
|
||||||
|
|
||||||
fieldSpec := FieldSpec{
|
fieldSpec := types.FieldSpec{
|
||||||
Gvk: resid.Gvk{Group: "GroupA", Kind: "KindB"},
|
Gvk: resid.Gvk{Group: "GroupA", Kind: "KindB"},
|
||||||
Path: "path/to/a/field",
|
Path: "path/to/a/field",
|
||||||
CreateIfNotPresent: true,
|
CreateIfNotPresent: true,
|
||||||
@@ -95,7 +96,7 @@ func TestMerge(t *testing.T) {
|
|||||||
Gvk: resid.Gvk{
|
Gvk: resid.Gvk{
|
||||||
Kind: "KindA",
|
Kind: "KindA",
|
||||||
},
|
},
|
||||||
FieldSpecs: []FieldSpec{
|
FieldSpecs: []types.FieldSpec{
|
||||||
{
|
{
|
||||||
Gvk: resid.Gvk{
|
Gvk: resid.Gvk{
|
||||||
Kind: "KindB",
|
Kind: "KindB",
|
||||||
@@ -109,7 +110,7 @@ func TestMerge(t *testing.T) {
|
|||||||
Gvk: resid.Gvk{
|
Gvk: resid.Gvk{
|
||||||
Kind: "KindA",
|
Kind: "KindA",
|
||||||
},
|
},
|
||||||
FieldSpecs: []FieldSpec{
|
FieldSpecs: []types.FieldSpec{
|
||||||
{
|
{
|
||||||
Gvk: resid.Gvk{
|
Gvk: resid.Gvk{
|
||||||
Kind: "KindC",
|
Kind: "KindC",
|
||||||
@@ -120,7 +121,7 @@ func TestMerge(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
fieldSpecs := []FieldSpec{
|
fieldSpecs := []types.FieldSpec{
|
||||||
{
|
{
|
||||||
Gvk: resid.Gvk{Group: "GroupA", Kind: "KindB"},
|
Gvk: resid.Gvk{Group: "GroupA", Kind: "KindB"},
|
||||||
Path: "path/to/a/field",
|
Path: "path/to/a/field",
|
||||||
|
|||||||
@@ -19,34 +19,34 @@ package transformers
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// mapTransformer applies a string->string map to fieldSpecs.
|
// mapTransformer applies a string->string map to fieldSpecs.
|
||||||
type mapTransformer struct {
|
type mapTransformer struct {
|
||||||
m map[string]string
|
m map[string]string
|
||||||
fieldSpecs []config.FieldSpec
|
fieldSpecs []types.FieldSpec
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ resmap.Transformer = &mapTransformer{}
|
var _ resmap.Transformer = &mapTransformer{}
|
||||||
|
|
||||||
// NewLabelsMapTransformer constructs a mapTransformer.
|
// NewLabelsMapTransformer constructs a mapTransformer.
|
||||||
func NewLabelsMapTransformer(
|
func NewLabelsMapTransformer(
|
||||||
m map[string]string, fs []config.FieldSpec) (resmap.Transformer, error) {
|
m map[string]string, fs []types.FieldSpec) (resmap.Transformer, error) {
|
||||||
return NewMapTransformer(fs, m)
|
return NewMapTransformer(fs, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAnnotationsMapTransformer construct a mapTransformer.
|
// NewAnnotationsMapTransformer construct a mapTransformer.
|
||||||
func NewAnnotationsMapTransformer(
|
func NewAnnotationsMapTransformer(
|
||||||
m map[string]string, fs []config.FieldSpec) (resmap.Transformer, error) {
|
m map[string]string, fs []types.FieldSpec) (resmap.Transformer, error) {
|
||||||
return NewMapTransformer(fs, m)
|
return NewMapTransformer(fs, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMapTransformer construct a mapTransformer.
|
// NewMapTransformer construct a mapTransformer.
|
||||||
func NewMapTransformer(
|
func NewMapTransformer(
|
||||||
pc []config.FieldSpec, m map[string]string) (resmap.Transformer, error) {
|
pc []types.FieldSpec, m map[string]string) (resmap.Transformer, error) {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return NewNoOpTransformer(), nil
|
return NewNoOpTransformer(), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,16 +18,16 @@ package transformers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/expansion"
|
"sigs.k8s.io/kustomize/v3/pkg/expansion"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type RefVarTransformer struct {
|
type RefVarTransformer struct {
|
||||||
varMap map[string]interface{}
|
varMap map[string]interface{}
|
||||||
replacementCounts map[string]int
|
replacementCounts map[string]int
|
||||||
fieldSpecs []config.FieldSpec
|
fieldSpecs []types.FieldSpec
|
||||||
mappingFunc func(string) interface{}
|
mappingFunc func(string) interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ type RefVarTransformer struct {
|
|||||||
// that replaces $(VAR) style variables with values.
|
// that replaces $(VAR) style variables with values.
|
||||||
// The fieldSpecs are the places to look for occurrences of $(VAR).
|
// The fieldSpecs are the places to look for occurrences of $(VAR).
|
||||||
func NewRefVarTransformer(
|
func NewRefVarTransformer(
|
||||||
varMap map[string]interface{}, fs []config.FieldSpec) *RefVarTransformer {
|
varMap map[string]interface{}, fs []types.FieldSpec) *RefVarTransformer {
|
||||||
return &RefVarTransformer{
|
return &RefVarTransformer{
|
||||||
varMap: varMap,
|
varMap: varMap,
|
||||||
fieldSpecs: fs,
|
fieldSpecs: fs,
|
||||||
|
|||||||
@@ -6,17 +6,17 @@ package transformers
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmaptest"
|
"sigs.k8s.io/kustomize/v3/pkg/resmaptest"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVarRef(t *testing.T) {
|
func TestVarRef(t *testing.T) {
|
||||||
type given struct {
|
type given struct {
|
||||||
varMap map[string]interface{}
|
varMap map[string]interface{}
|
||||||
fs []config.FieldSpec
|
fs []types.FieldSpec
|
||||||
res resmap.ResMap
|
res resmap.ResMap
|
||||||
}
|
}
|
||||||
type expected struct {
|
type expected struct {
|
||||||
@@ -37,7 +37,7 @@ func TestVarRef(t *testing.T) {
|
|||||||
"BAZ": int64(5),
|
"BAZ": int64(5),
|
||||||
"BOO": true,
|
"BOO": true,
|
||||||
},
|
},
|
||||||
fs: []config.FieldSpec{
|
fs: []types.FieldSpec{
|
||||||
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/map"},
|
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/map"},
|
||||||
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/slice"},
|
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/slice"},
|
||||||
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/interface"},
|
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/interface"},
|
||||||
|
|||||||
@@ -2,16 +2,16 @@
|
|||||||
package builtin
|
package builtin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add the given annotations to the given field specifications.
|
// Add the given annotations to the given field specifications.
|
||||||
type AnnotationsTransformerPlugin struct {
|
type AnnotationsTransformerPlugin struct {
|
||||||
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
|
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
|
||||||
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *AnnotationsTransformerPlugin) Config(
|
func (p *AnnotationsTransformerPlugin) Config(
|
||||||
|
|||||||
@@ -9,15 +9,14 @@ import (
|
|||||||
|
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Find matching image declarations and replace
|
// Find matching image declarations and replace
|
||||||
// the name, tag and/or digest.
|
// the name, tag and/or digest.
|
||||||
type ImageTagTransformerPlugin struct {
|
type ImageTagTransformerPlugin struct {
|
||||||
ImageTag types.Image `json:"imageTag,omitempty" yaml:"imageTag,omitempty"`
|
ImageTag types.Image `json:"imageTag,omitempty" yaml:"imageTag,omitempty"`
|
||||||
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ImageTagTransformerPlugin) Config(
|
func (p *ImageTagTransformerPlugin) Config(
|
||||||
|
|||||||
@@ -2,16 +2,16 @@
|
|||||||
package builtin
|
package builtin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add the given labels to the given field specifications.
|
// Add the given labels to the given field specifications.
|
||||||
type LabelTransformerPlugin struct {
|
type LabelTransformerPlugin struct {
|
||||||
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
|
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
|
||||||
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *LabelTransformerPlugin) Config(
|
func (p *LabelTransformerPlugin) Config(
|
||||||
|
|||||||
@@ -9,14 +9,13 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Change or set the namespace of non-cluster level resources.
|
// Change or set the namespace of non-cluster level resources.
|
||||||
type NamespaceTransformerPlugin struct {
|
type NamespaceTransformerPlugin struct {
|
||||||
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
|
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
|
||||||
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NamespaceTransformerPlugin) Config(
|
func (p *NamespaceTransformerPlugin) Config(
|
||||||
@@ -62,8 +61,8 @@ const metaNamespace = "metadata/namespace"
|
|||||||
// all objects have it, even "ClusterKind" objects
|
// all objects have it, even "ClusterKind" objects
|
||||||
// that don't exist in a namespace (the Namespace
|
// that don't exist in a namespace (the Namespace
|
||||||
// object itself doesn't live in a namespace).
|
// object itself doesn't live in a namespace).
|
||||||
func (p *NamespaceTransformerPlugin) applicableFieldSpecs(id resid.ResId) []config.FieldSpec {
|
func (p *NamespaceTransformerPlugin) applicableFieldSpecs(id resid.ResId) []types.FieldSpec {
|
||||||
var res []config.FieldSpec
|
var res []types.FieldSpec
|
||||||
for _, fs := range p.FieldSpecs {
|
for _, fs := range p.FieldSpecs {
|
||||||
if id.IsSelected(&fs.Gvk) && (fs.Path != metaNamespace || (fs.Path == metaNamespace && id.IsNamespaceableKind())) {
|
if id.IsSelected(&fs.Gvk) && (fs.Path != metaNamespace || (fs.Path == metaNamespace && id.IsNamespaceableKind())) {
|
||||||
res = append(res, fs)
|
res = append(res, fs)
|
||||||
|
|||||||
@@ -4,23 +4,23 @@ package builtin
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add the given prefix and suffix to the field.
|
// Add the given prefix and suffix to the field.
|
||||||
type PrefixSuffixTransformerPlugin struct {
|
type PrefixSuffixTransformerPlugin struct {
|
||||||
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
|
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
|
||||||
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
|
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
|
||||||
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not placed in a file yet due to lack of demand.
|
// Not placed in a file yet due to lack of demand.
|
||||||
var prefixSuffixFieldSpecsToSkip = []config.FieldSpec{
|
var prefixSuffixFieldSpecsToSkip = []types.FieldSpec{
|
||||||
{
|
{
|
||||||
Gvk: resid.Gvk{Kind: "CustomResourceDefinition"},
|
Gvk: resid.Gvk{Kind: "CustomResourceDefinition"},
|
||||||
},
|
},
|
||||||
@@ -92,7 +92,7 @@ func (p *PrefixSuffixTransformerPlugin) Transform(m resmap.ResMap) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func smellsLikeANameChange(fs *config.FieldSpec) bool {
|
func smellsLikeANameChange(fs *types.FieldSpec) bool {
|
||||||
return fs.Path == "metadata/name"
|
return fs.Path == "metadata/name"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,15 +8,14 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/v3/api/types"
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Find matching replicas declarations and replace the count.
|
// Find matching replicas declarations and replace the count.
|
||||||
// Eases the kustomization configuration of replica changes.
|
// Eases the kustomization configuration of replica changes.
|
||||||
type ReplicaCountTransformerPlugin struct {
|
type ReplicaCountTransformerPlugin struct {
|
||||||
Replica types.Replica `json:"replica,omitempty" yaml:"replica,omitempty"`
|
Replica types.Replica `json:"replica,omitempty" yaml:"replica,omitempty"`
|
||||||
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ReplicaCountTransformerPlugin) Config(
|
func (p *ReplicaCountTransformerPlugin) Config(
|
||||||
|
|||||||
@@ -5,16 +5,16 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add the given annotations to the given field specifications.
|
// Add the given annotations to the given field specifications.
|
||||||
type plugin struct {
|
type plugin struct {
|
||||||
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
|
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
|
||||||
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection GoUnusedGlobalVariable
|
//noinspection GoUnusedGlobalVariable
|
||||||
|
|||||||
@@ -12,15 +12,14 @@ import (
|
|||||||
|
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Find matching image declarations and replace
|
// Find matching image declarations and replace
|
||||||
// the name, tag and/or digest.
|
// the name, tag and/or digest.
|
||||||
type plugin struct {
|
type plugin struct {
|
||||||
ImageTag types.Image `json:"imageTag,omitempty" yaml:"imageTag,omitempty"`
|
ImageTag types.Image `json:"imageTag,omitempty" yaml:"imageTag,omitempty"`
|
||||||
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection GoUnusedGlobalVariable
|
//noinspection GoUnusedGlobalVariable
|
||||||
|
|||||||
@@ -5,16 +5,16 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add the given labels to the given field specifications.
|
// Add the given labels to the given field specifications.
|
||||||
type plugin struct {
|
type plugin struct {
|
||||||
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
|
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
|
||||||
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection GoUnusedGlobalVariable
|
//noinspection GoUnusedGlobalVariable
|
||||||
|
|||||||
@@ -12,14 +12,13 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Change or set the namespace of non-cluster level resources.
|
// Change or set the namespace of non-cluster level resources.
|
||||||
type plugin struct {
|
type plugin struct {
|
||||||
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
|
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
|
||||||
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection GoUnusedGlobalVariable
|
//noinspection GoUnusedGlobalVariable
|
||||||
@@ -68,8 +67,8 @@ const metaNamespace = "metadata/namespace"
|
|||||||
// all objects have it, even "ClusterKind" objects
|
// all objects have it, even "ClusterKind" objects
|
||||||
// that don't exist in a namespace (the Namespace
|
// that don't exist in a namespace (the Namespace
|
||||||
// object itself doesn't live in a namespace).
|
// object itself doesn't live in a namespace).
|
||||||
func (p *plugin) applicableFieldSpecs(id resid.ResId) []config.FieldSpec {
|
func (p *plugin) applicableFieldSpecs(id resid.ResId) []types.FieldSpec {
|
||||||
var res []config.FieldSpec
|
var res []types.FieldSpec
|
||||||
for _, fs := range p.FieldSpecs {
|
for _, fs := range p.FieldSpecs {
|
||||||
if id.IsSelected(&fs.Gvk) && (fs.Path != metaNamespace || (fs.Path == metaNamespace && id.IsNamespaceableKind())) {
|
if id.IsSelected(&fs.Gvk) && (fs.Path != metaNamespace || (fs.Path == metaNamespace && id.IsNamespaceableKind())) {
|
||||||
res = append(res, fs)
|
res = append(res, fs)
|
||||||
|
|||||||
@@ -7,26 +7,26 @@ package main
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add the given prefix and suffix to the field.
|
// Add the given prefix and suffix to the field.
|
||||||
type plugin struct {
|
type plugin struct {
|
||||||
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
|
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
|
||||||
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
|
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
|
||||||
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection GoUnusedGlobalVariable
|
//noinspection GoUnusedGlobalVariable
|
||||||
var KustomizePlugin plugin
|
var KustomizePlugin plugin
|
||||||
|
|
||||||
// Not placed in a file yet due to lack of demand.
|
// Not placed in a file yet due to lack of demand.
|
||||||
var prefixSuffixFieldSpecsToSkip = []config.FieldSpec{
|
var prefixSuffixFieldSpecsToSkip = []types.FieldSpec{
|
||||||
{
|
{
|
||||||
Gvk: resid.Gvk{Kind: "CustomResourceDefinition"},
|
Gvk: resid.Gvk{Kind: "CustomResourceDefinition"},
|
||||||
},
|
},
|
||||||
@@ -98,7 +98,7 @@ func (p *plugin) Transform(m resmap.ResMap) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func smellsLikeANameChange(fs *config.FieldSpec) bool {
|
func smellsLikeANameChange(fs *types.FieldSpec) bool {
|
||||||
return fs.Path == "metadata/name"
|
return fs.Path == "metadata/name"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,15 +11,14 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/v3/api/types"
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Find matching replicas declarations and replace the count.
|
// Find matching replicas declarations and replace the count.
|
||||||
// Eases the kustomization configuration of replica changes.
|
// Eases the kustomization configuration of replica changes.
|
||||||
type plugin struct {
|
type plugin struct {
|
||||||
Replica types.Replica `json:"replica,omitempty" yaml:"replica,omitempty"`
|
Replica types.Replica `json:"replica,omitempty" yaml:"replica,omitempty"`
|
||||||
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection GoUnusedGlobalVariable
|
//noinspection GoUnusedGlobalVariable
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ etc.
|
|||||||
Generated plugins are used in kustomize via
|
Generated plugins are used in kustomize via
|
||||||
|
|
||||||
package whatever
|
package whatever
|
||||||
import "sigs.k8s.io/kustomize/v3/plugin/builtin
|
import sigs.k8s.io/kustomize/v3/plugin/builtin
|
||||||
...
|
...
|
||||||
g := builtin.NewSecretGenerator()
|
g := builtin.NewSecretGenerator()
|
||||||
g.Config(h, k)
|
g.Config(h, k)
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
"sigs.k8s.io/kustomize/v3/plugin/builtin"
|
"sigs.k8s.io/kustomize/v3/plugin/builtin"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
@@ -25,10 +25,10 @@ func (p *plugin) makePrefixSuffixPluginConfig() ([]byte, error) {
|
|||||||
var s struct {
|
var s struct {
|
||||||
Prefix string
|
Prefix string
|
||||||
Suffix string
|
Suffix string
|
||||||
FieldSpecs []config.FieldSpec
|
FieldSpecs []types.FieldSpec
|
||||||
}
|
}
|
||||||
s.Prefix = getDate() + "-"
|
s.Prefix = getDate() + "-"
|
||||||
s.FieldSpecs = []config.FieldSpec{
|
s.FieldSpecs = []types.FieldSpec{
|
||||||
{Path: "metadata/name"},
|
{Path: "metadata/name"},
|
||||||
}
|
}
|
||||||
return yaml.Marshal(s)
|
return yaml.Marshal(s)
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"sigs.k8s.io/kustomize/v3/api/types"
|
"sigs.k8s.io/kustomize/v3/api/types"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
||||||
"sigs.k8s.io/kustomize/v3/plugin/builtin"
|
"sigs.k8s.io/kustomize/v3/plugin/builtin"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
@@ -27,10 +26,10 @@ func (p *plugin) makePrefixSuffixPluginConfig(n string) ([]byte, error) {
|
|||||||
var s struct {
|
var s struct {
|
||||||
Prefix string
|
Prefix string
|
||||||
Suffix string
|
Suffix string
|
||||||
FieldSpecs []config.FieldSpec
|
FieldSpecs []types.FieldSpec
|
||||||
}
|
}
|
||||||
s.Prefix = n + "-"
|
s.Prefix = n + "-"
|
||||||
s.FieldSpecs = []config.FieldSpec{
|
s.FieldSpecs = []types.FieldSpec{
|
||||||
{Path: "metadata/name"},
|
{Path: "metadata/name"},
|
||||||
}
|
}
|
||||||
return yaml.Marshal(s)
|
return yaml.Marshal(s)
|
||||||
|
|||||||
Reference in New Issue
Block a user