mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 10:30:59 +00:00
Compare commits
136 Commits
api/v0.8.1
...
release-ku
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1eb3c1a075 | ||
|
|
a1746f2f8c | ||
|
|
b727febd08 | ||
|
|
c819d69ae4 | ||
|
|
bb6f83fb96 | ||
|
|
02d14d724a | ||
|
|
aa92d83d8c | ||
|
|
5427ab7cc3 | ||
|
|
e583f199b8 | ||
|
|
b465c20f65 | ||
|
|
5c2c617ff0 | ||
|
|
3ab0665c19 | ||
|
|
4b66043735 | ||
|
|
979f03e76c | ||
|
|
c8b049f57f | ||
|
|
f3d8883046 | ||
|
|
e308f321d3 | ||
|
|
beea785ead | ||
|
|
95c5b686be | ||
|
|
0ddf68cc8a | ||
|
|
4cadad5cfe | ||
|
|
9e4a6397d6 | ||
|
|
2e8a3b7c45 | ||
|
|
276d0430bf | ||
|
|
1aa7a1e709 | ||
|
|
dac84d867e | ||
|
|
217e5c7268 | ||
|
|
936ac37a2e | ||
|
|
cb4f5c3983 | ||
|
|
1801d33287 | ||
|
|
b01da61d83 | ||
|
|
23e28bb18a | ||
|
|
a1f1c2d32f | ||
|
|
10331d9560 | ||
|
|
60038d44f9 | ||
|
|
24d06f83ca | ||
|
|
e76638f98d | ||
|
|
ef1b9d4854 | ||
|
|
3c0f805674 | ||
|
|
324581594c | ||
|
|
7fae7d1bd6 | ||
|
|
0af3a75708 | ||
|
|
d39d7db9ed | ||
|
|
a04a6de0ef | ||
|
|
69a6708f9b | ||
|
|
c19a972739 | ||
|
|
2e674337b3 | ||
|
|
727e24f365 | ||
|
|
7e8ba62e9f | ||
|
|
fe60d0c403 | ||
|
|
2e0556b544 | ||
|
|
479acac581 | ||
|
|
3b37fed24b | ||
|
|
8fdb3f1703 | ||
|
|
95e242353b | ||
|
|
199802a176 | ||
|
|
065432e074 | ||
|
|
62fd36facb | ||
|
|
f121e74744 | ||
|
|
5aa2f534be | ||
|
|
86dd74fd62 | ||
|
|
218da9858f | ||
|
|
cebda58437 | ||
|
|
6a82437bc9 | ||
|
|
6b9e8eb891 | ||
|
|
615984bf2d | ||
|
|
bc6ac8a68a | ||
|
|
39f24ef8d2 | ||
|
|
24294d3bd0 | ||
|
|
234fcbfc02 | ||
|
|
b54093ebca | ||
|
|
db307a7084 | ||
|
|
a0c7997b66 | ||
|
|
7458a53a73 | ||
|
|
cf6e6ca4db | ||
|
|
e847ec7474 | ||
|
|
440026b9b3 | ||
|
|
64331ad845 | ||
|
|
294070b3ab | ||
|
|
cabbea0d97 | ||
|
|
732a8522df | ||
|
|
8f82c4c748 | ||
|
|
d0bc25f339 | ||
|
|
ed3200e4f5 | ||
|
|
a3ed120efb | ||
|
|
f1b191c02f | ||
|
|
1493b24b46 | ||
|
|
5993eae1aa | ||
|
|
3e506eae02 | ||
|
|
0305860078 | ||
|
|
0205090e0d | ||
|
|
6adefe4562 | ||
|
|
da1bd901b4 | ||
|
|
636b9c7aeb | ||
|
|
942f112ef5 | ||
|
|
03bbb076bf | ||
|
|
e468d6b4d2 | ||
|
|
57206a628d | ||
|
|
f061bb887b | ||
|
|
75fd9a43a3 | ||
|
|
58165dfc89 | ||
|
|
0e8257c387 | ||
|
|
62e78f8349 | ||
|
|
84724a3ebf | ||
|
|
23544e0431 | ||
|
|
b1fda3d62e | ||
|
|
b8ae69b748 | ||
|
|
4014440d06 | ||
|
|
74b0b3adc6 | ||
|
|
382f09a126 | ||
|
|
f9afdc5c95 | ||
|
|
5e4fb4796e | ||
|
|
76f8988865 | ||
|
|
fa3e829eb6 | ||
|
|
d9435bd1b1 | ||
|
|
af96bb4bda | ||
|
|
8607e0adec | ||
|
|
5a2a7709a4 | ||
|
|
437e8f90f6 | ||
|
|
06ac670951 | ||
|
|
3ee1579688 | ||
|
|
5954314b98 | ||
|
|
c0324456a7 | ||
|
|
172adc404f | ||
|
|
501748192b | ||
|
|
f6e6ac0320 | ||
|
|
a10ce1d787 | ||
|
|
839cc2467c | ||
|
|
dbc11ed29f | ||
|
|
0f614e92f7 | ||
|
|
afaf7c62bc | ||
|
|
78d22069d7 | ||
|
|
22720a8b7a | ||
|
|
38c66d213a | ||
|
|
73da51d0ac | ||
|
|
df10d5a17d |
15
.github/workflows/go.yml
vendored
15
.github/workflows/go.yml
vendored
@@ -23,7 +23,7 @@ jobs:
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Lint
|
||||
run: ./scripts/kyaml-pre-commit.sh
|
||||
run: ./hack/kyaml-pre-commit.sh
|
||||
env:
|
||||
KUSTOMIZE_DOCKER_E2E: false # don't need to do e2e tests for linting
|
||||
|
||||
@@ -45,6 +45,10 @@ jobs:
|
||||
run: go test -cover ./...
|
||||
working-directory: ./kyaml
|
||||
|
||||
- name: Test api
|
||||
run: go test -cover ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222"
|
||||
working-directory: ./api
|
||||
|
||||
- name: Test cmd/config
|
||||
run: go test -cover ./...
|
||||
working-directory: ./cmd/config
|
||||
@@ -69,6 +73,10 @@ jobs:
|
||||
run: go test -cover ./...
|
||||
working-directory: ./kyaml
|
||||
|
||||
- name: Test api
|
||||
run: go test -cover ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222"
|
||||
working-directory: ./api
|
||||
|
||||
- name: Test cmd/config
|
||||
run: go test -cover ./...
|
||||
working-directory: ./cmd/config
|
||||
@@ -93,6 +101,11 @@ jobs:
|
||||
run: go test -cover ./...
|
||||
working-directory: ./kyaml
|
||||
|
||||
# TODO: uncomment once Windows tests are passing.
|
||||
# - name: Test api
|
||||
# run: go test -cover ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222"
|
||||
# working-directory: ./api
|
||||
|
||||
- name: Test cmd/config
|
||||
run: go test -cover ./...
|
||||
working-directory: ./cmd/config
|
||||
|
||||
@@ -20,6 +20,20 @@ We have full documentation on how to get started contributing here:
|
||||
|
||||
- [Mentoring Initiatives](https://git.k8s.io/community/mentoring) - We have a diverse set of mentorship programs available that are always looking for volunteers!
|
||||
|
||||
## Contributor Ladder
|
||||
|
||||
Kustomize generally follows the [Kubernetes Community Membership](https://github.com/kubernetes/community/blob/master/community-membership.md) contributor ladder. Roles are as follows:
|
||||
|
||||
1. Contributor: Anyone who actively contributes code, issues or reviews to the project. There are no Kustomize-specific requirements for this status. All contributors must [sign the CLA](https://github.com/kubernetes/community/tree/master/contributors/guide#prerequisites).
|
||||
1. Member/Reviewer: All Kubernetes-SIGs org members have LGTM rights on the Kustomize repo. There are no Kustomize-specific requirements. Kustomize does not currently have any formal reviewers, but the role will be created if there is interest.
|
||||
1. Maintainer/Approver: Highly experienced active reviewer and contributor to Kustomize. Has both LTGM and approval rights on the Kustomize repo, as well as [Github "maintain" rights](https://docs.github.com/en/organizations/managing-access-to-your-organizations-repositories/repository-permission-levels-for-an-organization#repository-access-for-each-permission-level).
|
||||
1. Admin/Owner: Maintainer who sets technical direction and makes or approves design decisions for the project. Has LGTM and approval rights on the Kustomize repo as well as [Github "admin" rights](https://docs.github.com/en/organizations/managing-access-to-your-organizations-repositories/repository-permission-levels-for-an-organization#repository-access-for-each-permission-level).
|
||||
|
||||
Administrative notes:
|
||||
- Maintainers and admins must be added to the appropriate list both [in the Kustomize repo](https://github.com/kubernetes-sigs/kustomize/blob/8049f7b1af52e8a7ec26faf6cf714f560d0043c5/OWNERS_ALIASES) and [in the community repo](https://github.com/kubernetes/org/blob/main/config/kubernetes-sigs/sig-cli/teams.yaml). If this isn't done, the individual in question will lack either PR approval rights (Kustomize list) or the appropriate Github repository permissions (community list).
|
||||
- The spec for the OWNERS file is [in the community repo](https://github.com/kubernetes/community/blob/master/contributors/guide/owners.md).
|
||||
|
||||
|
||||
## Contact Information
|
||||
|
||||
- [Slack channel](https://kubernetes.slack.com/messages/sig-cli)
|
||||
|
||||
8
Makefile
8
Makefile
@@ -131,6 +131,7 @@ pSrc=plugin/builtin
|
||||
_builtinplugins = \
|
||||
AnnotationsTransformer.go \
|
||||
ConfigMapGenerator.go \
|
||||
IAMPolicyGenerator.go \
|
||||
HashTransformer.go \
|
||||
ImageTagTransformer.go \
|
||||
LabelTransformer.go \
|
||||
@@ -158,6 +159,7 @@ builtinplugins = $(patsubst %,$(pGen)/%,$(_builtinplugins))
|
||||
# that file, will be recreated.
|
||||
$(pGen)/AnnotationsTransformer.go: $(pSrc)/annotationstransformer/AnnotationsTransformer.go
|
||||
$(pGen)/ConfigMapGenerator.go: $(pSrc)/configmapgenerator/ConfigMapGenerator.go
|
||||
$(pGen)/GkeSaGenerator.go: $(pSrc)/gkesagenerator/GkeSaGenerator.go
|
||||
$(pGen)/HashTransformer.go: $(pSrc)/hashtransformer/HashTransformer.go
|
||||
$(pGen)/ImageTagTransformer.go: $(pSrc)/imagetagtransformer/ImageTagTransformer.go
|
||||
$(pGen)/LabelTransformer.go: $(pSrc)/labeltransformer/LabelTransformer.go
|
||||
@@ -241,10 +243,10 @@ test-unit-kustomize-all: \
|
||||
test-unit-kustomize-plugins
|
||||
|
||||
test-unit-cmd-all:
|
||||
./scripts/kyaml-pre-commit.sh
|
||||
./hack/kyaml-pre-commit.sh
|
||||
|
||||
test-go-mod:
|
||||
./scripts/check-go-mod.sh
|
||||
./hack/check-go-mod.sh
|
||||
|
||||
# Environment variables are defined at
|
||||
# https://github.com/kubernetes/test-infra/blob/master/prow/jobs.md#job-environment-variables
|
||||
@@ -256,7 +258,7 @@ test-multi-module: $(MYGOBIN)/prchecker
|
||||
export REPO_NAME=$(REPO_NAME); \
|
||||
export PULL_NUMBER=$(PULL_NUMBER); \
|
||||
export MODULES=$(MODULES); \
|
||||
./scripts/check-multi-module.sh; \
|
||||
./hack/check-multi-module.sh; \
|
||||
)
|
||||
|
||||
.PHONY:
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
# Keep *-admins and *-maintainers list in sync with corresponding lists in
|
||||
# https://github.com/kubernetes/org/blob/main/config/kubernetes-sigs/sig-cli/teams.yaml
|
||||
aliases:
|
||||
kustomize-admins:
|
||||
- knverey
|
||||
- monopole
|
||||
- pwittrock
|
||||
kustomize-maintainers:
|
||||
- droot
|
||||
- justinsb
|
||||
- knverey
|
||||
- monopole
|
||||
- mortent
|
||||
- natasha41575
|
||||
- phanimarupaka
|
||||
- pwittrock
|
||||
- Shell32-Natsu
|
||||
# emeritus
|
||||
# - liujingfang1
|
||||
# - mengqiy
|
||||
emeritus-maintainers:
|
||||
- liujingfang1
|
||||
- mengqiy
|
||||
|
||||
16
README.md
16
README.md
@@ -22,15 +22,21 @@ This tool is sponsored by [sig-cli] ([KEP]).
|
||||
|
||||
The kustomize build flow at [v2.0.3] was added
|
||||
to [kubectl v1.14][kubectl announcement]. The kustomize
|
||||
flow in kubectl has remained frozen at v2.0.3 while work
|
||||
to extract kubectl from the k/k repo, and work to remove
|
||||
kustomize's dependence on core k/k code ([#2506]) has proceeded.
|
||||
The reintegration effort is tracked in [#1500] (and its blocking
|
||||
issues).
|
||||
flow in kubectl remained frozen at v2.0.3 until kubectl v1.21,
|
||||
which [updated it to v4.0.5][kust-in-kubectl update]. It will
|
||||
be updated on a regular basis going forward, and such updates
|
||||
will be reflected in the Kubernetes release notes.
|
||||
|
||||
| Kubectl version | Kustomize version |
|
||||
| --- | --- |
|
||||
| < v1.14 | n/a |
|
||||
| v1.14-v1.20 | v2.0.3 |
|
||||
| v1.21 | v4.0.5 |
|
||||
|
||||
[v2.0.3]: /../../tree/v2.0.3
|
||||
[#2506]: https://github.com/kubernetes-sigs/kustomize/issues/2506
|
||||
[#1500]: https://github.com/kubernetes-sigs/kustomize/issues/1500
|
||||
[kust-in-kubectl update]: https://github.com/kubernetes/kubernetes/blob/4d75a6238a6e330337526e0513e67d02b1940b63/CHANGELOG/CHANGELOG-1.21.md#kustomize-updates-in-kubectl
|
||||
|
||||
For examples and guides for using the kubectl integration please
|
||||
see the [kubectl book] or the [kubernetes documentation].
|
||||
|
||||
@@ -280,6 +280,9 @@ func (p *HelmChartInflationGeneratorPlugin) templateCommand() []string {
|
||||
// I've tried placing the flag before and after the name argument.
|
||||
args = append(args, "--generate-name")
|
||||
}
|
||||
if p.IncludeCRDs {
|
||||
args = append(args, "--include-crds")
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
|
||||
33
api/builtins/IAMPolicyGenerator.go
Normal file
33
api/builtins/IAMPolicyGenerator.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// Code generated by pluginator on IAMPolicyGenerator; DO NOT EDIT.
|
||||
// pluginator {unknown 1970-01-01T00:00:00Z }
|
||||
|
||||
package builtins
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/api/filters/iampolicygenerator"
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
type IAMPolicyGeneratorPlugin struct {
|
||||
types.IAMPolicyGeneratorArgs
|
||||
}
|
||||
|
||||
func (p *IAMPolicyGeneratorPlugin) Config(h *resmap.PluginHelpers, config []byte) (err error) {
|
||||
p.IAMPolicyGeneratorArgs = types.IAMPolicyGeneratorArgs{}
|
||||
err = yaml.Unmarshal(config, p)
|
||||
return
|
||||
}
|
||||
|
||||
func (p *IAMPolicyGeneratorPlugin) Generate() (resmap.ResMap, error) {
|
||||
r := resmap.New()
|
||||
err := r.ApplyFilter(iampolicygenerator.Filter{
|
||||
IAMPolicyGenerator: p.IAMPolicyGeneratorArgs,
|
||||
})
|
||||
return r, err
|
||||
}
|
||||
|
||||
func NewIAMPolicyGeneratorPlugin() resmap.GeneratorPlugin {
|
||||
return &IAMPolicyGeneratorPlugin{}
|
||||
}
|
||||
61
api/filesys/filesys.go
Normal file
61
api/filesys/filesys.go
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright 2021 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package filesys provides a file system abstraction,
|
||||
// a subset of that provided by golang.org/pkg/os,
|
||||
// with an on-disk and in-memory representation.
|
||||
//
|
||||
// Deprecated: use sigs.k8s.io/kustomize/kyaml/filesys instead.
|
||||
package filesys
|
||||
|
||||
import "sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
|
||||
const (
|
||||
// Separator is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.Separator.
|
||||
Separator = filesys.Separator
|
||||
// SelfDir is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.SelfDir.
|
||||
SelfDir = filesys.SelfDir
|
||||
// ParentDir is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.ParentDir.
|
||||
ParentDir = filesys.ParentDir
|
||||
)
|
||||
|
||||
type (
|
||||
// FileSystem is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.FileSystem.
|
||||
FileSystem = filesys.FileSystem
|
||||
// FileSystemOrOnDisk is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.FileSystemOrOnDisk.
|
||||
FileSystemOrOnDisk = filesys.FileSystemOrOnDisk
|
||||
// ConfirmedDir is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.ConfirmedDir.
|
||||
ConfirmedDir = filesys.ConfirmedDir
|
||||
)
|
||||
|
||||
// MakeEmptyDirInMemory is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.MakeEmptyDirInMemory.
|
||||
func MakeEmptyDirInMemory() FileSystem { return filesys.MakeEmptyDirInMemory() }
|
||||
|
||||
// MakeFsInMemory is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.MakeFsInMemory.
|
||||
func MakeFsInMemory() FileSystem { return filesys.MakeFsInMemory() }
|
||||
|
||||
// MakeFsOnDisk is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.MakeFsOnDisk.
|
||||
func MakeFsOnDisk() FileSystem { return filesys.MakeFsOnDisk() }
|
||||
|
||||
// NewTmpConfirmedDir is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.NewTmpConfirmedDir.
|
||||
func NewTmpConfirmedDir() (filesys.ConfirmedDir, error) { return filesys.NewTmpConfirmedDir() }
|
||||
|
||||
// RootedPath is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.RootedPath.
|
||||
func RootedPath(elem ...string) string { return filesys.RootedPath(elem...) }
|
||||
|
||||
// StripTrailingSeps is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.StripTrailingSeps.
|
||||
func StripTrailingSeps(s string) string { return filesys.StripTrailingSeps(s) }
|
||||
|
||||
// StripLeadingSeps is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.StripLeadingSeps.
|
||||
func StripLeadingSeps(s string) string { return filesys.StripLeadingSeps(s) }
|
||||
|
||||
// PathSplit is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.PathSplit.
|
||||
func PathSplit(incoming string) []string { return filesys.PathSplit(incoming) }
|
||||
|
||||
// PathJoin is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.PathJoin.
|
||||
func PathJoin(incoming []string) string { return filesys.PathJoin(incoming) }
|
||||
|
||||
// InsertPathPart is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.InsertPathPart.
|
||||
func InsertPathPart(path string, pos int, part string) string {
|
||||
return filesys.InsertPathPart(path, pos, part)
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package filesys provides a file system abstraction layer.
|
||||
package filesys
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const (
|
||||
Separator = string(filepath.Separator)
|
||||
SelfDir = "."
|
||||
ParentDir = ".."
|
||||
)
|
||||
|
||||
// FileSystem groups basic os filesystem methods.
|
||||
// It's supposed be functional subset of https://golang.org/pkg/os
|
||||
type FileSystem interface {
|
||||
// Create a file.
|
||||
Create(path string) (File, error)
|
||||
// MkDir makes a directory.
|
||||
Mkdir(path string) error
|
||||
// MkDirAll makes a directory path, creating intervening directories.
|
||||
MkdirAll(path string) error
|
||||
// RemoveAll removes path and any children it contains.
|
||||
RemoveAll(path string) error
|
||||
// Open opens the named file for reading.
|
||||
Open(path string) (File, error)
|
||||
// IsDir returns true if the path is a directory.
|
||||
IsDir(path string) bool
|
||||
// CleanedAbs converts the given path into a
|
||||
// directory and a file name, where the directory
|
||||
// is represented as a ConfirmedDir and all that implies.
|
||||
// If the entire path is a directory, the file component
|
||||
// is an empty string.
|
||||
CleanedAbs(path string) (ConfirmedDir, string, error)
|
||||
// Exists is true if the path exists in the file system.
|
||||
Exists(path string) bool
|
||||
// Glob returns the list of matching files,
|
||||
// emulating https://golang.org/pkg/path/filepath/#Glob
|
||||
Glob(pattern string) ([]string, error)
|
||||
// ReadFile returns the contents of the file at the given path.
|
||||
ReadFile(path string) ([]byte, error)
|
||||
// WriteFile writes the data to a file at the given path,
|
||||
// overwriting anything that's already there.
|
||||
WriteFile(path string, data []byte) error
|
||||
// Walk walks the file system with the given WalkFunc.
|
||||
Walk(path string, walkFn filepath.WalkFunc) error
|
||||
}
|
||||
5
api/filters/doc.go
Normal file
5
api/filters/doc.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package filters
|
||||
|
||||
// Package filters collects various implementations
|
||||
// sigs.k8s.io/kustomize/kyaml/kio.Filter used by kustomize
|
||||
// transformers to modify kubernetes objects.
|
||||
@@ -49,7 +49,7 @@ func (fltr Filter) Filter(obj *yaml.RNode) (*yaml.RNode, error) {
|
||||
if match := isMatchGVK(fltr.FieldSpec, obj); !match {
|
||||
return obj, nil
|
||||
}
|
||||
fltr.path = utils.PathSplitter(fltr.FieldSpec.Path)
|
||||
fltr.path = utils.PathSplitter(fltr.FieldSpec.Path, "/")
|
||||
if err := fltr.filter(obj); err != nil {
|
||||
s, _ := obj.String()
|
||||
return nil, errors.WrapPrefixf(err,
|
||||
|
||||
3
api/filters/iampolicygenerator/doc.go
Normal file
3
api/filters/iampolicygenerator/doc.go
Normal file
@@ -0,0 +1,3 @@
|
||||
// Package gkesagenerator contains a kio.Filter that that generates a
|
||||
// iampolicy-related resources for a given cloud provider
|
||||
package iampolicygenerator
|
||||
46
api/filters/iampolicygenerator/example_test.go
Normal file
46
api/filters/iampolicygenerator/example_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright 2021 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package iampolicygenerator
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
func ExampleFilter() {
|
||||
f := Filter{}
|
||||
var err = yaml.Unmarshal([]byte(`
|
||||
cloud: gke
|
||||
kubernetesService:
|
||||
namespace: k8s-namespace
|
||||
name: k8s-sa-name
|
||||
serviceAccount:
|
||||
name: gsa-name
|
||||
projectId: project-id
|
||||
`), &f)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = kio.Pipeline{
|
||||
Inputs: []kio.Reader{},
|
||||
Filters: []kio.Filter{f},
|
||||
Outputs: []kio.Writer{kio.ByteWriter{Writer: os.Stdout}},
|
||||
}.Execute()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// apiVersion: v1
|
||||
// kind: ServiceAccount
|
||||
// metadata:
|
||||
// annotations:
|
||||
// iam.gke.io/gcp-service-account: gsa-name@project-id.iam.gserviceaccount.com
|
||||
// name: k8s-sa-name
|
||||
// namespace: k8s-namespace
|
||||
}
|
||||
55
api/filters/iampolicygenerator/iampolicygenerator.go
Normal file
55
api/filters/iampolicygenerator/iampolicygenerator.go
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright 2021 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package iampolicygenerator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
type Filter struct {
|
||||
IAMPolicyGenerator types.IAMPolicyGeneratorArgs `json:",inline,omitempty" yaml:",inline,omitempty"`
|
||||
}
|
||||
|
||||
// Filter adds a GKE service account object to nodes
|
||||
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||
switch f.IAMPolicyGenerator.Cloud {
|
||||
case types.GKE:
|
||||
IAMPolicyResources, err := f.generateGkeIAMPolicyResources()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nodes = append(nodes, IAMPolicyResources...)
|
||||
default:
|
||||
return nil, fmt.Errorf("cloud provider %s not supported yet", f.IAMPolicyGenerator.Cloud)
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (f Filter) generateGkeIAMPolicyResources() ([]*yaml.RNode, error) {
|
||||
var result []*yaml.RNode
|
||||
input := fmt.Sprintf(`
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
annotations:
|
||||
iam.gke.io/gcp-service-account: %s@%s.iam.gserviceaccount.com
|
||||
name: %s
|
||||
`, f.IAMPolicyGenerator.ServiceAccount.Name,
|
||||
f.IAMPolicyGenerator.ProjectId,
|
||||
f.IAMPolicyGenerator.KubernetesService.Name)
|
||||
|
||||
if f.IAMPolicyGenerator.Namespace != "" {
|
||||
input = input + fmt.Sprintf("\n namespace: %s", f.IAMPolicyGenerator.Namespace)
|
||||
}
|
||||
|
||||
sa, err := yaml.Parse(input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return append(result, sa), nil
|
||||
}
|
||||
75
api/filters/iampolicygenerator/iampolicygenerator_test.go
Normal file
75
api/filters/iampolicygenerator/iampolicygenerator_test.go
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright 2021 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package iampolicygenerator
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
filtertest "sigs.k8s.io/kustomize/api/testutils/filtertest"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
)
|
||||
|
||||
func TestFilter(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
args types.IAMPolicyGeneratorArgs
|
||||
expected string
|
||||
}{
|
||||
"with namespace": {
|
||||
args: types.IAMPolicyGeneratorArgs{
|
||||
Cloud: types.GKE,
|
||||
KubernetesService: types.KubernetesService{
|
||||
Namespace: "k8s-namespace",
|
||||
Name: "k8s-sa-name",
|
||||
},
|
||||
ServiceAccount: types.ServiceAccount{
|
||||
Name: "gsa-name",
|
||||
ProjectId: "project-id",
|
||||
},
|
||||
},
|
||||
expected: `
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
annotations:
|
||||
iam.gke.io/gcp-service-account: gsa-name@project-id.iam.gserviceaccount.com
|
||||
name: k8s-sa-name
|
||||
namespace: k8s-namespace
|
||||
`,
|
||||
},
|
||||
"without namespace": {
|
||||
args: types.IAMPolicyGeneratorArgs{
|
||||
Cloud: types.GKE,
|
||||
KubernetesService: types.KubernetesService{
|
||||
Name: "k8s-sa-name",
|
||||
},
|
||||
ServiceAccount: types.ServiceAccount{
|
||||
Name: "gsa-name",
|
||||
ProjectId: "project-id",
|
||||
},
|
||||
},
|
||||
expected: `
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
annotations:
|
||||
iam.gke.io/gcp-service-account: gsa-name@project-id.iam.gserviceaccount.com
|
||||
name: k8s-sa-name
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
for tn, tc := range testCases {
|
||||
t.Run(tn, func(t *testing.T) {
|
||||
f := Filter{
|
||||
IAMPolicyGenerator: tc.args,
|
||||
}
|
||||
actual := filtertest.RunFilter(t, "", f)
|
||||
if !assert.Equal(t, strings.TrimSpace(tc.expected), strings.TrimSpace(actual)) {
|
||||
t.FailNow()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
package imagetag
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/api/internal/utils"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
@@ -74,7 +75,7 @@ func (f findFieldsFilter) walk(node *yaml.RNode) error {
|
||||
return err
|
||||
}
|
||||
key := n.Key.YNode().Value
|
||||
if contains(f.fields, key) {
|
||||
if utils.StringSliceContains(f.fields, key) {
|
||||
return f.fieldCallback(n.Value)
|
||||
}
|
||||
return nil
|
||||
@@ -87,15 +88,6 @@ func (f findFieldsFilter) walk(node *yaml.RNode) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func contains(slice []string, str string) bool {
|
||||
for _, s := range slice {
|
||||
if s == str {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func checkImageTagsFn(imageTag types.Image) fieldCallback {
|
||||
return func(node *yaml.RNode) error {
|
||||
if node.YNode().Kind != yaml.SequenceNode {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/internal/utils"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/resid"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
@@ -43,11 +44,17 @@ func applyReplacement(nodes []*yaml.RNode, value *yaml.RNode, targets []*types.T
|
||||
t.FieldPaths = []string{types.DefaultReplacementFieldPath}
|
||||
}
|
||||
for _, n := range nodes {
|
||||
id := makeResId(n)
|
||||
if id.IsSelectedBy(t.Select.ResId) && !rejectId(t.Reject, id) {
|
||||
err := applyToNode(n, value, t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
ids, err := utils.MakeResIds(n)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, id := range ids {
|
||||
if id.IsSelectedBy(t.Select.ResId) && !rejectId(t.Reject, &id) {
|
||||
err := applyToNode(n, value, t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,7 +73,7 @@ func rejectId(rejects []*types.Selector, id *resid.ResId) bool {
|
||||
|
||||
func applyToNode(node *yaml.RNode, value *yaml.RNode, target *types.TargetSelector) error {
|
||||
for _, fp := range target.FieldPaths {
|
||||
fieldPath := strings.Split(fp, ".")
|
||||
fieldPath := utils.SmarterPathSplitter(fp, ".")
|
||||
var t *yaml.RNode
|
||||
var err error
|
||||
if target.Options != nil && target.Options.Create {
|
||||
@@ -87,12 +94,11 @@ func applyToNode(node *yaml.RNode, value *yaml.RNode, target *types.TargetSelect
|
||||
}
|
||||
|
||||
func setTargetValue(options *types.FieldOptions, t *yaml.RNode, value *yaml.RNode) error {
|
||||
value = value.Copy()
|
||||
if options != nil && options.Delimiter != "" {
|
||||
|
||||
if t.YNode().Kind != yaml.ScalarNode {
|
||||
return fmt.Errorf("delimiter option can only be used with scalar nodes")
|
||||
}
|
||||
|
||||
tv := strings.Split(t.YNode().Value, options.Delimiter)
|
||||
v := yaml.GetValue(value)
|
||||
// TODO: Add a way to remove an element
|
||||
@@ -119,7 +125,7 @@ func getReplacement(nodes []*yaml.RNode, r *types.Replacement) (*yaml.RNode, err
|
||||
if r.Source.FieldPath == "" {
|
||||
r.Source.FieldPath = types.DefaultReplacementFieldPath
|
||||
}
|
||||
fieldPath := strings.Split(r.Source.FieldPath, ".")
|
||||
fieldPath := utils.SmarterPathSplitter(r.Source.FieldPath, ".")
|
||||
|
||||
rn, err := source.Pipe(yaml.Lookup(fieldPath...))
|
||||
if err != nil {
|
||||
@@ -152,12 +158,19 @@ func getRefinedValue(options *types.FieldOptions, rn *yaml.RNode) (*yaml.RNode,
|
||||
func selectSourceNode(nodes []*yaml.RNode, selector *types.SourceSelector) (*yaml.RNode, error) {
|
||||
var matches []*yaml.RNode
|
||||
for _, n := range nodes {
|
||||
if makeResId(n).IsSelectedBy(selector.ResId) {
|
||||
if len(matches) > 0 {
|
||||
return nil, fmt.Errorf(
|
||||
"multiple matches for selector %s", selector)
|
||||
ids, err := utils.MakeResIds(n)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, id := range ids {
|
||||
if id.IsSelectedBy(selector.ResId) {
|
||||
if len(matches) > 0 {
|
||||
return nil, fmt.Errorf(
|
||||
"multiple matches for selector %s", selector)
|
||||
}
|
||||
matches = append(matches, n)
|
||||
break
|
||||
}
|
||||
matches = append(matches, n)
|
||||
}
|
||||
}
|
||||
if len(matches) == 0 {
|
||||
@@ -165,17 +178,3 @@ func selectSourceNode(nodes []*yaml.RNode, selector *types.SourceSelector) (*yam
|
||||
}
|
||||
return matches[0], nil
|
||||
}
|
||||
|
||||
// makeResId makes a ResId from an RNode.
|
||||
func makeResId(n *yaml.RNode) *resid.ResId {
|
||||
apiVersion := n.Field(yaml.APIVersionField)
|
||||
var group, version string
|
||||
if apiVersion != nil {
|
||||
group, version = resid.ParseGroupVersion(yaml.GetValue(apiVersion.Value))
|
||||
}
|
||||
return &resid.ResId{
|
||||
Gvk: resid.Gvk{Group: group, Version: version, Kind: n.GetKind()},
|
||||
Name: n.GetName(),
|
||||
Namespace: n.GetNamespace(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1338,6 +1338,224 @@ spec:
|
||||
`,
|
||||
expectedErr: "delimiter option can only be used with scalar nodes",
|
||||
},
|
||||
"mapping value contains '.' character": {
|
||||
input: `apiVersion: v1
|
||||
kind: Custom
|
||||
metadata:
|
||||
name: custom
|
||||
annotations:
|
||||
a.b.c/d-e: source
|
||||
f.g.h/i-j: target
|
||||
`,
|
||||
replacements: `replacements:
|
||||
- source:
|
||||
name: custom
|
||||
fieldPath: metadata.annotations.[a.b.c/d-e]
|
||||
targets:
|
||||
- select:
|
||||
name: custom
|
||||
fieldPaths:
|
||||
- metadata.annotations.[f.g.h/i-j]
|
||||
`,
|
||||
expected: `apiVersion: v1
|
||||
kind: Custom
|
||||
metadata:
|
||||
name: custom
|
||||
annotations:
|
||||
a.b.c/d-e: source
|
||||
f.g.h/i-j: source
|
||||
`,
|
||||
},
|
||||
"list index contains '.' character": {
|
||||
input: `apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: source
|
||||
data:
|
||||
value: example
|
||||
---
|
||||
apiVersion: kubernetes-client.io/v1
|
||||
kind: ExternalSecret
|
||||
metadata:
|
||||
name: some-secret
|
||||
spec:
|
||||
backendType: secretsManager
|
||||
data:
|
||||
- key: some-prefix-replaceme
|
||||
name: .first
|
||||
version: latest
|
||||
property: first
|
||||
- key: some-prefix-replaceme
|
||||
name: second
|
||||
version: latest
|
||||
property: second
|
||||
`,
|
||||
replacements: `replacements:
|
||||
- source:
|
||||
kind: ConfigMap
|
||||
version: v1
|
||||
name: source
|
||||
fieldPath: data.value
|
||||
targets:
|
||||
- select:
|
||||
group: kubernetes-client.io
|
||||
version: v1
|
||||
kind: ExternalSecret
|
||||
name: some-secret
|
||||
fieldPaths:
|
||||
- spec.data.[name=.first].key
|
||||
- spec.data.[name=second].key
|
||||
options:
|
||||
delimiter: "-"
|
||||
index: 2
|
||||
`,
|
||||
expected: `apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: source
|
||||
data:
|
||||
value: example
|
||||
---
|
||||
apiVersion: kubernetes-client.io/v1
|
||||
kind: ExternalSecret
|
||||
metadata:
|
||||
name: some-secret
|
||||
spec:
|
||||
backendType: secretsManager
|
||||
data:
|
||||
- key: some-prefix-example
|
||||
name: .first
|
||||
version: latest
|
||||
property: first
|
||||
- key: some-prefix-example
|
||||
name: second
|
||||
version: latest
|
||||
property: second`,
|
||||
},
|
||||
"multiple field paths in target": {
|
||||
input: `apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: source
|
||||
data:
|
||||
value: example
|
||||
---
|
||||
apiVersion: kubernetes-client.io/v1
|
||||
kind: ExternalSecret
|
||||
metadata:
|
||||
name: some-secret
|
||||
spec:
|
||||
backendType: secretsManager
|
||||
data:
|
||||
- key: some-prefix-replaceme
|
||||
name: first
|
||||
version: latest
|
||||
property: first
|
||||
- key: some-prefix-replaceme
|
||||
name: second
|
||||
version: latest
|
||||
property: second
|
||||
- key: some-prefix-replaceme
|
||||
name: third
|
||||
version: latest
|
||||
property: third
|
||||
`,
|
||||
replacements: `replacements:
|
||||
- source:
|
||||
kind: ConfigMap
|
||||
version: v1
|
||||
name: source
|
||||
fieldPath: data.value
|
||||
targets:
|
||||
- select:
|
||||
group: kubernetes-client.io
|
||||
version: v1
|
||||
kind: ExternalSecret
|
||||
name: some-secret
|
||||
fieldPaths:
|
||||
- spec.data.0.key
|
||||
- spec.data.1.key
|
||||
- spec.data.2.key
|
||||
options:
|
||||
delimiter: "-"
|
||||
index: 2
|
||||
`,
|
||||
expected: `apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: source
|
||||
data:
|
||||
value: example
|
||||
---
|
||||
apiVersion: kubernetes-client.io/v1
|
||||
kind: ExternalSecret
|
||||
metadata:
|
||||
name: some-secret
|
||||
spec:
|
||||
backendType: secretsManager
|
||||
data:
|
||||
- key: some-prefix-example
|
||||
name: first
|
||||
version: latest
|
||||
property: first
|
||||
- key: some-prefix-example
|
||||
name: second
|
||||
version: latest
|
||||
property: second
|
||||
- key: some-prefix-example
|
||||
name: third
|
||||
version: latest
|
||||
property: third
|
||||
`,
|
||||
},
|
||||
"using a previous ID": {
|
||||
input: `apiVersion: v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: pre-deploy
|
||||
annotations:
|
||||
config.kubernetes.io/previousNames: deploy,deploy
|
||||
config.kubernetes.io/previousKinds: CronJob,Deployment
|
||||
config.kubernetes.io/previousNamespaces: default,default
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:1.7.9
|
||||
name: nginx-tagged
|
||||
- image: postgres:1.8.0
|
||||
name: postgresdb
|
||||
`,
|
||||
replacements: `replacements:
|
||||
- source:
|
||||
kind: CronJob
|
||||
name: deploy
|
||||
fieldPath: spec.template.spec.containers.0.image
|
||||
targets:
|
||||
- select:
|
||||
kind: Deployment
|
||||
name: deploy
|
||||
fieldPaths:
|
||||
- spec.template.spec.containers.1.image
|
||||
`,
|
||||
expected: `apiVersion: v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: pre-deploy
|
||||
annotations:
|
||||
config.kubernetes.io/previousNames: deploy,deploy
|
||||
config.kubernetes.io/previousKinds: CronJob,Deployment
|
||||
config.kubernetes.io/previousNamespaces: default,default
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:1.7.9
|
||||
name: nginx-tagged
|
||||
- image: nginx:1.7.9
|
||||
name: postgresdb
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
for tn, tc := range testCases {
|
||||
@@ -1353,7 +1571,7 @@ spec:
|
||||
t.Errorf("unexpected error: %s\n", err.Error())
|
||||
t.FailNow()
|
||||
}
|
||||
if !assert.Equal(t, tc.expectedErr, err.Error()) {
|
||||
if !assert.Contains(t, err.Error(), tc.expectedErr) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ package valueadd
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ module sigs.k8s.io/kustomize/api
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/evanphx/json-patch v4.5.0+incompatible
|
||||
github.com/evanphx/json-patch v4.11.0+incompatible
|
||||
github.com/go-errors/errors v1.0.1
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||
github.com/imdario/mergo v0.3.5
|
||||
@@ -11,8 +11,6 @@ require (
|
||||
github.com/stretchr/testify v1.5.1
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e
|
||||
sigs.k8s.io/kustomize/kyaml v0.10.20
|
||||
sigs.k8s.io/kustomize/kyaml v0.11.0
|
||||
sigs.k8s.io/yaml v1.2.0
|
||||
)
|
||||
|
||||
replace gopkg.in/yaml.v3 => gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
|
||||
|
||||
11
api/go.sum
11
api/go.sum
@@ -30,8 +30,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
|
||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
|
||||
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
|
||||
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/evanphx/json-patch v4.11.0+incompatible h1:glyUF9yIYtMHzn8xaKw5rMhdWcwsYV8dZHIq5567/xs=
|
||||
github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
|
||||
@@ -217,15 +217,14 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
|
||||
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e h1:KLHHjkdQFomZy8+06csTWZ0m1343QqxZhR2LJ1OxCYM=
|
||||
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e/go.mod h1:vHXdDvt9+2spS2Rx9ql3I8tycm3H9FDfdUoIuKCefvw=
|
||||
sigs.k8s.io/kustomize/kyaml v0.10.20 h1:L9JNKvJfCBpmYFr4tP0igpfj/pXP7nW2aXOWNtF5k1g=
|
||||
sigs.k8s.io/kustomize/kyaml v0.10.20/go.mod h1:TYWhGwW9vjoRh3rWqBwB/ZOXyEGRVWe7Ggc3+KZIO+c=
|
||||
sigs.k8s.io/kustomize/kyaml v0.11.0 h1:9KhiCPKaVyuPcgOLJXkvytOvjMJLoxpjodiycb4gHsA=
|
||||
sigs.k8s.io/kustomize/kyaml v0.11.0/go.mod h1:GNMwjim4Ypgp/MueD3zXHLRJEjz7RvtPae0AwlvEMFM=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/kube-openapi/pkg/validation/spec"
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/ifc"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
"sigs.k8s.io/kustomize/kyaml/resid"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
@@ -178,9 +178,12 @@ func loadCrdIntoConfig(
|
||||
}
|
||||
}
|
||||
if property.Ref.GetURL() != nil {
|
||||
loadCrdIntoConfig(
|
||||
err = loadCrdIntoConfig(
|
||||
theConfig, theGvk, theMap,
|
||||
property.Ref.String(), append(path, propName))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -7,11 +7,12 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"github.com/stretchr/testify/require"
|
||||
. "sigs.k8s.io/kustomize/api/internal/accumulator"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
|
||||
"sigs.k8s.io/kustomize/api/loader"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
"sigs.k8s.io/kustomize/kyaml/resid"
|
||||
)
|
||||
|
||||
@@ -162,16 +163,13 @@ func TestLoadCRDs(t *testing.T) {
|
||||
}
|
||||
|
||||
fSys := filesys.MakeFsInMemory()
|
||||
fSys.WriteFile("/testpath/crd.json", []byte(crdContent))
|
||||
err := fSys.WriteFile("/testpath/crd.json", []byte(crdContent))
|
||||
require.NoError(t, err)
|
||||
ldr, err := loader.NewLoader(loader.RestrictionRootOnly, "/testpath", fSys)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error:%v", err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
actualTc, err := LoadConfigFromCRDs(ldr, []string{"crd.json"})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error:%v", err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
if !reflect.DeepEqual(actualTc, expectedTc) {
|
||||
t.Fatalf("expected\n %v\n but got\n %v\n", expectedTc, actualTc)
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
. "sigs.k8s.io/kustomize/api/internal/accumulator"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
|
||||
"sigs.k8s.io/kustomize/api/provider"
|
||||
@@ -224,20 +225,26 @@ func TestResolveVarConflicts(t *testing.T) {
|
||||
// create accumulators holding apparently conflicting vars that are not
|
||||
// actually in conflict because they point to the same concrete value.
|
||||
rm0 := resmap.New()
|
||||
rm0.Append(rf.FromMap(fooAws))
|
||||
err := rm0.Append(rf.FromMap(fooAws))
|
||||
require.NoError(t, err)
|
||||
ac0 := MakeEmptyAccumulator()
|
||||
ac0.AppendAll(rm0)
|
||||
ac0.MergeVars([]types.Var{varFoo})
|
||||
err = ac0.AppendAll(rm0)
|
||||
require.NoError(t, err)
|
||||
err = ac0.MergeVars([]types.Var{varFoo})
|
||||
require.NoError(t, err)
|
||||
|
||||
rm1 := resmap.New()
|
||||
rm1.Append(rf.FromMap(barAws))
|
||||
err = rm1.Append(rf.FromMap(barAws))
|
||||
require.NoError(t, err)
|
||||
ac1 := MakeEmptyAccumulator()
|
||||
ac1.AppendAll(rm1)
|
||||
ac1.MergeVars([]types.Var{varBar})
|
||||
err = ac1.AppendAll(rm1)
|
||||
require.NoError(t, err)
|
||||
err = ac1.MergeVars([]types.Var{varBar})
|
||||
require.NoError(t, err)
|
||||
|
||||
// validate that two vars of the same name which reference the same concrete
|
||||
// value do not produce a conflict.
|
||||
err := ac0.MergeAccumulator(ac1)
|
||||
err = ac0.MergeAccumulator(ac1)
|
||||
if err == nil {
|
||||
t.Fatalf("see bug gh-1600")
|
||||
}
|
||||
@@ -246,10 +253,13 @@ func TestResolveVarConflicts(t *testing.T) {
|
||||
// two above (because it contains a variable whose name is used in the other
|
||||
// accumulators AND whose concrete values are different).
|
||||
rm2 := resmap.New()
|
||||
rm2.Append(rf.FromMap(barGcp))
|
||||
err = rm2.Append(rf.FromMap(barGcp))
|
||||
require.NoError(t, err)
|
||||
ac2 := MakeEmptyAccumulator()
|
||||
ac2.AppendAll(rm2)
|
||||
ac2.MergeVars([]types.Var{varBar})
|
||||
err = ac2.AppendAll(rm2)
|
||||
require.NoError(t, err)
|
||||
err = ac2.MergeVars([]types.Var{varBar})
|
||||
require.NoError(t, err)
|
||||
err = ac1.MergeAccumulator(ac2)
|
||||
if err == nil {
|
||||
t.Fatalf("dupe vars w/ different concrete values should conflict")
|
||||
|
||||
@@ -40,7 +40,13 @@ func MakeConfigMap(
|
||||
if err = rn.LoadMapIntoConfigMapData(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
copyLabelsAndAnnotations(rn, args.Options)
|
||||
setImmutable(rn, args.Options)
|
||||
err = copyLabelsAndAnnotations(rn, args.Options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = setImmutable(rn, args.Options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rn, nil
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
. "sigs.k8s.io/kustomize/api/internal/generators"
|
||||
"sigs.k8s.io/kustomize/api/kv"
|
||||
"sigs.k8s.io/kustomize/api/loader"
|
||||
valtest_test "sigs.k8s.io/kustomize/api/testutils/valtest"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
var binaryHello = []byte{
|
||||
|
||||
@@ -8,12 +8,12 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
. "sigs.k8s.io/kustomize/api/internal/generators"
|
||||
"sigs.k8s.io/kustomize/api/kv"
|
||||
"sigs.k8s.io/kustomize/api/loader"
|
||||
valtest_test "sigs.k8s.io/kustomize/api/testutils/valtest"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
func TestMakeSecret(t *testing.T) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
// Cloner is a function that can clone a git repo.
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/internal/utils"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
// gitRunner runs the external git binary.
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
// Used as a temporary non-empty occupant of the cloneDir
|
||||
|
||||
@@ -35,7 +35,6 @@ var hostNamesRawAndNormalized = [][]string{
|
||||
{"git::https://git.example.com/", "https://git.example.com/"},
|
||||
{"git@github.com:", "git@github.com:"},
|
||||
{"git@github.com/", "git@github.com:"},
|
||||
{"git@gitlab2.sqtools.ru:10022/", "git@gitlab2.sqtools.ru:10022/"},
|
||||
}
|
||||
|
||||
func makeUrl(hostFmt, orgRepo, path, href string) string {
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/loader"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
"sigs.k8s.io/kustomize/kyaml/resid"
|
||||
)
|
||||
|
||||
|
||||
@@ -11,25 +11,26 @@ func _() {
|
||||
_ = x[Unknown-0]
|
||||
_ = x[AnnotationsTransformer-1]
|
||||
_ = x[ConfigMapGenerator-2]
|
||||
_ = x[HashTransformer-3]
|
||||
_ = x[ImageTagTransformer-4]
|
||||
_ = x[LabelTransformer-5]
|
||||
_ = x[LegacyOrderTransformer-6]
|
||||
_ = x[NamespaceTransformer-7]
|
||||
_ = x[PatchJson6902Transformer-8]
|
||||
_ = x[PatchStrategicMergeTransformer-9]
|
||||
_ = x[PatchTransformer-10]
|
||||
_ = x[PrefixSuffixTransformer-11]
|
||||
_ = x[ReplicaCountTransformer-12]
|
||||
_ = x[SecretGenerator-13]
|
||||
_ = x[ValueAddTransformer-14]
|
||||
_ = x[HelmChartInflationGenerator-15]
|
||||
_ = x[ReplacementTransformer-16]
|
||||
_ = x[IAMPolicyGenerator-3]
|
||||
_ = x[HashTransformer-4]
|
||||
_ = x[ImageTagTransformer-5]
|
||||
_ = x[LabelTransformer-6]
|
||||
_ = x[LegacyOrderTransformer-7]
|
||||
_ = x[NamespaceTransformer-8]
|
||||
_ = x[PatchJson6902Transformer-9]
|
||||
_ = x[PatchStrategicMergeTransformer-10]
|
||||
_ = x[PatchTransformer-11]
|
||||
_ = x[PrefixSuffixTransformer-12]
|
||||
_ = x[ReplicaCountTransformer-13]
|
||||
_ = x[SecretGenerator-14]
|
||||
_ = x[ValueAddTransformer-15]
|
||||
_ = x[HelmChartInflationGenerator-16]
|
||||
_ = x[ReplacementTransformer-17]
|
||||
}
|
||||
|
||||
const _BuiltinPluginType_name = "UnknownAnnotationsTransformerConfigMapGeneratorHashTransformerImageTagTransformerLabelTransformerLegacyOrderTransformerNamespaceTransformerPatchJson6902TransformerPatchStrategicMergeTransformerPatchTransformerPrefixSuffixTransformerReplicaCountTransformerSecretGeneratorValueAddTransformerHelmChartInflationGeneratorReplacementTransformer"
|
||||
const _BuiltinPluginType_name = "UnknownAnnotationsTransformerConfigMapGeneratorIAMPolicyGeneratorHashTransformerImageTagTransformerLabelTransformerLegacyOrderTransformerNamespaceTransformerPatchJson6902TransformerPatchStrategicMergeTransformerPatchTransformerPrefixSuffixTransformerReplicaCountTransformerSecretGeneratorValueAddTransformerHelmChartInflationGeneratorReplacementTransformer"
|
||||
|
||||
var _BuiltinPluginType_index = [...]uint16{0, 7, 29, 47, 62, 81, 97, 119, 139, 163, 193, 209, 232, 255, 270, 289, 316, 338}
|
||||
var _BuiltinPluginType_index = [...]uint16{0, 7, 29, 47, 65, 80, 99, 115, 137, 157, 181, 211, 227, 250, 273, 288, 307, 334, 356}
|
||||
|
||||
func (i BuiltinPluginType) String() string {
|
||||
if i < 0 || i >= BuiltinPluginType(len(_BuiltinPluginType_index)-1) {
|
||||
|
||||
@@ -15,6 +15,7 @@ const (
|
||||
Unknown BuiltinPluginType = iota
|
||||
AnnotationsTransformer
|
||||
ConfigMapGenerator
|
||||
IAMPolicyGenerator
|
||||
HashTransformer
|
||||
ImageTagTransformer
|
||||
LabelTransformer
|
||||
@@ -58,6 +59,7 @@ func GetBuiltinPluginType(n string) BuiltinPluginType {
|
||||
|
||||
var GeneratorFactories = map[BuiltinPluginType]func() resmap.GeneratorPlugin{
|
||||
ConfigMapGenerator: builtins.NewConfigMapGeneratorPlugin,
|
||||
IAMPolicyGenerator: builtins.NewIAMPolicyGeneratorPlugin,
|
||||
SecretGenerator: builtins.NewSecretGeneratorPlugin,
|
||||
HelmChartInflationGenerator: builtins.NewHelmChartInflationGeneratorPlugin,
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
. "sigs.k8s.io/kustomize/api/internal/plugins/compiler"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
// Regression coverage over compiler behavior.
|
||||
|
||||
@@ -94,9 +94,6 @@ TO GENERATE CODE
|
||||
cd $repo/plugin/builtin
|
||||
go generate ./...
|
||||
|
||||
See scripts/kyaml-pre-commit.sh for canonical way
|
||||
to execute the above.
|
||||
|
||||
This creates
|
||||
|
||||
$repo/api/plugins/builtins/SecretGenerator.go
|
||||
|
||||
@@ -89,7 +89,10 @@ type argsConfig struct {
|
||||
|
||||
func (p *ExecPlugin) processOptionalArgsFields() error {
|
||||
var c argsConfig
|
||||
yaml.Unmarshal(p.cfg, &c)
|
||||
err := yaml.Unmarshal(p.cfg, &c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if c.ArgsOneLiner != "" {
|
||||
p.args, _ = shlex.Split(c.ArgsOneLiner)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"github.com/stretchr/testify/require"
|
||||
. "sigs.k8s.io/kustomize/api/internal/plugins/execplugin"
|
||||
pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
|
||||
@@ -17,15 +17,17 @@ import (
|
||||
"sigs.k8s.io/kustomize/api/provider"
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
func TestExecPluginConfig(t *testing.T) {
|
||||
fSys := filesys.MakeFsInMemory()
|
||||
fSys.WriteFile("sed-input.txt", []byte(`
|
||||
err := fSys.WriteFile("sed-input.txt", []byte(`
|
||||
s/$FOO/foo/g
|
||||
s/$BAR/bar baz/g
|
||||
\ \ \
|
||||
`))
|
||||
require.NoError(t, err)
|
||||
ldr, err := fLdr.NewLoader(
|
||||
fLdr.RestrictionRootOnly, filesys.Separator, fSys)
|
||||
if err != nil {
|
||||
@@ -62,9 +64,10 @@ s/$BAR/bar baz/g
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
p.Config(
|
||||
err = p.Config(
|
||||
resmap.NewPluginHelpers(ldr, pvd.GetFieldValidator(), rf, pc),
|
||||
yaml)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := "someteam.example.com/v1/sedtransformer/SedTransformer"
|
||||
if !strings.HasSuffix(p.Path(), expected) {
|
||||
|
||||
@@ -78,6 +78,7 @@ func NewFnPlugin(o *types.FnPluginLoadingOptions) *FnPlugin {
|
||||
EnableExec: o.EnableExec,
|
||||
StorageMounts: toStorageMounts(o.Mounts),
|
||||
Env: o.Env,
|
||||
AsCurrentUser: o.AsCurrentUser,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/ifc"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/builtinhelpers"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/execplugin"
|
||||
@@ -23,6 +22,7 @@ import (
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
"sigs.k8s.io/kustomize/api/resource"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
"sigs.k8s.io/kustomize/kyaml/resid"
|
||||
)
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ package loader_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
. "sigs.k8s.io/kustomize/api/internal/plugins/loader"
|
||||
"sigs.k8s.io/kustomize/api/loader"
|
||||
"sigs.k8s.io/kustomize/api/provider"
|
||||
@@ -14,6 +13,7 @@ import (
|
||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||
valtest_test "sigs.k8s.io/kustomize/api/testutils/valtest"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -12,11 +12,11 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
"sigs.k8s.io/kustomize/api/resource"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -192,7 +192,9 @@ func UpdateResMapValues(pluginName string, h *resmap.PluginHelpers, output []byt
|
||||
for _, id := range rm.AllIds() {
|
||||
newIdx, _ := newMap.GetIndexOfCurrentId(id)
|
||||
if newIdx == -1 {
|
||||
rm.Remove(id)
|
||||
if err = rm.Remove(id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,13 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"github.com/stretchr/testify/require"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
"sigs.k8s.io/kustomize/api/provider"
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
"sigs.k8s.io/kustomize/api/resource"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
func TestDeterminePluginSrcRoot(t *testing.T) {
|
||||
@@ -86,8 +87,10 @@ func TestUpdateResourceOptions(t *testing.T) {
|
||||
}
|
||||
for i, c := range cases {
|
||||
name := fmt.Sprintf("test%d", i)
|
||||
in.Append(makeConfigMap(rf, name, c.behavior, c.hashValue))
|
||||
expected.Append(makeConfigMapOptions(rf, name, c.behavior, !c.needsHash))
|
||||
err := in.Append(makeConfigMap(rf, name, c.behavior, c.hashValue))
|
||||
require.NoError(t, err)
|
||||
err = expected.Append(makeConfigMapOptions(rf, name, c.behavior, !c.needsHash))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
actual, err := UpdateResourceOptions(in)
|
||||
assert.NoError(t, err)
|
||||
@@ -105,10 +108,9 @@ func TestUpdateResourceOptionsWithInvalidHashAnnotationValues(t *testing.T) {
|
||||
for i, c := range cases {
|
||||
name := fmt.Sprintf("test%d", i)
|
||||
in := resmap.New()
|
||||
in.Append(makeConfigMap(rf, name, "", &c))
|
||||
_, err := UpdateResourceOptions(in)
|
||||
if err == nil {
|
||||
t.Errorf("expected error from value %q", c)
|
||||
}
|
||||
err := in.Append(makeConfigMap(rf, name, "", &c))
|
||||
require.NoError(t, err)
|
||||
_, err = UpdateResourceOptions(in)
|
||||
require.Error(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ package target_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader"
|
||||
"sigs.k8s.io/kustomize/api/internal/target"
|
||||
fLdr "sigs.k8s.io/kustomize/api/loader"
|
||||
@@ -14,6 +13,7 @@ import (
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
valtest_test "sigs.k8s.io/kustomize/api/testutils/valtest"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
func makeAndLoadKustTarget(
|
||||
|
||||
79
api/internal/utils/makeResIds.go
Normal file
79
api/internal/utils/makeResIds.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
"sigs.k8s.io/kustomize/kyaml/resid"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
const (
|
||||
BuildAnnotationPreviousKinds = konfig.ConfigAnnoDomain + "/previousKinds"
|
||||
BuildAnnotationPreviousNames = konfig.ConfigAnnoDomain + "/previousNames"
|
||||
BuildAnnotationPrefixes = konfig.ConfigAnnoDomain + "/prefixes"
|
||||
BuildAnnotationSuffixes = konfig.ConfigAnnoDomain + "/suffixes"
|
||||
BuildAnnotationPreviousNamespaces = konfig.ConfigAnnoDomain + "/previousNamespaces"
|
||||
|
||||
// the following are only for patches, to specify whether they can change names
|
||||
// and kinds of their targets
|
||||
BuildAnnotationAllowNameChange = konfig.ConfigAnnoDomain + "/allowNameChange"
|
||||
BuildAnnotationAllowKindChange = konfig.ConfigAnnoDomain + "/allowKindChange"
|
||||
Allowed = "allowed"
|
||||
)
|
||||
|
||||
// MakeResIds returns all of an RNode's current and previous Ids
|
||||
func MakeResIds(n *yaml.RNode) ([]resid.ResId, error) {
|
||||
var result []resid.ResId
|
||||
apiVersion := n.Field(yaml.APIVersionField)
|
||||
var group, version string
|
||||
if apiVersion != nil {
|
||||
group, version = resid.ParseGroupVersion(yaml.GetValue(apiVersion.Value))
|
||||
}
|
||||
result = append(result, resid.NewResIdWithNamespace(
|
||||
resid.Gvk{Group: group, Version: version, Kind: n.GetKind()}, n.GetName(), n.GetNamespace()),
|
||||
)
|
||||
prevIds, err := PrevIds(n)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result = append(result, prevIds...)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// PrevIds returns all of an RNode's previous Ids
|
||||
func PrevIds(n *yaml.RNode) ([]resid.ResId, error) {
|
||||
var ids []resid.ResId
|
||||
// TODO: merge previous names and namespaces into one list of
|
||||
// pairs on one annotation so there is no chance of error
|
||||
annotations := n.GetAnnotations()
|
||||
if _, ok := annotations[BuildAnnotationPreviousNames]; !ok {
|
||||
return nil, nil
|
||||
}
|
||||
names := strings.Split(annotations[BuildAnnotationPreviousNames], ",")
|
||||
ns := strings.Split(annotations[BuildAnnotationPreviousNamespaces], ",")
|
||||
kinds := strings.Split(annotations[BuildAnnotationPreviousKinds], ",")
|
||||
// This should never happen
|
||||
if len(names) != len(ns) || len(names) != len(kinds) {
|
||||
return nil, fmt.Errorf(
|
||||
"number of previous names, " +
|
||||
"number of previous namespaces, " +
|
||||
"number of previous kinds not equal")
|
||||
}
|
||||
for i := range names {
|
||||
meta, err := n.GetMeta()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
group, version := resid.ParseGroupVersion(meta.APIVersion)
|
||||
gvk := resid.Gvk{
|
||||
Group: group,
|
||||
Version: version,
|
||||
Kind: kinds[i],
|
||||
}
|
||||
ids = append(ids, resid.NewResIdWithNamespace(
|
||||
gvk, names[i], ns[i]))
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
@@ -5,18 +5,60 @@ package utils
|
||||
|
||||
import "strings"
|
||||
|
||||
// PathSplitter splits a slash delimited string, permitting escaped slashes.
|
||||
func PathSplitter(path string) []string {
|
||||
ps := strings.Split(path, "/")
|
||||
// TODO: Move these to kyaml
|
||||
|
||||
// PathSplitter splits a delimited string, permitting escaped delimiters.
|
||||
func PathSplitter(path string, delimiter string) []string {
|
||||
ps := strings.Split(path, delimiter)
|
||||
var res []string
|
||||
res = append(res, ps[0])
|
||||
for i := 1; i < len(ps); i++ {
|
||||
last := len(res) - 1
|
||||
if strings.HasSuffix(res[last], `\`) {
|
||||
res[last] = strings.TrimSuffix(res[last], `\`) + "/" + ps[i]
|
||||
res[last] = strings.TrimSuffix(res[last], `\`) + delimiter + ps[i]
|
||||
} else {
|
||||
res = append(res, ps[i])
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// SmarterPathSplitter splits a path, retaining bracketed elements.
|
||||
// If the element is a list entry identifier (defined by the '='),
|
||||
// it will retain the brackets.
|
||||
// E.g. "[name=com.foo.someapp]" survives as one thing after splitting
|
||||
// "spec.template.spec.containers.[name=com.foo.someapp].image"
|
||||
// See kyaml/yaml/match.go for use of list entry identifiers.
|
||||
// If the element is a mapping entry identifier, it will remove the
|
||||
// brackets.
|
||||
// E.g. "a.b.c" survives as one thing after splitting
|
||||
// "metadata.annotations.[a.b.c]
|
||||
// This function uses `PathSplitter`, so it also respects escaped delimiters.
|
||||
func SmarterPathSplitter(path string, delimiter string) []string {
|
||||
var result []string
|
||||
split := PathSplitter(path, delimiter)
|
||||
|
||||
for i := 0; i < len(split); i++ {
|
||||
elem := split[i]
|
||||
if strings.HasPrefix(elem, "[") && !strings.HasSuffix(elem, "]") {
|
||||
// continue until we find the matching "]"
|
||||
bracketed := []string{elem}
|
||||
for i < len(split)-1 {
|
||||
i++
|
||||
bracketed = append(bracketed, split[i])
|
||||
if strings.HasSuffix(split[i], "]") {
|
||||
break
|
||||
}
|
||||
}
|
||||
bracketedStr := strings.Join(bracketed, delimiter)
|
||||
if strings.Contains(bracketedStr, "=") {
|
||||
result = append(result, bracketedStr)
|
||||
} else {
|
||||
result = append(result, strings.Trim(bracketedStr, "[]"))
|
||||
}
|
||||
} else {
|
||||
result = append(result, elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -44,6 +44,51 @@ func TestPathSplitter(t *testing.T) {
|
||||
"nginx.ingress.kubernetes.io/auth-secret"},
|
||||
},
|
||||
} {
|
||||
assert.Equal(t, tc.exp, PathSplitter(tc.path))
|
||||
assert.Equal(t, tc.exp, PathSplitter(tc.path, "/"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSmarterPathSplitter(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
input string
|
||||
expected []string
|
||||
}{
|
||||
"simple": {
|
||||
input: "spec.replicas",
|
||||
expected: []string{"spec", "replicas"},
|
||||
},
|
||||
"sequence": {
|
||||
input: "spec.data.[name=first].key",
|
||||
expected: []string{"spec", "data", "[name=first]", "key"},
|
||||
},
|
||||
"key, value with . prefix": {
|
||||
input: "spec.data.[.name=.first].key",
|
||||
expected: []string{"spec", "data", "[.name=.first]", "key"},
|
||||
},
|
||||
"key, value with . suffix": {
|
||||
input: "spec.data.[name.=first.].key",
|
||||
expected: []string{"spec", "data", "[name.=first.]", "key"},
|
||||
},
|
||||
"multiple '.' in value": {
|
||||
input: "spec.data.[name=f.i.r.s.t.].key",
|
||||
expected: []string{"spec", "data", "[name=f.i.r.s.t.]", "key"},
|
||||
},
|
||||
"with escaped delimiter": {
|
||||
input: `spec\.replicas`,
|
||||
expected: []string{`spec.replicas`},
|
||||
},
|
||||
"unmatched bracket": {
|
||||
input: "spec.data.[name=f.i.[r.s.t..key",
|
||||
expected: []string{"spec", "data", "[name=f.i.[r.s.t..key"},
|
||||
},
|
||||
"mapping value with .": {
|
||||
input: "metadata.annotations.[a.b.c/d.e.f-g.]",
|
||||
expected: []string{"metadata", "annotations", "a.b.c/d.e.f-g."},
|
||||
},
|
||||
}
|
||||
for tn, tc := range testCases {
|
||||
t.Run(tn, func(t *testing.T) {
|
||||
assert.Equal(t, tc.expected, SmarterPathSplitter(tc.input, "."))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
44
api/internal/utils/stringslice.go
Normal file
44
api/internal/utils/stringslice.go
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2020 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package utils
|
||||
|
||||
// StringSliceIndex returns the index of the str, else -1.
|
||||
func StringSliceIndex(slice []string, str string) int {
|
||||
for i := range slice {
|
||||
if slice[i] == str {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// StringSliceContains returns true if the slice has the string.
|
||||
func StringSliceContains(slice []string, str string) bool {
|
||||
for _, s := range slice {
|
||||
if s == str {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SameEndingSubSlice returns true if the slices end the same way, e.g.
|
||||
// {"a", "b", "c"}, {"b", "c"} => true
|
||||
// {"a", "b", "c"}, {"a", "b"} => false
|
||||
// If one slice is empty and the other is not, return false.
|
||||
func SameEndingSubSlice(shortest, longest []string) bool {
|
||||
if len(shortest) > len(longest) {
|
||||
longest, shortest = shortest, longest
|
||||
}
|
||||
diff := len(longest) - len(shortest)
|
||||
if len(shortest) == 0 {
|
||||
return diff == 0
|
||||
}
|
||||
for i := len(shortest) - 1; i >= 0; i-- {
|
||||
if longest[i+diff] != shortest[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
37
api/internal/utils/stringslice_test.go
Normal file
37
api/internal/utils/stringslice_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2020 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package utils_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
. "sigs.k8s.io/kustomize/api/internal/utils"
|
||||
)
|
||||
|
||||
func TestStringSliceIndex(t *testing.T) {
|
||||
assert.Equal(t, 0, StringSliceIndex([]string{"a", "b"}, "a"))
|
||||
assert.Equal(t, 1, StringSliceIndex([]string{"a", "b"}, "b"))
|
||||
assert.Equal(t, -1, StringSliceIndex([]string{"a", "b"}, "c"))
|
||||
assert.Equal(t, -1, StringSliceIndex([]string{}, "c"))
|
||||
}
|
||||
|
||||
func TestStringSliceContains(t *testing.T) {
|
||||
assert.True(t, StringSliceContains([]string{"a", "b"}, "a"))
|
||||
assert.True(t, StringSliceContains([]string{"a", "b"}, "b"))
|
||||
assert.False(t, StringSliceContains([]string{"a", "b"}, "c"))
|
||||
assert.False(t, StringSliceContains([]string{}, "c"))
|
||||
}
|
||||
|
||||
func TestSameEndingSubarray(t *testing.T) {
|
||||
assert.True(t, SameEndingSubSlice([]string{"", "a", "b"}, []string{"a", "b"}))
|
||||
assert.True(t, SameEndingSubSlice([]string{"a", "b", ""}, []string{"b", ""}))
|
||||
assert.True(t, SameEndingSubSlice([]string{"a", "b"}, []string{"a", "b"}))
|
||||
assert.True(t, SameEndingSubSlice([]string{"a", "b"}, []string{"b"}))
|
||||
assert.True(t, SameEndingSubSlice([]string{"b"}, []string{"a", "b"}))
|
||||
assert.True(t, SameEndingSubSlice([]string{}, []string{}))
|
||||
assert.False(t, SameEndingSubSlice([]string{"a", "b"}, []string{"b", "a"}))
|
||||
assert.False(t, SameEndingSubSlice([]string{"a", "b"}, []string{}))
|
||||
assert.False(t, SameEndingSubSlice([]string{"a", "b"}, []string{""}))
|
||||
}
|
||||
@@ -3,9 +3,6 @@
|
||||
|
||||
package builtinpluginconsts
|
||||
|
||||
// TODO: rename 'fieldSpecs' to 'referrers' for clarity.
|
||||
// This will, however, break anyone using a custom config.
|
||||
|
||||
const (
|
||||
nameReferenceFieldSpecs = `
|
||||
nameReference:
|
||||
|
||||
@@ -2,5 +2,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package konfig provides configuration methods and constants
|
||||
// for the kustomize API.
|
||||
// for the kustomize API, e.g. the set of file names to look for
|
||||
// to identify a kustomization root.
|
||||
package konfig
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -9,20 +9,20 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"github.com/stretchr/testify/require"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
func TestDefaultAbsPluginHome_NoKustomizePluginHomeEnv(t *testing.T) {
|
||||
fSys := filesys.MakeFsInMemory()
|
||||
keep, isSet := os.LookupEnv(KustomizePluginHomeEnv)
|
||||
if isSet {
|
||||
_ = os.Unsetenv(KustomizePluginHomeEnv)
|
||||
unsetenv(t, KustomizePluginHomeEnv)
|
||||
}
|
||||
_, err := DefaultAbsPluginHome(fSys)
|
||||
if isSet {
|
||||
os.Setenv(KustomizePluginHomeEnv, keep)
|
||||
setenv(t, KustomizePluginHomeEnv, keep)
|
||||
}
|
||||
if err == nil {
|
||||
t.Fatalf("expected err")
|
||||
@@ -43,13 +43,13 @@ func TestDefaultAbsPluginHome_NoKustomizePluginHomeEnv(t *testing.T) {
|
||||
|
||||
func TestDefaultAbsPluginHome_EmptyKustomizePluginHomeEnv(t *testing.T) {
|
||||
keep, isSet := os.LookupEnv(KustomizePluginHomeEnv)
|
||||
os.Setenv(KustomizePluginHomeEnv, "")
|
||||
setenv(t, KustomizePluginHomeEnv, "")
|
||||
|
||||
_, err := DefaultAbsPluginHome(filesys.MakeFsInMemory())
|
||||
if !isSet {
|
||||
_ = os.Unsetenv(KustomizePluginHomeEnv)
|
||||
unsetenv(t, KustomizePluginHomeEnv)
|
||||
} else {
|
||||
_ = os.Setenv(KustomizePluginHomeEnv, keep)
|
||||
setenv(t, KustomizePluginHomeEnv, keep)
|
||||
}
|
||||
if err == nil {
|
||||
t.Fatalf("expected err")
|
||||
@@ -65,16 +65,15 @@ func TestDefaultAbsPluginHome_WithKustomizePluginHomeEnv(t *testing.T) {
|
||||
keep, isSet := os.LookupEnv(KustomizePluginHomeEnv)
|
||||
if !isSet {
|
||||
keep = "whatever"
|
||||
os.Setenv(KustomizePluginHomeEnv, keep)
|
||||
setenv(t, KustomizePluginHomeEnv, keep)
|
||||
}
|
||||
fSys.Mkdir(keep)
|
||||
err := fSys.Mkdir(keep)
|
||||
require.NoError(t, err)
|
||||
h, err := DefaultAbsPluginHome(fSys)
|
||||
if !isSet {
|
||||
_ = os.Unsetenv(KustomizePluginHomeEnv)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
unsetenv(t, KustomizePluginHomeEnv)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
if h != keep {
|
||||
t.Fatalf("unexpected config dir: %s", h)
|
||||
}
|
||||
@@ -85,13 +84,14 @@ func TestDefaultAbsPluginHomeWithXdg(t *testing.T) {
|
||||
keep, isSet := os.LookupEnv(XdgConfigHomeEnv)
|
||||
if !isSet {
|
||||
keep = "whatever"
|
||||
os.Setenv(XdgConfigHomeEnv, keep)
|
||||
setenv(t, XdgConfigHomeEnv, keep)
|
||||
}
|
||||
configDir := filepath.Join(keep, ProgramName, RelPluginHome)
|
||||
fSys.Mkdir(configDir)
|
||||
err := fSys.Mkdir(configDir)
|
||||
require.NoError(t, err)
|
||||
h, err := DefaultAbsPluginHome(fSys)
|
||||
if !isSet {
|
||||
_ = os.Unsetenv(XdgConfigHomeEnv)
|
||||
unsetenv(t, XdgConfigHomeEnv)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
@@ -105,11 +105,11 @@ func TestDefaultAbsPluginHomeNoConfig(t *testing.T) {
|
||||
fSys := filesys.MakeFsInMemory()
|
||||
keep, isSet := os.LookupEnv(XdgConfigHomeEnv)
|
||||
if isSet {
|
||||
_ = os.Unsetenv(XdgConfigHomeEnv)
|
||||
unsetenv(t, XdgConfigHomeEnv)
|
||||
}
|
||||
_, err := DefaultAbsPluginHome(fSys)
|
||||
if isSet {
|
||||
os.Setenv(XdgConfigHomeEnv, keep)
|
||||
setenv(t, XdgConfigHomeEnv, keep)
|
||||
}
|
||||
if err == nil {
|
||||
t.Fatalf("expected err")
|
||||
@@ -121,13 +121,13 @@ func TestDefaultAbsPluginHomeNoConfig(t *testing.T) {
|
||||
|
||||
func TestDefaultAbsPluginHomeEmptyXdgConfig(t *testing.T) {
|
||||
keep, isSet := os.LookupEnv(XdgConfigHomeEnv)
|
||||
os.Setenv(XdgConfigHomeEnv, "")
|
||||
setenv(t, XdgConfigHomeEnv, "")
|
||||
if isSet {
|
||||
_ = os.Unsetenv(XdgConfigHomeEnv)
|
||||
unsetenv(t, XdgConfigHomeEnv)
|
||||
}
|
||||
_, err := DefaultAbsPluginHome(filesys.MakeFsInMemory())
|
||||
if isSet {
|
||||
os.Setenv(XdgConfigHomeEnv, keep)
|
||||
setenv(t, XdgConfigHomeEnv, keep)
|
||||
}
|
||||
if err == nil {
|
||||
t.Fatalf("expected err")
|
||||
@@ -142,14 +142,16 @@ func TestDefaultAbsPluginHomeNoXdgWithDotConfig(t *testing.T) {
|
||||
fSys := filesys.MakeFsInMemory()
|
||||
configDir := filepath.Join(
|
||||
HomeDir(), XdgConfigHomeEnvDefault, ProgramName, RelPluginHome)
|
||||
fSys.Mkdir(configDir)
|
||||
err := fSys.Mkdir(configDir)
|
||||
require.NoError(t, err)
|
||||
keep, isSet := os.LookupEnv(XdgConfigHomeEnv)
|
||||
if isSet {
|
||||
_ = os.Unsetenv(XdgConfigHomeEnv)
|
||||
unsetenv(t, XdgConfigHomeEnv)
|
||||
}
|
||||
s, _ := DefaultAbsPluginHome(fSys)
|
||||
s, err := DefaultAbsPluginHome(fSys)
|
||||
require.NoError(t, err)
|
||||
if isSet {
|
||||
os.Setenv(XdgConfigHomeEnv, keep)
|
||||
setenv(t, XdgConfigHomeEnv, keep)
|
||||
}
|
||||
if s != configDir {
|
||||
t.Fatalf("unexpected config dir: %s", s)
|
||||
@@ -160,16 +162,26 @@ func TestDefaultAbsPluginHomeNoXdgJustHomeDir(t *testing.T) {
|
||||
fSys := filesys.MakeFsInMemory()
|
||||
configDir := filepath.Join(
|
||||
HomeDir(), ProgramName, RelPluginHome)
|
||||
fSys.Mkdir(configDir)
|
||||
err := fSys.Mkdir(configDir)
|
||||
require.NoError(t, err)
|
||||
keep, isSet := os.LookupEnv(XdgConfigHomeEnv)
|
||||
if isSet {
|
||||
_ = os.Unsetenv(XdgConfigHomeEnv)
|
||||
unsetenv(t, XdgConfigHomeEnv)
|
||||
}
|
||||
s, _ := DefaultAbsPluginHome(fSys)
|
||||
s, err := DefaultAbsPluginHome(fSys)
|
||||
require.NoError(t, err)
|
||||
if isSet {
|
||||
os.Setenv(XdgConfigHomeEnv, keep)
|
||||
setenv(t, XdgConfigHomeEnv, keep)
|
||||
}
|
||||
if s != configDir {
|
||||
t.Fatalf("unexpected config dir: %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
func setenv(t *testing.T, key, value string) {
|
||||
require.NoError(t, os.Setenv(key, value))
|
||||
}
|
||||
|
||||
func unsetenv(t *testing.T, key string) {
|
||||
require.NoError(t, os.Unsetenv(key))
|
||||
}
|
||||
|
||||
124
api/krusty/iampolicygenerator_test.go
Normal file
124
api/krusty/iampolicygenerator_test.go
Normal file
@@ -0,0 +1,124 @@
|
||||
package krusty_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||
)
|
||||
|
||||
func TestGkeGenerator(t *testing.T) {
|
||||
th := kusttest_test.MakeEnhancedHarness(t)
|
||||
defer th.Reset()
|
||||
|
||||
th.WriteK(".", `
|
||||
generators:
|
||||
- |-
|
||||
apiVersion: builtin
|
||||
kind: IAMPolicyGenerator
|
||||
metadata:
|
||||
name: my-gke-generator
|
||||
cloud: gke
|
||||
kubernetesService:
|
||||
name: k8s-sa-name
|
||||
serviceAccount:
|
||||
name: gsa-name
|
||||
projectId: project-id
|
||||
`)
|
||||
expected := `
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
annotations:
|
||||
iam.gke.io/gcp-service-account: gsa-name@project-id.iam.gserviceaccount.com
|
||||
name: k8s-sa-name
|
||||
`
|
||||
m := th.Run(".", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, expected)
|
||||
}
|
||||
|
||||
func TestGkeGeneratorWithNamespace(t *testing.T) {
|
||||
th := kusttest_test.MakeEnhancedHarness(t)
|
||||
defer th.Reset()
|
||||
|
||||
th.WriteK(".", `
|
||||
generators:
|
||||
- |-
|
||||
apiVersion: builtin
|
||||
kind: IAMPolicyGenerator
|
||||
metadata:
|
||||
name: my-gke-generator
|
||||
cloud: gke
|
||||
kubernetesService:
|
||||
namespace: k8s-namespace
|
||||
name: k8s-sa-name
|
||||
serviceAccount:
|
||||
name: gsa-name
|
||||
projectId: project-id
|
||||
`)
|
||||
expected := `
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
annotations:
|
||||
iam.gke.io/gcp-service-account: gsa-name@project-id.iam.gserviceaccount.com
|
||||
name: k8s-sa-name
|
||||
namespace: k8s-namespace
|
||||
`
|
||||
m := th.Run(".", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, expected)
|
||||
}
|
||||
|
||||
func TestGkeGeneratorWithTwo(t *testing.T) {
|
||||
th := kusttest_test.MakeEnhancedHarness(t)
|
||||
defer th.Reset()
|
||||
|
||||
th.WriteK(".", `
|
||||
generators:
|
||||
- gkegenerator1.yaml
|
||||
- gkegenerator2.yaml
|
||||
`)
|
||||
|
||||
th.WriteF("gkegenerator1.yaml", `
|
||||
apiVersion: builtin
|
||||
kind: IAMPolicyGenerator
|
||||
metadata:
|
||||
name: my-gke-generator1
|
||||
cloud: gke
|
||||
kubernetesService:
|
||||
namespace: k8s-namespace-1
|
||||
name: k8s-sa-name-1
|
||||
serviceAccount:
|
||||
name: gsa-name-1
|
||||
projectId: project-id-1
|
||||
`)
|
||||
th.WriteF("gkegenerator2.yaml", `
|
||||
apiVersion: builtin
|
||||
kind: IAMPolicyGenerator
|
||||
metadata:
|
||||
name: my-gke-generator2
|
||||
cloud: gke
|
||||
kubernetesService:
|
||||
name: k8s-sa-name-2
|
||||
serviceAccount:
|
||||
name: gsa-name-2
|
||||
projectId: project-id-2
|
||||
`)
|
||||
expected := `
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
annotations:
|
||||
iam.gke.io/gcp-service-account: gsa-name-1@project-id-1.iam.gserviceaccount.com
|
||||
name: k8s-sa-name-1
|
||||
namespace: k8s-namespace-1
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
annotations:
|
||||
iam.gke.io/gcp-service-account: gsa-name-2@project-id-2.iam.gserviceaccount.com
|
||||
name: k8s-sa-name-2
|
||||
`
|
||||
m := th.Run(".", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, expected)
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/builtins"
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader"
|
||||
"sigs.k8s.io/kustomize/api/internal/target"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
@@ -17,6 +16,7 @@ import (
|
||||
"sigs.k8s.io/kustomize/api/provider"
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
"sigs.k8s.io/kustomize/kyaml/openapi"
|
||||
)
|
||||
|
||||
@@ -90,19 +90,25 @@ func (b *Kustomizer) Run(
|
||||
return nil, err
|
||||
}
|
||||
if b.options.DoLegacyResourceSort {
|
||||
builtins.NewLegacyOrderTransformerPlugin().Transform(m)
|
||||
err = builtins.NewLegacyOrderTransformerPlugin().Transform(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if b.options.AddManagedbyLabel {
|
||||
t := builtins.LabelTransformerPlugin{
|
||||
Labels: map[string]string{
|
||||
konfig.ManagedbyLabelKey: fmt.Sprintf(
|
||||
"kustomize-%s", provenance.GetProvenance().Semver())},
|
||||
konfig.ManagedbyLabelKey: fmt.Sprintf("kustomize-%s", provenance.GetProvenance().Semver()),
|
||||
},
|
||||
FieldSpecs: []types.FieldSpec{{
|
||||
Path: "metadata/labels",
|
||||
CreateIfNotPresent: true,
|
||||
}},
|
||||
}
|
||||
t.Transform(m)
|
||||
err = t.Transform(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
m.RemoveBuildAnnotations()
|
||||
return m, nil
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/krusty"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
// A simple usage example to shows what happens when
|
||||
|
||||
@@ -6,9 +6,319 @@ package krusty_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||
)
|
||||
|
||||
func TestPatchesInOneFile(t *testing.T) {
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
th.WriteK("base", `
|
||||
resources:
|
||||
- namespace.yaml
|
||||
- deployment-controller-manager.yaml
|
||||
- deployment-audit-manager.yaml
|
||||
`)
|
||||
th.WriteF("base/namespace.yaml", `
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
labels:
|
||||
control-plane: controller-manager
|
||||
admission.gatekeeper.sh/ignore: no-self-managing
|
||||
name: system
|
||||
`)
|
||||
th.WriteF("base/deployment-controller-manager.yaml", `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: controller-manager
|
||||
namespace: system
|
||||
labels:
|
||||
control-plane: controller-manager
|
||||
gatekeeper.sh/operation: webhook
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
control-plane: controller-manager
|
||||
gatekeeper.sh/operation: webhook
|
||||
replicas: 3
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
container.seccomp.security.alpha.kubernetes.io/manager: runtime/default
|
||||
labels:
|
||||
control-plane: controller-manager
|
||||
gatekeeper.sh/operation: webhook
|
||||
spec:
|
||||
containers:
|
||||
- command:
|
||||
- /manager
|
||||
args:
|
||||
- "--port=8443"
|
||||
- "--logtostderr"
|
||||
- "--exempt-namespace=gatekeeper-system"
|
||||
- "--operation=webhook"
|
||||
image: openpolicyagent/gatekeeper:v3.4.0
|
||||
imagePullPolicy: Always
|
||||
name: manager
|
||||
terminationGracePeriodSeconds: 60
|
||||
nodeSelector:
|
||||
kubernetes.io/os: linux
|
||||
priorityClassName: system-cluster-critical
|
||||
`)
|
||||
th.WriteF("base/deployment-audit-manager.yaml", `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: audit
|
||||
namespace: system
|
||||
labels:
|
||||
control-plane: audit-controller
|
||||
gatekeeper.sh/operation: audit
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
control-plane: audit-controller
|
||||
gatekeeper.sh/operation: audit
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
control-plane: audit-controller
|
||||
gatekeeper.sh/operation: audit
|
||||
annotations:
|
||||
container.seccomp.security.alpha.kubernetes.io/manager: runtime/default
|
||||
spec:
|
||||
automountServiceAccountToken: true
|
||||
containers:
|
||||
- args:
|
||||
- --operation=audit
|
||||
- --operation=status
|
||||
- --logtostderr
|
||||
command:
|
||||
- /manager
|
||||
env:
|
||||
- name: POD_NAMESPACE
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
apiVersion: v1
|
||||
fieldPath: metadata.namespace
|
||||
- name: POD_NAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
image: openpolicyagent/gatekeeper:v3.4.0
|
||||
imagePullPolicy: Always
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /healthz
|
||||
port: 9090
|
||||
name: manager
|
||||
serviceAccountName: gatekeeper-admin
|
||||
terminationGracePeriodSeconds: 60
|
||||
nodeSelector:
|
||||
kubernetes.io/os: linux
|
||||
priorityClassName: system-cluster-critical
|
||||
`)
|
||||
const imagePatchAuditManager = `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: audit
|
||||
namespace: system
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- image: AUDIT_IMAGE
|
||||
name: manager
|
||||
args:
|
||||
- --port=8443
|
||||
- --logtostderr
|
||||
- --emit-admission-events
|
||||
- --exempt-namespace=gatekeeper-system
|
||||
- --operation=webhook
|
||||
- --disable-opa-builtin=http.send
|
||||
`
|
||||
const imagePatchControllerManager = `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: controller-manager
|
||||
namespace: system
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- image: CONTROLLER_IMAGE
|
||||
name: manager
|
||||
args:
|
||||
- --emit-audit-events
|
||||
- --operation=audit
|
||||
- --operation=status
|
||||
- --logtostderr
|
||||
`
|
||||
th.WriteF(
|
||||
"overlay/image_patch_audit_manager.yaml",
|
||||
imagePatchAuditManager)
|
||||
th.WriteF(
|
||||
"overlay/image_patch_controller_manager.yaml",
|
||||
imagePatchControllerManager)
|
||||
const expected = `
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
labels:
|
||||
admission.gatekeeper.sh/ignore: no-self-managing
|
||||
control-plane: controller-manager
|
||||
name: system
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
control-plane: controller-manager
|
||||
gatekeeper.sh/operation: webhook
|
||||
name: controller-manager
|
||||
namespace: system
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
control-plane: controller-manager
|
||||
gatekeeper.sh/operation: webhook
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
container.seccomp.security.alpha.kubernetes.io/manager: runtime/default
|
||||
labels:
|
||||
control-plane: controller-manager
|
||||
gatekeeper.sh/operation: webhook
|
||||
spec:
|
||||
containers:
|
||||
- args:
|
||||
- --emit-audit-events
|
||||
- --operation=audit
|
||||
- --operation=status
|
||||
- --logtostderr
|
||||
command:
|
||||
- /manager
|
||||
image: CONTROLLER_IMAGE
|
||||
imagePullPolicy: Always
|
||||
name: manager
|
||||
nodeSelector:
|
||||
kubernetes.io/os: linux
|
||||
priorityClassName: system-cluster-critical
|
||||
terminationGracePeriodSeconds: 60
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
control-plane: audit-controller
|
||||
gatekeeper.sh/operation: audit
|
||||
name: audit
|
||||
namespace: system
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
control-plane: audit-controller
|
||||
gatekeeper.sh/operation: audit
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
container.seccomp.security.alpha.kubernetes.io/manager: runtime/default
|
||||
labels:
|
||||
control-plane: audit-controller
|
||||
gatekeeper.sh/operation: audit
|
||||
spec:
|
||||
automountServiceAccountToken: true
|
||||
containers:
|
||||
- args:
|
||||
- --port=8443
|
||||
- --logtostderr
|
||||
- --emit-admission-events
|
||||
- --exempt-namespace=gatekeeper-system
|
||||
- --operation=webhook
|
||||
- --disable-opa-builtin=http.send
|
||||
command:
|
||||
- /manager
|
||||
env:
|
||||
- name: POD_NAMESPACE
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
apiVersion: v1
|
||||
fieldPath: metadata.namespace
|
||||
- name: POD_NAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
image: AUDIT_IMAGE
|
||||
imagePullPolicy: Always
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /healthz
|
||||
port: 9090
|
||||
name: manager
|
||||
nodeSelector:
|
||||
kubernetes.io/os: linux
|
||||
priorityClassName: system-cluster-critical
|
||||
serviceAccountName: gatekeeper-admin
|
||||
terminationGracePeriodSeconds: 60
|
||||
`
|
||||
// Technique 1: "patchesStrategicMerge:" field, two patch files.
|
||||
th.WriteK("overlay", `
|
||||
resources:
|
||||
- ../base
|
||||
patchesStrategicMerge:
|
||||
- image_patch_controller_manager.yaml
|
||||
- image_patch_audit_manager.yaml
|
||||
`)
|
||||
m := th.Run("overlay", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, expected)
|
||||
|
||||
// Technique 2: "patches:" field, two patch files.
|
||||
th.WriteK("overlay", `
|
||||
resources:
|
||||
- ../base
|
||||
patches:
|
||||
- path: image_patch_controller_manager.yaml
|
||||
- path: image_patch_audit_manager.yaml
|
||||
`)
|
||||
m = th.Run("overlay", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, expected)
|
||||
|
||||
// Technique 3: "patchesStrategicMerge:" field, one patch file.
|
||||
th.WriteK("overlay", `
|
||||
resources:
|
||||
- ../base
|
||||
patchesStrategicMerge:
|
||||
- twoPatchesInOneFile.yaml
|
||||
`)
|
||||
th.WriteF(
|
||||
"overlay/twoPatchesInOneFile.yaml",
|
||||
imagePatchAuditManager+"\n---\n"+imagePatchControllerManager)
|
||||
m = th.Run("overlay", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, expected)
|
||||
|
||||
// Technique 4: "patches:" field, one patch file. Fails.
|
||||
th.WriteK("overlay", `
|
||||
resources:
|
||||
- ../base
|
||||
patches:
|
||||
- path: twoPatchesInOneFile.yaml
|
||||
`)
|
||||
err := th.RunWithErr("overlay", th.MakeDefaultOptions())
|
||||
assert.Error(t, err)
|
||||
// This should fail, because the semantics of the `patches` field.
|
||||
// That field allows specific patch targeting to a list of targets,
|
||||
// while the `patchesStrategicMerge` field accepts patches that
|
||||
// implicitly identify their targets via GVKN.
|
||||
assert.Contains(t, err.Error(), "unable to parse SM or JSON patch from ")
|
||||
}
|
||||
|
||||
func TestRemoveEmptyDirWithNullFieldInSmp(t *testing.T) {
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
th.WriteK(".", `
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
// The PrintPluginEnv plugin is a toy plugin that emits
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/internal/utils"
|
||||
"sigs.k8s.io/kustomize/api/krusty"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
func TestRemoteLoad(t *testing.T) {
|
||||
|
||||
@@ -261,3 +261,84 @@ spec:
|
||||
name: nginx
|
||||
`)
|
||||
}
|
||||
|
||||
func TestReplacementTransformerWithOriginalName(t *testing.T) {
|
||||
th := kusttest_test.MakeEnhancedHarness(t)
|
||||
defer th.Reset()
|
||||
|
||||
th.WriteF("base/deployments.yaml", `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: target
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:oldtag
|
||||
name: nginx
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: source
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:newtag
|
||||
name: nginx
|
||||
`)
|
||||
th.WriteK("base", `
|
||||
resources:
|
||||
- deployments.yaml
|
||||
`)
|
||||
th.WriteK("overlay", `
|
||||
namePrefix: prefix1-
|
||||
resources:
|
||||
- ../base
|
||||
`)
|
||||
|
||||
th.WriteK(".", `
|
||||
namePrefix: prefix2-
|
||||
resources:
|
||||
- overlay
|
||||
replacements:
|
||||
- path: replacement.yaml
|
||||
`)
|
||||
th.WriteF("replacement.yaml", `
|
||||
source:
|
||||
name: source
|
||||
fieldPath: spec.template.spec.containers.0.image
|
||||
targets:
|
||||
- select:
|
||||
name: prefix1-target
|
||||
fieldPaths:
|
||||
- spec.template.spec.containers.[name=nginx].image
|
||||
`)
|
||||
|
||||
m := th.Run(".", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: prefix2-prefix1-target
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:newtag
|
||||
name: nginx
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: prefix2-prefix1-source
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:newtag
|
||||
name: nginx
|
||||
`)
|
||||
}
|
||||
|
||||
@@ -7,10 +7,11 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"github.com/stretchr/testify/require"
|
||||
ldr "sigs.k8s.io/kustomize/api/loader"
|
||||
valtest_test "sigs.k8s.io/kustomize/api/testutils/valtest"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
func makeKvLoader(fSys filesys.FileSystem) *loader {
|
||||
@@ -83,7 +84,8 @@ func TestKeyValuesFromFileSources(t *testing.T) {
|
||||
}
|
||||
|
||||
fSys := filesys.MakeFsInMemory()
|
||||
fSys.WriteFile("/files/app-init.ini", []byte("FOO=bar"))
|
||||
err := fSys.WriteFile("/files/app-init.ini", []byte("FOO=bar"))
|
||||
require.NoError(t, err)
|
||||
kvl := makeKvLoader(fSys)
|
||||
for _, tc := range tests {
|
||||
kvs, err := kvl.keyValuesFromFileSources(tc.sources)
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/ifc"
|
||||
"sigs.k8s.io/kustomize/api/internal/git"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
// fileLoader is a kustomization's interface to files.
|
||||
|
||||
@@ -14,10 +14,10 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/ifc"
|
||||
"sigs.k8s.io/kustomize/api/internal/git"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
type testData struct {
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
package loader
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/ifc"
|
||||
"sigs.k8s.io/kustomize/api/internal/git"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
// NewLoader returns a Loader pointed at the given target.
|
||||
|
||||
@@ -6,7 +6,7 @@ package loader
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
type LoadRestrictorFunc func(
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
func TestRestrictionNone(t *testing.T) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/ifc"
|
||||
"sigs.k8s.io/kustomize/api/kv"
|
||||
"sigs.k8s.io/kustomize/api/loader"
|
||||
@@ -16,6 +15,7 @@ import (
|
||||
resmaptest_test "sigs.k8s.io/kustomize/api/testutils/resmaptest"
|
||||
valtest_test "sigs.k8s.io/kustomize/api/testutils/valtest"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
|
||||
@@ -22,6 +22,12 @@ import (
|
||||
// Factory makes instances of Resource.
|
||||
type Factory struct {
|
||||
hasher ifc.KustHasher
|
||||
|
||||
// When set to true, IncludeLocalConfigs indicates
|
||||
// that Factory should include resources with the
|
||||
// annotation 'config.kubernetes.io/local-config'.
|
||||
// By default these resources are ignored.
|
||||
IncludeLocalConfigs bool
|
||||
}
|
||||
|
||||
// NewFactory makes an instance of Factory.
|
||||
@@ -221,13 +227,15 @@ func (rf *Factory) shouldIgnore(n *yaml.RNode) (bool, error) {
|
||||
if n.IsNilOrEmpty() {
|
||||
return true, nil
|
||||
}
|
||||
md, err := n.GetValidatedMetadata()
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
_, ignore := md.ObjectMeta.Annotations[konfig.IgnoredByKustomizeAnnotation]
|
||||
if ignore {
|
||||
return true, nil
|
||||
if !rf.IncludeLocalConfigs {
|
||||
md, err := n.GetValidatedMetadata()
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
_, ignore := md.ObjectMeta.Annotations[konfig.IgnoredByKustomizeAnnotation]
|
||||
if ignore {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
if foundNil, path := n.HasNilEntryInList(); foundNil {
|
||||
return true, fmt.Errorf("empty item at %v in object %v", path, n)
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/loader"
|
||||
. "sigs.k8s.io/kustomize/api/resource"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
func TestSliceFromBytes(t *testing.T) {
|
||||
|
||||
@@ -4,14 +4,13 @@
|
||||
package resource
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filters/patchstrategicmerge"
|
||||
"sigs.k8s.io/kustomize/api/ifc"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
"sigs.k8s.io/kustomize/api/internal/utils"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
"sigs.k8s.io/kustomize/kyaml/resid"
|
||||
@@ -28,28 +27,14 @@ type Resource struct {
|
||||
refVarNames []string
|
||||
}
|
||||
|
||||
const (
|
||||
buildAnnotationPreviousKinds = konfig.ConfigAnnoDomain + "/previousKinds"
|
||||
buildAnnotationPreviousNames = konfig.ConfigAnnoDomain + "/previousNames"
|
||||
buildAnnotationPrefixes = konfig.ConfigAnnoDomain + "/prefixes"
|
||||
buildAnnotationSuffixes = konfig.ConfigAnnoDomain + "/suffixes"
|
||||
buildAnnotationPreviousNamespaces = konfig.ConfigAnnoDomain + "/previousNamespaces"
|
||||
|
||||
// the following are only for patches, to specify whether they can change names
|
||||
// and kinds of their targets
|
||||
buildAnnotationAllowNameChange = konfig.ConfigAnnoDomain + "/allowNameChange"
|
||||
buildAnnotationAllowKindChange = konfig.ConfigAnnoDomain + "/allowKindChange"
|
||||
allowed = "allowed"
|
||||
)
|
||||
|
||||
var buildAnnotations = []string{
|
||||
buildAnnotationPreviousKinds,
|
||||
buildAnnotationPreviousNames,
|
||||
buildAnnotationPrefixes,
|
||||
buildAnnotationSuffixes,
|
||||
buildAnnotationPreviousNamespaces,
|
||||
buildAnnotationAllowNameChange,
|
||||
buildAnnotationAllowKindChange,
|
||||
var BuildAnnotations = []string{
|
||||
utils.BuildAnnotationPreviousKinds,
|
||||
utils.BuildAnnotationPreviousNames,
|
||||
utils.BuildAnnotationPrefixes,
|
||||
utils.BuildAnnotationSuffixes,
|
||||
utils.BuildAnnotationPreviousNamespaces,
|
||||
utils.BuildAnnotationAllowNameChange,
|
||||
utils.BuildAnnotationAllowKindChange,
|
||||
}
|
||||
|
||||
func (r *Resource) ResetRNode(incoming *Resource) {
|
||||
@@ -191,12 +176,12 @@ func copyStringSlice(s []string) []string {
|
||||
|
||||
// Implements ResCtx AddNamePrefix
|
||||
func (r *Resource) AddNamePrefix(p string) {
|
||||
r.appendCsvAnnotation(buildAnnotationPrefixes, p)
|
||||
r.appendCsvAnnotation(utils.BuildAnnotationPrefixes, p)
|
||||
}
|
||||
|
||||
// Implements ResCtx AddNameSuffix
|
||||
func (r *Resource) AddNameSuffix(s string) {
|
||||
r.appendCsvAnnotation(buildAnnotationSuffixes, s)
|
||||
r.appendCsvAnnotation(utils.BuildAnnotationSuffixes, s)
|
||||
}
|
||||
|
||||
func (r *Resource) appendCsvAnnotation(name, value string) {
|
||||
@@ -214,30 +199,14 @@ func (r *Resource) appendCsvAnnotation(name, value string) {
|
||||
}
|
||||
}
|
||||
|
||||
func SameEndingSubarray(shortest, longest []string) bool {
|
||||
if len(shortest) > len(longest) {
|
||||
longest, shortest = shortest, longest
|
||||
}
|
||||
diff := len(longest) - len(shortest)
|
||||
if len(shortest) == 0 {
|
||||
return diff == 0
|
||||
}
|
||||
for i := len(shortest) - 1; i >= 0; i-- {
|
||||
if longest[i+diff] != shortest[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Implements ResCtx GetNamePrefixes
|
||||
func (r *Resource) GetNamePrefixes() []string {
|
||||
return r.getCsvAnnotation(buildAnnotationPrefixes)
|
||||
return r.getCsvAnnotation(utils.BuildAnnotationPrefixes)
|
||||
}
|
||||
|
||||
// Implements ResCtx GetNameSuffixes
|
||||
func (r *Resource) GetNameSuffixes() []string {
|
||||
return r.getCsvAnnotation(buildAnnotationSuffixes)
|
||||
return r.getCsvAnnotation(utils.BuildAnnotationSuffixes)
|
||||
}
|
||||
|
||||
func (r *Resource) getCsvAnnotation(name string) []string {
|
||||
@@ -252,7 +221,8 @@ func (r *Resource) getCsvAnnotation(name string) []string {
|
||||
// as OutermostPrefixSuffix but performs a deeper comparison
|
||||
// of the suffix and prefix slices.
|
||||
func (r *Resource) PrefixesSuffixesEquals(o ResCtx) bool {
|
||||
return SameEndingSubarray(r.GetNamePrefixes(), o.GetNamePrefixes()) && SameEndingSubarray(r.GetNameSuffixes(), o.GetNameSuffixes())
|
||||
return utils.SameEndingSubSlice(r.GetNamePrefixes(), o.GetNamePrefixes()) &&
|
||||
utils.SameEndingSubSlice(r.GetNameSuffixes(), o.GetNameSuffixes())
|
||||
}
|
||||
|
||||
// RemoveBuildAnnotations removes annotations created by the build process.
|
||||
@@ -263,7 +233,7 @@ func (r *Resource) RemoveBuildAnnotations() {
|
||||
if len(annotations) == 0 {
|
||||
return
|
||||
}
|
||||
for _, a := range buildAnnotations {
|
||||
for _, a := range BuildAnnotations {
|
||||
delete(annotations, a)
|
||||
}
|
||||
if err := r.SetAnnotations(annotations); err != nil {
|
||||
@@ -272,16 +242,16 @@ func (r *Resource) RemoveBuildAnnotations() {
|
||||
}
|
||||
|
||||
func (r *Resource) setPreviousId(ns string, n string, k string) *Resource {
|
||||
r.appendCsvAnnotation(buildAnnotationPreviousNames, n)
|
||||
r.appendCsvAnnotation(buildAnnotationPreviousNamespaces, ns)
|
||||
r.appendCsvAnnotation(buildAnnotationPreviousKinds, k)
|
||||
r.appendCsvAnnotation(utils.BuildAnnotationPreviousNames, n)
|
||||
r.appendCsvAnnotation(utils.BuildAnnotationPreviousNamespaces, ns)
|
||||
r.appendCsvAnnotation(utils.BuildAnnotationPreviousKinds, k)
|
||||
return r
|
||||
}
|
||||
|
||||
// AllowNameChange allows name changes to the resource.
|
||||
func (r *Resource) AllowNameChange() {
|
||||
annotations := r.GetAnnotations()
|
||||
annotations[buildAnnotationAllowNameChange] = allowed
|
||||
annotations[utils.BuildAnnotationAllowNameChange] = utils.Allowed
|
||||
if err := r.SetAnnotations(annotations); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -289,14 +259,14 @@ func (r *Resource) AllowNameChange() {
|
||||
|
||||
func (r *Resource) NameChangeAllowed() bool {
|
||||
annotations := r.GetAnnotations()
|
||||
v, ok := annotations[buildAnnotationAllowNameChange]
|
||||
return ok && v == allowed
|
||||
v, ok := annotations[utils.BuildAnnotationAllowNameChange]
|
||||
return ok && v == utils.Allowed
|
||||
}
|
||||
|
||||
// AllowKindChange allows kind changes to the resource.
|
||||
func (r *Resource) AllowKindChange() {
|
||||
annotations := r.GetAnnotations()
|
||||
annotations[buildAnnotationAllowKindChange] = allowed
|
||||
annotations[utils.BuildAnnotationAllowKindChange] = utils.Allowed
|
||||
if err := r.SetAnnotations(annotations); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -304,8 +274,8 @@ func (r *Resource) AllowKindChange() {
|
||||
|
||||
func (r *Resource) KindChangeAllowed() bool {
|
||||
annotations := r.GetAnnotations()
|
||||
v, ok := annotations[buildAnnotationAllowKindChange]
|
||||
return ok && v == allowed
|
||||
v, ok := annotations[utils.BuildAnnotationAllowKindChange]
|
||||
return ok && v == utils.Allowed
|
||||
}
|
||||
|
||||
// String returns resource as JSON.
|
||||
@@ -369,26 +339,12 @@ func (r *Resource) OrgId() resid.ResId {
|
||||
// The returned array does not include the resource's current
|
||||
// ID. If there are no previous IDs, this will return nil.
|
||||
func (r *Resource) PrevIds() []resid.ResId {
|
||||
var ids []resid.ResId
|
||||
// TODO: merge previous names and namespaces into one list of
|
||||
// pairs on one annotation so there is no chance of error
|
||||
names := r.getCsvAnnotation(buildAnnotationPreviousNames)
|
||||
ns := r.getCsvAnnotation(buildAnnotationPreviousNamespaces)
|
||||
kinds := r.getCsvAnnotation(buildAnnotationPreviousKinds)
|
||||
if len(names) != len(ns) || len(names) != len(kinds) {
|
||||
panic(errors.New(
|
||||
"number of previous names, " +
|
||||
"number of previous namespaces, " +
|
||||
"number of previous kinds not equal"))
|
||||
prevIds, err := utils.PrevIds(&r.RNode)
|
||||
if err != nil {
|
||||
// this should never happen
|
||||
panic(err)
|
||||
}
|
||||
for i := range names {
|
||||
k := kinds[i]
|
||||
gvk := r.GetGvk()
|
||||
gvk.Kind = k
|
||||
ids = append(ids, resid.NewResIdWithNamespace(
|
||||
gvk, names[i], ns[i]))
|
||||
}
|
||||
return ids
|
||||
return prevIds
|
||||
}
|
||||
|
||||
// StorePreviousId stores the resource's current ID via build annotations.
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sigs.k8s.io/kustomize/api/internal/utils"
|
||||
"sigs.k8s.io/kustomize/api/provider"
|
||||
. "sigs.k8s.io/kustomize/api/resource"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
@@ -1077,7 +1078,7 @@ func TestSameEndingSubarray(t *testing.T) {
|
||||
for n := range testCases {
|
||||
tc := testCases[n]
|
||||
t.Run(n, func(t *testing.T) {
|
||||
assert.Equal(t, tc.expected, SameEndingSubarray(tc.a, tc.b))
|
||||
assert.Equal(t, tc.expected, utils.SameEndingSubSlice(tc.a, tc.b))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
"sigs.k8s.io/kustomize/api/konfig/builtinpluginconsts"
|
||||
"sigs.k8s.io/kustomize/api/krusty"
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
// Harness manages a test environment.
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/ifc"
|
||||
pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
@@ -20,6 +19,7 @@ import (
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
valtest_test "sigs.k8s.io/kustomize/api/testutils/valtest"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
// HarnessEnhanced manages a full plugin environment for tests.
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/compiler"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
// pluginTestEnv manages compiling plugins for tests.
|
||||
|
||||
@@ -39,7 +39,7 @@ func (g *GenArgs) ShouldAddHashSuffixToName() bool {
|
||||
|
||||
// Behavior returns Behavior field of GeneratorArgs
|
||||
func (g *GenArgs) Behavior() GenerationBehavior {
|
||||
if g.args == nil {
|
||||
if g == nil || g.args == nil {
|
||||
return BehaviorUnspecified
|
||||
}
|
||||
return NewGenerationBehavior(g.args.Behavior)
|
||||
|
||||
@@ -68,6 +68,10 @@ type HelmChart struct {
|
||||
// Legal values: 'merge', 'override', 'replace'.
|
||||
// Defaults to 'override'.
|
||||
ValuesMerge string `json:"valuesMerge,omitempty" yaml:"valuesMerge,omitempty"`
|
||||
|
||||
// IncludeCRDs specifies if Helm should also generate CustomResourceDefinitions.
|
||||
// Defaults to 'false'.
|
||||
IncludeCRDs bool `json:"includeCRDs,omitempty" yaml:"includeCRDs,omitempty"`
|
||||
}
|
||||
|
||||
// HelmChartArgs contains arguments to helm.
|
||||
|
||||
36
api/types/iampolicygenerator.go
Normal file
36
api/types/iampolicygenerator.go
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package types
|
||||
|
||||
type Cloud string
|
||||
|
||||
const GKE Cloud = "gke"
|
||||
|
||||
// IAMPolicyGeneratorArgs contains arguments to generate a GKE service account resource.
|
||||
type IAMPolicyGeneratorArgs struct {
|
||||
// which cloud provider to generate for (e.g. "gke")
|
||||
Cloud `json:"cloud" yaml:"cloud"`
|
||||
|
||||
// information about the kubernetes cluster for this object
|
||||
KubernetesService `json:"kubernetesService" yaml:"kubernetesService"`
|
||||
|
||||
// information about the service account and project
|
||||
ServiceAccount `json:"serviceAccount" yaml:"serviceAccount"`
|
||||
}
|
||||
|
||||
type KubernetesService struct {
|
||||
// the name used for the Kubernetes service account
|
||||
Name string `json:"name" yaml:"name"`
|
||||
|
||||
// the name of the Kubernetes namespace for this object
|
||||
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
|
||||
}
|
||||
|
||||
type ServiceAccount struct {
|
||||
// the name of the new cloud provider service account
|
||||
Name string `json:"name" yaml:"name"`
|
||||
|
||||
// The ID of the project
|
||||
ProjectId string `json:"projectId" yaml:"projectId"`
|
||||
}
|
||||
@@ -42,7 +42,7 @@ const (
|
||||
BploLoadFromFileSys
|
||||
)
|
||||
|
||||
// FnPluginLoadingOptions set way functions-based pluing are restricted
|
||||
// FnPluginLoadingOptions set way functions-based plugins are restricted
|
||||
type FnPluginLoadingOptions struct {
|
||||
// Allow to run executables
|
||||
EnableExec bool
|
||||
@@ -55,4 +55,6 @@ type FnPluginLoadingOptions struct {
|
||||
Mounts []string
|
||||
// list of env variables to pass to fn
|
||||
Env []string
|
||||
// Run as uid and gid of the command executor
|
||||
AsCurrentUser bool
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@ type SourceSelector struct {
|
||||
resid.ResId `json:",inline,omitempty" yaml:",inline,omitempty"`
|
||||
|
||||
// Structured field path expected in the allowed object.
|
||||
FieldPath string `json:"fieldPath" yaml:"fieldPath"`
|
||||
FieldPath string `json:"fieldPath,omitempty" yaml:"fieldPath,omitempty"`
|
||||
|
||||
// Used to refine the interpretation of the field.
|
||||
Options *FieldOptions `json:"options" yaml:"options"`
|
||||
Options *FieldOptions `json:"options,omitempty" yaml:"options,omitempty"`
|
||||
}
|
||||
|
||||
func (s *SourceSelector) String() string {
|
||||
@@ -54,34 +54,34 @@ type TargetSelector struct {
|
||||
Select *Selector `json:"select" yaml:"select"`
|
||||
|
||||
// From the allowed set, remove objects that match this.
|
||||
Reject []*Selector `json:"reject" yaml:"reject"`
|
||||
Reject []*Selector `json:"reject,omitempty" yaml:"reject,omitempty"`
|
||||
|
||||
// Structured field paths expected in each allowed object.
|
||||
FieldPaths []string `json:"fieldPaths" yaml:"fieldPaths"`
|
||||
FieldPaths []string `json:"fieldPaths,omitempty" yaml:"fieldPaths,omitempty"`
|
||||
|
||||
// Used to refine the interpretation of the field.
|
||||
Options *FieldOptions `json:"options" yaml:"options"`
|
||||
Options *FieldOptions `json:"options,omitempty" yaml:"options,omitempty"`
|
||||
}
|
||||
|
||||
// FieldOptions refine the interpretation of FieldPaths.
|
||||
type FieldOptions struct {
|
||||
// Used to split/join the field.
|
||||
Delimiter string `json:"delimiter" yaml:"delimiter"`
|
||||
Delimiter string `json:"delimiter,omitempty" yaml:"delimiter,omitempty"`
|
||||
|
||||
// Which position in the split to consider.
|
||||
Index int `json:"index" yaml:"index"`
|
||||
Index int `json:"index,omitempty" yaml:"index,omitempty"`
|
||||
|
||||
// TODO (#3492): Implement use of this option
|
||||
// None, Base64, URL, Hex, etc
|
||||
Encoding string `json:"encoding" yaml:"encoding"`
|
||||
Encoding string `json:"encoding,omitempty" yaml:"encoding,omitempty"`
|
||||
|
||||
// If field missing, add it.
|
||||
Create bool `json:"create" yaml:"create"`
|
||||
Create bool `json:"create,omitempty" yaml:"create,omitempty"`
|
||||
}
|
||||
|
||||
func (fo *FieldOptions) String() string {
|
||||
if fo == nil || fo.Delimiter == "" {
|
||||
if fo == nil || (fo.Delimiter == "" && !fo.Create) {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%s(%d)", fo.Delimiter, fo.Index)
|
||||
return fmt.Sprintf("%s(%d), create=%t", fo.Delimiter, fo.Index, fo.Create)
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@ type Selector struct {
|
||||
LabelSelector string `json:"labelSelector,omitempty" yaml:"labelSelector,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Selector) Copy() Selector {
|
||||
return *s
|
||||
}
|
||||
|
||||
func (s *Selector) String() string {
|
||||
return fmt.Sprintf(
|
||||
"%s:a=%s:l=%s", s.ResId, s.AnnotationSelector, s.LabelSelector)
|
||||
|
||||
@@ -17,17 +17,18 @@ func NewCommand() *cobra.Command {
|
||||
DisableFlagsInUseLine: true,
|
||||
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
|
||||
Args: cobra.ExactValidArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
switch args[0] {
|
||||
case "bash":
|
||||
cmd.Root().GenBashCompletion(os.Stdout)
|
||||
return cmd.Root().GenBashCompletion(os.Stdout)
|
||||
case "zsh":
|
||||
cmd.Root().GenZshCompletion(os.Stdout)
|
||||
return cmd.Root().GenZshCompletion(os.Stdout)
|
||||
case "fish":
|
||||
cmd.Root().GenFishCompletion(os.Stdout, true)
|
||||
return cmd.Root().GenFishCompletion(os.Stdout, true)
|
||||
case "powershell":
|
||||
cmd.Root().GenPowerShellCompletion(os.Stdout)
|
||||
return cmd.Root().GenPowerShellCompletion(os.Stdout)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
# Configuration IO API Semantics
|
||||
|
||||
Resource Configuration may be read / written from / to sources such as directories,
|
||||
stdin|out or network. Tools may be composed using pipes such that the tools writing
|
||||
Resource Configuration may be a different tool from the one that read the configuration.
|
||||
In order for tools to be composed in this way, while preserving origin information --
|
||||
such as the original file, index, etc.:
|
||||
|
||||
Tools **SHOULD** insert the following annotations when reading from sources,
|
||||
and **SHOULD** delete the annotations when writing to sinks.
|
||||
|
||||
### `config.kubernetes.io/path`
|
||||
|
||||
Records the slash-delimited, OS-agnostic, relative file path to a Resource.
|
||||
|
||||
This annotation **SHOULD** be set when reading Resources from files.
|
||||
It **SHOULD** be unset when writing Resources to files.
|
||||
When writing Resources to a directory, the Resource **SHOULD** be written to the corresponding
|
||||
path relative to that directory.
|
||||
|
||||
Example:
|
||||
|
||||
```yaml
|
||||
metadata:
|
||||
annotations:
|
||||
config.kubernetes.io/path: "relative/file/path.yaml"
|
||||
```
|
||||
|
||||
### `config.kubernetes.io/index`
|
||||
|
||||
Records the index of a Resource in file. In a multi-object YAML file, Resources are separated
|
||||
by three dashes (`---`), and the index represents the position of the Resource starting from zero.
|
||||
|
||||
This annotation **SHOULD** be set when reading Resources from files.
|
||||
It **SHOULD** be unset when writing Resources to files.
|
||||
When writing multiple Resources to the same file, the Resource **SHOULD** be written in the
|
||||
relative order matching the index.
|
||||
|
||||
When this annotation is not specified, it implies a value of `0`.
|
||||
|
||||
Example:
|
||||
|
||||
```yaml
|
||||
metadata:
|
||||
annotations:
|
||||
config.kubernetes.io/path: "relative/file/path.yaml"
|
||||
config.kubernetes.io/index: 2
|
||||
```
|
||||
|
||||
This represents the third Resource in the file.
|
||||
|
||||
### `config.kubernetes.io/local-config`
|
||||
|
||||
`config.kubernetes.io/local-config` declares that the configuration is to local tools
|
||||
rather than a remote Resource. e.g. The `Kustomization` config in a `kustomization.yaml`
|
||||
**SHOULD** contain this annotation so that tools know it is not intended to be sent to
|
||||
the Kubernetes api server.
|
||||
|
||||
Example:
|
||||
|
||||
```yaml
|
||||
metadata:
|
||||
annotations:
|
||||
config.kubernetes.io/local-config: "true"
|
||||
```
|
||||
@@ -1,13 +1,18 @@
|
||||
# Configuration Functions Specification
|
||||
# KRM Functions Specification
|
||||
|
||||
_apiVersion: v1_
|
||||
|
||||
## Overview
|
||||
|
||||
This document specifies a standard for client-side functions that operate on
|
||||
Kubernetes declarative configurations. This standard enables creating
|
||||
small, interoperable, and language-independent executable programs packaged as
|
||||
containers that can be chained together as part of a configuration management pipeline.
|
||||
The end result of such a pipeline are fully rendered configurations that can then be
|
||||
applied to a control plane (e.g. Using ‘kubectl apply’ for Kubernetes control plane).
|
||||
As such, although this document references Kubernetes Resource Model and API conventions,
|
||||
it is completely decoupled from Kubernetes API machinery and does not depend on any
|
||||
Kubernetes declarative configurations referred to as _KRM Functions_. This
|
||||
standard enables creating small, interoperable, and language-independent
|
||||
executable programs packaged as containers that can be chained together as part
|
||||
of a configuration management pipeline. The end result of such a pipeline are
|
||||
fully rendered configurations that can then be applied to a control plane (e.g.
|
||||
Using ‘kubectl apply’ for Kubernetes control plane). As such, although this
|
||||
document references Kubernetes Resource Model and API conventions, it is
|
||||
completely decoupled from Kubernetes API machinery and does not depend on any
|
||||
in-cluster components.
|
||||
|
||||
This document references terms described in [Kubernetes API Conventions][1].
|
||||
@@ -18,168 +23,359 @@ interpreted as described in [RFC 2119][2].
|
||||
|
||||
## Use Cases
|
||||
|
||||
_Configuration functions_ enable shift-left practices (client-side) through:
|
||||
KRM functions enable shift-left practices (client-side) through:
|
||||
|
||||
- Pre-commit / delivery validation and linting of configuration
|
||||
- e.g. Fail if any containers don't have PodSecurityPolicy or CPU / Memory limits
|
||||
- Implementation of abstractions as client actuated APIs (e.g. templating)
|
||||
- e.g. Create a client-side _"CRD"_ for generating configuration checked into git
|
||||
- Aspect Orient configuration / Injection of cross-cutting configuration
|
||||
- e.g. T-Shirt size containers by annotating Resources with `small`, `medium`, `large`
|
||||
and inject the cpu and memory resources into containers accordingly.
|
||||
- e.g. Inject `init` and `side-car` containers into Resources based off of Resource
|
||||
Type, annotations, etc.
|
||||
- e.g. Fail if any containers don't have PodSecurityPolicy or CPU / Memory
|
||||
limits
|
||||
- Implementation of abstractions as client actuated APIs
|
||||
- e.g. Create a client-side _"CRD"_ for generating configuration checked into
|
||||
git
|
||||
- Injection of cross-cutting configuration
|
||||
- e.g. T-Shirt size containers by annotating resources with `small`, `medium`,
|
||||
`large` and inject the cpu and memory resources into containers accordingly.
|
||||
- e.g. Inject `init` and `side-car` containers into resources based off of
|
||||
resource type, annotations, etc.
|
||||
|
||||
Performing these on the client rather than the server enables:
|
||||
|
||||
- Configuration to be reviewed prior to being sent to the API server
|
||||
- Configuration to be validated as part of the CI/CD pipeline
|
||||
- Configuration for Resources to validated holistically rather than individually
|
||||
per-Resource
|
||||
- Configuration for resources to validated holistically rather than individually
|
||||
per-resource
|
||||
- e.g. ensure the `Service.selector` and `Deployment.spec.template` labels
|
||||
match.
|
||||
- e.g. MutatingWebHooks are scoped to a single Resource instance at a time.
|
||||
- e.g. MutatingWebHooks are scoped to a single resource instance at a time.
|
||||
- Low-level tweaks to the output of high-level abstractions
|
||||
- e.g. add an `init container` to a client _"CRD"_ Resource after it was generated.
|
||||
- e.g. add an `init container` to a client _"CRD"_ resource after it was
|
||||
generated.
|
||||
- Composition and layering of multiple functions together
|
||||
- Compose generation, injection, validation together
|
||||
|
||||
## Spec
|
||||
## Definitions
|
||||
|
||||
### Input Type
|
||||
- **function:** A containerized program conforming to the spec described in this
|
||||
document.
|
||||
- **orchestrator:** A program that invokes the function container, passing
|
||||
arguments and processing its output.
|
||||
|
||||
A function MUST accept as input a single [Kubernetes List type][3].
|
||||
The `items` field in the input will contain a sequence of [Object types][3].
|
||||
A function MAY not support [Simple types][3] and List types.
|
||||
## Interface
|
||||
|
||||
An example using `v1/ConfigMapList` as input:
|
||||
The inter-process communication between the orchestrator and a function works as
|
||||
follows:
|
||||
|
||||
1. Orchestrator runs the function container and provides the input on `stdin`.
|
||||
The input is a Kubernetes object of kind `ResourceList` as described below.
|
||||
2. Function reads the input from `stdin`, performs computations, and provides
|
||||
the output as a `ResourceList` to `stdout`. The function MAY also emit
|
||||
non-structured error message on `stderr`.
|
||||
3. Orchestrator uses the `stdout`, `stderr`, and the exit code of the function
|
||||
as it sees fit following to the semantics described below.
|
||||
|
||||
### Schema
|
||||
|
||||
A function MUST accept input from `stdin` and MUST output to `stdout` a
|
||||
Kubernetes object of kind `ResourceList` with the following OpenAPI schema:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMapList
|
||||
items:
|
||||
- apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: config1
|
||||
data:
|
||||
p1: v1
|
||||
p2: v2
|
||||
- apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: config2
|
||||
swagger: "2.0"
|
||||
info:
|
||||
title: KRM Functions Specification (ResourceList)
|
||||
version: v1
|
||||
definitions:
|
||||
ResourceList:
|
||||
type: object
|
||||
description: ResourceList is the input/output wire format for KRM functions.
|
||||
x-kubernetes-group-version-kind:
|
||||
- group: config.kubernetes.io
|
||||
kind: ResourceList
|
||||
version: v1
|
||||
- group: config.kubernetes.io
|
||||
kind: ResourceList
|
||||
version: v1beta1
|
||||
required:
|
||||
- items
|
||||
properties:
|
||||
apiVersion:
|
||||
description: apiVersion of ResourceList
|
||||
type: string
|
||||
kind:
|
||||
description: kind of ResourceList i.e. `ResourceList`
|
||||
type: string
|
||||
items:
|
||||
type: array
|
||||
description: |
|
||||
[input/output]
|
||||
Items is a list of Kubernetes objects:
|
||||
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#types-kinds).
|
||||
|
||||
A function will read this field in the input ResourceList and populate
|
||||
this field in the output ResourceList.
|
||||
items:
|
||||
type: object
|
||||
functionConfig:
|
||||
type: object
|
||||
description: |
|
||||
[input]
|
||||
FunctionConfig is an optional Kubernetes object for passing arguments to a
|
||||
function invocation.
|
||||
results:
|
||||
type: array
|
||||
description: |
|
||||
[output]
|
||||
Results is an optional list that can be used by function to emit results
|
||||
for observability and debugging purposes.
|
||||
items:
|
||||
"$ref": "#/definitions/Result"
|
||||
Result:
|
||||
type: object
|
||||
required:
|
||||
- message
|
||||
properties:
|
||||
message:
|
||||
type: string
|
||||
description: Message is a human readable message.
|
||||
severity:
|
||||
type: string
|
||||
enum:
|
||||
- error
|
||||
- warning
|
||||
- info
|
||||
default: error
|
||||
description: |
|
||||
Severity is the severity of a result:
|
||||
|
||||
"error": indicates an error result.
|
||||
"warning": indicates a warning result.
|
||||
"info": indicates an informational result.
|
||||
resourceRef:
|
||||
type: object
|
||||
description: |
|
||||
ResourceRef is the metadata for referencing a Kubernetes object
|
||||
associated with a result.
|
||||
required:
|
||||
- apiVersion
|
||||
- kind
|
||||
- name
|
||||
properties:
|
||||
apiVersion:
|
||||
description:
|
||||
APIVersion refers to the `apiVersion` field of the object
|
||||
manifest.
|
||||
type: string
|
||||
kind:
|
||||
description: Kind refers to the `kind` field of the object.
|
||||
type: string
|
||||
namespace:
|
||||
description:
|
||||
Namespace refers to the `metadata.namespace` field of the object
|
||||
manifest.
|
||||
type: string
|
||||
name:
|
||||
description:
|
||||
Name refers to the `metadata.name` field of the object manifest.
|
||||
type: string
|
||||
field:
|
||||
type: object
|
||||
description: |
|
||||
Field is the reference to a field in the object.
|
||||
If defined, `ResourceRef` must also be provided.
|
||||
required:
|
||||
- path
|
||||
properties:
|
||||
path:
|
||||
type: string
|
||||
description: |
|
||||
Path is the JSON path of the field
|
||||
e.g. `spec.template.spec.containers[3].resources.limits.cpu`
|
||||
currentValue:
|
||||
description: |
|
||||
CurrrentValue is the current value of the field.
|
||||
Can be any value - string, number, boolean, array or object.
|
||||
proposedValue:
|
||||
description: |
|
||||
PropposedValue is the proposed value of the field to fix an issue.
|
||||
Can be any value - string, number, boolean, array or object.
|
||||
file:
|
||||
type: object
|
||||
description: File references a file containing the resource.
|
||||
required:
|
||||
- path
|
||||
properties:
|
||||
path:
|
||||
type: string
|
||||
description: |
|
||||
Path is the OS agnostic, slash-delimited, relative path.
|
||||
e.g. `some-dir/some-file.yaml`.
|
||||
index:
|
||||
type: number
|
||||
default: 0
|
||||
description: Index of the object in a multi-object YAML file.
|
||||
tags:
|
||||
type: object
|
||||
additionalProperties:
|
||||
type: string
|
||||
description: |
|
||||
Tags is an unstructured key value map stored with a result that may be set
|
||||
by external tools to store and retrieve arbitrary metadata.
|
||||
paths: {}
|
||||
```
|
||||
|
||||
An example using `v1/List` as input:
|
||||
#### Examples
|
||||
|
||||
The following is an example input, where the custom resource of kind
|
||||
`FulfillmentCenter` is provided as `functionConfig`. The function will operate
|
||||
on one resource of kind `Service`.
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: List
|
||||
items:
|
||||
- apiVersion: foo-corp.com/v1
|
||||
kind: FulfillmentCenter
|
||||
metadata:
|
||||
name: staging
|
||||
address: "100 Main St."
|
||||
- apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: namespace-reader
|
||||
rules:
|
||||
- resources:
|
||||
- namespaces
|
||||
apiGroups:
|
||||
- ""
|
||||
verbs:
|
||||
- get
|
||||
- watch
|
||||
- list
|
||||
```
|
||||
|
||||
In addition, a function MUST accept as input a List of kind `ResourceList` where the
|
||||
`functionConfig` field, if present, will contain the invocation-specific configuration passed to the function
|
||||
by the orchestrator.
|
||||
Functions MAY consider this field optional so that they can be triggered in an ad-hoc fashion.
|
||||
|
||||
An example using `config.kubernetes.io/v1beta1/ResourceList` as input:
|
||||
|
||||
```yaml
|
||||
apiVersion: config.kubernetes.io/v1beta1
|
||||
apiVersion: config.kubernetes.io/v1
|
||||
kind: ResourceList
|
||||
functionConfig:
|
||||
apiVersion: foo-corp.com/v1
|
||||
kind: FulfillmentCenter
|
||||
metadata:
|
||||
name: staging
|
||||
metadata:
|
||||
annotations:
|
||||
config.kubernetes.io/function: |
|
||||
container:
|
||||
image: gcr.io/example/foo:v1.0.0
|
||||
spec:
|
||||
address: "100 Main St."
|
||||
items:
|
||||
- apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
- apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: namespace-reader
|
||||
rules:
|
||||
- resources:
|
||||
- namespaces
|
||||
apiGroups:
|
||||
- ""
|
||||
verbs:
|
||||
- get
|
||||
- watch
|
||||
- list
|
||||
name: wordpress
|
||||
labels:
|
||||
app: wordpress
|
||||
annotations:
|
||||
config.kubernetes.io/index: "0"
|
||||
config.kubernetes.io/path: "service.yaml"
|
||||
spec: # Example comment
|
||||
type: LoadBalancer
|
||||
selector:
|
||||
app: wordpress
|
||||
tier: frontend
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 80
|
||||
```
|
||||
|
||||
Here `FulfillmentCenter` kind with name `staging` is passed as the invocation-specific configuration
|
||||
to the function.
|
||||
The following is an example output containing one result representing a
|
||||
validation error:
|
||||
|
||||
### Output Type
|
||||
|
||||
A function’s output MUST be the same as the input specification above
|
||||
-- i.e. `ResourceList` or `List`.
|
||||
This is necessary to enable chaining two or more functions together in a pipeline.
|
||||
The serialization format of the output SHOULD match that of its input on each invocation
|
||||
-- e.g. if the input was a `ResourceList`, the output should also be a `ResourceList`.
|
||||
```yaml
|
||||
apiVersion: config.kubernetes.io/v1
|
||||
kind: ResourceList
|
||||
items:
|
||||
- apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: wordpress
|
||||
labels:
|
||||
app: wordpress
|
||||
annotations:
|
||||
config.kubernetes.io/index: "0"
|
||||
config.kubernetes.io/path: "service.yaml"
|
||||
spec: # Example comment
|
||||
type: LoadBalancer
|
||||
selector:
|
||||
app: wordpress
|
||||
tier: frontend
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 80
|
||||
results:
|
||||
- message: "Invalid type. Expected: integer, given: string"
|
||||
severity: error
|
||||
resourceRef:
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
name: wordpress
|
||||
field:
|
||||
path: spec.ports.0.port
|
||||
file:
|
||||
path: service.yaml
|
||||
```
|
||||
|
||||
### Serialization Format
|
||||
|
||||
A function MUST support YAML as a serialization format for the input and output.
|
||||
A function MUST use utf8 encoding (as YAML is a superset of JSON, JSON will also be supported
|
||||
by any conforming function).
|
||||
|
||||
### Operations
|
||||
|
||||
A function MAY Create, Update, or Delete any number of items in the `items` field and output the
|
||||
resultant list.
|
||||
|
||||
A function MAY modify annotations with prefix `config.kubernetes.io`, but must be careful about
|
||||
doing so since they’re used for orchestration purposes and will likely impact subsequent functions
|
||||
in the pipeline.
|
||||
|
||||
A function SHOULD preserve comments when input serialization format is YAML.
|
||||
This allows for human authoring of configuration to coexist with changes made by functions.
|
||||
A function MUST use utf8 encoding (as YAML is a superset of JSON, JSON will also
|
||||
be supported by any conforming function).
|
||||
|
||||
### Containerization
|
||||
|
||||
A function MUST be implemented as a container.
|
||||
|
||||
A function container MUST be capable of running as a non-root user if it does not require
|
||||
access to host filesystem or makes network calls.
|
||||
A function container MUST be capable of running as a non-root user `nobody` if
|
||||
it does not require access to host filesystem.
|
||||
|
||||
### stdin/stdout/stderr and Exit Codes
|
||||
### stderr
|
||||
|
||||
A function MUST accept input from stdin and emit output to stdout.
|
||||
Any non-structured error messages MUST be emitted to `stderr`. `stdout` is
|
||||
reserved for `ResourceList` as described above.
|
||||
|
||||
Any error messages MUST be emitted to stderr.
|
||||
### Exit Code
|
||||
|
||||
An exit code of zero indicates function execution was successful.
|
||||
A non-zero exit code indicates a failure.
|
||||
An exit code of zero indicates function execution was successful. A non-zero
|
||||
exit code indicates a failure.
|
||||
|
||||
[1]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md
|
||||
### Operations
|
||||
|
||||
A function MAY Create, Update, or Delete any number of items in the `items`
|
||||
field and output the resultant list in the corresponding `items` field of the
|
||||
output.
|
||||
|
||||
A function SHOULD preserve comments when input serialization format is YAML.
|
||||
This allows for human authoring of configuration to coexist with changes made by
|
||||
functions.
|
||||
|
||||
### Annotations
|
||||
|
||||
The orchestrator annotates resources in the wire format with annotation prefix
|
||||
`config.kubernetes.io`. These annotations are not persisted when the
|
||||
orchestrator writes the resources to the filesystem. The orchestrator sets this
|
||||
annotation when reading files from the local filesystem and removes the
|
||||
annotation when writing the output of functions back to the filesystem.
|
||||
|
||||
In general, a function MUST NOT modify these annotations except the ones
|
||||
explicitly listed below.
|
||||
|
||||
#### `config.kubernetes.io/path`
|
||||
|
||||
Records the slash-delimited, OS-agnostic, relative file path to a resource. The
|
||||
path is relative to a fix location on the filesystem. Different orchestrator
|
||||
implementations can choose different fixed points.
|
||||
|
||||
A function SHOULD NOT modify this annotation.
|
||||
|
||||
Example:
|
||||
|
||||
```yaml
|
||||
metadata:
|
||||
annotations:
|
||||
config.kubernetes.io/path: "relative/file/path.yaml"
|
||||
```
|
||||
|
||||
#### `config.kubernetes.io/index`
|
||||
|
||||
Records the index of a Resource in file. In a multi-object YAML file, resources
|
||||
are separated by three dashes (`---`), and the index represents the position of
|
||||
the Resource starting from zero. When this annotation is not specified, it
|
||||
implies a value of `0`.
|
||||
|
||||
A function SHOULD NOT modify this annotation.
|
||||
|
||||
Example:
|
||||
|
||||
```yaml
|
||||
metadata:
|
||||
annotations:
|
||||
config.kubernetes.io/path: "relative/file/path.yaml"
|
||||
config.kubernetes.io/index: 2
|
||||
```
|
||||
|
||||
This represents the third resource in the file.
|
||||
|
||||
[1]:
|
||||
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md
|
||||
[2]: https://tools.ietf.org/html/rfc2119
|
||||
[3]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#types-kinds
|
||||
[3]:
|
||||
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#types-kinds
|
||||
|
||||
@@ -16,7 +16,5 @@ require (
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||
gopkg.in/inf.v0 v0.9.1
|
||||
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e
|
||||
sigs.k8s.io/kustomize/kyaml v0.10.20
|
||||
sigs.k8s.io/kustomize/kyaml v0.11.0
|
||||
)
|
||||
|
||||
replace gopkg.in/yaml.v3 => gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
|
||||
|
||||
@@ -237,14 +237,15 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
|
||||
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e h1:KLHHjkdQFomZy8+06csTWZ0m1343QqxZhR2LJ1OxCYM=
|
||||
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e/go.mod h1:vHXdDvt9+2spS2Rx9ql3I8tycm3H9FDfdUoIuKCefvw=
|
||||
sigs.k8s.io/kustomize/kyaml v0.10.20 h1:L9JNKvJfCBpmYFr4tP0igpfj/pXP7nW2aXOWNtF5k1g=
|
||||
sigs.k8s.io/kustomize/kyaml v0.10.20/go.mod h1:TYWhGwW9vjoRh3rWqBwB/ZOXyEGRVWe7Ggc3+KZIO+c=
|
||||
sigs.k8s.io/kustomize/kyaml v0.11.0 h1:9KhiCPKaVyuPcgOLJXkvytOvjMJLoxpjodiycb4gHsA=
|
||||
sigs.k8s.io/kustomize/kyaml v0.11.0/go.mod h1:GNMwjim4Ypgp/MueD3zXHLRJEjz7RvtPae0AwlvEMFM=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
|
||||
@@ -104,9 +104,9 @@ func (r *AnnotateRunner) ExecuteCmd(w io.Writer, pkgPath string) error {
|
||||
return err
|
||||
}
|
||||
// print error message and continue if there are multiple packages to annotate
|
||||
fmt.Fprintf(w, "%s\n", err.Error())
|
||||
_, _ = fmt.Fprintf(w, "%s\n", err.Error())
|
||||
} else {
|
||||
fmt.Fprint(w, "added annotations in the package\n")
|
||||
_, _ = fmt.Fprint(w, "added annotations in the package\n")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -117,8 +117,8 @@ items:
|
||||
name: test
|
||||
app: nginx
|
||||
ports:
|
||||
# This i the port.
|
||||
- name: http
|
||||
# This i the port.
|
||||
port: 8080
|
||||
targetPort: 8080
|
||||
`
|
||||
@@ -169,8 +169,8 @@ items:
|
||||
name: test
|
||||
app: nginx
|
||||
ports:
|
||||
# This i the port.
|
||||
- name: http
|
||||
# This i the port.
|
||||
port: 8080
|
||||
targetPort: 8080
|
||||
`
|
||||
@@ -269,8 +269,8 @@ items:
|
||||
name: test
|
||||
app: nginx
|
||||
ports:
|
||||
# This i the port.
|
||||
- name: http
|
||||
# This i the port.
|
||||
port: 8080
|
||||
targetPort: 8080
|
||||
`
|
||||
|
||||
@@ -87,8 +87,18 @@ metadata:
|
||||
expectedFiles: func(d string) map[string]string {
|
||||
return map[string]string{
|
||||
"deployment.json": `
|
||||
{"apiVersion": "apps/v1", "kind": "Deployment", "metadata": {"name": "foo", annotations: {
|
||||
a-string-value: '', a-int-value: '0', a-bool-value: 'false'}}}
|
||||
{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"a-bool-value": "false",
|
||||
"a-int-value": "0",
|
||||
"a-string-value": ""
|
||||
},
|
||||
"name": "foo"
|
||||
}
|
||||
}
|
||||
`,
|
||||
}
|
||||
},
|
||||
|
||||
@@ -53,8 +53,7 @@ spec:
|
||||
name: app-config
|
||||
env:
|
||||
- name: JAVA_OPTS
|
||||
value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
|
||||
-Djava.security.egd=file:/dev/./urandom
|
||||
value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Djava.security.egd=file:/dev/./urandom
|
||||
imagePullPolicy: Always
|
||||
minReadySeconds: 5
|
||||
`), 0600)
|
||||
@@ -104,8 +103,7 @@ spec:
|
||||
name: app-config
|
||||
env:
|
||||
- name: JAVA_OPTS
|
||||
value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
|
||||
-Djava.security.egd=file:/dev/./urandom
|
||||
value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Djava.security.egd=file:/dev/./urandom
|
||||
imagePullPolicy: Always
|
||||
minReadySeconds: 20
|
||||
`), 0600)
|
||||
@@ -152,8 +150,7 @@ spec:
|
||||
name: app-config
|
||||
env:
|
||||
- name: JAVA_OPTS
|
||||
value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
|
||||
-Djava.security.egd=file:/dev/./urandom
|
||||
value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Djava.security.egd=file:/dev/./urandom
|
||||
imagePullPolicy: Always
|
||||
minReadySeconds: 5
|
||||
`), 0600)
|
||||
@@ -201,8 +198,7 @@ spec:
|
||||
name: app-config
|
||||
env:
|
||||
- name: JAVA_OPTS
|
||||
value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
|
||||
-Djava.security.egd=file:/dev/./urandom
|
||||
value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Djava.security.egd=file:/dev/./urandom
|
||||
imagePullPolicy: Always
|
||||
minReadySeconds: 20
|
||||
`), 0600)
|
||||
|
||||
@@ -72,7 +72,7 @@ func GetRunFnRunner(name string) *RunFnRunner {
|
||||
&r.Env, "env", "e", []string{},
|
||||
"a list of environment variables to be used by functions")
|
||||
r.Command.Flags().BoolVar(
|
||||
&r.AsCurrentUser, "as-current-user", false, "use the uid and gid that kpt is running with to run the function in the container")
|
||||
&r.AsCurrentUser, "as-current-user", false, "use the uid and gid of the command executor to run the function in the container")
|
||||
return r
|
||||
}
|
||||
|
||||
|
||||
@@ -194,13 +194,8 @@ func TestSourceCommandJSON(t *testing.T) {
|
||||
if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1
|
||||
kind: ResourceList
|
||||
items:
|
||||
- {"kind": "Deployment", "metadata": {"labels": {"app": "nginx2"}, "name": "foo",
|
||||
"annotations": {"app": "nginx2", config.kubernetes.io/index: '0', config.kubernetes.io/path: 'f1.json'}},
|
||||
"spec": {"replicas": 1}}
|
||||
- {"apiVersion": "v1", "kind": "Abstraction", "metadata": {"name": "foo", "annotations": {
|
||||
"config.kubernetes.io/function": "container:\n image: gcr.io/example/reconciler:v1\n",
|
||||
"config.kubernetes.io/local-config": "true", config.kubernetes.io/index: '0',
|
||||
config.kubernetes.io/path: 'f2.json'}}, "spec": {"replicas": 3}}
|
||||
- {"kind": "Deployment", "metadata": {"labels": {"app": "nginx2"}, "name": "foo", "annotations": {"app": "nginx2", config.kubernetes.io/index: '0', config.kubernetes.io/path: 'f1.json'}}, "spec": {"replicas": 1}}
|
||||
- {"apiVersion": "v1", "kind": "Abstraction", "metadata": {"name": "foo", "annotations": {"config.kubernetes.io/function": "container:\n image: gcr.io/example/reconciler:v1\n", "config.kubernetes.io/local-config": "true", config.kubernetes.io/index: '0', config.kubernetes.io/path: 'f2.json'}}, "spec": {"replicas": 3}}
|
||||
`, b.String()) {
|
||||
return
|
||||
}
|
||||
@@ -307,9 +302,7 @@ func TestSourceCommandJSON_Stdin(t *testing.T) {
|
||||
if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1
|
||||
kind: ResourceList
|
||||
items:
|
||||
- {"kind": "Deployment", "metadata": {"labels": {"app": "nginx2"}, "name": "foo",
|
||||
"annotations": {"app": "nginx2", config.kubernetes.io/index: '0'}}, "spec": {
|
||||
"replicas": 1}}
|
||||
- {"kind": "Deployment", "metadata": {"labels": {"app": "nginx2"}, "name": "foo", "annotations": {"app": "nginx2", config.kubernetes.io/index: '0'}}, "spec": {"replicas": 1}}
|
||||
`, out.String()) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,7 +1,23 @@
|
||||
## Checking openapi build issues
|
||||
# Troubles with dependencies on openapi
|
||||
|
||||
|
||||
If you see the error
|
||||
|
||||
> cannot use api.Schema.SchemaProps.Properties
|
||||
|
||||
then you have a set of incompatible dependencies. This doc describes the problem and a fix.
|
||||
|
||||
tl;dr A mix of old and new is bad.
|
||||
|
||||
Anyone depending on k8s.io `v0.20.x` or _older_ packages must avoid depending on anything that depends
|
||||
on `k8s.io/kube-openapi` newer than v0.0.0-20210323165736-1a6458611d18.
|
||||
|
||||
> More context in https://github.com/kubernetes/cli-runtime/issues/19
|
||||
|
||||
This dir exists to test the problem.
|
||||
|
||||
Edit the `main.go` and `go.mod` in this dir to see what builds
|
||||
with various combinations of cli-runtime kube-openapi.
|
||||
with various combinations of `cli-runtime` and `kube-openapi`.
|
||||
|
||||
####
|
||||
|
||||
@@ -16,9 +32,9 @@ means that anyone depending on
|
||||
and _any other package that imports kube-openapi_ (e.g. kyaml)
|
||||
may see a build error like
|
||||
|
||||
~/go/pkg/mod/sigs.k8s.io/kustomize@v2.0.3+incompatible/pkg/transformers/config/factorycrd.go:71:47:
|
||||
cannot use api.Schema.SchemaProps.Properties (type map[string]"k8s.io/kube-openapi/pkg/validation/spec".Schema)
|
||||
as type myProperties in argument to looksLikeAk8sType
|
||||
> ~/go/pkg/mod/sigs.k8s.io/kustomize@v2.0.3+incompatible/pkg/transformers/config/factorycrd.go:71:47:
|
||||
> cannot use api.Schema.SchemaProps.Properties (type map[string]"k8s.io/kube-openapi/pkg/validation/spec".Schema)
|
||||
> as type myProperties in argument to looksLikeAk8sType
|
||||
|
||||
## Why?
|
||||
|
||||
|
||||
@@ -26,14 +26,14 @@ var (
|
||||
|
||||
// TODO: make this a PATH-like flag
|
||||
// e.g.: --excludes ".git:.idea:site:docs"
|
||||
excSlice = []string{
|
||||
exclusions = []string{
|
||||
".git",
|
||||
".github",
|
||||
".idea",
|
||||
"docs",
|
||||
"examples",
|
||||
"hack",
|
||||
// "plugin",
|
||||
"plugin",
|
||||
"releasing",
|
||||
"site",
|
||||
}
|
||||
@@ -94,7 +94,7 @@ func (a *Args) ConditionalModule() misc.ModuleShortName {
|
||||
|
||||
func (a *Args) Exclusions() (result []string) {
|
||||
// Make sure the list has no repeats.
|
||||
for k := range utils.SliceToSet(excSlice) {
|
||||
for k := range utils.SliceToSet(exclusions) {
|
||||
result = append(result, k)
|
||||
}
|
||||
return
|
||||
|
||||
@@ -6,8 +6,6 @@ require (
|
||||
github.com/rakyll/statik v0.1.7
|
||||
github.com/spf13/cobra v1.0.0
|
||||
github.com/stretchr/testify v1.5.1
|
||||
sigs.k8s.io/kustomize/api v0.8.9
|
||||
sigs.k8s.io/kustomize/kyaml v0.10.20
|
||||
sigs.k8s.io/kustomize/api v0.8.11
|
||||
sigs.k8s.io/kustomize/kyaml v0.11.0
|
||||
)
|
||||
|
||||
replace sigs.k8s.io/kustomize/api => ../../api
|
||||
|
||||
@@ -30,8 +30,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
|
||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
|
||||
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
|
||||
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/evanphx/json-patch v4.11.0+incompatible h1:glyUF9yIYtMHzn8xaKw5rMhdWcwsYV8dZHIq5567/xs=
|
||||
github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
|
||||
@@ -222,15 +222,16 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
|
||||
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e h1:KLHHjkdQFomZy8+06csTWZ0m1343QqxZhR2LJ1OxCYM=
|
||||
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e/go.mod h1:vHXdDvt9+2spS2Rx9ql3I8tycm3H9FDfdUoIuKCefvw=
|
||||
sigs.k8s.io/kustomize/kyaml v0.10.20 h1:L9JNKvJfCBpmYFr4tP0igpfj/pXP7nW2aXOWNtF5k1g=
|
||||
sigs.k8s.io/kustomize/kyaml v0.10.20/go.mod h1:TYWhGwW9vjoRh3rWqBwB/ZOXyEGRVWe7Ggc3+KZIO+c=
|
||||
sigs.k8s.io/kustomize/api v0.8.11 h1:LzQzlq6Z023b+mBtc6v72N2mSHYmN8x7ssgbf/hv0H8=
|
||||
sigs.k8s.io/kustomize/api v0.8.11/go.mod h1:a77Ls36JdfCWojpUqR6m60pdGY1AYFix4AH83nJtY1g=
|
||||
sigs.k8s.io/kustomize/kyaml v0.11.0 h1:9KhiCPKaVyuPcgOLJXkvytOvjMJLoxpjodiycb4gHsA=
|
||||
sigs.k8s.io/kustomize/kyaml v0.11.0/go.mod h1:GNMwjim4Ypgp/MueD3zXHLRJEjz7RvtPae0AwlvEMFM=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
|
||||
@@ -27,7 +27,7 @@ const (
|
||||
|
||||
// ConvertToBuiltInPlugin converts the input plugin file to
|
||||
// kustomize builtin plugin and writes it to proper directory
|
||||
func ConvertToBuiltInPlugin() error {
|
||||
func ConvertToBuiltInPlugin() (retErr error) {
|
||||
root, err := inputFileRoot()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -47,7 +47,12 @@ func ConvertToBuiltInPlugin() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer w.close()
|
||||
defer func() {
|
||||
closeErr := w.Close()
|
||||
if retErr == nil {
|
||||
retErr = closeErr
|
||||
}
|
||||
}()
|
||||
|
||||
// This particular phrasing is required.
|
||||
w.write(
|
||||
@@ -139,10 +144,10 @@ func makeOutputFileName(root string) string {
|
||||
"..", "..", "..", "api", packageForGeneratedCode, root+".go")
|
||||
}
|
||||
|
||||
func (w *writer) close() {
|
||||
func (w *writer) Close() error {
|
||||
// Do this for debugging.
|
||||
// fmt.Println("Generated " + makeOutputFileName(w.root))
|
||||
w.f.Close()
|
||||
return w.f.Close()
|
||||
}
|
||||
|
||||
func (w *writer) write(line string) {
|
||||
|
||||
@@ -5,15 +5,15 @@ English | [简体中文](zh/README.md)
|
||||
To run these examples, your `$PATH` must contain `kustomize`.
|
||||
See the [installation instructions](../docs/INSTALL.md).
|
||||
|
||||
These examples are [tested](../scripts/kyaml-pre-commit.sh)
|
||||
These examples are [tested](../hack/testExamplesAgainstKustomize.sh)
|
||||
to work with the latest _released_ version of kustomize.
|
||||
|
||||
Basic Usage
|
||||
|
||||
* [valueAdd](valueAdd.md) -
|
||||
* [valueAdd](valueAdd.md) -
|
||||
Add a simple string value easily to various fields, including
|
||||
fields that happen to hold file paths.
|
||||
|
||||
|
||||
* [configGenerations](configGeneration.md) -
|
||||
Rolling update when ConfigMapGenerator changes.
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ Define this base the usual way by creating a
|
||||
cat <<'EOF' >$DEMO_HOME/base/kustomization.yaml
|
||||
helmCharts:
|
||||
- name: minecraft
|
||||
includeCRDs: false
|
||||
valuesInline:
|
||||
minecraftServer:
|
||||
eula: true
|
||||
@@ -105,6 +106,10 @@ field, specifying a single chart.
|
||||
|
||||
The `valuesInline` field overrides some native chart values.
|
||||
|
||||
The `includeCRDs` field instructs Helm to generate
|
||||
`CustomResourceDefinitions`.
|
||||
See [the Helm documentation](https://helm.sh/docs/chart_best_practices/custom_resource_definitions/) for details.
|
||||
|
||||
Check the directory layout:
|
||||
|
||||
<!-- @tree -->
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
这些示例默认 `kustomize` 在您的 `$PATH` 中。
|
||||
|
||||
这些示例通过了 [pre-commit](../../scripts/kyaml-pre-commit.sh) 测试,并且应该与 HEAD 一起使用。
|
||||
这些示例通过了 [pre-commit](../../hack/testExamplesAgainstKustomize.sh) 测试,并且应该与 HEAD 一起使用。
|
||||
|
||||
```
|
||||
go get sigs.k8s.io/kustomize/v3/cmd/kustomize
|
||||
@@ -58,4 +58,4 @@ go get sigs.k8s.io/kustomize/v3/cmd/kustomize
|
||||
|
||||
* [multibases](multibases.md) - 使用相同的 base 生成三个 variants(dev,staging,production)。
|
||||
|
||||
>声明:部分文档可能稍微滞后于英文版本,同步工作持续进行中
|
||||
>声明:部分文档可能稍微滞后于英文版本,同步工作持续进行中
|
||||
|
||||
@@ -3,6 +3,7 @@ module sigs.k8s.io/kustomize/functions/examples/application-cr
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
|
||||
k8s.io/apimachinery v0.18.3
|
||||
sigs.k8s.io/application v0.8.2
|
||||
sigs.k8s.io/kustomize/kyaml v0.7.1
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user