| 1 |
// Copyright 2019 The Kubernetes Authors. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package target |
| 5 |
|
| 6 |
import ( |
| 7 |
"sigs.k8s.io/kustomize/api/resmap" |
| 8 |
) |
| 9 |
|
| 10 |
// multiTransformer contains a list of transformers. |
| 11 |
type multiTransformer struct { |
| 12 |
transformers []*resmap.TransformerWithProperties |
| 13 |
} |
| 14 |
|
| 15 |
var _ resmap.Transformer = &multiTransformer{} |
| 16 |
|
| 17 |
// newMultiTransformer constructs a multiTransformer. |
| 18 |
func newMultiTransformer(t []*resmap.TransformerWithProperties) resmap.Transformer { |
| 19 |
r := &multiTransformer{ |
| 20 |
transformers: make([]*resmap.TransformerWithProperties, len(t)), |
| 21 |
} |
| 22 |
copy(r.transformers, t) |
| 23 |
return r |
| 24 |
} |
| 25 |
|
| 26 |
// Transform applies the member transformers in order to the resources, |
| 27 |
// optionally detecting and erroring on commutation conflict. |
| 28 |
func (o *multiTransformer) Transform(m resmap.ResMap) error { |
| 29 |
for _, t := range o.transformers { |
| 30 |
if err := t.Transform(m); err != nil { |
| 31 |
return err |
| 32 |
} |
| 33 |
if t.Origin != nil { |
| 34 |
if err := m.AddTransformerAnnotation(t.Origin); err != nil { |
| 35 |
return err |
| 36 |
} |
| 37 |
} |
| 38 |
m.DropEmpties() |
| 39 |
} |
| 40 |
return nil |
| 41 |
} |