Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions api/internal/builtins/PrefixTransformer.go

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

17 changes: 15 additions & 2 deletions api/internal/builtins/SuffixTransformer.go

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

17 changes: 15 additions & 2 deletions plugin/builtin/prefixtransformer/PrefixTransformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import (
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/resid"
"sigs.k8s.io/kustomize/kyaml/yaml"
"k8s.io/apimachinery/pkg/labels"
)

// Add the given prefix to the field
type plugin struct {
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
FieldSpecs types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
ExcludeLabelSelector string `json:"excludeLabelSelector,omitempty" yaml:"excludeLabelSelector,omitempty"`
FieldSpecs types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}

var KustomizePlugin plugin //nolint:gochecknoglobals
Expand All @@ -44,6 +46,14 @@ func (p *plugin) Config(
}

func (p *plugin) Transform(m resmap.ResMap) error {
var selector labels.Selector
if p.ExcludeLabelSelector != "" {
var err error
selector, err = labels.Parse(p.ExcludeLabelSelector)
if err != nil {
return err
}
}
// Even if the Prefix is empty we want to proceed with the
// transformation. This allows to add contextual information
// to the resources (AddNamePrefix).
Expand All @@ -52,6 +62,9 @@ func (p *plugin) Transform(m resmap.ResMap) error {
if p.shouldSkip(r.OrgId()) {
continue
}
if selector != nil && selector.Matches(labels.Set(r.GetLabels())) {
continue
}
id := r.OrgId()
// current default configuration contains
// only one entry: "metadata/name" with no GVK
Expand Down
17 changes: 15 additions & 2 deletions plugin/builtin/suffixtransformer/SuffixTransformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import (
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/resid"
"sigs.k8s.io/kustomize/kyaml/yaml"
"k8s.io/apimachinery/pkg/labels"
)

// Add the given suffix to the field
type plugin struct {
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
FieldSpecs types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
ExcludeLabelSelector string `json:"excludeLabelSelector,omitempty" yaml:"excludeLabelSelector,omitempty"`
FieldSpecs types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}

var KustomizePlugin plugin //nolint:gochecknoglobals
Expand All @@ -44,6 +46,14 @@ func (p *plugin) Config(
}

func (p *plugin) Transform(m resmap.ResMap) error {
var selector labels.Selector
if p.ExcludeLabelSelector != "" {
var err error
selector, err = labels.Parse(p.ExcludeLabelSelector)
if err != nil {
return err
}
}
// Even if the Suffix is empty we want to proceed with the
// transformation. This allows to add contextual information
// to the resources (AddNameSuffix).
Expand All @@ -52,6 +62,9 @@ func (p *plugin) Transform(m resmap.ResMap) error {
if p.shouldSkip(r.OrgId()) {
continue
}
if selector != nil && selector.Matches(labels.Set(r.GetLabels())) {
continue
}
id := r.OrgId()
// current default configuration contains
// only one entry: "metadata/name" with no GVK
Expand Down