Skip to content

Commit

Permalink
fix comments and variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
koba1t committed Jul 3, 2023
1 parent a761588 commit 549935d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
30 changes: 15 additions & 15 deletions api/internal/builtins/PatchTransformer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions plugin/builtin/patchtransformer/PatchTransformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
)

type plugin struct {
loadedPatches []*resource.Resource
decodedPatch jsonpatch.Patch
Path string `json:"path,omitempty" yaml:"path,omitempty"`
Patch string `json:"patch,omitempty" yaml:"patch,omitempty"`
Target *types.Selector `json:"target,omitempty" yaml:"target,omitempty"`
Options map[string]bool `json:"options,omitempty" yaml:"options,omitempty"`
smPatches []*resource.Resource // strategic-merge patches
jsonPatch jsonpatch.Patch // json6902 patch
Path string `json:"path,omitempty" yaml:"path,omitempty"`
Patch string `json:"patch,omitempty" yaml:"patch,omitempty"`
Target *types.Selector `json:"target,omitempty" yaml:"target,omitempty"`
Options map[string]bool `json:"options,omitempty" yaml:"options,omitempty"`
}

var KustomizePlugin plugin //nolint:gochecknoglobals
Expand Down Expand Up @@ -64,8 +64,8 @@ func (p *plugin) Config(
"unable to parse SM or JSON patch from [%v]", p.Patch)
}
if errSM == nil {
p.loadedPatches = patchesSM
for _, loadedPatch := range p.loadedPatches {
p.smPatches = patchesSM
for _, loadedPatch := range p.smPatches {
if p.Options["allowNameChange"] {
loadedPatch.AllowNameChange()
}
Expand All @@ -74,24 +74,24 @@ func (p *plugin) Config(
}
}
} else {
p.decodedPatch = patchJson
p.jsonPatch = patchJson
}
return nil
}

func (p *plugin) Transform(m resmap.ResMap) error {
if p.loadedPatches == nil {
return p.transformJson6902(m, p.decodedPatch)
if p.smPatches == nil {
return p.transformJson6902(m, p.jsonPatch)
}
// The patch was a strategic merge patch
return p.transformStrategicMerge(m)
}

// transformStrategicMerge applies the provided strategic merge patch
// to all the resources in the ResMap that match either the Target or
// the identifier of the patch.
// transformStrategicMerge applies each loaded strategic merge patch
// to the resource in the ResMap that matches the identifier of the patch.
// If only one patch is specified, the Target can be used instead.
func (p *plugin) transformStrategicMerge(m resmap.ResMap) error {
for _, patch := range p.loadedPatches {
for _, patch := range p.smPatches {
if p.Target == nil {
target, err := m.GetById(patch.OrgId())
if err != nil {
Expand Down

0 comments on commit 549935d

Please sign in to comment.