refactor the strategic merge patch transformer toward moving it to a plugin (#1340)

This commit is contained in:
Jingfang Liu
2019-07-11 10:22:56 -07:00
committed by GitHub
parent 7a48b2ba8e
commit 31ab347da2
13 changed files with 168 additions and 121 deletions

View File

@@ -14,11 +14,12 @@ import (
// Factory makes instances of ResMap.
type Factory struct {
resF *resource.Factory
tf PatchFactory
}
// NewFactory returns a new resmap.Factory.
func NewFactory(rf *resource.Factory) *Factory {
return &Factory{resF: rf}
func NewFactory(rf *resource.Factory, tf PatchFactory) *Factory {
return &Factory{resF: rf, tf: tf}
}
// RF returns a resource.Factory.
@@ -118,6 +119,11 @@ func (rmF *Factory) FromSecretArgs(
return rmF.FromResource(res), nil
}
func (rmF *Factory) MergePatches(patches []*resource.Resource) (
ResMap, error) {
return rmF.tf.MergePatches(patches, rmF.resF)
}
func newResMapFromResourceSlice(resources []*resource.Resource) (ResMap, error) {
result := New()
for _, res := range resources {

View File

@@ -0,0 +1,15 @@
/// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package patch holds miscellaneous interfaces used by kustomize.
package resmap
import (
"sigs.k8s.io/kustomize/v3/pkg/resource"
)
// PatchFactory makes transformers that require k8sdeps.
type PatchFactory interface {
MergePatches(patches []*resource.Resource,
rf *resource.Factory) (ResMap, error)
}

View File

@@ -19,7 +19,7 @@ import (
var rf = resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
var rmF = NewFactory(rf)
var rmF = NewFactory(rf, nil)
func doAppend(t *testing.T, w ResMap, r *resource.Resource) {
err := w.Append(r)