mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Idiom fixes.
- func/struct names prefixed with package name - public funcs/structs that should be private
This commit is contained in:
@@ -26,12 +26,12 @@ func NewFactoryImpl() *FactoryImpl {
|
|||||||
func (p *FactoryImpl) MakePatchTransformer(
|
func (p *FactoryImpl) MakePatchTransformer(
|
||||||
slice []*resource.Resource,
|
slice []*resource.Resource,
|
||||||
rf *resource.Factory) (transformers.Transformer, error) {
|
rf *resource.Factory) (transformers.Transformer, error) {
|
||||||
return patch.NewPatchTransformer(slice, rf)
|
return patch.NewTransformer(slice, rf)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeHashTransformer makes a new name hash transformer
|
// MakeHashTransformer makes a new name hash transformer
|
||||||
func (p *FactoryImpl) MakeHashTransformer() transformers.Transformer {
|
func (p *FactoryImpl) MakeHashTransformer() transformers.Transformer {
|
||||||
return hash.NewNameHashTransformer()
|
return hash.NewTransformer()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *FactoryImpl) MakeInventoryTransformer(
|
func (p *FactoryImpl) MakeInventoryTransformer(
|
||||||
@@ -39,5 +39,5 @@ func (p *FactoryImpl) MakeInventoryTransformer(
|
|||||||
ldr ifc.Loader,
|
ldr ifc.Loader,
|
||||||
namespace string,
|
namespace string,
|
||||||
gp types.GarbagePolicy) transformers.Transformer {
|
gp types.GarbagePolicy) transformers.Transformer {
|
||||||
return inventory.NewInventoryTransformer(arg, ldr, namespace, gp)
|
return inventory.NewTransformer(arg, ldr, namespace, gp)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2017 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
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 hash
|
package hash
|
||||||
|
|
||||||
@@ -26,16 +13,16 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KustHash compute hash for unstructured objects
|
// kustHash computes a hash of an unstructured object.
|
||||||
type KustHash struct{}
|
type kustHash struct{}
|
||||||
|
|
||||||
// NewKustHash returns a KustHash object
|
// NewKustHash returns a kustHash object
|
||||||
func NewKustHash() *KustHash {
|
func NewKustHash() *kustHash {
|
||||||
return &KustHash{}
|
return &kustHash{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash returns a hash of either a ConfigMap or a Secret
|
// Hash returns a hash of either a ConfigMap or a Secret
|
||||||
func (h *KustHash) Hash(m map[string]interface{}) (string, error) {
|
func (h *kustHash) Hash(m map[string]interface{}) (string, error) {
|
||||||
u := unstructured.Unstructured{
|
u := unstructured.Unstructured{
|
||||||
Object: m,
|
Object: m,
|
||||||
}
|
}
|
||||||
@@ -46,22 +33,23 @@ func (h *KustHash) Hash(m map[string]interface{}) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return ConfigMapHash(cm)
|
return configMapHash(cm)
|
||||||
case "Secret":
|
case "Secret":
|
||||||
sec, err := unstructuredToSecret(u)
|
sec, err := unstructuredToSecret(u)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return SecretHash(sec)
|
return secretHash(sec)
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("type %s is supported for hashing in %v", kind, m)
|
return "", fmt.Errorf(
|
||||||
|
"type %s is not supported for hashing in %v", kind, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigMapHash returns a hash of the ConfigMap.
|
// configMapHash returns a hash of the ConfigMap.
|
||||||
// The Data, Kind, and Name are taken into account.
|
// The Data, Kind, and Name are taken into account.
|
||||||
func ConfigMapHash(cm *v1.ConfigMap) (string, error) {
|
func configMapHash(cm *v1.ConfigMap) (string, error) {
|
||||||
encoded, err := encodeConfigMap(cm)
|
encoded, err := encodeConfigMap(cm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -75,7 +63,7 @@ func ConfigMapHash(cm *v1.ConfigMap) (string, error) {
|
|||||||
|
|
||||||
// SecretHash returns a hash of the Secret.
|
// SecretHash returns a hash of the Secret.
|
||||||
// The Data, Kind, Name, and Type are taken into account.
|
// The Data, Kind, Name, and Type are taken into account.
|
||||||
func SecretHash(sec *v1.Secret) (string, error) {
|
func secretHash(sec *v1.Secret) (string, error) {
|
||||||
encoded, err := encodeSecret(sec)
|
encoded, err := encodeSecret(sec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -54,7 +54,7 @@ func TestConfigMapHash(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
h, err := ConfigMapHash(c.cm)
|
h, err := configMapHash(c.cm)
|
||||||
if SkipRest(t, c.desc, err, c.err) {
|
if SkipRest(t, c.desc, err, c.err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -80,7 +80,7 @@ func TestSecretHash(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
h, err := SecretHash(c.secret)
|
h, err := secretHash(c.secret)
|
||||||
if SkipRest(t, c.desc, err, c.err) {
|
if SkipRest(t, c.desc, err, c.err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2018 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package hash
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
|
||||||
"sigs.k8s.io/kustomize/pkg/transformers"
|
|
||||||
)
|
|
||||||
|
|
||||||
type nameHashTransformer struct{}
|
|
||||||
|
|
||||||
var _ transformers.Transformer = &nameHashTransformer{}
|
|
||||||
|
|
||||||
// NewNameHashTransformer construct a nameHashTransformer.
|
|
||||||
func NewNameHashTransformer() transformers.Transformer {
|
|
||||||
return &nameHashTransformer{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Transform appends hash to generated resources.
|
|
||||||
func (o *nameHashTransformer) Transform(m resmap.ResMap) error {
|
|
||||||
for _, res := range m {
|
|
||||||
if res.NeedHashSuffix() {
|
|
||||||
h, err := NewKustHash().Hash(res.Map())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
res.SetName(fmt.Sprintf("%s-%s", res.GetName(), h))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
34
k8sdeps/transformer/hash/transformer.go
Normal file
34
k8sdeps/transformer/hash/transformer.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package hash
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||||
|
"sigs.k8s.io/kustomize/pkg/transformers"
|
||||||
|
)
|
||||||
|
|
||||||
|
type transformer struct{}
|
||||||
|
|
||||||
|
var _ transformers.Transformer = &transformer{}
|
||||||
|
|
||||||
|
// NewTransformer make a hash transformer.
|
||||||
|
func NewTransformer() transformers.Transformer {
|
||||||
|
return &transformer{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transform appends hash to generated resources.
|
||||||
|
func (tf *transformer) Transform(m resmap.ResMap) error {
|
||||||
|
for _, res := range m {
|
||||||
|
if res.NeedHashSuffix() {
|
||||||
|
h, err := NewKustHash().Hash(res.Map())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
res.SetName(fmt.Sprintf("%s-%s", res.GetName(), h))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// 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");
|
|
||||||
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 hash
|
package hash
|
||||||
|
|
||||||
@@ -152,7 +139,7 @@ func TestNameHashTransformer(t *testing.T) {
|
|||||||
}, &types.GeneratorArgs{Behavior: "create"}, &types.GeneratorOptions{DisableNameSuffixHash: false}),
|
}, &types.GeneratorArgs{Behavior: "create"}, &types.GeneratorOptions{DisableNameSuffixHash: false}),
|
||||||
}
|
}
|
||||||
|
|
||||||
tran := NewNameHashTransformer()
|
tran := NewTransformer()
|
||||||
tran.Transform(objs)
|
tran.Transform(objs)
|
||||||
|
|
||||||
if !reflect.DeepEqual(objs, expected) {
|
if !reflect.DeepEqual(objs, expected) {
|
||||||
@@ -17,18 +17,18 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/pkg/types"
|
"sigs.k8s.io/kustomize/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// inventoryTransformer compute the inventory object used in prune
|
// transformer compute the inventory object used in prune
|
||||||
type inventoryTransformer struct {
|
type transformer struct {
|
||||||
garbagePolicy types.GarbagePolicy
|
garbagePolicy types.GarbagePolicy
|
||||||
ldr ifc.Loader
|
ldr ifc.Loader
|
||||||
cmName string
|
cmName string
|
||||||
cmNamespace string
|
cmNamespace string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ transformers.Transformer = &inventoryTransformer{}
|
var _ transformers.Transformer = &transformer{}
|
||||||
|
|
||||||
// NewInventoryTransformer makes a inventoryTransformer.
|
// NewTransformer makes a new inventory transformer.
|
||||||
func NewInventoryTransformer(
|
func NewTransformer(
|
||||||
p *types.Inventory,
|
p *types.Inventory,
|
||||||
ldr ifc.Loader,
|
ldr ifc.Loader,
|
||||||
namespace string,
|
namespace string,
|
||||||
@@ -36,7 +36,7 @@ func NewInventoryTransformer(
|
|||||||
if p == nil || p.Type != "ConfigMap" || p.ConfigMap.Namespace != namespace {
|
if p == nil || p.Type != "ConfigMap" || p.ConfigMap.Namespace != namespace {
|
||||||
return transformers.NewNoOpTransformer()
|
return transformers.NewNoOpTransformer()
|
||||||
}
|
}
|
||||||
return &inventoryTransformer{
|
return &transformer{
|
||||||
garbagePolicy: gp,
|
garbagePolicy: gp,
|
||||||
ldr: ldr,
|
ldr: ldr,
|
||||||
cmName: p.ConfigMap.Name,
|
cmName: p.ConfigMap.Name,
|
||||||
@@ -52,7 +52,7 @@ func NewInventoryTransformer(
|
|||||||
// The inventory data is written to annotation since
|
// The inventory data is written to annotation since
|
||||||
// 1. The key in data field is constrained and couldn't include arbitrary letters
|
// 1. The key in data field is constrained and couldn't include arbitrary letters
|
||||||
// 2. The annotation can be put into any kind of objects
|
// 2. The annotation can be put into any kind of objects
|
||||||
func (o *inventoryTransformer) Transform(m resmap.ResMap) error {
|
func (tf *transformer) Transform(m resmap.ResMap) error {
|
||||||
invty := inventory.NewInventory()
|
invty := inventory.NewInventory()
|
||||||
var keys []string
|
var keys []string
|
||||||
for _, r := range m {
|
for _, r := range m {
|
||||||
@@ -74,8 +74,8 @@ func (o *inventoryTransformer) Transform(m resmap.ResMap) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args := &types.ConfigMapArgs{}
|
args := &types.ConfigMapArgs{}
|
||||||
args.Name = o.cmName
|
args.Name = tf.cmName
|
||||||
args.Namespace = o.cmNamespace
|
args.Namespace = tf.cmNamespace
|
||||||
opts := &types.GeneratorOptions{
|
opts := &types.GeneratorOptions{
|
||||||
Annotations: make(map[string]string),
|
Annotations: make(map[string]string),
|
||||||
}
|
}
|
||||||
@@ -86,12 +86,12 @@ func (o *inventoryTransformer) Transform(m resmap.ResMap) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kf := kunstruct.NewKunstructuredFactoryImpl()
|
kf := kunstruct.NewKunstructuredFactoryImpl()
|
||||||
k, err := kf.MakeConfigMap(o.ldr, opts, args)
|
k, err := kf.MakeConfigMap(tf.ldr, opts, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if o.garbagePolicy == types.GarbageCollect {
|
if tf.garbagePolicy == types.GarbageCollect {
|
||||||
for k := range m {
|
for k := range m {
|
||||||
delete(m, k)
|
delete(m, k)
|
||||||
}
|
}
|
||||||
@@ -102,8 +102,8 @@ func (o *inventoryTransformer) Transform(m resmap.ResMap) error {
|
|||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "ConfigMap",
|
Kind: "ConfigMap",
|
||||||
},
|
},
|
||||||
o.cmName,
|
tf.cmName,
|
||||||
"", o.cmNamespace)
|
"", tf.cmNamespace)
|
||||||
if _, ok := m[id]; ok {
|
if _, ok := m[id]; ok {
|
||||||
return fmt.Errorf("id %v is already used, please use a different name in the prune field", id)
|
return fmt.Errorf("id %v is already used, please use a different name in the prune field", id)
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ func TestInventoryTransformer(t *testing.T) {
|
|||||||
objs := makeResMap()
|
objs := makeResMap()
|
||||||
|
|
||||||
// include the original resmap; only return the ConfigMap for pruning
|
// include the original resmap; only return the ConfigMap for pruning
|
||||||
tran := NewInventoryTransformer(p, ldr, "default", types.GarbageCollect)
|
tran := NewTransformer(p, ldr, "default", types.GarbageCollect)
|
||||||
tran.Transform(objs)
|
tran.Transform(objs)
|
||||||
|
|
||||||
if !reflect.DeepEqual(objs, expected) {
|
if !reflect.DeepEqual(objs, expected) {
|
||||||
@@ -151,7 +151,7 @@ func TestInventoryTransformer(t *testing.T) {
|
|||||||
expected = objs.DeepCopy(rf)
|
expected = objs.DeepCopy(rf)
|
||||||
expected[resid.NewResIdWithPrefixNamespace(cmap, "pruneCM", "", "default")] = pruneMap
|
expected[resid.NewResIdWithPrefixNamespace(cmap, "pruneCM", "", "default")] = pruneMap
|
||||||
// append the ConfigMap for pruning to the original resmap
|
// append the ConfigMap for pruning to the original resmap
|
||||||
tran = NewInventoryTransformer(p, ldr, "default", types.GarbageIgnore)
|
tran = NewTransformer(p, ldr, "default", types.GarbageIgnore)
|
||||||
tran.Transform(objs)
|
tran.Transform(objs)
|
||||||
|
|
||||||
if !reflect.DeepEqual(objs, expected) {
|
if !reflect.DeepEqual(objs, expected) {
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// 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");
|
|
||||||
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 patch
|
package patch
|
||||||
|
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// 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");
|
|
||||||
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 patch
|
package patch
|
||||||
|
|
||||||
@@ -31,27 +18,27 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/pkg/transformers"
|
"sigs.k8s.io/kustomize/pkg/transformers"
|
||||||
)
|
)
|
||||||
|
|
||||||
// patchTransformer applies patches.
|
// transformer applies strategic merge patches.
|
||||||
type patchTransformer struct {
|
type transformer struct {
|
||||||
patches []*resource.Resource
|
patches []*resource.Resource
|
||||||
rf *resource.Factory
|
rf *resource.Factory
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ transformers.Transformer = &patchTransformer{}
|
var _ transformers.Transformer = &transformer{}
|
||||||
|
|
||||||
// NewPatchTransformer constructs a patchTransformer.
|
// NewTransformer constructs a strategic merge patch transformer.
|
||||||
func NewPatchTransformer(
|
func NewTransformer(
|
||||||
slice []*resource.Resource, rf *resource.Factory) (transformers.Transformer, error) {
|
slice []*resource.Resource, rf *resource.Factory) (transformers.Transformer, error) {
|
||||||
if len(slice) == 0 {
|
if len(slice) == 0 {
|
||||||
return transformers.NewNoOpTransformer(), nil
|
return transformers.NewNoOpTransformer(), nil
|
||||||
}
|
}
|
||||||
return &patchTransformer{patches: slice, rf: rf}, nil
|
return &transformer{patches: slice, rf: rf}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform apply the patches on top of the base resources.
|
// Transform apply the patches on top of the base resources.
|
||||||
func (pt *patchTransformer) Transform(baseResourceMap resmap.ResMap) error {
|
func (tf *transformer) Transform(baseResourceMap resmap.ResMap) error {
|
||||||
// Merge and then index the patches by Id.
|
// Merge and then index the patches by Id.
|
||||||
patches, err := pt.mergePatches()
|
patches, err := tf.mergePatches()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -118,9 +105,9 @@ func (pt *patchTransformer) Transform(baseResourceMap resmap.ResMap) error {
|
|||||||
|
|
||||||
// mergePatches merge and index patches by Id.
|
// mergePatches merge and index patches by Id.
|
||||||
// It errors out if there is conflict between patches.
|
// It errors out if there is conflict between patches.
|
||||||
func (pt *patchTransformer) mergePatches() (resmap.ResMap, error) {
|
func (tf *transformer) mergePatches() (resmap.ResMap, error) {
|
||||||
rc := resmap.ResMap{}
|
rc := resmap.ResMap{}
|
||||||
for ix, patch := range pt.patches {
|
for ix, patch := range tf.patches {
|
||||||
id := patch.Id()
|
id := patch.Id()
|
||||||
existing, found := rc[id]
|
existing, found := rc[id]
|
||||||
if !found {
|
if !found {
|
||||||
@@ -134,9 +121,9 @@ func (pt *patchTransformer) mergePatches() (resmap.ResMap, error) {
|
|||||||
}
|
}
|
||||||
var cd conflictDetector
|
var cd conflictDetector
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cd = newJMPConflictDetector(pt.rf)
|
cd = newJMPConflictDetector(tf.rf)
|
||||||
} else {
|
} else {
|
||||||
cd, err = newSMPConflictDetector(versionedObj, pt.rf)
|
cd, err = newSMPConflictDetector(versionedObj, tf.rf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -147,7 +134,7 @@ func (pt *patchTransformer) mergePatches() (resmap.ResMap, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if conflict {
|
if conflict {
|
||||||
conflictingPatch, err := cd.findConflict(ix, pt.patches)
|
conflictingPatch, err := cd.findConflict(ix, tf.patches)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// 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");
|
|
||||||
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 patch
|
package patch
|
||||||
|
|
||||||
@@ -128,7 +115,7 @@ func TestOverlayRun(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
lt, err := NewPatchTransformer(patch, rf)
|
lt, err := NewTransformer(patch, rf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -258,7 +245,7 @@ func TestMultiplePatches(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
lt, err := NewPatchTransformer(patch, rf)
|
lt, err := NewTransformer(patch, rf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -344,7 +331,7 @@ func TestMultiplePatchesWithConflict(t *testing.T) {
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
lt, err := NewPatchTransformer(patch, rf)
|
lt, err := NewTransformer(patch, rf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -407,7 +394,7 @@ func TestNoSchemaOverlayRun(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
lt, err := NewPatchTransformer(patch, rf)
|
lt, err := NewTransformer(patch, rf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -491,7 +478,7 @@ func TestNoSchemaMultiplePatches(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
lt, err := NewPatchTransformer(patch, rf)
|
lt, err := NewTransformer(patch, rf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -549,7 +536,7 @@ func TestNoSchemaMultiplePatchesWithConflict(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
lt, err := NewPatchTransformer(patch, rf)
|
lt, err := NewTransformer(patch, rf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user