Compare commits

...

118 Commits

Author SHA1 Message Date
Natasha Sarkar
fa574866b4 Merge pull request #5165 from natasha41575/pin
pin to kyaml and cmd/config released versions
2023-05-09 14:41:36 -05:00
natasha41575
4b807107a6 pin to kyaml and cmd/config released versions 2023-05-09 14:27:34 -05:00
Kubernetes Prow Robot
6bb62dd6ef Merge pull request #5164 from kubernetes-sigs/revert-4999-fix-same-chart-multiple-versions
Revert "Fix using same helm chart with different versions"
2023-05-09 12:21:54 -07:00
Natasha Sarkar
3d6f40bd5e Revert "Fix using same helm chart with different versions (#4999)"
This reverts commit 0f244a4a07.
2023-05-09 13:16:22 -05:00
Kubernetes Prow Robot
c2bd42e774 Merge pull request #5162 from natasha41575/unpin
unpin everything
2023-05-05 13:53:16 -07:00
natasha41575
529a25d30b unpin everything 2023-05-05 15:38:19 -05:00
Natasha Sarkar
ccdc148472 Merge pull request #5161 from natasha41575/api
pin to api 0.13.3
2023-05-05 15:30:10 -05:00
natasha41575
7dcb2a50ff pin to api 0.13.3 2023-05-05 15:12:27 -05:00
Kubernetes Prow Robot
1e3215226e Merge pull request #5160 from natasha41575/cmdconfig
pin to cmd/config v0.11.2
2023-05-05 13:03:01 -07:00
natasha41575
459d0198d9 pin to cmd/config v0.11.2 2023-05-05 14:49:36 -05:00
Natasha Sarkar
3abf91644e Merge pull request #5159 from natasha41575/pintokyaml
pin to kyaml v0.14.2
2023-05-05 14:44:25 -05:00
natasha41575
1f98338481 pin to kyaml v0.14.2 2023-05-05 14:32:02 -05:00
Kubernetes Prow Robot
5a3e920902 Merge pull request #5157 from KnVerey/update-maintainer-lists
Move inactive contributors to emeritus
2023-05-02 15:12:15 -07:00
Katrina Verey
96f893f350 Move inactive contributors to emeritus 2023-05-02 17:47:32 -04:00
Kubernetes Prow Robot
ee3f506d10 Merge pull request #5145 from SimonTheLeg/deepcopy-for-meta-types
Add DeepCopy for ResourceMeta and ObjectMeta
2023-04-25 18:14:15 -07:00
Dustin Lish
0f244a4a07 Fix using same helm chart with different versions (#4999)
* Fix using same helm chart with different versions

* Fix p.ValuesFile when version is set

* Updated: Fix using same helm chart with different versions

* Add test for issue #4813

* Use if/else for readability, add version check to absChartHome
2023-04-24 15:09:02 -07:00
Simon Bein
c79916b1ba Add DeepCopy for ResourceMeta and ObjectMeta 2023-04-24 20:19:33 +02:00
Kubernetes Prow Robot
2ce1c7cce3 Merge pull request #5133 from timja/issue-5072-non-core-api-version-namespace
Only override name of core api version
2023-04-18 14:40:58 -07:00
Tim Jacomb
75fa235498 Only override name of core api version 2023-04-18 09:41:28 +01:00
Tim Jacomb
7413c6a5fb Regression test 2023-04-18 09:41:28 +01:00
Kubernetes Prow Robot
315ed56450 Merge pull request #5130 from KnVerey/fn-framework-example
Add a rich example of fn framework for abstraction
2023-04-14 12:34:41 -07:00
Katrina Verey
38d5bf8e09 Add licence and make script use current year 2023-04-13 17:45:47 -04:00
Katrina Verey
85d623bc86 Add a rich example of fn framework for abstraction 2023-04-13 16:57:50 -04:00
Kubernetes Prow Robot
d3184da4c6 Merge pull request #5111 from yutaroyamanaka/reenable-skipped-tests
Re-enable tests disabled in #3880
2023-04-05 11:45:48 -07:00
Kubernetes Prow Robot
eadb469712 Merge pull request #4924 from koba1t/chore/set_go_version_on_actions_from_gowork_file
Set go version on github actions from gowork file
2023-04-05 10:17:46 -07:00
yutaroyamanaka
2649d39fd3 docker build locally because gcr.io/kustomize-functions/e2econtainerconfig doesn't exist in the public 2023-04-04 18:22:43 +09:00
yutaroyamanaka
faab836ec9 use test helpers 2023-04-01 23:16:58 +09:00
yutaroyamanaka
c9f500cc0b add another resource for making sure an existing resource isn't affeced by a generator 2023-04-01 23:13:04 +09:00
Yutaro
42bf3c0e2b prevent all uses of YAML aliases from being overwritten by a transformer (#5096)
* return copied Node

* add a test case about imageTagTransformer for anchor scenario

* add TestPatchTransformerAnchor

* TestReplacementTransformerAnchor
2023-03-31 16:07:50 -07:00
Kubernetes Prow Robot
3b395a9da2 Merge pull request #5074 from plobsing/master
Only strip surrounding quotes if there are at least two characters.
2023-03-31 15:11:49 -07:00
Peter Lobsinger
633da991d2 Only strip surrounding quotes if there are at least two characters.
Otherwise, a value consisting of a single quote character triggers a
panic:

    go test krusty/configmaps_test.go
    --- FAIL: TestDataIsSingleQuote (0.00s)
    panic: runtime error: slice bounds out of range [1:0] [recovered]
    	panic: runtime error: slice bounds out of range [1:0]
2023-03-28 14:17:47 -07:00
Kubernetes Prow Robot
e07b8a5d15 Merge pull request #5105 from koba1t/chore/use_enable-all_option_for_golangci-lint
use enable-all on golangci-lint
2023-03-27 14:26:21 -07:00
yutaroyamanaka
71a7a7df13 re-enabled TestFnContainerGenerator with enable-gcp-services 2023-03-27 23:00:24 +09:00
yutaroyamanaka
436a047617 re-enabled TestFnContainerTransformer with e2econtainerconfig container 2023-03-27 21:33:57 +09:00
xin gu
4d70a36c25 emove the kyaml/openapi/kubernetesapi/v1_21_2/swagger.pb (#5077) 2023-03-23 10:48:31 -07:00
koba1t
304d0e951f use enable-all on golangci-lint 2023-03-23 05:54:54 +09:00
Kubernetes Prow Robot
2fdb35614d Merge pull request #5080 from chlunde/perf-2
perf: Intersection: Avoid callid AllIds inside inner loop
2023-03-20 23:03:07 -07:00
Kubernetes Prow Robot
5dff9df1f7 Merge pull request #5099 from justinsb/dont_swallow_helm_errors
Don't swallow helm execution errors
2023-03-20 12:35:09 -07:00
Kubernetes Prow Robot
84682a1159 Merge pull request #5101 from justinsb/fixlint_2
Fix unused error value
2023-03-20 12:23:07 -07:00
justinsb
c151147258 Don't swallow helm execution errors
These are otherwise hard to debug.
2023-03-20 19:14:07 +00:00
justinsb
317fcadccb Fix unused error value
The linter was complaining about err being unchecked.
2023-03-20 19:11:11 +00:00
Kubernetes Prow Robot
a2e9682002 Merge pull request #5100 from justinsb/fixlint
Fix lint task in CI
2023-03-20 10:27:19 -07:00
justinsb
5dcf0ae683 Fix lint task in CI
The lint task was failing at head, due to a nolint:exhaustive error
directive that golangci nolintlint believes is unused.

Issue seems to be https://github.com/golangci/golangci-lint/issues/3228
and seems to be a bug in golang-ci / nolintlint, using the workaround
proposed in https://github.com/golangci/golangci-lint/issues/1940
which is to clear the cache between runs.
2023-03-20 14:14:30 +00:00
Katrina Verey
ce3e394a41 Merge pull request #5091 from KnVerey/unpinEverything
Back to development mode; unpin the modules
2023-03-13 21:58:32 -04:00
Katrina Verey
0c92647760 Back to development mode; unpin the modules 2023-03-13 21:43:46 -04:00
Katrina Verey
39527da73c Merge pull request #5090 from KnVerey/pinToApi
Update api to v0.13.2
2023-03-13 21:20:22 -04:00
Katrina Verey
fa90046136 Update api to v0.13.2 2023-03-13 21:07:40 -04:00
Katrina Verey
efe1374940 Merge pull request #5089 from KnVerey/pinToCmdConfig
Update cmd/config to v0.11.1
2023-03-13 20:49:50 -04:00
Katrina Verey
b751ffe5a0 Update cmd/config to v0.11.1 2023-03-13 20:27:40 -04:00
Katrina Verey
28a2a01c29 Merge pull request #5088 from KnVerey/pinToKyaml
Update kyaml to v0.14.1
2023-03-13 19:45:23 -04:00
Katrina Verey
0c650423ed Update kyaml to v0.14.1 2023-03-13 19:24:20 -04:00
Katrina Verey
4ffc861854 Merge pull request #5087 from KnVerey/prerelease_update
Changes from local test run
2023-03-13 19:11:00 -04:00
Katrina Verey
8338873e56 Changes from local test run 2023-03-13 18:40:16 -04:00
Katrina Verey
dd520f8889 Revert strict decoding of Kustomization due to regression in anchor handling (#5073)
* Revert strict decoding of Kustomization due to regression in anchor handling

* Empty commit
2023-03-13 13:46:47 -07:00
Carl Henrik Lunde
4842d8be60 perf: Intersection: Avoid callid AllIds inside inner loop
This shaves of another 8.5 seconds (one third) of the remaining execution
time for a kustomization tree with 4000 documents, reducing the execution
time from 27.46s to 18.94s

     0.02s 0.062% 11.14%      8.45s 26.36%  sigs.k8s.io/kustomize/api/internal/accumulator.(*ResAccumulator).Intersection
     0.06s  0.19% 11.32%      8.32s 25.95%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).AllIds

before

    (pprof) top25 -cum
    Showing nodes accounting for 3.63s, 11.32% of 32.06s total
    Dropped 614 nodes (cum <= 0.16s)
    Showing top 25 nodes out of 171
        flat  flat%   sum%        cum   cum%
            0     0%     0%     27.46s 85.65%  github.com/spf13/cobra.(*Command).Execute
            0     0%     0%     27.46s 85.65%  github.com/spf13/cobra.(*Command).ExecuteC
            0     0%     0%     27.46s 85.65%  github.com/spf13/cobra.(*Command).execute
            0     0%     0%     27.46s 85.65%  main.main
            0     0%     0%     27.46s 85.65%  runtime.main
            0     0%     0%     27.46s 85.65%  sigs.k8s.io/kustomize/kustomize/v5/commands/build.NewCmdBuild.func1
            0     0%     0%     26.95s 84.06%  sigs.k8s.io/kustomize/api/krusty.(*Kustomizer).Run
            0     0%     0%     22.09s 68.90%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).MakeCustomizedResMap (inline)
            0     0%     0%     22.09s 68.90%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).makeCustomizedResMap
        0.29s   0.9%   0.9%     20.96s 65.38%  sigs.k8s.io/kustomize/api/resource.(*Resource).CurId
            0     0%   0.9%     13.61s 42.45%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).Append
            0     0%   0.9%     13.60s 42.42%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).GetMatchingResourcesByCurrentId (partial-inline)
        0.14s  0.44%  1.34%     13.60s 42.42%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).filteredById
        0.05s  0.16%  1.50%     12.91s 40.27%  sigs.k8s.io/kustomize/api/resmap.GetCurrentId
        0.25s  0.78%  2.28%     12.48s 38.93%  sigs.k8s.io/kustomize/api/resource.(*Resource).GetGvk (inline)
        0.49s  1.53%  3.81%     12.23s 38.15%  sigs.k8s.io/kustomize/kyaml/resid.GvkFromNode
            0     0%  3.81%     11.61s 36.21%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).IgnoreLocal
            0     0%  3.81%     10.47s 32.66%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).AccumulateTarget
            0     0%  3.81%     10.47s 32.66%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateTarget
        0.01s 0.031%  3.84%     10.46s 32.63%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateResources
            0     0%  3.84%     10.43s 32.53%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateDirectory
        0.64s  2.00%  5.83%     10.12s 31.57%  sigs.k8s.io/kustomize/kyaml/yaml.visitMappingNodeFields
        1.68s  5.24% 11.07%      9.48s 29.57%  sigs.k8s.io/kustomize/kyaml/yaml.visitFieldsWhileTrue
        0.02s 0.062% 11.14%      8.45s 26.36%  sigs.k8s.io/kustomize/api/internal/accumulator.(*ResAccumulator).Intersection
        0.06s  0.19% 11.32%      8.32s 25.95%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).AllIds

after

    (pprof) top30 -cum
    Showing nodes accounting for 5.04s, 22.63% of 22.27s total
    Dropped 540 nodes (cum <= 0.11s)
    Showing top 30 nodes out of 209
        flat  flat%   sum%        cum   cum%
            0     0%     0%     18.94s 85.05%  github.com/spf13/cobra.(*Command).Execute
            0     0%     0%     18.94s 85.05%  github.com/spf13/cobra.(*Command).ExecuteC
            0     0%     0%     18.94s 85.05%  github.com/spf13/cobra.(*Command).execute
            0     0%     0%     18.94s 85.05%  main.main
            0     0%     0%     18.94s 85.05%  runtime.main
            0     0%     0%     18.94s 85.05%  sigs.k8s.io/kustomize/kustomize/v5/commands/build.NewCmdBuild.func1
            0     0%     0%     18.40s 82.62%  sigs.k8s.io/kustomize/api/krusty.(*Kustomizer).Run
            0     0%     0%     13.65s 61.29%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).MakeCustomizedResMap (inline)
            0     0%     0%     13.65s 61.29%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).makeCustomizedResMap
            0     0%     0%     13.52s 60.71%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).Append
            0     0%     0%     13.44s 60.35%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).GetMatchingResourcesByCurrentId (inline)
        0.16s  0.72%  0.72%     13.44s 60.35%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).filteredById
        0.04s  0.18%   0.9%     12.54s 56.31%  sigs.k8s.io/kustomize/api/resmap.GetCurrentId
        0.19s  0.85%  1.75%     12.49s 56.08%  sigs.k8s.io/kustomize/api/resource.(*Resource).CurId
            0     0%  1.75%     10.37s 46.56%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).AccumulateTarget
            0     0%  1.75%     10.37s 46.56%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateResources
            0     0%  1.75%     10.37s 46.56%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateTarget
            0     0%  1.75%     10.34s 46.43%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateDirectory
        0.19s  0.85%  2.60%      7.82s 35.11%  sigs.k8s.io/kustomize/api/resource.(*Resource).GetGvk (inline)
        0.42s  1.89%  4.49%      7.63s 34.26%  sigs.k8s.io/kustomize/kyaml/resid.GvkFromNode
        0.26s  1.17%  5.66%      6.01s 26.99%  sigs.k8s.io/kustomize/kyaml/yaml.visitMappingNodeFields
            0     0%  5.66%      5.76s 25.86%  sigs.k8s.io/kustomize/api/internal/accumulator.(*ResAccumulator).MergeAccumulator
        1.12s  5.03% 10.69%      5.75s 25.82%  sigs.k8s.io/kustomize/kyaml/yaml.visitFieldsWhileTrue
            0     0% 10.69%      5.57s 25.01%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).appendAll (inline)
            0     0% 10.69%      5.55s 24.92%  sigs.k8s.io/kustomize/api/internal/accumulator.(*ResAccumulator).AppendAll (inline)
            0     0% 10.69%      5.55s 24.92%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).AppendAll
            0     0% 10.69%      4.73s 21.24%  sigs.k8s.io/kustomize/api/internal/builtins.(*SortOrderTransformerPlugin).Transform
            0     0% 10.69%      4.73s 21.24%  sigs.k8s.io/kustomize/api/krusty.(*Kustomizer).applySortOrder
            0     0% 10.69%      4.72s 21.19%  sigs.k8s.io/kustomize/api/internal/builtins.applyOrdering
        2.66s 11.94% 22.63%      4.63s 20.79%  sigs.k8s.io/kustomize/kyaml/yaml.visitMappingNodeFields.func2
2023-03-12 15:50:11 +01:00
Kubernetes Prow Robot
bf6e6ad33b Merge pull request #5085 from koba1t/chore/update_golangci_to_1.51.2
update golangci-lint to v1.51.2
2023-03-10 14:28:39 -08:00
koba1t
e1094da3cf skip unrelevant lint 2023-03-11 05:11:47 +09:00
koba1t
7d150ce973 Revert "use enable-all on golangci-lint"
This reverts commit 39264a7057.
2023-03-11 05:08:25 +09:00
koba1t
39264a7057 use enable-all on golangci-lint 2023-03-09 05:25:19 +09:00
koba1t
736e166168 update golangci-lint to 1.51.2 2023-03-09 05:08:25 +09:00
Kubernetes Prow Robot
e8b521e3ab Merge pull request #5053 from kubernetes-sigs/dependabot/go_modules/functions/examples/application-cr/image/golang.org/x/net-0.7.0
Bump golang.org/x/net from 0.4.0 to 0.7.0 in /functions/examples/application-cr/image
2023-02-28 11:33:16 -08:00
dependabot[bot]
a4954d386a Bump golang.org/x/net in /functions/examples/application-cr/image
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.4.0 to 0.7.0.
- [Release notes](https://github.com/golang/net/releases)
- [Commits](https://github.com/golang/net/compare/v0.4.0...v0.7.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-27 18:17:11 +00:00
Kubernetes Prow Robot
976193ce70 Merge pull request #5054 from kubernetes-sigs/dependabot/go_modules/cmd/depprobcheck/golang.org/x/net-0.7.0
Bump golang.org/x/net from 0.4.0 to 0.7.0 in /cmd/depprobcheck
2023-02-27 10:08:39 -08:00
dependabot[bot]
ee0b26601b Bump golang.org/x/net from 0.4.0 to 0.7.0 in /cmd/depprobcheck
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.4.0 to 0.7.0.
- [Release notes](https://github.com/golang/net/releases)
- [Commits](https://github.com/golang/net/compare/v0.4.0...v0.7.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-27 16:35:34 +00:00
Kubernetes Prow Robot
78e310231e Merge pull request #5065 from kubernetes-sigs/dependabot/go_modules/cmd/depprobcheck/golang.org/x/crypto-0.1.0
Bump golang.org/x/crypto from 0.0.0-20210921155107-089bfa567519 to 0.1.0 in /cmd/depprobcheck
2023-02-27 08:34:38 -08:00
Kubernetes Prow Robot
ffa554b371 Merge pull request #5064 from kubernetes-sigs/dependabot/go_modules/functions/examples/application-cr/image/golang.org/x/crypto-0.1.0
Bump golang.org/x/crypto from 0.0.0-20210921155107-089bfa567519 to 0.1.0 in /functions/examples/application-cr/image
2023-02-27 08:26:39 -08:00
dependabot[bot]
68a0fc95da Bump golang.org/x/crypto in /cmd/depprobcheck
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.0.0-20210921155107-089bfa567519 to 0.1.0.
- [Release notes](https://github.com/golang/crypto/releases)
- [Commits](https://github.com/golang/crypto/commits/v0.1.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-25 03:30:10 +00:00
dependabot[bot]
9b43e76947 Bump golang.org/x/crypto in /functions/examples/application-cr/image
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.0.0-20210921155107-089bfa567519 to 0.1.0.
- [Release notes](https://github.com/golang/crypto/releases)
- [Commits](https://github.com/golang/crypto/commits/v0.1.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-25 00:50:47 +00:00
Kubernetes Prow Robot
adf760e246 Merge pull request #5058 from ephesused/optimize-gvk-version
perf: optimize Gvk.ApiVersion()
2023-02-21 11:57:56 -08:00
Kubernetes Prow Robot
7a89df8350 Merge pull request #5048 from cailynse/issue-5039
Remove Log Assignment to Stdout
2023-02-21 11:23:56 -08:00
Ed Overton
93d7511b38 perf: optimize Gvk.ApiVersion()
Convert Gvk.ApiVersion() from using strings.Builder to raw string
concatenation. The logic in Gvk.ApiVersion() is simple enough that
raw concatenation executes quicker and consumes less memory.
2023-02-21 11:02:57 -05:00
Cailyn Edwards
7c33fe30b7 Remove Log Assignment to Stdout 2023-02-21 10:53:22 -05:00
Kubernetes Prow Robot
22dbd3eb17 Merge pull request #5038 from KnVerey/unpin-modules
Update all modules to latest releases, but unpinned
2023-02-08 11:08:44 -08:00
Katrina Verey
51e2714408 Back to development mode; unpin the modules 2023-02-07 19:56:39 -05:00
Katrina Verey
d825beff27 Update all modules to latest releases 2023-02-07 19:56:11 -05:00
Katrina Verey
aa4eb59bb0 Fix constant reference in instructions 2023-02-07 19:54:58 -05:00
Katrina Verey
00d450cce7 Revert plugin exclusion to name sanity check 2023-02-07 19:47:21 -05:00
Kubernetes Prow Robot
a090ceac6c Merge pull request #5026 from KnVerey/update_releasing_instr
Update releasing workflow
2023-02-07 13:14:58 -08:00
Katrina Verey
63c37b1780 Update releasing/README.md
Co-authored-by: Cailyn <cailyn.s.e@gmail.com>
2023-02-06 16:49:19 -05:00
Kubernetes Prow Robot
0fd385d719 Merge pull request #4946 from researchapps/add/github-token-install
add GitHub token to install_kustomize.sh
2023-02-02 13:58:42 -08:00
Katrina Verey
57d8583887 Fix lint errors 2023-02-02 14:25:20 -05:00
Katrina Verey
9c116e9031 Bespoke mod edits no longer needed if gorepomod pins all modules 2023-02-02 14:23:23 -05:00
Katrina Verey
e6c16a6ddc Restore previous test-go-mod and commit changes 2023-02-02 14:20:13 -05:00
Katrina Verey
03669a1804 Improve error message and fix typo in iampolicygenerator module name 2023-02-02 14:15:40 -05:00
vsoch
3c44db8746 add GitHub token to install_kustomize.sh
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
2023-02-02 12:08:20 -07:00
Katrina Verey
9a1a203b52 Update example targets 2023-02-02 12:28:37 -05:00
Katrina Verey
8b51c295a1 Allow gorepomod to update plugin mod files 2023-02-02 11:33:46 -05:00
Kubernetes Prow Robot
738ca56ccd Merge pull request #5027 from KnVerey/remove-replaces
Remove leftover replace statements
2023-02-02 08:32:41 -08:00
Katrina Verey
f901b4a5fd Remove leftover replace statements 2023-02-02 11:23:00 -05:00
Katrina Verey
4fff8399ea Update releasing instructions 2023-02-02 11:22:00 -05:00
Katrina Verey
e532d6f1a1 Merge pull request #5025 from KnVerey/pinToApi
Update api to v0.13.1
2023-02-02 10:58:41 -05:00
Katrina Verey
db2a3800ed Update api to v0.13.1 2023-02-02 10:45:39 -05:00
Kubernetes Prow Robot
183928e6ba Merge pull request #5023 from KnVerey/issue4998
Fix regression with scp-style urls with only one path element
2023-02-01 23:41:29 -08:00
Katrina Verey
c0e2030905 Fix regression with scp-style urls with only one path element 2023-02-01 22:19:40 -05:00
Kubernetes Prow Robot
87c428e7cd Merge pull request #5021 from KnVerey/module_version_v5
Bump kustomize module to v5
2023-02-01 17:03:29 -08:00
Katrina Verey
f5ad795995 Bump kustomize module to v5 2023-02-01 19:01:08 -05:00
Kubernetes Prow Robot
f851cc7181 Merge pull request #5020 from KnVerey/pinToCmdConfig
Pin to cmd config
2023-02-01 14:39:36 -08:00
Katrina Verey
7e3ad53890 Allow cloud build to authenticate to gh when generating changelog 2023-02-01 17:25:57 -05:00
Katrina Verey
5cdc080406 Update cmd/config to v0.11.0 2023-02-01 17:22:46 -05:00
Katrina Verey
10fb04cdf2 Merge pull request #5019 from KnVerey/pinToKyaml
Update kyaml to v0.14.0
2023-02-01 17:09:20 -05:00
Katrina Verey
ea8fc77f2f Update kyaml in the secondary modules 2023-02-01 16:55:56 -05:00
Katrina Verey
e9507c940d Update kyaml to v0.14.0 2023-02-01 16:44:34 -05:00
Katrina Verey
bea105d793 Merge pull request #5017 from KnVerey/fix-changelog-unauthed
Don't have empty string when no auth info
2023-02-01 16:30:39 -05:00
Katrina Verey
e4d7eaa479 Don't have empty string when no auth info 2023-02-01 16:28:20 -05:00
Kubernetes Prow Robot
85949329b8 Merge pull request #5015 from KnVerey/changelog-auth
Allow authenticated Github use in changelog script and improve error messages
2023-02-01 12:59:36 -08:00
Katrina Verey
0c34cf4192 Allow authenticated Github use in changelog script and improve error messages 2023-02-01 15:39:38 -05:00
Cailyn
95edcc0681 Update Versioning to Improve Output (#5000)
* Update Versioning to Improve Output

* Always get commit from build info, always get date and version from ldflag

* Just replace broken main output with semver and deprecate short flag as is

---------

Co-authored-by: Katrina Verey <katrina.verey@shopify.com>
2023-02-01 11:25:37 -08:00
Anna Song
9d8ed39d3d Localize helm additionValuesFiles (#5013) 2023-02-01 10:39:20 -08:00
Natasha Sarkar
1957d5c746 support for more helm template args (#4926)
* support for more helm template args

* move templateArgs and unit tests to api/types

* undo package name change

* use our own simple helm chart instead of forking one

* add argument to AsHelmArgs

* code review

* lint errors
2023-02-01 10:19:05 -08:00
Anna Song
236166097e Add localize command handle (#4959)
* Add localize command handle

* Align to kustomize command conventions

* Print success msg
2023-02-01 08:11:07 -08:00
Kubernetes Prow Robot
3370177b9d Merge pull request #5012 from natasha41575/reponotfileerr
make TestResourcesRepoNotFile even less specific
2023-01-31 11:16:50 -08:00
natasha41575
c8b112c79f make TestResourcesRepoNotFile even less specific 2023-01-31 12:58:55 -06:00
Katrina Verey
d91e31cf18 Run test-go-mod unpinned (#5011)
* Remove go module ci job

* Add script that runs go mod tidy with replace statements

* Invoke one script from the makefile and pass in the command to run in the pinned context

---------

Co-authored-by: Anna Song <annasong@google.com>
2023-01-31 09:56:48 -08:00
Kubernetes Prow Robot
00b0bd8473 Merge pull request #5010 from annasong20/expose-localize-dst
Expose path to `localize` destination
2023-01-30 18:36:48 -08:00
Anna Song
e2aff13587 Expose path to localize destination 2023-01-30 15:42:58 -08:00
Anna Song
361154dabc Localize HelmChartInflationGenerator (#5007)
* Localize HelmChartInflationGenerator

* Add explicit inline generators test
2023-01-30 13:16:48 -08:00
Kubernetes Prow Robot
7db330d2cc Merge pull request #5009 from kubernetes-sigs/no-partial-releases
Warn against partial releases
2023-01-30 13:04:49 -08:00
yugo kobayashi
ffd45f6893 Set go version on github actions from gowork file 2022-12-09 18:14:09 +00:00
246 changed files with 3615 additions and 15814 deletions

View File

@@ -10,26 +10,21 @@ permissions:
contents: read
jobs:
lint:
name: Lint
runs-on: [ubuntu-latest]
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: '^1.19.0'
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version-file: go.work
id: go
- name: Lint
run: make lint
- name: Verify boilerplate
run: make check-license
@@ -37,66 +32,56 @@ jobs:
name: Test Linux
runs-on: [ubuntu-latest]
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: '^1.19.0'
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Test all modules
run: make test-unit-non-plugin
env:
KUSTOMIZE_DOCKER_E2E: true
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version-file: go.work
id: go
- name: Test all modules
run: make test-unit-non-plugin
env:
KUSTOMIZE_DOCKER_E2E: true
test-macos:
name: Test MacOS
runs-on: [macos-latest]
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: '^1.19.0'
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Test all modules
run: make test-unit-non-plugin
env:
KUSTOMIZE_DOCKER_E2E: false # docker not installed on mac
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version-file: go.work
id: go
- name: Test all modules
run: make test-unit-non-plugin
env:
KUSTOMIZE_DOCKER_E2E: false # docker not installed on mac
test-windows:
name: Test Windows
runs-on: [windows-latest]
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version-file: go.work
id: go
- name: Test kyaml
run: go test -cover ./...
working-directory: ./kyaml
- name: Test cmd/config
run: go test -cover ./...
working-directory: ./cmd/config
env:
KUSTOMIZE_DOCKER_E2E: false # docker on windows not working well yet
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: '^1.19.0'
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Test kyaml
run: go test -cover ./...
working-directory: ./kyaml
- name: Test cmd/config
run: go test -cover ./...
working-directory: ./cmd/config
env:
KUSTOMIZE_DOCKER_E2E: false # docker on windows not working well yet
# TODO (#4001): replace specific modules above with this once Windows tests are passing.
#- name: Test all modules
# run: make test-unit-non-plugin
# env:
# KUSTOMIZE_DOCKER_E2E: false # docker on windows not working well yet
# TODO (#4001): replace specific modules above with this once Windows tests are passing.
#- name: Test all modules
# run: make test-unit-non-plugin
# env:
# KUSTOMIZE_DOCKER_E2E: false # docker on windows not working well yet

View File

@@ -6,93 +6,34 @@ run:
go: '1.19'
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- asciicheck
- bidichk
- bodyclose
- contextcheck
# - cyclop
- depguard
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- errname
- errorlint
- exhaustive
# - exhaustivestruct
- exportloopref
# - forbidigo
- forcetypeassert
# - funlen
# - gci
- gochecknoglobals
- gochecknoinits
# - gocognit
- goconst
- gocritic
- gocyclo
# - godot
# - godox
# - goerr113
- gofmt
# - gofumpt
- goheader
- goimports
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
# - ifshort # too many false positives
- importas
- ineffassign
# - ireturn
- lll
- makezero
- misspell
- nakedret
- nestif
- nilerr
# - nilnil
# - nlreturn
# - noctx
- nolintlint
# - paralleltest
- prealloc
- predeclared
- promlinter
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
# - stylecheck
- tagliatelle
- tenv
- testpackage
- testableexamples
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
# - varnamelen
- wastedassign
- whitespace
- wrapcheck
# - wsl
- asasalint
- usestdlibvars
- interfacebloat
- loggercheck
- reassign
enable-all: true
disable:
- cyclop
- exhaustivestruct
- forbidigo
- funlen
- gci
- gocognit
- godot
- godox
- goerr113
- gofumpt
- ifshort # too many false positives
- ireturn
- nilnil
- nlreturn
- noctx
- paralleltest
- stylecheck
- varnamelen
- wsl
- exhaustruct
- deadcode
- scopelint
- nonamedreturns
- golint
- maintidx
- nosnakecase
linters-settings:
dupl:
@@ -110,6 +51,7 @@ linters-settings:
gomnd:
ignored-functions:
- os.WriteFile
- make
gomoddirectives:
replace-local: true
gosec:

View File

@@ -3,7 +3,7 @@
#
# Makefile for kustomize CLI and API.
LATEST_V4_RELEASE=v4.5.6
LATEST_RELEASE=v5.0.1
SHELL := /usr/bin/env bash
GOOS = $(shell go env GOOS)
@@ -75,7 +75,8 @@ $(MYGOBIN)/pluginator:
# Build from local source.
$(MYGOBIN)/kustomize: build-kustomize-api
cd kustomize; \
go install .
go install -ldflags "-X sigs.k8s.io/kustomize/api/provenance.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')" \
.
kustomize: $(MYGOBIN)/kustomize
@@ -100,7 +101,7 @@ verify-kustomize-repo: \
build-non-plugin-all \
test-go-mod \
test-examples-kustomize-against-HEAD \
test-examples-kustomize-against-v4-release
test-examples-kustomize-against-latest-release
# The following target referenced by a file in
# https://github.com/kubernetes/test-infra/tree/master/config/jobs/kubernetes-sigs/kustomize
@@ -111,7 +112,7 @@ prow-presubmit-check: \
test-go-mod \
build-non-plugin-all \
test-examples-kustomize-against-HEAD \
test-examples-kustomize-against-v4-release
test-examples-kustomize-against-latest-release
.PHONY: license
license: $(MYGOBIN)/addlicense
@@ -133,11 +134,11 @@ test-unit-all: \
# This target is used by our Github Actions CI to run unit tests for all non-plugin modules in multiple GOOS environments.
.PHONY: test-unit-non-plugin
test-unit-non-plugin:
./hack/for-each-module.sh "make test" "./plugin/*" 15
./hack/for-each-module.sh "make test" "./plugin/*" 16
.PHONY: build-non-plugin-all
build-non-plugin-all:
./hack/for-each-module.sh "make build" "./plugin/*" 15
./hack/for-each-module.sh "make build" "./plugin/*" 16
.PHONY: test-unit-kustomize-plugins
test-unit-kustomize-plugins:
@@ -152,7 +153,7 @@ functions-examples-all:
done
test-go-mod:
./hack/for-each-module.sh "go list -m -json all > /dev/null && go mod tidy -v"
./hack/for-each-module.sh "go mod tidy -v"
.PHONY:
verify-kustomize-e2e: $(MYGOBIN)/mdrip $(MYGOBIN)/kind
@@ -169,8 +170,8 @@ test-examples-kustomize-against-HEAD: $(MYGOBIN)/kustomize $(MYGOBIN)/mdrip
./hack/testExamplesAgainstKustomize.sh HEAD
.PHONY:
test-examples-kustomize-against-v4-release: $(MYGOBIN)/mdrip
./hack/testExamplesAgainstKustomize.sh v4@$(LATEST_V4_RELEASE)
test-examples-kustomize-against-latest-release: $(MYGOBIN)/mdrip
./hack/testExamplesAgainstKustomize.sh v5@$(LATEST_RELEASE)
# --- Cleanup targets ---

View File

@@ -14,6 +14,7 @@ include $(KUSTOMIZE_ROOT)/Makefile-tools.mk
.PHONY: lint test fix fmt tidy vet build
lint: $(MYGOBIN)/golangci-lint
$(MYGOBIN)/golangci-lint cache clean # Workaround for https://github.com/golangci/golangci-lint/issues/3228
$(MYGOBIN)/golangci-lint \
-c $$KUSTOMIZE_ROOT/.golangci.yml \
--path-prefix $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\2|') \

View File

@@ -1,7 +1,7 @@
# Copyright 2022 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
GOLANGCI_LINT_VERSION=v1.50.1
GOLANGCI_LINT_VERSION=v1.51.2
MYGOBIN = $(shell go env GOBIN)
ifeq ($(MYGOBIN),)

1
OWNERS
View File

@@ -1,6 +1,5 @@
# See https://github.com/kubernetes/community/blob/master/community-membership.md
approvers:
- kustomize-approvers
reviewers:
- kustomize-reviewers

View File

@@ -13,19 +13,12 @@ aliases:
- yuwenma
- annasong20
- koba1t
kyaml-approvers:
- mengqiy
- mortent
- phanimarupaka
kyaml-reviewers:
- mengqiy
- mortent
- phanimarupaka
emeritus-approvers:
- liujingfang1
- Shell32-Natsu
- justinsb
- monopole
- pwittrock
# emeritus:
# - liujingfang1
# - Shell32-Natsu
# - justinsb
# - monopole
# - pwittrock
# - mengqiy
# - mortent
# - phanimarupaka

View File

@@ -20,6 +20,14 @@ This tool is sponsored by [sig-cli] ([KEP]).
## kubectl integration
To find the kustomize version embedded in recent versions of kubectl, run `kubectl version`:
```sh
> kubectl version --short --client
Client Version: v1.26.0
Kustomize Version: v4.5.7
```
The kustomize build flow at [v2.0.3] was added
to [kubectl v1.14][kubectl announcement]. The kustomize
flow in kubectl remained frozen at v2.0.3 until kubectl v1.21,

View File

@@ -4,10 +4,10 @@
include ../Makefile-modules.mk
test:
go test -v -timeout 45m -cover ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222"
go test -v -timeout 45m -cover ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.buildDate=2023-01-31T23:38:41Z -X sigs.k8s.io/kustomize/api/provenance.version=(test)"
build:
go build -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222" ./...
go build -ldflags "-X sigs.k8s.io/kustomize/api/provenance.buildDate=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")" ./...
generate: $(MYGOBIN)/k8scopy $(MYGOBIN)/stringer
go generate ./...

View File

@@ -56,9 +56,11 @@ func (ns Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
// Run runs the filter on a single node rather than a slice
func (ns Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
// Special handling for metadata.namespace -- :(
// Special handling for metadata.namespace and metadata.name -- :(
// never let SetEntry handle metadata.namespace--it will incorrectly include cluster-scoped resources
ns.FsSlice = ns.removeMetaNamespaceFieldSpecs(ns.FsSlice)
// only update metadata.name if api version is expected one--so-as it leaves other resources of kind namespace alone
apiVersion := node.GetApiVersion()
ns.FsSlice = ns.removeUnneededMetaFieldSpecs(apiVersion, ns.FsSlice)
gvk := resid.GvkFromNode(node)
if err := ns.metaNamespaceHack(node, gvk); err != nil {
return nil, err
@@ -186,12 +188,15 @@ func (ns Filter) removeRoleBindingSubjectFieldSpecs(fs types.FsSlice) types.FsSl
return val
}
func (ns Filter) removeMetaNamespaceFieldSpecs(fs types.FsSlice) types.FsSlice {
func (ns Filter) removeUnneededMetaFieldSpecs(apiVersion string, fs types.FsSlice) types.FsSlice {
var val types.FsSlice
for i := range fs {
if fs[i].Path == types.MetadataNamespacePath {
continue
}
if apiVersion != types.MetadataNamespaceApiVersion && fs[i].Path == types.MetadataNamePath {
continue
}
val = append(val, fs[i])
}
return val

View File

@@ -10,7 +10,7 @@ require (
github.com/stretchr/testify v1.8.1
gopkg.in/yaml.v2 v2.4.0
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596
sigs.k8s.io/kustomize/kyaml v0.13.9
sigs.k8s.io/kustomize/kyaml v0.14.2
sigs.k8s.io/yaml v1.3.0
)
@@ -28,6 +28,7 @@ require (
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/sys v0.3.0 // indirect

View File

@@ -51,6 +51,7 @@ github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@@ -68,11 +69,13 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@@ -135,6 +138,7 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
@@ -145,7 +149,7 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596 h1:8cNCQs+WqqnSpZ7y0LMQPKD+RZUHU17VqLPMW3qxnxc=
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596/go.mod h1:/BYxry62FuDzmI+i9B+X2pqfySRmSOW2ARmj5Zbqhj0=
sigs.k8s.io/kustomize/kyaml v0.13.9 h1:Qz53EAaFFANyNgyOEJbT/yoIHygK40/ZcvU3rgry2Tk=
sigs.k8s.io/kustomize/kyaml v0.13.9/go.mod h1:QsRbD0/KcU+wdk0/L0fIp2KLnohkVzs6fQ85/nOXac4=
sigs.k8s.io/kustomize/kyaml v0.14.2 h1:9WSwztbzwGszG1bZTziQUmVMrJccnyrLb5ZMKpJGvXw=
sigs.k8s.io/kustomize/kyaml v0.14.2/go.mod h1:AN1/IpawKilWD7V+YvQwRGUvuUOOWpjsHu6uHwonSF4=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=

View File

@@ -170,9 +170,10 @@ func (ra *ResAccumulator) FixBackReferences() (err error) {
// Intersection drops the resources which "other" does not have.
func (ra *ResAccumulator) Intersection(other resmap.ResMap) error {
otherIds := other.AllIds()
for _, curId := range ra.resMap.AllIds() {
toDelete := true
for _, otherId := range other.AllIds() {
for _, otherId := range otherIds {
if otherId == curId {
toDelete = false
break

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on AnnotationsTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on ConfigMapGenerator; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on HashTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on HelmChartInflationGenerator; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins
@@ -16,6 +16,7 @@ import (
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/yaml"
)
@@ -86,12 +87,20 @@ func (p *HelmChartInflationGeneratorPlugin) validateArgs() (err error) {
p.ChartHome = types.HelmDefaultHome
}
// The ValuesFile may be consulted by the plugin, so it must
// The ValuesFile(s) may be consulted by the plugin, so it must
// be under the loader root (unless root restrictions are
// disabled).
if p.ValuesFile == "" {
p.ValuesFile = filepath.Join(p.ChartHome, p.Name, "values.yaml")
}
for i, file := range p.AdditionalValuesFiles {
// use Load() to enforce root restrictions
if _, err := p.h.Loader().Load(file); err != nil {
return errors.WrapPrefixf(err, "could not load additionalValuesFile")
}
// the additional values filepaths must be relative to the kust root
p.AdditionalValuesFiles[i] = filepath.Join(p.h.Loader().Root(), file)
}
if err = p.errIfIllegalValuesMerge(); err != nil {
return err
@@ -146,8 +155,8 @@ func (p *HelmChartInflationGeneratorPlugin) runHelmCommand(
helm := p.h.GeneralConfig().HelmConfig.Command
err = errors.WrapPrefixf(
fmt.Errorf(
"unable to run: '%s %s' with env=%s (is '%s' installed?)",
helm, strings.Join(args, " "), env, helm),
"unable to run: '%s %s' with env=%s (is '%s' installed?): %w",
helm, strings.Join(args, " "), env, helm, err),
stderr.String(),
)
}
@@ -240,49 +249,31 @@ func (p *HelmChartInflationGeneratorPlugin) Generate() (rm resmap.ResMap, err er
return nil, err
}
var stdout []byte
stdout, err = p.runHelmCommand(p.templateCommand())
stdout, err = p.runHelmCommand(p.AsHelmArgs(p.absChartHome()))
if err != nil {
return nil, err
}
rm, err = p.h.ResmapFactory().NewResMapFromBytes(stdout)
if err == nil {
rm, resMapErr := p.h.ResmapFactory().NewResMapFromBytes(stdout)
if resMapErr == nil {
return rm, nil
}
// try to remove the contents before first "---" because
// helm may produce messages to stdout before it
stdoutStr := string(stdout)
if idx := strings.Index(stdoutStr, "\n---\n"); idx != -1 {
return p.h.ResmapFactory().NewResMapFromBytes([]byte(stdoutStr[idx:]))
r := &kio.ByteReader{Reader: bytes.NewBufferString(string(stdout)), OmitReaderAnnotations: true}
nodes, err := r.Read()
if err != nil {
return nil, fmt.Errorf("error reading helm output: %w", err)
}
return nil, err
}
func (p *HelmChartInflationGeneratorPlugin) templateCommand() []string {
args := []string{"template"}
if p.ReleaseName != "" {
args = append(args, p.ReleaseName)
if len(nodes) != 0 {
rm, err = p.h.ResmapFactory().NewResMapFromRNodeSlice(nodes)
if err != nil {
return nil, fmt.Errorf("could not parse rnode slice into resource map: %w", err)
}
return rm, nil
}
if p.Namespace != "" {
args = append(args, "--namespace", p.Namespace)
}
args = append(args, filepath.Join(p.absChartHome(), p.Name))
if p.ValuesFile != "" {
args = append(args, "--values", p.ValuesFile)
}
if p.ReleaseName == "" {
// AFAICT, this doesn't work as intended due to a bug in helm.
// See https://github.com/helm/helm/issues/6019
// I've tried placing the flag before and after the name argument.
args = append(args, "--generate-name")
}
if p.IncludeCRDs {
args = append(args, "--include-crds")
}
if p.SkipHooks {
args = append(args, "--no-hooks")
}
return args
return nil, fmt.Errorf("could not parse bytes into resource map: %w", resMapErr)
}
func (p *HelmChartInflationGeneratorPlugin) pullCommand() []string {

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on IAMPolicyGenerator; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on ImageTagTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on LabelTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on NamespaceTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on PatchJson6902Transformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on PatchStrategicMergeTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on PatchTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on PrefixTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on ReplacementTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on ReplicaCountTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on SecretGenerator; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on SortOrderTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on SuffixTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -1,5 +1,5 @@
// Code generated by pluginator on ValueAddTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
// pluginator {(devel) unknown }
package builtins

View File

@@ -370,8 +370,9 @@ func trimPrefixIgnoreCase(s, prefix string) (string, bool) {
func findPathSeparator(hostPath string, acceptSCP bool) int {
sepIndex := strings.Index(hostPath, pathSeparator)
if acceptSCP {
colonIndex := strings.Index(hostPath, ":")
// The colon acts as a delimiter in scp-style ssh URLs only if not prefixed by '/'.
if colonIndex := strings.Index(hostPath, ":"); colonIndex > 0 && colonIndex < sepIndex {
if sepIndex == -1 || (colonIndex > 0 && colonIndex < sepIndex) {
sepIndex = colonIndex
}
}

View File

@@ -659,6 +659,26 @@ func TestNewRepoSpecFromUrl_Smoke(t *testing.T) {
RepoPath: "kubernetes-sigs/kustomize",
},
},
{
name: "scp format gist url",
input: "git@gist.github.com:bc7947cb727d7f9217e7862d961a1ffd.git",
cloneSpec: "git@gist.github.com:bc7947cb727d7f9217e7862d961a1ffd.git",
absPath: notCloned.String(),
repoSpec: RepoSpec{
Host: "git@gist.github.com:",
RepoPath: "bc7947cb727d7f9217e7862d961a1ffd.git",
},
},
{
name: "https gist url",
input: "https://gist.github.com/bc7947cb727d7f9217e7862d961a1ffd.git",
cloneSpec: "https://gist.github.com/bc7947cb727d7f9217e7862d961a1ffd.git",
absPath: notCloned.String(),
repoSpec: RepoSpec{
Host: "https://gist.github.com/",
RepoPath: "bc7947cb727d7f9217e7862d961a1ffd.git",
},
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {

View File

@@ -48,6 +48,14 @@ func (lbp *localizeBuiltinPlugins) Filter(plugins []*yaml.RNode) ([]*yaml.RNode,
Gvk: resid.Gvk{Version: konfig.BuiltinPluginApiVersion, Kind: builtinhelpers.SecretGenerator.String()},
Path: "envs",
},
types.FieldSpec{
Gvk: resid.Gvk{Version: konfig.BuiltinPluginApiVersion, Kind: builtinhelpers.HelmChartInflationGenerator.String()},
Path: "valuesFile",
},
types.FieldSpec{
Gvk: resid.Gvk{Version: konfig.BuiltinPluginApiVersion, Kind: builtinhelpers.HelmChartInflationGenerator.String()},
Path: "additionalValuesFiles",
},
types.FieldSpec{
Gvk: resid.Gvk{Version: konfig.BuiltinPluginApiVersion, Kind: builtinhelpers.PatchTransformer.String()},
Path: "path",
@@ -82,6 +90,24 @@ func (lbp *localizeBuiltinPlugins) Filter(plugins []*yaml.RNode) ([]*yaml.RNode,
return lbp.localizeAll(node)
},
},
yaml.FilterFunc(func(node *yaml.RNode) (*yaml.RNode, error) {
isHelm := node.GetApiVersion() == konfig.BuiltinPluginApiVersion &&
node.GetKind() == builtinhelpers.HelmChartInflationGenerator.String()
if !isHelm {
return node, nil
}
home, err := node.Pipe(yaml.Lookup("chartHome"))
if err != nil {
return nil, errors.Wrap(err)
}
if home == nil {
_, err = lbp.lc.copyChartHomeEntry("")
} else {
lbp.locPathFn = lbp.lc.copyChartHomeEntry
err = lbp.localizeScalar(home)
}
return node, errors.WrapPrefixf(err, "plugin %s", resid.FromRNode(node))
}),
fieldspec.Filter{
FieldSpec: types.FieldSpec{
Gvk: resid.Gvk{Version: konfig.BuiltinPluginApiVersion, Kind: builtinhelpers.PatchStrategicMergeTransformer.String()},
@@ -92,7 +118,6 @@ func (lbp *localizeBuiltinPlugins) Filter(plugins []*yaml.RNode) ([]*yaml.RNode,
return lbp.localizeAll(node)
},
})
// TODO(annasong): localize HelmChartInflationGenerator
if err != nil {
return nil, errors.Wrap(err)
}
@@ -106,6 +131,7 @@ func (lbp *localizeBuiltinPlugins) localizeAll(node *yaml.RNode) error {
// We rely on the build command to throw errors for nodes in
// built-in plugins that are sequences when expected to be scalar,
// and vice versa.
//nolint: exhaustive
switch node.YNode().Kind {
case yaml.SequenceNode:
return errors.Wrap(node.VisitElements(lbp.localizeScalar))

View File

@@ -38,10 +38,11 @@ type localizer struct {
}
// Run attempts to localize the kustomization root at target with the given localize arguments
func Run(target string, scope string, newDir string, fSys filesys.FileSystem) error {
// and returns the path to the created newDir.
func Run(target, scope, newDir string, fSys filesys.FileSystem) (string, error) {
ldr, args, err := NewLoader(target, scope, newDir, fSys)
if err != nil {
return errors.Wrap(err)
return "", errors.Wrap(err)
}
defer func() { _ = ldr.Cleanup() }()
@@ -51,7 +52,7 @@ func Run(target string, scope string, newDir string, fSys filesys.FileSystem) er
}
dst := args.NewDir.Join(toDst)
if err = fSys.MkdirAll(dst); err != nil {
return errors.WrapPrefixf(err, "unable to create directory in localize destination")
return "", errors.WrapPrefixf(err, "unable to create directory in localize destination")
}
err = (&localizer{
@@ -66,9 +67,9 @@ func Run(target string, scope string, newDir string, fSys filesys.FileSystem) er
if errCleanup != nil {
log.Printf("unable to clean localize destination: %s", errCleanup)
}
return errors.WrapPrefixf(err, "unable to localize target %q", target)
return "", errors.WrapPrefixf(err, "unable to localize target %q", target)
}
return nil
return args.NewDir.String(), nil
}
// localize localizes the root that lc is at
@@ -279,6 +280,14 @@ func (lc *localizer) localizeHelmCharts(kust *types.Kustomization) error {
return errors.WrapPrefixf(err, "unable to localize helmCharts entry %d valuesFile", i)
}
kust.HelmCharts[i].ValuesFile = locFile
for j, valuesFile := range chart.AdditionalValuesFiles {
locFile, err = lc.localizeFile(valuesFile)
if err != nil {
return errors.WrapPrefixf(err, "unable to localize helmCharts entry %d additionalValuesFiles", i)
}
kust.HelmCharts[i].AdditionalValuesFiles[j] = locFile
}
}
if kust.HelmGlobals != nil {
locDir, err := lc.copyChartHomeEntry(kust.HelmGlobals.ChartHome)

View File

@@ -102,6 +102,14 @@ func addFiles(t *testing.T, fSys filesys.FileSystem, parentDir string, files map
}
}
func checkRun(t *testing.T, fSys filesys.FileSystem, target, scope, dst string) {
t.Helper()
actualDst, err := Run(target, scope, dst, fSys)
require.NoError(t, err)
require.Equal(t, dst, actualDst)
}
func makeFileSystems(t *testing.T, target string, files map[string]string) (expected filesys.FileSystem, actual filesys.FileSystem) {
t.Helper()
@@ -161,9 +169,7 @@ func checkLocalizeInTargetSuccess(t *testing.T, files map[string]string) {
fSys := makeMemoryFs(t)
addFiles(t, fSys, "/a", files)
err := Run("/a", "/", "dst", fSys)
require.NoError(t, err)
checkRun(t, fSys, "/a", "/", "/dst")
fSysExpected := makeMemoryFs(t)
addFiles(t, fSysExpected, "/a", files)
addFiles(t, fSysExpected, "/dst/a", files)
@@ -179,9 +185,7 @@ namePrefix: my-
}
fSysExpected, fSysActual := makeFileSystems(t, "/a", kustomization)
err := Run("/a", "", "/a/b/dst", fSysActual)
require.NoError(t, err)
checkRun(t, fSysActual, "/a", "/a", "/a/b/dst")
addFiles(t, fSysExpected, "/a/b/dst", kustomization)
checkFSys(t, fSysExpected, fSysActual)
}
@@ -202,9 +206,7 @@ patches:
}
fSysExpected, fSysActual := makeFileSystems(t, "/a/b", kustomization)
err := Run("/a/b", "/", "/a/b/dst", fSysActual)
require.NoError(t, err)
checkRun(t, fSysActual, "/a/b", "/", "/a/b/dst")
addFiles(t, fSysExpected, "/a/b/dst/a/b", kustomization)
checkFSys(t, fSysExpected, fSysActual)
}
@@ -259,9 +261,9 @@ func TestLoadUnknownKustFields(t *testing.T) {
suffix: invalid`,
})
err := Run("/a", "", "", fSysTest)
_, err := Run("/a", "", "", fSysTest)
require.EqualError(t, err,
`unable to localize target "/a": invalid Kustomization: error unmarshaling JSON: while decoding JSON: json: unknown field "suffix"`)
`unable to localize target "/a": invalid Kustomization: json: unknown field "suffix"`)
checkFSys(t, fSysExpected, fSysTest)
}
@@ -299,9 +301,7 @@ patches:
}
expected, actual := makeFileSystems(t, "/alpha/beta/gamma", kustAndPatch)
err := Run("/alpha/beta/gamma", "/", "", actual)
require.NoError(t, err)
checkRun(t, actual, "/alpha/beta/gamma", "/", "/localized-gamma")
addFiles(t, expected, "/localized-gamma/alpha/beta/gamma", map[string]string{
"kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
@@ -328,9 +328,7 @@ kind: Kustomization
}
expected, actual := makeFileSystems(t, "/alpha/beta", targetAndUnreferenced)
err := Run("/alpha/beta", "/alpha", "/beta", actual)
require.NoError(t, err)
checkRun(t, actual, "/alpha/beta", "/alpha", "/beta")
addFiles(t, expected, "/beta/beta", map[string]string{
"kustomization.yaml": targetAndUnreferenced["kustomization.yaml"],
"env": targetAndUnreferenced["env"],
@@ -586,15 +584,43 @@ patches:
}
expected, actual := makeFileSystems(t, "/a/b", kustAndPatch)
err := Run("/a/b", "", "/dst", actual)
_, err := Run("/a/b", "", "/dst", actual)
require.EqualError(t, err, `unable to localize target "/a/b": unable to localize patches: invalid file reference: '/a/b/name-DNE.yaml' doesn't exist`)
checkFSys(t, expected, actual)
}
func TestLocalizePluginsInlineAndFile(t *testing.T) {
kustAndPlugins := map[string]string{
"kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1
for _, test := range []struct {
name string
files map[string]string
}{
{
name: "generators",
files: map[string]string{
"kustomization.yaml": `generators:
- generator.yaml
- |
apiVersion: builtin
env: second.properties
kind: ConfigMapGenerator
metadata:
name: inline
`,
"generator.yaml": `apiVersion: builtin
env: first.properties
kind: ConfigMapGenerator
metadata:
name: file
`,
"first.properties": "APPLE=orange",
"second.properties": "BANANA=pear",
},
},
{
name: "transformers",
files: map[string]string{
"kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
transformers:
- |
@@ -605,16 +631,39 @@ transformers:
path: patchSM-one.yaml
- patch.yaml
`,
"patch.yaml": `apiVersion: builtin
"patch.yaml": `apiVersion: builtin
kind: PatchTransformer
metadata:
name: file
path: patchSM-two.yaml
`,
"patchSM-one.yaml": podConfiguration,
"patchSM-two.yaml": podConfiguration,
"patchSM-one.yaml": podConfiguration,
"patchSM-two.yaml": podConfiguration,
},
},
{
name: "validators",
files: map[string]string{
"kustomization.yaml": `validators:
- |
apiVersion: builtin
kind: ReplacementTransformer
metadata:
name: inline
replacements:
- path: first.yaml
- second.yaml
`,
"first.yaml": replacementTransformerWithPath,
"second.yaml": replacementTransformerWithPath,
"replacement.yaml": replacements,
},
},
} {
t.Run(test.name, func(t *testing.T) {
checkLocalizeInTargetSuccess(t, test.files)
})
}
checkLocalizeInTargetSuccess(t, kustAndPlugins)
}
func TestLocalizeMultiplePluginsInEntry(t *testing.T) {
@@ -659,9 +708,7 @@ transformers:
}
expected, actual := makeFileSystems(t, "/a", kustAndPlugins)
err := Run("/a", "", "/dst", actual)
require.NoError(t, err)
checkRun(t, actual, "/a", "/a", "/dst")
addFiles(t, expected, "/dst", map[string]string{
"kustomization.yaml": kustAndPlugins["kustomization.yaml"],
"patch.yaml": fmt.Sprintf(patchf, "patchSM.yaml"),
@@ -920,7 +967,7 @@ metadata:
t.Run(test.name, func(t *testing.T) {
expected, actual := makeFileSystems(t, "/", test.files)
err := Run("/", "", "/dst", actual)
_, err := Run("/", "", "/dst", actual)
var actualErr ResourceLoadError
require.ErrorAs(t, err, &actualErr)
@@ -974,7 +1021,7 @@ func TestLocalizeBuiltinPlugins_Errors(t *testing.T) {
} {
t.Run(name, func(t *testing.T) {
expected, actual := makeFileSystems(t, "/a", test.files)
err := Run("/a", "", "/dst", actual)
_, err := Run("/a", "", "/dst", actual)
const errPrefix = `unable to localize target "/a"`
require.EqualError(t, err, fmt.Sprintf(
"%s: %s: %s", errPrefix, test.fieldSpecErr, test.locErr))
@@ -1094,9 +1141,7 @@ namespace: kustomize-namespace
}
expected, actual := makeFileSystems(t, "/alpha", kustAndComponents)
err := Run("/alpha/beta/gamma", "/alpha", "/alpha/beta/dst", actual)
require.NoError(t, err)
checkRun(t, actual, "/alpha/beta/gamma", "/alpha", "/alpha/beta/dst")
cleanedFiles := map[string]string{
"beta/gamma/kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1
components:
@@ -1159,9 +1204,7 @@ namePrefix: my-
}
expected, actual := makeFileSystems(t, "/a/b", kustAndResources)
err := Run("/a/b", "/", "", actual)
require.NoError(t, err)
checkRun(t, actual, "/a/b", "/", "/localized-b")
addFiles(t, expected, "/localized-b/a/b", kustAndResources)
checkFSys(t, expected, actual)
}
@@ -1176,7 +1219,7 @@ resources:
}
expected, actual := makeFileSystems(t, "/a", kustAndResources)
err := Run("/a", "/", "", actual)
_, err := Run("/a", "/", "", actual)
const expectedFileErr = `invalid file reference: '/a/b' must resolve to a file`
const expectedRootErr = `unable to localize root "b": unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization' in directory '/a/b'`
@@ -1230,8 +1273,13 @@ func TestLocalizeHelmCharts(t *testing.T) {
- includeCRDs: true
name: localize-valuesFile
valuesFile: file
- additionalValuesFiles:
- another
- third
`,
"file": valuesFile,
"another": valuesFile,
"third": valuesFile,
"charts/nothing-to-localize/values.yaml": valuesFile,
"charts/localize-valuesFile/values.yaml": valuesFile,
},
@@ -1273,9 +1321,7 @@ func TestLocalizeHelmChartsNoDefault(t *testing.T) {
}
expected, actual := makeFileSystems(t, "/a", files)
err := Run("/a", "", "/dst", actual)
require.NoError(t, err)
checkRun(t, actual, "/a", "/a", "/dst")
addFiles(t, expected, "/dst", map[string]string{
"kustomization.yaml": files["kustomization.yaml"],
"home/name/values.yaml": valuesFile,
@@ -1389,9 +1435,7 @@ helmGlobals:
t.Run(name, func(t *testing.T) {
expected, actual := makeFileSystems(t, "/a/b", test.files)
err := Run("/a/b", "/a/b", "/dst", actual)
require.NoError(t, err)
checkRun(t, actual, "/a/b", "/a/b", "/dst")
addFiles(t, expected, "/dst", test.copiedFiles)
checkFSys(t, expected, actual)
})
@@ -1408,9 +1452,7 @@ func TestCopyChartHomeEmpty(t *testing.T) {
require.NoError(t, actual.Mkdir("/a/home"))
require.NoError(t, expected.Mkdir("/a/home"))
err := Run("/a", "", "/dst", actual)
require.NoError(t, err)
checkRun(t, actual, "/a", "/a", "/dst")
addFiles(t, expected, "/dst", kustomization)
require.NoError(t, expected.Mkdir("/dst/home"))
checkFSys(t, expected, actual)
@@ -1452,7 +1494,7 @@ func TestCopyChartHomeError(t *testing.T) {
t.Run(name, func(t *testing.T) {
expected, actual := makeFileSystems(t, "/", test.files)
err := Run("/a/b", "/a", "/dst", actual)
_, err := Run("/a/b", "/a", "/dst", actual)
const prefix = `unable to localize target "/a/b"`
require.EqualError(t, err, fmt.Sprintf("%s: %s", prefix, test.err))
@@ -1461,6 +1503,67 @@ func TestCopyChartHomeError(t *testing.T) {
}
}
func TestLocalizeGeneratorsHelm(t *testing.T) {
files := map[string]string{
"kustomization.yaml": `generators:
- default.yaml
- explicit.yaml
`,
"default.yaml": `apiVersion: builtin
kind: HelmChartInflationGenerator
metadata:
name: no-explicit-references
name: minecraft
releaseName: moria
repo: https://itzg.github.io/minecraft-server-charts
version: 3.1.3
`,
"explicit.yaml": `additionalValuesFiles:
- time.yaml
- life.yaml
- light.yaml
apiVersion: builtin
chartHome: home
kind: HelmChartInflationGenerator
metadata:
name: explicit-references
name: mapleStory
valuesFile: mapleValues.yaml
`,
"time.yaml": valuesFile,
"life.yaml": valuesFile,
"light.yaml": valuesFile,
"mapleValues.yaml": valuesFile,
"home/mapleStory/values.yaml": valuesFile,
"charts/minecraft/values.yaml": valuesFile,
}
checkLocalizeInTargetSuccess(t, files)
}
func TestLocalizeGeneratorsNoHelm(t *testing.T) {
files := map[string]string{
"kustomization.yaml": `generators:
- configMap.yaml
`,
"configMap.yaml": `apiVersion: builtin
kind: ConfigMapGenerator
literals:
- APPLE=orange
metadata:
name: not-helm-shouldn't-copy-default-helm-chart-home
`,
"charts/minecraft/values.yaml": valuesFile,
}
expected, actual := makeFileSystems(t, "/a", files)
checkRun(t, actual, "/a", "/a", "/dst")
addFiles(t, expected, "/dst", map[string]string{
"kustomization.yaml": files["kustomization.yaml"],
"configMap.yaml": files["configMap.yaml"],
})
checkFSys(t, expected, actual)
}
func TestLocalizeEmpty(t *testing.T) {
for name, kustomization := range map[string]string{
"file": `configurations:

View File

@@ -6,6 +6,7 @@ package localizer_test
import (
"bytes"
"log"
"os"
"testing"
"github.com/stretchr/testify/require"
@@ -37,6 +38,9 @@ func TestLocalLoadNewAndCleanup(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
defer func() {
log.SetOutput(os.Stderr)
}()
// typical setup
ldr, args, err := NewLoader("a", "/", "/newDir", fSys)
req.NoError(err)
@@ -223,6 +227,9 @@ func TestNewLocLoaderFails(t *testing.T) {
t.Run(name, func(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
defer func() {
log.SetOutput(os.Stderr)
}()
_, _, err := NewLoader(params.target, params.scope, params.dest, makeMemoryFs(t))
require.Error(t, err)

View File

@@ -6,7 +6,6 @@ package krusty_test
import (
"testing"
"github.com/stretchr/testify/assert"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
@@ -229,6 +228,9 @@ type: Opaque
`)
}
// TODO: This should be an error instead. However, we can't strict unmarshal until we have a yaml
// lib that support case-insensitive keys and anchors.
// See https://github.com/kubernetes-sigs/kustomize/issues/5061
func TestGeneratorRepeatsInKustomization(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
@@ -261,13 +263,24 @@ krypton
xenon
radon
`)
err := th.RunWithErr(".", th.MakeDefaultOptions())
if err == nil {
t.Fatalf("expected an error")
}
assert.Contains(t, err.Error(),
"invalid Kustomization: error converting YAML to JSON: yaml: unmarshal errors:\n"+
" line 13: key \"literals\" already set in map\n line 18: key \"files\" already set in map")
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
fruit: apple
nobles: |2
helium
neon
argon
krypton
xenon
radon
vegetable: broccoli
kind: ConfigMap
metadata:
name: blah-bob-db529cg5bk
`)
}
func TestIssue3393(t *testing.T) {
@@ -558,3 +571,23 @@ metadata:
name: test-k9cc55dfm5
`)
}
func TestDataIsSingleQuote(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
configMapGenerator:
- name: test
literals:
- TEST='
`)
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(
m, `apiVersion: v1
data:
TEST: ''''
kind: ConfigMap
metadata:
name: test-m8t7bmb6g2
`)
}

View File

@@ -504,313 +504,106 @@ func skipIfNoDocker(t *testing.T) {
}
func TestFnContainerGenerator(t *testing.T) {
t.Skip("wait for #3881")
skipIfNoDocker(t)
// Function plugins should not need the env setup done by MakeEnhancedHarness
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
o := th.MakeOptionsPluginsEnabled()
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
th.WriteK(tmpDir.String(), `
resources:
- short_secret.yaml
- deployment.yaml
generators:
- gener.yaml
- project-service-set.yaml
`)
// Create generator config
th.WriteF("gener.yaml", `
apiVersion: examples.config.kubernetes.io/v1beta1
kind: CockroachDB
th.WriteF(filepath.Join(tmpDir.String(), "project-service-set.yaml"), `
apiVersion: blueprints.cloud.google.com/v1alpha1
kind: ProjectServiceSet
metadata:
name: demo
annotations:
config.kubernetes.io/function: |
container:
image: gcr.io/kustomize-functions/example-cockroachdb:v0.1.0
image: gcr.io/kpt-fn/enable-gcp-services:v0.1.0
spec:
replicas: 3
services:
- compute.googleapis.com
projectID: foo
`)
// Create some additional resource just to make sure everything is added
th.WriteF("short_secret.yaml", `
apiVersion: v1
kind: Secret
// Create another resource just to make sure everything is added
th.WriteF(filepath.Join(tmpDir.String(), "deployment.yaml"), `
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
airshipit.org/ephemeral-user-data: "true"
name: node1-bmc-secret
type: Opaque
stringData:
userData: |
bootcmd:
- mkdir /mnt/vda
name: foo
`)
m := th.Run(".", th.MakeOptionsPluginsEnabled())
th.AssertActualEqualsExpected(m, `
apiVersion: v1
kind: Secret
m := th.Run(tmpDir.String(), o)
actual, err := m.AsYaml()
assert.NoError(t, err)
assert.Equal(t, `apiVersion: apps/v1
kind: Deployment
metadata:
labels:
airshipit.org/ephemeral-user-data: "true"
name: node1-bmc-secret
stringData:
userData: |
bootcmd:
- mkdir /mnt/vda
type: Opaque
name: foo
---
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
labels:
app: cockroachdb
name: demo
name: demo-budget
spec:
minAvailable: 67%
selector:
matchLabels:
app: cockroachdb
name: demo
---
apiVersion: v1
kind: Service
metadata:
labels:
app: cockroachdb
name: demo
name: demo-public
spec:
ports:
- name: grpc
port: 26257
targetPort: 26257
- name: http
port: 8080
targetPort: 8080
selector:
app: cockroachdb
name: demo
---
apiVersion: v1
apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1
kind: Service
metadata:
annotations:
prometheus.io/path: _status/vars
prometheus.io/port: "8080"
prometheus.io/scrape: "true"
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
labels:
app: cockroachdb
name: demo
name: demo
blueprints.cloud.google.com/ownerReference: blueprints.cloud.google.com/ProjectServiceSet/demo
config.kubernetes.io/function: |
container:
image: gcr.io/kpt-fn/enable-gcp-services:v0.1.0
name: demo-compute
spec:
clusterIP: None
ports:
- name: grpc
port: 26257
targetPort: 26257
- name: http
port: 8080
targetPort: 8080
selector:
app: cockroachdb
name: demo
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app: cockroachdb
name: demo
name: demo
spec:
replicas: 3
selector:
matchLabels:
app: cockroachdb
name: demo
serviceName: demo
template:
metadata:
labels:
app: cockroachdb
name: demo
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- cockroachdb
topologyKey: kubernetes.io/hostname
weight: 100
containers:
- command:
- /bin/bash
- -ecx
- |
# The use of qualified `+"`hostname -f`"+` is crucial:
# Other nodes aren't able to look up the unqualified hostname.
CRARGS=("start" "--logtostderr" "--insecure" "--host" "$(hostname -f)" "--http-host" "0.0.0.0")
# We only want to initialize a new cluster (by omitting the join flag)
# if we're sure that we're the first node (i.e. index 0) and that
# there aren't any other nodes running as part of the cluster that
# this is supposed to be a part of (which indicates that a cluster
# already exists and we should make sure not to create a new one).
# It's fine to run without --join on a restart if there aren't any
# other nodes.
if [ ! "$(hostname)" == "cockroachdb-0" ] || [ -e "/cockroach/cockroach-data/cluster_exists_marker" ]
then
# We don't join cockroachdb in order to avoid a node attempting
# to join itself, which currently doesn't work
# (https://github.com/cockroachdb/cockroach/issues/9625).
CRARGS+=("--join" "cockroachdb-public")
fi
exec /cockroach/cockroach ${CRARGS[*]}
image: cockroachdb/cockroach:v1.1.0
imagePullPolicy: IfNotPresent
name: demo
ports:
- containerPort: 26257
name: grpc
- containerPort: 8080
name: http
volumeMounts:
- mountPath: /cockroach/cockroach-data
name: datadir
initContainers:
- args:
- -on-start=/on-start.sh
- -service=cockroachdb
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: cockroachdb/cockroach-k8s-init:0.1
imagePullPolicy: IfNotPresent
name: bootstrap
volumeMounts:
- mountPath: /cockroach/cockroach-data
name: datadir
terminationGracePeriodSeconds: 60
volumes:
- name: datadir
persistentVolumeClaim:
claimName: datadir
volumeClaimTemplates:
- metadata:
name: datadir
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
`)
projectRef:
external: foo
resourceID: compute.googleapis.com
`, string(actual))
}
func TestFnContainerTransformer(t *testing.T) {
t.Skip("wait for #3881")
skipIfNoDocker(t)
// Function plugins should not need the env setup done by MakeEnhancedHarness
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
o := th.MakeOptionsPluginsEnabled()
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
th.WriteK(tmpDir.String(), `
resources:
- data.yaml
- deployment.yaml
transformers:
- transf1.yaml
- transf2.yaml
- e2econtainerconfig.yaml
`)
th.WriteF("data.yaml", `
th.WriteF(filepath.Join(tmpDir.String(), "deployment.yaml"), `
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
annotations:
tshirt-size: small # this injects the resource reservations
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
name: foo
`)
// This transformer should add resource reservations based on annotation in data.yaml
// See https://github.com/kubernetes-sigs/kustomize/tree/master/functions/examples/injection-tshirt-sizes
th.WriteF("transf1.yaml", `
apiVersion: examples.config.kubernetes.io/v1beta1
kind: Validator
th.WriteF(filepath.Join(tmpDir.String(), "e2econtainerconfig.yaml"), `
apiVersion: example.com/v1alpha1
kind: Input
metadata:
name: valid
annotations:
config.kubernetes.io/function: |-
container:
image: gcr.io/kustomize-functions/example-tshirt:v0.2.0
`)
// This transformer will check resources without and won't do any changes
// See https://github.com/kubernetes-sigs/kustomize/tree/master/functions/examples/validator-kubeval
th.WriteF("transf2.yaml", `
apiVersion: examples.config.kubernetes.io/v1beta1
kind: Kubeval
metadata:
name: validate
name: foo
annotations:
config.kubernetes.io/function: |
container:
image: gcr.io/kustomize-functions/example-validator-kubeval:v0.1.0
spec:
strict: true
ignoreMissingSchemas: true
# TODO: Update this to use network/volumes features.
# Relevant issues:
# - https://github.com/kubernetes-sigs/kustomize/issues/1901
# - https://github.com/kubernetes-sigs/kustomize/issues/1902
kubernetesVersion: "1.16.0"
schemaLocation: "file:///schemas"
image: "gcr.io/kustomize-functions/e2econtainerconfig"
`)
m := th.Run(".", th.MakeOptionsPluginsEnabled())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
build := exec.Command("docker", "build", ".", "-t", "gcr.io/kustomize-functions/e2econtainerconfig")
build.Dir = "../../cmd/config/internal/commands/e2e/e2econtainerconfig"
assert.NoError(t, build.Run())
m := th.Run(tmpDir.String(), o)
actual, err := m.AsYaml()
assert.NoError(t, err)
assert.Equal(t, `apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
tshirt-size: small
labels:
app: nginx
name: nginx
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx
name: nginx
resources:
requests:
cpu: 200m
memory: 50M
`)
a-bool-value: "false"
a-int-value: "0"
a-string-value: ""
name: foo
`, string(actual))
}
func TestFnContainerTransformerWithConfig(t *testing.T) {

View File

@@ -4,9 +4,12 @@
package krusty_test
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
"sigs.k8s.io/kustomize/kyaml/copyutil"
)
const expectedHelm = `
@@ -233,3 +236,193 @@ spec:
type: ClusterIP
`)
}
func TestHelmChartInflationGeneratorMultipleValuesFiles(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
defer th.Reset()
if err := th.ErrIfNoHelm(); err != nil {
t.Skip("skipping: " + err.Error())
}
copyValuesFilesTestChartsIntoHarness(t, th)
th.WriteK(th.GetRoot(), `
helmCharts:
- name: test-chart
releaseName: test-chart
additionalValuesFiles:
- charts/valuesFiles/file1.yaml
- charts/valuesFiles/file2.yaml
`)
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
asYaml, err := m.AsYaml()
require.NoError(t, err)
require.Equal(t, string(asYaml), `apiVersion: apps/v1
kind: Deployment
metadata:
labels:
chart: test-1.0.0
name: my-deploy
namespace: file-2
spec:
replicas: 1
selector:
matchLabels:
app: test
template:
spec:
containers:
- image: test-image-file1:file1
imagePullPolicy: Never
---
apiVersion: apps/v1
kind: Pod
metadata:
annotations:
helm.sh/hook: test
name: test-chart
`)
}
func TestHelmChartInflationGeneratorApiVersions(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
defer th.Reset()
if err := th.ErrIfNoHelm(); err != nil {
t.Skip("skipping: " + err.Error())
}
copyValuesFilesTestChartsIntoHarness(t, th)
th.WriteK(th.GetRoot(), `
helmCharts:
- name: test-chart
releaseName: test-chart
apiVersions:
- foo/v1
`)
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
asYaml, err := m.AsYaml()
require.NoError(t, err)
require.Equal(t, string(asYaml), `apiVersion: foo/v1
kind: Deployment
metadata:
labels:
chart: test-1.0.0
name: my-deploy
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: test
template:
spec:
containers:
- image: test-image:v1.0.0
imagePullPolicy: Always
---
apiVersion: foo/v1
kind: Pod
metadata:
annotations:
helm.sh/hook: test
name: test-chart
`)
}
func TestHelmChartInflationGeneratorSkipTests(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
defer th.Reset()
if err := th.ErrIfNoHelm(); err != nil {
t.Skip("skipping: " + err.Error())
}
copyValuesFilesTestChartsIntoHarness(t, th)
th.WriteK(th.GetRoot(), `
helmCharts:
- name: test-chart
releaseName: test-chart
skipTests: true
`)
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
asYaml, err := m.AsYaml()
require.NoError(t, err)
require.Equal(t, string(asYaml), `apiVersion: apps/v1
kind: Deployment
metadata:
labels:
chart: test-1.0.0
name: my-deploy
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: test
template:
spec:
containers:
- image: test-image:v1.0.0
imagePullPolicy: Always
`)
}
func TestHelmChartInflationGeneratorNameTemplate(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
defer th.Reset()
if err := th.ErrIfNoHelm(); err != nil {
t.Skip("skipping: " + err.Error())
}
copyValuesFilesTestChartsIntoHarness(t, th)
th.WriteK(th.GetRoot(), `
helmCharts:
- name: test-chart
nameTemplate: name-template
`)
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
asYaml, err := m.AsYaml()
require.NoError(t, err)
require.Equal(t, string(asYaml), `apiVersion: apps/v1
kind: Deployment
metadata:
labels:
chart: test-1.0.0
name: my-deploy
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: test
template:
spec:
containers:
- image: test-image:v1.0.0
imagePullPolicy: Always
---
apiVersion: apps/v1
kind: Pod
metadata:
annotations:
helm.sh/hook: test
name: name-template
`)
}
func copyValuesFilesTestChartsIntoHarness(t *testing.T, th *kusttest_test.HarnessEnhanced) {
t.Helper()
thDir := filepath.Join(th.GetRoot(), "charts")
chartDir := "testdata/helmcharts"
fs := th.GetFSys()
require.NoError(t, fs.MkdirAll(filepath.Join(thDir, "templates")))
require.NoError(t, copyutil.CopyDir(th.GetFSys(), chartDir, thDir))
}

View File

@@ -9,7 +9,9 @@ import (
"sigs.k8s.io/kustomize/kyaml/filesys"
)
// Run `kustomize localize`s files referenced by kustomization target in scope to destination newDir on fSys.
func Run(fSys filesys.FileSystem, target, scope, newDir string) error {
return errors.Wrap(localizer.Run(target, scope, newDir, fSys))
// Run executes `kustomize localize` on fSys given the `localize` arguments and
// returns the path to the created newDir.
func Run(fSys filesys.FileSystem, target, scope, newDir string) (string, error) {
dst, err := localizer.Run(target, scope, newDir, fSys)
return dst, errors.Wrap(err)
}

View File

@@ -264,10 +264,11 @@ func TestWorkingDir(t *testing.T) {
fsExpected, fsActual, wd := PrepareFs(t, []string{"target", "base"}, files)
SetWorkingDir(t, wd.String())
err := localizer.Run(fsActual, "target", ".", "")
dst, err := localizer.Run(fsActual, "target", ".", "")
require.NoError(t, err)
require.Equal(t, wd.Join("localized-target"), dst)
SetupDir(t, fsExpected, wd.Join("localized-target"), files)
SetupDir(t, fsExpected, dst, files)
CheckFs(t, wd.String(), fsExpected, fsActual)
}
@@ -301,10 +302,10 @@ func TestLoaderSymlinks(t *testing.T) {
})
SetWorkingDir(t, testDir.String())
err := localizer.Run(fsActual, "target-link", "target", "")
dst, err := localizer.Run(fsActual, "target-link", "target", "")
require.NoError(t, err)
require.Equal(t, testDir.Join("localized-target"), dst)
dst := testDir.Join("localized-target")
SetupDir(t, fsExpected, dst, map[string]string{
"kustomization.yaml": fmt.Sprintf(`resources:
- %s
@@ -322,10 +323,10 @@ func TestRemoteTargetDefaultDst(t *testing.T) {
SetWorkingDir(t, testDir.String())
const target = simpleURL + urlQuery
err := localizer.Run(fsActual, target, "", "")
dst, err := localizer.Run(fsActual, target, "", "")
require.NoError(t, err)
require.Equal(t, testDir.Join("localized-simple-kustomize-v4.5.7"), dst)
dst := testDir.Join("localized-simple-kustomize-v4.5.7")
_, files := simplePathAndFiles(t)
SetupDir(t, fsExpected,
filepath.Join(dst, "api", "krusty", "testdata", "localize", "simple"),
@@ -364,7 +365,7 @@ func TestBadArgs(t *testing.T) {
fsExpected, fsActual, testDir := PrepareFs(t, nil, kust)
SetWorkingDir(t, testDir.String())
err := localizer.Run(fsActual, test.target, test.scope, test.dst)
_, err := localizer.Run(fsActual, test.target, test.scope, test.dst)
require.EqualError(t, err, test.err)
SetupDir(t, fsExpected, testDir.String(), kust)
@@ -383,9 +384,10 @@ openapi:
"kustomization.yaml": fmt.Sprintf(kustf, `https://raw.githubusercontent.com/kubernetes-sigs/kustomize/kustomize/v4.5.7/api/krusty/testdata/customschema.json`),
})
dst := testDir.Join("dst")
err := localizer.Run(fsActual, testDir.String(), "", dst)
newDir := testDir.Join("dst")
dst, err := localizer.Run(fsActual, testDir.String(), "", newDir)
require.NoError(t, err)
require.Equal(t, newDir, dst)
localizedPath := filepath.Join(LocalizeDir, "raw.githubusercontent.com",
"kubernetes-sigs", "kustomize", "kustomize", "v4.5.7", "api", "krusty",
@@ -404,9 +406,10 @@ func TestRemoteRoot(t *testing.T) {
`, simpleURL+urlQuery),
})
dst := testDir.Join("dst")
err := localizer.Run(fsActual, testDir.String(), "", dst)
newDir := testDir.Join("dst")
dst, err := localizer.Run(fsActual, testDir.String(), "", newDir)
require.NoError(t, err)
require.Equal(t, newDir, dst)
localizedPath, files := simplePathAndFiles(t)
SetupDir(t, fsExpected, dst, map[string]string{
@@ -427,9 +430,10 @@ func TestNestedRemoteRoots(t *testing.T) {
`,
})
dst := testDir.Join("dst")
err := localizer.Run(fsActual, testDir.String(), "", dst)
newDir := testDir.Join("dst")
dst, err := localizer.Run(fsActual, testDir.String(), "", newDir)
require.NoError(t, err)
require.Equal(t, newDir, dst)
localizedPath, files := remotePathAndFiles(t)
SetupDir(t, fsExpected, dst, map[string]string{
@@ -450,15 +454,13 @@ func TestResourcesRepoNotFile(t *testing.T) {
}
fsExpected, fsActual, testDir := PrepareFs(t, nil, kustomization)
err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
_, err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
const readmeErr = `mapping values are not allowed in this context`
fileErr := fmt.Sprintf(`invalid resource at file "%s": MalformedYAMLError:`, repo)
fileErr := fmt.Sprintf(`invalid resource at file "%s"`, repo)
rootErr := fmt.Sprintf(`unable to localize root "%s": unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization'`, repo)
var actualErr PathLocalizeError
require.ErrorAs(t, err, &actualErr)
require.Equal(t, repo, actualErr.Path)
require.ErrorContains(t, actualErr.FileError, readmeErr)
require.ErrorContains(t, actualErr.FileError, fileErr)
require.ErrorContains(t, actualErr.RootError, rootErr)
@@ -475,7 +477,7 @@ func TestRemoteRootNoRef(t *testing.T) {
}
fsExpected, fsActual, testDir := PrepareFs(t, nil, kustomization)
err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
_, err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
const fileErr = "invalid file reference: URL is a git repository"
rootErr := fmt.Sprintf(`localize remote root "%s" missing ref query string parameter`, root)
@@ -499,7 +501,7 @@ func TestExistingCacheDir(t *testing.T) {
}
fsExpected, fsActual, testDir := PrepareFs(t, []string{LocalizeDir}, file)
err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
_, err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
require.ErrorContains(t, err, fmt.Sprintf(`already contains localized-files needed to store file "%s"`, remoteFile))
SetupDir(t, fsExpected, testDir.String(), file)
@@ -520,9 +522,10 @@ minecraftServer:
filepath.Join("nested", "dirs", "home", "name"),
}, files)
dst := testDir.Join("dst")
err := localizer.Run(fsActual, testDir.String(), "", dst)
newDir := testDir.Join("dst")
dst, err := localizer.Run(fsActual, testDir.String(), "", newDir)
require.NoError(t, err)
require.Equal(t, newDir, dst)
SetupDir(t, fsExpected, dst, files)
CheckFs(t, dst, fsExpected, fsActual)
@@ -555,9 +558,10 @@ helmGlobals:
filepath.Join("target", "home-link"): "home",
})
dst := scope.Join("dst")
err := localizer.Run(fsActual, scope.Join("target"), scope.String(), dst)
newDir := scope.Join("dst")
dst, err := localizer.Run(fsActual, scope.Join("target"), scope.String(), newDir)
require.NoError(t, err)
require.Equal(t, newDir, dst)
SetupDir(t, fsExpected, dst, map[string]string{
filepath.Join("target", "Kustomization"): fmt.Sprintf(`helmCharts:
@@ -594,9 +598,10 @@ helmChartInflationGenerator:
})
link(t, target, map[string]string{"charts": "home"})
dst := target.Join("dst")
err := localizer.Run(fsActual, target.String(), "", dst)
newDir := target.Join("dst")
dst, err := localizer.Run(fsActual, target.String(), "", newDir)
require.NoError(t, err)
require.Equal(t, newDir, dst)
SetupDir(t, fsExpected, dst, map[string]string{
"kustomization.yaml": `helmChartInflationGenerator:
@@ -634,9 +639,10 @@ func TestHelmHomeEscapesScope(t *testing.T) {
filepath.Join("target", "home", "file-link"): "file",
})
dst := testDir.Join("dst")
err := localizer.Run(fsActual, testDir.Join("target"), "", dst)
newDir := testDir.Join("dst")
dst, err := localizer.Run(fsActual, testDir.Join("target"), "", newDir)
require.NoError(t, err)
require.Equal(t, newDir, dst)
SetupDir(t, fsExpected, dst, map[string]string{
"kustomization.yaml": `helmGlobals:
@@ -663,9 +669,10 @@ func TestSymlinkedFileSource(t *testing.T) {
"filename-used-as-key-in-configMap": "different-key",
})
dst := target.Join("dst")
err := localizer.Run(fsActual, target.String(), "", dst)
newDir := target.Join("dst")
dst, err := localizer.Run(fsActual, target.String(), "", newDir)
require.NoError(t, err)
require.Equal(t, newDir, dst)
SetupDir(t, fsExpected, dst, map[string]string{
"kustomization.yaml": `configMapGenerator:

View File

@@ -13,14 +13,14 @@ const expected = `apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/managed-by: kustomize-v444.333.222
app.kubernetes.io/managed-by: kustomize-(test)
name: myService
spec:
ports:
- port: 7002
`
// This test may failed when running on package tests using the go command because `v444.333.222` is set on makefile.
// This test may fail when running on package tests using the go command because `(test)` is set on makefile.
func TestAddManagedbyLabel(t *testing.T) {
tests := []struct {
kustFile string

View File

@@ -42,7 +42,7 @@ spec:
serviceAccountName: mySvcAcct
containers:
- name: whatever
image: k8s.gcr.io/governmentCheese
image: registry.k8s.io/governmentCheese
`)
th.WriteF("base/serviceAccount.yaml", `
apiVersion: v1
@@ -61,7 +61,7 @@ spec:
template:
spec:
containers:
- image: k8s.gcr.io/governmentCheese
- image: registry.k8s.io/governmentCheese
name: whatever
serviceAccountName: mySvcAcct
---
@@ -80,7 +80,7 @@ spec:
template:
spec:
containers:
- image: k8s.gcr.io/governmentCheese
- image: registry.k8s.io/governmentCheese
name: whatever
serviceAccountName: mySvcAcct-private
---
@@ -115,7 +115,7 @@ commonLabels:
app: external-dns
instance: public
images:
- name: k8s.gcr.io/external-dns/external-dns
- name: registry.k8s.io/external-dns/external-dns
newName: xxx.azurecr.io/external-dns
newTag: v0.7.4_sylr.1
- name: quay.io/sylr/external-dns
@@ -153,7 +153,7 @@ commonLabels:
app: external-dns
instance: private
images:
- name: k8s.gcr.io/external-dns/external-dns
- name: registry.k8s.io/external-dns/external-dns
newName: xxx.azurecr.io/external-dns
newTag: v0.7.4_sylr.1
- name: quay.io/sylr/external-dns
@@ -192,7 +192,7 @@ commonLabels:
app: external-dns
instance: public
images:
- name: k8s.gcr.io/external-dns/external-dns
- name: registry.k8s.io/external-dns/external-dns
newName: quay.io/sylr/external-dns
newTag: v0.7.4-73-g00a9a0c7
secretGenerator:
@@ -243,7 +243,7 @@ spec:
serviceAccountName: external-dns
containers:
- name: external-dns
image: k8s.gcr.io/external-dns/external-dns
image: registry.k8s.io/external-dns/external-dns
args:
- --domain-filter=""
- --txt-owner-id=""

View File

@@ -801,3 +801,31 @@ metadata:
namespace: iter8-monitoring
`)
}
// Demonstrates that metadata.name is only overridden for a kind: Namespace with apiVersion: v1
// Test for issue #5072
func TestNameNotOveriddenForNonCoreApiVersionOnANamespaceKind(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteF("azure-servicebus.yaml", `
apiVersion: servicebus.azure.com/v1beta20210101preview
kind: Namespace
metadata:
name: core-sb-99
namespace: without-podinfo
`)
th.WriteK(".", `
namespace: podinfo
resources:
- azure-servicebus.yaml
`)
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: servicebus.azure.com/v1beta20210101preview
kind: Namespace
metadata:
name: core-sb-99
namespace: podinfo
`)
}

View File

@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A simple test helm chart.
name: test
version: 1.0.0

View File

@@ -0,0 +1 @@
This is a simple test chart.

View File

@@ -0,0 +1,7 @@
{{- define "apiversion" -}}
{{- if .Capabilities.APIVersions.Has "foo/v1" -}}
foo/v1
{{- else -}}
apps/v1
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,18 @@
---
apiVersion: {{ template "apiversion" . }}
kind: Deployment
metadata:
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
name: my-deploy
namespace: {{ .Values.data.namespace }}
spec:
replicas: 1
selector:
matchLabels:
app: {{ .Chart.Name }}
template:
spec:
containers:
- image: "{{ .Values.data.image.name }}:{{ .Values.data.image.tag }}"
imagePullPolicy: {{ .Values.data.image.imagePullPolicy }}

View File

@@ -0,0 +1,6 @@
apiVersion: {{ template "apiversion" . }}
kind: Pod
metadata:
name: {{ .Release.Name }}
annotations:
"helm.sh/hook": test

View File

@@ -0,0 +1,6 @@
data:
namespace: default
image:
name: test-image
tag: v1.0.0
imagePullPolicy: Always

View File

@@ -0,0 +1,5 @@
data:
image:
name: test-image-file1
tag: file1
imagePullPolicy: Never

View File

@@ -0,0 +1,2 @@
data:
namespace: file-2

View File

@@ -37,7 +37,7 @@ spec:
spec:
containers:
- name: nginx
image: k8s.gcr.io/nginx-slim:0.8
image: registry.k8s.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
@@ -62,7 +62,7 @@ spec:
spec:
containers:
- name: nginx
image: k8s.gcr.io/nginx-slim:0.8
image: registry.k8s.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
@@ -116,7 +116,7 @@ spec:
notIn: arrays
spec:
containers:
- image: k8s.gcr.io/nginx-slim:0.8
- image: registry.k8s.io/nginx-slim:0.8
name: nginx
ports:
- containerPort: 80
@@ -142,7 +142,7 @@ spec:
notIn: arrays
spec:
containers:
- image: k8s.gcr.io/nginx-slim:0.8
- image: registry.k8s.io/nginx-slim:0.8
name: nginx
ports:
- containerPort: 80

View File

@@ -1848,7 +1848,7 @@ spec:
terminationGracePeriodSeconds: 10
containers:
- name: nginx
image: k8s.gcr.io/nginx-slim:0.8
image: registry.k8s.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
@@ -2123,7 +2123,7 @@ spec:
app: nginx
spec:
containers:
- image: k8s.gcr.io/nginx-slim:0.8
- image: registry.k8s.io/nginx-slim:0.8
name: nginx
ports:
- containerPort: 80

View File

@@ -187,7 +187,7 @@ func parseLiteralSource(source string) (keyName, value string, err error) {
// removeQuotes removes the surrounding quotes from the provided string only if it is surrounded on both sides
// rather than blindly trimming all quotation marks on either side.
func removeQuotes(str string) string {
if len(str) == 0 || str[0] != str[len(str)-1] {
if len(str) < 2 || str[0] != str[len(str)-1] {
return str
}
if str[0] == '"' || str[0] == '\'' {

View File

@@ -6,47 +6,63 @@ package provenance
import (
"fmt"
"runtime"
"runtime/debug"
"strings"
)
// These variables are set at build time using ldflags.
//
//nolint:gochecknoglobals
var (
version = "unknown"
// sha1 from git, output of $(git rev-parse HEAD)
gitCommit = "$Format:%H$"
// During a release, this will be set to the release tag, e.g. "kustomize/v4.5.7"
version = developmentVersion
// build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
buildDate = "1970-01-01T00:00:00Z"
goos = runtime.GOOS
goarch = runtime.GOARCH
buildDate = "unknown"
)
// This default value, (devel), matches
// the value debug.BuildInfo uses for an unset main module version.
const developmentVersion = "(devel)"
// Provenance holds information about the build of an executable.
type Provenance struct {
// Version of the kustomize binary.
Version string `json:"version,omitempty"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
// GitCommit is a git commit
GitCommit string `json:"gitCommit,omitempty"`
GitCommit string `json:"gitCommit,omitempty" yaml:"gitCommit,omitempty"`
// BuildDate is date of the build.
BuildDate string `json:"buildDate,omitempty"`
BuildDate string `json:"buildDate,omitempty" yaml:"buildDate,omitempty"`
// GoOs holds OS name.
GoOs string `json:"goOs,omitempty"`
GoOs string `json:"goOs,omitempty" yaml:"goOs,omitempty"`
// GoArch holds architecture name.
GoArch string `json:"goArch,omitempty"`
GoArch string `json:"goArch,omitempty" yaml:"goArch,omitempty"`
// GoVersion holds Go version.
GoVersion string `json:"goVersion,omitempty" yaml:"goVersion,omitempty"`
}
// GetProvenance returns an instance of Provenance.
func GetProvenance() Provenance {
return Provenance{
version,
gitCommit,
buildDate,
goos,
goarch,
p := Provenance{
BuildDate: buildDate,
Version: version,
GitCommit: "unknown",
GoOs: runtime.GOOS,
GoArch: runtime.GOARCH,
GoVersion: runtime.Version(),
}
info, ok := debug.ReadBuildInfo()
if !ok {
return p
}
}
// Full returns the full provenance stamp.
func (v Provenance) Full() string {
return fmt.Sprintf("%+v", v)
for _, setting := range info.Settings {
// For now, the git commit is the only information of interest.
// We could consider adding other info such as the commit date in the future.
if setting.Key == "vcs.revision" {
p.GitCommit = setting.Value
}
}
return p
}
// Short returns the shortened provenance stamp.

View File

@@ -0,0 +1,47 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package provenance_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"sigs.k8s.io/kustomize/api/provenance"
)
const expectedBuildDateFromLdFlag = "2023-01-31T23:38:41Z"
const expectedVersionFromLdFlag = "(test)"
func TestGetProvenance(t *testing.T) {
p := provenance.GetProvenance()
// These are set by ldflags in our Makefile
assert.Equal(t, expectedVersionFromLdFlag, p.Version)
assert.Equal(t, expectedBuildDateFromLdFlag, p.BuildDate)
// This comes from BuildInfo, which is not set during go test: https://github.com/golang/go/issues/33976
assert.Equal(t, "unknown", p.GitCommit)
// These are set properly during go test
assert.NotEmpty(t, p.GoArch)
assert.NotEmpty(t, p.GoOs)
assert.Contains(t, p.GoVersion, "go1.")
}
func TestProvenance_Short(t *testing.T) {
p := provenance.GetProvenance()
// The version not set during go test, so this comes from an ldflag: https://github.com/golang/go/issues/33976
assert.Equal(t, fmt.Sprintf("{%s %s }", expectedVersionFromLdFlag, expectedBuildDateFromLdFlag), p.Short())
p.Version = "kustomize/v4.11.12"
assert.Equal(t, fmt.Sprintf("{kustomize/v4.11.12 %s }", expectedBuildDateFromLdFlag), p.Short())
}
func TestProvenance_Semver(t *testing.T) {
p := provenance.GetProvenance()
// The version not set during go test
assert.Equal(t, "(test)", p.Semver())
p.Version = "kustomize/v4.11.12"
assert.Equal(t, "v4.11.12", p.Semver())
}

View File

@@ -3,6 +3,8 @@
package types
import "path/filepath"
const HelmDefaultHome = "charts"
type HelmGlobals struct {
@@ -57,7 +59,11 @@ type HelmChart struct {
// in the helm template
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
// ValuesFile is local file path to a values file to use _instead of_
// AdditionalValuesFiles are local file paths to values files to be used in
// addition to either the default values file or the values specified in ValuesFile.
AdditionalValuesFiles []string `json:"additionalValuesFiles,omitempty" yaml:"additionalValuesFiles,omitempty"`
// ValuesFile is a local file path to a values file to use _instead of_
// the default values that accompanied the chart.
// The default values are in '{ChartHome}/{Name}/values.yaml'.
ValuesFile string `json:"valuesFile,omitempty" yaml:"valuesFile,omitempty"`
@@ -78,6 +84,15 @@ type HelmChart struct {
// SkipHooks sets the --no-hooks flag when calling helm template. This prevents
// helm from erroneously rendering test templates.
SkipHooks bool `json:"skipHooks,omitempty" yaml:"skipHooks,omitempty"`
// ApiVersions is the kubernetes apiversions used for Capabilities.APIVersions
ApiVersions []string `json:"apiVersions,omitempty" yaml:"apiVersions,omitempty"`
// NameTemplate is for specifying the name template used to name the release.
NameTemplate string `json:"nameTemplate,omitempty" yaml:"nameTemplate,omitempty"`
// SkipTests skips tests from templated output.
SkipTests bool `json:"skipTests,omitempty" yaml:"skipTests,omitempty"`
}
// HelmChartArgs contains arguments to helm.
@@ -126,3 +141,45 @@ func makeHelmChartFromHca(old *HelmChartArgs) (c HelmChart) {
c.ReleaseName = old.ReleaseName
return
}
func (h HelmChart) AsHelmArgs(absChartHome string) []string {
args := []string{"template"}
if h.ReleaseName != "" {
args = append(args, h.ReleaseName)
} else {
// AFAICT, this doesn't work as intended due to a bug in helm.
// See https://github.com/helm/helm/issues/6019
// I've tried placing the flag before and after the name argument.
args = append(args, "--generate-name")
}
if h.Name != "" {
args = append(args, filepath.Join(absChartHome, h.Name))
}
if h.Namespace != "" {
args = append(args, "--namespace", h.Namespace)
}
if h.NameTemplate != "" {
args = append(args, "--name-template", h.NameTemplate)
}
if h.ValuesFile != "" {
args = append(args, "-f", h.ValuesFile)
}
for _, valuesFile := range h.AdditionalValuesFiles {
args = append(args, "-f", valuesFile)
}
for _, apiVer := range h.ApiVersions {
args = append(args, "--api-versions", apiVer)
}
if h.IncludeCRDs {
args = append(args, "--include-crds")
}
if h.SkipTests {
args = append(args, "--skip-tests")
}
if h.SkipHooks {
args = append(args, "--no-hooks")
}
return args
}

View File

@@ -0,0 +1,61 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package types_test
import (
"testing"
"github.com/stretchr/testify/require"
"sigs.k8s.io/kustomize/api/types"
)
func TestAsHelmArgs(t *testing.T) {
t.Run("use generate-name", func(t *testing.T) {
p := types.HelmChart{
Name: "chart-name",
Version: "1.0.0",
Repo: "https://helm.releases.hashicorp.com",
ApiVersions: []string{"foo", "bar"},
NameTemplate: "template",
SkipTests: true,
IncludeCRDs: true,
SkipHooks: true,
ValuesFile: "values",
AdditionalValuesFiles: []string{"values1", "values2"},
Namespace: "my-ns",
}
require.Equal(t, p.AsHelmArgs("/home/charts"),
[]string{"template", "--generate-name",
"/home/charts/chart-name",
"--namespace", "my-ns",
"--name-template", "template",
"-f", "values",
"-f", "values1", "-f", "values2",
"--api-versions", "foo", "--api-versions", "bar",
"--include-crds",
"--skip-tests",
"--no-hooks"})
})
t.Run("use release-name", func(t *testing.T) {
p := types.HelmChart{
Name: "chart-name",
Version: "1.0.0",
Repo: "https://helm.releases.hashicorp.com",
ApiVersions: []string{"foo", "bar"},
NameTemplate: "template",
ValuesFile: "values",
AdditionalValuesFiles: []string{"values1", "values2"},
Namespace: "my-ns",
ReleaseName: "test",
}
require.Equal(t, p.AsHelmArgs("/home/charts"),
[]string{"template", "test", "/home/charts/chart-name",
"--namespace", "my-ns",
"--name-template", "template",
"-f", "values",
"-f", "values1", "-f", "values2",
"--api-versions", "foo", "--api-versions", "bar"})
})
}

View File

@@ -4,6 +4,8 @@
package types
import (
"bytes"
"encoding/json"
"fmt"
"sigs.k8s.io/kustomize/kyaml/errors"
@@ -12,11 +14,13 @@ import (
)
const (
KustomizationVersion = "kustomize.config.k8s.io/v1beta1"
KustomizationKind = "Kustomization"
ComponentVersion = "kustomize.config.k8s.io/v1alpha1"
ComponentKind = "Component"
MetadataNamespacePath = "metadata/namespace"
KustomizationVersion = "kustomize.config.k8s.io/v1beta1"
KustomizationKind = "Kustomization"
ComponentVersion = "kustomize.config.k8s.io/v1alpha1"
ComponentKind = "Component"
MetadataNamespacePath = "metadata/namespace"
MetadataNamespaceApiVersion = "v1"
MetadataNamePath = "metadata/name"
OriginAnnotations = "originAnnotations"
TransformerAnnotations = "transformerAnnotations"
@@ -313,8 +317,20 @@ func (k *Kustomization) EnforceFields() []string {
// Unmarshal replace k with the content in YAML input y
func (k *Kustomization) Unmarshal(y []byte) error {
if err := yaml.UnmarshalStrict(y, &k); err != nil {
// TODO: switch to strict decoding to catch duplicate keys.
// We can't do so until there is a yaml decoder that supports anchors AND case-insensitive keys.
// See https://github.com/kubernetes-sigs/kustomize/issues/5061
j, err := yaml.YAMLToJSON(y)
if err != nil {
return errors.WrapPrefixf(err, "invalid Kustomization")
}
dec := json.NewDecoder(bytes.NewReader(j))
dec.DisallowUnknownFields()
var nk Kustomization
err = dec.Decode(&nk)
if err != nil {
return errors.WrapPrefixf(err, "invalid Kustomization")
}
*k = nk
return nil
}

View File

@@ -278,7 +278,7 @@ unknown: foo`)
if err == nil {
t.Fatalf("expect an error")
}
expect := "invalid Kustomization: error unmarshaling JSON: while decoding JSON: json: unknown field \"unknown\""
expect := "invalid Kustomization: json: unknown field \"unknown\""
if err.Error() != expect {
t.Fatalf("expect %v but got: %v", expect, err.Error())
}

View File

@@ -1,6 +0,0 @@
# See https://github.com/kubernetes/community/blob/master/community-membership.md
approvers:
- kyaml-approvers
reviewers:
- kyaml-reviewers

View File

@@ -7,7 +7,7 @@ require (
github.com/spf13/cobra v1.4.0
github.com/stretchr/testify v1.8.1
gopkg.in/inf.v0 v0.9.1
sigs.k8s.io/kustomize/kyaml v0.13.9
sigs.k8s.io/kustomize/kyaml v0.14.2
)
require (
@@ -23,7 +23,6 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect

View File

@@ -60,8 +60,6 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
@@ -153,7 +151,7 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596 h1:8cNCQs+WqqnSpZ7y0LMQPKD+RZUHU17VqLPMW3qxnxc=
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596/go.mod h1:/BYxry62FuDzmI+i9B+X2pqfySRmSOW2ARmj5Zbqhj0=
sigs.k8s.io/kustomize/kyaml v0.13.9 h1:Qz53EAaFFANyNgyOEJbT/yoIHygK40/ZcvU3rgry2Tk=
sigs.k8s.io/kustomize/kyaml v0.13.9/go.mod h1:QsRbD0/KcU+wdk0/L0fIp2KLnohkVzs6fQ85/nOXac4=
sigs.k8s.io/kustomize/kyaml v0.14.2 h1:9WSwztbzwGszG1bZTziQUmVMrJccnyrLb5ZMKpJGvXw=
sigs.k8s.io/kustomize/kyaml v0.14.2/go.mod h1:AN1/IpawKilWD7V+YvQwRGUvuUOOWpjsHu6uHwonSF4=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=

View File

@@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/assert"
"sigs.k8s.io/kustomize/cmd/config/internal/commands"
"sigs.k8s.io/kustomize/kyaml/copyutil"
"sigs.k8s.io/kustomize/kyaml/filesys"
"sigs.k8s.io/kustomize/kyaml/openapi"
)
@@ -614,7 +615,7 @@ spec:
defer openapi.ResetOpenAPI()
sourceDir := filepath.Join("test", "testdata", test.dataset)
baseDir := t.TempDir()
copyutil.CopyDir(sourceDir, baseDir)
assert.NoError(t, copyutil.CopyDir(filesys.MakeFsOnDisk(), sourceDir, baseDir))
runner := commands.GetCatRunner("")
actual := &bytes.Buffer{}
runner.Command.SetOut(actual)

View File

@@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/assert"
"sigs.k8s.io/kustomize/cmd/config/internal/commands"
"sigs.k8s.io/kustomize/kyaml/copyutil"
"sigs.k8s.io/kustomize/kyaml/filesys"
"sigs.k8s.io/kustomize/kyaml/openapi"
)
@@ -117,7 +118,7 @@ Deployment: 1
defer openapi.ResetOpenAPI()
sourceDir := filepath.Join("test", "testdata", test.dataset)
baseDir := t.TempDir()
copyutil.CopyDir(sourceDir, baseDir)
assert.NoError(t, copyutil.CopyDir(filesys.MakeFsOnDisk(), sourceDir, baseDir))
runner := commands.GetCountRunner("")
actual := &bytes.Buffer{}
runner.Command.SetOut(actual)

View File

@@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/assert"
"sigs.k8s.io/kustomize/cmd/config/internal/commands"
"sigs.k8s.io/kustomize/kyaml/copyutil"
"sigs.k8s.io/kustomize/kyaml/filesys"
)
// TestGrepCommand_files verifies grep reads the files and filters them
@@ -396,7 +397,7 @@ spec:
t.Run(test.name, func(t *testing.T) {
sourceDir := filepath.Join("test", "testdata", test.dataset)
baseDir := t.TempDir()
copyutil.CopyDir(sourceDir, baseDir)
assert.NoError(t, copyutil.CopyDir(filesys.MakeFsOnDisk(), sourceDir, baseDir))
runner := commands.GetGrepRunner("")
actual := &bytes.Buffer{}
runner.Command.SetOut(actual)

View File

@@ -40,12 +40,12 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/cobra v1.4.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.3.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect

View File

@@ -376,8 +376,8 @@ golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -443,8 +443,8 @@ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU=
golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -496,18 +496,18 @@ golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201112073958-5cba982894dd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI=
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

View File

@@ -36,7 +36,6 @@ var (
"docs",
"examples",
"hack",
"plugin",
"releasing",
"site",
}

View File

@@ -34,7 +34,7 @@ func (e *Editor) run(args ...string) error {
if e.doIt {
out, err := c.CombinedOutput()
if err != nil {
return fmt.Errorf("%s out=%q", err.Error(), out)
return fmt.Errorf("failed to run go mod command in %s: %w (stdout=%q)", e.module.ShortName(), err, out)
}
} else {
fmt.Printf("in %-60s; %s\n", c.Dir, c.String())
@@ -57,6 +57,8 @@ func (e *Editor) Tidy() error {
func (e *Editor) Pin(target misc.LaModule, oldV, newV semver.SemVer) error {
err := e.run(
"edit",
"-dropreplace="+target.ImportPath(),
"-dropreplace="+target.ImportPath()+"@"+oldV.String(),
"-require="+target.ImportPath()+"@"+newV.String(),
)
if err != nil {

View File

@@ -45,8 +45,9 @@ func (dg *DotGitData) AbsPath() string {
// NewDotGitDataFromPath wants the incoming path to hold dotGit
// E.g.
// ~/gopath/src/sigs.k8s.io/kustomize
// ~/gopath/src/github.com/monopole/gorepomod
//
// ~/gopath/src/sigs.k8s.io/kustomize
// ~/gopath/src/github.com/monopole/gorepomod
func NewDotGitDataFromPath(path string) (*DotGitData, error) {
if !utils.DirExists(filepath.Join(path, dotGitFileName)) {
return nil, fmt.Errorf(

View File

@@ -5,8 +5,8 @@ go 1.19
require (
github.com/spf13/cobra v1.4.0
github.com/stretchr/testify v1.8.1
sigs.k8s.io/kustomize/api v0.12.1
sigs.k8s.io/kustomize/kyaml v0.13.9
sigs.k8s.io/kustomize/api v0.13.3
sigs.k8s.io/kustomize/kyaml v0.14.2
)
require (
@@ -25,7 +25,6 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
@@ -37,3 +36,5 @@ require (
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
replace sigs.k8s.io/kustomize/api => ../../api

View File

@@ -66,7 +66,6 @@ github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
@@ -156,9 +155,7 @@ k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596 h1:8cNCQs+WqqnSpZ7y0LMQPK
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596/go.mod h1:/BYxry62FuDzmI+i9B+X2pqfySRmSOW2ARmj5Zbqhj0=
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 h1:HNSDgDCrr/6Ly3WEGKZftiE7IY19Vz2GdbOCyI4qqhc=
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
sigs.k8s.io/kustomize/api v0.12.1 h1:7YM7gW3kYBwtKvoY216ZzY+8hM+lV53LUayghNRJ0vM=
sigs.k8s.io/kustomize/api v0.12.1/go.mod h1:y3JUhimkZkR6sbLNwfJHxvo1TCLwuwm14sCYnkH6S1s=
sigs.k8s.io/kustomize/kyaml v0.13.9 h1:Qz53EAaFFANyNgyOEJbT/yoIHygK40/ZcvU3rgry2Tk=
sigs.k8s.io/kustomize/kyaml v0.13.9/go.mod h1:QsRbD0/KcU+wdk0/L0fIp2KLnohkVzs6fQ85/nOXac4=
sigs.k8s.io/kustomize/kyaml v0.14.2 h1:9WSwztbzwGszG1bZTziQUmVMrJccnyrLb5ZMKpJGvXw=
sigs.k8s.io/kustomize/kyaml v0.14.2/go.mod h1:AN1/IpawKilWD7V+YvQwRGUvuUOOWpjsHu6uHwonSF4=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=

View File

@@ -31,9 +31,9 @@ require (
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect

View File

@@ -551,8 +551,8 @@ golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -638,8 +638,8 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU=
golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -720,9 +720,9 @@ golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI=
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -733,8 +733,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

View File

@@ -0,0 +1,25 @@
export KUSTOMIZE_ROOT ?= $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\1|')
include $(KUSTOMIZE_ROOT)/Makefile-modules.mk
CONTROLLER_GEN_VERSION=v0.11.3
generate: $(MYGOBIN)/controller-gen $(MYGOBIN)/embedmd
go generate ./...
embedmd -w README.md
build: generate
go build -v -o $(MYGOBIN)/app-fn cmd/main.go
$(MYGOBIN)/controller-gen:
go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)
$(MYGOBIN)/embedmd:
go install github.com/campoy/embedmd@v1.0.0
.PHONY: example
example: build
$(MYGOBIN)/app-fn pkg/exampleapp/testdata/success/basic/config.yaml
test: generate
go test -v -timeout 45m -cover ./...

View File

@@ -0,0 +1,132 @@
## Kyaml Functions Framework Example: Application Custom Resource
This is a moderate-complexity example of a KRM function built using the [KRM Functions Framework package](https://pkg.go.dev/sigs.k8s.io/kustomize/kyaml/fn/framework). It demonstrates how to write a function that implements a custom resource (CR) representing an abstract application.
[embedmd]:# (pkg/exampleapp/v1alpha1/testdata/success/basic/config.yaml)
```yaml
apiVersion: platform.example.com/v1alpha1
kind: ExampleApp
metadata:
name: simple-app-sample
env: production
workloads:
webWorkers:
- name: web-worker
domains:
- example.com
jobWorkers:
- name: job-worker
replicas: 10
resources: medium
queues:
- high
- medium
- low
- name: job-worker-2
replicas: 5
queues:
- bg2
datastores:
postgresInstance: simple-app-sample-postgres
```
It also demonstrates the pattern of having the CR accept patches, allowing the user to customize the final result beyond the fields the CR exposes.
[embedmd]:# (pkg/exampleapp/v1alpha1/testdata/success/overrides/config.yaml)
```yaml
apiVersion: platform.example.com/v1alpha1
kind: ExampleApp
metadata:
name: simple-app-sample
env: production
workloads:
webWorkers:
- name: web-worker
domains:
- first.example.com
- name: web-worker-no-sidecar
domains:
- second.example.com
overrides:
additionalResources:
- custom-configmap.yaml
resourcePatches:
- web-worker-sidecar.yaml
containerPatches:
- custom-app-env.yaml
```
## Implementation walkthrough
The entrypoint for the function is [cmd/main.go](cmd/main.go), which invokes a ["dispatcher"](pkg/dispatcher/dispatcher.go) that determines which `Filter` implements the resource passed in. The dispatcher pattern allows a single function binary to handle multiple CRs, and is also useful for evolving a single CR over time (e.g. handle `ExampleApp` API versions `example.com/v1beta1` and `example.com/v1`).
[embedmd]:# (pkg/dispatcher/dispatcher.go go /.*VersionedAPIProcessor.*/ /}}/)
```go
p := framework.VersionedAPIProcessor{FilterProvider: framework.GVKFilterMap{
"ExampleApp": map[string]kio.Filter{
"platform.example.com/v1alpha1": &v1alpha1.ExampleApp{},
},
}}
```
The ExampleApp type is defined in [pkg/exampleapp/v1alpha1/types.go](pkg/exampleapp/v1alpha1/types.go). It is responsible for implementing the logic of the CR, most of which is done by implementing the `kyaml.Filter` interface in [pkg/exampleapp/v1alpha1/processing.go](pkg/exampleapp/v1alpha1/processing.go). Internally, the filter function mostly builds up and executes a `framework.TemplateProcessor`.
The ExampleApp type is annotated with [kubebuilder markers](https://book.kubebuilder.io/reference/markers/crd-validation.html), and a Go generator uses those to create the CRD YAML in [pkg/exampleapp/v1alpha1/platform.example.com_exampleapps.yaml](pkg/exampleapp/v1alpha1/platform.example.com_exampleapps.yaml). The CR then implements `framework.ValidationSchemaProvider`, which causes the CRD to be used for validation. It also implements `framework.Validator` to add custom validations and `framework.Defaulter` to add defaulting.
[embedmd]:# (pkg/exampleapp/v1alpha1/types.go go /.*type ExampleApp.*/ /}/)
```go
type ExampleApp struct {
// Embedding these structs is required to use controller-gen to produce the CRD
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
// +kubebuilder:validation:Enum=production;staging;development
Env string `json:"env" yaml:"env"`
// +optional
AppImage string `json:"appImage" yaml:"appImage"`
Workloads Workloads `json:"workloads" yaml:"workloads"`
// +optional
Datastores Datastores `json:"datastores,omitempty" yaml:"datastores,omitempty"`
// +optional
Overrides Overrides `json:"overrides,omitempty" yaml:"overrides,omitempty"`
}
```
[embedmd]:# (pkg/exampleapp/v1alpha1/processing.go go /.*Filter.*/ /error\) {/)
```go
func (a ExampleApp) Filter(items []*yaml.RNode) ([]*yaml.RNode, error) {
```
[embedmd]:# (pkg/exampleapp/v1alpha1/processing.go go /.*Schema.*/ /error\) {/)
```go
func (a *ExampleApp) Schema() (*spec.Schema, error) {
```
[embedmd]:# (pkg/exampleapp/v1alpha1/processing.go go /.*Validate.*/ /error {/)
```go
func (a *ExampleApp) Validate() error {
```
[embedmd]:# (pkg/exampleapp/v1alpha1/processing.go go /.*Default.*/ /error {/)
```go
func (a *ExampleApp) Default() error {
```
## Running the Example
There are three ways to try this out:
A. Run `make example` in the root of the example to run the function with the test data in [pkg/exampleapp/v1alpha1/testdata/success/basic](pkg/exampleapp/v1alpha1/testdata/success/basic).
B. Run `go run cmd/main.go [FILE]` in the root of the example. Try it with the test input from one of the cases in [pkg/exampleapp/v1alpha1/testdata/success](pkg/exampleapp/v1alpha1/testdata/success). For example: `go run cmd/main.go pkg/exampleapp/v1alpha1/testdata/success/basic/config.yaml`.
C. Build the binary with `make build`, then run it with `app-fn [FILE]`. Try it with the test input from one of the cases in [pkg/exampleapp/v1alpha1/testdata/success](pkg/exampleapp/v1alpha1/testdata/success). For example: `app-fn pkg/exampleapp/v1alpha1/testdata/success/basic/config.yaml`.

View File

@@ -0,0 +1,10 @@
// Copyright 2023 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package main
import "sigs.k8s.io/kustomize/functions/examples/fn-framework-application/pkg/dispatcher"
func main() {
_ = dispatcher.NewCommand().Execute()
}

View File

@@ -0,0 +1,50 @@
module sigs.k8s.io/kustomize/functions/examples/fn-framework-application
go 1.19
require (
github.com/spf13/cobra v1.4.0
k8s.io/apimachinery v0.27.0
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a
sigs.k8s.io/kustomize/kyaml v0.14.1
)
require (
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

View File

@@ -0,0 +1,207 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
github.com/go-openapi/jsonreference v0.20.1 h1:FBLnyygC4/IZZr893oiomc9XaghoveYTrLC1F86HID8=
github.com/go-openapi/jsonreference v0.20.1/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/gnostic v0.5.7-v3refs h1:FhTMOKj2VhjpouxvWJAV1TL304uMlb9zcDqkl6cEI54=
github.com/google/gnostic v0.5.7-v3refs/go.mod h1:73MKFl6jIHelAJNaBGFzt3SPtZULs9dYrGFt8OiIsHQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/xlab/treeprint v1.1.0 h1:G/1DjNkPpfZCFt9CSh6b5/nY4VimlbHF3Rh4obvtzDk=
github.com/xlab/treeprint v1.1.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/apimachinery v0.27.0 h1:vEyy/PVMbPMCPutrssCVHCf0JNZ0Px+YqPi82K2ALlk=
k8s.io/apimachinery v0.27.0/go.mod h1:5ikh59fK3AJ287GUvpUsryoMFtH9zj/ARfWCo3AyXTM=
k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw=
k8s.io/klog/v2 v2.90.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a h1:gmovKNur38vgoWfGtP5QOGNOA7ki4n6qNYoFAgMlNvg=
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a/go.mod h1:y5VtZWM9sHHc2ZodIH/6SHzXj+TPU5USoA8lcIeKEKY=
k8s.io/utils v0.0.0-20230209194617-a36077c30491 h1:r0BAOLElQnnFhE/ApUsg3iHdVYYPBjNSSOMowRZxxsY=
k8s.io/utils v0.0.0-20230209194617-a36077c30491/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/kustomize/kyaml v0.14.1 h1:c8iibius7l24G2wVAGZn/Va2wNys03GXLjYVIcFVxKA=
sigs.k8s.io/kustomize/kyaml v0.14.1/go.mod h1:AN1/IpawKilWD7V+YvQwRGUvuUOOWpjsHu6uHwonSF4=
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=
sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=

View File

@@ -0,0 +1,41 @@
// Copyright 2023 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package dispatcher
import (
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/functions/examples/fn-framework-application/pkg/exampleapp/v1alpha1"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/fn/framework"
"sigs.k8s.io/kustomize/kyaml/fn/framework/command"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/kio/filters"
)
func New() framework.ResourceListProcessor {
return framework.ResourceListProcessorFunc(processKnownAPIGroups)
}
func NewCommand() *cobra.Command {
return command.Build(New(), command.StandaloneEnabled, false)
}
func processKnownAPIGroups(rl *framework.ResourceList) error {
p := framework.VersionedAPIProcessor{FilterProvider: framework.GVKFilterMap{
"ExampleApp": map[string]kio.Filter{
"platform.example.com/v1alpha1": &v1alpha1.ExampleApp{},
},
}}
if err := p.Process(rl); err != nil {
return errors.Wrap(err)
}
var err error
// FormatFilter sorts the fields in a deterministic order, which makes the output
// more suitable for review in version control.
rl.Items, err = filters.FormatFilter{UseSchema: true}.Filter(rl.Items)
if err != nil {
return errors.WrapPrefixf(err, "formatting output")
}
return nil
}

View File

@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Copyright 2023 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
set -eo pipefail
# This generates a useful starting point for a CRD that can be used for validation.
echo " - Generating CRD"
controller-gen crd paths=./... output:crd:dir=.
# controller-gen does not currently support "additionalProperties: false".
# This hack adds it manually to all properties sections of the schema.
echo " - Adding additionalProperties: false to all properties sections"
if [[ "$OSTYPE" == linux* ]]; then
# Linux (GNU sed) expression
sed -i "s/\(^[[:space:]]*\)properties:/\1additionalProperties: false\n\1properties:/g" ./platform.example.com_exampleapps.yaml
elif [[ "$OSTYPE" == darwin* ]]; then
# macOS (BSD sed) expression
sed -i "" "s/\(^[[:space:]]*\)properties:/\1additionalProperties: false\n\1properties:/g" ./platform.example.com_exampleapps.yaml
else
echo "Unsupported OS: $OSTYPE"
exit 1
fi

View File

@@ -0,0 +1,20 @@
// Copyright 2023 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package v1alpha1_test
import (
"testing"
"sigs.k8s.io/kustomize/functions/examples/fn-framework-application/pkg/dispatcher"
"sigs.k8s.io/kustomize/kyaml/fn/framework/frameworktestutil"
)
func TestExampleApp_GoldenFiles(t *testing.T) {
c := frameworktestutil.CommandResultsChecker{
Command: dispatcher.NewCommand,
// TestDataDirectory: "testdata/success",
// UpdateExpectedFromActual: true,
}
c.Assert(t)
}

View File

@@ -0,0 +1,131 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.3
creationTimestamp: null
name: exampleapps.platform.example.com
spec:
group: platform.example.com
names:
kind: ExampleApp
listKind: ExampleAppList
plural: exampleapps
singular: exampleapp
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
additionalProperties: false
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
appImage:
type: string
datastores:
additionalProperties: false
properties:
postgresInstance:
type: string
type: object
env:
enum:
- production
- staging
- development
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
overrides:
minProperties: 1
additionalProperties: false
properties:
additionalResources:
items:
type: string
type: array
containerPatches:
items:
type: string
type: array
resourcePatches:
items:
type: string
type: array
type: object
workloads:
minProperties: 1
additionalProperties: false
properties:
jobWorkers:
items:
additionalProperties: false
properties:
name:
pattern: ^[a-z0-9](?:[-a-z0-9]*[a-z0-9])?(?:\.[a-z0-9](?:[-a-z0-9]*[a-z0-9])?)*$
type: string
queues:
items:
type: string
minItems: 1
type: array
uniqueItems: true
replicas:
minimum: 0
type: integer
resources:
enum:
- small
- medium
- large
type: string
required:
- name
- queues
type: object
type: array
webWorkers:
items:
additionalProperties: false
properties:
domains:
items:
type: string
minItems: 1
type: array
uniqueItems: true
name:
pattern: ^[a-z0-9](?:[-a-z0-9]*[a-z0-9])?(?:\.[a-z0-9](?:[-a-z0-9]*[a-z0-9])?)*$
type: string
replicas:
minimum: 0
type: integer
resources:
enum:
- small
- medium
- large
type: string
required:
- domains
- name
type: object
type: array
type: object
required:
- env
- metadata
- workloads
type: object
served: true
storage: true

View File

@@ -0,0 +1,219 @@
// Copyright 2023 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package v1alpha1
import (
"bytes"
"embed"
"encoding/json"
"fmt"
"strings"
"k8s.io/kube-openapi/pkg/validation/spec"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/fn/framework"
"sigs.k8s.io/kustomize/kyaml/fn/framework/parser"
"sigs.k8s.io/kustomize/kyaml/resid"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
//go:embed templates/*
var templateFS embed.FS
func (a *ExampleApp) Schema() (*spec.Schema, error) {
schema, err := framework.SchemaFromFunctionDefinition(resid.NewGvk(Group, Version, Kind), CRDString)
return schema, errors.WrapPrefixf(err, "parsing %s schema", Kind)
}
func (a *ExampleApp) Default() error {
if a.AppImage == "" {
a.AppImage = fmt.Sprintf("registry.example.com/path/to/%s", a.ObjectMeta.Name)
}
for i := range a.Workloads.WebWorkers {
if a.Workloads.WebWorkers[i].Replicas == nil {
a.Workloads.WebWorkers[i].Replicas = func() *int { three := 3; return &three }()
}
if a.Workloads.WebWorkers[i].Resources == "" {
a.Workloads.WebWorkers[i].Resources = ResourceBinSizeSmall
}
}
for i := range a.Workloads.JobWorkers {
if a.Workloads.JobWorkers[i].Replicas == nil {
a.Workloads.JobWorkers[i].Replicas = func() *int { one := 1; return &one }()
}
if a.Workloads.JobWorkers[i].Resources == "" {
a.Workloads.JobWorkers[i].Resources = ResourceBinSizeSmall
}
}
return nil
}
func (a *ExampleApp) Validate() error {
seenDomains := make(map[string]bool)
for i, worker := range a.Workloads.WebWorkers {
for _, domain := range worker.Domains {
if seenDomains[domain] {
return errors.Errorf("duplicate domain %q in worker %d", domain, i)
}
seenDomains[domain] = true
}
}
return nil
}
func (a ExampleApp) Filter(items []*yaml.RNode) ([]*yaml.RNode, error) {
templates := make([]framework.ResourceTemplate, 0)
for _, worker := range a.Workloads.JobWorkers {
templates = append(templates, framework.ResourceTemplate{
Templates: parser.TemplateFiles("templates/job_worker.template.yaml").FromFS(templateFS),
TemplateData: a.jobWorkerTemplateData(worker),
})
}
for _, worker := range a.Workloads.WebWorkers {
templates = append(templates, framework.ResourceTemplate{
Templates: parser.TemplateFiles("templates/web_worker.template.yaml").FromFS(templateFS),
TemplateData: a.webWorkerTemplateData(worker),
})
}
var patches []framework.PatchTemplate
if a.Datastores.PostgresInstance != "" {
templates = append(templates, framework.ResourceTemplate{
TemplateData: map[string]interface{}{"Name": a.Datastores.PostgresInstance},
Templates: parser.TemplateStrings(`apiVersion: apps.example.com/v1
kind: PostgresSecretRequest
metadata:
name: {{ .Name }}
`)})
patches = append(patches, framework.PatchTemplate(&framework.ContainerPatchTemplate{
Templates: parser.TemplateFiles("templates/postgres_secret_env_patch.template.yaml").FromFS(templateFS),
ContainerMatcher: framework.ContainerNameMatcher("app"),
}))
}
if len(a.Overrides.AdditionalResources) > 0 {
templates = append(templates, framework.ResourceTemplate{
Templates: parser.TemplateFiles(a.Overrides.AdditionalResources...).WithExtensions(".yaml", ".template.yaml"),
TemplateData: a,
})
}
for i, resource := range a.Overrides.ResourcePatches {
overridePatches, err := a.resourceSMPsFromOverrides(resource, i, patches)
if err != nil {
return nil, err
}
patches = append(patches, overridePatches...)
}
if len(a.Overrides.ContainerPatches) > 0 {
patches = append(patches, framework.PatchTemplate(&framework.ContainerPatchTemplate{
Templates: parser.TemplateFiles(a.Overrides.ContainerPatches...).WithExtensions(".yaml", ".template.yaml"),
TemplateData: a,
}))
}
items, err := framework.TemplateProcessor{
ResourceTemplates: templates,
PatchTemplates: patches,
}.Filter(items)
if err != nil {
return nil, errors.WrapPrefixf(err, "processing templates")
}
return items, nil
}
// resourceSMPsFromOverrides parses the resource template and returns a patch that
// is targeted to match resources with the same GVKNN the patch itself contains.
// TODO: This is standard SMP semantics, so the framework should make this easier.
func (a ExampleApp) resourceSMPsFromOverrides(resource string, i int, patches []framework.PatchTemplate) ([]framework.PatchTemplate, error) {
tpl, err := parser.TemplateFiles(resource).WithExtensions(".yaml", ".template.yaml").Parse()
if err != nil {
return nil, errors.WrapPrefixf(err, "parsing resource template %d", i)
}
for _, template := range tpl {
var b bytes.Buffer
if err := template.Execute(&b, a); err != nil {
return nil, errors.WrapPrefixf(err, "failed to render patch template %v", template.DefinedTemplates())
}
var id yaml.ResourceMeta
err := yaml.Unmarshal(b.Bytes(), &id)
if err != nil {
return nil, errors.WrapPrefixf(err, "failed to unmarshal resource identifier from %v", template.DefinedTemplates())
}
selector := framework.MatchAll(
framework.GVKMatcher(strings.Join([]string{id.APIVersion, id.Kind}, "/")), framework.NameMatcher(id.Name),
framework.NamespaceMatcher(id.Namespace))
selector.FailOnEmptyMatch = true
patches = append(patches, framework.PatchTemplate(&framework.ResourcePatchTemplate{
Templates: parser.TemplateFiles(a.Overrides.ResourcePatches...).WithExtensions(".yaml", ".template.yaml"),
Selector: selector,
}))
}
return patches, nil
}
type resourceBucket struct {
Requests resourceAllocation `yaml:"requests" json:"requests"`
Limits resourceAllocation `yaml:"limits" json:"limits"`
}
type resourceAllocation struct {
CPU string `yaml:"cpu" json:"cpu"`
Memory string `yaml:"memory" json:"memory"`
}
//nolint:gochecknoglobals
var resourceBucketConversion = map[ResourceBinSize]resourceBucket{
"small": {
Requests: resourceAllocation{CPU: "100m", Memory: "128Mi"},
Limits: resourceAllocation{CPU: "500m", Memory: "512Mi"},
},
"medium": {
Requests: resourceAllocation{CPU: "1", Memory: "1Gi"},
Limits: resourceAllocation{CPU: "2", Memory: "2Gi"},
},
"large": {
Requests: resourceAllocation{CPU: "8", Memory: "8Gi"},
Limits: resourceAllocation{CPU: "8", Memory: "8Gi"},
},
}
const anArbitraryMultiplier = 2
func (a ExampleApp) jobWorkerTemplateData(w JobWorker) map[string]interface{} {
resourcesJson, err := json.Marshal(resourceBucketConversion[w.Resources])
if err != nil {
panic("failed to marshal resources for job worker" + err.Error())
}
return map[string]interface{}{
"Name": w.Name,
"AppImage": a.AppImage,
"QueueList": strings.Join(w.Queues, ","),
"ProcessPoolSize": len(w.Queues) * anArbitraryMultiplier,
"Resources": string(resourcesJson),
"Replicas": w.Replicas,
"Environment": a.Env,
}
}
const containerPort = 8080
func (a ExampleApp) webWorkerTemplateData(w WebWorker) map[string]interface{} {
resourcesJson, err := json.Marshal(resourceBucketConversion[w.Resources])
if err != nil {
panic("failed to marshal resources for web worker" + err.Error())
}
return map[string]interface{}{
"Name": w.Name,
"AppImage": a.AppImage,
"Resources": string(resourcesJson),
"Replicas": w.Replicas,
"Port": containerPort,
"Environment": a.Env,
}
}

View File

@@ -0,0 +1,45 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
name: {{ .Name }}
env: {{ .Environment }}
type: jobs
name: {{ .Name }}
spec:
replicas: {{ .Replicas }}
selector:
matchLabels:
type: jobs
name: {{ .Name }}
env: {{ .Environment }}
template:
metadata:
labels:
type: jobs
name: {{ .Name }}
env: {{ .Environment }}
spec:
automountServiceAccountToken: false
containers:
- name: app
image: {{ .AppImage }}
args: [
"job-worker",
"--queues",
"{{ .QueueList }}",
"--workers", "{{ .ProcessPoolSize }}",
]
readinessProbe:
exec:
command:
- "bin/job-worker-readiness-probe"
resources: {{ .Resources }}
env:
- name: KUBE_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: ENV
value: {{ .Environment }}

View File

@@ -0,0 +1,6 @@
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: database-url
key: DATABASE_URL

View File

@@ -0,0 +1,50 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Name }}
labels:
name: {{ .Name }}
env: {{ .Environment }}
type: web
spec:
replicas: {{ .Replicas }}
selector:
matchLabels:
name: {{ .Name }}
env: {{ .Environment }}
type: web
template:
metadata:
labels:
name: {{ .Name }}
env: {{ .Environment }}
type: web
spec:
containers:
- name: app
image: {{ .AppImage }}
args:
- web
ports:
- containerPort: {{ .Port }}
name: http
readinessProbe:
httpGet:
path: "/ping"
port: {{ .Port }}
httpHeaders:
- name: "X-Forwarded-Proto"
value: "https"
initialDelaySeconds: 20
timeoutSeconds: 3
env:
- name: ENV
value: {{ .Environment }}
- name: PORT
value: "{{ .Port }}"
- name: KUBE_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
resources: {{ .Resources }}

View File

@@ -0,0 +1,21 @@
apiVersion: platform.example.com/v1alpha1
kind: ExampleApp
metadata:
name: simple-app-sample
env: invalid
workloads:
webWorkers:
- name: web-worker
replicas: -1
resources: small
domains:
- example.com
- name: web-worker-2
domains:
- example.com
jobWorkers:
- name: job-worker-$$
queues: []
datastores:
mongoDB: simple-app-sample-mongo
extraProperty: true

View File

@@ -0,0 +1,8 @@
validation failure list:
.extraProperty in body is a forbidden property
workloads.jobWorkers\[0\].name in body should match
workloads.jobWorkers\[0\].queues in body should have at least 1 items
workloads.webWorkers\[0\].replicas in body should be greater than or equal to 0
datastores.mongoDB in body is a forbidden property
env in body should be one of \[production staging development\]
duplicate domain \"example.com\" in worker 1

View File

@@ -0,0 +1,24 @@
apiVersion: platform.example.com/v1alpha1
kind: ExampleApp
metadata:
name: simple-app-sample
env: production
workloads:
webWorkers:
- name: web-worker
domains:
- example.com
jobWorkers:
- name: job-worker
replicas: 10
resources: medium
queues:
- high
- medium
- low
- name: job-worker-2
replicas: 5
queues:
- bg2
datastores:
postgresInstance: simple-app-sample-postgres

View File

@@ -0,0 +1,149 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: job-worker
labels:
name: job-worker
type: jobs
env: production
spec:
replicas: 10
selector:
matchLabels:
name: job-worker
type: jobs
env: production
template:
metadata:
labels:
name: job-worker
type: jobs
env: production
spec:
automountServiceAccountToken: false
containers:
- name: app
image: registry.example.com/path/to/simple-app-sample
args: ["job-worker", "--queues", "high,medium,low", "--workers", "6"]
env:
- name: KUBE_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: ENV
value: production
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: database-url
key: DATABASE_URL
resources: {"limits": {"cpu": "2", "memory": "2Gi"}, "requests": {"cpu": "1", "memory": "1Gi"}}
readinessProbe:
exec:
command:
- "bin/job-worker-readiness-probe"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: job-worker-2
labels:
name: job-worker-2
type: jobs
env: production
spec:
replicas: 5
selector:
matchLabels:
name: job-worker-2
type: jobs
env: production
template:
metadata:
labels:
name: job-worker-2
type: jobs
env: production
spec:
automountServiceAccountToken: false
containers:
- name: app
image: registry.example.com/path/to/simple-app-sample
args: ["job-worker", "--queues", "bg2", "--workers", "2"]
env:
- name: KUBE_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: ENV
value: production
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: database-url
key: DATABASE_URL
resources: {"limits": {"cpu": "500m", "memory": "512Mi"}, "requests": {"cpu": "100m", "memory": "128Mi"}}
readinessProbe:
exec:
command:
- "bin/job-worker-readiness-probe"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-worker
labels:
name: web-worker
type: web
env: production
spec:
replicas: 3
selector:
matchLabels:
name: web-worker
type: web
env: production
template:
metadata:
labels:
name: web-worker
type: web
env: production
spec:
containers:
- name: app
image: registry.example.com/path/to/simple-app-sample
args:
- web
ports:
- name: http
containerPort: 8080
env:
- name: ENV
value: production
- name: PORT
value: "8080"
- name: KUBE_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: database-url
key: DATABASE_URL
resources: {"limits": {"cpu": "500m", "memory": "512Mi"}, "requests": {"cpu": "100m", "memory": "128Mi"}}
readinessProbe:
httpGet:
port: 8080
httpHeaders:
- name: "X-Forwarded-Proto"
value: "https"
path: "/ping"
initialDelaySeconds: 20
timeoutSeconds: 3
---
apiVersion: apps.example.com/v1
kind: PostgresSecretRequest
metadata:
name: simple-app-sample-postgres

View File

@@ -0,0 +1,21 @@
apiVersion: platform.example.com/v1alpha1
kind: ExampleApp
metadata:
name: simple-app-sample
env: production
workloads:
webWorkers:
- name: web-worker
domains:
- first.example.com
- name: web-worker-no-sidecar
domains:
- second.example.com
overrides:
additionalResources:
- custom-configmap.yaml
resourcePatches:
- web-worker-sidecar.yaml
containerPatches:
- custom-app-env.yaml

View File

@@ -0,0 +1,6 @@
env:
- name: MY_NEW_VAR
value: "new value"
envFrom:
- configMapRef:
name: custom-configmap

View File

@@ -0,0 +1,6 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: custom-configmap
data:
LOADED: "true"

View File

@@ -0,0 +1,126 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-worker
labels:
name: web-worker
type: web
env: production
spec:
replicas: 3
selector:
matchLabels:
name: web-worker
type: web
env: production
template:
metadata:
labels:
name: web-worker
type: web
env: production
spec:
containers:
- name: app
image: registry.example.com/path/to/simple-app-sample
args:
- web
ports:
- name: http
containerPort: 8080
envFrom:
- configMapRef:
name: custom-configmap
env:
- name: ENV
value: production
- name: PORT
value: "8080"
- name: KUBE_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: MY_NEW_VAR
value: "new value"
resources: {"limits": {"cpu": "500m", "memory": "512Mi"}, "requests": {"cpu": "100m", "memory": "128Mi"}}
readinessProbe:
httpGet:
port: 8080
httpHeaders:
- name: "X-Forwarded-Proto"
value: "https"
path: "/ping"
initialDelaySeconds: 20
timeoutSeconds: 3
- name: sidecar
image: registry.example.com/path/to/custom-sidecar
args:
- run
envFrom:
- configMapRef:
name: custom-configmap
env:
- name: MY_NEW_VAR
value: "new value"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-worker-no-sidecar
labels:
name: web-worker-no-sidecar
type: web
env: production
spec:
replicas: 3
selector:
matchLabels:
name: web-worker-no-sidecar
type: web
env: production
template:
metadata:
labels:
name: web-worker-no-sidecar
type: web
env: production
spec:
containers:
- name: app
image: registry.example.com/path/to/simple-app-sample
args:
- web
ports:
- name: http
containerPort: 8080
envFrom:
- configMapRef:
name: custom-configmap
env:
- name: ENV
value: production
- name: PORT
value: "8080"
- name: KUBE_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: MY_NEW_VAR
value: "new value"
resources: {"limits": {"cpu": "500m", "memory": "512Mi"}, "requests": {"cpu": "100m", "memory": "128Mi"}}
readinessProbe:
httpGet:
port: 8080
httpHeaders:
- name: "X-Forwarded-Proto"
value: "https"
path: "/ping"
initialDelaySeconds: 20
timeoutSeconds: 3
---
apiVersion: v1
kind: ConfigMap
metadata:
name: custom-configmap
data:
LOADED: "true"

View File

@@ -0,0 +1,12 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-worker
spec:
template:
spec:
containers:
- name: sidecar
image: registry.example.com/path/to/custom-sidecar
args:
- run

View File

@@ -0,0 +1,111 @@
// Copyright 2023 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// +groupName=platform.example.com
// +versionName=v1alpha1
// +kubebuilder:validation:Required
package v1alpha1
import (
_ "embed"
"strings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
//go:generate ./crd_gen.sh
//go:embed platform.example.com_exampleapps.yaml
var CRDString string
const Group = "platform.example.com"
const Version = "v1alpha1"
const Kind = "ExampleApp"
//nolint:gochecknoglobals
var GroupVersion = strings.Join([]string{Group, Version}, "/")
type ExampleApp struct {
// Embedding these structs is required to use controller-gen to produce the CRD
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
// +kubebuilder:validation:Enum=production;staging;development
Env string `json:"env" yaml:"env"`
// +optional
AppImage string `json:"appImage" yaml:"appImage"`
Workloads Workloads `json:"workloads" yaml:"workloads"`
// +optional
Datastores Datastores `json:"datastores,omitempty" yaml:"datastores,omitempty"`
// +optional
Overrides Overrides `json:"overrides,omitempty" yaml:"overrides,omitempty"`
}
// +kubebuilder:validation:MinProperties=1
type Overrides struct {
// +optional
AdditionalResources []string `json:"additionalResources,omitempty" yaml:"additionalResources,omitempty"`
// +optional
ResourcePatches []string `json:"resourcePatches,omitempty" yaml:"resourcePatches,omitempty"`
// +optional
ContainerPatches []string `json:"containerPatches,omitempty" yaml:"containerPatches,omitempty"`
}
// +kubebuilder:validation:MinProperties=1
type Workloads struct {
// +optional
JobWorkers []JobWorker `json:"jobWorkers,omitempty" yaml:"jobWorkers,omitempty"`
// +optional
WebWorkers []WebWorker `json:"webWorkers,omitempty" yaml:"webWorkers,omitempty"`
}
// +kubebuilder:validation:Pattern="^[a-z0-9](?:[-a-z0-9]*[a-z0-9])?(?:\\.[a-z0-9](?:[-a-z0-9]*[a-z0-9])?)*$"
type KubernetesMetaName string
type JobWorker struct {
Name KubernetesMetaName `json:"name" yaml:"name"`
// +kubebuilder:validation:Minimum=0
// +optional
Replicas *int `json:"replicas,omitempty" yaml:"replicas,omitempty"`
// +optional
Resources ResourceBinSize `json:"resources,omitempty" yaml:"resources,omitempty"`
// +kubebuilder:validation:UniqueItems=true
// +kubebuilder:validation:MinItems=1
Queues []string `json:"queues" yaml:"queues"`
}
// +kubebuilder:validation:Enum=small;medium;large
type ResourceBinSize string
const ResourceBinSizeSmall ResourceBinSize = "small"
type WebWorker struct {
Name KubernetesMetaName `json:"name" yaml:"name"`
// +kubebuilder:validation:Minimum=0
// +optional
Replicas *int `json:"replicas,omitempty" yaml:"replicas,omitempty"`
// +optional
Resources ResourceBinSize `json:"resources,omitempty" yaml:"resources,omitempty"`
// +kubebuilder:validation:UniqueItems=true
// +kubebuilder:validation:MinItems=1
Domains []string `json:"domains" yaml:"domains"`
}
type Datastores struct {
// +optional
PostgresInstance string `json:"postgresInstance,omitempty" yaml:"postgresInstance,omitempty"`
}

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