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.

3 changes: 3 additions & 0 deletions kustomize/commands/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func (o *Options) Validate(_ []string) error {
return fmt.Errorf("--short and --output are mutually exclusive")
}
}
if o.Output != "" && o.Output != "yaml" && o.Output != "json" {
return fmt.Errorf("--output must be 'yaml' or 'json'")
}
return nil
}

Expand Down
33 changes: 33 additions & 0 deletions kustomize/commands/version/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2026 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0

package version

import (
"bytes"
"testing"
)

func TestVersionInvalidOutput(t *testing.T) {
var buf bytes.Buffer
cmd := NewCmdVersion(&buf)
cmd.SetArgs([]string{"--output", "yml"})
err := cmd.Execute()
if err == nil {
t.Fatalf("expected error for invalid output format, got nil")
}
expectedErr := "--output must be 'yaml' or 'json'"
if err.Error() != expectedErr {
t.Errorf("expected error %q, got %q", expectedErr, err.Error())
}
}

func TestVersionValidOutput(t *testing.T) {
var buf bytes.Buffer
cmd := NewCmdVersion(&buf)
cmd.SetArgs([]string{"--output", "yaml"})
err := cmd.Execute()
if err != nil {
t.Fatalf("unexpected error for valid output format: %v", err)
}
}
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