Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(cmd): add local-config annotation on create #5798

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions api/konfig/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

package konfig

import (
"sigs.k8s.io/kustomize/api/types"
)

// RecognizedKustomizationFileNames is a list of file names
// that kustomize recognizes.
// To avoid ambiguity, a kustomization directory may not
Expand All @@ -19,6 +23,18 @@ func DefaultKustomizationFileName() string {
return RecognizedKustomizationFileNames()[0]
}

// DefaultKustomizationMetadata returns the default metadata
// for a kustomization configuration.
func DefaultKustomizationMetadata() *types.ObjectMeta {
defaultMetadata := &types.ObjectMeta{
Annotations: map[string]string{
IgnoredByKustomizeAnnotation: "true",
},
}

return defaultMetadata
}

const (
// An environment variable to consult for kustomization
// configuration data. See:
Expand Down
1 change: 1 addition & 0 deletions kustomize/commands/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func runCreate(opts createFlags, fSys filesys.FileSystem, rf *resource.Factory)
if err != nil {
return err
}
m.MetaData = konfig.DefaultKustomizationMetadata()
m.Resources = resources
m.Namespace = opts.namespace
m.NamePrefix = opts.prefix
Expand Down
16 changes: 16 additions & 0 deletions kustomize/commands/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sigs.k8s.io/kustomize/api/konfig"
"sigs.k8s.io/kustomize/api/provider"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile"
Expand Down Expand Up @@ -134,6 +135,21 @@ func TestCreateWithNameSuffix(t *testing.T) {
}
}

func TestCreateHasDefaultMetadata(t *testing.T) {
fSys := filesys.MakeEmptyDirInMemory()
fSys.WriteFile("foo.yaml", []byte(""))
fSys.WriteFile("bar.yaml", []byte(""))
opts := createFlags{resources: "foo.yaml,bar.yaml"}
err := runCreate(opts, fSys, factory)

require.NoErrorf(t, err, "unexpected cmd error: %v")

m := readKustomizationFS(t, fSys)
expected := konfig.DefaultKustomizationMetadata()

require.Truef(t, reflect.DeepEqual(m.MetaData, expected), "expected %v but got %v", expected, m.MetaData)
}

func writeDetectContent(fSys filesys.FileSystem) {
fSys.WriteFile("/test.yaml", []byte(`
apiVersion: v1
Expand Down