mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
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).
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
// Copyright 2020 The Kubernetes Authors.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package conflict
|
|
|
|
import (
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
sp "k8s.io/apimachinery/pkg/util/strategicpatch"
|
|
"k8s.io/client-go/kubernetes/scheme"
|
|
"sigs.k8s.io/kustomize/api/resid"
|
|
"sigs.k8s.io/kustomize/api/resource"
|
|
)
|
|
|
|
type cdFactory struct {
|
|
rf *resource.Factory
|
|
}
|
|
|
|
var _ resource.ConflictDetectorFactory = &cdFactory{}
|
|
|
|
// NewFactory returns a conflict detector factory.
|
|
// The detector uses a resource factory to convert resources to/from
|
|
// json/yaml/maps representations.
|
|
func NewFactory(rf *resource.Factory) resource.ConflictDetectorFactory {
|
|
return &cdFactory{rf: rf}
|
|
}
|
|
|
|
// New returns a conflict detector that's aware of the GVK type.
|
|
func (f *cdFactory) New(gvk resid.Gvk) (resource.ConflictDetector, error) {
|
|
// Convert to apimachinery representation of object
|
|
obj, err := scheme.Scheme.New(schema.GroupVersionKind{
|
|
Group: gvk.Group,
|
|
Version: gvk.Version,
|
|
Kind: gvk.Kind,
|
|
})
|
|
if err == nil {
|
|
meta, err := sp.NewPatchMetaFromStruct(obj)
|
|
return &conflictDetectorSm{
|
|
lookupPatchMeta: meta, resourceFactory: f.rf}, err
|
|
}
|
|
if runtime.IsNotRegisteredError(err) {
|
|
return &conflictDetectorJson{resourceFactory: f.rf}, nil
|
|
}
|
|
return nil, err
|
|
}
|