Compare commits

...

312 Commits

Author SHA1 Message Date
k8s-ci-robot
ec86b30d2b Merge pull request #498 from Liujingfang1/doc
Add example for transformer configurations: crd
2018-10-24 12:13:53 -07:00
Jingfang Liu
a90c957463 Add example for transformer configurations: crd 2018-10-24 12:08:48 -07:00
k8s-ci-robot
18a2321ddd Merge pull request #500 from Liujingfang1/namespace
create namespace resource if not found
2018-10-23 15:33:16 -07:00
Jingfang Liu
a5f0d457ec create namespace resource if not found 2018-10-23 13:46:03 -07:00
k8s-ci-robot
368b7f3939 Merge pull request #497 from Liujingfang1/generatoroptions
Allow setting shell and timeout in generatorOptions
2018-10-22 16:15:06 -07:00
k8s-ci-robot
e4dfbe79e1 Merge pull request #496 from Liujingfang1/master
enable preserving order with generatorOptions
2018-10-22 16:13:01 -07:00
Jingfang Liu
fdf5fa58d3 Allow setting shell and timeout in generatorOptions 2018-10-22 16:10:56 -07:00
Jingfang Liu
9ef96e9bb2 enable preserving order with generatorOptions 2018-10-22 16:01:46 -07:00
k8s-ci-robot
a8e393496f Merge pull request #495 from monopole/testFieldOrdering
Test field output ordering.
2018-10-19 17:32:54 -07:00
Jeffrey Regan
6b302443e6 Test field output ordering. 2018-10-19 16:20:23 -07:00
Jeff Regan
3fdf7a0b88 Merge pull request #494 from Liujingfang1/generatoroptions
allow add labels/annotations to generated resources
2018-10-19 16:01:53 -07:00
Jingfang Liu
0cb02f1448 allow add labels/annotations to generated resources 2018-10-19 15:40:06 -07:00
k8s-ci-robot
8b09afdf3e Merge pull request #493 from Liujingfang1/options
skip hash transformer when DisableHash is set to true
2018-10-19 15:25:14 -07:00
Jingfang Liu
23963e854a skip hash transformer when DisableHash is set to true 2018-10-19 14:44:23 -07:00
k8s-ci-robot
04167cf77e Merge pull request #487 from monopole/deletePenultimateUseOfDeprecatedField
Delete penultimate use of Patches field.
2018-10-19 14:28:05 -07:00
k8s-ci-robot
6f0a01fcf4 Merge pull request #490 from Liujingfang1/options
Add generatorOptions in Kustomization type
2018-10-19 14:18:42 -07:00
Jingfang Liu
0824433260 Add generatorOptions in Kustomization type 2018-10-19 14:12:33 -07:00
Jeffrey Regan
3e0f5ea327 Delete penultimate use of Patches field. 2018-10-19 11:26:05 -07:00
k8s-ci-robot
a4be48eb32 Merge pull request #488 from Liujingfang1/prefix
Skip adding nameprefix to namespace
2018-10-19 10:02:43 -07:00
Jingfang Liu
90d03b0afe Skip adding nameprefix to namespace 2018-10-18 13:52:11 -07:00
k8s-ci-robot
37802e1026 Merge pull request #485 from monopole/deleteSomeUnnecessaryParmPassing
Delete some unnecessary parameter passing.
2018-10-18 11:57:28 -07:00
k8s-ci-robot
16add04ccf Merge pull request #477 from Liujingfang1/sa
skip filtering resmap when the resource is a cluster level resource
2018-10-18 11:21:10 -07:00
Jingfang Liu
90c88d7f96 skip filtering resmap when the resource is a cluster level resource 2018-10-18 11:09:24 -07:00
Jeffrey Regan
2b0e2725f9 Delete some unnecessary parameter passing. 2018-10-18 10:59:59 -07:00
k8s-ci-robot
66bbae586f Merge pull request #483 from Liujingfang1/fieldspec
add commonLabel fieldpath for volumeClaimTemplates
2018-10-18 10:46:27 -07:00
k8s-ci-robot
d2ac2df372 Merge pull request #482 from Liujingfang1/validators
fix kustomize edit add label bug
2018-10-18 10:45:06 -07:00
Jingfang Liu
d5aed20f0a add commonLabel fieldpath for volumeClaimTemplates 2018-10-18 10:25:19 -07:00
k8s-ci-robot
42fcdef9f0 Merge pull request #481 from monopole/deleteExec
Delete unused exec package.
2018-10-18 10:12:37 -07:00
Jingfang Liu
482811460d fix kustomize edit add label bug 2018-10-18 10:01:18 -07:00
Jeffrey Regan
8fd93030b4 Delete unused exec package. 2018-10-18 09:54:45 -07:00
k8s-ci-robot
5db1ef23fe Merge pull request #475 from Liujingfang1/namespace
add namespace to id when create resmap from files
2018-10-17 16:45:00 -07:00
Jingfang Liu
14fc54e323 add namespace to id when create resmap from files 2018-10-17 16:22:19 -07:00
Jeff Regan
3d1d1f0bb8 Merge pull request #478 from monopole/messWithTypesDoc
Improve kustomization.go comments.
2018-10-17 14:24:39 -07:00
jregan
a5f56027b5 Improve kustomization.go comments. 2018-10-17 14:24:20 -07:00
k8s-ci-robot
bad3ccddc3 Merge pull request #473 from Liujingfang1/script
add script build/vendor_kustomize.sh
2018-10-16 17:26:43 -07:00
Jingfang Liu
da35a219d1 add script build/vendor_kustomize.sh 2018-10-16 15:53:04 -07:00
Jingfang Liu
8209aeea6d fix copyright misalignment (#472) 2018-10-16 11:02:47 -07:00
Jeff Regan
2d2315c4c4 Merge pull request #471 from Liujingfang1/dep
downgrade the transitive dependency to be consistent with kubernetes
2018-10-16 10:01:16 -07:00
Jingfang Liu
c6a78cee92 change github.com/aws/aws-sdk-go to be the same revision in kubernetes 2018-10-16 09:35:05 -07:00
Jingfang Liu
e0958159f3 change golang.org/x/net to be the same revision as used in kubernetes 2018-10-16 09:35:04 -07:00
Jingfang Liu
9d804ba3a8 fix lint errors in internal (#469) 2018-10-15 13:38:32 -07:00
Jingfang Liu
808df20cdb add missing lines after copyright (#468) 2018-10-15 12:02:41 -07:00
k8s-ci-robot
c46d2ce791 Merge pull request #467 from monopole/deleteSomeKunstructCode
Delete some kunstruct code in favor of apimachinery code.
2018-10-15 10:57:38 -07:00
jregan
f20528be35 Delete some kunstruct code in favor of apimachinery code. 2018-10-15 10:23:03 -07:00
k8s-ci-robot
5253747c00 Merge pull request #466 from monopole/improveGetFieldValueCoverage
Improve unstruct test coverage and error messages.
2018-10-15 09:58:19 -07:00
jregan
aaee97c0fa Improve unstruct test coverage and error messages. 2018-10-15 09:44:00 -07:00
Jeff Regan
d82c40c9fe Merge pull request #465 from monopole/moveYamlCheck
Move yaml check to file in which it is called.
2018-10-15 09:40:31 -07:00
jregan
dcc9c4d31a Move yaml check to file in which it is called. 2018-10-15 09:20:01 -07:00
k8s-ci-robot
3b119fb707 Merge pull request #463 from monopole/moarTesting
Objectify nbrSlice code.
2018-10-12 17:22:55 -07:00
Jeffrey Regan
b198b65d52 Objectify nbrSlice code. 2018-10-12 16:27:50 -07:00
k8s-ci-robot
f94974cc2c Merge pull request #462 from monopole/fixTransformConfigNames
Fix names/doc in transformation config code.
2018-10-12 13:41:49 -07:00
Jeffrey Regan
d9f9a51e55 Fix names/doc in transformation config code. 2018-10-12 13:36:22 -07:00
Jeff Regan
111f41785f Merge pull request #458 from camilosampedro/master
Notes on mySql example
2018-10-12 09:52:48 -07:00
Camilo Sampedro
e65995cd32 Notes on mySql example
mySql example was not running without the persistent disk nor the secret
called as it should.
2018-10-12 14:35:21 +09:00
k8s-ci-robot
ea9d5e3670 Merge pull request #455 from Liujingfang1/factory
Add KustFactory as a wrapper of all factories
2018-10-11 16:06:45 -07:00
Jingfang Liu
40b2bf76ae Add KustFactory as a wrapper of all factories 2018-10-11 13:51:27 -07:00
k8s-ci-robot
6fa110d4fd Merge pull request #457 from Liujingfang1/split
split k8sdeps package into sub packages
2018-10-11 11:36:00 -07:00
Jingfang Liu
d33d154e14 split k8sdeps package into sub packages 2018-10-11 11:30:46 -07:00
Jeff Regan
483d329556 Merge pull request #456 from Liujingfang1/configmap
use fake filesystem in configmapandsecret tests
2018-10-11 11:24:43 -07:00
Jingfang Liu
f3e4615a33 use FakeFileSystem in configmapandsecret tests 2018-10-11 11:04:26 -07:00
Jeff Regan
9106cee216 Merge pull request #454 from yanc0/literals-documentation
Literals documentation configMap Generation
2018-10-11 09:18:20 -07:00
Yann
2d26d95a98 fix indent 2018-10-11 09:16:14 +02:00
Yann
5745d030fb Add literals in configMapGenerator example 2018-10-11 09:14:06 +02:00
Jeff Regan
9f7eccc68f Merge pull request #453 from monopole/docFix
Update ptrs to DAM doc.
2018-10-10 16:20:58 -07:00
Jeffrey Regan
3fe047f79c Update ptrs to DAM doc. 2018-10-10 16:16:15 -07:00
k8s-ci-robot
9897ce8bf2 Merge pull request #452 from Liujingfang1/config
move transformerconfig package to transformers/config
2018-10-10 15:17:06 -07:00
Jingfang Liu
c33a97fcf2 move transformerconfig package to transformers/config 2018-10-10 15:12:32 -07:00
k8s-ci-robot
ca4a5d33f0 Merge pull request #451 from Liujingfang1/hash
add MakeHashTransformer in TransformerFactory; remove hash interface
2018-10-10 14:10:48 -07:00
Jingfang Liu
2953dad221 add MakeHashTransformer in TransformerFactory; remove hash interface 2018-10-10 14:05:13 -07:00
Jeff Regan
f35a11ff37 Merge pull request #450 from monopole/crdToFactory
Move crd package to transformerconfig.factory.
2018-10-10 13:29:25 -07:00
Jeffrey Regan
8534107fc8 Move crd package to transformerconfig.factory. 2018-10-10 13:14:43 -07:00
k8s-ci-robot
681e2bf213 Merge pull request #449 from monopole/tcFactory
Consolidate TransformerConfig creation to factory.
2018-10-10 13:04:07 -07:00
Jeffrey Regan
2283c06971 Consolidate transformer config creation to factory. 2018-10-10 12:33:19 -07:00
Jeff Regan
bb9435a604 Merge pull request #448 from Liujingfang1/decoder
remove decoder interface since it is only used inside k8sdeps
2018-10-10 12:01:15 -07:00
Jingfang Liu
96091dfcf5 remove decoder interface since it is only used inside k8sdeps 2018-10-10 11:08:23 -07:00
k8s-ci-robot
cf4a1ba083 Merge pull request #446 from Liujingfang1/gvk
remove dependency on apimachinery from gvk package
2018-10-09 17:26:42 -07:00
Jingfang Liu
4c7b63a215 remove dependency on apimachinery from gvk package 2018-10-09 16:25:25 -07:00
k8s-ci-robot
1e04a0e943 Merge pull request #445 from Liujingfang1/typemeta
copy TypeMeta from apimachinery
2018-10-09 16:18:09 -07:00
Jingfang Liu
f7353b1295 copy TypeMeta from apimachinery 2018-10-09 16:10:17 -07:00
k8s-ci-robot
dbf04985c4 Merge pull request #444 from Liujingfang1/configmap
hide core/v1 behind interface
2018-10-09 16:00:09 -07:00
Jingfang Liu
f783486057 hide core/v1 behind interface 2018-10-09 15:50:52 -07:00
Jeff Regan
0faef46773 Merge pull request #443 from ryancox/use-go-1.11
Use Go 1.11 for CI Builds
2018-10-09 15:02:54 -07:00
Ryan Cox
cbd7a1bb58 Use Go 1.11 2018-10-09 14:44:05 -07:00
k8s-ci-robot
19ac0e9327 Merge pull request #426 from schweikert/add_jsonpatch_yaml_test
Add jsonpatch yaml test
2018-10-09 13:26:51 -07:00
David Schweikert
b5cf3a2146 add yaml-version of jsonpatch tests 2018-10-09 21:04:34 +02:00
Jeff Regan
5cf0cbe041 Merge pull request #440 from monopole/fix428
Maintain fields of TransformerConfig in sorted order.
2018-10-09 10:47:55 -07:00
jregan
df5c3ab91e Maintain fields of TransformerConfig in sorted order.
Not needed for execution, just makes logging and tests deterministic.
Related to #428
2018-10-09 10:14:57 -07:00
Jeff Regan
5b95db2208 Merge pull request #441 from monopole/replantTree
Replant tree (needed for example tests).
2018-10-09 10:09:36 -07:00
Jeffrey Regan
22d955b3a9 Replant tree (needed for example tests). 2018-10-09 10:05:50 -07:00
Jeff Regan
b7fa38e2e7 Merge pull request #437 from ryancox/golangci-lint
port to golangci and make travisci improvements
2018-10-09 09:36:05 -07:00
Jeff Regan
b16c85888e Merge pull request #435 from Liujingfang1/flakytest
fix the flaky test in crd package
2018-10-09 09:33:20 -07:00
Ryan Cox
261d64ec1d port to golangci and make travisci improvements 2018-10-09 00:58:34 -07:00
Jingfang Liu
62f7cdbb43 fix the flaky test in crd package 2018-10-08 16:06:35 -07:00
Jeff Regan
30814302af Fix some minor naming mistakes. (#434)
* Fix some minor naming mistakes.

* Fix some minor naming mistakes.
2018-10-08 15:58:44 -07:00
Jeff Regan
fd3cd64e11 Merge pull request #433 from Liujingfang1/patchtransformer
hide patch transformer behind interface
2018-10-08 15:32:49 -07:00
k8s-ci-robot
536cd8d45e Merge pull request #432 from monopole/mergeResmapFactoryCode
Gather resmap factory code into one file.
2018-10-08 15:17:46 -07:00
Jingfang Liu
78de5374ed hide patch transformer behind interface 2018-10-08 15:15:03 -07:00
Jeffrey Regan
aff76e0d0e Gather resmap factory code into one file. 2018-10-08 15:09:22 -07:00
k8s-ci-robot
0f4ab07324 Merge pull request #431 from Liujingfang1/error
remove apimachinery dependency from internal/error package
2018-10-08 14:54:40 -07:00
Jingfang Liu
08da2455dd remove apimachinery dependency from internal/error package 2018-10-08 14:32:24 -07:00
Jingfang Liu
8e0c55f9fa remove apimachinery dependency from crd package (#430) 2018-10-08 14:27:18 -07:00
Jeff Regan
00b4beda91 Merge pull request #429 from monopole/kunstructedFactory
Further isolate unstructured with factories.
2018-10-08 14:26:32 -07:00
Jeffrey Regan
1af119db80 Further isolate unstructured with factories. 2018-10-08 14:21:48 -07:00
jregan
4eb2757847 Further isolate unstructured with factories. 2018-10-08 11:52:38 -07:00
k8s-ci-robot
3cdfbd843b Merge pull request #423 from monopole/hideUnstruct
Hide unstructured.Unstructured behind interface.
2018-10-08 11:21:45 -07:00
jregan
0f5a39f328 Hide unstructured.Unstructured behind interface. 2018-10-08 11:12:06 -07:00
k8s-ci-robot
9c8302b2d2 Merge pull request #427 from ryancox/resmap-tests
add tests for resmap
2018-10-08 10:57:22 -07:00
Ryan Cox
e5ea1b0a19 typo 2018-10-08 10:16:10 -07:00
Ryan Cox
e6558fb9fc PR comments 2018-10-08 10:13:05 -07:00
k8s-ci-robot
b67f8d2b7b Merge pull request #425 from schweikert/mac_sed
use 'sed -i.bak' instead of 'sed -i' to make it compatible with macos…
2018-10-08 08:53:24 -07:00
k8s-ci-robot
5c92f09dd0 Merge pull request #422 from schweikert/issue_368
unify processing of JSON6902 patches for both json and yaml format
2018-10-08 08:35:15 -07:00
Ryan Cox
f2f1125e44 add tests for resmap 2018-10-07 21:57:20 -07:00
David Schweikert
6d4ad82262 use 'sed -i.bak' instead of 'sed -i' to make it compatible with macos sed 2018-10-07 22:26:15 +02:00
Jeff Regan
7cf5f8caae Merge pull request #421 from Liujingfang1/hash
Add hash interface
2018-10-05 14:33:17 -07:00
David Schweikert
3d4bf3abbf for yaml-formatted JSON6902 patches, convert first to json, then use the same code as for json-formatted JSON6902 patches 2018-10-05 22:53:26 +02:00
Jingfang Liu
5036a12a65 Add hash interface 2018-10-05 13:29:06 -07:00
k8s-ci-robot
489f6e2e67 Merge pull request #416 from monopole/residPackage
Move ResId to its own package.
2018-10-05 13:13:52 -07:00
Jeffrey Regan
c9887e8c15 WIP residPackage 2018-10-05 12:58:48 -07:00
Jeff Regan
239db504ff Merge pull request #418 from Liujingfang1/hash
combine HashComfigMap and HashSecret to Hash
2018-10-05 12:58:31 -07:00
Jeff Regan
9b7ce3b6ba Merge pull request #419 from monopole/deleteMakeUnstruct
Delete unused unstruct code.
2018-10-05 12:46:13 -07:00
Jeffrey Regan
3b86e64faf Delete unused unstruct code. 2018-10-05 12:39:45 -07:00
Jingfang Liu
c3ae23d3a5 combine HashComfigMap and HashSecret to Hash 2018-10-05 12:02:58 -07:00
k8s-ci-robot
73e28ca556 Merge pull request #411 from Liujingfang1/hash
decouple configmapandsecret and hash packages
2018-10-05 09:39:18 -07:00
Jeff Regan
a634da4d19 Merge pull request #415 from monopole/nits
Fix some go nits.
2018-10-05 07:38:37 -07:00
Jeffrey Regan
a3dce9409b Fix some go nits. 2018-10-05 07:33:54 -07:00
Jingfang Liu
a9cf1975ca decouple configmapandsecret and hash packages 2018-10-04 16:17:23 -07:00
k8s-ci-robot
51ece9412e Merge pull request #407 from monopole/cmdSplit
Improve command package isolation.
2018-10-03 20:09:45 -07:00
Jeff Regan
b37258edf0 Merge pull request #406 from schweikert/fix_issue_335
error out if patchesJson6902 target can't be found, fixes #335
2018-10-03 16:32:48 -07:00
Jeffrey Regan
bb9fafa6cc Improve command package isolation. 2018-10-03 16:29:04 -07:00
Jeff Regan
f5fee4decf Merge pull request #405 from monopole/generaterIsolation
Isolate generator calls.
2018-10-03 16:28:36 -07:00
David Schweikert
279826f6d6 error out if patchesJson6902 target can't be found, fixes #335 2018-10-03 21:53:45 +02:00
Jeffrey Regan
56e11b57e3 Isolate generator calls. 2018-10-03 12:09:53 -07:00
k8s-ci-robot
6d65049221 Merge pull request #404 from monopole/deprecationFix
Deal with field deprecation immediately after load.
2018-10-03 11:24:13 -07:00
Jeffrey Regan
65ee4e4f2a Deal with field deprecation immediately after load. 2018-10-03 10:55:35 -07:00
k8s-ci-robot
a1538c5610 Merge pull request #403 from monopole/isolateK8sdeps
Isolate k8sdeps to top level internal.
2018-10-03 10:54:40 -07:00
Jeffrey Regan
e32e5c21d7 Isolate k8sdeps to top level internal. 2018-10-03 10:21:43 -07:00
k8s-ci-robot
132cdad7c4 Merge pull request #400 from Liujingfang1/decoder
Add validator interface
2018-10-02 17:14:37 -07:00
Jingfang Liu
fa89a0ab4d Add validator interface 2018-10-02 15:09:19 -07:00
k8s-ci-robot
ad093555a6 Merge pull request #398 from monopole/injectDecoder
Introduce k8sdeps package to isolate k8s deps.
2018-10-02 13:41:55 -07:00
k8s-ci-robot
2fbccdd05b Merge pull request #394 from Liujingfang1/var
use local types in var reference
2018-10-02 11:52:43 -07:00
k8s-ci-robot
eb985a8af0 Merge pull request #397 from Liujingfang1/issue395
fix kustomize edit add label bug
2018-10-02 11:48:49 -07:00
jregan
8f150d84ae Introduce k8sdeps package to isolate k8s deps. 2018-10-02 11:36:53 -07:00
Jingfang Liu
74d8575097 fix kustomize edit add label bug 2018-10-02 10:44:35 -07:00
Jingfang Liu
71c3cf163e use local types in var reference 2018-10-02 10:25:28 -07:00
k8s-ci-robot
b95423285f Merge pull request #393 from monopole/resourceTests
Add tests for patch/resource reading.
2018-10-01 14:47:51 -07:00
jregan
24733315d7 Add tests for patch/resource reading. 2018-10-01 14:25:15 -07:00
Jeff Regan
fbc38d0c60 Merge pull request #390 from monopole/fixPatchNaming
Spelling nits.
2018-10-01 11:24:25 -07:00
k8s-ci-robot
8b5c4aa591 Merge pull request #391 from Liujingfang1/string
change sets.NewString() to []string
2018-10-01 11:13:52 -07:00
jregan
c9aff4c47a Spelling nits. 2018-10-01 10:56:35 -07:00
Jingfang Liu
8a8f35863c change sets.NewString() to []string 2018-10-01 10:53:39 -07:00
k8s-ci-robot
9a5d759230 Merge pull request #389 from Liujingfang1/pathconfig
add command to save the default transformer configurations to local files
2018-10-01 10:24:45 -07:00
Jingfang Liu
94c3b1212e add command to save the default transformer configurations to local files 2018-10-01 09:48:38 -07:00
k8s-ci-robot
c129a3d3b8 Merge pull request #385 from monopole/fixNits
Fix some Go nits.
2018-09-30 18:40:07 -07:00
jregan
6d935b6a4a Fix some Go nits. 2018-09-28 18:08:36 -07:00
k8s-ci-robot
8f903b6e3f Merge pull request #384 from monopole/renameApp
Rename Application to KustTarget
2018-09-28 14:34:38 -07:00
jregan
78139957d2 Rename Application to KustTarget 2018-09-28 14:07:01 -07:00
Jeff Regan
ffffbedf41 Merge pull request #383 from Liujingfang1/buildflag
Add flag to load transfomer configurations from files
2018-09-28 14:02:52 -07:00
Jingfang Liu
fb6130e1e0 Add flag to load transfomer configurations from files 2018-09-28 13:57:29 -07:00
k8s-ci-robot
4c94f3ec38 Merge pull request #382 from Liujingfang1/pathconfig
enable crd testcase
2018-09-28 11:33:47 -07:00
Jingfang Liu
d67425daf1 enable crd testcase 2018-09-28 10:48:16 -07:00
k8s-ci-robot
48065cc694 Merge pull request #381 from monopole/simplify
Simplify default config construction.
2018-09-28 10:31:23 -07:00
jregan
f35e16bd8d Simplify default config code. 2018-09-28 10:20:20 -07:00
k8s-ci-robot
986c7cc31b Merge pull request #380 from Liujingfang1/pathconfig
remove hard coded pathconfig
2018-09-28 10:01:41 -07:00
Jingfang Liu
078c90cabe remove hard coded pathconfig 2018-09-28 09:28:39 -07:00
k8s-ci-robot
30597252c7 Merge pull request #379 from Liujingfang1/pathconfig
Modify PathConfig.PathSlice method and add tests
2018-09-27 16:30:47 -07:00
Jingfang Liu
d8b27ef8fe Modify PathConfig.PathSlice method and add tests 2018-09-27 15:36:37 -07:00
k8s-ci-robot
19197a490e Merge pull request #378 from monopole/stringStuff
Increase sort determinism.
2018-09-27 13:46:23 -07:00
Jeffrey Regan
317833aeff Increase sort determinism. 2018-09-27 13:29:00 -07:00
k8s-ci-robot
acf989f1be Merge pull request #377 from Liujingfang1/pathconfig
Refactor crd package to depend on transformerconfig
2018-09-27 13:07:14 -07:00
Jingfang Liu
7ab710889c Refactor crd package to depend on transformerconfig 2018-09-27 10:39:29 -07:00
Jeff Regan
8ef87309a2 Merge pull request #315 from nikhita/fix-template-files
Move template files from docs/ to root
2018-09-27 09:30:33 -07:00
k8s-ci-robot
20fa90a137 Merge pull request #376 from monopole/gvk
Introduce gvk package to isolate apimachinery schema.
2018-09-26 16:45:15 -07:00
Jeffrey Regan
fb355eb320 Introduce gvk package to isolate apimachinery schema. 2018-09-26 15:02:38 -07:00
k8s-ci-robot
8aa0cc145c Merge pull request #375 from monopole/resIdTest
Add resid tests.
2018-09-26 13:49:36 -07:00
k8s-ci-robot
e276fc71c7 Merge pull request #373 from Liujingfang1/pathconfigmore
add default configurations for different transformers
2018-09-26 13:41:44 -07:00
Jeff Regan
119c3e3b24 Merge pull request #367 from OpenSourceZombie/patch-2
missing : after patchesJson6902 in the example file kustomization.yaml
2018-09-26 13:40:31 -07:00
Jeffrey Regan
67adc56c73 Add resid tests. 2018-09-26 13:31:25 -07:00
k8s-ci-robot
97a771d1e2 Merge pull request #374 from Liujingfang1/integrationtest
fix integration test script
2018-09-26 11:38:53 -07:00
Jingfang Liu
c27279ce7a fix integration test script 2018-09-26 11:20:10 -07:00
Jingfang Liu
13c368a2db add default configurations for different transformers 2018-09-26 11:11:29 -07:00
Jeff Regan
2f47e298d2 Merge pull request #371 from monopole/oddHgStuff
Goland wants these vendored hg files.
2018-09-25 11:56:41 -07:00
Jeffrey Regan
188ede2cd4 Goland wants these vendored hg files. 2018-09-25 11:55:55 -07:00
Jeff Regan
f23419fde6 Merge pull request #361 from Liujingfang1/pathconfig
Add transformer config package
2018-09-25 11:50:42 -07:00
theShirbiny
c614f4b5de missing : after patchesJson6902 2018-09-24 17:55:32 +02:00
k8s-ci-robot
3266716584 Merge pull request #356 from liuhuiping2013/master
remove metadata.creationTimestamp field from configMapGenerator
2018-09-21 09:46:02 -07:00
Jingfang Liu
8cc6df51f3 Add transformerconfig package and default configs 2018-09-19 11:14:14 -07:00
Jeff Regan
6b1ffe13a0 Merge pull request #357 from greghaynes/fix/install-sigs.k8s.io
Update install doc to use sigs.k8s.io
2018-09-18 13:50:29 -07:00
Gregory Haynes
ce3daf254f Update install doc to use sigs.k8s.io
When using go get github.com/kubernetes-sigs/kustomize running kustomize
panics with 'log_dir redefined'.
2018-09-18 19:03:06 +00:00
liuhuiping
6c5a75bf73 remove metadata.creationTimestamp field from configMapGenerator 2018-09-18 18:35:40 +08:00
k8s-ci-robot
58492e2d83 Merge pull request #349 from Liujingfang1/master
fix the release and build files
2018-09-13 12:00:36 -07:00
Jingfang Liu
a9f44aa259 fix the release and build files 2018-09-13 11:51:47 -07:00
k8s-ci-robot
b17d7fbbfd Merge pull request #339 from lswith/master
treat sub paths correctly
2018-09-13 09:24:09 -07:00
Luke Swithenbank
d78e77fb92 fix remote build's for subdirectories 2018-09-13 09:56:04 +10:00
Jingfang Liu
64fdb8d760 change github.com/kubernetes-sigs to sigs.k8s.io (#343)
* change github.com/kubernetes-sigs to sigs.k8s.io

* change go_import_path in .travis.yml
2018-09-12 12:41:38 -07:00
Jeff Regan
a377ec1dde Merge pull request #342 from Liujingfang1/master
remove dependency on internal error
2018-09-12 11:08:52 -07:00
Jingfang Liu
87e9964091 Merge pull request #341 from ebriand/patch-1
Fix typo in multibases readme
2018-09-12 09:17:21 -07:00
Jingfang Liu
60d8334fed remove dependency on internal error 2018-09-11 15:23:30 -07:00
Eric Briand
71f5105a86 Fix typo on staging 2018-09-11 13:33:28 +02:00
Jeff Regan
09a62efe88 Merge pull request #331 from burdiyan/master
Implement support for digests in imageTags
2018-09-10 10:57:53 -07:00
Alexandr Burdiyan
6dbf4b5b60 Apply code review recommendations 2018-09-10 11:48:47 +02:00
Alexandr Burdiyan
5401bd367b Implement support for digests in imageTags
This commit adds a new field to imageTags transformer
so that digests can be used instead of image tags if needed.

Closes https://github.com/kubernetes-sigs/kustomize/issues/326
2018-09-10 11:21:53 +02:00
Jeff Regan
f7def79764 Merge pull request #333 from monopole/deleteCode
Remove duplicate code.
2018-09-09 13:51:54 -07:00
jregan
cda909a609 Remove duplicate code. 2018-09-09 12:33:23 -07:00
k8s-ci-robot
6f61cadf9f Merge pull request #325 from Liujingfang1/master
Add examples and docs for patchesJson6902
2018-09-07 13:14:34 -07:00
Jingfang Liu
1c616b1962 Add examples and docs for patchesJson6902 2018-09-07 11:55:12 -07:00
Jeff Regan
849343fb41 Merge pull request #324 from Liujingfang1/master
Enable jsonpath transformers in application
2018-09-06 14:18:47 -07:00
Jingfang Liu
8810027d89 Enable jsonpath transformers in application 2018-09-06 14:02:30 -07:00
k8s-ci-robot
548ea8a9fb Merge pull request #323 from Liujingfang1/master
remove inline json patch format
2018-09-06 13:36:19 -07:00
Jingfang Liu
81b5cf65d6 remove inline json patch format 2018-09-06 11:18:19 -07:00
Jeff Regan
dc9ae64646 Merge pull request #321 from Liujingfang1/multibases
filter by namespace, prefix and detect conflict when resolving name reference
2018-09-05 16:10:53 -07:00
Jingfang Liu
829cb2baa3 address comments 2018-09-05 16:08:24 -07:00
Jingfang Liu
7b301446fa filter by namespace and nameprefix in namereference transformer 2018-09-05 13:17:44 -07:00
Jingfang Liu
4a297fa138 improve idslice 2018-09-05 13:02:51 -07:00
Jingfang Liu
7811d9f2bc Add multibases test with namereference conflict 2018-09-05 13:01:56 -07:00
Jingfang Liu
21ff81b758 Add multibases test with namereference nonconflict 2018-09-05 13:01:15 -07:00
Jingfang Liu
485bbddd3e Merge pull request #320 from Liujingfang1/master
remove go get varcheck
2018-09-04 15:43:59 -07:00
Jingfang Liu
6dc80293a6 remove go get varcheck 2018-09-04 15:07:38 -07:00
Jeff Regan
b649ad5c69 Merge pull request #310 from Liujingfang1/patchtransformer
Update patch factory and add multi transformer with checking conflicts
2018-09-04 09:32:08 -07:00
Jingfang Liu
d782abb214 Update patch factory and add multi transformer with checking conflicts 2018-09-04 09:13:26 -07:00
k8s-ci-robot
95f5becee1 Merge pull request #312 from monopole/fixSomeImports
Remove some unnecessary import renames.
2018-09-04 08:31:31 -07:00
Nikhita Raghunath
cdb78cbdd3 Move template files from docs/ to root 2018-09-01 20:22:22 +05:30
k8s-ci-robot
694d809f33 Merge pull request #313 from monopole/fixMarkdownLinks
Fix some busted documentation links.
2018-08-31 18:30:41 -07:00
k8s-ci-robot
df3c3c3357 Merge pull request #314 from monopole/noCleanup
Remove unread variable.
2018-08-31 18:29:25 -07:00
Jeffrey Regan
99e770b05a Remove unused variable. 2018-08-31 17:25:00 -07:00
Jeffrey Regan
340cb2b385 Remove unnecessary import aliases. 2018-08-31 17:20:03 -07:00
Jeffrey Regan
cdbd83a645 Fix some busted documentation links. 2018-08-31 17:05:32 -07:00
Jeff Regan
fab2a5a5d7 Merge pull request #311 from monopole/updateDeps
Add gopkg.in/yaml.v2 to Gopkg.lock
2018-08-31 16:24:16 -07:00
Jeffrey Regan
8da2f37181 Add gopkg.in/yaml.v2 to Gopkg.lock 2018-08-31 16:20:18 -07:00
k8s-ci-robot
c906a0c16e Merge pull request #309 from monopole/cleanupAddLabels
Simplify addmetadata.
2018-08-31 16:13:31 -07:00
Jeffrey Regan
93618166b6 Cleanup addmetadata. 2018-08-31 15:58:36 -07:00
k8s-ci-robot
babfb3faa9 Merge pull request #300 from Liujingfang1/patchtransformer
Add transformer to apply json patch6902
2018-08-31 12:07:17 -07:00
Jingfang Liu
cedf215445 add PatchJson6902Factory to make transformer 2018-08-31 10:21:58 -07:00
Jeff Regan
51a4907f89 Merge pull request #307 from khrisrichardson/apimachinery-validation
use apimachinery for annotation/label validation
2018-08-31 09:42:47 -07:00
Khris Richardson
6457162383 use apimachinery for annotation/label validation 2018-08-31 07:40:00 -07:00
Jingfang Liu
7f0e9e3a6a Add patchJson6902 transformer 2018-08-30 15:34:42 -07:00
Jingfang Liu
95cf508b2b Add github.com/krishicks/yaml-patch to vendor 2018-08-30 13:45:25 -07:00
Jeff Regan
4a565ffdb8 Merge pull request #303 from gitirabassi/all-git-repos
if the prefix of the base is 'git::' will make the use of go-getter to download repo
2018-08-30 10:06:46 -07:00
Jeff Regan
17f1779a48 Merge pull request #302 from gitirabassi/storageClassSecret
Storage class secret
2018-08-30 10:03:03 -07:00
gitirabassi
a76cb0b008 force using the git protocol to downlaod every kind of repo non just from github 2018-08-30 11:02:03 +02:00
gitirabassi
9700bc3298 added all the documented secret for storageclasses 2018-08-29 23:05:40 +02:00
gitirabassi
ce31dac24f added storageclass paramether secret for glusterfs configuration with kustomize 2018-08-29 22:55:32 +02:00
k8s-ci-robot
a81b2e32e0 Merge pull request #299 from Liujingfang1/patch
change patches to patchesStrategicMerge in tests and examples
2018-08-28 13:57:00 -07:00
Jingfang Liu
b713d5a1cc change patches to patchesStrategicMerge in tests and examples 2018-08-28 09:40:34 -07:00
k8s-ci-robot
e11ba17248 Merge pull request #286 from Liujingfang1/master
Add patchesJson6902 and patchesStategicMerge to kustomization
2018-08-27 16:09:49 -07:00
Jingfang Liu
3d9d4bd36f address comments 2018-08-27 15:44:42 -07:00
Jingfang Liu
6a3e3c3a71 Add JSONPatch to kustomization 2018-08-27 13:52:21 -07:00
Jeff Regan
633c43a672 Merge pull request #292 from babiel/pdb-matchlabels
Disable creation of PDB matchLabels
2018-08-24 09:27:41 -07:00
Maximilian Gaß
0833693372 Disable creation of PDB matchLabels
Allow for using matchExpressions on its own
2018-08-24 13:51:05 +02:00
Jeff Regan
77c07ba96e Merge pull request #290 from philoserf/patch-1
trivial: Change dep constraint to an override
2018-08-23 17:07:44 -07:00
Mark Ayers
6847bb7924 trivial: Change dep constraint to an override
fixes #289
2018-08-23 15:58:27 -07:00
k8s-ci-robot
f0deaf707d Merge pull request #287 from emosbaugh/fix-gopath-isrepourl
Fix loader loader when run from gopath
2018-08-23 15:08:25 -07:00
Ethan Mosbaugh
e113944027 fix loader loader when run from gopath 2018-08-23 14:54:58 -07:00
k8s-ci-robot
1cf9131ae2 Merge pull request #285 from monopole/declutter
Move some docs to docs dir (declutter the top).
2018-08-23 13:33:06 -07:00
Jeffrey Regan
da142a8e97 Move some docs to docs dir (declutter the top). 2018-08-23 11:33:12 -07:00
Jeff Regan
6c81e3b95f Merge pull request #284 from Liujingfang1/vendor
Add missing files when running dep ensure
2018-08-23 11:27:47 -07:00
Jingfang Liu
a0089a2521 Add missing files when running dep ensure 2018-08-23 11:07:42 -07:00
k8s-ci-robot
11768f6232 Merge pull request #280 from monopole/fixntis
Fix some Go nits.
2018-08-23 10:37:58 -07:00
Jeff Regan
675c17737f Merge pull request #279 from Liujingfang1/quote
fix the double quotation problem in ConfigMapGenerator
2018-08-23 10:35:34 -07:00
Jeffrey Regan
735a93d000 Fix some Go nits. 2018-08-23 10:30:32 -07:00
Jeff Regan
67d2c2ed4a Merge pull request #281 from monopole/addVarCheck
Add varcheck to presubmit.
2018-08-23 10:25:32 -07:00
Jeffrey Regan
f931e15653 Add varcheck to presubmit. 2018-08-23 10:17:37 -07:00
Jingfang Liu
34169174a8 fix the double quotation problem in ConfigMapGenerator 2018-08-23 09:36:50 -07:00
Jeff Regan
ebf33964c7 Merge pull request #276 from kubernetes-sigs/add-code-of-conduct-1
Create CODE_OF_CONDUCT.md
2018-08-22 20:05:47 -07:00
Jeff Regan
38a5e12d66 Create CODE_OF_CONDUCT.md 2018-08-22 20:05:19 -07:00
k8s-ci-robot
04ab218fa0 Merge pull request #275 from monopole/deletediff
Delete diff command and code it uses.
2018-08-22 18:38:39 -07:00
Jeffrey Regan
950c353f90 Delete diff command and code it uses. 2018-08-22 17:18:39 -07:00
Jeff Regan
aff09b1108 Merge pull request #271 from Liujingfang1/cleanup
cleanup after handling remote bases
2018-08-22 17:14:11 -07:00
Jingfang Liu
6da691f874 cleanup after handling remote bases 2018-08-22 13:22:45 -07:00
Jeff Regan
22c99aa535 Merge pull request #274 from monopole/docsreadme
Tweak docs readme
2018-08-22 12:21:32 -07:00
Jeffrey Regan
5fa209acfa Tweak docs readme 2018-08-22 12:20:13 -07:00
Jeff Regan
d72879e109 Merge pull request #147 from guineveresaenger/labels-and-annotations
Edit add label/annotation
2018-08-22 10:33:00 -07:00
Jeff Regan
337f3631ff Merge pull request #272 from Liujingfang1/docs
Add docs README.md
2018-08-22 10:22:00 -07:00
guineveresaenger
b3993dc874 Adds starter validation framework for semantic validation of inputs. 2018-08-22 18:20:51 +02:00
guineveresaenger
11c04dd6c4 Removes semantic validation from addmetadata.go and tests.
Due to moving some input parsing to the Validate method, it was renamed to reflect this additional purpose.
Tests were removed where appropriate.
2018-08-22 18:15:34 +02:00
Jingfang Liu
b29e449d4a Add docs README.md 2018-08-22 09:05:54 -07:00
Jingfang Liu
430f2f84fb Merge pull request #270 from Liujingfang1/docs
fix bug in the example download links
2018-08-21 12:08:32 -07:00
Jingfang Liu
52c6b5755b fix bug in the example download links 2018-08-21 12:04:53 -07:00
k8s-ci-robot
958bc63293 Merge pull request #269 from Liujingfang1/pvc
Add namereference of PersistentVolume in PersistentVolumeClain
2018-08-21 09:48:33 -07:00
Jingfang Liu
94ed0fe515 Add namereference of PersistentVolume in PersistentVolumeClain 2018-08-21 09:37:25 -07:00
Jeff Regan
bb8233ceff Merge pull request #265 from Liujingfang1/metadata
add typemeta to kustomization
2018-08-20 13:59:43 -07:00
Jingfang Liu
6221bed190 add typemeta to kustomization 2018-08-20 13:47:33 -07:00
k8s-ci-robot
1ffeb181e7 Merge pull request #264 from Liujingfang1/docs
Add example for kustomize build {url} and remote bases
2018-08-20 12:19:00 -07:00
Jingfang Liu
759ba1cbf4 Add example for kustomize build {url} 2018-08-20 09:52:32 -07:00
k8s-ci-robot
12f2c41273 Merge pull request #266 from ahmetb/patch-1
add homebrew package to INSTALL.md
2018-08-17 10:48:01 -07:00
Ahmet Alp Balkan
2174741376 add homebrew package to INSTALL.md 2018-08-17 07:50:28 -07:00
guineveresaenger
31dd8fc5b1 Restructured tests 2018-08-16 13:32:42 -07:00
guineveresaenger
77f4811779 Tests test Validate function 2018-08-16 02:36:11 -07:00
Jeff Regan
7050a45134 Merge pull request #262 from Liujingfang1/repoUrl3
Add all dependency of go-getter
2018-08-15 15:47:35 -07:00
k8s-ci-robot
3b64f1e102 Merge pull request #260 from Liujingfang1/repoUrl2
Add kustomize build {repoUrl}
2018-08-15 15:45:00 -07:00
Jingfang Liu
6c4c79e2cc Merge pull request #263 from Liujingfang1/gc
Add garbage collection KEP link
2018-08-15 15:22:21 -07:00
Jingfang Liu
3975ebc21a Add garbage collection KEP link 2018-08-15 15:19:18 -07:00
Jingfang Liu
ec95e5f97e Add all dependency of go-getter 2018-08-15 11:37:03 -07:00
Jingfang Liu
72b1a4bc5c combine fileLoader.New and NewLoader into one function: NewLoader 2018-08-15 11:04:31 -07:00
k8s-ci-robot
16447efca3 Merge pull request #255 from sethpollack/secret
add docs for envCommand
2018-08-15 09:35:02 -07:00
guineveresaenger
524d593c5c Separate functions for RunnAddLabel and RunAddAnnotation 2018-08-15 03:51:56 -07:00
guineveresaenger
3b644474c4 Parse data into string map for easy access in RunAddMetadata 2018-08-15 03:13:03 -07:00
Seth Pollack
42e6ced2b0 add docs 2018-08-14 20:55:26 -04:00
Jingfang Liu
f018370628 Add kustomize build {repoUrl} 2018-08-14 16:10:51 -07:00
Jeff Regan
c9a8bc1121 Merge pull request #256 from ivan4th/command-timeout-1
Add timeoutSeconds to secretArgs
2018-08-14 14:54:50 -07:00
k8s-ci-robot
8c7cbb12dd Merge pull request #257 from Liujingfang1/repoUrl2
Add dependency: github.com/hashicorp/go-getter
2018-08-14 14:49:29 -07:00
Jingfang Liu
b02f7775c5 manually add dependency on go-getter 2018-08-14 14:37:31 -07:00
Ivan Shvedunov
f9a0e671b7 Add timeoutSeconds to secretArgs 2018-08-14 22:55:59 +03:00
Jeff Regan
70fb22cad6 Merge pull request #250 from ivan4th/fix-resource-load-crash
Don't crash on resource load errors
2018-08-14 12:53:24 -07:00
Ivan Shvedunov
2ae00db6a9 Don't crash on resource load errors 2018-08-14 22:14:12 +03:00
k8s-ci-robot
f9577ab540 Merge pull request #247 from ryane/setnamespace
add support for `kustomize edit set namespace`
2018-08-13 11:17:06 -07:00
guineveresaenger
6a2786a5c4 Remove Complete function and references 2018-08-13 07:49:51 -07:00
guineveresaenger
924aa6fb29 Use iota declaration for constants and implements string method for KindOfAdd metadata 2018-08-13 07:46:06 -07:00
ryane
e2cd44f9d8 add support for kustomize edit set namespace
fixes #246
2018-08-10 22:42:50 -04:00
guineveresaenger
187415430f Removed individual files in favor of combined metadata file 2018-07-18 17:09:41 -07:00
guineveresaenger
afac2fb46a Uses single file for both addLabel and addAnnotation commands, as the code is nearly identical. Tests included. 2018-07-18 17:09:41 -07:00
guineveresaenger
20fd433f75 Add tests 2018-07-18 17:09:41 -07:00
guineveresaenger
1e3824057b Implements labels and annotations as subcommands of edit 2018-07-18 17:09:41 -07:00
3475 changed files with 1962831 additions and 27850 deletions

4
.gitignore vendored
View File

@@ -4,9 +4,13 @@
*.dll
*.so
*.dylib
kustomize
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# We use sed -i.bak when doing in-line replace, because it works better cross-platform
.bak

30
.golangci.yml Normal file
View File

@@ -0,0 +1,30 @@
run:
deadline: 5m
linters:
disable-all: true
enable:
- dupl
- goconst
- gocyclo
- gofmt
- golint
- govet
- ineffassign
- interfacer
- lll
- misspell
- nakedret
- structcheck
- unparam
- varcheck
linters-settings:
dupl:
threshold: 400
lll:
line-length: 170
gocyclo:
min-complexity: 15
golint:
min-confidence: 0.85

View File

@@ -1,19 +1,25 @@
language: go
go:
- 1.10.x
- 1.11.x
# go_import_path: k8s.io/kubectl
go_import_path: sigs.k8s.io/kustomize
# Maybe, maybe not.
# sudo: false
# Only clone the most recent commit.
git:
depth: 1
env:
- GOLANGCI_RELEASE="v1.10.2"
before_install:
- source ./bin/consider-early-travis-exit.sh
- sudo apt-get install tree
- go get -u github.com/golang/lint/golint
- go get -u golang.org/x/tools/cmd/goimports
- go get -u github.com/onsi/ginkgo/ginkgo
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $GOPATH/bin ${GOLANGCI_RELEASE}
- go get -u github.com/monopole/mdrip
- go get -u github.com/fzipp/gocyclo
- go get -u gopkg.in/alecthomas/gometalinter.v2 && gometalinter.v2 --install
# Install must be set to prevent default `go get` to run.
# The dependencies have already been vendored by `dep` so

View File

@@ -1,36 +1,22 @@
# Contributing guidelines
# Contributing Guidelines
[Contributor License Agreement]: https://git.k8s.io/community/CLA.md
[github workflow guide]: https://github.com/kubernetes/community/blob/master/contributors/guide/github-workflow.md
[CNCF code of conduct]: https://github.com/cncf/foundation/blob/master/code-of-conduct.md
Welcome to Kubernetes. We are excited about the prospect of you joining our [community](https://github.com/kubernetes/community)! The Kubernetes community abides by the CNCF [code of conduct](code-of-conduct.md). Here is an excerpt:
## Contributing a Patch
_As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities._
1. Kubernetes projects require contributors to sign the
[Contributor License Agreement] before pull requests
can be considered.
1. Submit an issue describing your proposed change to
the repo in question.
1. The [repo owners](OWNERS) will respond to your issue
promptly.
1. Fork the repo, develop and test your code.
See the [github workflow guide].
1. For _new features_, provide a markdown-based demo following
the pattern established in the [examples](examples) directory.
Run `bin/pre-commit.sh` to test your demo.
1. Submit a pull request.
## Getting Started
## Community, discussion, contribution, and support
We have full documentation on how to get started contributing here:
Learn how to engage with the Kubernetes community on
the [community page](http://kubernetes.io/community/).
- [Contributor License Agreement](https://git.k8s.io/community/CLA.md) Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests
- [Kubernetes Contributor Guide](http://git.k8s.io/community/contributors/guide) - Main contributor documentation, or you can just jump directly to the [contributing section](http://git.k8s.io/community/contributors/guide#contributing)
- [Contributor Cheat Sheet](https://git.k8s.io/community/contributors/guide/contributor-cheatsheet.md) - Common resources for existing developers
You can reach the maintainers of this project at:
## Mentorship
- [Slack](http://slack.k8s.io/)
- [Mailing List](https://groups.google.com/forum/#!forum/kubernetes-kustomize)
- [Mentoring Initiatives](https://git.k8s.io/community/mentoring) - We have a diverse set of mentorship programs available that are always looking for volunteers!
## Code of conduct
## Contact Information
Participation in the Kubernetes community is governed
by the [CNCF code of conduct].
- [Slack channel](https://kubernetes.slack.com/messages/sig-cli)
- [Mailing list](https://groups.google.com/forum/#!forum/kubernetes-sig-cli)

144
Gopkg.lock generated
View File

@@ -17,6 +17,54 @@
pruneopts = ""
revision = "de5bf2ad457846296e2031421a34e2568e304e35"
[[projects]]
digest = "1:4905d4dce09d1a9e93fe2b9733f92bee5f149dd229727bbc074465b24fb489cd"
name = "github.com/aws/aws-sdk-go"
packages = [
"aws",
"aws/awserr",
"aws/awsutil",
"aws/client",
"aws/client/metadata",
"aws/corehandlers",
"aws/credentials",
"aws/credentials/ec2rolecreds",
"aws/credentials/endpointcreds",
"aws/credentials/stscreds",
"aws/csm",
"aws/defaults",
"aws/ec2metadata",
"aws/endpoints",
"aws/request",
"aws/session",
"aws/signer/v4",
"internal/sdkio",
"internal/sdkrand",
"internal/sdkuri",
"internal/shareddefaults",
"private/protocol",
"private/protocol/eventstream",
"private/protocol/eventstream/eventstreamapi",
"private/protocol/query",
"private/protocol/query/queryutil",
"private/protocol/rest",
"private/protocol/restxml",
"private/protocol/xml/xmlutil",
"service/s3",
"service/sts",
]
pruneopts = ""
revision = "fde4ded7becdeae4d26bf1212916aabba79349b4"
version = "v1.14.12"
[[projects]]
branch = "master"
digest = "1:98e84060475ed245c3b355042afd43a74aa7d32efe50658f4f995977916f9fc3"
name = "github.com/bgentry/go-netrc"
packages = ["netrc"]
pruneopts = ""
revision = "9fd32a8b3d3d3f9d43c341bfe098430e07609480"
[[projects]]
digest = "1:56c130d885a4aacae1dd9c7b71cfe39912c7ebc1ff7d2b46083c8812996dc43b"
name = "github.com/davecgh/go-spew"
@@ -52,6 +100,14 @@
revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7"
version = "v1.0.0"
[[projects]]
digest = "1:858b7fe7b0f4bc7ef9953926828f2816ea52d01a88d72d1c45bc8c108f23c356"
name = "github.com/go-ini/ini"
packages = ["."]
pruneopts = ""
revision = "358ee7663966325963d4e8b2e1fbd570c5195153"
version = "v1.38.1"
[[projects]]
branch = "master"
digest = "1:e116a4866bffeec941056a1fcfd37e520fad1ee60e4e3579719f19a43c392e10"
@@ -137,6 +193,41 @@
revision = "ee43cbb60db7bd22502942cccbc39059117352ab"
version = "v0.1.0"
[[projects]]
branch = "master"
digest = "1:f5d25fd7bdda08e39e01193ef94a1ebf7547b1b931bcdec785d08050598f306c"
name = "github.com/hashicorp/go-cleanhttp"
packages = ["."]
pruneopts = ""
revision = "d5fe4b57a186c716b0e00b8c301cbd9b4182694d"
[[projects]]
branch = "master"
digest = "1:fd15b3f6aac9d0fe68c6e38922282e0d2e88cd77b927ac3dd842e363645522c0"
name = "github.com/hashicorp/go-getter"
packages = [
".",
"helper/url",
]
pruneopts = ""
revision = "4bda8fa99001c61db3cad96b421d4c12a81f256d"
[[projects]]
branch = "master"
digest = "1:2cf6c60c74eacadd31652674364af55c8d54a86b8ea193548f1c37f8c9af8f9c"
name = "github.com/hashicorp/go-safetemp"
packages = ["."]
pruneopts = ""
revision = "b1a1dbde6fdc11e3ae79efd9039009e22d4ae240"
[[projects]]
branch = "master"
digest = "1:139bdc2c89779b8ff8b1150be28f889b0ed964e6da96f32cbc9035bd4642881c"
name = "github.com/hashicorp/go-version"
packages = ["."]
pruneopts = ""
revision = "270f2f71b1ee587f3b609f00f422b76a6b28f348"
[[projects]]
digest = "1:870d441fe217b8e689d7949fef6e43efbc787e50f200cb1e70dbca9204a1d6be"
name = "github.com/inconshreveable/mousetrap"
@@ -145,6 +236,13 @@
revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75"
version = "v1.0"
[[projects]]
digest = "1:6f49eae0c1e5dab1dafafee34b207aeb7a42303105960944828c2079b92fc88e"
name = "github.com/jmespath/go-jmespath"
packages = ["."]
pruneopts = ""
revision = "0b12d6b5"
[[projects]]
digest = "1:9eab2325abbed0ebcee9d44bb3660a69d5d10e42d5ac4a0e77f7a6ea22bfce88"
name = "github.com/json-iterator/go"
@@ -165,6 +263,22 @@
pruneopts = ""
revision = "3fdea8d05856a0c8df22ed4bc71b3219245e4485"
[[projects]]
branch = "master"
digest = "1:83854f6b1d2ce047b69657e3a87ba7602f4c5505e8bdfd02ab857db8e983bde1"
name = "github.com/mitchellh/go-homedir"
packages = ["."]
pruneopts = ""
revision = "58046073cbffe2f25d425fe1331102f55cf719de"
[[projects]]
branch = "master"
digest = "1:51c98e2c9a8d0a724a69f46421876af14e12132cb02f1d0e144785d752247162"
name = "github.com/mitchellh/go-testing-interface"
packages = ["."]
pruneopts = ""
revision = "a61a99592b77c9ba629d254a693acffaeb4b7e28"
[[projects]]
digest = "1:0c0ff2a89c1bb0d01887e1dac043ad7efbf3ec77482ef058ac423d13497e16fd"
name = "github.com/modern-go/concurrent"
@@ -205,18 +319,31 @@
revision = "583c0c0531f06d5278b7d917446061adc344b5cd"
version = "v1.0.1"
[[projects]]
digest = "1:ee723e6a1962a196eeba1b24f82af61a4f60f8821d7aa96d48e787f8337bcffc"
name = "github.com/ulikunitz/xz"
packages = [
".",
"internal/hash",
"internal/xlog",
"lzma",
]
pruneopts = ""
revision = "0c6b41e72360850ca4f98dc341fd999726ea007f"
version = "v0.5.4"
[[projects]]
branch = "master"
digest = "1:9e548233d0dc00e74be262e54a9d1bbe7e4c19e5951083520261740e37daeb02"
digest = "1:35171304d8332a0cfac5f3bd9222467f036732ddde75c65278b16f65216e03ed"
name = "golang.org/x/net"
packages = [
"http/httpguts",
"http2",
"http2/hpack",
"idna",
"lex/httplex",
]
pruneopts = ""
revision = "2491c5de3490fced2f6cff376127c667efeed857"
revision = "1c05540f6879653db88113bc4a2b70aec4bd491f"
[[projects]]
digest = "1:5acd3512b047305d49e8763eef7ba423901e85d5dd2fd1e71778a0ea8de10bd4"
@@ -300,9 +427,14 @@
digest = "1:bcb2285bb525712de7903a5d254c2789df65c8b58d2cfac5a26d950ad94c2079"
name = "k8s.io/apimachinery"
packages = [
"pkg/api/equality",
"pkg/api/meta",
"pkg/api/resource",
"pkg/api/validation",
"pkg/apis/meta/v1",
"pkg/apis/meta/v1/unstructured",
"pkg/apis/meta/v1/validation",
"pkg/apis/meta/v1beta1",
"pkg/conversion",
"pkg/conversion/queryparams",
"pkg/fields",
@@ -362,17 +494,21 @@
"github.com/evanphx/json-patch",
"github.com/ghodss/yaml",
"github.com/golang/glog",
"github.com/hashicorp/go-getter",
"github.com/pkg/errors",
"github.com/spf13/cobra",
"gopkg.in/yaml.v2",
"k8s.io/api/core/v1",
"k8s.io/apimachinery/pkg/api/validation",
"k8s.io/apimachinery/pkg/apis/meta/v1",
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured",
"k8s.io/apimachinery/pkg/apis/meta/v1/validation",
"k8s.io/apimachinery/pkg/runtime",
"k8s.io/apimachinery/pkg/runtime/schema",
"k8s.io/apimachinery/pkg/util/mergepatch",
"k8s.io/apimachinery/pkg/util/sets",
"k8s.io/apimachinery/pkg/util/strategicpatch",
"k8s.io/apimachinery/pkg/util/validation",
"k8s.io/apimachinery/pkg/util/validation/field",
"k8s.io/apimachinery/pkg/util/yaml",
"k8s.io/client-go/kubernetes/scheme",
"k8s.io/kube-openapi/pkg/common",

View File

@@ -49,10 +49,18 @@
name = "k8s.io/client-go"
version = "7.0.0"
[[constraint]]
[[override]]
branch = "master"
name = "k8s.io/utils"
[[constraint]]
[[override]]
branch = "master"
name = "github.com/go-openapi/spec"
[[constraint]]
branch = "master"
name = "github.com/hashicorp/go-getter"
[[constraint]]
name = "github.com/krishicks/yaml-patch"
version = "0.0.10"

View File

@@ -9,6 +9,8 @@ patch [kubernetes style] API objects. It's like
[`make`], in that what it does is declared in a file,
and it's like [`sed`], in that it emits editted text.
This tool is sponsored by [sig-cli] ([KEP]).
[![Build Status](https://travis-ci.org/kubernetes-sigs/kustomize.svg?branch=master)](https://travis-ci.org/kubernetes-sigs/kustomize)
[![Go Report Card](https://goreportcard.com/badge/github.com/kubernetes-sigs/kustomize)](https://goreportcard.com/report/github.com/kubernetes-sigs/kustomize)
@@ -113,10 +115,18 @@ The YAML can be directly [applied] to a cluster:
> kustomize build ~/someApp/overlays/production | kubectl apply -f -
> ```
## About
## Community, discussion, contribution, and support
This tool is sponsored by [sig-cli] ([KEP]).
Learn how to engage with the Kubernetes community on the [community page].
You can reach the maintainers of this project at:
- [Slack]
- [Mailing List]
### Code of conduct
Participation in the Kubernetes community is governed by the [Kubernetes Code of Conduct].
[KEP]: https://github.com/kubernetes/community/blob/master/keps/sig-cli/0008-kustomize.md
[`make`]: https://www.gnu.org/software/make
@@ -127,7 +137,7 @@ This tool is sponsored by [sig-cli] ([KEP]).
[examples]: examples/README.md
[imageBase]: docs/base.jpg
[imageOverlay]: docs/overlay.jpg
[install]: INSTALL.md
[install]: docs/INSTALL.md
[kubernetes style]: docs/glossary.md#kubernetes-style-object
[kustomization]: docs/glossary.md#kustomization
[overlay]: docs/glossary.md#overlay
@@ -139,3 +149,7 @@ This tool is sponsored by [sig-cli] ([KEP]).
[variant]: docs/glossary.md#variant
[variants]: docs/glossary.md#variant
[workflows]: docs/workflows.md
[community page]: http://kubernetes.io/community/
[Kubernetes Code of Conduct]: code-of-conduct.md
[Slack]: https://kubernetes.slack.com/messages/sig-cli
[Mailing List]: https://groups.google.com/forum/#!forum/kubernetes-sig-cli

View File

@@ -11,10 +11,6 @@ cd "$base_dir" || {
rc=0
function go_dirs {
go list -f '{{.Dir}}' ./... | tail -n +2 | tr '\n' '\0'
}
function runTest {
local name=$1
local result="SUCCESS"
@@ -28,41 +24,8 @@ function runTest {
printf "============== end %s : %s code=%d\n\n\n" "$name" "$result" $code
}
function testGoFmt {
diff <(echo -n) <(go_dirs | xargs -0 gofmt -s -d -l)
}
function testGoCyclo {
diff <(echo -n) <(go_dirs | xargs -0 gocyclo -over 15)
}
function testGoLint {
diff -u <(echo -n) <(go_dirs | xargs -0 golint --min_confidence 0.85 )
}
function testGoMetalinter {
diff -u <(echo -n) <(go_dirs | xargs -0 gometalinter.v2 --disable-all --deadline 5m \
--enable=misspell \
--enable=structcheck \
--enable=deadcode \
# Disabling 'goimports' because it reports hyphens in imported package \
# names as errors, and we have to vendor them in regardless. \
# --enable=goimports \
--enable=varcheck \
--enable=goconst \
--enable=unparam \
--enable=ineffassign \
--enable=nakedret \
--enable=interfacer \
--enable=misspell \
--line-length=170 --enable=lll \
--dupl-threshold=400 --enable=dupl)
}
function testGoVet {
go vet -all ./...
function testGoLangCILint {
golangci-lint run ./...
}
function testGoTest {
@@ -73,11 +36,7 @@ function testExamples {
mdrip --mode test --label test README.md ./examples
}
runTest testGoFmt
runTest testGoMetalinter
runTest testGoLint
runTest testGoVet
runTest testGoCyclo
runTest testGoLangCILint
runTest testGoTest
runTest testExamples

View File

@@ -23,10 +23,10 @@ set -x
# - Use /go as the default GOPATH because this is what the image uses
# - Link our current directory (containing the source code) to the package location in the GOPATH
OWNER="kubernetes-sigs"
OWNER="sigs.k8s.io"
REPO="kustomize"
GO_PKG_OWNER=$GOPATH/src/github.com/$OWNER
GO_PKG_OWNER=$GOPATH/src/$OWNER
GO_PKG_PATH=$GO_PKG_OWNER/$REPO
mkdir -p $GO_PKG_OWNER

View File

@@ -4,7 +4,7 @@ project_name: kustomize
builds:
- main: ./kustomize.go
binary: kustomize
ldflags: -s -X github.com/kubernetes-sigs/kustomize/pkg/commands.kustomizeVersion={{.Version}} -X github.com/kubernetes-sigs/kustomize/pkg/commands.gitCommit={{.Commit}} -X github.com/kubernetes-sigs/kustomize/pkg/commands.buildDate={{.Date}}
ldflags: -s -X sigs.k8s.io/kustomize/pkg/commands.kustomizeVersion={{.Version}} -X sigs.k8s.io/kustomize/pkg/commands.gitCommit={{.Commit}} -X sigs.k8s.io/kustomize/pkg/commands.buildDate={{.Date}}
goos:
- darwin
- linux

144
build/vendor_kustomize.sh Executable file
View File

@@ -0,0 +1,144 @@
#!/bin/bash
#
# Copyright 2018 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
set -x
# vendor_kustomize.sh creates the change in kubernetes repo for vendoring kustomize
function setUpWorkspace {
KPATH=~/kustomize_vendor
mkdir $KPATH
GOPATH=$KPATH
}
function cloneK8s {
mkdir -p $GOPATH/src/k8s.io
cd $GOPATH/src/k8s.io
git clone git@github.com:kubernetes/kubernetes.git
}
function godepRestore {
cd $GOPATH/src/k8s.io/kubernetes
# restore dependencies
hack/godep-restore.sh
}
function getKustomizeDeps {
# get Kustomize and Kustomize dependencies
godep get sigs.k8s.io/kustomize/pkg/commands
godep get github.com/bgentry/go-netrc/netrc
godep get github.com/hashicorp/go-cleanhttp
godep get github.com/hashicorp/go-getter
godep get github.com/hashicorp/go-safetemp
godep get github.com/hashicorp/go-version
# The hashes below passed bin/pre-commit.sh with kustomize HEAD at time of merger.
DEPS=(
"hashicorp/go-getter 4bda8fa99001c61db3cad96b421d4c12a81f256d"
"hashicorp/go-cleanhttp d5fe4b57a186c716b0e00b8c301cbd9b4182694d"
"hashicorp/go-safetemp b1a1dbde6fdc11e3ae79efd9039009e22d4ae240"
"hashicorp/go-version 270f2f71b1ee587f3b609f00f422b76a6b28f348"
"bgentry/go-netrc 9fd32a8b3d3d3f9d43c341bfe098430e07609480"
"mitchellh/go-homedir 58046073cbffe2f25d425fe1331102f55cf719de"
"mitchellh/go-testing-interface a61a99592b77c9ba629d254a693acffaeb4b7e28"
"ulikunitz/xz v0.5.4"
)
function foo {
cd $GOPATH/src/github.com/$1
git checkout $2
}
for i in "${DEPS[@]}"; do
foo $i
done
}
function updateK8s {
# Copy k8sdeps from Kustomize to kubectl
mkdir -p $GOPATH/src/k8s.io/kubernetes/pkg/kubectl/kustomize
cp -r $GOPATH/src/sigs.k8s.io/kustomize/internal/k8sdeps \
$GOPATH/src/k8s.io/kubernetes/pkg/kubectl/kustomize/k8sdeps
# Change import path of k8sdeps
find $GOPATH/src/k8s.io/kubernetes/pkg/kubectl/kustomize/k8sdeps \
-type f -name "*.go" | \
xargs sed -i \
's!sigs.k8s.io/kustomize/internal/k8sdeps!k8s.io/kubernetes/pkg/kubectl/kustomize/k8sdeps!'
# Add kustomize command to kubectl
cat > $GOPATH/kubectl.diff << EOF
diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go
index 43a541ecc9..2d23bfd27d 100644
--- a/pkg/kubectl/cmd/cmd.go
+++ b/pkg/kubectl/cmd/cmd.go
@@ -74,6 +74,8 @@ import (
"k8s.io/kubernetes/pkg/kubectl/util/templates"
"k8s.io/cli-runtime/pkg/genericclioptions"
+ "k8s.io/kubernetes/pkg/kubectl/kustomize/k8sdeps"
+ "sigs.k8s.io/kustomize/pkg/commands"
)
const (
@@ -505,6 +507,7 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command {
replace.NewCmdReplace(f, ioStreams),
wait.NewCmdWait(f, ioStreams),
convert.NewCmdConvert(f, ioStreams),
+ templates.NormalizeAll(commands.NewDefaultCommand(k8sdeps.NewFactory())),
},
},
{
EOF
cd $GOPATH/src/k8s.io/kubernetes
git apply --ignore-space-change --ignore-whitespace $GOPATH/kubectl.diff
}
function godepSave {
# Save all dependencies into k8s.io/kubernetes/vendor by running
# hack/godep-save.sh
./hack/godep-save.sh
}
function verify {
# make sure in k8s.io/kubernetes/vendor/sigs.k8s.io/kustomize
# there is no internal package
test 0 == $(ls $GOPATH/src/k8s.io/kubernetes/vendor/sigs.k8s.io/kustomize | grep “internal” | wc -l)
# Make sure it compiles.
test 0 == $(bazel build cmd/kubectl:kubectl)
# next step, open a PR
echo "The change for vendoring kustomize is ready in $GOPATH/src/k8s.io/kubernetes.\n Next step, open a PR for it.\n"
}
function updateDocs {
./hack/update-generated-docs.sh
}
setUpWorkspace
cloneK8s
godepRestore
getKustomizeDeps
updateK8s
godepSave
verify
updateDocs

View File

@@ -1,6 +1,3 @@
[Kubernetes Community Code of Conduct]: https://git.k8s.io/community/code-of-conduct.md
# Kubernetes Community Code of Conduct
# Code of Conduct
This project has adopted the
[Kubernetes Community Code of Conduct].
Please refer to our [Kubernetes Community Code of Conduct](https://git.k8s.io/community/code-of-conduct.md)

View File

@@ -3,7 +3,13 @@
## Installation
Download a binary from the [release page].
On macOS, you can install kustomize with Homebrew package
manager:
brew install kustomize
For all operating systems, download a binary from the
[release page].
Or try this to grab the latest official release
using the command line:
@@ -23,5 +29,5 @@ To install from head with [Go] v1.10.1 or higher:
<!-- @installkustomize @test -->
```
go get github.com/kubernetes-sigs/kustomize
go get sigs.k8s.io/kustomize
```

23
docs/README.md Normal file
View File

@@ -0,0 +1,23 @@
# Kustomize docs
* [installation instructions](INSTALL.md)
* [kustomization.yaml](kustomization.yaml) - Example of a
[kustomization](glossary.md#kustomization)
with explanations of each field.
* [workflow](workflows.md) - Some steps one might take in using
bespoke and off-the-shelf configurations.
* [glossary](glossary.md) - An attempt to disambiguiate terminology.
* [eschewed features](eschewedFeatures.md) - Why certain features are (currently)
not supported in Kustomize.
* [contributing guidelines](../CONTRIBUTING.md) - Please read before sending a PR.
* [code of conduct](../code-of-conduct.md)

View File

@@ -1,5 +1,9 @@
# Eschewed Features
For a bigger picture about why kustomize
does some things and not others, see the
glossary entry for [DAM].
## Removal directives
`kustomize` supports configurations that can be reasoned about as
@@ -74,6 +78,7 @@ In this way the resources, patches and bases used at _build time_
remain explicitly declared in version control.
[DAM]: glossary.md#declarative-application-management
[base]: glossary.md#base
[kustomization]: glossary.md#kustomization
[OTS workflow]: workflows.md#off-the-shelf-configuration

View File

@@ -1,7 +1,10 @@
# Glossary
[CRD spec]: https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/
[CRD]: #custom-resource-definition
[DAM]: #declarative-application-management
[Declarative Application Management]: https://github.com/kubernetes/community/blob/master/contributors/design-proposals/architecture/declarative-application-management.md
[JSON]: https://www.json.org/
[JSONPatch]: https://tools.ietf.org/html/rfc6902
[Resource]: #resource
[YAML]: http://www.yaml.org/start.html
[application]: #application
@@ -15,16 +18,20 @@
[kubernetes]: #kubernetes
[kustomize]: #kustomize
[kustomization]: #kustomization
[off-the-shelf]: #off-the-shelf
[off-the-shelf]: #off-the-shelf-configuration
[overlay]: #overlay
[overlays]: #overlay
[patch]: #patch
[patches]: #patch
[patchJson6902]: #patchjson6902
[patchExampleJson6902]: https://github.com/kubernetes-sigs/kustomize/blob/master/examples/jsonpatch.md
[patchesJson6902]: #patchjson6902
[proposal]: https://github.com/kubernetes/community/pull/1629
[rebase]: https://git-scm.com/docs/git-rebase
[resource]: #resource
[resources]: #resource
[rpm]: https://en.wikipedia.org/wiki/Rpm_(software)
[strategic-merge]: https://github.com/kubernetes/community/blob/master/contributors/devel/strategic-merge-patch.md
[target]: #target
[variant]: #variant
[variants]: #variant
@@ -92,22 +99,37 @@ simpler than the workflow associated with an
periodically capturing someone else's upgrades to the
[off-the-shelf] config.
## custom resource definition
One can extend the k8s API by making a
Custom Resource Definition ([CRD spec]).
This defines a custom [resource] (CD), an entirely
new resource that can be used alongside _native_
resources like ConfigMaps, Deployments, etc.
Kustomize can customize a CD, but to do so
kustomize must also be given the corresponding CRD
so that it can interpret the structure correctly.
## declarative application management
_Declarative Application Management_ (DAM) is a [set of
ideas](https://goo.gl/T66ZcD) aiming to ease management
of k8s clusters.
Kustomize aspires to support [Declarative Application Management],
a set of best practices around managing k8s clusters.
* Works with any configuration, be it bespoke,
In brief, kustomize should
* Work with any configuration, be it bespoke,
off-the-shelf, stateless, stateful, etc.
* Supports common customizations, and creation of
[variants] (dev vs. staging vs. production).
* Exposes and teaches native k8s APIs, rather than
hiding them.
* No friction integration with version control to
* Support common customizations, and creation of
[variants] (e.g. _development_ vs.
_staging_ vs. _production_).
* Expose and teach native k8s APIs, rather than
hide them.
* Add no friction to version control integration to
support reviews and audit trails.
* Composable with other tools in a unix sense.
* Eschews crossing the line into templating, domain
* Compose with other tools in a unix sense.
* Eschew crossing the line into templating, domain
specific languages, etc., frustrating the other
goals.
@@ -127,18 +149,23 @@ Here's an [example](kustomization.yaml).
A kustomization contains fields falling into these categories:
* Immediate customization declarations, e.g.
_namePrefix_, _commonLabels_, etc.
* Resource _generators_ for configmaps and secrets.
* References to _external files_ in these categories:
* _Customization operators_ for modifying operands, e.g.
_namePrefix_, _commonLabels_, _patches_, etc.
* _Customization operands_:
* [resources] - completely specified k8s API objects,
e.g. `deployment.yaml`, `configmap.yaml`, etc.
* [patches] - _partial_ resources that modify full
resources defined in a [base]
(only meaningful in an [overlay]).
* [bases] - path to a directory containing
a [kustomization] (only meaningful in an [overlay]).
* (_TBD_) Standard k8s API kind-version fields.
* [bases] - paths or github URLs specifying directories
containing a [kustomization]. These bases may
be subjected to more customization, or merely
included in the output.
* [CRD]s - custom resource definition files, to allow use
of _custom_ resources in the _resources_ list.
Not an actual operand - but allows the use of new operands.
* Generators, for creating more resources
(configmaps and secrets) which can then be
customized.
## kubernetes
@@ -242,36 +269,68 @@ management tool in the tradition of, say, [apt] or
## patch
A _patch_ is a partially defined k8s resource with a
name that must match a resource already known per
traversal rules built into [kustomize].
General instructions to modify a resource.
_Patch_ is a field in the kustomization, distinct from
resources, because a patch file looks like a resource
file, but has different semantics. A patch depends on
(modifies) a resource, whereas a resource has no
dependencies. Since any resource file can be used as a
patch, one cannot reliably distinguish a resource from
a patch just by looking at the file's [YAML].
There are two alternative techniques with similar
power but different notation - the
[strategic merge patch](#patchstrategicmerge)
and the [JSON patch](#patchjson6902).
## patchStrategicMerge
A _patchStrategicMerge_ is [strategic-merge]-style patch (SMP).
An SMP looks like an incomplete YAML specification of
a k8s resource. The SMP includes `TypeMeta`
fields to establish the group/version/kind/name of the
[resource] to patch, then just enough remaining fields
to step into a nested structure to specify a new field
value, e.g. an image tag.
By default, an SMP _replaces_ values. This
usually desired when the target value is a simple
string, but may not be desired when the target
value is a list.
To change this
default behavior, add a _directive_. Recognized
directives include _replace_ (the default), _merge_
(avoid replacing a list), _delete_ and a few more
(see [these notes][strategic-merge]).
Fun fact - any resource file can be used as
an SMP, overwriting matching fields in another
resource with the same group/version/kind/name,
but leaving all other fields as they were.
TODO(monopole): add ptr to example.
## patchJson6902
A _patchJson6902_ refers to a kubernetes [resource] and
a [JSONPatch] specifying how to change the resource.
A _patchJson6902_ can do almost everything a
_patchStrategicMerge_ can do, but with a briefer
syntax. See this [example][patchExampleJson6902].
## resource
A _resource_, in the context of kustomize, is a path to
a [YAML] or [JSON] file that completely defines a
functional k8s API object, like a deployment or a
configmap.
A _resource_ in the context of a REST-ful API is the
target object of an HTTP operation like _GET_, _PUT_ or
_POST_. k8s offers a REST-ful API surface to interact
with clients.
A _resource_, in the context of kustomization file,
is a path to a [YAML] or [JSON] file describing
a k8s API object, like a Deployment or a
ConfigmMap.
More generally, a resource can be any correct YAML file
that [defines an object](https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/#required-fields)
with a _kind_ and a _metadata/name_ field.
A _resource_ in the content of a REST-ful API is the
target of an HTTP operation like _GET_, _PUT_ or
_POST_. k8s offers a RESTful API surface to interact
with clients.
## sub-target / sub-application / sub-package
A _sub-whatever_ is not a thing. There are only
@@ -285,7 +344,7 @@ The _target_ is the argument to `kustomize build`, e.g.:
> kustomize build $target
> ```
`$target` must be a path to a directory that
`$target` must be a path or a url to a directory that
immediately contains a [kustomization].
The target contains, or refers to, all the information

View File

@@ -63,13 +63,18 @@ resources:
# Each entry in this list results in the creation of
# one ConfigMap resource (it's a generator of n maps).
# The example below creates a ConfigMap with the
# names and contents of the given files.
# The example below creates two ConfigMaps. One with the
# names and contents of the given files, the other with
# key/value as data.
configMapGenerator:
- name: myJavaServerProps
files:
- application.properties
- more.properties
- name: myJavaServerEnvVars
literals:
- JAVA_HOME=/opt/java/jdk
- JAVA_TOOL_OPTIONS=-agentlib:hprof
# Each entry in this list results in the creation of
# one Secret resource (it's a generator of n secrets).
@@ -83,15 +88,29 @@ secretGenerator:
tls.key: "cat secret/tls.key"
type: "kubernetes.io/tls"
- name: downloaded_secret
# timeoutSeconds specifies the number of seconds to
# wait for the commands below. It defaults to 5 seconds.
timeoutSeconds: 30
commands:
username: "curl -s https://path/to/secrets/username.yaml"
password: "curl -s https://path/to/secrets/password.yaml"
type: Opaque
- name: env_file_secret
# envCommand is similar to command but outputs lines of key=val pairs
# i.e. a Docker .env file or a .ini file.
# you can only specify one envCommand per secret.
envCommand: printf \"DB_USERNAME=admin\nDB_PASSWORD=somepw\"
type: Opaque
# Each entry in this list should resolve to a directory
# containing a kustomization file, else the
# customization fails.
#
# The entry could be a relative path pointing to a local directory
# or a url pointing to a directory in a remote repo.
# The url should follow hashicorp/go-getter URL format
# https://github.com/hashicorp/go-getter#url-format
#
# The presence of this field means this file (the file
# you a reading) is an _overlay_ that further
# customizes information coming from these _bases_.
@@ -102,6 +121,9 @@ secretGenerator:
# etc. that differ from the common base).
bases:
- ../../base
- github.com/kubernetes-sigs/kustomize//examples/multibases?ref=v1.0.6
- github.com/Liujingfang1/mysql
- github.com/Liujingfang1/kustomize//examples/helloWorld?ref=test-branch
# Each entry in this list should resolve to
# a partial or complete resource definition file.
@@ -121,6 +143,41 @@ patches:
- deployment_increase_replicas.yaml
- deployment_increase_memory.yaml
# Each entry in this list should resolve to
# a kubernetes object and a JSON patch that will be applied
# to the object.
# The JSON patch is documented at https://tools.ietf.org/html/rfc6902
#
# target field points to a kubernetes object within the same kustomization
# by the object's group, version, kind, name and namespace.
# path field is a relative file path of a JSON patch file.
# The content in this patch file can be either in JSON format as
#
# [
# {"op": "add", "path": "/some/new/path", "value": "value"},
# {"op": "replace", "path": "/some/existing/path", "value": "new value"}
# ]
#
# or in YAML format as
#
# - op: add
# path: /some/new/path
# value: value
# - op:replace
# path: /some/existing/path
# value: new value
#
patchesJson6902:
- target:
version: v1
kind: Deployment
name: my-deployment
path: add_init_container.yaml
- target:
version: v1
kind: Service
name: my-service
path: add_service_annotation.yaml
# Each entry in this list should be a relative path to
# a file for custom resource definition(CRD).
@@ -195,8 +252,12 @@ vars:
# image: nginx:1.7.9
#```
# one can change the tag of myimage to v1 and the tag of nginx to 1.8.0 with the following:
#
# It also supports digests. If digest is present newTag is ignored.
imageTags:
- name: mycontainerregistry/myimage
newTag: v1
- name: nginx
newTag: 1.8.0
- name: alpine
digest: sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3

View File

@@ -1,11 +1,11 @@
[OTS]: glossary.md#off-the-shelf
[OTS]: glossary.md#off-the-shelf-configuration
[apply]: glossary.md#apply
[applying]: glossary.md#apply
[base]: glossary.md#base
[fork]: https://guides.github.com/activities/forking/
[variants]: glossary.md#variant
[kustomization]: glossary.md#kustomization
[off-the-shelf]: glossary.md#off-the-shelf
[off-the-shelf]: glossary.md#off-the-shelf-configuration
[overlays]: glossary.md#overlay
[patch]: glossary.md#patch
[patches]: glossary.md#patch
@@ -21,14 +21,17 @@ use and maintain a configuration.
## Bespoke configuration
In this workflow, all configuration files are owned by
the user. No content is incorporated from version
In this workflow, all configuration (resource YAML) files
are owned by the user. No content is incorporated from version
control repositories owned by others.
![bespoke config workflow image][workflowBespoke]
#### 1) create a directory in version control
Speculate some overall cluster application called _ldap_;
we want to keep its configuration in its own repo.
> ```
> git init ~/ldap
> ```

View File

@@ -7,7 +7,7 @@ tests, and should work with HEAD
<!-- @installkustomize @test -->
```
go get github.com/kubernetes-sigs/kustomize
go get sigs.k8s.io/kustomize
```
* [hello world](helloWorld/README.md) - Deploy multiple
@@ -37,4 +37,11 @@ go get github.com/kubernetes-sigs/kustomize
* [image tags](imageTags.md) - Updating image tags without applying a patch.
* [multibases](multibases/README.md) - Composing three variants (dev, staging, production) with a common base.
* [multibases](multibases/README.md) - Composing three variants (dev, staging, production) with a common base.
* [remote target](remoteBuild.md) - Building a kustomization from a github URL
* [json patch](jsonpatch.md) - Apply a json patch in a kustomization
* [transformer configs](transformerconfigs/README.md) - Customize transformer configurations

View File

@@ -73,7 +73,7 @@ commonLabels:
who: alice
bases:
- ../../base
patches:
patchesStrategicMerge:
- temperature.yaml
EOF
@@ -96,7 +96,7 @@ commonLabels:
who: bob
bases:
- ../../base
patches:
patchesStrategicMerge:
- topping.yaml
EOF

View File

@@ -1,6 +1,6 @@
[patch]: ../../docs/glossary.md#patch
[resource]: ../../docs/glossary.md#resource
[variant]: ../../docs/glossary.md#variant
[patch]: ../docs/glossary.md#patch
[resource]: ../docs/glossary.md#resource
[variant]: ../docs/glossary.md#variant
## ConfigMap generation and rolling updates
@@ -67,7 +67,7 @@ commonAnnotations:
note: Hello, I am staging!
bases:
- ../../base
patches:
patchesStrategicMerge:
- map.yaml
EOF
@@ -109,8 +109,8 @@ configuration is to
This latter change initiates rolling update to the pods
in the deployment. The older configMap, when no longer
referenced by any other resource, is eventually garbage
collected.
referenced by any other resource, is eventually [garbage
collected](https://github.com/kubernetes-sigs/kustomize/issues/242).
### How this works with kustomize
@@ -164,7 +164,7 @@ the server will use:
<!-- @changeMap @test -->
```
sed -i 's/pineapple/kiwi/' $OVERLAYS/staging/map.yaml
sed -i.bak 's/pineapple/kiwi/' $OVERLAYS/staging/map.yaml
```
See the new greeting:

View File

@@ -108,16 +108,10 @@ label_ applied to all resources:
<!-- @addLabel @test -->
```
sed -i 's/app: hello/app: my-hello/' \
sed -i.bak 's/app: hello/app: my-hello/' \
$BASE/kustomization.yaml
```
On a Mac, use:
```
sed -i '' $pattern $file
```
to get in-place editing.
See the effect:
<!-- @checkLabel @test -->
```
@@ -156,7 +150,7 @@ commonAnnotations:
note: Hello, I am staging!
bases:
- ../../base
patches:
patchesStrategicMerge:
- map.yaml
EOF
```
@@ -197,7 +191,7 @@ commonAnnotations:
note: Hello, I am production!
bases:
- ../../base
patches:
patchesStrategicMerge:
- deployment.yaml
EOF
```

View File

@@ -48,7 +48,7 @@ function setUpEnv {
[[ $? -eq 0 ]] || "Failed to cd to $repo"
echo "pwd is " `pwd`
local expectedRepo=kubernetes-sigs/kustomize
local expectedRepo=sigs.k8s.io/kustomize
if [[ `pwd` != */$expectedRepo ]]; then
exitWith "Script must be run from $expectedRepo"
fi

118
examples/jsonpatch.md Normal file
View File

@@ -0,0 +1,118 @@
# Demo: applying a json patch
A kustomization file supports customizing resources via [JSON patches](https://tools.ietf.org/html/rfc6902).
The example below modifies an `Ingress` object with such a patch.
Make a `kustomization` containing an ingress resource.
<!-- @createIngress @test -->
```
DEMO_HOME=$(mktemp -d)
cat <<EOF >$DEMO_HOME/kustomization.yaml
resources:
- ingress.yaml
EOF
cat <<EOF >$DEMO_HOME/ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-ingress
spec:
rules:
- host: foo.bar.com
http:
paths:
- backend:
serviceName: my-api
servicePort: 80
EOF
```
Declare a JSON patch file to update two fields of the Ingress object:
- change host from `foo.bar.com` to `foo.bar.io`
- change servicePort from `80` to `8080`
<!-- @addJsonPatch @test -->
```
cat <<EOF >$DEMO_HOME/ingress_patch.json
[
{"op": "replace", "path": "/spec/rules/0/host", "value": "foo.bar.io"},
{"op": "replace", "path": "/spec/rules/0/http/paths/0/backend/servicePort", "value": 8080}
]
EOF
```
You can also write the patch in YAML format. This example also shows the "add" operation:
<!-- @addYamlPatch @test -->
```
cat <<EOF >$DEMO_HOME/ingress_patch.yaml
- op: replace
path: /spec/rules/0/host
value: foo.bar.io
- op: add
path: /spec/rules/0/http/paths/-
value:
path: '/test'
backend:
serviceName: my-test
servicePort: 8081
EOF
```
Apply the patch by adding _patchesJson6902_ field in kustomization.yaml
<!-- @applyJsonPatch @test -->
```
cat <<EOF >>$DEMO_HOME/kustomization.yaml
patchesJson6902:
- target:
group: extensions
version: v1beta1
kind: Ingress
name: my-ingress
path: ingress_patch.json
EOF
```
Running `kustomize build $DEMO_HOME`, in the output confirm that host has been updated correctly.
<!-- @confirmHost @test -->
```
test 1 == \
$(kustomize build $DEMO_HOME | grep "host: foo.bar.io" | wc -l); \
echo $?
```
Running `kustomize build $DEMO_HOME`, in the output confirm that the servicePort has been updated correctly.
<!-- @confirmServicePort @test -->
```
test 1 == \
$(kustomize build $DEMO_HOME | grep "servicePort: 8080" | wc -l); \
echo $?
```
If the patch is YAML-formatted, it will be parsed correctly:
<!-- @applyYamlPatch @test -->
```
cat <<EOF >>$DEMO_HOME/kustomization.yaml
patchesJson6902:
- target:
group: extensions
version: v1beta1
kind: Ingress
name: my-ingress
path: ingress_patch.yaml
EOF
```
<!-- @confirmYamlPatch @test -->
```
test 1 == \
$(kustomize build $DEMO_HOME | grep "path: /test" | wc -l); \
echo $?
```

View File

@@ -1,5 +1,5 @@
bases:
- ../../base
patches:
patchesStrategicMerge:
- deployment.yaml
namePrefix: production-

View File

@@ -1,6 +1,6 @@
bases:
- ../../base
patches:
patchesStrategicMerge:
- deployment.yaml
nameprefix: staging-
configMapGenerator:

View File

@@ -107,7 +107,7 @@ Now the workspace has following directories
> └── kustomization.yaml
> ```
Confirm that the `kustomize build` output contains three pod objects from dev, staing and production variants.
Confirm that the `kustomize build` output contains three pod objects from dev, staging and production variants.
<!-- @confirmVariants @test -->
```

View File

@@ -136,7 +136,7 @@ a label, but one can always edit `kustomization.yaml` directly:
<!-- @customizeLabels @test -->
```
sed -i 's/app: helloworld/app: prod/' \
sed -i.bak 's/app: helloworld/app: prod/' \
$DEMO_HOME/kustomization.yaml
```
@@ -150,7 +150,7 @@ Off the shelf MySQL uses `emptyDir` type volume, which
gets wiped away if the MySQL Pod is recreated, and that
is certainly not desirable for production
environment. So we want to use Persistent Disk in
production. kustomize lets you apply `patches` to the
production. kustomize lets you apply `patchesStrategicMerge` to the
resources.
<!-- @createPatchFile @test -->
@@ -176,11 +176,13 @@ Add the patch file to `kustomization.yaml`:
<!-- @specifyPatch @test -->
```
cat <<'EOF' >> $DEMO_HOME/kustomization.yaml
patches:
patchesStrategicMerge:
- persistent-disk.yaml
EOF
```
A `mysql-persistent-storage` persistent disk needs to exist for it to run successfully.
Lets break this down:
- In the first step, we created a YAML file named
@@ -188,7 +190,7 @@ Lets break this down:
in deployment.yaml
- Then we added `persistent-disk.yaml` to list of
`patches` in `kustomization.yaml`. `kustomize build`
`patchesStrategicMerge` in `kustomization.yaml`. `kustomize build`
will apply this patch to the deployment resource with
the name `mysql` as defined in the patch.

View File

@@ -2,7 +2,7 @@ apiVersion: v1
kind: Secret
metadata:
creationTimestamp: null
name: mysql-pass-d2gtcm2t2k
name: mysql-pass
type: Opaque
data:
# Default password is "admin".

69
examples/remoteBuild.md Normal file
View File

@@ -0,0 +1,69 @@
# remote targets
`kustomize build` can be run against a url. The effect is the same as cloing the repo, checking out the specified ref,
then running `kustomize build` against the desired directory in the local copy.
Take `github.com/kubernetes-sigs/kustomize//examples/multibases?ref=v1.0.6` as an example.
According to [multibases](multibases/README.md) demo, this kustomization contains three Pod objects with names as
`cluster-a-dev-myapp-pod`, `cluster-a-stag-myapp-pod`, `cluster-a-prod-myapp-pod`.
Running `kustomize build` against the url gives the same output.
<!-- @remoteBuild @test -->
```
target=github.com/kubernetes-sigs/kustomize//examples/multibases?ref=v1.0.6
test 3 == \
$(kustomize build $target | grep cluster-a-.*-myapp-pod | wc -l); \
echo $?
```
Overlays can be remote as well:
<!-- @remoteOverlayBuild @test -->
```
target=github.com/kubernetes-sigs/kustomize//examples/multibases/dev/?ref=v1.0.6
test 1 == \
$(kustomize build $target | grep cluster-a-dev-myapp-pod | wc -l); \
echo $?
```
A base can also be specified as a URL:
<!-- @createOverlay @test -->
```
DEMO_HOME=$(mktemp -d)
cat <<EOF >$DEMO_HOME/kustomization.yaml
bases:
- github.com/kubernetes-sigs/kustomize//examples/multibases?ref=v1.0.6
namePrefix: remote-
EOF
```
Running `kustomize build $DEMO_HOME` and confirm the output contains three Pods and all have `remote-` prefix.
<!-- @remoteBases @test -->
```
test 3 == \
$(kustomize build $DEMO_HOME | grep remote-.*-myapp-pod | wc -l); \
echo $?
```
## URL format
The url should follow
[hashicorp/go-getter URL format](https://github.com/hashicorp/go-getter#url-format).
Here are some example urls pointing to Github repos following this convention.
- a repo with a root level kustomization.yaml
`github.com/Liujingfang1/mysql`
- a repo with a root level kustomization.yaml on branch test
`github.com/Liujingfang1/mysql?ref=test`
- a subdirectory in a repo on version v1.0.6
`github.com/kubernetes-sigs/kustomize//examples/multibases?ref=v1.0.6`
- a subdirectory in a repo on branch repoUrl2
`github.com/Liujingfang1/kustomize//examples/helloWorld?ref=repoUrl2`
- a subdirectory in a repo on commit `7050a45134e9848fca214ad7e7007e96e5042c03`
`github.com/Liujingfang1/kustomize//examples/helloWorld?ref=7050a45134e9848fca214ad7e7007e96e5042c03`

View File

@@ -291,7 +291,7 @@ kustomize edit add patch healthcheck_patch.yaml
`kustomization.yaml` should have patches field:
> ```
> patches:
> patchesStrategicMerge:
> - patch.yaml
> - memorylimit_patch.yaml
> - healthcheck_patch.yaml

View File

@@ -1,6 +1,6 @@
bases:
- ../../base
patches:
patchesStrategicMerge:
- patch.yaml
- healthcheck_patch.yaml
- memorylimit_patch.yaml

View File

@@ -0,0 +1,96 @@
# Transformer Configurations
Kustomize computes the resources by applying a series of transformers:
- namespace transformer
- prefix transformer
- label transformer
- annotation transformer
- name reference transformer
- variable reference transformer
Each transformer takes a list of resources and modifies certain fields. The modification is based on the transformer's rule.
The fields to update is the transformer's configuration, which is a list of filedspec that can be represented in YAML format.
## fieldSpec
FieldSpec is a type to represent a path to a field in one kind of resources. It has following format
```
group: some-group
version: some-version
kind: some-kind
path: path/to/the/field
create: false
```
If `create` is set to true, it indicates the transformer to create the path if it is not found in the resources. This is most useful for label and annotation transformers, where the path for labels or annotations may not be set before the transformation.
## prefix transformer
Name prefix transformer adds prefix to the `metadata/name` field for all resources with following configuration:
```
namePrefix:
- path: metadata/name
```
## label transformer
Label transformer adds labels to `metadata/labels` field for all resources. It also adds labels to `spec/selector` field in all Service and to `spec/selector/matchLabels` field in all Deployment.
```
commonLabels:
- path: metadata/labels
create: true
- path: spec/selector
create: true
version: v1
kind: Service
- path: spec/selector/matchLabels
create: true
kind: Deployment
(etc.)
```
## name reference transformer
Name reference transformer's configuration is different from all other transformers. It contains a list of namebackreferences, which represented all the possible fields that a type could be used as a reference in other types of resources. A namebackreference contains a type such as ConfigMap as well as a list of FieldSpecs where ConfigMap is referenced. Here is an example.
```
kind: ConfigMap
version: v1
FieldSpecs:
- kind: Pod
version: v1
path: spec/volumes/configMap/name
- kind: Deployment
path: spec/template/spec/volumes/configMap/name
- kind: Job
path: spec/template/spec/volumes/configMap/name
(etc.)
```
Name reference transformer configuration contains a list of such namebackreferences for ConfigMap, Secret, Service, Role, ServiceAccount and so on.
```
nameReference:
- kind: ConfigMap
version: v1
fieldSpecs:
- path: spec/volumes/configMap/name
version: v1
kind: Pod
- path: spec/containers/env/valueFrom/configMapKeyRef/name
version: v1
kind: Pod
(etc.)
- kind: Secret
version: v1
fieldSpecs:
- path: spec/volumes/secret/secretName
version: v1
kind: Pod
- path: spec/containers/env/valueFrom/secretKeyRef/name
version: v1
kind: Pod
(etc.)
```
## cusotmizing transformer configurations
Kustomize has a default set of configurations. They can be saved to local directory through `kustomize config save -d`. kusotmize allows modifying those configuration files and using them in `kustomize build` through `-t`. This tutorial shows how to customize those configurations to
- [support a crd type](crd/README.md)
- disabling adding commonLabels to fields in some kind of resources
- add extra fields for variable substitution
- add extra fields for name reference

View File

@@ -0,0 +1,171 @@
## Transformer Configurations - CRD
This tutorial shows how to add transformer configurations to support a CRD type.
### Get Default Config
Get the default transformer configurations by
<!-- @saveConfig @test -->
```
kustomize config save -d ~/.kustomize/config
```
The default configurations are save in directory `~/.kustomize/config` as several files
> ```
> commonannotations.yaml commonlabels.yaml nameprefix.yaml namereference.yaml namespace.yaml varreference.yaml
> ```
### Add Config for a CRD
All transformers will be involved for a CRD type. The default configurations already include some common fieldSpec for all types:
- nameprefix is added to `.metadata.name`
- namespace is added to `.metadata.namespace`
- labels is added to `.metadata.labels`
- annotations is added to `.metadata.annotations`
Thus those fieldSpec don't need to be added to support a CRD type.
Consider a CRD type `MyKind` with fields
- `.spec.secretRef.name` reference a Secret
- `.spec.beeRef.name` reference an instance of CRD `Bee`
- `.spec.containers.command` as the list of container commands
- `.spec.selectors` as the label selectors
Add following file to configure the transformers for the above fields
<!-- @addConfig @test -->
```
cat > ~/.kustomize/config/mykind.yaml << EOF
commonLabels:
- path: spec/selectors
create: true
kind: MyKind
nameReference:
- kind: Bee
fieldSpecs:
- path: spec/beeRef/name
kind: MyKind
- kind: Secret
fieldSpecs:
- path: spec/secretRef/name
kind: MyKind
varReference:
- path: spec/containers/command
kind: MyKind
- path: spec/beeRef/action
kind: MyKind
EOF
```
### Apply config
Create a kustomization with a `MyKind` instance.
<!-- @createKustomization @test -->
```
DEMO_HOME=$(mktemp -d)
cat > $DEMO_HOME/kustomization.yaml << EOF
resources:
- resources.yaml
namePrefix: test-
commonLabels:
foo: bar
vars:
- name: BEE_ACTION
objref:
kind: Bee
name: bee
apiVersion: v1beta1
fieldref:
fieldpath: spec.action
EOF
cat > $DEMO_HOME/resources.yaml << EOF
apiVersion: v1
kind: Secret
metadata:
name: crdsecret
data:
PATH: YmJiYmJiYmIK
---
apiVersion: v1beta1
kind: Bee
metadata:
name: bee
spec:
action: fly
---
apiVersion: jingfang.example.com/v1beta1
kind: MyKind
metadata:
name: mykind
spec:
secretRef:
name: crdsecret
beeRef:
name: bee
action: \$(BEE_ACTION)
containers:
- command:
- "echo"
- "\$(BEE_ACTION)"
image: myapp
EOF
```
Run `kustomize build` with customized transformer configurations and verify that
the namereference is correctly resolved.
<!-- @build @test -->
```
test 2 == \
$(kustomize build $DEMO_HOME -t ~/.kustomize/config | grep -A 2 ".*Ref" | grep "test-" | wc -l); \
echo $?
```
Run `kustomize build` with customized transformer configurations and verify that
the vars correctly resolved.
<!-- @verify @test -->
```
test 0 == \
$(kustomize build $DEMO_HOME -t ~/.kustomize/config | grep "BEE_ACTION" | wc -l); \
echo $?
```
To understand this better, compare the output using default transformer configurations.
<!-- @compareOutput -->
```
diff \
<(kustomize build $DEMO_HOME) \
<(kustomize build $DEMO_HOME -t ~/.kustomize/config ) |\
more
```
The difference output should look something like
> ```
> 20,21c20,21
> < action: $(BEE_ACTION)
> < name: bee
> ---
> > action: fly
> > name: test-bee
> 25c25
> < - $(BEE_ACTION)
> ---
> > - fly
> 28c28,30
> < name: crdsecret
> ---
> > name: test-crdsecret
> > selectors:
> > foo: bar
> ```

View File

@@ -0,0 +1,16 @@
resources:
- resources.yaml
namePrefix: test-
commonLabels:
foo: bar
vars:
- name: BEE_ACTION
objref:
kind: Bee
name: bee
apiVersion: v1beta1
fieldref:
fieldpath: spec.action

View File

@@ -0,0 +1,29 @@
apiVersion: v1
kind: Secret
metadata:
name: crdsecret
data:
PATH: YmJiYmJiYmIK
---
apiVersion: v1beta1
kind: Bee
metadata:
name: bee
spec:
action: fly
---
apiVersion: jingfang.example.com/v1beta1
kind: MyKind
metadata:
name: mykind
spec:
secretRef:
name: crdsecret
beeRef:
name: bee
action: $(BEE_ACTION)
containers:
- command:
- "echo"
- "$(BEE_ACTION)"
image: myapp

View File

@@ -53,6 +53,8 @@ bases:
- wordpress
- mysql
namePrefix: demo-
patchesStrategicMerge:
- patch.yaml
EOF
```
@@ -65,7 +67,7 @@ In the new kustomization, apply a patch for wordpress deployment. The patch does
```
CONTENT="https://raw.githubusercontent.com\
/kubernetes-sigs/kustomize\
/master/examples/patch.yaml"
/master/examples/wordpress"
curl -s -o "$DEMO_HOME/#1.yaml" \
"$CONTENT/{patch}.yaml"

View File

@@ -1,7 +1,7 @@
bases:
- wordpress
- mysql
patches:
patchesStrategicMerge:
- patch.yaml
namePrefix: demo-

View File

@@ -18,61 +18,31 @@ limitations under the License.
package configmapandsecret
import (
"encoding/json"
"fmt"
"path"
"strings"
"github.com/kubernetes-sigs/kustomize/pkg/fs"
"github.com/kubernetes-sigs/kustomize/pkg/hash"
"github.com/kubernetes-sigs/kustomize/pkg/loader"
"github.com/kubernetes-sigs/kustomize/pkg/types"
"github.com/pkg/errors"
"k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation"
"sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/ifc"
"sigs.k8s.io/kustomize/pkg/types"
)
// ConfigMapFactory makes ConfigMaps.
type ConfigMapFactory struct {
fSys fs.FileSystem
ldr loader.Loader
ldr ifc.Loader
}
// NewConfigMapFactory returns a new ConfigMapFactory.
func NewConfigMapFactory(
fSys fs.FileSystem, l loader.Loader) *ConfigMapFactory {
fSys fs.FileSystem, l ifc.Loader) *ConfigMapFactory {
return &ConfigMapFactory{fSys: fSys, ldr: l}
}
// MakeUnstructAndGenerateName returns an configmap and the name appended with a hash.
func (f *ConfigMapFactory) MakeUnstructAndGenerateName(
args *types.ConfigMapArgs) (*unstructured.Unstructured, string, error) {
cm, err := f.MakeConfigMap(args)
if err != nil {
return nil, "", err
}
h, err := hash.ConfigMapHash(cm)
if err != nil {
return nil, "", err
}
nameWithHash := fmt.Sprintf("%s-%s", cm.GetName(), h)
unstructuredCM, err := objectToUnstructured(cm)
return unstructuredCM, nameWithHash, err
}
func objectToUnstructured(in runtime.Object) (*unstructured.Unstructured, error) {
marshaled, err := json.Marshal(in)
if err != nil {
return nil, err
}
var out unstructured.Unstructured
err = out.UnmarshalJSON(marshaled)
return &out, err
}
func (f *ConfigMapFactory) makeFreshConfigMap(
args *types.ConfigMapArgs) *corev1.ConfigMap {
cm := &corev1.ConfigMap{}
@@ -85,7 +55,7 @@ func (f *ConfigMapFactory) makeFreshConfigMap(
// MakeConfigMap returns a new ConfigMap, or nil and an error.
func (f *ConfigMapFactory) MakeConfigMap(
args *types.ConfigMapArgs) (*corev1.ConfigMap, error) {
args *types.ConfigMapArgs, options *types.GeneratorOptions) (*corev1.ConfigMap, error) {
var all []kvPair
var err error
cm := f.makeFreshConfigMap(args)
@@ -118,6 +88,10 @@ func (f *ConfigMapFactory) MakeConfigMap(
return nil, err
}
}
if options != nil {
cm.SetLabels(options.Labels)
cm.SetAnnotations(options.Annotations)
}
return cm, nil
}
@@ -133,7 +107,7 @@ func keyValuesFromLiteralSources(sources []string) ([]kvPair, error) {
return kvs, nil
}
func keyValuesFromFileSources(ldr loader.Loader, sources []string) ([]kvPair, error) {
func keyValuesFromFileSources(ldr ifc.Loader, sources []string) ([]kvPair, error) {
var kvs []kvPair
for _, s := range sources {
k, fPath, err := parseFileSource(s)
@@ -149,7 +123,7 @@ func keyValuesFromFileSources(ldr loader.Loader, sources []string) ([]kvPair, er
return kvs, nil
}
func keyValuesFromEnvFile(l loader.Loader, path string) ([]kvPair, error) {
func keyValuesFromEnvFile(l ifc.Loader, path string) ([]kvPair, error) {
if path == "" {
return nil, nil
}
@@ -212,6 +186,5 @@ func parseLiteralSource(source string) (keyName, value string, err error) {
if len(items) != 2 {
return "", "", fmt.Errorf("invalid literal source %v, expected key=value", source)
}
return items[0], items[1], nil
return items[0], strings.Trim(items[1], "\"'"), nil
}

View File

@@ -20,12 +20,11 @@ import (
"reflect"
"testing"
"github.com/kubernetes-sigs/kustomize/pkg/fs"
"github.com/kubernetes-sigs/kustomize/pkg/loader"
"github.com/kubernetes-sigs/kustomize/pkg/types"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/loader"
"sigs.k8s.io/kustomize/pkg/types"
)
func makeEnvConfigMap(name string) *corev1.ConfigMap {
@@ -44,23 +43,6 @@ func makeEnvConfigMap(name string) *corev1.ConfigMap {
}
}
func makeUnstructuredEnvConfigMap(name string) *unstructured.Unstructured {
return &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": name,
"creationTimestamp": nil,
},
"data": map[string]interface{}{
"DB_USERNAME": "admin",
"DB_PASSWORD": "somepw",
},
},
}
}
func makeFileConfigMap(name string) *corev1.ConfigMap {
return &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
@@ -79,7 +61,7 @@ BAR=baz
}
func makeLiteralConfigMap(name string) *corev1.ConfigMap {
return &corev1.ConfigMap{
cm := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "ConfigMap",
@@ -90,14 +72,19 @@ func makeLiteralConfigMap(name string) *corev1.ConfigMap {
Data: map[string]string{
"a": "x",
"b": "y",
"c": "Hello World",
"d": "true",
},
}
cm.SetLabels(map[string]string{"foo": "bar"})
return cm
}
func TestConstructConfigMap(t *testing.T) {
type testCase struct {
description string
input types.ConfigMapArgs
options *types.GeneratorOptions
expected *corev1.ConfigMap
}
@@ -107,9 +94,10 @@ func TestConstructConfigMap(t *testing.T) {
input: types.ConfigMapArgs{
Name: "envConfigMap",
DataSources: types.DataSources{
EnvSource: "../examplelayout/simple/instances/exampleinstance/configmap/app.env",
EnvSource: "configmap/app.env",
},
},
options: nil,
expected: makeEnvConfigMap("envConfigMap"),
},
{
@@ -117,9 +105,10 @@ func TestConstructConfigMap(t *testing.T) {
input: types.ConfigMapArgs{
Name: "fileConfigMap",
DataSources: types.DataSources{
FileSources: []string{"../examplelayout/simple/instances/exampleinstance/configmap/app-init.ini"},
FileSources: []string{"configmap/app-init.ini"},
},
},
options: nil,
expected: makeFileConfigMap("fileConfigMap"),
},
{
@@ -127,18 +116,24 @@ func TestConstructConfigMap(t *testing.T) {
input: types.ConfigMapArgs{
Name: "literalConfigMap",
DataSources: types.DataSources{
LiteralSources: []string{"a=x", "b=y"},
LiteralSources: []string{"a=x", "b=y", "c=\"Hello World\"", "d='true'"},
},
},
options: &types.GeneratorOptions{
Labels: map[string]string{
"foo": "bar",
},
},
expected: makeLiteralConfigMap("literalConfigMap"),
},
}
// TODO: all tests should use a FakeFs
fSys := fs.MakeRealFS()
fSys := fs.MakeFakeFS()
fSys.WriteFile("configmap/app.env", []byte("DB_USERNAME=admin\nDB_PASSWORD=somepw\n"))
fSys.WriteFile("configmap/app-init.ini", []byte("FOO=bar\nBAR=baz\n"))
f := NewConfigMapFactory(fSys, loader.NewFileLoader(fSys))
for _, tc := range testCases {
cm, err := f.MakeConfigMap(&tc.input)
cm, err := f.MakeConfigMap(&tc.input, tc.options)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
@@ -147,33 +142,3 @@ func TestConstructConfigMap(t *testing.T) {
}
}
}
func TestObjectConvertToUnstructured(t *testing.T) {
type testCase struct {
description string
input *corev1.ConfigMap
expected *unstructured.Unstructured
}
testCases := []testCase{
{
description: "convert config map",
input: makeEnvConfigMap("envConfigMap"),
expected: makeUnstructuredEnvConfigMap("envConfigMap"),
},
{
description: "convert secret",
input: makeEnvConfigMap("envSecret"),
expected: makeUnstructuredEnvConfigMap("envSecret"),
},
}
for _, tc := range testCases {
actual, err := objectToUnstructured(tc.input)
if err != nil {
t.Fatalf("%s: unexpected error: %v", tc.description, err)
}
if !reflect.DeepEqual(actual, tc.expected) {
t.Fatalf("%s: %#v\ndoesn't match expected\n%#v\n", tc.description, actual, tc.expected)
}
}
}

View File

@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package configmapandsecret
import (

View File

@@ -19,16 +19,21 @@ package configmapandsecret
import (
"context"
"fmt"
"log"
"os/exec"
"path/filepath"
"strings"
"time"
"github.com/kubernetes-sigs/kustomize/pkg/fs"
"github.com/kubernetes-sigs/kustomize/pkg/types"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/validation"
"sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/types"
)
const (
defaultCommandTimeout = 5 * time.Second
)
// SecretFactory makes Secrets.
@@ -56,12 +61,18 @@ func (f *SecretFactory) makeFreshSecret(args *types.SecretArgs) *corev1.Secret {
}
// MakeSecret returns a new secret.
func (f *SecretFactory) MakeSecret(args *types.SecretArgs) (*corev1.Secret, error) {
func (f *SecretFactory) MakeSecret(args *types.SecretArgs, options *types.GeneratorOptions) (*corev1.Secret, error) {
var all []kvPair
var err error
s := f.makeFreshSecret(args)
pairs, err := f.keyValuesFromEnvFileCommand(args.EnvCommand)
timeout := defaultCommandTimeout
if args.TimeoutSeconds != nil {
log.Println("SecretArgs.TimeoutSeconds will be deprected in next release. Please use GeneratorOptions.TimeoutSeconds instread.")
timeout = time.Duration(*args.TimeoutSeconds) * time.Second
}
pairs, err := f.keyValuesFromEnvFileCommand(args.EnvCommand, timeout, options)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf(
"env source file: %s",
@@ -69,7 +80,7 @@ func (f *SecretFactory) MakeSecret(args *types.SecretArgs) (*corev1.Secret, erro
}
all = append(all, pairs...)
pairs, err = f.keyValuesFromCommands(args.Commands)
pairs, err = f.keyValuesFromCommands(args.Commands, timeout, options)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf(
"commands %v", args.Commands))
@@ -82,7 +93,10 @@ func (f *SecretFactory) MakeSecret(args *types.SecretArgs) (*corev1.Secret, erro
return nil, err
}
}
if options != nil {
s.SetLabels(options.Labels)
s.SetAnnotations(options.Annotations)
}
return s, nil
}
@@ -98,18 +112,18 @@ func addKvToSecret(secret *corev1.Secret, keyName, data string) error {
return nil
}
func (f *SecretFactory) keyValuesFromEnvFileCommand(cmd string) ([]kvPair, error) {
content, err := f.createSecretKey(cmd)
func (f *SecretFactory) keyValuesFromEnvFileCommand(cmd string, timeout time.Duration, options *types.GeneratorOptions) ([]kvPair, error) {
content, err := f.createSecretKey(cmd, timeout, options)
if err != nil {
return nil, err
}
return keyValuesFromLines(content)
}
func (f *SecretFactory) keyValuesFromCommands(sources map[string]string) ([]kvPair, error) {
func (f *SecretFactory) keyValuesFromCommands(sources map[string]string, timeout time.Duration, options *types.GeneratorOptions) ([]kvPair, error) {
var kvs []kvPair
for k, cmd := range sources {
content, err := f.createSecretKey(cmd)
content, err := f.createSecretKey(cmd, timeout, options)
if err != nil {
return nil, err
}
@@ -119,16 +133,30 @@ func (f *SecretFactory) keyValuesFromCommands(sources map[string]string) ([]kvPa
}
// Run a command, return its output as the secret.
func (f *SecretFactory) createSecretKey(command string) ([]byte, error) {
func (f *SecretFactory) createSecretKey(command string, timeout time.Duration, options *types.GeneratorOptions) ([]byte, error) {
if !f.fSys.IsDir(f.wd) {
f.wd = filepath.Dir(f.wd)
if !f.fSys.IsDir(f.wd) {
return nil, errors.New("not a directory: " + f.wd)
}
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
if options != nil && options.TimeoutSeconds != nil {
t := time.Duration(*options.TimeoutSeconds) * time.Second
if t > timeout {
timeout = t
}
}
var commands []string
if options == nil || len(options.Shell) == 0 {
commands = []string{"sh", "-c", command}
} else {
commands = append(options.Shell, command)
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
cmd := exec.CommandContext(ctx, "sh", "-c", command)
cmd := exec.CommandContext(ctx, commands[0], commands[1:]...)
cmd.Dir = f.wd
return cmd.Output()
}

76
internal/k8sdeps/doc.go Normal file
View File

@@ -0,0 +1,76 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// It's possible that kustomize's features will be vendored into
// the kubernetes/kubernetes repo and made available to kubectl
// commands, while at the same time the kustomize program will
// continue to exist as an independent CLI. Vendoring snapshots
// would be taken just before a kubectl release.
//
// This creates a problem in that freestanding-kustomize depends on
// (for example):
//
// https://github.com/kubernetes/apimachinery/
// tree/master/pkg/util/yaml
//
// It vendors that package into
// sigs.k8s.io/kustomize/vendor/k8s.io/apimachinery/
//
// Whereas kubectl-kustomize would have to depend on the "staging"
// version of this code, located at
//
// https://github.com/kubernetes/kubernetes/
// blob/master/staging/src/k8s.io/apimachinery/pkg/util/yaml
//
// which is "vendored" via symlinks:
// k8s.io/kubernetes/vendor/k8s.io/apimachinery
// is a symlink to
// ../../staging/src/k8s.io/apimachinery
//
// The staging version is the canonical, under-development
// version of the code that kubectl depends on, whereas the packages
// at kubernetes/apimachinery are periodic snapshots of staging made
// for outside tools to depend on.
//
// apimachinery isn't the only package that poses this problem, just
// using it as a specific example.
//
// The kubectl binary cannot vendor in kustomize code that in
// turn vendors in the non-staging packages.
//
// One way to fix some of this would be to copy code - a hard fork.
// This has all the problems associated with a hard forking.
//
// Another way would be to break the kustomize repo into three:
//
// (1) kustomize - repo with the main() function,
// vendoring (2) and (3).
//
// (2) kustomize-libs - packages used by (1) with no
// apimachinery dependence.
//
// (3) kustomize-k8sdeps - A thin code layer that depends
// on (vendors) apimachinery to provide thin implementations
// to interfaces used in (2).
//
// The kubectl repo would then vendor from (2) only, and have
// a local implementation of (3). With that in mind, it's clear
// that (3) doesn't have to be a repo; the kustomize version of
// the thin layer can live directly in (1).
//
// This package is the code in (3), meant for kustomize.
package k8sdeps

View File

@@ -0,0 +1,34 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package k8sdeps provides kustomize factory with k8s dependencies
package k8sdeps
import (
"sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/internal/k8sdeps/transformer"
"sigs.k8s.io/kustomize/internal/k8sdeps/validator"
"sigs.k8s.io/kustomize/pkg/factory"
)
// NewFactory creates an instance of KustFactory using k8sdeps factories
func NewFactory() *factory.KustFactory {
return factory.NewKustFactory(
kunstruct.NewKunstructuredFactoryImpl(),
validator.NewKustValidator(),
transformer.NewFactoryImpl(),
)
}

View File

@@ -0,0 +1,96 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kunstruct
import (
"bytes"
"io"
"strings"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/util/yaml"
"sigs.k8s.io/kustomize/internal/k8sdeps/configmapandsecret"
"sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/ifc"
"sigs.k8s.io/kustomize/pkg/types"
)
// KunstructurerFactoryImpl hides construction using apimachinery types.
type KunstructurerFactoryImpl struct {
cmfactory *configmapandsecret.ConfigMapFactory
secfactory *configmapandsecret.SecretFactory
}
var _ ifc.KunstructuredFactory = &KunstructurerFactoryImpl{}
// NewKunstructuredFactoryImpl returns a factory.
func NewKunstructuredFactoryImpl() ifc.KunstructuredFactory {
return &KunstructurerFactoryImpl{}
}
// SliceFromBytes returns a slice of Kunstructured.
func (kf *KunstructurerFactoryImpl) SliceFromBytes(
in []byte) ([]ifc.Kunstructured, error) {
decoder := yaml.NewYAMLOrJSONDecoder(bytes.NewReader(in), 1024)
var result []ifc.Kunstructured
var err error
for err == nil || isEmptyYamlError(err) {
var out unstructured.Unstructured
err = decoder.Decode(&out)
if err == nil {
result = append(result, &UnstructAdapter{Unstructured: out})
}
}
if err != io.EOF {
return nil, err
}
return result, nil
}
func isEmptyYamlError(err error) bool {
return strings.Contains(err.Error(), "is missing in 'null'")
}
// FromMap returns an instance of Kunstructured.
func (kf *KunstructurerFactoryImpl) FromMap(
m map[string]interface{}) ifc.Kunstructured {
return &UnstructAdapter{Unstructured: unstructured.Unstructured{Object: m}}
}
// MakeConfigMap returns an instance of Kunstructured for ConfigMap
func (kf *KunstructurerFactoryImpl) MakeConfigMap(args *types.ConfigMapArgs, options *types.GeneratorOptions) (ifc.Kunstructured, error) {
cm, err := kf.cmfactory.MakeConfigMap(args, options)
if err != nil {
return nil, err
}
return NewKunstructuredFromObject(cm)
}
// MakeSecret returns an instance of Kunstructured for Secret
func (kf *KunstructurerFactoryImpl) MakeSecret(args *types.SecretArgs, options *types.GeneratorOptions) (ifc.Kunstructured, error) {
sec, err := kf.secfactory.MakeSecret(args, options)
if err != nil {
return nil, err
}
return NewKunstructuredFromObject(sec)
}
// Set sets loader, filesystem and workdirectory
func (kf *KunstructurerFactoryImpl) Set(fs fs.FileSystem, ldr ifc.Loader) {
kf.cmfactory = configmapandsecret.NewConfigMapFactory(fs, ldr)
kf.secfactory = configmapandsecret.NewSecretFactory(fs, ldr.Root())
}

View File

@@ -0,0 +1,124 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kunstruct
import (
"reflect"
"testing"
"sigs.k8s.io/kustomize/pkg/ifc"
)
func TestSliceFromBytes(t *testing.T) {
factory := NewKunstructuredFactoryImpl()
testConfigMap := factory.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "winnie",
},
})
tests := []struct {
name string
input []byte
expectedOut []ifc.Kunstructured
expectedErr bool
}{
{
name: "garbage",
input: []byte("garbageIn: garbageOut"),
expectedOut: []ifc.Kunstructured{},
expectedErr: true,
},
{
name: "noBytes",
input: []byte{},
expectedOut: []ifc.Kunstructured{},
expectedErr: false,
},
{
name: "goodJson",
input: []byte(`
{"apiVersion":"v1","kind":"ConfigMap","metadata":{"name":"winnie"}}
`),
expectedOut: []ifc.Kunstructured{testConfigMap},
expectedErr: false,
},
{
name: "goodYaml1",
input: []byte(`
apiVersion: v1
kind: ConfigMap
metadata:
name: winnie
`),
expectedOut: []ifc.Kunstructured{testConfigMap},
expectedErr: false,
},
{
name: "goodYaml2",
input: []byte(`
apiVersion: v1
kind: ConfigMap
metadata:
name: winnie
---
apiVersion: v1
kind: ConfigMap
metadata:
name: winnie
`),
expectedOut: []ifc.Kunstructured{testConfigMap, testConfigMap},
expectedErr: false,
},
{
name: "garbageInOneOfTwoObjects",
input: []byte(`
apiVersion: v1
kind: ConfigMap
metadata:
name: winnie
---
WOOOOOOOOOOOOOOOOOOOOOOOOT: woot
`),
expectedOut: []ifc.Kunstructured{},
expectedErr: true,
},
}
for _, test := range tests {
rs, err := factory.SliceFromBytes(test.input)
if test.expectedErr && err == nil {
t.Fatalf("%v: should return error", test.name)
}
if !test.expectedErr && err != nil {
t.Fatalf("%v: unexpected error: %s", test.name, err)
}
if len(rs) != len(test.expectedOut) {
t.Fatalf("%s: length mismatch %d != %d",
test.name, len(rs), len(test.expectedOut))
}
for i := range rs {
if !reflect.DeepEqual(test.expectedOut[i], rs[i]) {
t.Fatalf("%s: Got: %v\nexpected:%v",
test.name, test.expectedOut[i], rs[i])
}
}
}
}

View File

@@ -0,0 +1,89 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package kunstruct provides unstructured from api machinery and factory for creating unstructured
package kunstruct
import (
"encoding/json"
"fmt"
"strings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/ifc"
)
var _ ifc.Kunstructured = &UnstructAdapter{}
// UnstructAdapter wraps unstructured.Unstructured from
// https://github.com/kubernetes/apimachinery/blob/master/
// pkg/apis/meta/v1/unstructured/unstructured.go
// to isolate dependence on apimachinery.
type UnstructAdapter struct {
unstructured.Unstructured
}
// NewKunstructuredFromObject returns a new instance of Kunstructured.
func NewKunstructuredFromObject(obj runtime.Object) (ifc.Kunstructured, error) {
// Convert obj to a byte stream, then convert that to JSON (Unstructured).
marshaled, err := json.Marshal(obj)
if err != nil {
return &UnstructAdapter{}, err
}
var u unstructured.Unstructured
err = u.UnmarshalJSON(marshaled)
// creationTimestamp always 'null', remove it
u.SetCreationTimestamp(metav1.Time{})
return &UnstructAdapter{Unstructured: u}, err
}
// GetGvk returns the Gvk name of the object.
func (fs *UnstructAdapter) GetGvk() gvk.Gvk {
x := fs.GroupVersionKind()
return gvk.Gvk{
Group: x.Group,
Version: x.Version,
Kind: x.Kind,
}
}
// Copy provides a copy behind an interface.
func (fs *UnstructAdapter) Copy() ifc.Kunstructured {
return &UnstructAdapter{*fs.DeepCopy()}
}
// Map returns the unstructured content map.
func (fs *UnstructAdapter) Map() map[string]interface{} {
return fs.Object
}
// SetMap overrides the unstructured content map.
func (fs *UnstructAdapter) SetMap(m map[string]interface{}) {
fs.Object = m
}
// GetFieldValue returns value at the given fieldpath.
func (fs *UnstructAdapter) GetFieldValue(path string) (string, error) {
s, found, err := unstructured.NestedString(
fs.UnstructuredContent(), strings.Split(path, ".")...)
if found || err != nil {
return s, err
}
return "", fmt.Errorf("no field named '%s'", path)
}

View File

@@ -0,0 +1,148 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kunstruct
import (
"testing"
)
func TestGetFieldValue(t *testing.T) {
factory := NewKunstructuredFactoryImpl()
kunstructured := factory.FromMap(map[string]interface{}{
"Kind": "Service",
"metadata": map[string]interface{}{
"labels": map[string]string{
"app": "application-name",
},
"name": "service-name",
},
"spec": map[string]interface{}{
"ports": map[string]interface{}{
"port": "80",
},
},
"this": map[string]interface{}{
"is": map[string]interface{}{
"aNumber": 1000,
"aNilValue": nil,
"anEmptyMap": map[string]interface{}{},
"unrecognizable": testing.InternalExample{
Name: "fooBar",
},
},
},
})
tests := []struct {
name string
pathToField string
expectedValue string
errorExpected bool
errorMsg string
}{
{
name: "oneField",
pathToField: "Kind",
expectedValue: "Service",
errorExpected: false,
},
{
name: "twoFields",
pathToField: "metadata.name",
expectedValue: "service-name",
errorExpected: false,
},
{
name: "threeFields",
pathToField: "spec.ports.port",
expectedValue: "80",
errorExpected: false,
},
{
name: "empty",
pathToField: "",
errorExpected: true,
errorMsg: "no field named ''",
},
{
name: "emptyDotEmpty",
pathToField: ".",
errorExpected: true,
errorMsg: "no field named '.'",
},
{
name: "twoFieldsOneMissing",
pathToField: "metadata.banana",
errorExpected: true,
errorMsg: "no field named 'metadata.banana'",
},
{
name: "deeperMissingField",
pathToField: "this.is.aDeep.field.that.does.not.exist",
errorExpected: true,
errorMsg: "no field named 'this.is.aDeep.field.that.does.not.exist'",
},
{
name: "emptyMap",
pathToField: "this.is.anEmptyMap",
errorExpected: true,
errorMsg: ".this.is.anEmptyMap accessor error: map[] is of the type map[string]interface {}, expected string",
},
{
name: "numberAsValue",
pathToField: "this.is.aNumber",
errorExpected: true,
errorMsg: ".this.is.aNumber accessor error: 1000 is of the type int, expected string",
},
{
name: "nilAsValue",
pathToField: "this.is.aNilValue",
errorExpected: true,
errorMsg: ".this.is.aNilValue accessor error: <nil> is of the type <nil>, expected string",
},
{
name: "unrecognizable",
pathToField: "this.is.unrecognizable.Name",
errorExpected: true,
errorMsg: ".this.is.unrecognizable.Name accessor error: {fooBar <nil> false} is of the type testing.InternalExample, expected map[string]interface{}",
},
}
for _, test := range tests {
s, err := kunstructured.GetFieldValue(test.pathToField)
if test.errorExpected {
if err == nil {
t.Fatalf("%q; path %q - should return error, but no error returned",
test.name, test.pathToField)
}
if test.errorMsg != err.Error() {
t.Fatalf("%q; path %q - expected error: \"%s\", got error: \"%v\"",
test.name, test.pathToField, test.errorMsg, err.Error())
}
continue
}
if err != nil {
t.Fatalf("%q; path %q - unexpected error %v",
test.name, test.pathToField, err)
}
if test.expectedValue != s {
t.Fatalf("%q; Got: %s expected: %s",
test.name, s, test.expectedValue)
}
}
}

View File

@@ -0,0 +1,43 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package transformer provides transformer factory
package transformer
import (
"sigs.k8s.io/kustomize/internal/k8sdeps/transformer/hash"
"sigs.k8s.io/kustomize/internal/k8sdeps/transformer/patch"
"sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/transformers"
)
// FactoryImpl makes patch transformer and name hash transformer
type FactoryImpl struct{}
// NewFactoryImpl makes a new factoryImpl instance
func NewFactoryImpl() *FactoryImpl {
return &FactoryImpl{}
}
// MakePatchTransformer makes a new patch transformer
func (p *FactoryImpl) MakePatchTransformer(slice []*resource.Resource, rf *resource.Factory) (transformers.Transformer, error) {
return patch.NewPatchTransformer(slice, rf)
}
// MakeHashTransformer makes a new name hash transformer
func (p *FactoryImpl) MakeHashTransformer() transformers.Transformer {
return hash.NewNameHashTransformer()
}

View File

@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Package hash generates hash strings from configmaps and secrets.
package hash
import (
@@ -23,8 +22,42 @@ import (
"fmt"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
// KustHash compute hash for unstructured objects
type KustHash struct{}
// NewKustHash returns a KustHash object
func NewKustHash() *KustHash {
return &KustHash{}
}
// Hash returns a hash of either a ConfigMap or a Secret
func (h *KustHash) Hash(m map[string]interface{}) (string, error) {
u := unstructured.Unstructured{
Object: m,
}
kind := u.GetKind()
switch kind {
case "ConfigMap":
cm, err := unstructuredToConfigmap(u)
if err != nil {
return "", err
}
return ConfigMapHash(cm)
case "Secret":
sec, err := unstructuredToSecret(u)
if err != nil {
return "", err
}
return SecretHash(sec)
default:
return "", fmt.Errorf("type %s is supported for hashing in %v", kind, m)
}
}
// ConfigMapHash returns a hash of the ConfigMap.
// The Data, Kind, and Name are taken into account.
func ConfigMapHash(cm *v1.ConfigMap) (string, error) {
@@ -113,3 +146,23 @@ func encodeHash(hex string) (string, error) {
func hash(data string) string {
return fmt.Sprintf("%x", sha256.Sum256([]byte(data)))
}
func unstructuredToConfigmap(u unstructured.Unstructured) (*v1.ConfigMap, error) {
marshaled, err := json.Marshal(u.Object)
if err != nil {
return nil, err
}
var out v1.ConfigMap
err = json.Unmarshal(marshaled, &out)
return &out, err
}
func unstructuredToSecret(u unstructured.Unstructured) (*v1.Secret, error) {
marshaled, err := json.Marshal(u.Object)
if err != nil {
return nil, err
}
var out v1.Secret
err = json.Unmarshal(marshaled, &out)
return &out, err
}

View File

@@ -22,8 +22,14 @@ import (
"testing"
"k8s.io/api/core/v1"
"sigs.k8s.io/kustomize/pkg/gvk"
)
var service = gvk.Gvk{Version: "v1", Kind: "Service"}
var secret = gvk.Gvk{Version: "v1", Kind: "Secret"}
var cmap = gvk.Gvk{Version: "v1", Kind: "ConfigMap"}
var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}
func TestConfigMapHash(t *testing.T) {
cases := []struct {
desc string

View File

@@ -0,0 +1,57 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package hash
import (
"fmt"
"sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/transformers"
)
type nameHashTransformer struct{}
var _ transformers.Transformer = &nameHashTransformer{}
// NewNameHashTransformer construct a nameHashTransformer.
func NewNameHashTransformer() transformers.Transformer {
return &nameHashTransformer{}
}
// Transform appends hash to configmaps and secrets.
func (o *nameHashTransformer) Transform(m resmap.ResMap) error {
for _, res := range m {
if res.IsGenerated() {
err := o.appendHash(res)
if err != nil {
return err
}
}
}
return nil
}
func (o *nameHashTransformer) appendHash(res *resource.Resource) error {
h, err := NewKustHash().Hash(res.Map())
if err != nil {
return err
}
nameWithHash := fmt.Sprintf("%s-%s", res.GetName(), h)
res.SetName(nameWithHash)
return nil
}

View File

@@ -14,19 +14,24 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package transformers
package hash
import (
"reflect"
"testing"
"github.com/kubernetes-sigs/kustomize/pkg/resmap"
"github.com/kubernetes-sigs/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/pkg/ifc"
"sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource"
)
func TestNameHashTransformer(t *testing.T) {
rf := resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
objs := resmap.ResMap{
resource.NewResId(cmap, "cm1"): resource.NewResourceFromMap(
resid.NewResId(cmap, "cm1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
@@ -34,7 +39,7 @@ func TestNameHashTransformer(t *testing.T) {
"name": "cm1",
},
}),
resource.NewResId(deploy, "deploy1"): resource.NewResourceFromMap(
resid.NewResId(deploy, "deploy1"): rf.FromMap(
map[string]interface{}{
"group": "apps",
"apiVersion": "v1",
@@ -60,7 +65,7 @@ func TestNameHashTransformer(t *testing.T) {
},
},
}),
resource.NewResId(service, "svc1"): resource.NewResourceFromMap(
resid.NewResId(service, "svc1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Service",
@@ -76,18 +81,18 @@ func TestNameHashTransformer(t *testing.T) {
},
},
}),
resource.NewResId(secret, "secret1"): resource.NewResourceFromMap(
resid.NewResId(secret, "secret1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "secret1",
},
}).SetBehavior(resource.BehaviorCreate),
}).SetBehavior(ifc.BehaviorCreate),
}
expected := resmap.ResMap{
resource.NewResId(cmap, "cm1"): resource.NewResourceFromMap(
resid.NewResId(cmap, "cm1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
@@ -95,7 +100,7 @@ func TestNameHashTransformer(t *testing.T) {
"name": "cm1",
},
}),
resource.NewResId(deploy, "deploy1"): resource.NewResourceFromMap(
resid.NewResId(deploy, "deploy1"): rf.FromMap(
map[string]interface{}{
"group": "apps",
"apiVersion": "v1",
@@ -121,7 +126,7 @@ func TestNameHashTransformer(t *testing.T) {
},
},
}),
resource.NewResId(service, "svc1"): resource.NewResourceFromMap(
resid.NewResId(service, "svc1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Service",
@@ -137,14 +142,14 @@ func TestNameHashTransformer(t *testing.T) {
},
},
}),
resource.NewResId(secret, "secret1"): resource.NewResourceFromMap(
resid.NewResId(secret, "secret1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "secret1-7kc45hd5f7",
},
}).SetBehavior(resource.BehaviorCreate),
}).SetBehavior(ifc.BehaviorCreate),
}
tran := NewNameHashTransformer()

View File

@@ -14,33 +14,38 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package transformers
package patch
import (
"encoding/json"
"fmt"
"github.com/evanphx/json-patch"
"github.com/kubernetes-sigs/kustomize/pkg/resmap"
"github.com/kubernetes-sigs/kustomize/pkg/resource"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/transformers"
)
// patchTransformer applies patches.
type patchTransformer struct {
patches []*resource.Resource
rf *resource.Factory
}
var _ Transformer = &patchTransformer{}
var _ transformers.Transformer = &patchTransformer{}
// NewPatchTransformer constructs a patchTransformer.
func NewPatchTransformer(slice []*resource.Resource) (Transformer, error) {
func NewPatchTransformer(
slice []*resource.Resource, rf *resource.Factory) (transformers.Transformer, error) {
if len(slice) == 0 {
return NewNoOpTransformer(), nil
return transformers.NewNoOpTransformer(), nil
}
return &patchTransformer{slice}, nil
return &patchTransformer{patches: slice, rf: rf}, nil
}
// Transform apply the patches on top of the base resources.
@@ -60,21 +65,21 @@ func (pt *patchTransformer) Transform(baseResourceMap resmap.ResMap) error {
return fmt.Errorf("failed to find an object with %#v to apply the patch", id.Gvk())
}
if len(matchedIds) > 1 {
return fmt.Errorf("Found multiple objects %#v that the patch %#v can apply", matchedIds, id)
return fmt.Errorf("found multiple objects %#v targeted by patch %#v (ambiguous)", matchedIds, id)
}
id = matchedIds[0]
base := baseResourceMap[id]
merged := map[string]interface{}{}
versionedObj, err := scheme.Scheme.New(id.Gvk())
versionedObj, err := scheme.Scheme.New(toSchemaGvk(id.Gvk()))
baseName := base.GetName()
switch {
case runtime.IsNotRegisteredError(err):
// Use JSON merge patch to handle types w/o schema
baseBytes, err := json.Marshal(base)
baseBytes, err := json.Marshal(base.Map())
if err != nil {
return err
}
patchBytes, err := json.Marshal(patch)
patchBytes, err := json.Marshal(patch.Map())
if err != nil {
return err
}
@@ -92,21 +97,21 @@ func (pt *patchTransformer) Transform(baseResourceMap resmap.ResMap) error {
// Use Strategic-Merge-Patch to handle types w/ schema
// TODO: Change this to use the new Merge package.
// Store the name of the base object, because this name may have been munged.
// Apply this name to the StrategicMergePatched object.
// Apply this name to the patched object.
lookupPatchMeta, err := strategicpatch.NewPatchMetaFromStruct(versionedObj)
if err != nil {
return err
}
merged, err = strategicpatch.StrategicMergeMapPatchUsingLookupPatchMeta(
base.Object,
patch.Object,
base.Map(),
patch.Map(),
lookupPatchMeta)
if err != nil {
return err
}
}
base.SetName(baseName)
baseResourceMap[id].Object = merged
baseResourceMap[id].SetMap(merged)
}
return nil
}
@@ -123,15 +128,15 @@ func (pt *patchTransformer) mergePatches() (resmap.ResMap, error) {
continue
}
versionedObj, err := scheme.Scheme.New(id.Gvk())
versionedObj, err := scheme.Scheme.New(toSchemaGvk(id.Gvk()))
if err != nil && !runtime.IsNotRegisteredError(err) {
return nil, err
}
var cd conflictDetector
if err != nil {
cd = newJMPConflictDetector()
cd = newJMPConflictDetector(pt.rf)
} else {
cd, err = newSMPConflictDetector(versionedObj)
cd, err = newSMPConflictDetector(versionedObj, pt.rf)
if err != nil {
return nil, err
}
@@ -146,7 +151,9 @@ func (pt *patchTransformer) mergePatches() (resmap.ResMap, error) {
if err != nil {
return nil, err
}
return nil, fmt.Errorf("there is conflict between %#v and %#v", conflictingPatch.Object, patch.Object)
return nil, fmt.Errorf(
"conflict between %#v and %#v",
conflictingPatch.Map(), patch.Map())
}
merged, err := cd.mergePatches(existing, patch)
if err != nil {
@@ -156,3 +163,12 @@ func (pt *patchTransformer) mergePatches() (resmap.ResMap, error) {
}
return rc, nil
}
// toSchemaGvk converts to a schema.GroupVersionKind.
func toSchemaGvk(x gvk.Gvk) schema.GroupVersionKind {
return schema.GroupVersionKind{
Group: x.Group,
Version: x.Version,
Kind: x.Kind,
}
}

View File

@@ -14,20 +14,28 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package transformers
package patch
import (
"reflect"
"strings"
"testing"
"github.com/kubernetes-sigs/kustomize/pkg/resmap"
"github.com/kubernetes-sigs/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource"
)
var rf = resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}
var foo = gvk.Gvk{Group: "example.com", Version: "v1", Kind: "Foo"}
func TestOverlayRun(t *testing.T) {
base := resmap.ResMap{
resource.NewResId(deploy, "deploy1"): resource.NewResourceFromMap(
resid.NewResId(deploy, "deploy1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
@@ -54,7 +62,7 @@ func TestOverlayRun(t *testing.T) {
}),
}
patch := []*resource.Resource{
resource.NewResourceFromMap(map[string]interface{}{
rf.FromMap(map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
@@ -87,7 +95,7 @@ func TestOverlayRun(t *testing.T) {
),
}
expected := resmap.ResMap{
resource.NewResId(deploy, "deploy1"): resource.NewResourceFromMap(
resid.NewResId(deploy, "deploy1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
@@ -120,7 +128,7 @@ func TestOverlayRun(t *testing.T) {
},
}),
}
lt, err := NewPatchTransformer(patch)
lt, err := NewPatchTransformer(patch, rf)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
@@ -136,7 +144,7 @@ func TestOverlayRun(t *testing.T) {
func TestMultiplePatches(t *testing.T) {
base := resmap.ResMap{
resource.NewResId(deploy, "deploy1"): resource.NewResourceFromMap(
resid.NewResId(deploy, "deploy1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
@@ -158,7 +166,7 @@ func TestMultiplePatches(t *testing.T) {
}),
}
patch := []*resource.Resource{
resource.NewResourceFromMap(map[string]interface{}{
rf.FromMap(map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
@@ -184,7 +192,7 @@ func TestMultiplePatches(t *testing.T) {
},
},
),
resource.NewResourceFromMap(map[string]interface{}{
rf.FromMap(map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
@@ -215,7 +223,7 @@ func TestMultiplePatches(t *testing.T) {
),
}
expected := resmap.ResMap{
resource.NewResId(deploy, "deploy1"): resource.NewResourceFromMap(
resid.NewResId(deploy, "deploy1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
@@ -250,7 +258,7 @@ func TestMultiplePatches(t *testing.T) {
},
}),
}
lt, err := NewPatchTransformer(patch)
lt, err := NewPatchTransformer(patch, rf)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
@@ -266,7 +274,7 @@ func TestMultiplePatches(t *testing.T) {
func TestMultiplePatchesWithConflict(t *testing.T) {
base := resmap.ResMap{
resource.NewResId(deploy, "deploy1"): resource.NewResourceFromMap(
resid.NewResId(deploy, "deploy1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
@@ -288,7 +296,7 @@ func TestMultiplePatchesWithConflict(t *testing.T) {
}),
}
patch := []*resource.Resource{
resource.NewResourceFromMap(map[string]interface{}{
rf.FromMap(map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
@@ -314,7 +322,7 @@ func TestMultiplePatchesWithConflict(t *testing.T) {
},
},
),
resource.NewResourceFromMap(map[string]interface{}{
rf.FromMap(map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
@@ -336,7 +344,7 @@ func TestMultiplePatchesWithConflict(t *testing.T) {
),
}
lt, err := NewPatchTransformer(patch)
lt, err := NewPatchTransformer(patch, rf)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
@@ -351,7 +359,7 @@ func TestMultiplePatchesWithConflict(t *testing.T) {
func TestNoSchemaOverlayRun(t *testing.T) {
base := resmap.ResMap{
resource.NewResId(foo, "my-foo"): resource.NewResourceFromMap(
resid.NewResId(foo, "my-foo"): rf.FromMap(
map[string]interface{}{
"apiVersion": "example.com/v1",
"kind": "Foo",
@@ -367,7 +375,7 @@ func TestNoSchemaOverlayRun(t *testing.T) {
}),
}
patch := []*resource.Resource{
resource.NewResourceFromMap(map[string]interface{}{
rf.FromMap(map[string]interface{}{
"apiVersion": "example.com/v1",
"kind": "Foo",
"metadata": map[string]interface{}{
@@ -383,7 +391,7 @@ func TestNoSchemaOverlayRun(t *testing.T) {
),
}
expected := resmap.ResMap{
resource.NewResId(foo, "my-foo"): resource.NewResourceFromMap(
resid.NewResId(foo, "my-foo"): rf.FromMap(
map[string]interface{}{
"apiVersion": "example.com/v1",
"kind": "Foo",
@@ -399,7 +407,7 @@ func TestNoSchemaOverlayRun(t *testing.T) {
}),
}
lt, err := NewPatchTransformer(patch)
lt, err := NewPatchTransformer(patch, rf)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
@@ -414,7 +422,7 @@ func TestNoSchemaOverlayRun(t *testing.T) {
func TestNoSchemaMultiplePatches(t *testing.T) {
base := resmap.ResMap{
resource.NewResId(foo, "my-foo"): resource.NewResourceFromMap(
resid.NewResId(foo, "my-foo"): rf.FromMap(
map[string]interface{}{
"apiVersion": "example.com/v1",
"kind": "Foo",
@@ -430,7 +438,7 @@ func TestNoSchemaMultiplePatches(t *testing.T) {
}),
}
patch := []*resource.Resource{
resource.NewResourceFromMap(map[string]interface{}{
rf.FromMap(map[string]interface{}{
"apiVersion": "example.com/v1",
"kind": "Foo",
"metadata": map[string]interface{}{
@@ -444,7 +452,7 @@ func TestNoSchemaMultiplePatches(t *testing.T) {
},
},
),
resource.NewResourceFromMap(map[string]interface{}{
rf.FromMap(map[string]interface{}{
"apiVersion": "example.com/v1",
"kind": "Foo",
"metadata": map[string]interface{}{
@@ -463,7 +471,7 @@ func TestNoSchemaMultiplePatches(t *testing.T) {
),
}
expected := resmap.ResMap{
resource.NewResId(foo, "my-foo"): resource.NewResourceFromMap(
resid.NewResId(foo, "my-foo"): rf.FromMap(
map[string]interface{}{
"apiVersion": "example.com/v1",
"kind": "Foo",
@@ -483,7 +491,7 @@ func TestNoSchemaMultiplePatches(t *testing.T) {
}),
}
lt, err := NewPatchTransformer(patch)
lt, err := NewPatchTransformer(patch, rf)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
@@ -498,7 +506,7 @@ func TestNoSchemaMultiplePatches(t *testing.T) {
func TestNoSchemaMultiplePatchesWithConflict(t *testing.T) {
base := resmap.ResMap{
resource.NewResId(foo, "my-foo"): resource.NewResourceFromMap(
resid.NewResId(foo, "my-foo"): rf.FromMap(
map[string]interface{}{
"apiVersion": "example.com/v1",
"kind": "Foo",
@@ -514,7 +522,7 @@ func TestNoSchemaMultiplePatchesWithConflict(t *testing.T) {
}),
}
patch := []*resource.Resource{
resource.NewResourceFromMap(map[string]interface{}{
rf.FromMap(map[string]interface{}{
"apiVersion": "example.com/v1",
"kind": "Foo",
"metadata": map[string]interface{}{
@@ -527,7 +535,7 @@ func TestNoSchemaMultiplePatchesWithConflict(t *testing.T) {
},
},
}),
resource.NewResourceFromMap(map[string]interface{}{
rf.FromMap(map[string]interface{}{
"apiVersion": "example.com/v1",
"kind": "Foo",
"metadata": map[string]interface{}{
@@ -541,7 +549,7 @@ func TestNoSchemaMultiplePatchesWithConflict(t *testing.T) {
}),
}
lt, err := NewPatchTransformer(patch)
lt, err := NewPatchTransformer(patch, rf)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@@ -14,16 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package transformers
package patch
import (
"encoding/json"
"github.com/evanphx/json-patch"
"github.com/kubernetes-sigs/kustomize/pkg/resource"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/mergepatch"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"sigs.k8s.io/kustomize/pkg/resource"
)
type conflictDetector interface {
@@ -32,28 +32,33 @@ type conflictDetector interface {
mergePatches(patch1, patch2 *resource.Resource) (*resource.Resource, error)
}
type jsonMergePatch struct{}
type jsonMergePatch struct {
rf *resource.Factory
}
var _ conflictDetector = &jsonMergePatch{}
func newJMPConflictDetector() conflictDetector {
return &jsonMergePatch{}
func newJMPConflictDetector(rf *resource.Factory) conflictDetector {
return &jsonMergePatch{rf: rf}
}
func (jmp *jsonMergePatch) hasConflict(patch1, patch2 *resource.Resource) (bool, error) {
return mergepatch.HasConflicts(patch1.Object, patch2.Object)
func (jmp *jsonMergePatch) hasConflict(
patch1, patch2 *resource.Resource) (bool, error) {
return mergepatch.HasConflicts(patch1.Map(), patch2.Map())
}
func (jmp *jsonMergePatch) findConflict(conflictingPatchIdx int, patches []*resource.Resource) (*resource.Resource, error) {
func (jmp *jsonMergePatch) findConflict(
conflictingPatchIdx int, patches []*resource.Resource) (*resource.Resource, error) {
for i, patch := range patches {
if i == conflictingPatchIdx {
continue
}
if patches[conflictingPatchIdx].GroupVersionKind() != patch.GroupVersionKind() ||
patches[conflictingPatchIdx].GetName() != patch.GetName() {
if !patches[conflictingPatchIdx].Id().GvknEquals(patch.Id()) {
continue
}
conflict, err := mergepatch.HasConflicts(patch.Object, patches[conflictingPatchIdx].Object)
conflict, err := mergepatch.HasConflicts(
patch.Map(),
patches[conflictingPatchIdx].Map())
if err != nil {
return nil, err
}
@@ -64,14 +69,13 @@ func (jmp *jsonMergePatch) findConflict(conflictingPatchIdx int, patches []*reso
return nil, nil
}
func (jmp *jsonMergePatch) mergePatches(patch1, patch2 *resource.Resource) (*resource.Resource, error) {
var merged resource.Resource
var mergedMap map[string]interface{}
baseBytes, err := json.Marshal(patch1.Object)
func (jmp *jsonMergePatch) mergePatches(
patch1, patch2 *resource.Resource) (*resource.Resource, error) {
baseBytes, err := json.Marshal(patch1.Map())
if err != nil {
return nil, err
}
patchBytes, err := json.Marshal(patch2.Object)
patchBytes, err := json.Marshal(patch2.Map())
if err != nil {
return nil, err
}
@@ -79,37 +83,43 @@ func (jmp *jsonMergePatch) mergePatches(patch1, patch2 *resource.Resource) (*res
if err != nil {
return nil, err
}
mergedMap := make(map[string]interface{})
err = json.Unmarshal(mergedBytes, &mergedMap)
merged.SetUnstructuredContent(mergedMap)
return &merged, err
return jmp.rf.FromMap(mergedMap), err
}
type strategicMergePatch struct {
lookupPatchMeta strategicpatch.LookupPatchMeta
rf *resource.Factory
}
var _ conflictDetector = &strategicMergePatch{}
func newSMPConflictDetector(versionedObj runtime.Object) (conflictDetector, error) {
func newSMPConflictDetector(
versionedObj runtime.Object,
rf *resource.Factory) (conflictDetector, error) {
lookupPatchMeta, err := strategicpatch.NewPatchMetaFromStruct(versionedObj)
return &strategicMergePatch{lookupPatchMeta: lookupPatchMeta}, err
return &strategicMergePatch{lookupPatchMeta: lookupPatchMeta, rf: rf}, err
}
func (smp *strategicMergePatch) hasConflict(patch1, patch2 *resource.Resource) (bool, error) {
return strategicpatch.MergingMapsHaveConflicts(patch1.Object, patch2.Object, smp.lookupPatchMeta)
func (smp *strategicMergePatch) hasConflict(p1, p2 *resource.Resource) (bool, error) {
return strategicpatch.MergingMapsHaveConflicts(
p1.Map(), p2.Map(), smp.lookupPatchMeta)
}
func (smp *strategicMergePatch) findConflict(conflictingPatchIdx int, patches []*resource.Resource) (*resource.Resource, error) {
func (smp *strategicMergePatch) findConflict(
conflictingPatchIdx int, patches []*resource.Resource) (*resource.Resource, error) {
for i, patch := range patches {
if i == conflictingPatchIdx {
continue
}
if patches[conflictingPatchIdx].GroupVersionKind() != patch.GroupVersionKind() ||
patches[conflictingPatchIdx].GetName() != patch.GetName() {
if !patches[conflictingPatchIdx].Id().GvknEquals(patch.Id()) {
continue
}
conflict, err := strategicpatch.MergingMapsHaveConflicts(
patch.Object, patches[conflictingPatchIdx].Object, smp.lookupPatchMeta)
patch.Map(),
patches[conflictingPatchIdx].Map(),
smp.lookupPatchMeta)
if err != nil {
return nil, err
}
@@ -121,9 +131,7 @@ func (smp *strategicMergePatch) findConflict(conflictingPatchIdx int, patches []
}
func (smp *strategicMergePatch) mergePatches(patch1, patch2 *resource.Resource) (*resource.Resource, error) {
merged := resource.Resource{}
mergeJsonMap, err := strategicpatch.MergeStrategicMergeMapPatchUsingLookupPatchMeta(
smp.lookupPatchMeta, patch1.Object, patch2.Object)
merged.SetUnstructuredContent(mergeJsonMap)
return &merged, err
mergeJSONMap, err := strategicpatch.MergeStrategicMergeMapPatchUsingLookupPatchMeta(
smp.lookupPatchMeta, patch1.Map(), patch2.Map())
return smp.rf.FromMap(mergeJSONMap), err
}

View File

@@ -0,0 +1,61 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package validator provides functions to validate labels, annotations, namespace using apimachinery
package validator
import (
"errors"
apivalidation "k8s.io/apimachinery/pkg/api/validation"
v1validation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
)
// KustValidator validates Labels and annotations by apimachinery
type KustValidator struct{}
// NewKustValidator returns a KustValidator object
func NewKustValidator() *KustValidator {
return &KustValidator{}
}
// MakeAnnotationValidator returns a MapValidatorFunc using apimachinery.
func (v *KustValidator) MakeAnnotationValidator() func(map[string]string) error {
return func(x map[string]string) error {
errs := apivalidation.ValidateAnnotations(x, field.NewPath("field"))
if len(errs) > 0 {
return errors.New(errs.ToAggregate().Error())
}
return nil
}
}
// MakeLabelValidator returns a MapValidatorFunc using apimachinery.
func (v *KustValidator) MakeLabelValidator() func(map[string]string) error {
return func(x map[string]string) error {
errs := v1validation.ValidateLabels(x, field.NewPath("field"))
if len(errs) > 0 {
return errors.New(errs.ToAggregate().Error())
}
return nil
}
}
// ValidateNamespace validates a string is a valid namespace using apimachinery.
func (v *KustValidator) ValidateNamespace(s string) []string {
return validation.IsDNS1123Label(s)
}

View File

@@ -20,14 +20,14 @@ import (
"os"
"github.com/golang/glog"
"github.com/kubernetes-sigs/kustomize/pkg/commands"
"sigs.k8s.io/kustomize/internal/k8sdeps"
"sigs.k8s.io/kustomize/pkg/commands"
)
func main() {
defer glog.Flush()
if err := commands.NewDefaultCommand().Execute(); err != nil {
if err := commands.NewDefaultCommand(k8sdeps.NewFactory()).Execute(); err != nil {
os.Exit(1)
}
os.Exit(0)

View File

@@ -1,342 +0,0 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package app
import (
"encoding/base64"
"reflect"
"testing"
"github.com/kubernetes-sigs/kustomize/pkg/constants"
"github.com/kubernetes-sigs/kustomize/pkg/fs"
"github.com/kubernetes-sigs/kustomize/pkg/internal/loadertest"
"github.com/kubernetes-sigs/kustomize/pkg/loader"
"github.com/kubernetes-sigs/kustomize/pkg/resmap"
"github.com/kubernetes-sigs/kustomize/pkg/resource"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)
const (
kustomizationContent1 = `
namePrefix: foo-
namespace: ns1
commonLabels:
app: nginx
commonAnnotations:
note: This is a test annotation
resources:
- deployment.yaml
- namespace.yaml
configMapGenerator:
- name: literalConfigMap
literals:
- DB_USERNAME=admin
- DB_PASSWORD=somepw
secretGenerator:
- name: secret
commands:
DB_USERNAME: "printf admin"
DB_PASSWORD: "printf somepw"
type: Opaque
`
deploymentContent = `apiVersion: apps/v1
metadata:
name: dply1
kind: Deployment
`
namespaceContent = `apiVersion: v1
kind: Namespace
metadata:
name: ns1
`
)
func makeLoader1(t *testing.T) loader.Loader {
ldr := loadertest.NewFakeLoader("/testpath")
err := ldr.AddFile("/testpath/"+constants.KustomizationFileName, []byte(kustomizationContent1))
if err != nil {
t.Fatalf("Failed to setup fake ldr.")
}
err = ldr.AddFile("/testpath/deployment.yaml", []byte(deploymentContent))
if err != nil {
t.Fatalf("Failed to setup fake ldr.")
}
err = ldr.AddFile("/testpath/namespace.yaml", []byte(namespaceContent))
if err != nil {
t.Fatalf("Failed to setup fake ldr.")
}
return ldr
}
var deploy = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}
var cmap = schema.GroupVersionKind{Version: "v1", Kind: "ConfigMap"}
var secret = schema.GroupVersionKind{Version: "v1", Kind: "Secret"}
var ns = schema.GroupVersionKind{Version: "v1", Kind: "Namespace"}
var svc = schema.GroupVersionKind{Version: "v1", Kind: "Service"}
func TestResources1(t *testing.T) {
expected := resmap.ResMap{
resource.NewResIdWithPrefixNamespace(deploy, "dply1", "foo-", "ns1"): resource.NewResourceFromMap(
map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
"name": "foo-dply1",
"namespace": "ns1",
"labels": map[string]interface{}{
"app": "nginx",
},
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
},
"spec": map[string]interface{}{
"selector": map[string]interface{}{
"matchLabels": map[string]interface{}{
"app": "nginx",
},
},
"template": map[string]interface{}{
"metadata": map[string]interface{}{
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
"labels": map[string]interface{}{
"app": "nginx",
},
},
},
},
}),
resource.NewResIdWithPrefixNamespace(cmap, "literalConfigMap", "foo-", "ns1"): resource.NewResourceFromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "foo-literalConfigMap-mc92bgcbh5",
"namespace": "ns1",
"labels": map[string]interface{}{
"app": "nginx",
},
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
"creationTimestamp": nil,
},
"data": map[string]interface{}{
"DB_USERNAME": "admin",
"DB_PASSWORD": "somepw",
},
}).SetBehavior(resource.BehaviorCreate),
resource.NewResIdWithPrefixNamespace(secret, "secret", "foo-", "ns1"): resource.NewResourceFromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "foo-secret-877fcfhgt5",
"namespace": "ns1",
"labels": map[string]interface{}{
"app": "nginx",
},
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
"creationTimestamp": nil,
},
"type": string(corev1.SecretTypeOpaque),
"data": map[string]interface{}{
"DB_USERNAME": base64.StdEncoding.EncodeToString([]byte("admin")),
"DB_PASSWORD": base64.StdEncoding.EncodeToString([]byte("somepw")),
},
}).SetBehavior(resource.BehaviorCreate),
resource.NewResIdWithPrefixNamespace(ns, "ns1", "foo-", ""): resource.NewResourceFromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": map[string]interface{}{
"name": "foo-ns1",
"labels": map[string]interface{}{
"app": "nginx",
},
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
},
}),
}
l := makeLoader1(t)
fakeFs := fs.MakeFakeFS()
fakeFs.Mkdir("/")
app, err := NewApplication(l, fakeFs)
if err != nil {
t.Fatalf("Unexpected construction error %v", err)
}
actual, err := app.MakeCustomizedResMap()
if err != nil {
t.Fatalf("Unexpected Resources error %v", err)
}
if !reflect.DeepEqual(actual, expected) {
err = expected.ErrorIfNotEqual(actual)
t.Fatalf("unexpected inequality: %v", err)
}
}
func TestRawResources1(t *testing.T) {
expected := resmap.ResMap{
resource.NewResId(deploy, "dply1"): resource.NewResourceFromMap(
map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
"name": "dply1",
},
}),
resource.NewResId(ns, "ns1"): resource.NewResourceFromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": map[string]interface{}{
"name": "ns1",
},
}),
}
l := makeLoader1(t)
app, err := NewApplication(l, fs.MakeFakeFS())
if err != nil {
t.Fatalf("Unexpected construction error %v", err)
}
actual, err := app.MakeUncustomizedResMap()
if err != nil {
t.Fatalf("Unexpected RawResources error %v", err)
}
if err := expected.ErrorIfNotEqual(actual); err != nil {
t.Fatalf("unexpected inequality: %v", err)
}
}
const (
kustomizationContentBase = `
namePrefix: foo-
commonLabels:
app: banana
resources:
- deployment.yaml
`
kustomizationContentOverlay = `
commonLabels:
env: staging
resources:
- service.yaml
bases:
- base
`
serviceContent = `apiVersion: v1
kind: Service
metadata:
name: svc
spec:
type: LoadBalancer
`
)
func makeLoader2(t *testing.T) loader.Loader {
ldr := loadertest.NewFakeLoader("/testpath")
err := ldr.AddFile("/testpath/"+constants.KustomizationFileName, []byte(kustomizationContentOverlay))
if err != nil {
t.Fatal(err)
}
err = ldr.AddFile("/testpath/service.yaml", []byte(serviceContent))
if err != nil {
t.Fatalf("Failed to setup fake ldr.")
}
err = ldr.AddDirectory("/testpath/base")
if err != nil {
t.Fatalf("Failed to setup fake ldr.")
}
err = ldr.AddFile("/testpath/base/"+constants.KustomizationFileName, []byte(kustomizationContentBase))
if err != nil {
t.Fatalf("Failed to setup fake ldr.")
}
err = ldr.AddFile("/testpath/base/deployment.yaml", []byte(deploymentContent))
if err != nil {
t.Fatalf("Failed to setup fake ldr.")
}
return ldr
}
// TODO: This test covers incorrect behavior; it should not pass.
// It asks for raw resources. The Service resource is returned in raw form,
// but the resources in the base are modified to have the banana label,
// the 'foo' name prefix, etc. This method exists only to support the
// diff command comparing customized to non-customized resources;
// perhaps it's not worth supporting the command.
func TestRawResources2(t *testing.T) {
expected := resmap.ResMap{
resource.NewResIdWithPrefix(deploy, "dply1", "foo-"): resource.NewResourceFromMap(
map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
"name": "foo-dply1",
"labels": map[string]interface{}{
"app": "banana",
},
},
"spec": map[string]interface{}{
"selector": map[string]interface{}{
"matchLabels": map[string]interface{}{
"app": "banana",
},
},
"template": map[string]interface{}{
"metadata": map[string]interface{}{
"labels": map[string]interface{}{
"app": "banana",
},
},
},
},
}),
resource.NewResId(svc, "svc"): resource.NewResourceFromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Service",
"metadata": map[string]interface{}{
"name": "svc",
},
"spec": map[string]interface{}{
"type": "LoadBalancer",
},
}),
}
l := makeLoader2(t)
app, err := NewApplication(l, fs.MakeFakeFS())
if err != nil {
t.Fatalf("Unexpected construction error %v", err)
}
actual, err := app.MakeUncustomizedResMap()
if err != nil {
t.Fatalf("Unexpected RawResources error %v", err)
}
if err := expected.ErrorIfNotEqual(actual); err != nil {
t.Fatalf("unexpected inequality: %v", err)
}
}

View File

@@ -1,112 +0,0 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package commands
import (
"io"
"path/filepath"
"github.com/spf13/cobra"
"errors"
"github.com/kubernetes-sigs/kustomize/pkg/app"
"github.com/kubernetes-sigs/kustomize/pkg/constants"
"github.com/kubernetes-sigs/kustomize/pkg/fs"
"github.com/kubernetes-sigs/kustomize/pkg/loader"
)
type buildOptions struct {
kustomizationPath string
outputPath string
}
// newCmdBuild creates a new build command.
func newCmdBuild(out io.Writer, fs fs.FileSystem) *cobra.Command {
var o buildOptions
cmd := &cobra.Command{
Use: "build [path]",
Short: "Print current configuration per contents of " + constants.KustomizationFileName,
Example: "Use the file somedir/" + constants.KustomizationFileName +
" to generate a set of api resources:\nbuild somedir/",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
err := o.Validate(args)
if err != nil {
return err
}
return o.RunBuild(out, fs)
},
}
cmd.Flags().StringVarP(
&o.outputPath,
"output", "o", "",
"If specified, write the build output to this path.")
return cmd
}
// Validate validates build command.
func (o *buildOptions) Validate(args []string) error {
if len(args) > 1 {
return errors.New("specify one path to " + constants.KustomizationFileName)
}
if len(args) == 0 {
o.kustomizationPath = "./"
return nil
}
o.kustomizationPath = args[0]
return nil
}
// RunBuild runs build command.
func (o *buildOptions) RunBuild(out io.Writer, fSys fs.FileSystem) error {
l := loader.NewFileLoader(fSys)
absPath, err := filepath.Abs(o.kustomizationPath)
if err != nil {
return err
}
rootLoader, err := l.New(absPath)
if err != nil {
return err
}
application, err := app.NewApplication(rootLoader, fSys)
if err != nil {
return err
}
allResources, err := application.MakeCustomizedResMap()
if err != nil {
return err
}
// Output the objects.
res, err := allResources.EncodeAsYaml()
if err != nil {
return err
}
if o.outputPath != "" {
return fSys.WriteFile(o.outputPath, res)
}
_, err = out.Write(res)
return err
}

170
pkg/commands/build/build.go Normal file
View File

@@ -0,0 +1,170 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package build
import (
"io"
"strings"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/pkg/constants"
"sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/ifc/transformer"
"sigs.k8s.io/kustomize/pkg/loader"
"sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/target"
"sigs.k8s.io/kustomize/pkg/transformers/config"
)
type buildOptions struct {
kustomizationPath string
outputPath string
transformerconfigPaths []string
}
var examples = `
Use the file somedir/kustomization.yaml to generate a set of api resources:
build somedir
Use a url pointing to a remote directory/kustomization.yaml to generate a set of api resources:
build url
The url should follow hashicorp/go-getter URL format described in
https://github.com/hashicorp/go-getter#url-format
url examples:
sigs.k8s.io/kustomize//examples/multibases?ref=v1.0.6
github.com/Liujingfang1/mysql
github.com/Liujingfang1/kustomize//examples/helloWorld?ref=repoUrl2
Advanced usage:
Use different transformer configurations by passing files to kustomize
build somedir -t someconfigdir
build somedir -t some-transformer-configfile,another-transformer-configfile
`
// NewCmdBuild creates a new build command.
func NewCmdBuild(
out io.Writer, fs fs.FileSystem,
rf *resmap.Factory,
ptf transformer.Factory) *cobra.Command {
var o buildOptions
var p string
cmd := &cobra.Command{
Use: "build [path]",
Short: "Print current configuration per contents of " + constants.KustomizationFileName,
Example: examples,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
err := o.Validate(args, p, fs)
if err != nil {
return err
}
return o.RunBuild(out, fs, rf, ptf)
},
}
cmd.Flags().StringVarP(
&o.outputPath,
"output", "o", "",
"If specified, write the build output to this path.")
cmd.Flags().StringVarP(
&p,
"transformer-config", "t", "",
"If specified, use the transformer configs load from these files.")
return cmd
}
// Validate validates build command.
func (o *buildOptions) Validate(args []string, p string, fs fs.FileSystem) error {
if len(args) > 1 {
return errors.New("specify one path to " + constants.KustomizationFileName)
}
if len(args) == 0 {
o.kustomizationPath = "./"
return nil
}
o.kustomizationPath = args[0]
if p == "" {
return nil
}
if fs.IsDir(p) {
paths, err := fs.Glob(p + "/*")
if err != nil {
return err
}
o.transformerconfigPaths = paths
} else {
o.transformerconfigPaths = strings.Split(p, ",")
}
return nil
}
// RunBuild runs build command.
func (o *buildOptions) RunBuild(
out io.Writer, fSys fs.FileSystem,
rf *resmap.Factory,
ptf transformer.Factory) error {
rootLoader, err := loader.NewLoader(o.kustomizationPath, "", fSys)
if err != nil {
return err
}
tc, err := makeTransformerconfig(fSys, o.transformerconfigPaths)
if err != nil {
return err
}
defer rootLoader.Cleanup()
kt, err := target.NewKustTarget(
rootLoader, fSys,
rf,
ptf, tc)
if err != nil {
return err
}
allResources, err := kt.MakeCustomizedResMap()
if err != nil {
return err
}
// Output the objects.
res, err := allResources.EncodeAsYaml()
if err != nil {
return err
}
if o.outputPath != "" {
return fSys.WriteFile(o.outputPath, res)
}
_, err = out.Write(res)
return err
}
// makeTransformerConfig returns a complete TransformerConfig object from either files
// or the default configs
func makeTransformerconfig(
fSys fs.FileSystem, paths []string) (*config.TransformerConfig, error) {
if paths == nil || len(paths) == 0 {
return config.NewFactory(nil).DefaultConfig(), nil
}
ldr, err := loader.NewLoader(".", "", fSys)
if err != nil {
return nil, errors.Wrap(
err, "cannot create transformer configuration loader")
}
return config.NewFactory(ldr).FromFiles(paths)
}

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package commands
package build
import (
"bytes"
@@ -26,10 +26,10 @@ import (
"testing"
"github.com/ghodss/yaml"
"github.com/kubernetes-sigs/kustomize/pkg/constants"
"github.com/kubernetes-sigs/kustomize/pkg/fs"
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/kustomize/internal/k8sdeps"
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
"sigs.k8s.io/kustomize/pkg/constants"
"sigs.k8s.io/kustomize/pkg/fs"
)
type buildTestCase struct {
@@ -56,7 +56,7 @@ func TestBuildValidate(t *testing.T) {
}
for _, mycase := range cases {
opts := buildOptions{}
e := opts.Validate(mycase.args)
e := opts.Validate(mycase.args, "", nil)
if len(mycase.erMsg) > 0 {
if e == nil {
t.Errorf("%s: Expected an error %v", mycase.name, mycase.erMsg)
@@ -81,7 +81,7 @@ func TestBuild(t *testing.T) {
updateKustomizeExpected := os.Getenv(updateEnvVar) == "true"
fSys := fs.MakeRealFS()
testcases := sets.NewString()
var testcases []string
filepath.Walk("testdata", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
@@ -92,19 +92,22 @@ func TestBuild(t *testing.T) {
name := filepath.Base(path)
if info.IsDir() {
if strings.HasPrefix(name, "testcase-") {
testcases.Insert(strings.TrimPrefix(name, "testcase-"))
testcases = append(testcases, strings.TrimPrefix(name, "testcase-"))
}
return filepath.SkipDir
}
return nil
})
// sanity check that we found the right folder
if !testcases.Has("simple") {
if !kustfile.StringInSlice("simple", testcases) {
t.Fatalf("Error locating testcases")
}
for _, testcaseName := range testcases.List() {
t.Run(testcaseName, func(t *testing.T) { runBuildTestCase(t, testcaseName, updateKustomizeExpected, fSys) })
for _, testcaseName := range testcases {
t.Run(testcaseName,
func(t *testing.T) {
runBuildTestCase(t, testcaseName, updateKustomizeExpected, fSys)
})
}
}
@@ -125,7 +128,11 @@ func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected
kustomizationPath: testcase.Filename,
}
buf := bytes.NewBuffer([]byte{})
err = ops.RunBuild(buf, fSys)
f := k8sdeps.NewFactory()
err = ops.RunBuild(
buf, fSys,
f.ResmapF,
f.TransformerF)
switch {
case err != nil && len(testcase.ExpectedError) == 0:
t.Errorf("unexpected error: %v", err)
@@ -145,7 +152,7 @@ func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected
t.Errorf("unexpected error: %v", err)
}
if !reflect.DeepEqual(actualBytes, expectedBytes) {
t.Errorf("%s\ndoesn't equal expected:\n%s\n", actualBytes, expectedBytes)
t.Errorf("\n**** Actual:\n\n%s\n\n**** doesn't equal expected:\n\n%s\n\n", actualBytes, expectedBytes)
}
} else {
ioutil.WriteFile(testcase.ExpectedStdout, actualBytes, 0644)

View File

@@ -6,7 +6,6 @@ data:
kind: ConfigMap
metadata:
annotations: {}
creationTimestamp: null
labels: {}
name: p1-com1-dhbbm922gd
---
@@ -16,6 +15,5 @@ data:
kind: ConfigMap
metadata:
annotations: {}
creationTimestamp: null
labels: {}
name: p2-com2-c4b8md75k9

View File

@@ -5,13 +5,6 @@ kind: Secret
metadata:
name: test-crdsecret
---
apiVersion: v1beta1
kind: Bee
metadata:
name: test-bee
spec:
action: fly
---
apiVersion: jingfang.example.com/v1beta1
kind: MyKind
metadata:
@@ -21,3 +14,10 @@ spec:
name: test-bee
secretRef:
name: test-crdsecret
---
apiVersion: v1beta1
kind: Bee
metadata:
name: test-bee
spec:
action: fly

View File

@@ -0,0 +1,4 @@
resources:
- serviceaccount.yaml
- rolebinding.yaml
namePrefix: base-

View File

@@ -0,0 +1,11 @@
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: role
subjects:
- kind: ServiceAccount
name: serviceaccount

View File

@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: serviceaccount

View File

@@ -0,0 +1,3 @@
bases:
- ../overlays/a
- ../overlays/b

View File

@@ -0,0 +1,7 @@
bases:
- ../../base/
namePrefix: a-
resources:
- serviceaccount.yaml

View File

@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: serviceaccount

View File

@@ -0,0 +1,4 @@
bases:
- ../../base/
namePrefix: b-

View File

@@ -0,0 +1,4 @@
description: multibases with name reference
args: []
filename: testdata/testcase-multibases-conflict/combined
expectedError: detected conflicts when resolving name references serviceaccount

View File

@@ -0,0 +1,4 @@
resources:
- serviceaccount.yaml
- rolebinding.yaml
namePrefix: base-

View File

@@ -0,0 +1,11 @@
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: role
subjects:
- kind: ServiceAccount
name: serviceaccount

View File

@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: serviceaccount

View File

@@ -0,0 +1,3 @@
bases:
- ../overlays/a
- ../overlays/b

View File

@@ -0,0 +1,33 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: a-base-serviceaccount
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: b-base-serviceaccount
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: a-base-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: role
subjects:
- kind: ServiceAccount
name: a-base-serviceaccount
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: b-base-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: role
subjects:
- kind: ServiceAccount
name: b-base-serviceaccount

View File

@@ -0,0 +1,4 @@
bases:
- ../../base/
namePrefix: a-

Some files were not shown because too many files have changed in this diff Show More