mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-17 01:39:06 +00:00
Extract conflict detection to it's own interface.
This PR - defines a patch conflict detector interface, - extracts implementations of the interface from the merginator code, making the merginator code independent of --enable_kyaml. - injects those implementations into kustomize as a function of --enable_kyaml. So, instead of using different merginators to combine resmaps, this pr allows the use of a single patch merge code path that uses different conflict detectors. So instead of debating how to merge, we're now only considering whether to warn on conflict detection in one transformer. This PR is in service of #3304, eliminating seven instances where --enable_kyaml was consulted. These were cases where conflict detection wasn't an issue (but merging patches was).
This commit is contained in:
@@ -12,24 +12,18 @@ import (
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
// Merginator merges resources.
|
||||
type Merginator interface {
|
||||
// Merge creates a new ResMap by merging incoming resources.
|
||||
// Error if conflict found.
|
||||
Merge([]*resource.Resource) (ResMap, error)
|
||||
}
|
||||
|
||||
// Factory makes instances of ResMap.
|
||||
type Factory struct {
|
||||
// Makes resources.
|
||||
resF *resource.Factory
|
||||
// Makes ResMaps via merging.
|
||||
pm Merginator
|
||||
// Makes ConflictDetectors.
|
||||
cdf resource.ConflictDetectorFactory
|
||||
}
|
||||
|
||||
// NewFactory returns a new resmap.Factory.
|
||||
func NewFactory(rf *resource.Factory, pm Merginator) *Factory {
|
||||
return &Factory{resF: rf, pm: pm}
|
||||
func NewFactory(
|
||||
rf *resource.Factory, cdf resource.ConflictDetectorFactory) *Factory {
|
||||
return &Factory{resF: rf, cdf: cdf}
|
||||
}
|
||||
|
||||
// RF returns a resource.Factory.
|
||||
@@ -134,8 +128,8 @@ func (rmF *Factory) FromSecretArgs(
|
||||
|
||||
// Merge creates a new ResMap by merging incoming resources.
|
||||
// Error if conflict found.
|
||||
func (rmF *Factory) Merge(patches []*resource.Resource) (ResMap, error) {
|
||||
return rmF.pm.Merge(patches)
|
||||
func (rmF *Factory) Merge(incoming []*resource.Resource) (ResMap, error) {
|
||||
return (&merginator{cdf: rmF.cdf}).Merge(incoming)
|
||||
}
|
||||
|
||||
func newResMapFromResourceSlice(
|
||||
|
||||
Reference in New Issue
Block a user