Compare commits
513 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
978cc0c5b8 | ||
|
|
4e009a7167 | ||
|
|
176444263c | ||
|
|
87232fd4dd | ||
|
|
0361a08aa0 | ||
|
|
be154d079b | ||
|
|
feccc36415 | ||
|
|
06b8ad2402 | ||
|
|
023a709b6a | ||
|
|
6681cd05a9 | ||
|
|
56807fddf6 | ||
|
|
51504406da | ||
|
|
d28cdd9726 | ||
|
|
c1f120facc | ||
|
|
87f792915a | ||
|
|
9fb5fe3af3 | ||
|
|
0648f56049 | ||
|
|
7da8ffd87f | ||
|
|
79f900b82e | ||
|
|
0394c4d5ef | ||
|
|
693f0c1da1 | ||
|
|
65481c223e | ||
|
|
d2222426f5 | ||
|
|
18924d29a7 | ||
|
|
84a3cdde93 | ||
|
|
e5eb4d4a67 | ||
|
|
60c44c16f5 | ||
|
|
f22222f71d | ||
|
|
287ac6b003 | ||
|
|
5b422bef17 | ||
|
|
1dc3ff6c59 | ||
|
|
ed13067ff2 | ||
|
|
a3151aa10c | ||
|
|
536f4c31ce | ||
|
|
3a8765859d | ||
|
|
369ae5aa71 | ||
|
|
ca2b93ba39 | ||
|
|
8ff8295d0c | ||
|
|
0439154564 | ||
|
|
e7e05f870b | ||
|
|
d54f08e7a9 | ||
|
|
ece3a07567 | ||
|
|
9c37506130 | ||
|
|
58b4ed586a | ||
|
|
c479eb80c6 | ||
|
|
da7af5ab5f | ||
|
|
d1b4851fbe | ||
|
|
a9f53b4f1a | ||
|
|
7327b14a62 | ||
|
|
3d5fc3dc18 | ||
|
|
1d80ff2b09 | ||
|
|
28111d27fb | ||
|
|
ddd377b997 | ||
|
|
e01810037b | ||
|
|
f5563de144 | ||
|
|
8ecaa56461 | ||
|
|
9d38ea6ffc | ||
|
|
f58b82fb4e | ||
|
|
be361a44d5 | ||
|
|
12e065cc43 | ||
|
|
f9e69089ea | ||
|
|
2eced064dd | ||
|
|
7be91884b7 | ||
|
|
b2b610b55e | ||
|
|
21a943e6f9 | ||
|
|
cb1b117d17 | ||
|
|
96f177b101 | ||
|
|
7621418b72 | ||
|
|
7a94a3ac71 | ||
|
|
58b799fa83 | ||
|
|
38635e0ec5 | ||
|
|
d79e49f80b | ||
|
|
5e44b7b1b3 | ||
|
|
131c05d9c7 | ||
|
|
3ac8d54a30 | ||
|
|
c605f9a44f | ||
|
|
eefd47d701 | ||
|
|
0014bc4c43 | ||
|
|
ccf358f0ca | ||
|
|
bd284ab28b | ||
|
|
bed46f6b68 | ||
|
|
fdd3fd1d06 | ||
|
|
e81201b8cb | ||
|
|
2c1085d9ce | ||
|
|
49eb1c5444 | ||
|
|
81dc4adc69 | ||
|
|
8e23989418 | ||
|
|
f532bd2d48 | ||
|
|
da9df03675 | ||
|
|
91965ddfc9 | ||
|
|
0bd78ca80c | ||
|
|
96b96ac78e | ||
|
|
a9a63b8423 | ||
|
|
8abb93e831 | ||
|
|
645f9df4f0 | ||
|
|
6924a16ac7 | ||
|
|
dc2a4c267b | ||
|
|
d5e5a26f5c | ||
|
|
df5ac34c9b | ||
|
|
319dbad795 | ||
|
|
28feb8b1d7 | ||
|
|
f4d898cb92 | ||
|
|
75b5b0fd3c | ||
|
|
6ee3439462 | ||
|
|
4eda5a7ccd | ||
|
|
ad94037516 | ||
|
|
882fb35601 | ||
|
|
48f10a6a20 | ||
|
|
2c35880cbf | ||
|
|
c8af9ced89 | ||
|
|
f89525f8bd | ||
|
|
ad11fbcd00 | ||
|
|
9db661ae63 | ||
|
|
fff5cd50f0 | ||
|
|
b3b50cf503 | ||
|
|
cbebad9586 | ||
|
|
c01023d8f8 | ||
|
|
df610c3cca | ||
|
|
3b7c40bbb3 | ||
|
|
8674f31874 | ||
|
|
b518aad5ac | ||
|
|
12959dec88 | ||
|
|
e381da6a08 | ||
|
|
b004fbfc41 | ||
|
|
8c56ccc5b0 | ||
|
|
c8051eeeed | ||
|
|
5d944b69df | ||
|
|
1fca76c4a8 | ||
|
|
d0e6fcad3f | ||
|
|
d4ba6c4f44 | ||
|
|
35e1b5cbb9 | ||
|
|
f8da3a1b44 | ||
|
|
4ea253220a | ||
|
|
0a5048a56b | ||
|
|
a06652a374 | ||
|
|
86e3991998 | ||
|
|
d9102150cf | ||
|
|
fd08bae1c7 | ||
|
|
4b2af2ede2 | ||
|
|
c6be0b9389 | ||
|
|
6ccdfa074f | ||
|
|
8801029d95 | ||
|
|
5faf6ebadc | ||
|
|
f92d708051 | ||
|
|
76c31c6303 | ||
|
|
cf8ac4dd0e | ||
|
|
879041677c | ||
|
|
cac36365ae | ||
|
|
2c12385344 | ||
|
|
fa217b8775 | ||
|
|
6f7cdde1ba | ||
|
|
da9cc00a56 | ||
|
|
161c90eb8f | ||
|
|
ad5daee004 | ||
|
|
35ea91c111 | ||
|
|
6763490ef6 | ||
|
|
93382f65bb | ||
|
|
190c732c3a | ||
|
|
8bd13edc75 | ||
|
|
98e0774f56 | ||
|
|
c3a44e890d | ||
|
|
a4734d7e30 | ||
|
|
2c267c95e5 | ||
|
|
78f9a6214c | ||
|
|
7ee90a34e5 | ||
|
|
1a6b09afb4 | ||
|
|
c7e158aaa7 | ||
|
|
98c7afd69c | ||
|
|
f3da59e5af | ||
|
|
a17210f387 | ||
|
|
443212d3da | ||
|
|
7a5f60e23f | ||
|
|
7a1d978339 | ||
|
|
6c7ef96354 | ||
|
|
d2e7a37eb4 | ||
|
|
1d8105247a | ||
|
|
6d110cdfb1 | ||
|
|
d015895caa | ||
|
|
64e76a23c6 | ||
|
|
f5006aa239 | ||
|
|
4bd06771ae | ||
|
|
4643f8383e | ||
|
|
b82759b35a | ||
|
|
0343575146 | ||
|
|
e7847b75db | ||
|
|
bb1078d610 | ||
|
|
6f6c097980 | ||
|
|
73692df272 | ||
|
|
138cba6e57 | ||
|
|
2abf932ee4 | ||
|
|
939a75115c | ||
|
|
9f41efb6f7 | ||
|
|
c3d7cad53e | ||
|
|
463f9fbc64 | ||
|
|
4a51b111e6 | ||
|
|
63ebd7fd09 | ||
|
|
c31367909e | ||
|
|
0f0649a674 | ||
|
|
09cbf348a7 | ||
|
|
287bc520b1 | ||
|
|
65a2ceec5c | ||
|
|
516399bf81 | ||
|
|
4ea70765af | ||
|
|
d6372e396b | ||
|
|
7b20ad5dd2 | ||
|
|
3d962136a8 | ||
|
|
f3386505cf | ||
|
|
f4c8da35e8 | ||
|
|
cc3f2c7bde | ||
|
|
80b87729b6 | ||
|
|
2282223592 | ||
|
|
f6c96aea48 | ||
|
|
1fa48bf916 | ||
|
|
d49b77c8d2 | ||
|
|
91132e9c87 | ||
|
|
4680abe951 | ||
|
|
2963708a6c | ||
|
|
1f57cf3d31 | ||
|
|
80611ec70e | ||
|
|
d37bb42995 | ||
|
|
1bf63a94c2 | ||
|
|
cad251444c | ||
|
|
358c6d38b7 | ||
|
|
b8fd46d0df | ||
|
|
6a1ba3c545 | ||
|
|
33a874800b | ||
|
|
f417352370 | ||
|
|
72d90b5692 | ||
|
|
d7dadb4425 | ||
|
|
348408e16e | ||
|
|
04de52044a | ||
|
|
45a00a0170 | ||
|
|
1ac380a7f9 | ||
|
|
2971d34a13 | ||
|
|
90f0d81532 | ||
|
|
d5262404f3 | ||
|
|
03c3cb860a | ||
|
|
a1faa1d965 | ||
|
|
c40d290e46 | ||
|
|
5106a71e6a | ||
|
|
491acf57ad | ||
|
|
0694a9582f | ||
|
|
0c817378cf | ||
|
|
ec2aa13165 | ||
|
|
c921cf0d54 | ||
|
|
11dd0d918c | ||
|
|
467969de0f | ||
|
|
bdc5ae4573 | ||
|
|
1eb4b67013 | ||
|
|
e777947539 | ||
|
|
70b906cae2 | ||
|
|
c57afa1e56 | ||
|
|
73668d19d9 | ||
|
|
82f847e21d | ||
|
|
753b2e6eda | ||
|
|
7b95e90a33 | ||
|
|
7824229d7b | ||
|
|
20557f9f15 | ||
|
|
6430f2b4b0 | ||
|
|
92e136ed54 | ||
|
|
e79b008878 | ||
|
|
43cdea01d6 | ||
|
|
6ddaedb4fc | ||
|
|
b4fef0a6b9 | ||
|
|
735ebd3336 | ||
|
|
a5a9158a24 | ||
|
|
93fdd795da | ||
|
|
18c944d18a | ||
|
|
2c9ef85f6d | ||
|
|
80669d71ef | ||
|
|
b993d17148 | ||
|
|
c454dd481b | ||
|
|
07de9d9ffe | ||
|
|
9f26b09a06 | ||
|
|
ad0f3373b6 | ||
|
|
f880cce4f9 | ||
|
|
8a0fd6ddf9 | ||
|
|
c56f338b12 | ||
|
|
463d241a91 | ||
|
|
db0920ba32 | ||
|
|
16d3180e42 | ||
|
|
81d2ad8245 | ||
|
|
96d1c1b2bd | ||
|
|
545949c67f | ||
|
|
342bb81687 | ||
|
|
60b483569d | ||
|
|
b7a2fb4be0 | ||
|
|
5bdc083ce2 | ||
|
|
787b6953c8 | ||
|
|
40717fa4f4 | ||
|
|
899a1fffca | ||
|
|
02b38ac8e0 | ||
|
|
5dcd599612 | ||
|
|
854ec02823 | ||
|
|
9386b9e0c3 | ||
|
|
f2d749069e | ||
|
|
d4169aa4dd | ||
|
|
c06072d5cf | ||
|
|
7e2d235f53 | ||
|
|
b810aea6cc | ||
|
|
75a879c770 | ||
|
|
d4c5a137a1 | ||
|
|
d4718f6ff4 | ||
|
|
ac9b3d193d | ||
|
|
7c7e76f9f0 | ||
|
|
08401f62b2 | ||
|
|
69e26ca1d9 | ||
|
|
41aac68193 | ||
|
|
fcd38c9395 | ||
|
|
fe4b65972a | ||
|
|
4c576bf599 | ||
|
|
70d30fd52e | ||
|
|
803104578f | ||
|
|
030b6bc77c | ||
|
|
009413affd | ||
|
|
9e76787e9f | ||
|
|
b78bbd5b9d | ||
|
|
3e15e83926 | ||
|
|
1b327e9d4e | ||
|
|
7dd736954b | ||
|
|
6b98590461 | ||
|
|
8049634e4d | ||
|
|
adc7981f22 | ||
|
|
30e5389d02 | ||
|
|
b6a78f42ea | ||
|
|
e4fb8e75f9 | ||
|
|
2f35367a7f | ||
|
|
2d8db4f20d | ||
|
|
12a491f538 | ||
|
|
9503ecafb1 | ||
|
|
e927d39a27 | ||
|
|
ac50aea21f | ||
|
|
c45536723c | ||
|
|
fb1de8c649 | ||
|
|
e1c082e5ac | ||
|
|
1889b64b4e | ||
|
|
0cfdc5d674 | ||
|
|
96afee996a | ||
|
|
da9747a406 | ||
|
|
36d219e05c | ||
|
|
ea2de24ade | ||
|
|
f01911d0e2 | ||
|
|
43eb9327d5 | ||
|
|
ca212ac592 | ||
|
|
fe3e0efcf1 | ||
|
|
ed7a880287 | ||
|
|
e94853f023 | ||
|
|
cbecd8ab56 | ||
|
|
feaab54f70 | ||
|
|
02e12cf871 | ||
|
|
7aeec0a0c4 | ||
|
|
abeea06e72 | ||
|
|
4a55b828b1 | ||
|
|
6b9c0a5e48 | ||
|
|
e060873246 | ||
|
|
143609b9fb | ||
|
|
a22438b7fa | ||
|
|
34321983e7 | ||
|
|
44762933b3 | ||
|
|
2912d1d437 | ||
|
|
4885278691 | ||
|
|
8a7c94180b | ||
|
|
183b9a7ee0 | ||
|
|
0fc582d6fd | ||
|
|
c7a6ed53ca | ||
|
|
547e39d24c | ||
|
|
115b58fe49 | ||
|
|
613e270d00 | ||
|
|
c24e738973 | ||
|
|
e2fb6089c9 | ||
|
|
95eb7aede0 | ||
|
|
3cef177e24 | ||
|
|
c430556498 | ||
|
|
ff9c982df4 | ||
|
|
724c93c23d | ||
|
|
769e20423d | ||
|
|
d12e697769 | ||
|
|
874b05c5da | ||
|
|
1894b90d84 | ||
|
|
cdf5bf3c9e | ||
|
|
5f35bd4e00 | ||
|
|
12504c76d0 | ||
|
|
7346b1a762 | ||
|
|
f7d616d223 | ||
|
|
443e5b5539 | ||
|
|
f6c14c939d | ||
|
|
a602c57e5d | ||
|
|
9ae41899a8 | ||
|
|
cfdd5f0284 | ||
|
|
04b0a0a7ae | ||
|
|
83fcac1868 | ||
|
|
efb0ecb4f9 | ||
|
|
7498d516d4 | ||
|
|
2fe3362c3d | ||
|
|
6473331399 | ||
|
|
6f85363e58 | ||
|
|
02c0d3bd0d | ||
|
|
f1f4cc007a | ||
|
|
7293771766 | ||
|
|
25d065c211 | ||
|
|
bf14f47459 | ||
|
|
8576073b9d | ||
|
|
cbe1331815 | ||
|
|
998b763cf9 | ||
|
|
15e8f106ce | ||
|
|
9aee262054 | ||
|
|
c718336143 | ||
|
|
355ed94852 | ||
|
|
56c5e784fb | ||
|
|
0a30bc1024 | ||
|
|
a55548de07 | ||
|
|
b84e613b5e | ||
|
|
6b9e6cb9a5 | ||
|
|
f24c4034e2 | ||
|
|
797352e4fa | ||
|
|
7d742924f6 | ||
|
|
e19ea796b1 | ||
|
|
bcef28e80b | ||
|
|
4acef9d508 | ||
|
|
8128fc190d | ||
|
|
2ba0c4435e | ||
|
|
b8164717da | ||
|
|
ed88e9dec5 | ||
|
|
5ebb985b10 | ||
|
|
7f5f80286e | ||
|
|
3cd0bc9672 | ||
|
|
95f896e92c | ||
|
|
0b9e3d24ef | ||
|
|
3f0efc9435 | ||
|
|
64205cf523 | ||
|
|
38c62d46c7 | ||
|
|
b1ac3a26f4 | ||
|
|
b795e612f7 | ||
|
|
a1a2286794 | ||
|
|
8c5d83d9fe | ||
|
|
5130a154e4 | ||
|
|
938f2570ef | ||
|
|
97a7b4450f | ||
|
|
46fbc7c71b | ||
|
|
e35da1c890 | ||
|
|
9af6175302 | ||
|
|
e1def4f8ac | ||
|
|
e09078f697 | ||
|
|
7232ff9ea0 | ||
|
|
45876a723c | ||
|
|
1ece35e4c5 | ||
|
|
5dee903374 | ||
|
|
4dd20af7e0 | ||
|
|
b9fbdfc9a4 | ||
|
|
ab00e348a4 | ||
|
|
b5c0ae9d5a | ||
|
|
8e4044eed9 | ||
|
|
7034ef46af | ||
|
|
8dfbe952ae | ||
|
|
f1e9da56dc | ||
|
|
f924c5f76d | ||
|
|
57442e8faa | ||
|
|
95bfd3b3a4 | ||
|
|
2858e83fe1 | ||
|
|
5430152c7f | ||
|
|
3433079121 | ||
|
|
151b84b8fe | ||
|
|
e3e01cb5da | ||
|
|
c4c890d4e9 | ||
|
|
64a473db2e | ||
|
|
cc9bcbaefd | ||
|
|
787d491bd5 | ||
|
|
5c4991299c | ||
|
|
33ac3ef2c6 | ||
|
|
c7504442bd | ||
|
|
1a546a1d82 | ||
|
|
713365a12c | ||
|
|
5d8248d31d | ||
|
|
5346c1cca3 | ||
|
|
baadaa05d2 | ||
|
|
224a1ce941 | ||
|
|
52f1bfed4c | ||
|
|
5c9cbe676d | ||
|
|
e25bb74c05 | ||
|
|
c2f465e246 | ||
|
|
6bbbf16140 | ||
|
|
c5cdb70031 | ||
|
|
2955cd70a8 | ||
|
|
7b4940914c | ||
|
|
30f977a7cb | ||
|
|
e06fa24616 | ||
|
|
20d7d0c78a | ||
|
|
606078c1b3 | ||
|
|
0135eb19d4 | ||
|
|
8b989190c4 | ||
|
|
a85ea59824 | ||
|
|
d012f0f2bc | ||
|
|
7e2b63ea5d | ||
|
|
cb53243fc1 | ||
|
|
5536af9756 | ||
|
|
28087c1d76 | ||
|
|
b80f32ce7d | ||
|
|
8bad59ebde | ||
|
|
b44e4617e0 | ||
|
|
5d99e3d191 | ||
|
|
1807852b6b | ||
|
|
4f4a5c0ba0 | ||
|
|
24188e58ff | ||
|
|
e2be598988 | ||
|
|
9e2a4f329b | ||
|
|
574b86cbca | ||
|
|
4b7042cc46 | ||
|
|
5ae4711f7b | ||
|
|
97a53b1536 | ||
|
|
cc982cf3b1 | ||
|
|
3f652f8b05 | ||
|
|
dcd86dec6e | ||
|
|
0d8194c800 |
14
.github/aur/flux-bin/.SRCINFO.template
vendored
14
.github/aur/flux-bin/.SRCINFO.template
vendored
@@ -8,9 +8,15 @@ pkgbase = flux-bin
|
|||||||
arch = armv7h
|
arch = armv7h
|
||||||
arch = aarch64
|
arch = aarch64
|
||||||
license = APACHE
|
license = APACHE
|
||||||
source_x86_64 = flux-bin-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v1/flux_${PKGVER}_linux_amd64.tar.gz
|
optdepends = bash-completion: auto-completion for flux in Bash
|
||||||
source_armv6h = flux-bin-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v1/flux_${PKGVER}_linux_arm.tar.gz
|
optdepends = zsh-completions: auto-completion for flux in ZSH
|
||||||
source_armv7h = flux-bin-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v1/flux_${PKGVER}_linux_arm.tar.gz
|
source_x86_64 = ${PKGNAME}-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${PKGVER}/flux_${PKGVER}_linux_amd64.tar.gz
|
||||||
source_aarch64 = flux-bin-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v1/flux_${PKGVER}_linux_arm64.tar.gz
|
sha256sums_x86_64 = ${SHA256SUM_AMD64}
|
||||||
|
source_armv6h = ${PKGNAME}-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${PKGVER}/flux_${PKGVER}_linux_arm.tar.gz
|
||||||
|
sha256sums_armv6h = ${SHA256SUM_ARM}
|
||||||
|
source_armv7h = ${PKGNAME}-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${PKGVER}/flux_${PKGVER}_linux_arm.tar.gz
|
||||||
|
sha256sums_armv7h = ${SHA256SUM_ARM}
|
||||||
|
source_aarch64 = ${PKGNAME}-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${PKGVER}/flux_${PKGVER}_linux_arm64.tar.gz
|
||||||
|
sha256sums_aarch64 = ${SHA256SUM_ARM64}
|
||||||
|
|
||||||
pkgname = flux-bin
|
pkgname = flux-bin
|
||||||
|
|||||||
4
.github/aur/flux-bin/PKGBUILD.template
vendored
4
.github/aur/flux-bin/PKGBUILD.template
vendored
@@ -8,8 +8,8 @@ pkgdesc="Open and extensible continuous delivery solution for Kubernetes"
|
|||||||
url="https://fluxcd.io/"
|
url="https://fluxcd.io/"
|
||||||
arch=("x86_64" "armv6h" "armv7h" "aarch64")
|
arch=("x86_64" "armv6h" "armv7h" "aarch64")
|
||||||
license=("APACHE")
|
license=("APACHE")
|
||||||
optdepends=('bash-completion: auto-completion for flux in Bash',
|
optdepends=('bash-completion: auto-completion for flux in Bash'
|
||||||
'zsh-completions: auto-completion for flux in ZSH')
|
'zsh-completions: auto-completion for flux in ZSH')
|
||||||
source_x86_64=(
|
source_x86_64=(
|
||||||
"${pkgname}-${pkgver}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${pkgver}/flux_${pkgver}_linux_amd64.tar.gz"
|
"${pkgname}-${pkgver}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${pkgver}/flux_${pkgver}_linux_amd64.tar.gz"
|
||||||
)
|
)
|
||||||
|
|||||||
9
.github/dependabot.yml
vendored
Normal file
9
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
version: 2
|
||||||
|
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
labels: ["area/build"]
|
||||||
|
schedule:
|
||||||
|
# by default this will be on a monday.
|
||||||
|
interval: "weekly"
|
||||||
34
.github/runners/README.md
vendored
34
.github/runners/README.md
vendored
@@ -1,24 +1,32 @@
|
|||||||
# Flux ARM64 GitHub runners
|
# Flux ARM64 GitHub runners
|
||||||
|
|
||||||
The Flux ARM64 end-to-end tests run on Equinix instances provisioned with Docker and GitHub self-hosted runners.
|
The Flux ARM64 end-to-end tests run on Equinix Metal instances provisioned with Docker and GitHub self-hosted runners.
|
||||||
|
|
||||||
## Current instances
|
## Current instances
|
||||||
|
|
||||||
| Runner | Instance | Region |
|
| Repository | Runner | Instance | Location |
|
||||||
|---------------|---------------------|--------|
|
|-----------------------------|------------------|------------------------|---------------|
|
||||||
| equinix-arm-1 | flux-equinix-arm-01 | AMS1 |
|
| flux2 | equinix-arm-dc-1 | flux-equinix-arm-dc-01 | Washington DC |
|
||||||
| equinix-arm-2 | flux-equinix-arm-01 | AMS1 |
|
| flux2 | equinix-arm-dc-2 | flux-equinix-arm-dc-01 | Washington DC |
|
||||||
| equinix-arm-3 | flux-equinix-arm-01 | AMS1 |
|
| flux2 | equinix-arm-da-1 | flux-equinix-arm-da-01 | Dallas |
|
||||||
| equinix-arm-4 | flux-equinix-arm-02 | DFW2 |
|
| flux2 | equinix-arm-da-2 | flux-equinix-arm-da-01 | Dallas |
|
||||||
| equinix-arm-5 | flux-equinix-arm-02 | DFW2 |
|
| source-controller | equinix-arm-dc-1 | flux-equinix-arm-dc-01 | Washington DC |
|
||||||
| equinix-arm-6 | flux-equinix-arm-02 | DFW2 |
|
| source-controller | equinix-arm-da-1 | flux-equinix-arm-da-01 | Dallas |
|
||||||
|
| image-automation-controller | equinix-arm-dc-1 | flux-equinix-arm-dc-01 | Washington DC |
|
||||||
|
| image-automation-controller | equinix-arm-da-1 | flux-equinix-arm-da-01 | Dallas |
|
||||||
|
|
||||||
|
Instance spec:
|
||||||
|
- Ampere Altra Q80-30 80-core processor @ 2.8GHz
|
||||||
|
- 2 x 960GB NVME
|
||||||
|
- 256GB RAM
|
||||||
|
- 2 x 25Gbps
|
||||||
|
|
||||||
## Instance setup
|
## Instance setup
|
||||||
|
|
||||||
In order to add a new runner to the GitHub Actions pool,
|
In order to add a new runner to the GitHub Actions pool,
|
||||||
first create a server on Equinix with the following configuration:
|
first create a server on Equinix with the following configuration:
|
||||||
- Type: c2.large.arm
|
- Type: `c3.large.arm64`
|
||||||
- OS: Ubuntu 20.04
|
- OS: `Ubuntu 22.04 LTS`
|
||||||
|
|
||||||
### Install prerequisites
|
### Install prerequisites
|
||||||
|
|
||||||
@@ -54,14 +62,14 @@ sudo ./prereq.sh
|
|||||||
|
|
||||||
- Retrieve the GitHub runner token from the repository [settings page](https://github.com/fluxcd/flux2/settings/actions/runners/new?arch=arm64&os=linux)
|
- Retrieve the GitHub runner token from the repository [settings page](https://github.com/fluxcd/flux2/settings/actions/runners/new?arch=arm64&os=linux)
|
||||||
|
|
||||||
- Create 3 directories `runner1`, `runner2`, `runner3`
|
- Create two directories `flux2-01`, `flux2-02`
|
||||||
|
|
||||||
- In each dir run:
|
- In each dir run:
|
||||||
```shell
|
```shell
|
||||||
curl -sL https://raw.githubusercontent.com/fluxcd/flux2/main/.github/runners/runner-setup.sh > runner-setup.sh \
|
curl -sL https://raw.githubusercontent.com/fluxcd/flux2/main/.github/runners/runner-setup.sh > runner-setup.sh \
|
||||||
&& chmod +x ./runner-setup.sh
|
&& chmod +x ./runner-setup.sh
|
||||||
|
|
||||||
./runner-setup.sh equinix-arm-<NUMBER> <TOKEN>
|
./runner-setup.sh equinix-arm-<NUMBER> <TOKEN> <REPO>
|
||||||
```
|
```
|
||||||
|
|
||||||
- Reboot the instance
|
- Reboot the instance
|
||||||
|
|||||||
14
.github/runners/prereq.sh
vendored
14
.github/runners/prereq.sh
vendored
@@ -18,11 +18,11 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
KIND_VERSION=0.11.1
|
KIND_VERSION=0.17.0
|
||||||
KUBECTL_VERSION=1.21.2
|
KUBECTL_VERSION=1.24.0
|
||||||
KUSTOMIZE_VERSION=4.1.3
|
KUSTOMIZE_VERSION=4.5.7
|
||||||
HELM_VERSION=3.7.2
|
HELM_VERSION=3.10.1
|
||||||
GITHUB_RUNNER_VERSION=2.285.1
|
GITHUB_RUNNER_VERSION=2.298.2
|
||||||
PACKAGES="apt-transport-https ca-certificates software-properties-common build-essential libssl-dev gnupg lsb-release jq pkg-config"
|
PACKAGES="apt-transport-https ca-certificates software-properties-common build-essential libssl-dev gnupg lsb-release jq pkg-config"
|
||||||
|
|
||||||
# install prerequisites
|
# install prerequisites
|
||||||
@@ -31,6 +31,10 @@ apt-get update \
|
|||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# fix Kubernetes DNS resolution
|
||||||
|
rm /etc/resolv.conf
|
||||||
|
cat "/run/systemd/resolve/stub-resolv.conf" | sed '/search/d' > /etc/resolv.conf
|
||||||
|
|
||||||
# install docker
|
# install docker
|
||||||
curl -fsSL https://get.docker.com -o get-docker.sh \
|
curl -fsSL https://get.docker.com -o get-docker.sh \
|
||||||
&& chmod +x get-docker.sh
|
&& chmod +x get-docker.sh
|
||||||
|
|||||||
2
.github/runners/runner-setup.sh
vendored
2
.github/runners/runner-setup.sh
vendored
@@ -22,7 +22,7 @@ RUNNER_NAME=$1
|
|||||||
REPOSITORY_TOKEN=$2
|
REPOSITORY_TOKEN=$2
|
||||||
REPOSITORY_URL=${3:-https://github.com/fluxcd/flux2}
|
REPOSITORY_URL=${3:-https://github.com/fluxcd/flux2}
|
||||||
|
|
||||||
GITHUB_RUNNER_VERSION=2.285.1
|
GITHUB_RUNNER_VERSION=2.298.2
|
||||||
|
|
||||||
# download runner
|
# download runner
|
||||||
curl -o actions-runner-linux-arm64.tar.gz -L https://github.com/actions/runner/releases/download/v${GITHUB_RUNNER_VERSION}/actions-runner-linux-arm64-${GITHUB_RUNNER_VERSION}.tar.gz \
|
curl -o actions-runner-linux-arm64.tar.gz -L https://github.com/actions/runner/releases/download/v${GITHUB_RUNNER_VERSION}/actions-runner-linux-arm64-${GITHUB_RUNNER_VERSION}.tar.gz \
|
||||||
|
|||||||
50
.github/workflows/README.md
vendored
Normal file
50
.github/workflows/README.md
vendored
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
# Flux GitHub Workflows
|
||||||
|
|
||||||
|
## End-to-end Testing
|
||||||
|
|
||||||
|
The e2e workflows run a series of tests to ensure that the Flux CLI and
|
||||||
|
the GitOps Toolkit controllers work well all together.
|
||||||
|
The tests are written in Go, Bash, Make and Terraform.
|
||||||
|
|
||||||
|
| Workflow | Jobs | Runner | Role |
|
||||||
|
|--------------------|----------------------|----------------|-----------------------------------------------|
|
||||||
|
| e2e.yaml | e2e-amd64-kubernetes | GitHub Ubuntu | integration testing with Kubernetes Kind<br/> |
|
||||||
|
| e2e-arm64.yaml | e2e-arm64-kubernetes | Equinix Ubuntu | integration testing with Kubernetes Kind<br/> |
|
||||||
|
| e2e-bootstrap.yaml | e2e-boostrap-github | GitHub Ubuntu | integration testing with GitHub API<br/> |
|
||||||
|
| e2e-azure.yaml | e2e-amd64-aks | GitHub Ubuntu | integration testing with Azure API<br/> |
|
||||||
|
| scan.yaml | scan-fossa | GitHub Ubuntu | license scanning<br/> |
|
||||||
|
| scan.yaml | scan-snyk | GitHub Ubuntu | vulnerability scanning<br/> |
|
||||||
|
| scan.yaml | scan-codeql | GitHub Ubuntu | vulnerability scanning<br/> |
|
||||||
|
|
||||||
|
## Components Update
|
||||||
|
|
||||||
|
The components update workflow scans the GitOps Toolkit controller repositories for new releases,
|
||||||
|
amd when it finds a new controller version, the workflow performs the following steps:
|
||||||
|
- Updates the controller API package version in `go.mod`.
|
||||||
|
- Patches the controller CRDs version in the `manifests/crds` overlay.
|
||||||
|
- Patches the controller Deployment version in `manifests/bases` overlay.
|
||||||
|
- Opens a Pull Request against the `main` branch.
|
||||||
|
- Triggers the e2e test suite to run for the opened PR.
|
||||||
|
|
||||||
|
|
||||||
|
| Workflow | Jobs | Runner | Role |
|
||||||
|
|-------------|-------------------|---------------|-----------------------------------------------------|
|
||||||
|
| update.yaml | update-components | GitHub Ubuntu | update the GitOps Toolkit APIs and controllers<br/> |
|
||||||
|
|
||||||
|
## Release
|
||||||
|
|
||||||
|
The release workflow is triggered by a semver Git tag and performs the following steps:
|
||||||
|
- Generates the Flux install manifests (YAML).
|
||||||
|
- Generates the OpenAPI validation schemas for the GitOps Toolkit CRDs (JSON).
|
||||||
|
- Generates a Software Bill of Materials (SPDX JSON).
|
||||||
|
- Builds the Flux CLI binaries and the multi-arch container images.
|
||||||
|
- Pushes the container images to GitHub Container Registry and DockerHub.
|
||||||
|
- Signs the sbom, the binaries checksum and the container images with Cosign and GitHub OIDC.
|
||||||
|
- Uploads the sbom, binaries, checksums and install manifests to GitHub Releases.
|
||||||
|
- Pushes the install manifests as OCI artifacts to GitHub Container Registry and DockerHub.
|
||||||
|
- Signs the OCI artifacts with Cosign and GitHub OIDC.
|
||||||
|
|
||||||
|
| Workflow | Jobs | Runner | Role |
|
||||||
|
|--------------|------------------------|---------------|------------------------------------------------------|
|
||||||
|
| release.yaml | release-flux-cli | GitHub Ubuntu | build, push and sign the CLI release artifacts<br/> |
|
||||||
|
| release.yaml | release-flux-manifests | GitHub Ubuntu | build, push and sign the Flux install manifests<br/> |
|
||||||
80
.github/workflows/e2e-arm64.yaml
vendored
80
.github/workflows/e2e-arm64.yaml
vendored
@@ -3,33 +3,97 @@ name: e2e-arm64
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches: [ main, update-components, equinix-runners ]
|
branches: [ main, update-components, e2e-arm64* ]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
e2e-arm64-kubernetes:
|
||||||
# Hosted on Equinix
|
# Hosted on Equinix
|
||||||
# Docs: https://github.com/fluxcd/flux2/tree/main/.github/runners
|
# Docs: https://github.com/fluxcd/flux2/tree/main/.github/runners
|
||||||
runs-on: [self-hosted, Linux, ARM64, equinix]
|
runs-on: [self-hosted, Linux, ARM64, equinix]
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
# Keep this list up-to-date with https://endoflife.date/kubernetes
|
||||||
|
KUBERNETES_VERSION: [ 1.23.13, 1.24.7, 1.25.3 ]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568
|
||||||
with:
|
with:
|
||||||
go-version: 1.17.x
|
go-version: 1.19.x
|
||||||
- name: Prepare
|
- name: Prepare
|
||||||
id: prep
|
id: prep
|
||||||
run: |
|
run: |
|
||||||
echo ::set-output name=CLUSTER::arm64-${GITHUB_SHA:0:7}-$(date +%s)
|
ID=${GITHUB_SHA:0:7}-${{ matrix.KUBERNETES_VERSION }}-$(date +%s)
|
||||||
echo ::set-output name=CONTEXT::kind-arm64-${GITHUB_SHA:0:7}-$(date +%s)
|
echo "CLUSTER=arm64-${ID}" >> $GITHUB_OUTPUT
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
make build
|
make build
|
||||||
- name: Setup Kubernetes Kind
|
- name: Setup Kubernetes Kind
|
||||||
run: |
|
run: |
|
||||||
kind create cluster --name ${{ steps.prep.outputs.CLUSTER }} --kubeconfig=/tmp/${{ steps.prep.outputs.CLUSTER }}
|
kind create cluster \
|
||||||
|
--wait 5m \
|
||||||
|
--name ${{ steps.prep.outputs.CLUSTER }} \
|
||||||
|
--kubeconfig=/tmp/${{ steps.prep.outputs.CLUSTER }} \
|
||||||
|
--image=kindest/node:v${{ matrix.KUBERNETES_VERSION }}
|
||||||
- name: Run e2e tests
|
- name: Run e2e tests
|
||||||
run: TEST_KUBECONFIG=/tmp/${{ steps.prep.outputs.CLUSTER }} make e2e
|
run: TEST_KUBECONFIG=/tmp/${{ steps.prep.outputs.CLUSTER }} make e2e
|
||||||
|
- name: Run multi-tenancy tests
|
||||||
|
env:
|
||||||
|
KUBECONFIG: /tmp/${{ steps.prep.outputs.CLUSTER }}
|
||||||
|
run: |
|
||||||
|
./bin/flux install
|
||||||
|
./bin/flux create source git flux-system \
|
||||||
|
--interval=15m \
|
||||||
|
--url=https://github.com/fluxcd/flux2-multi-tenancy \
|
||||||
|
--branch=main \
|
||||||
|
--ignore-paths="./clusters/**/flux-system/"
|
||||||
|
./bin/flux create kustomization flux-system \
|
||||||
|
--interval=15m \
|
||||||
|
--source=flux-system \
|
||||||
|
--path=./clusters/staging
|
||||||
|
kubectl -n flux-system wait kustomization/tenants --for=condition=ready --timeout=5m
|
||||||
|
kubectl -n apps wait kustomization/dev-team --for=condition=ready --timeout=1m
|
||||||
|
kubectl -n apps wait helmrelease/podinfo --for=condition=ready --timeout=1m
|
||||||
|
- name: Run monitoring tests
|
||||||
|
# Keep this test in sync with https://fluxcd.io/flux/guides/monitoring/
|
||||||
|
env:
|
||||||
|
KUBECONFIG: /tmp/${{ steps.prep.outputs.CLUSTER }}
|
||||||
|
run: |
|
||||||
|
./bin/flux create source git flux-monitoring \
|
||||||
|
--interval=30m \
|
||||||
|
--url=https://github.com/fluxcd/flux2 \
|
||||||
|
--branch=${GITHUB_REF#refs/heads/}
|
||||||
|
./bin/flux create kustomization kube-prometheus-stack \
|
||||||
|
--interval=1h \
|
||||||
|
--prune \
|
||||||
|
--source=flux-monitoring \
|
||||||
|
--path="./manifests/monitoring/kube-prometheus-stack" \
|
||||||
|
--health-check-timeout=5m \
|
||||||
|
--wait
|
||||||
|
./bin/flux create kustomization monitoring-config \
|
||||||
|
--depends-on=kube-prometheus-stack \
|
||||||
|
--interval=1h \
|
||||||
|
--prune=true \
|
||||||
|
--source=flux-monitoring \
|
||||||
|
--path="./manifests/monitoring/monitoring-config" \
|
||||||
|
--health-check-timeout=1m \
|
||||||
|
--wait
|
||||||
|
kubectl -n flux-system wait kustomization/kube-prometheus-stack --for=condition=ready --timeout=5m
|
||||||
|
kubectl -n flux-system wait kustomization/monitoring-config --for=condition=ready --timeout=5m
|
||||||
|
kubectl -n monitoring wait helmrelease/kube-prometheus-stack --for=condition=ready --timeout=1m
|
||||||
|
- name: Debug failure
|
||||||
|
if: failure()
|
||||||
|
env:
|
||||||
|
KUBECONFIG: /tmp/${{ steps.prep.outputs.CLUSTER }}
|
||||||
|
run: |
|
||||||
|
kubectl -n flux-system get all
|
||||||
|
kubectl -n flux-system describe po
|
||||||
|
kubectl -n flux-system logs deploy/source-controller
|
||||||
|
kubectl -n flux-system logs deploy/kustomize-controller
|
||||||
- name: Cleanup
|
- name: Cleanup
|
||||||
if: always()
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
31
.github/workflows/e2e-azure.yaml
vendored
31
.github/workflows/e2e-azure.yaml
vendored
@@ -7,31 +7,26 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches: [ azure* ]
|
branches: [ azure* ]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
e2e:
|
e2e-amd64-aks:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
|
||||||
- name: Restore Go cache
|
- name: Restore Go cache
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@58c146cc91c5b9e778e71775dfe9bf1442ad9a12
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go1.17-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go1.18-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go1.17-
|
${{ runner.os }}-go1.18-
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568
|
||||||
with:
|
with:
|
||||||
go-version: 1.17.x
|
go-version: 1.19.x
|
||||||
- name: Install libgit2
|
|
||||||
run: |
|
|
||||||
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138
|
|
||||||
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 0E98404D386FA1D9
|
|
||||||
echo "deb http://deb.debian.org/debian unstable main" | sudo tee -a /etc/apt/sources.list
|
|
||||||
echo "deb-src http://deb.debian.org/debian unstable main" | sudo tee -a /etc/apt/sources.list
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y --allow-downgrades libgit2-dev/unstable zlib1g-dev/unstable libssh2-1-dev/unstable libpcre3-dev/unstable
|
|
||||||
- name: Setup Flux CLI
|
- name: Setup Flux CLI
|
||||||
run: |
|
run: |
|
||||||
make build
|
make build
|
||||||
@@ -44,9 +39,9 @@ jobs:
|
|||||||
mkdir -p $HOME/.local/bin
|
mkdir -p $HOME/.local/bin
|
||||||
mv sops-v3.7.1.linux $HOME/.local/bin/sops
|
mv sops-v3.7.1.linux $HOME/.local/bin/sops
|
||||||
- name: Setup Terraform
|
- name: Setup Terraform
|
||||||
uses: hashicorp/setup-terraform@v1
|
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2
|
||||||
with:
|
with:
|
||||||
terraform_version: 1.0.7
|
terraform_version: 1.2.8
|
||||||
terraform_wrapper: false
|
terraform_wrapper: false
|
||||||
- name: Setup Azure CLI
|
- name: Setup Azure CLI
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -1,34 +1,39 @@
|
|||||||
name: bootstrap
|
name: e2e-bootstrap
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
github:
|
e2e-boostrap-github:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
|
if: (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && github.actor != 'dependabot[bot]'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
|
||||||
- name: Restore Go cache
|
- name: Restore Go cache
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@58c146cc91c5b9e778e71775dfe9bf1442ad9a12
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go1.17-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go1.18-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go1.17-
|
${{ runner.os }}-go1.18-
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568
|
||||||
with:
|
with:
|
||||||
go-version: 1.17.x
|
go-version: 1.19.x
|
||||||
- name: Setup Kubernetes
|
- name: Setup Kubernetes
|
||||||
uses: engineerd/setup-kind@v0.5.0
|
uses: helm/kind-action@d8ccf8fb623ce1bb360ae2f45f323d9d5c5e9f00 # v1.5.0
|
||||||
with:
|
with:
|
||||||
version: v0.11.1
|
version: v0.17.0
|
||||||
image: kindest/node:v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6
|
cluster_name: kind
|
||||||
|
node_image: kindest/node:v1.25.2
|
||||||
- name: Setup Kustomize
|
- name: Setup Kustomize
|
||||||
uses: fluxcd/pkg//actions/kustomize@main
|
uses: fluxcd/pkg//actions/kustomize@main
|
||||||
- name: Build
|
- name: Build
|
||||||
69
.github/workflows/e2e.yaml
vendored
69
.github/workflows/e2e.yaml
vendored
@@ -1,34 +1,44 @@
|
|||||||
name: e2e
|
name: e2e
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches: [ main, e2e* ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main, oci ]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
kind:
|
e2e-amd64-kubernetes:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
services:
|
||||||
|
registry:
|
||||||
|
image: registry:2
|
||||||
|
ports:
|
||||||
|
- 5000:5000
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
|
||||||
- name: Restore Go cache
|
- name: Restore Go cache
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@58c146cc91c5b9e778e71775dfe9bf1442ad9a12
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go1.17-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go1.18-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go1.17-
|
${{ runner.os }}-go1.18-
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568
|
||||||
with:
|
with:
|
||||||
go-version: 1.17.x
|
go-version: 1.19.x
|
||||||
- name: Setup Kubernetes
|
- name: Setup Kubernetes
|
||||||
uses: engineerd/setup-kind@v0.5.0
|
uses: helm/kind-action@d8ccf8fb623ce1bb360ae2f45f323d9d5c5e9f00 # v1.5.0
|
||||||
with:
|
with:
|
||||||
version: v0.11.1
|
version: v0.17.0
|
||||||
image: kindest/node:v1.20.7
|
cluster_name: kind
|
||||||
config: .github/kind/config.yaml # disable KIND-net
|
config: .github/kind/config.yaml # disable KIND-net
|
||||||
|
node_image: kindest/node:v1.23.13
|
||||||
- name: Setup Calico for network policy
|
- name: Setup Calico for network policy
|
||||||
run: |
|
run: |
|
||||||
kubectl apply -f https://docs.projectcalico.org/v3.20/manifests/calico.yaml
|
kubectl apply -f https://docs.projectcalico.org/v3.20/manifests/calico.yaml
|
||||||
@@ -168,6 +178,36 @@ jobs:
|
|||||||
- name: flux delete source git
|
- name: flux delete source git
|
||||||
run: |
|
run: |
|
||||||
/tmp/flux delete source git podinfo --silent
|
/tmp/flux delete source git podinfo --silent
|
||||||
|
- name: flux oci artifacts
|
||||||
|
run: |
|
||||||
|
/tmp/flux push artifact oci://localhost:5000/fluxcd/flux:${{ github.sha }} \
|
||||||
|
--path="./manifests" \
|
||||||
|
--source="${{ github.repositoryUrl }}" \
|
||||||
|
--revision="${{ github.ref }}/${{ github.sha }}"
|
||||||
|
/tmp/flux tag artifact oci://localhost:5000/fluxcd/flux:${{ github.sha }} \
|
||||||
|
--tag latest
|
||||||
|
/tmp/flux list artifacts oci://localhost:5000/fluxcd/flux
|
||||||
|
- name: flux oci repositories
|
||||||
|
run: |
|
||||||
|
/tmp/flux create source oci podinfo-oci \
|
||||||
|
--url oci://ghcr.io/stefanprodan/manifests/podinfo \
|
||||||
|
--tag-semver 6.1.x \
|
||||||
|
--interval 10m
|
||||||
|
/tmp/flux create kustomization podinfo-oci \
|
||||||
|
--source=OCIRepository/podinfo-oci \
|
||||||
|
--path="./kustomize" \
|
||||||
|
--prune=true \
|
||||||
|
--interval=5m \
|
||||||
|
--target-namespace=default \
|
||||||
|
--wait=true \
|
||||||
|
--health-check-timeout=3m
|
||||||
|
/tmp/flux reconcile source oci podinfo-oci
|
||||||
|
/tmp/flux suspend source oci podinfo-oci
|
||||||
|
/tmp/flux get sources oci
|
||||||
|
/tmp/flux resume source oci podinfo-oci
|
||||||
|
/tmp/flux export source oci podinfo-oci
|
||||||
|
/tmp/flux delete ks podinfo-oci --silent
|
||||||
|
/tmp/flux delete source oci podinfo-oci --silent
|
||||||
- name: flux create tenant
|
- name: flux create tenant
|
||||||
run: |
|
run: |
|
||||||
/tmp/flux create tenant dev-team --with-namespace=apps
|
/tmp/flux create tenant dev-team --with-namespace=apps
|
||||||
@@ -183,14 +223,13 @@ jobs:
|
|||||||
/tmp/flux create source git flux-system \
|
/tmp/flux create source git flux-system \
|
||||||
--url=https://github.com/fluxcd/flux2-kustomize-helm-example \
|
--url=https://github.com/fluxcd/flux2-kustomize-helm-example \
|
||||||
--branch=main \
|
--branch=main \
|
||||||
|
--ignore-paths="./clusters/**/flux-system/" \
|
||||||
--recurse-submodules
|
--recurse-submodules
|
||||||
/tmp/flux create kustomization flux-system \
|
/tmp/flux create kustomization flux-system \
|
||||||
--source=flux-system \
|
--source=flux-system \
|
||||||
--path=./clusters/staging
|
--path=./clusters/staging
|
||||||
kubectl -n flux-system wait kustomization/infrastructure --for=condition=ready --timeout=5m
|
kubectl -n flux-system wait kustomization/infra-controllers --for=condition=ready --timeout=5m
|
||||||
kubectl -n flux-system wait kustomization/apps --for=condition=ready --timeout=5m
|
kubectl -n flux-system wait kustomization/apps --for=condition=ready --timeout=5m
|
||||||
kubectl -n nginx wait helmrelease/nginx --for=condition=ready --timeout=5m
|
|
||||||
kubectl -n redis wait helmrelease/redis --for=condition=ready --timeout=5m
|
|
||||||
kubectl -n podinfo wait helmrelease/podinfo --for=condition=ready --timeout=5m
|
kubectl -n podinfo wait helmrelease/podinfo --for=condition=ready --timeout=5m
|
||||||
- name: flux tree
|
- name: flux tree
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
21
.github/workflows/rebase.yaml
vendored
21
.github/workflows/rebase.yaml
vendored
@@ -1,21 +0,0 @@
|
|||||||
name: rebase
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
types: [ opened ]
|
|
||||||
issue_comment:
|
|
||||||
types: [ created ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
rebase:
|
|
||||||
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase') && (github.event.comment.author_association == 'CONTRIBUTOR' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER')
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout the latest code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- name: Automatic Rebase
|
|
||||||
uses: cirrus-actions/rebase@1.3.1
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
|
|
||||||
100
.github/workflows/release.yaml
vendored
100
.github/workflows/release.yaml
vendored
@@ -5,41 +5,43 @@ on:
|
|||||||
tags: [ 'v*' ]
|
tags: [ 'v*' ]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write # needed to write releases
|
contents: read
|
||||||
id-token: write # needed for keyless signing
|
|
||||||
packages: write # needed for ghcr access
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
goreleaser:
|
release-flux-cli:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write # needed to write releases
|
||||||
|
id-token: write # needed for keyless signing
|
||||||
|
packages: write # needed for ghcr access
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
|
||||||
- name: Unshallow
|
- name: Unshallow
|
||||||
run: git fetch --prune --unshallow
|
run: git fetch --prune --unshallow
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568
|
||||||
with:
|
with:
|
||||||
go-version: 1.17.x
|
go-version: 1.19.x
|
||||||
- name: Setup QEMU
|
- name: Setup QEMU
|
||||||
uses: docker/setup-qemu-action@v1
|
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2
|
||||||
- name: Setup Docker Buildx
|
- name: Setup Docker Buildx
|
||||||
id: buildx
|
id: buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@15c905b16b06416d2086efa066dd8e3a35cc7f98 # v2
|
||||||
- name: Setup Syft
|
- name: Setup Syft
|
||||||
uses: anchore/sbom-action/download-syft@v0
|
uses: anchore/sbom-action/download-syft@07978da4bdb4faa726e52dfc6b1bed63d4b56479 # v0.13.3
|
||||||
- name: Setup Cosign
|
- name: Setup Cosign
|
||||||
uses: sigstore/cosign-installer@main
|
uses: sigstore/cosign-installer@9becc617647dfa20ae7b1151972e9b3a2c338a2b # v2.8.1
|
||||||
- name: Setup Kustomize
|
- name: Setup Kustomize
|
||||||
uses: fluxcd/pkg//actions/kustomize@main
|
uses: fluxcd/pkg//actions/kustomize@main
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: fluxcdbot
|
username: fluxcdbot
|
||||||
password: ${{ secrets.GHCR_TOKEN }}
|
password: ${{ secrets.GHCR_TOKEN }}
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2
|
||||||
with:
|
with:
|
||||||
username: fluxcdbot
|
username: fluxcdbot
|
||||||
password: ${{ secrets.DOCKER_FLUXCD_PASSWORD }}
|
password: ${{ secrets.DOCKER_FLUXCD_PASSWORD }}
|
||||||
@@ -51,10 +53,8 @@ jobs:
|
|||||||
- name: Build CRDs
|
- name: Build CRDs
|
||||||
run: |
|
run: |
|
||||||
kustomize build manifests/crds > all-crds.yaml
|
kustomize build manifests/crds > all-crds.yaml
|
||||||
# Pinned to commit before https://github.com/fluxcd/pkg/pull/189 due to
|
|
||||||
# introduction faulty behavior.
|
|
||||||
- name: Generate OpenAPI JSON schemas from CRDs
|
- name: Generate OpenAPI JSON schemas from CRDs
|
||||||
uses: fluxcd/pkg//actions/crdjsonschema@49e26aa2ee9e734c3233c560253fd9542afe18ae
|
uses: fluxcd/pkg//actions/crdjsonschema@main
|
||||||
with:
|
with:
|
||||||
crd: all-crds.yaml
|
crd: all-crds.yaml
|
||||||
output: schemas
|
output: schemas
|
||||||
@@ -73,7 +73,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Run GoReleaser
|
- name: Run GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@v1
|
uses: goreleaser/goreleaser-action@9754a253a8673b0ea869c2e863b4e975497efd0c # v3
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
args: release --release-notes=output/notes.md --skip-validate
|
args: release --release-notes=output/notes.md --skip-validate
|
||||||
@@ -81,3 +81,69 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
|
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
|
||||||
AUR_BOT_SSH_PRIVATE_KEY: ${{ secrets.AUR_BOT_SSH_PRIVATE_KEY }}
|
AUR_BOT_SSH_PRIVATE_KEY: ${{ secrets.AUR_BOT_SSH_PRIVATE_KEY }}
|
||||||
|
release-flux-manifests:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: release-flux-cli
|
||||||
|
permissions:
|
||||||
|
id-token: write
|
||||||
|
packages: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
|
||||||
|
- name: Setup Kustomize
|
||||||
|
uses: fluxcd/pkg/actions/kustomize@main
|
||||||
|
- name: Setup Flux CLI
|
||||||
|
uses: ./action/
|
||||||
|
- name: Prepare
|
||||||
|
id: prep
|
||||||
|
run: |
|
||||||
|
VERSION=$(flux version --client | awk '{ print $NF }')
|
||||||
|
echo ::set-output name=VERSION::${VERSION}
|
||||||
|
- name: Login to GHCR
|
||||||
|
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: fluxcdbot
|
||||||
|
password: ${{ secrets.GHCR_TOKEN }}
|
||||||
|
- name: Login to DockerHub
|
||||||
|
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2
|
||||||
|
with:
|
||||||
|
username: fluxcdbot
|
||||||
|
password: ${{ secrets.DOCKER_FLUXCD_PASSWORD }}
|
||||||
|
- name: Push manifests to GHCR
|
||||||
|
run: |
|
||||||
|
mkdir -p ./ghcr.io/flux-system
|
||||||
|
flux install --registry=ghcr.io/fluxcd \
|
||||||
|
--components-extra=image-reflector-controller,image-automation-controller \
|
||||||
|
--export > ./ghcr.io/flux-system/gotk-components.yaml
|
||||||
|
|
||||||
|
cd ./ghcr.io && flux push artifact \
|
||||||
|
oci://ghcr.io/fluxcd/flux-manifests:${{ steps.prep.outputs.VERSION }} \
|
||||||
|
--path="./flux-system" \
|
||||||
|
--source=${{ github.repositoryUrl }} \
|
||||||
|
--revision="${{ github.ref_name }}/${{ github.sha }}"
|
||||||
|
- name: Push manifests to DockerHub
|
||||||
|
run: |
|
||||||
|
mkdir -p ./docker.io/flux-system
|
||||||
|
flux install --registry=docker.io/fluxcd \
|
||||||
|
--components-extra=image-reflector-controller,image-automation-controller \
|
||||||
|
--export > ./docker.io/flux-system/gotk-components.yaml
|
||||||
|
|
||||||
|
cd ./docker.io && flux push artifact \
|
||||||
|
oci://docker.io/fluxcd/flux-manifests:${{ steps.prep.outputs.VERSION }} \
|
||||||
|
--path="./flux-system" \
|
||||||
|
--source=${{ github.repositoryUrl }} \
|
||||||
|
--revision="${{ github.ref_name }}/${{ github.sha }}"
|
||||||
|
- uses: sigstore/cosign-installer@9becc617647dfa20ae7b1151972e9b3a2c338a2b # v2.8.1
|
||||||
|
- name: Sign manifests
|
||||||
|
env:
|
||||||
|
COSIGN_EXPERIMENTAL: 1
|
||||||
|
run: |
|
||||||
|
cosign sign ghcr.io/fluxcd/flux-manifests:${{ steps.prep.outputs.VERSION }}
|
||||||
|
cosign sign docker.io/fluxcd/flux-manifests:${{ steps.prep.outputs.VERSION }}
|
||||||
|
- name: Tag manifests
|
||||||
|
run: |
|
||||||
|
flux tag artifact oci://ghcr.io/fluxcd/flux-manifests:${{ steps.prep.outputs.VERSION }} \
|
||||||
|
--tag latest
|
||||||
|
|
||||||
|
flux tag artifact oci://docker.io/fluxcd/flux-manifests:${{ steps.prep.outputs.VERSION }} \
|
||||||
|
--tag latest
|
||||||
|
|||||||
45
.github/workflows/scan.yaml
vendored
45
.github/workflows/scan.yaml
vendored
@@ -1,6 +1,7 @@
|
|||||||
name: Scan
|
name: scan
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
pull_request:
|
pull_request:
|
||||||
@@ -8,53 +9,63 @@ on:
|
|||||||
schedule:
|
schedule:
|
||||||
- cron: '18 10 * * 3'
|
- cron: '18 10 * * 3'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
fossa:
|
scan-fossa:
|
||||||
name: FOSSA
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
if: github.actor != 'dependabot[bot]'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
|
||||||
- name: Run FOSSA scan and upload build data
|
- name: Run FOSSA scan and upload build data
|
||||||
uses: fossa-contrib/fossa-action@v1
|
uses: fossa-contrib/fossa-action@6cffaa064112e1cf9b5798c6224f9487dc1ec316 # v1
|
||||||
with:
|
with:
|
||||||
# FOSSA Push-Only API Token
|
# FOSSA Push-Only API Token
|
||||||
fossa-api-key: 5ee8bf422db1471e0bcf2bcb289185de
|
fossa-api-key: 5ee8bf422db1471e0bcf2bcb289185de
|
||||||
github-token: ${{ github.token }}
|
github-token: ${{ github.token }}
|
||||||
|
|
||||||
snyk:
|
scan-snyk:
|
||||||
name: Snyk
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
|
permissions:
|
||||||
|
security-events: write
|
||||||
|
if: (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && github.actor != 'dependabot[bot]'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
|
||||||
- name: Setup Kustomize
|
- name: Setup Kustomize
|
||||||
uses: fluxcd/pkg//actions/kustomize@main
|
uses: fluxcd/pkg//actions/kustomize@main
|
||||||
- name: Build manifests
|
- name: Build manifests
|
||||||
run: |
|
run: |
|
||||||
make cmd/flux/.manifests.done
|
make cmd/flux/.manifests.done
|
||||||
- name: Run Snyk to check for vulnerabilities
|
- name: Run Snyk to check for vulnerabilities
|
||||||
uses: snyk/actions/golang@master
|
uses: snyk/actions/golang@e25b2e6f5658d1bb7a6671b113260f13134cc3af # v0.3.0
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
env:
|
env:
|
||||||
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
|
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
|
||||||
with:
|
with:
|
||||||
args: --sarif-file-output=snyk.sarif
|
args: --sarif-file-output=snyk.sarif
|
||||||
- name: Upload result to GitHub Code Scanning
|
- name: Upload result to GitHub Code Scanning
|
||||||
uses: github/codeql-action/upload-sarif@v1
|
uses: github/codeql-action/upload-sarif@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2
|
||||||
with:
|
with:
|
||||||
sarif_file: snyk.sarif
|
sarif_file: snyk.sarif
|
||||||
|
|
||||||
codeql:
|
scan-codeql:
|
||||||
name: CodeQL
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
security-events: write
|
||||||
|
if: github.actor != 'dependabot[bot]'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568
|
||||||
|
with:
|
||||||
|
go-version: 1.19.x
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v1
|
uses: github/codeql-action/init@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2
|
||||||
with:
|
with:
|
||||||
languages: go
|
languages: go
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v1
|
uses: github/codeql-action/autobuild@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v1
|
uses: github/codeql-action/analyze@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2
|
||||||
|
|||||||
16
.github/workflows/update.yaml
vendored
16
.github/workflows/update.yaml
vendored
@@ -1,4 +1,4 @@
|
|||||||
name: Update Components
|
name: update
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
@@ -7,16 +7,22 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update-components:
|
update-components:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pull-requests: write
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code
|
- name: Check out code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568
|
||||||
with:
|
with:
|
||||||
go-version: 1.17.x
|
go-version: 1.19.x
|
||||||
- name: Update component versions
|
- name: Update component versions
|
||||||
id: update
|
id: update
|
||||||
run: |
|
run: |
|
||||||
@@ -69,7 +75,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
id: cpr
|
id: cpr
|
||||||
uses: peter-evans/create-pull-request@v3
|
uses: peter-evans/create-pull-request@2b011faafdcbc9ceb11414d64d0573f37c774b04 # v4
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.BOT_GITHUB_TOKEN }}
|
token: ${{ secrets.BOT_GITHUB_TOKEN }}
|
||||||
commit-message: |
|
commit-message: |
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ This project is composed of:
|
|||||||
### Understanding the code
|
### Understanding the code
|
||||||
|
|
||||||
To get started with developing controllers, you might want to review
|
To get started with developing controllers, you might want to review
|
||||||
[our guide](https://fluxcd.io/docs/gitops-toolkit/source-watcher/) which
|
[our guide](https://fluxcd.io/flux/gitops-toolkit/source-watcher/) which
|
||||||
walks you through writing a short and concise controller that watches out
|
walks you through writing a short and concise controller that watches out
|
||||||
for source changes.
|
for source changes.
|
||||||
|
|
||||||
@@ -67,9 +67,10 @@ for source changes.
|
|||||||
|
|
||||||
Prerequisites:
|
Prerequisites:
|
||||||
|
|
||||||
* go >= 1.17
|
* go >= 1.19
|
||||||
* kubectl >= 1.20
|
* kubectl >= 1.20
|
||||||
* kustomize >= 4.4
|
* kustomize >= 4.4
|
||||||
|
* coreutils (on Mac OS)
|
||||||
|
|
||||||
Install the [controller-runtime/envtest](https://github.com/kubernetes-sigs/controller-runtime/tree/master/tools/setup-envtest) binaries with:
|
Install the [controller-runtime/envtest](https://github.com/kubernetes-sigs/controller-runtime/tree/master/tools/setup-envtest) binaries with:
|
||||||
|
|
||||||
|
|||||||
10
Dockerfile
10
Dockerfile
@@ -1,19 +1,15 @@
|
|||||||
FROM alpine:3.15 as builder
|
FROM alpine:3.17 as builder
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates curl
|
RUN apk add --no-cache ca-certificates curl
|
||||||
|
|
||||||
ARG ARCH=linux/amd64
|
ARG ARCH=linux/amd64
|
||||||
ARG KUBECTL_VER=1.23.1
|
ARG KUBECTL_VER=1.26.1
|
||||||
|
|
||||||
RUN curl -sL https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VER}/bin/${ARCH}/kubectl \
|
RUN curl -sL https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VER}/bin/${ARCH}/kubectl \
|
||||||
-o /usr/local/bin/kubectl && chmod +x /usr/local/bin/kubectl && \
|
-o /usr/local/bin/kubectl && chmod +x /usr/local/bin/kubectl && \
|
||||||
kubectl version --client=true
|
kubectl version --client=true
|
||||||
|
|
||||||
FROM alpine:3.15 as flux-cli
|
FROM alpine:3.17 as flux-cli
|
||||||
|
|
||||||
# Create minimal nsswitch.conf file to prioritize the usage of /etc/hosts over DNS queries.
|
|
||||||
# https://github.com/gliderlabs/docker-alpine/issues/367#issuecomment-354316460
|
|
||||||
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf
|
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates
|
RUN apk add --no-cache ca-certificates
|
||||||
|
|
||||||
|
|||||||
18
MAINTAINERS
18
MAINTAINERS
@@ -2,19 +2,7 @@ The maintainers are generally available in Slack at
|
|||||||
https://cloud-native.slack.com in #flux (https://cloud-native.slack.com/messages/CLAJ40HV3)
|
https://cloud-native.slack.com in #flux (https://cloud-native.slack.com/messages/CLAJ40HV3)
|
||||||
(obtain an invitation at https://slack.cncf.io/).
|
(obtain an invitation at https://slack.cncf.io/).
|
||||||
|
|
||||||
These maintainers are shared with other Flux v2-related git
|
The Flux2 maintainers team is identical with the core maintainers of the project
|
||||||
repositories under https://github.com/fluxcd, as noted in their
|
as listed in
|
||||||
respective MAINTAINERS files.
|
|
||||||
|
|
||||||
For convenience, they are reflected in the GitHub team
|
https://github.com/fluxcd/community/blob/main/CORE-MAINTAINERS
|
||||||
@fluxcd/flux2-maintainers -- if the list here changes, that team also
|
|
||||||
should.
|
|
||||||
|
|
||||||
In alphabetical order:
|
|
||||||
|
|
||||||
Aurel Canciu, NexHealth <aurel.canciu@nexhealth.com> (github: @relu, slack: relu)
|
|
||||||
Hidde Beydals, Weaveworks <hidde@weave.works> (github: @hiddeco, slack: hidde)
|
|
||||||
Max Jonas Werner, D2iQ <max@e13.dev> (github: @makkes, slack: max)
|
|
||||||
Philip Laine, Xenit <philip.laine@xenit.se> (github: @phillebaba, slack: phillebaba)
|
|
||||||
Stefan Prodan, Weaveworks <stefan@weave.works> (github: @stefanprodan, slack: stefanprodan)
|
|
||||||
Sunny, Weaveworks <sunny@weave.works> (github: @darkowlzz, slack: darkowlzz)
|
|
||||||
|
|||||||
8
Makefile
8
Makefile
@@ -1,4 +1,5 @@
|
|||||||
VERSION?=$(shell grep 'VERSION' cmd/flux/main.go | awk '{ print $$4 }' | head -n 1 | tr -d '"')
|
VERSION?=$(shell grep 'VERSION' cmd/flux/main.go | awk '{ print $$4 }' | head -n 1 | tr -d '"')
|
||||||
|
DEV_VERSION?=0.0.0-$(shell git rev-parse --abbrev-ref HEAD)-$(shell git rev-parse --short HEAD)-$(shell date +%s)
|
||||||
EMBEDDED_MANIFESTS_TARGET=cmd/flux/.manifests.done
|
EMBEDDED_MANIFESTS_TARGET=cmd/flux/.manifests.done
|
||||||
TEST_KUBECONFIG?=/tmp/flux-e2e-test-kubeconfig
|
TEST_KUBECONFIG?=/tmp/flux-e2e-test-kubeconfig
|
||||||
# Architecture to use envtest with
|
# Architecture to use envtest with
|
||||||
@@ -16,8 +17,8 @@ rwildcard=$(foreach d,$(wildcard $(addsuffix *,$(1))),$(call rwildcard,$(d)/,$(2
|
|||||||
all: test build
|
all: test build
|
||||||
|
|
||||||
tidy:
|
tidy:
|
||||||
go mod tidy -compat=1.17
|
go mod tidy -compat=1.19
|
||||||
cd tests/azure && go mod tidy -compat=1.17
|
cd tests/azure && go mod tidy -compat=1.19
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
@@ -55,6 +56,9 @@ $(EMBEDDED_MANIFESTS_TARGET): $(call rwildcard,manifests/,*.yaml *.json)
|
|||||||
build: $(EMBEDDED_MANIFESTS_TARGET)
|
build: $(EMBEDDED_MANIFESTS_TARGET)
|
||||||
CGO_ENABLED=0 go build -ldflags="-s -w -X main.VERSION=$(VERSION)" -o ./bin/flux ./cmd/flux
|
CGO_ENABLED=0 go build -ldflags="-s -w -X main.VERSION=$(VERSION)" -o ./bin/flux ./cmd/flux
|
||||||
|
|
||||||
|
build-dev: $(EMBEDDED_MANIFESTS_TARGET)
|
||||||
|
CGO_ENABLED=0 go build -ldflags="-s -w -X main.VERSION=$(DEV_VERSION)" -o ./bin/flux ./cmd/flux
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install:
|
install:
|
||||||
CGO_ENABLED=0 go install ./cmd/flux
|
CGO_ENABLED=0 go install ./cmd/flux
|
||||||
|
|||||||
74
README.md
74
README.md
@@ -1,14 +1,13 @@
|
|||||||
# Flux version 2
|
# Flux version 2
|
||||||
|
|
||||||
[](https://bestpractices.coreinfrastructure.org/projects/4782)
|
|
||||||
[](https://github.com/fluxcd/flux2/actions)
|
|
||||||
[](https://goreportcard.com/report/github.com/fluxcd/flux2)
|
|
||||||
[](https://github.com/fluxcd/flux2/blob/main/LICENSE)
|
|
||||||
[](https://github.com/fluxcd/flux2/releases)
|
[](https://github.com/fluxcd/flux2/releases)
|
||||||
|
[](https://bestpractices.coreinfrastructure.org/projects/4782)
|
||||||
|
[](https://app.fossa.com/projects/custom%2B162%2Fgithub.com%2Ffluxcd%2Fflux2?ref=badge_shield)
|
||||||
|
[](https://artifacthub.io/packages/helm/fluxcd-community/flux2)
|
||||||
|
|
||||||
Flux is a tool for keeping Kubernetes clusters in sync with sources of
|
Flux is a tool for keeping Kubernetes clusters in sync with sources of
|
||||||
configuration (like Git repositories), and automating updates to
|
configuration (like Git repositories and OCI artifacts),
|
||||||
configuration when there is new code to deploy.
|
and automating updates to configuration when there is new code to deploy.
|
||||||
|
|
||||||
Flux version 2 ("v2") is built from the ground up to use Kubernetes'
|
Flux version 2 ("v2") is built from the ground up to use Kubernetes'
|
||||||
API extension system, and to integrate with Prometheus and other core
|
API extension system, and to integrate with Prometheus and other core
|
||||||
@@ -20,18 +19,19 @@ Flux v2 is constructed with the [GitOps Toolkit](#gitops-toolkit), a
|
|||||||
set of composable APIs and specialized tools for building Continuous
|
set of composable APIs and specialized tools for building Continuous
|
||||||
Delivery on top of Kubernetes.
|
Delivery on top of Kubernetes.
|
||||||
|
|
||||||
Flux is a Cloud Native Computing Foundation ([CNCF](https://www.cncf.io/)) project.
|
Flux is a Cloud Native Computing Foundation ([CNCF](https://www.cncf.io/)) project, used in
|
||||||
|
production by various [organisations](https://fluxcd.io/adopters) and [cloud providers](https://fluxcd.io/ecosystem).
|
||||||
|
|
||||||
## Quickstart and documentation
|
## Quickstart and documentation
|
||||||
|
|
||||||
To get started check out this [guide](https://fluxcd.io/docs/get-started/)
|
To get started check out this [guide](https://fluxcd.io/flux/get-started/)
|
||||||
on how to bootstrap Flux on Kubernetes and deploy a sample application in a GitOps manner.
|
on how to bootstrap Flux on Kubernetes and deploy a sample application in a GitOps manner.
|
||||||
|
|
||||||
For more comprehensive documentation, see the following guides:
|
For more comprehensive documentation, see the following guides:
|
||||||
- [Ways of structuring your repositories](https://fluxcd.io/docs/guides/repository-structure/)
|
- [Ways of structuring your repositories](https://fluxcd.io/flux/guides/repository-structure/)
|
||||||
- [Manage Helm Releases](https://fluxcd.io/docs/guides/helmreleases/)
|
- [Manage Helm Releases](https://fluxcd.io/flux/guides/helmreleases/)
|
||||||
- [Automate image updates to Git](https://fluxcd.io/docs/guides/image-update/)
|
- [Automate image updates to Git](https://fluxcd.io/flux/guides/image-update/)
|
||||||
- [Manage Kubernetes secrets with Mozilla SOPS](https://fluxcd.io/docs/guides/mozilla-sops/)
|
- [Manage Kubernetes secrets with Mozilla SOPS](https://fluxcd.io/flux/guides/mozilla-sops/)
|
||||||
|
|
||||||
If you need help, please refer to our **[Support page](https://fluxcd.io/support/)**.
|
If you need help, please refer to our **[Support page](https://fluxcd.io/support/)**.
|
||||||
|
|
||||||
@@ -46,27 +46,28 @@ automation tooling.
|
|||||||
|
|
||||||
You can use the toolkit to extend Flux, or to build your own systems
|
You can use the toolkit to extend Flux, or to build your own systems
|
||||||
for continuous delivery -- see [the developer
|
for continuous delivery -- see [the developer
|
||||||
guides](https://fluxcd.io/docs/gitops-toolkit/source-watcher/).
|
guides](https://fluxcd.io/flux/gitops-toolkit/source-watcher/).
|
||||||
|
|
||||||
### Components
|
### Components
|
||||||
|
|
||||||
- [Source Controller](https://fluxcd.io/docs/components/source/)
|
- [Source Controller](https://fluxcd.io/flux/components/source/)
|
||||||
- [GitRepository CRD](https://fluxcd.io/docs/components/source/gitrepositories/)
|
- [GitRepository CRD](https://fluxcd.io/flux/components/source/gitrepositories/)
|
||||||
- [HelmRepository CRD](https://fluxcd.io/docs/components/source/helmrepositories/)
|
- [OCIRepository CRD](https://fluxcd.io/flux/components/source/ocirepositories/)
|
||||||
- [HelmChart CRD](https://fluxcd.io/docs/components/source/helmcharts/)
|
- [HelmRepository CRD](https://fluxcd.io/flux/components/source/helmrepositories/)
|
||||||
- [Bucket CRD](https://fluxcd.io/docs/components/source/buckets/)
|
- [HelmChart CRD](https://fluxcd.io/flux/components/source/helmcharts/)
|
||||||
- [Kustomize Controller](https://fluxcd.io/docs/components/kustomize/)
|
- [Bucket CRD](https://fluxcd.io/flux/components/source/buckets/)
|
||||||
- [Kustomization CRD](https://fluxcd.io/docs/components/kustomize/kustomization/)
|
- [Kustomize Controller](https://fluxcd.io/flux/components/kustomize/)
|
||||||
- [Helm Controller](https://fluxcd.io/docs/components/helm/)
|
- [Kustomization CRD](https://fluxcd.io/flux/components/kustomize/kustomization/)
|
||||||
- [HelmRelease CRD](https://fluxcd.io/docs/components/helm/helmreleases/)
|
- [Helm Controller](https://fluxcd.io/flux/components/helm/)
|
||||||
- [Notification Controller](https://fluxcd.io/docs/components/notification/)
|
- [HelmRelease CRD](https://fluxcd.io/flux/components/helm/helmreleases/)
|
||||||
- [Provider CRD](https://fluxcd.io/docs/components/notification/provider/)
|
- [Notification Controller](https://fluxcd.io/flux/components/notification/)
|
||||||
- [Alert CRD](https://fluxcd.io/docs/components/notification/alert/)
|
- [Provider CRD](https://fluxcd.io/flux/components/notification/provider/)
|
||||||
- [Receiver CRD](https://fluxcd.io/docs/components/notification/receiver/)
|
- [Alert CRD](https://fluxcd.io/flux/components/notification/alert/)
|
||||||
- [Image Automation Controllers](https://fluxcd.io/docs/components/image/)
|
- [Receiver CRD](https://fluxcd.io/flux/components/notification/receiver/)
|
||||||
- [ImageRepository CRD](https://fluxcd.io/docs/components/image/imagerepositories/)
|
- [Image Automation Controllers](https://fluxcd.io/flux/components/image/)
|
||||||
- [ImagePolicy CRD](https://fluxcd.io/docs/components/image/imagepolicies/)
|
- [ImageRepository CRD](https://fluxcd.io/flux/components/image/imagerepositories/)
|
||||||
- [ImageUpdateAutomation CRD](https://fluxcd.io/docs/components/image/imageupdateautomations/)
|
- [ImagePolicy CRD](https://fluxcd.io/flux/components/image/imagepolicies/)
|
||||||
|
- [ImageUpdateAutomation CRD](https://fluxcd.io/flux/components/image/imageupdateautomations/)
|
||||||
|
|
||||||
## Community
|
## Community
|
||||||
|
|
||||||
@@ -74,18 +75,19 @@ Need help or want to contribute? Please see the links below. The Flux project is
|
|||||||
new contributors and there are a multitude of ways to get involved.
|
new contributors and there are a multitude of ways to get involved.
|
||||||
|
|
||||||
- Getting Started?
|
- Getting Started?
|
||||||
- Look at our [Get Started guide](https://fluxcd.io/docs/get-started/) and give us feedback
|
- Look at our [Get Started guide](https://fluxcd.io/flux/get-started/) and give us feedback
|
||||||
- Need help?
|
- Need help?
|
||||||
- First: Ask questions on our [GH Discussions page](https://github.com/fluxcd/flux2/discussions)
|
- First: Ask questions on our [GH Discussions page](https://github.com/fluxcd/flux2/discussions).
|
||||||
- Second: Talk to us in the #flux channel on [CNCF Slack](https://slack.cncf.io/)
|
- Second: Talk to us in the #flux channel on [CNCF Slack](https://slack.cncf.io/).
|
||||||
- Please follow our [Support Guidelines](https://fluxcd.io/support/)
|
- Please follow our [Support Guidelines](https://fluxcd.io/support/)
|
||||||
(in short: be nice, be respectful of volunteers' time, understand that maintainers and
|
(in short: be nice, be respectful of volunteers' time, understand that maintainers and
|
||||||
contributors cannot respond to all DMs, and keep discussions in the public #flux channel as much as possible).
|
contributors cannot respond to all DMs, and keep discussions in the public #flux channel as much as possible).
|
||||||
- Have feature proposals or want to contribute?
|
- Have feature proposals or want to contribute?
|
||||||
- Propose features on our [GH Discussions page](https://github.com/fluxcd/flux2/discussions)
|
- Propose features on our [GitHub Discussions page](https://github.com/fluxcd/flux2/discussions).
|
||||||
- Join our upcoming dev meetings ([meeting access and agenda](https://docs.google.com/document/d/1l_M0om0qUEN_NNiGgpqJ2tvsF2iioHkaARDeh6b70B0/view))
|
- Join our upcoming dev meetings ([meeting access and agenda](https://docs.google.com/document/d/1l_M0om0qUEN_NNiGgpqJ2tvsF2iioHkaARDeh6b70B0/view)).
|
||||||
- [Join the flux-dev mailing list](https://lists.cncf.io/g/cncf-flux-dev).
|
- [Join the flux-dev mailing list](https://lists.cncf.io/g/cncf-flux-dev).
|
||||||
- Check out [how to contribute](CONTRIBUTING.md) to the project
|
- Check out [how to contribute](CONTRIBUTING.md) to the project.
|
||||||
|
- Check out the [project roadmap](https://fluxcd.io/roadmap/).
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
|||||||
118
action/README.md
118
action/README.md
@@ -32,9 +32,23 @@ You can download a specific version with:
|
|||||||
- name: Setup Flux CLI
|
- name: Setup Flux CLI
|
||||||
uses: fluxcd/flux2/action@main
|
uses: fluxcd/flux2/action@main
|
||||||
with:
|
with:
|
||||||
version: 0.8.0
|
version: 0.32.0
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can also authenticate against the GitHub API using GitHub Actions' `GITHUB_TOKEN` secret.
|
||||||
|
|
||||||
|
For more information, please [read about the GitHub token secret](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret).
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- name: Setup Flux CLI
|
||||||
|
uses: fluxcd/flux2/action@main
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is useful if you are seeing failures on shared runners, those failures are usually API limits being hit.
|
||||||
|
|
||||||
### Automate Flux updates
|
### Automate Flux updates
|
||||||
|
|
||||||
Example workflow for updating Flux's components generated with `flux bootstrap --path=clusters/production`:
|
Example workflow for updating Flux's components generated with `flux bootstrap --path=clusters/production`:
|
||||||
@@ -52,7 +66,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code
|
- name: Check out code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: Setup Flux CLI
|
- name: Setup Flux CLI
|
||||||
uses: fluxcd/flux2/action@main
|
uses: fluxcd/flux2/action@main
|
||||||
- name: Check for updates
|
- name: Check for updates
|
||||||
@@ -62,9 +76,9 @@ jobs:
|
|||||||
--export > ./clusters/production/flux-system/gotk-components.yaml
|
--export > ./clusters/production/flux-system/gotk-components.yaml
|
||||||
|
|
||||||
VERSION="$(flux -v)"
|
VERSION="$(flux -v)"
|
||||||
echo "::set-output name=flux_version::$VERSION"
|
echo "flux_version=$VERSION" >> $GITHUB_OUTPUT
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
uses: peter-evans/create-pull-request@v3
|
uses: peter-evans/create-pull-request@v4
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
branch: update-flux
|
branch: update-flux
|
||||||
@@ -74,6 +88,100 @@ jobs:
|
|||||||
${{ steps.update.outputs.flux_version }}
|
${{ steps.update.outputs.flux_version }}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Push Kubernetes manifests to container registries
|
||||||
|
|
||||||
|
Example workflow for publishing Kubernetes manifests bundled as OCI artifacts to GitHub Container Registry:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: push-artifact-staging
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'main'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
packages: write # needed for ghcr.io access
|
||||||
|
|
||||||
|
env:
|
||||||
|
OCI_REPO: "oci://ghcr.io/my-org/manifests/${{ github.event.repository.name }}"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
kubernetes:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Flux CLI
|
||||||
|
uses: fluxcd/flux2/action@main
|
||||||
|
- name: Login to GHCR
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Generate manifests
|
||||||
|
run: |
|
||||||
|
kustomize build ./manifests/staging > ./deploy/app.yaml
|
||||||
|
- name: Push manifests
|
||||||
|
run: |
|
||||||
|
flux push artifact $OCI_REPO:$(git rev-parse --short HEAD) \
|
||||||
|
--path="./deploy" \
|
||||||
|
--source="$(git config --get remote.origin.url)" \
|
||||||
|
--revision="$(git branch --show-current)/$(git rev-parse HEAD)"
|
||||||
|
- name: Deploy manifests to staging
|
||||||
|
run: |
|
||||||
|
flux tag artifact $OCI_REPO:$(git rev-parse --short HEAD) --tag staging
|
||||||
|
```
|
||||||
|
|
||||||
|
### Push and sign Kubernetes manifests to container registries
|
||||||
|
|
||||||
|
Example workflow for publishing Kubernetes manifests bundled as OCI artifacts
|
||||||
|
which are signed with Cosign and GitHub OIDC:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: push-sign-artifact
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'main'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
packages: write # needed for ghcr.io access
|
||||||
|
id-token: write # needed for keyless signing
|
||||||
|
|
||||||
|
env:
|
||||||
|
OCI_REPO: "oci://ghcr.io/my-org/manifests/${{ github.event.repository.name }}"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
kubernetes:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Flux CLI
|
||||||
|
uses: fluxcd/flux2/action@main
|
||||||
|
- name: Setup Cosign
|
||||||
|
uses: sigstore/cosign-installer@main
|
||||||
|
- name: Login to GHCR
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Push and sign manifests
|
||||||
|
run: |
|
||||||
|
digest_url=$(flux push artifact \
|
||||||
|
$OCI_REPO:$(git rev-parse --short HEAD) \
|
||||||
|
--path="./manifests" \
|
||||||
|
--source="$(git config --get remote.origin.url)" \
|
||||||
|
--revision="$(git branch --show-current)/$(git rev-parse HEAD)" |\
|
||||||
|
jq -r '. | .repository + "@" + .digest')
|
||||||
|
|
||||||
|
cosign sign $digest_url
|
||||||
|
```
|
||||||
|
|
||||||
### End-to-end testing
|
### End-to-end testing
|
||||||
|
|
||||||
Example workflow for running Flux in Kubernetes Kind:
|
Example workflow for running Flux in Kubernetes Kind:
|
||||||
@@ -91,7 +199,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: Setup Flux CLI
|
- name: Setup Flux CLI
|
||||||
uses: fluxcd/flux2/action@main
|
uses: fluxcd/flux2/action@main
|
||||||
- name: Setup Kubernetes Kind
|
- name: Setup Kubernetes Kind
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ inputs:
|
|||||||
bindir:
|
bindir:
|
||||||
description: "Optional location of the Flux binary. Will not use sudo if set. Updates System Path."
|
description: "Optional location of the Flux binary. Will not use sudo if set. Updates System Path."
|
||||||
required: false
|
required: false
|
||||||
|
token:
|
||||||
|
description: "GitHub Token used to authentication against the API (generally only needed to prevent quota limit errors)"
|
||||||
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
@@ -23,20 +26,29 @@ runs:
|
|||||||
run: |
|
run: |
|
||||||
ARCH=${{ inputs.arch }}
|
ARCH=${{ inputs.arch }}
|
||||||
VERSION=${{ inputs.version }}
|
VERSION=${{ inputs.version }}
|
||||||
|
TOKEN=${{ inputs.token }}
|
||||||
|
|
||||||
if [ -z $VERSION ]; then
|
if [ -z "${VERSION}" ]; then
|
||||||
VERSION=$(curl https://api.github.com/repos/fluxcd/flux2/releases/latest -sL | grep tag_name | sed -E 's/.*"([^"]+)".*/\1/' | cut -c 2-)
|
if [ -n "${TOKEN}" ]; then
|
||||||
|
VERSION_SLUG=$(curl https://api.github.com/repos/fluxcd/flux2/releases/latest --silent --location --header "Authorization: token ${TOKEN}" | grep tag_name)
|
||||||
|
else
|
||||||
|
# With no GITHUB_TOKEN you will experience occasional failures due to rate limiting
|
||||||
|
# Ref: https://github.com/fluxcd/flux2/issues/3509#issuecomment-1400820992
|
||||||
|
VERSION_SLUG=$(curl https://api.github.com/repos/fluxcd/flux2/releases/latest --silent --location | grep tag_name)
|
||||||
|
fi
|
||||||
|
|
||||||
|
VERSION=$(echo "${VERSION_SLUG}" | sed -E 's/.*"([^"]+)".*/\1/' | cut -c 2-)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BIN_URL="https://github.com/fluxcd/flux2/releases/download/v${VERSION}/flux_${VERSION}_linux_${ARCH}.tar.gz"
|
BIN_URL="https://github.com/fluxcd/flux2/releases/download/v${VERSION}/flux_${VERSION}_linux_${ARCH}.tar.gz"
|
||||||
curl -sL ${BIN_URL} -o /tmp/flux.tar.gz
|
curl --silent --fail --location "${BIN_URL}" --output /tmp/flux.tar.gz
|
||||||
mkdir -p /tmp/flux
|
mkdir -p /tmp/flux
|
||||||
tar -C /tmp/flux/ -zxvf /tmp/flux.tar.gz
|
tar -C /tmp/flux/ -zxvf /tmp/flux.tar.gz
|
||||||
- name: "Copy Flux binary to execute location"
|
- name: "Copy Flux binary to execute location"
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
BINDIR=${{ inputs.bindir }}
|
BINDIR=${{ inputs.bindir }}
|
||||||
if [ -z $BINDIR ]; then
|
if [ -z "${BINDIR}" ]; then
|
||||||
sudo cp /tmp/flux/flux /usr/local/bin
|
sudo cp /tmp/flux/flux /usr/local/bin
|
||||||
else
|
else
|
||||||
cp /tmp/flux/flux "${BINDIR}"
|
cp /tmp/flux/flux "${BINDIR}"
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// notificationv1.Alert
|
// notificationv1.Alert
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// notificationv1.Provider
|
// notificationv1.Provider
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ func buildEmbeddedManifestBase() (string, error) {
|
|||||||
if !isEmbeddedVersion(bootstrapArgs.version) {
|
if !isEmbeddedVersion(bootstrapArgs.version) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
tmpBaseDir, err := os.MkdirTemp("", "flux-manifests-")
|
tmpBaseDir, err := manifestgen.MkdirTempAbs("", "flux-manifests-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,14 +22,15 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
"github.com/fluxcd/pkg/git"
|
||||||
|
"github.com/fluxcd/pkg/git/gogit"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/bootstrap"
|
|
||||||
"github.com/fluxcd/flux2/internal/bootstrap/git/gogit"
|
|
||||||
"github.com/fluxcd/flux2/internal/bootstrap/provider"
|
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/bootstrap"
|
||||||
|
"github.com/fluxcd/flux2/pkg/bootstrap/provider"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
||||||
@@ -121,13 +122,15 @@ func bootstrapBServerCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manifest base
|
// Manifest base
|
||||||
if ver, err := getVersion(bootstrapArgs.version); err == nil {
|
if ver, err := getVersion(bootstrapArgs.version); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
bootstrapArgs.version = ver
|
bootstrapArgs.version = ver
|
||||||
}
|
}
|
||||||
manifestsBase, err := buildEmbeddedManifestBase()
|
manifestsBase, err := buildEmbeddedManifestBase()
|
||||||
@@ -165,15 +168,22 @@ func bootstrapBServerCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Lazy go-git repository
|
// Lazy go-git repository
|
||||||
tmpDir, err := os.MkdirTemp("", "flux-bootstrap-")
|
tmpDir, err := manifestgen.MkdirTempAbs("", "flux-bootstrap-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
gitClient := gogit.New(tmpDir, &http.BasicAuth{
|
|
||||||
Username: user,
|
clientOpts := []gogit.ClientOption{gogit.WithDiskStorage(), gogit.WithFallbackToDefaultKnownHosts()}
|
||||||
Password: bitbucketToken,
|
gitClient, err := gogit.NewClient(tmpDir, &git.AuthOptions{
|
||||||
})
|
Transport: git.HTTPS,
|
||||||
|
Username: user,
|
||||||
|
Password: bitbucketToken,
|
||||||
|
CAFile: caBundle,
|
||||||
|
}, clientOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create a Git client: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Install manifest config
|
// Install manifest config
|
||||||
installOptions := install.Options{
|
installOptions := install.Options{
|
||||||
@@ -211,19 +221,18 @@ func bootstrapBServerCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
secretOpts.Username = bServerArgs.username
|
secretOpts.Username = bServerArgs.username
|
||||||
}
|
}
|
||||||
secretOpts.Password = bitbucketToken
|
secretOpts.Password = bitbucketToken
|
||||||
|
secretOpts.CAFile = caBundle
|
||||||
if bootstrapArgs.caFile != "" {
|
|
||||||
secretOpts.CAFilePath = bootstrapArgs.caFile
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
keypair, err := sourcesecret.LoadKeyPairFromPath(bootstrapArgs.privateKeyFile, gitArgs.password)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
secretOpts.Keypair = keypair
|
||||||
secretOpts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(bootstrapArgs.keyAlgorithm)
|
secretOpts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(bootstrapArgs.keyAlgorithm)
|
||||||
secretOpts.RSAKeyBits = int(bootstrapArgs.keyRSABits)
|
secretOpts.RSAKeyBits = int(bootstrapArgs.keyRSABits)
|
||||||
secretOpts.ECDSACurve = bootstrapArgs.keyECDSACurve.Curve
|
secretOpts.ECDSACurve = bootstrapArgs.keyECDSACurve.Curve
|
||||||
secretOpts.SSHHostname = bServerArgs.hostname
|
|
||||||
|
|
||||||
if bootstrapArgs.privateKeyFile != "" {
|
secretOpts.SSHHostname = bServerArgs.hostname
|
||||||
secretOpts.PrivateKeyPath = bootstrapArgs.privateKeyFile
|
|
||||||
}
|
|
||||||
if bootstrapArgs.sshHostname != "" {
|
if bootstrapArgs.sshHostname != "" {
|
||||||
secretOpts.SSHHostname = bootstrapArgs.sshHostname
|
secretOpts.SSHHostname = bootstrapArgs.sshHostname
|
||||||
}
|
}
|
||||||
@@ -242,19 +251,24 @@ func bootstrapBServerCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
RecurseSubmodules: bootstrapArgs.recurseSubmodules,
|
RecurseSubmodules: bootstrapArgs.recurseSubmodules,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entityList, err := bootstrap.LoadEntityListFromPath(bootstrapArgs.gpgKeyRingPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Bootstrap config
|
// Bootstrap config
|
||||||
|
|
||||||
bootstrapOpts := []bootstrap.GitProviderOption{
|
bootstrapOpts := []bootstrap.GitProviderOption{
|
||||||
bootstrap.WithProviderRepository(bServerArgs.owner, bServerArgs.repository, bServerArgs.personal),
|
bootstrap.WithProviderRepository(bServerArgs.owner, bServerArgs.repository, bServerArgs.personal),
|
||||||
bootstrap.WithBranch(bootstrapArgs.branch),
|
bootstrap.WithBranch(bootstrapArgs.branch),
|
||||||
bootstrap.WithBootstrapTransportType("https"),
|
bootstrap.WithBootstrapTransportType("https"),
|
||||||
bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail),
|
bootstrap.WithSignature(bootstrapArgs.authorName, bootstrapArgs.authorEmail),
|
||||||
bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix),
|
bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix),
|
||||||
bootstrap.WithProviderTeamPermissions(mapTeamSlice(bServerArgs.teams, bServerDefaultPermission)),
|
bootstrap.WithProviderTeamPermissions(mapTeamSlice(bServerArgs.teams, bServerDefaultPermission)),
|
||||||
bootstrap.WithReadWriteKeyPermissions(bServerArgs.readWriteKey),
|
bootstrap.WithReadWriteKeyPermissions(bServerArgs.readWriteKey),
|
||||||
bootstrap.WithKubeconfig(kubeconfigArgs),
|
bootstrap.WithKubeconfig(kubeconfigArgs, kubeclientOptions),
|
||||||
bootstrap.WithLogger(logger),
|
bootstrap.WithLogger(logger),
|
||||||
bootstrap.WithCABundle(caBundle),
|
bootstrap.WithGitCommitSigning(entityList, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID),
|
||||||
bootstrap.WithGitCommitSigning(bootstrapArgs.gpgKeyRingPath, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID),
|
|
||||||
}
|
}
|
||||||
if bootstrapArgs.sshHostname != "" {
|
if bootstrapArgs.sshHostname != "" {
|
||||||
bootstrapOpts = append(bootstrapOpts, bootstrap.WithSSHHostname(bootstrapArgs.sshHostname))
|
bootstrapOpts = append(bootstrapOpts, bootstrap.WithSSHHostname(bootstrapArgs.sshHostname))
|
||||||
|
|||||||
@@ -24,20 +24,19 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5/plumbing/transport"
|
|
||||||
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
|
||||||
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
|
|
||||||
"github.com/manifoldco/promptui"
|
"github.com/manifoldco/promptui"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/bootstrap"
|
|
||||||
"github.com/fluxcd/flux2/internal/bootstrap/git/gogit"
|
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/bootstrap"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
||||||
|
"github.com/fluxcd/pkg/git"
|
||||||
|
"github.com/fluxcd/pkg/git/gogit"
|
||||||
)
|
)
|
||||||
|
|
||||||
var bootstrapGitCmd = &cobra.Command{
|
var bootstrapGitCmd = &cobra.Command{
|
||||||
@@ -53,24 +52,38 @@ command will perform an upgrade if needed.`,
|
|||||||
# Run bootstrap for a Git repository and authenticate using a password
|
# Run bootstrap for a Git repository and authenticate using a password
|
||||||
flux bootstrap git --url=https://example.com/repository.git --password=<password>
|
flux bootstrap git --url=https://example.com/repository.git --password=<password>
|
||||||
|
|
||||||
|
# Run bootstrap for a Git repository and authenticate using a password from environment variable
|
||||||
|
GIT_PASSWORD=<password> && flux bootstrap git --url=https://example.com/repository.git
|
||||||
|
|
||||||
# Run bootstrap for a Git repository with a passwordless private key
|
# Run bootstrap for a Git repository with a passwordless private key
|
||||||
flux bootstrap git --url=ssh://git@example.com/repository.git --private-key-file=<path/to/private.key>
|
flux bootstrap git --url=ssh://git@example.com/repository.git --private-key-file=<path/to/private.key>
|
||||||
|
|
||||||
# Run bootstrap for a Git repository with a private key and password
|
# Run bootstrap for a Git repository with a private key and password
|
||||||
flux bootstrap git --url=ssh://git@example.com/repository.git --private-key-file=<path/to/private.key> --password=<password>
|
flux bootstrap git --url=ssh://git@example.com/repository.git --private-key-file=<path/to/private.key> --password=<password>
|
||||||
|
|
||||||
|
# Run bootstrap for a Git repository on AWS CodeCommit
|
||||||
|
flux bootstrap git --url=ssh://<SSH-Key-ID>@git-codecommit.<region>.amazonaws.com/v1/repos/<repository> --private-key-file=<path/to/private.key> --password=<SSH-passphrase>
|
||||||
|
|
||||||
|
# Run bootstrap for a Git repository on Azure Devops
|
||||||
|
flux bootstrap git --url=ssh://git@ssh.dev.azure.com/v3/<org>/<project>/<repository> --ssh-key-algorithm=rsa --ssh-rsa-bits=4096
|
||||||
`,
|
`,
|
||||||
RunE: bootstrapGitCmdRun,
|
RunE: bootstrapGitCmdRun,
|
||||||
}
|
}
|
||||||
|
|
||||||
type gitFlags struct {
|
type gitFlags struct {
|
||||||
url string
|
url string
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
path flags.SafeRelativePath
|
path flags.SafeRelativePath
|
||||||
username string
|
username string
|
||||||
password string
|
password string
|
||||||
silent bool
|
silent bool
|
||||||
|
insecureHttpAllowed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
gitPasswordEnvVar = "GIT_PASSWORD"
|
||||||
|
)
|
||||||
|
|
||||||
var gitArgs gitFlags
|
var gitArgs gitFlags
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -80,11 +93,25 @@ func init() {
|
|||||||
bootstrapGitCmd.Flags().StringVarP(&gitArgs.username, "username", "u", "git", "basic authentication username")
|
bootstrapGitCmd.Flags().StringVarP(&gitArgs.username, "username", "u", "git", "basic authentication username")
|
||||||
bootstrapGitCmd.Flags().StringVarP(&gitArgs.password, "password", "p", "", "basic authentication password")
|
bootstrapGitCmd.Flags().StringVarP(&gitArgs.password, "password", "p", "", "basic authentication password")
|
||||||
bootstrapGitCmd.Flags().BoolVarP(&gitArgs.silent, "silent", "s", false, "assumes the deploy key is already setup, skips confirmation")
|
bootstrapGitCmd.Flags().BoolVarP(&gitArgs.silent, "silent", "s", false, "assumes the deploy key is already setup, skips confirmation")
|
||||||
|
bootstrapGitCmd.Flags().BoolVar(&gitArgs.insecureHttpAllowed, "allow-insecure-http", false, "allows http git url connections")
|
||||||
|
|
||||||
bootstrapCmd.AddCommand(bootstrapGitCmd)
|
bootstrapCmd.AddCommand(bootstrapGitCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
gitPassword := os.Getenv(gitPasswordEnvVar)
|
||||||
|
if gitPassword != "" && gitArgs.password == "" {
|
||||||
|
gitArgs.password = gitPassword
|
||||||
|
}
|
||||||
|
if bootstrapArgs.tokenAuth && gitArgs.password == "" {
|
||||||
|
var err error
|
||||||
|
gitPassword, err = readPasswordFromStdin("Please enter your Git repository password: ")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not read token: %w", err)
|
||||||
|
}
|
||||||
|
gitArgs.password = gitPassword
|
||||||
|
}
|
||||||
|
|
||||||
if err := bootstrapValidate(); err != nil {
|
if err := bootstrapValidate(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -93,21 +120,36 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
gitAuth, err := transportForURL(repositoryURL)
|
|
||||||
if err != nil {
|
if strings.Contains(repositoryURL.Hostname(), "git-codecommit") && strings.Contains(repositoryURL.Hostname(), "amazonaws.com") {
|
||||||
return err
|
if repositoryURL.Scheme == string(git.SSH) {
|
||||||
|
if repositoryURL.User == nil {
|
||||||
|
return fmt.Errorf("invalid AWS CodeCommit url: ssh username should be specified in the url")
|
||||||
|
}
|
||||||
|
if repositoryURL.User.Username() == git.DefaultPublicKeyAuthUser {
|
||||||
|
return fmt.Errorf("invalid AWS CodeCommit url: ssh username should be the SSH key ID for the provided private key")
|
||||||
|
}
|
||||||
|
if bootstrapArgs.privateKeyFile == "" {
|
||||||
|
return fmt.Errorf("private key file is required for bootstrapping against AWS CodeCommit using ssh")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if repositoryURL.Scheme == string(git.HTTPS) && !bootstrapArgs.tokenAuth {
|
||||||
|
return fmt.Errorf("--token-auth=true must be specified for using a HTTPS AWS CodeCommit url")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manifest base
|
// Manifest base
|
||||||
if ver, err := getVersion(bootstrapArgs.version); err == nil {
|
if ver, err := getVersion(bootstrapArgs.version); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
bootstrapArgs.version = ver
|
bootstrapArgs.version = ver
|
||||||
}
|
}
|
||||||
manifestsBase, err := buildEmbeddedManifestBase()
|
manifestsBase, err := buildEmbeddedManifestBase()
|
||||||
@@ -117,12 +159,33 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
defer os.RemoveAll(manifestsBase)
|
defer os.RemoveAll(manifestsBase)
|
||||||
|
|
||||||
// Lazy go-git repository
|
// Lazy go-git repository
|
||||||
tmpDir, err := os.MkdirTemp("", "flux-bootstrap-")
|
tmpDir, err := manifestgen.MkdirTempAbs("", "flux-bootstrap-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
gitClient := gogit.New(tmpDir, gitAuth)
|
|
||||||
|
var caBundle []byte
|
||||||
|
if bootstrapArgs.caFile != "" {
|
||||||
|
var err error
|
||||||
|
caBundle, err = os.ReadFile(bootstrapArgs.caFile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to read TLS CA file: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
authOpts, err := getAuthOpts(repositoryURL, caBundle)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create authentication options for %s: %w", repositoryURL.String(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
clientOpts := []gogit.ClientOption{gogit.WithDiskStorage(), gogit.WithFallbackToDefaultKnownHosts()}
|
||||||
|
if gitArgs.insecureHttpAllowed {
|
||||||
|
clientOpts = append(clientOpts, gogit.WithInsecureCredentialsOverHTTP())
|
||||||
|
}
|
||||||
|
gitClient, err := gogit.NewClient(tmpDir, authOpts, clientOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create a Git client: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Install manifest config
|
// Install manifest config
|
||||||
installOptions := install.Options{
|
installOptions := install.Options{
|
||||||
@@ -156,10 +219,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
if bootstrapArgs.tokenAuth {
|
if bootstrapArgs.tokenAuth {
|
||||||
secretOpts.Username = gitArgs.username
|
secretOpts.Username = gitArgs.username
|
||||||
secretOpts.Password = gitArgs.password
|
secretOpts.Password = gitArgs.password
|
||||||
|
secretOpts.CAFile = caBundle
|
||||||
if bootstrapArgs.caFile != "" {
|
|
||||||
secretOpts.CAFilePath = bootstrapArgs.caFile
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove port of the given host when not syncing over HTTP/S to not assume port for protocol
|
// Remove port of the given host when not syncing over HTTP/S to not assume port for protocol
|
||||||
// This _might_ be overwritten later on by e.g. --ssh-hostname
|
// This _might_ be overwritten later on by e.g. --ssh-hostname
|
||||||
@@ -169,7 +229,9 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
// Configure repository URL to match auth config for sync.
|
// Configure repository URL to match auth config for sync.
|
||||||
repositoryURL.User = nil
|
repositoryURL.User = nil
|
||||||
repositoryURL.Scheme = "https"
|
if !gitArgs.insecureHttpAllowed {
|
||||||
|
repositoryURL.Scheme = "https"
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
secretOpts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(bootstrapArgs.keyAlgorithm)
|
secretOpts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(bootstrapArgs.keyAlgorithm)
|
||||||
secretOpts.Password = gitArgs.password
|
secretOpts.Password = gitArgs.password
|
||||||
@@ -188,9 +250,12 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
if bootstrapArgs.sshHostname != "" {
|
if bootstrapArgs.sshHostname != "" {
|
||||||
repositoryURL.Host = bootstrapArgs.sshHostname
|
repositoryURL.Host = bootstrapArgs.sshHostname
|
||||||
}
|
}
|
||||||
if bootstrapArgs.privateKeyFile != "" {
|
|
||||||
secretOpts.PrivateKeyPath = bootstrapArgs.privateKeyFile
|
keypair, err := sourcesecret.LoadKeyPairFromPath(bootstrapArgs.privateKeyFile, gitArgs.password)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
secretOpts.Keypair = keypair
|
||||||
|
|
||||||
// Configure last as it depends on the config above.
|
// Configure last as it depends on the config above.
|
||||||
secretOpts.SSHHostname = repositoryURL.Host
|
secretOpts.SSHHostname = repositoryURL.Host
|
||||||
@@ -210,26 +275,21 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
RecurseSubmodules: bootstrapArgs.recurseSubmodules,
|
RecurseSubmodules: bootstrapArgs.recurseSubmodules,
|
||||||
}
|
}
|
||||||
|
|
||||||
var caBundle []byte
|
entityList, err := bootstrap.LoadEntityListFromPath(bootstrapArgs.gpgKeyRingPath)
|
||||||
if bootstrapArgs.caFile != "" {
|
if err != nil {
|
||||||
var err error
|
return err
|
||||||
caBundle, err = os.ReadFile(bootstrapArgs.caFile)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unable to read TLS CA file: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bootstrap config
|
// Bootstrap config
|
||||||
bootstrapOpts := []bootstrap.GitOption{
|
bootstrapOpts := []bootstrap.GitOption{
|
||||||
bootstrap.WithRepositoryURL(gitArgs.url),
|
bootstrap.WithRepositoryURL(gitArgs.url),
|
||||||
bootstrap.WithBranch(bootstrapArgs.branch),
|
bootstrap.WithBranch(bootstrapArgs.branch),
|
||||||
bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail),
|
bootstrap.WithSignature(bootstrapArgs.authorName, bootstrapArgs.authorEmail),
|
||||||
bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix),
|
bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix),
|
||||||
bootstrap.WithKubeconfig(kubeconfigArgs),
|
bootstrap.WithKubeconfig(kubeconfigArgs, kubeclientOptions),
|
||||||
bootstrap.WithPostGenerateSecretFunc(promptPublicKey),
|
bootstrap.WithPostGenerateSecretFunc(promptPublicKey),
|
||||||
bootstrap.WithLogger(logger),
|
bootstrap.WithLogger(logger),
|
||||||
bootstrap.WithCABundle(caBundle),
|
bootstrap.WithGitCommitSigning(entityList, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID),
|
||||||
bootstrap.WithGitCommitSigning(bootstrapArgs.gpgKeyRingPath, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup bootstrapper with constructed configs
|
// Setup bootstrapper with constructed configs
|
||||||
@@ -242,22 +302,47 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return bootstrap.Run(ctx, b, manifestsBase, installOptions, secretOpts, syncOpts, rootArgs.pollInterval, rootArgs.timeout)
|
return bootstrap.Run(ctx, b, manifestsBase, installOptions, secretOpts, syncOpts, rootArgs.pollInterval, rootArgs.timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// transportForURL constructs a transport.AuthMethod based on the scheme
|
// getAuthOpts retruns a AuthOptions based on the scheme
|
||||||
// of the given URL and the configured flags. If the protocol equals
|
// of the given URL and the configured flags. If the protocol equals
|
||||||
// "ssh" but no private key is configured, authentication using the local
|
// "ssh" but no private key is configured, authentication using the local
|
||||||
// SSH-agent is attempted.
|
// SSH-agent is attempted.
|
||||||
func transportForURL(u *url.URL) (transport.AuthMethod, error) {
|
func getAuthOpts(u *url.URL, caBundle []byte) (*git.AuthOptions, error) {
|
||||||
switch u.Scheme {
|
switch u.Scheme {
|
||||||
|
case "http":
|
||||||
|
if !gitArgs.insecureHttpAllowed {
|
||||||
|
return nil, fmt.Errorf("scheme http is insecure, pass --allow-insecure-http=true to allow it")
|
||||||
|
}
|
||||||
|
return &git.AuthOptions{
|
||||||
|
Transport: git.HTTP,
|
||||||
|
Username: gitArgs.username,
|
||||||
|
Password: gitArgs.password,
|
||||||
|
}, nil
|
||||||
case "https":
|
case "https":
|
||||||
return &http.BasicAuth{
|
return &git.AuthOptions{
|
||||||
Username: gitArgs.username,
|
Transport: git.HTTPS,
|
||||||
Password: gitArgs.password,
|
Username: gitArgs.username,
|
||||||
|
Password: gitArgs.password,
|
||||||
|
CAFile: caBundle,
|
||||||
}, nil
|
}, nil
|
||||||
case "ssh":
|
case "ssh":
|
||||||
if bootstrapArgs.privateKeyFile != "" {
|
authOpts := &git.AuthOptions{
|
||||||
return ssh.NewPublicKeysFromFile(u.User.Username(), bootstrapArgs.privateKeyFile, gitArgs.password)
|
Transport: git.SSH,
|
||||||
|
Username: u.User.Username(),
|
||||||
|
Password: gitArgs.password,
|
||||||
}
|
}
|
||||||
return nil, nil
|
if bootstrapArgs.privateKeyFile != "" {
|
||||||
|
pk, err := os.ReadFile(bootstrapArgs.privateKeyFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
kh, err := sourcesecret.ScanHostKey(u.Host)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
authOpts.Identity = pk
|
||||||
|
authOpts.KnownHosts = kh
|
||||||
|
}
|
||||||
|
return authOpts, nil
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("scheme %q is not supported", u.Scheme)
|
return nil, fmt.Errorf("scheme %q is not supported", u.Scheme)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,14 +22,15 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
"github.com/fluxcd/pkg/git"
|
||||||
|
"github.com/fluxcd/pkg/git/gogit"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/bootstrap"
|
|
||||||
"github.com/fluxcd/flux2/internal/bootstrap/git/gogit"
|
|
||||||
"github.com/fluxcd/flux2/internal/bootstrap/provider"
|
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/bootstrap"
|
||||||
|
"github.com/fluxcd/flux2/pkg/bootstrap/provider"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
||||||
@@ -125,13 +126,15 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manifest base
|
// Manifest base
|
||||||
if ver, err := getVersion(bootstrapArgs.version); err == nil {
|
if ver, err := getVersion(bootstrapArgs.version); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
bootstrapArgs.version = ver
|
bootstrapArgs.version = ver
|
||||||
}
|
}
|
||||||
manifestsBase, err := buildEmbeddedManifestBase()
|
manifestsBase, err := buildEmbeddedManifestBase()
|
||||||
@@ -160,16 +163,22 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lazy go-git repository
|
tmpDir, err := manifestgen.MkdirTempAbs("", "flux-bootstrap-")
|
||||||
tmpDir, err := os.MkdirTemp("", "flux-bootstrap-")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
gitClient := gogit.New(tmpDir, &http.BasicAuth{
|
|
||||||
Username: githubArgs.owner,
|
clientOpts := []gogit.ClientOption{gogit.WithDiskStorage(), gogit.WithFallbackToDefaultKnownHosts()}
|
||||||
Password: ghToken,
|
gitClient, err := gogit.NewClient(tmpDir, &git.AuthOptions{
|
||||||
})
|
Transport: git.HTTPS,
|
||||||
|
Username: githubArgs.owner,
|
||||||
|
Password: ghToken,
|
||||||
|
CAFile: caBundle,
|
||||||
|
}, clientOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create a Git client: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Install manifest config
|
// Install manifest config
|
||||||
installOptions := install.Options{
|
installOptions := install.Options{
|
||||||
@@ -203,16 +212,13 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
if bootstrapArgs.tokenAuth {
|
if bootstrapArgs.tokenAuth {
|
||||||
secretOpts.Username = "git"
|
secretOpts.Username = "git"
|
||||||
secretOpts.Password = ghToken
|
secretOpts.Password = ghToken
|
||||||
|
secretOpts.CAFile = caBundle
|
||||||
if bootstrapArgs.caFile != "" {
|
|
||||||
secretOpts.CAFilePath = bootstrapArgs.caFile
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
secretOpts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(bootstrapArgs.keyAlgorithm)
|
secretOpts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(bootstrapArgs.keyAlgorithm)
|
||||||
secretOpts.RSAKeyBits = int(bootstrapArgs.keyRSABits)
|
secretOpts.RSAKeyBits = int(bootstrapArgs.keyRSABits)
|
||||||
secretOpts.ECDSACurve = bootstrapArgs.keyECDSACurve.Curve
|
secretOpts.ECDSACurve = bootstrapArgs.keyECDSACurve.Curve
|
||||||
secretOpts.SSHHostname = githubArgs.hostname
|
|
||||||
|
|
||||||
|
secretOpts.SSHHostname = githubArgs.hostname
|
||||||
if bootstrapArgs.sshHostname != "" {
|
if bootstrapArgs.sshHostname != "" {
|
||||||
secretOpts.SSHHostname = bootstrapArgs.sshHostname
|
secretOpts.SSHHostname = bootstrapArgs.sshHostname
|
||||||
}
|
}
|
||||||
@@ -231,19 +237,23 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
RecurseSubmodules: bootstrapArgs.recurseSubmodules,
|
RecurseSubmodules: bootstrapArgs.recurseSubmodules,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entityList, err := bootstrap.LoadEntityListFromPath(bootstrapArgs.gpgKeyRingPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Bootstrap config
|
// Bootstrap config
|
||||||
bootstrapOpts := []bootstrap.GitProviderOption{
|
bootstrapOpts := []bootstrap.GitProviderOption{
|
||||||
bootstrap.WithProviderRepository(githubArgs.owner, githubArgs.repository, githubArgs.personal),
|
bootstrap.WithProviderRepository(githubArgs.owner, githubArgs.repository, githubArgs.personal),
|
||||||
bootstrap.WithBranch(bootstrapArgs.branch),
|
bootstrap.WithBranch(bootstrapArgs.branch),
|
||||||
bootstrap.WithBootstrapTransportType("https"),
|
bootstrap.WithBootstrapTransportType("https"),
|
||||||
bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail),
|
bootstrap.WithSignature(bootstrapArgs.authorName, bootstrapArgs.authorEmail),
|
||||||
bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix),
|
bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix),
|
||||||
bootstrap.WithProviderTeamPermissions(mapTeamSlice(githubArgs.teams, ghDefaultPermission)),
|
bootstrap.WithProviderTeamPermissions(mapTeamSlice(githubArgs.teams, ghDefaultPermission)),
|
||||||
bootstrap.WithReadWriteKeyPermissions(githubArgs.readWriteKey),
|
bootstrap.WithReadWriteKeyPermissions(githubArgs.readWriteKey),
|
||||||
bootstrap.WithKubeconfig(kubeconfigArgs),
|
bootstrap.WithKubeconfig(kubeconfigArgs, kubeclientOptions),
|
||||||
bootstrap.WithLogger(logger),
|
bootstrap.WithLogger(logger),
|
||||||
bootstrap.WithCABundle(caBundle),
|
bootstrap.WithGitCommitSigning(entityList, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID),
|
||||||
bootstrap.WithGitCommitSigning(bootstrapArgs.gpgKeyRingPath, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID),
|
|
||||||
}
|
}
|
||||||
if bootstrapArgs.sshHostname != "" {
|
if bootstrapArgs.sshHostname != "" {
|
||||||
bootstrapOpts = append(bootstrapOpts, bootstrap.WithSSHHostname(bootstrapArgs.sshHostname))
|
bootstrapOpts = append(bootstrapOpts, bootstrap.WithSSHHostname(bootstrapArgs.sshHostname))
|
||||||
|
|||||||
@@ -24,14 +24,15 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
"github.com/fluxcd/pkg/git"
|
||||||
|
"github.com/fluxcd/pkg/git/gogit"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/bootstrap"
|
|
||||||
"github.com/fluxcd/flux2/internal/bootstrap/git/gogit"
|
|
||||||
"github.com/fluxcd/flux2/internal/bootstrap/provider"
|
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/bootstrap"
|
||||||
|
"github.com/fluxcd/flux2/pkg/bootstrap/provider"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
||||||
@@ -129,13 +130,15 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manifest base
|
// Manifest base
|
||||||
if ver, err := getVersion(bootstrapArgs.version); err == nil {
|
if ver, err := getVersion(bootstrapArgs.version); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
bootstrapArgs.version = ver
|
bootstrapArgs.version = ver
|
||||||
}
|
}
|
||||||
manifestsBase, err := buildEmbeddedManifestBase()
|
manifestsBase, err := buildEmbeddedManifestBase()
|
||||||
@@ -172,15 +175,22 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Lazy go-git repository
|
// Lazy go-git repository
|
||||||
tmpDir, err := os.MkdirTemp("", "flux-bootstrap-")
|
tmpDir, err := manifestgen.MkdirTempAbs("", "flux-bootstrap-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
gitClient := gogit.New(tmpDir, &http.BasicAuth{
|
|
||||||
Username: gitlabArgs.owner,
|
clientOpts := []gogit.ClientOption{gogit.WithDiskStorage(), gogit.WithFallbackToDefaultKnownHosts()}
|
||||||
Password: glToken,
|
gitClient, err := gogit.NewClient(tmpDir, &git.AuthOptions{
|
||||||
})
|
Transport: git.HTTPS,
|
||||||
|
Username: gitlabArgs.owner,
|
||||||
|
Password: glToken,
|
||||||
|
CAFile: caBundle,
|
||||||
|
}, clientOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create a Git client: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Install manifest config
|
// Install manifest config
|
||||||
installOptions := install.Options{
|
installOptions := install.Options{
|
||||||
@@ -214,19 +224,18 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
if bootstrapArgs.tokenAuth {
|
if bootstrapArgs.tokenAuth {
|
||||||
secretOpts.Username = "git"
|
secretOpts.Username = "git"
|
||||||
secretOpts.Password = glToken
|
secretOpts.Password = glToken
|
||||||
|
secretOpts.CAFile = caBundle
|
||||||
if bootstrapArgs.caFile != "" {
|
|
||||||
secretOpts.CAFilePath = bootstrapArgs.caFile
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
keypair, err := sourcesecret.LoadKeyPairFromPath(bootstrapArgs.privateKeyFile, gitArgs.password)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
secretOpts.Keypair = keypair
|
||||||
secretOpts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(bootstrapArgs.keyAlgorithm)
|
secretOpts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(bootstrapArgs.keyAlgorithm)
|
||||||
secretOpts.RSAKeyBits = int(bootstrapArgs.keyRSABits)
|
secretOpts.RSAKeyBits = int(bootstrapArgs.keyRSABits)
|
||||||
secretOpts.ECDSACurve = bootstrapArgs.keyECDSACurve.Curve
|
secretOpts.ECDSACurve = bootstrapArgs.keyECDSACurve.Curve
|
||||||
secretOpts.SSHHostname = gitlabArgs.hostname
|
|
||||||
|
|
||||||
if bootstrapArgs.privateKeyFile != "" {
|
secretOpts.SSHHostname = gitlabArgs.hostname
|
||||||
secretOpts.PrivateKeyPath = bootstrapArgs.privateKeyFile
|
|
||||||
}
|
|
||||||
if bootstrapArgs.sshHostname != "" {
|
if bootstrapArgs.sshHostname != "" {
|
||||||
secretOpts.SSHHostname = bootstrapArgs.sshHostname
|
secretOpts.SSHHostname = bootstrapArgs.sshHostname
|
||||||
}
|
}
|
||||||
@@ -245,19 +254,23 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
RecurseSubmodules: bootstrapArgs.recurseSubmodules,
|
RecurseSubmodules: bootstrapArgs.recurseSubmodules,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entityList, err := bootstrap.LoadEntityListFromPath(bootstrapArgs.gpgKeyRingPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Bootstrap config
|
// Bootstrap config
|
||||||
bootstrapOpts := []bootstrap.GitProviderOption{
|
bootstrapOpts := []bootstrap.GitProviderOption{
|
||||||
bootstrap.WithProviderRepository(gitlabArgs.owner, gitlabArgs.repository, gitlabArgs.personal),
|
bootstrap.WithProviderRepository(gitlabArgs.owner, gitlabArgs.repository, gitlabArgs.personal),
|
||||||
bootstrap.WithBranch(bootstrapArgs.branch),
|
bootstrap.WithBranch(bootstrapArgs.branch),
|
||||||
bootstrap.WithBootstrapTransportType("https"),
|
bootstrap.WithBootstrapTransportType("https"),
|
||||||
bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail),
|
bootstrap.WithSignature(bootstrapArgs.authorName, bootstrapArgs.authorEmail),
|
||||||
bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix),
|
bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix),
|
||||||
bootstrap.WithProviderTeamPermissions(mapTeamSlice(gitlabArgs.teams, glDefaultPermission)),
|
bootstrap.WithProviderTeamPermissions(mapTeamSlice(gitlabArgs.teams, glDefaultPermission)),
|
||||||
bootstrap.WithReadWriteKeyPermissions(gitlabArgs.readWriteKey),
|
bootstrap.WithReadWriteKeyPermissions(gitlabArgs.readWriteKey),
|
||||||
bootstrap.WithKubeconfig(kubeconfigArgs),
|
bootstrap.WithKubeconfig(kubeconfigArgs, kubeclientOptions),
|
||||||
bootstrap.WithLogger(logger),
|
bootstrap.WithLogger(logger),
|
||||||
bootstrap.WithCABundle(caBundle),
|
bootstrap.WithGitCommitSigning(entityList, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID),
|
||||||
bootstrap.WithGitCommitSigning(bootstrapArgs.gpgKeyRingPath, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID),
|
|
||||||
}
|
}
|
||||||
if bootstrapArgs.sshHostname != "" {
|
if bootstrapArgs.sshHostname != "" {
|
||||||
bootstrapOpts = append(bootstrapOpts, bootstrap.WithSSHHostname(bootstrapArgs.sshHostname))
|
bootstrapOpts = append(bootstrapOpts, bootstrap.WithSSHHostname(bootstrapArgs.sshHostname))
|
||||||
|
|||||||
116
cmd/flux/build_artifact.go
Normal file
116
cmd/flux/build_artifact.go
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
oci "github.com/fluxcd/pkg/oci/client"
|
||||||
|
"github.com/fluxcd/pkg/sourceignore"
|
||||||
|
)
|
||||||
|
|
||||||
|
var buildArtifactCmd = &cobra.Command{
|
||||||
|
Use: "artifact",
|
||||||
|
Short: "Build artifact",
|
||||||
|
Long: `The build artifact command creates a tgz file with the manifests from the given directory or a single manifest file.`,
|
||||||
|
Example: ` # Build the given manifests directory into an artifact
|
||||||
|
flux build artifact --path ./path/to/local/manifests --output ./path/to/artifact.tgz
|
||||||
|
|
||||||
|
# Build the given single manifest file into an artifact
|
||||||
|
flux build artifact --path ./path/to/local/manifest.yaml --output ./path/to/artifact.tgz
|
||||||
|
|
||||||
|
# List the files bundled in the artifact
|
||||||
|
tar -ztvf ./path/to/artifact.tgz
|
||||||
|
`,
|
||||||
|
RunE: buildArtifactCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
type buildArtifactFlags struct {
|
||||||
|
output string
|
||||||
|
path string
|
||||||
|
ignorePaths []string
|
||||||
|
}
|
||||||
|
|
||||||
|
var excludeOCI = append(strings.Split(sourceignore.ExcludeVCS, ","), strings.Split(sourceignore.ExcludeExt, ",")...)
|
||||||
|
|
||||||
|
var buildArtifactArgs buildArtifactFlags
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
buildArtifactCmd.Flags().StringVarP(&buildArtifactArgs.path, "path", "p", "", "Path to the directory where the Kubernetes manifests are located.")
|
||||||
|
buildArtifactCmd.Flags().StringVarP(&buildArtifactArgs.output, "output", "o", "artifact.tgz", "Path to where the artifact tgz file should be written.")
|
||||||
|
buildArtifactCmd.Flags().StringSliceVar(&buildArtifactArgs.ignorePaths, "ignore-paths", excludeOCI, "set paths to ignore in .gitignore format")
|
||||||
|
|
||||||
|
buildCmd.AddCommand(buildArtifactCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
if buildArtifactArgs.path == "" {
|
||||||
|
return fmt.Errorf("invalid path %q", buildArtifactArgs.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
path := buildArtifactArgs.path
|
||||||
|
var err error
|
||||||
|
if buildArtifactArgs.path == "-" {
|
||||||
|
path, err = saveReaderToFile(os.Stdin)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer os.Remove(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(path); err != nil {
|
||||||
|
return fmt.Errorf("invalid path '%s', must point to an existing directory or file", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Actionf("building artifact from %s", path)
|
||||||
|
|
||||||
|
ociClient := oci.NewLocalClient()
|
||||||
|
if err := ociClient.Build(buildArtifactArgs.output, path, buildArtifactArgs.ignorePaths); err != nil {
|
||||||
|
return fmt.Errorf("bulding artifact failed, error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Successf("artifact created at %s", buildArtifactArgs.output)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func saveReaderToFile(reader io.Reader) (string, error) {
|
||||||
|
b, err := io.ReadAll(bufio.NewReader(reader))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
b = bytes.TrimRight(b, "\r\n")
|
||||||
|
f, err := os.CreateTemp("", "*.yaml")
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("unable to create temp dir for stdin")
|
||||||
|
}
|
||||||
|
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
if _, err := f.Write(b); err != nil {
|
||||||
|
return "", fmt.Errorf("error writing stdin to file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return f.Name(), nil
|
||||||
|
}
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
//go:build !e2e
|
|
||||||
// +build !e2e
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2020 The Flux authors
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -17,34 +14,57 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package flags
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHelmReleaseValuesFrom_Set(t *testing.T) {
|
func Test_saveReaderToFile(t *testing.T) {
|
||||||
|
g := NewWithT(t)
|
||||||
|
|
||||||
|
testString := `apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: myapp
|
||||||
|
data:
|
||||||
|
foo: bar`
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
str string
|
string string
|
||||||
expect string
|
|
||||||
expectErr bool
|
expectErr bool
|
||||||
}{
|
}{
|
||||||
{"supported", "Secret/foo", "Secret/foo", false},
|
{
|
||||||
{"lower case kind", "secret/foo", "Secret/foo", false},
|
name: "yaml",
|
||||||
{"unsupported", "Unsupported/kind", "", true},
|
string: testString,
|
||||||
{"invalid format", "Secret", "", true},
|
},
|
||||||
{"empty", "", "", true},
|
{
|
||||||
|
name: "yaml with carriage return",
|
||||||
|
string: testString + "\r\n",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
var h HelmReleaseValuesFrom
|
tmpFile, err := saveReaderToFile(strings.NewReader(tt.string))
|
||||||
if err := h.Set(tt.str); (err != nil) != tt.expectErr {
|
g.Expect(err).To(BeNil())
|
||||||
t.Errorf("Set() error = %v, expectErr %v", err, tt.expectErr)
|
|
||||||
}
|
defer os.Remove(tmpFile)
|
||||||
if str := h.String(); str != tt.expect {
|
|
||||||
t.Errorf("Set() = %v, expect %v", str, tt.expect)
|
b, err := os.ReadFile(tmpFile)
|
||||||
|
if tt.expectErr {
|
||||||
|
g.Expect(err).To(Not(BeNil()))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g.Expect(err).To(BeNil())
|
||||||
|
g.Expect(string(b)).To(BeEquivalentTo(testString))
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,25 +33,38 @@ var buildKsCmd = &cobra.Command{
|
|||||||
Short: "Build Kustomization",
|
Short: "Build Kustomization",
|
||||||
Long: `The build command queries the Kubernetes API and fetches the specified Flux Kustomization.
|
Long: `The build command queries the Kubernetes API and fetches the specified Flux Kustomization.
|
||||||
It then uses the fetched in cluster flux kustomization to perform needed transformation on the local kustomization.yaml
|
It then uses the fetched in cluster flux kustomization to perform needed transformation on the local kustomization.yaml
|
||||||
pointed at by --path. The local kustomization.yaml is generated if it does not exist. Finally it builds the overlays using the local kustomization.yaml, and write the resulting multi-doc YAML to stdout.`,
|
pointed at by --path. The local kustomization.yaml is generated if it does not exist. Finally it builds the overlays using the local kustomization.yaml, and write the resulting multi-doc YAML to stdout.
|
||||||
|
|
||||||
|
It is possible to specify a Flux kustomization file using --kustomization-file.`,
|
||||||
Example: `# Build the local manifests as they were built on the cluster
|
Example: `# Build the local manifests as they were built on the cluster
|
||||||
flux build kustomization my-app --path ./path/to/local/manifests`,
|
flux build kustomization my-app --path ./path/to/local/manifests
|
||||||
|
|
||||||
|
# Build using a local flux kustomization file
|
||||||
|
flux build kustomization my-app --path ./path/to/local/manifests --kustomization-file ./path/to/local/my-app.yaml
|
||||||
|
|
||||||
|
# Build in dry-run mode without connecting to the cluster.
|
||||||
|
# Note that variable substitutions from Secrets and ConfigMaps are skipped in dry-run mode.
|
||||||
|
flux build kustomization my-app --path ./path/to/local/manifests --kustomization-file ./path/to/local/my-app.yaml --dry-run`,
|
||||||
ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)),
|
ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)),
|
||||||
RunE: buildKsCmdRun,
|
RunE: buildKsCmdRun,
|
||||||
}
|
}
|
||||||
|
|
||||||
type buildKsFlags struct {
|
type buildKsFlags struct {
|
||||||
path string
|
kustomizationFile string
|
||||||
|
path string
|
||||||
|
dryRun bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var buildKsArgs buildKsFlags
|
var buildKsArgs buildKsFlags
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
buildKsCmd.Flags().StringVar(&buildKsArgs.path, "path", "", "Path to the manifests location.)")
|
buildKsCmd.Flags().StringVar(&buildKsArgs.path, "path", "", "Path to the manifests location.")
|
||||||
|
buildKsCmd.Flags().StringVar(&buildKsArgs.kustomizationFile, "kustomization-file", "", "Path to the Flux Kustomization YAML file.")
|
||||||
|
buildKsCmd.Flags().BoolVar(&buildKsArgs.dryRun, "dry-run", false, "Dry run mode.")
|
||||||
buildCmd.AddCommand(buildKsCmd)
|
buildCmd.AddCommand(buildKsCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildKsCmdRun(cmd *cobra.Command, args []string) error {
|
func buildKsCmdRun(cmd *cobra.Command, args []string) (err error) {
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
return fmt.Errorf("%s name is required", kustomizationType.humanKind)
|
return fmt.Errorf("%s name is required", kustomizationType.humanKind)
|
||||||
}
|
}
|
||||||
@@ -65,7 +78,32 @@ func buildKsCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return fmt.Errorf("invalid resource path %q", buildKsArgs.path)
|
return fmt.Errorf("invalid resource path %q", buildKsArgs.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
builder, err := build.NewBuilder(kubeconfigArgs, name, buildKsArgs.path, build.WithTimeout(rootArgs.timeout))
|
if buildKsArgs.dryRun && buildKsArgs.kustomizationFile == "" {
|
||||||
|
return fmt.Errorf("dry-run mode requires a kustomization file")
|
||||||
|
}
|
||||||
|
|
||||||
|
if buildKsArgs.kustomizationFile != "" {
|
||||||
|
if fs, err := os.Stat(buildKsArgs.kustomizationFile); os.IsNotExist(err) || fs.IsDir() {
|
||||||
|
return fmt.Errorf("invalid kustomization file %q", buildKsArgs.kustomizationFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var builder *build.Builder
|
||||||
|
if buildKsArgs.dryRun {
|
||||||
|
builder, err = build.NewBuilder(name, buildKsArgs.path,
|
||||||
|
build.WithTimeout(rootArgs.timeout),
|
||||||
|
build.WithKustomizationFile(buildKsArgs.kustomizationFile),
|
||||||
|
build.WithDryRun(buildKsArgs.dryRun),
|
||||||
|
build.WithNamespace(*kubeconfigArgs.Namespace),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
builder, err = build.NewBuilder(name, buildKsArgs.path,
|
||||||
|
build.WithClientConfig(kubeconfigArgs, kubeclientOptions),
|
||||||
|
build.WithTimeout(rootArgs.timeout),
|
||||||
|
build.WithKustomizationFile(buildKsArgs.kustomizationFile),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ limitations under the License.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setup(t *testing.T, tmpl map[string]string) {
|
func setup(t *testing.T, tmpl map[string]string) {
|
||||||
@@ -54,6 +57,12 @@ func TestBuildKustomization(t *testing.T) {
|
|||||||
resultFile: "./testdata/build-kustomization/podinfo-without-service-result.yaml",
|
resultFile: "./testdata/build-kustomization/podinfo-without-service-result.yaml",
|
||||||
assertFunc: "assertGoldenTemplateFile",
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "build deployment and configmap with var substitution",
|
||||||
|
args: "build kustomization podinfo --path ./testdata/build-kustomization/var-substitution",
|
||||||
|
resultFile: "./testdata/build-kustomization/podinfo-with-var-substitution-result.yaml",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl := map[string]string{
|
tmpl := map[string]string{
|
||||||
@@ -81,3 +90,107 @@ func TestBuildKustomization(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildLocalKustomization(t *testing.T) {
|
||||||
|
podinfo := `apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: Kustomization
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: {{ .fluxns }}
|
||||||
|
spec:
|
||||||
|
interval: 5m0s
|
||||||
|
path: ./kustomize
|
||||||
|
force: true
|
||||||
|
prune: true
|
||||||
|
sourceRef:
|
||||||
|
kind: GitRepository
|
||||||
|
name: podinfo
|
||||||
|
targetNamespace: default
|
||||||
|
postBuild:
|
||||||
|
substitute:
|
||||||
|
cluster_env: "prod"
|
||||||
|
cluster_region: "eu-central-1"
|
||||||
|
`
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
resultFile string
|
||||||
|
assertFunc string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "no args",
|
||||||
|
args: "build kustomization podinfo --kustomization-file ./wrongfile/ --path ./testdata/build-kustomization/podinfo",
|
||||||
|
resultFile: "invalid kustomization file \"./wrongfile/\"",
|
||||||
|
assertFunc: "assertError",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "build podinfo",
|
||||||
|
args: "build kustomization podinfo --kustomization-file ./testdata/build-kustomization/podinfo.yaml --path ./testdata/build-kustomization/podinfo",
|
||||||
|
resultFile: "./testdata/build-kustomization/podinfo-result.yaml",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "build podinfo without service",
|
||||||
|
args: "build kustomization podinfo --kustomization-file ./testdata/build-kustomization/podinfo.yaml --path ./testdata/build-kustomization/delete-service",
|
||||||
|
resultFile: "./testdata/build-kustomization/podinfo-without-service-result.yaml",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "build deployment and configmap with var substitution",
|
||||||
|
args: "build kustomization podinfo --kustomization-file ./testdata/build-kustomization/podinfo.yaml --path ./testdata/build-kustomization/var-substitution",
|
||||||
|
resultFile: "./testdata/build-kustomization/podinfo-with-var-substitution-result.yaml",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "build deployment and configmap with var substitution in dry-run mode",
|
||||||
|
args: "build kustomization podinfo --kustomization-file ./testdata/build-kustomization/podinfo.yaml --path ./testdata/build-kustomization/var-substitution --dry-run",
|
||||||
|
resultFile: "./testdata/build-kustomization/podinfo-with-var-substitution-result.yaml",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl := map[string]string{
|
||||||
|
"fluxns": allocateNamespace("flux-system"),
|
||||||
|
}
|
||||||
|
|
||||||
|
testEnv.CreateObjectFile("./testdata/build-kustomization/podinfo-source.yaml", tmpl, t)
|
||||||
|
|
||||||
|
temp, err := template.New("podinfo").Parse(podinfo)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var b bytes.Buffer
|
||||||
|
err = temp.Execute(&b, tmpl)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.WriteFile("./testdata/build-kustomization/podinfo.yaml", b.Bytes(), 0666)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer os.Remove("./testdata/build-kustomization/podinfo.yaml")
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
var assert assertFunc
|
||||||
|
|
||||||
|
switch tt.assertFunc {
|
||||||
|
case "assertGoldenTemplateFile":
|
||||||
|
assert = assertGoldenTemplateFile(tt.resultFile, tmpl)
|
||||||
|
case "assertError":
|
||||||
|
assert = assertError(tt.resultFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.args + " -n " + tmpl["fluxns"],
|
||||||
|
assert: assert,
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/Masterminds/semver/v3"
|
"github.com/Masterminds/semver/v3"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
v1 "k8s.io/api/apps/v1"
|
v1 "k8s.io/api/apps/v1"
|
||||||
|
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
@@ -95,9 +96,17 @@ func runCheckCmd(cmd *cobra.Command, args []string) error {
|
|||||||
if !componentsCheck() {
|
if !componentsCheck() {
|
||||||
checkFailed = true
|
checkFailed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Actionf("checking crds")
|
||||||
|
if !crdsCheck() {
|
||||||
|
checkFailed = true
|
||||||
|
}
|
||||||
|
|
||||||
if checkFailed {
|
if checkFailed {
|
||||||
|
logger.Failuref("check failed")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Successf("all checks passed")
|
logger.Successf("all checks passed")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -125,7 +134,7 @@ func fluxCheck() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func kubernetesCheck(constraints []string) bool {
|
func kubernetesCheck(constraints []string) bool {
|
||||||
cfg, err := utils.KubeConfig(kubeconfigArgs)
|
cfg, err := utils.KubeConfig(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Failuref("Kubernetes client initialization failed: %s", err.Error())
|
logger.Failuref("Kubernetes client initialization failed: %s", err.Error())
|
||||||
return false
|
return false
|
||||||
@@ -173,7 +182,7 @@ func componentsCheck() bool {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeConfig, err := utils.KubeConfig(kubeconfigArgs)
|
kubeConfig, err := utils.KubeConfig(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -183,7 +192,7 @@ func componentsCheck() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -191,7 +200,14 @@ func componentsCheck() bool {
|
|||||||
ok := true
|
ok := true
|
||||||
selector := client.MatchingLabels{manifestgen.PartOfLabelKey: manifestgen.PartOfLabelValue}
|
selector := client.MatchingLabels{manifestgen.PartOfLabelKey: manifestgen.PartOfLabelValue}
|
||||||
var list v1.DeploymentList
|
var list v1.DeploymentList
|
||||||
if err := kubeClient.List(ctx, &list, client.InNamespace(*kubeconfigArgs.Namespace), selector); err == nil {
|
ns := *kubeconfigArgs.Namespace
|
||||||
|
if err := kubeClient.List(ctx, &list, client.InNamespace(ns), selector); err == nil {
|
||||||
|
if len(list.Items) == 0 {
|
||||||
|
logger.Failuref("no controllers found in the '%s' namespace with the label selector '%s=%s'",
|
||||||
|
ns, manifestgen.PartOfLabelKey, manifestgen.PartOfLabelValue)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
for _, d := range list.Items {
|
for _, d := range list.Items {
|
||||||
if ref, err := buildComponentObjectRefs(d.Name); err == nil {
|
if ref, err := buildComponentObjectRefs(d.Name); err == nil {
|
||||||
if err := statusChecker.Assess(ref...); err != nil {
|
if err := statusChecker.Assess(ref...); err != nil {
|
||||||
@@ -205,3 +221,35 @@ func componentsCheck() bool {
|
|||||||
}
|
}
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func crdsCheck() bool {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
ok := true
|
||||||
|
selector := client.MatchingLabels{manifestgen.PartOfLabelKey: manifestgen.PartOfLabelValue}
|
||||||
|
var list apiextensionsv1.CustomResourceDefinitionList
|
||||||
|
if err := kubeClient.List(ctx, &list, client.InNamespace(*kubeconfigArgs.Namespace), selector); err == nil {
|
||||||
|
if len(list.Items) == 0 {
|
||||||
|
logger.Failuref("no crds found with the label selector '%s=%s'",
|
||||||
|
manifestgen.PartOfLabelKey, manifestgen.PartOfLabelValue)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, crd := range list.Items {
|
||||||
|
versions := crd.Status.StoredVersions
|
||||||
|
if len(versions) > 0 {
|
||||||
|
logger.Successf(crd.Name + "/" + versions[len(versions)-1])
|
||||||
|
} else {
|
||||||
|
ok = false
|
||||||
|
logger.Failuref("no stored versions for %s", crd.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
"k8s.io/apimachinery/pkg/version"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCheckPre(t *testing.T) {
|
func TestCheckPre(t *testing.T) {
|
||||||
@@ -35,17 +34,19 @@ func TestCheckPre(t *testing.T) {
|
|||||||
t.Fatalf("Error running utils.ExecKubectlCommand: %v", err.Error())
|
t.Fatalf("Error running utils.ExecKubectlCommand: %v", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var versions map[string]version.Info
|
var versions map[string]interface{}
|
||||||
if err := json.Unmarshal([]byte(jsonOutput), &versions); err != nil {
|
if err := json.Unmarshal([]byte(jsonOutput), &versions); err != nil {
|
||||||
t.Fatalf("Error unmarshalling: %v", err.Error())
|
t.Fatalf("Error unmarshalling '%s': %v", jsonOutput, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
serverVersion := strings.TrimPrefix(versions["serverVersion"].GitVersion, "v")
|
serverGitVersion := strings.TrimPrefix(
|
||||||
|
versions["serverVersion"].(map[string]interface{})["gitVersion"].(string),
|
||||||
|
"v")
|
||||||
|
|
||||||
cmd := cmdTestCase{
|
cmd := cmdTestCase{
|
||||||
args: "check --pre",
|
args: "check --pre",
|
||||||
assert: assertGoldenTemplateFile("testdata/check/check_pre.golden", map[string]string{
|
assert: assertGoldenTemplateFile("testdata/check/check_pre.golden", map[string]string{
|
||||||
"serverVersion": serverVersion,
|
"serverVersion": serverGitVersion,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
cmd.runTestCmd(t)
|
cmd.runTestCmd(t)
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func resourceNamesCompletionFunc(gvk schema.GroupVersionKind) func(cmd *cobra.Co
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
cfg, err := utils.KubeConfig(kubeconfigArgs)
|
cfg, err := utils.KubeConfig(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return completionError(err)
|
return completionError(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,12 +34,12 @@ To configure your powershell shell to load completions for each session add to y
|
|||||||
Windows:
|
Windows:
|
||||||
|
|
||||||
cd "$env:USERPROFILE\Documents\WindowsPowerShell\Modules"
|
cd "$env:USERPROFILE\Documents\WindowsPowerShell\Modules"
|
||||||
flux completion >> flux-completion.ps1
|
flux completion powershell >> flux-completion.ps1
|
||||||
|
|
||||||
Linux:
|
Linux:
|
||||||
|
|
||||||
cd "${XDG_CONFIG_HOME:-"$HOME/.config/"}/powershell/modules"
|
cd "${XDG_CONFIG_HOME:-"$HOME/.config/"}/powershell/modules"
|
||||||
flux completion >> flux-completions.ps1`,
|
flux completion powershell >> flux-completions.ps1`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
rootCmd.GenPowerShellCompletion(os.Stdout)
|
rootCmd.GenPowerShellCompletion(os.Stdout)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -79,12 +79,12 @@ type upsertable interface {
|
|||||||
// want to update. The mutate function is nullary -- you mutate a
|
// want to update. The mutate function is nullary -- you mutate a
|
||||||
// value in the closure, e.g., by doing this:
|
// value in the closure, e.g., by doing this:
|
||||||
//
|
//
|
||||||
// var existing Value
|
// var existing Value
|
||||||
// existing.Name = name
|
// existing.Name = name
|
||||||
// existing.Namespace = ns
|
// existing.Namespace = ns
|
||||||
// upsert(ctx, client, valueAdapter{&value}, func() error {
|
// upsert(ctx, client, valueAdapter{&value}, func() error {
|
||||||
// value.Spec = onePreparedEarlier
|
// value.Spec = onePreparedEarlier
|
||||||
// })
|
// })
|
||||||
func (names apiType) upsert(ctx context.Context, kubeClient client.Client, object upsertable, mutate func() error) (types.NamespacedName, error) {
|
func (names apiType) upsert(ctx context.Context, kubeClient client.Client, object upsertable, mutate func() error) (types.NamespacedName, error) {
|
||||||
nsname := types.NamespacedName{
|
nsname := types.NamespacedName{
|
||||||
Namespace: object.GetNamespace(),
|
Namespace: object.GetNamespace(),
|
||||||
@@ -117,7 +117,7 @@ func (names apiType) upsertAndWait(object upsertWaitable, mutate func() error) e
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs) // NB globals
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) // NB globals
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
"github.com/fluxcd/pkg/apis/meta"
|
"github.com/fluxcd/pkg/apis/meta"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
@@ -119,7 +119,7 @@ func createAlertCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
"github.com/fluxcd/pkg/apis/meta"
|
"github.com/fluxcd/pkg/apis/meta"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
@@ -115,7 +115,7 @@ func createAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
@@ -108,21 +110,26 @@ var createHelmReleaseCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type helmReleaseFlags struct {
|
type helmReleaseFlags struct {
|
||||||
name string
|
name string
|
||||||
source flags.HelmChartSource
|
source flags.HelmChartSource
|
||||||
dependsOn []string
|
dependsOn []string
|
||||||
chart string
|
chart string
|
||||||
chartVersion string
|
chartVersion string
|
||||||
targetNamespace string
|
targetNamespace string
|
||||||
createNamespace bool
|
createNamespace bool
|
||||||
valuesFiles []string
|
valuesFiles []string
|
||||||
valuesFrom flags.HelmReleaseValuesFrom
|
valuesFrom []string
|
||||||
saName string
|
saName string
|
||||||
crds flags.CRDsPolicy
|
crds flags.CRDsPolicy
|
||||||
|
reconcileStrategy string
|
||||||
|
chartInterval time.Duration
|
||||||
|
kubeConfigSecretRef string
|
||||||
}
|
}
|
||||||
|
|
||||||
var helmReleaseArgs helmReleaseFlags
|
var helmReleaseArgs helmReleaseFlags
|
||||||
|
|
||||||
|
var supportedHelmReleaseValuesFromKinds = []string{"Secret", "ConfigMap"}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.name, "release-name", "", "name used for the Helm release, defaults to a composition of '[<target-namespace>-]<HelmRelease-name>'")
|
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.name, "release-name", "", "name used for the Helm release, defaults to a composition of '[<target-namespace>-]<HelmRelease-name>'")
|
||||||
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.source, "source", helmReleaseArgs.source.Description())
|
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.source, "source", helmReleaseArgs.source.Description())
|
||||||
@@ -132,9 +139,12 @@ func init() {
|
|||||||
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.targetNamespace, "target-namespace", "", "namespace to install this release, defaults to the HelmRelease namespace")
|
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.targetNamespace, "target-namespace", "", "namespace to install this release, defaults to the HelmRelease namespace")
|
||||||
createHelmReleaseCmd.Flags().BoolVar(&helmReleaseArgs.createNamespace, "create-target-namespace", false, "create the target namespace if it does not exist")
|
createHelmReleaseCmd.Flags().BoolVar(&helmReleaseArgs.createNamespace, "create-target-namespace", false, "create the target namespace if it does not exist")
|
||||||
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.saName, "service-account", "", "the name of the service account to impersonate when reconciling this HelmRelease")
|
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.saName, "service-account", "", "the name of the service account to impersonate when reconciling this HelmRelease")
|
||||||
|
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.reconcileStrategy, "reconcile-strategy", "ChartVersion", "the reconcile strategy for helm chart created by the helm release(accepted values: Revision and ChartRevision)")
|
||||||
|
createHelmReleaseCmd.Flags().DurationVarP(&helmReleaseArgs.chartInterval, "chart-interval", "", 0, "the interval of which to check for new chart versions")
|
||||||
createHelmReleaseCmd.Flags().StringSliceVar(&helmReleaseArgs.valuesFiles, "values", nil, "local path to values.yaml files, also accepts comma-separated values")
|
createHelmReleaseCmd.Flags().StringSliceVar(&helmReleaseArgs.valuesFiles, "values", nil, "local path to values.yaml files, also accepts comma-separated values")
|
||||||
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.valuesFrom, "values-from", helmReleaseArgs.valuesFrom.Description())
|
createHelmReleaseCmd.Flags().StringSliceVar(&helmReleaseArgs.valuesFrom, "values-from", nil, "a Kubernetes object reference that contains the values.yaml data key in the format '<kind>/<name>', where kind must be one of: (Secret,ConfigMap)")
|
||||||
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.crds, "crds", helmReleaseArgs.crds.Description())
|
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.crds, "crds", helmReleaseArgs.crds.Description())
|
||||||
|
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.kubeConfigSecretRef, "kubeconfig-secret-ref", "", "the name of the Kubernetes Secret that contains a key with the kubeconfig file for connecting to a remote cluster")
|
||||||
createCmd.AddCommand(createHelmReleaseCmd)
|
createCmd.AddCommand(createHelmReleaseCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +164,11 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
logger.Generatef("generating HelmRelease")
|
logger.Generatef("generating HelmRelease")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !validateStrategy(helmReleaseArgs.reconcileStrategy) {
|
||||||
|
return fmt.Errorf("'%s' is an invalid reconcile strategy(valid: Revision, ChartVersion)",
|
||||||
|
helmReleaseArgs.reconcileStrategy)
|
||||||
|
}
|
||||||
|
|
||||||
helmRelease := helmv2.HelmRelease{
|
helmRelease := helmv2.HelmRelease{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
@@ -177,12 +192,27 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
Name: helmReleaseArgs.source.Name,
|
Name: helmReleaseArgs.source.Name,
|
||||||
Namespace: helmReleaseArgs.source.Namespace,
|
Namespace: helmReleaseArgs.source.Namespace,
|
||||||
},
|
},
|
||||||
|
ReconcileStrategy: helmReleaseArgs.reconcileStrategy,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Suspend: false,
|
Suspend: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if helmReleaseArgs.kubeConfigSecretRef != "" {
|
||||||
|
helmRelease.Spec.KubeConfig = &helmv2.KubeConfig{
|
||||||
|
SecretRef: meta.SecretKeyReference{
|
||||||
|
Name: helmReleaseArgs.kubeConfigSecretRef,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if helmReleaseArgs.chartInterval != 0 {
|
||||||
|
helmRelease.Spec.Chart.Spec.Interval = &metav1.Duration{
|
||||||
|
Duration: helmReleaseArgs.chartInterval,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if helmReleaseArgs.createNamespace {
|
if helmReleaseArgs.createNamespace {
|
||||||
if helmRelease.Spec.Install == nil {
|
if helmRelease.Spec.Install == nil {
|
||||||
helmRelease.Spec.Install = &helmv2.Install{}
|
helmRelease.Spec.Install = &helmv2.Install{}
|
||||||
@@ -233,11 +263,25 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
helmRelease.Spec.Values = &apiextensionsv1.JSON{Raw: jsonRaw}
|
helmRelease.Spec.Values = &apiextensionsv1.JSON{Raw: jsonRaw}
|
||||||
}
|
}
|
||||||
|
|
||||||
if helmReleaseArgs.valuesFrom.String() != "" {
|
if len(helmReleaseArgs.valuesFrom) != 0 {
|
||||||
helmRelease.Spec.ValuesFrom = []helmv2.ValuesReference{{
|
values := []helmv2.ValuesReference{}
|
||||||
Kind: helmReleaseArgs.valuesFrom.Kind,
|
for _, value := range helmReleaseArgs.valuesFrom {
|
||||||
Name: helmReleaseArgs.valuesFrom.Name,
|
sourceKind, sourceName := utils.ParseObjectKindName(value)
|
||||||
}}
|
if sourceKind == "" {
|
||||||
|
return fmt.Errorf("invalid Kubernetes object reference '%s', must be in format <kind>/<name>", value)
|
||||||
|
}
|
||||||
|
cleanSourceKind, ok := utils.ContainsEqualFoldItemString(supportedHelmReleaseValuesFromKinds, sourceKind)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("reference kind '%s' is not supported, must be one of: %s",
|
||||||
|
sourceKind, strings.Join(supportedHelmReleaseValuesFromKinds, ", "))
|
||||||
|
}
|
||||||
|
|
||||||
|
values = append(values, helmv2.ValuesReference{
|
||||||
|
Name: sourceName,
|
||||||
|
Kind: cleanSourceKind,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
helmRelease.Spec.ValuesFrom = values
|
||||||
}
|
}
|
||||||
|
|
||||||
if createArgs.export {
|
if createArgs.export {
|
||||||
@@ -247,7 +291,7 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -316,3 +360,15 @@ func isHelmReleaseReady(ctx context.Context, kubeClient client.Client,
|
|||||||
return apimeta.IsStatusConditionTrue(helmRelease.Status.Conditions, meta.ReadyCondition), nil
|
return apimeta.IsStatusConditionTrue(helmRelease.Status.Conditions, meta.ReadyCondition), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateStrategy(input string) bool {
|
||||||
|
allowedStrategy := []string{"Revision", "ChartVersion"}
|
||||||
|
|
||||||
|
for _, strategy := range allowedStrategy {
|
||||||
|
if strategy == input {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -42,22 +42,21 @@ var createKsCmd = &cobra.Command{
|
|||||||
Use: "kustomization [name]",
|
Use: "kustomization [name]",
|
||||||
Aliases: []string{"ks"},
|
Aliases: []string{"ks"},
|
||||||
Short: "Create or update a Kustomization resource",
|
Short: "Create or update a Kustomization resource",
|
||||||
Long: "The kustomization source create command generates a Kustomize resource for a given source.",
|
Long: "The create command generates a Kustomization resource for a given source.",
|
||||||
Example: ` # Create a Kustomization resource from a source at a given path
|
Example: ` # Create a Kustomization resource from a source at a given path
|
||||||
flux create kustomization contour \
|
flux create kustomization kyverno \
|
||||||
--source=GitRepository/contour \
|
--source=GitRepository/kyverno \
|
||||||
--path="./examples/contour/" \
|
--path="./config/release" \
|
||||||
--prune=true \
|
--prune=true \
|
||||||
--interval=10m \
|
--interval=60m \
|
||||||
--health-check="Deployment/contour.projectcontour" \
|
--wait=true \
|
||||||
--health-check="DaemonSet/envoy.projectcontour" \
|
|
||||||
--health-check-timeout=3m
|
--health-check-timeout=3m
|
||||||
|
|
||||||
# Create a Kustomization resource that depends on the previous one
|
# Create a Kustomization resource that depends on the previous one
|
||||||
flux create kustomization webapp \
|
flux create kustomization kyverno-policies \
|
||||||
--depends-on=contour \
|
--depends-on=kyverno \
|
||||||
--source=GitRepository/webapp \
|
--source=GitRepository/kyverno-policies \
|
||||||
--path="./deploy/overlays/dev" \
|
--path="./policies/flux" \
|
||||||
--prune=true \
|
--prune=true \
|
||||||
--interval=5m
|
--interval=5m
|
||||||
|
|
||||||
@@ -65,7 +64,14 @@ var createKsCmd = &cobra.Command{
|
|||||||
flux create kustomization podinfo \
|
flux create kustomization podinfo \
|
||||||
--namespace=default \
|
--namespace=default \
|
||||||
--source=GitRepository/podinfo.flux-system \
|
--source=GitRepository/podinfo.flux-system \
|
||||||
--path="./deploy/overlays/dev" \
|
--path="./kustomize" \
|
||||||
|
--prune=true \
|
||||||
|
--interval=5m
|
||||||
|
|
||||||
|
# Create a Kustomization resource that references an OCIRepository
|
||||||
|
flux create kustomization podinfo \
|
||||||
|
--source=OCIRepository/podinfo \
|
||||||
|
--target-namespace=default \
|
||||||
--prune=true \
|
--prune=true \
|
||||||
--interval=5m
|
--interval=5m
|
||||||
|
|
||||||
@@ -78,18 +84,19 @@ var createKsCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type kustomizationFlags struct {
|
type kustomizationFlags struct {
|
||||||
source flags.KustomizationSource
|
source flags.KustomizationSource
|
||||||
path flags.SafeRelativePath
|
path flags.SafeRelativePath
|
||||||
prune bool
|
prune bool
|
||||||
dependsOn []string
|
dependsOn []string
|
||||||
validation string
|
validation string
|
||||||
healthCheck []string
|
healthCheck []string
|
||||||
healthTimeout time.Duration
|
healthTimeout time.Duration
|
||||||
saName string
|
saName string
|
||||||
decryptionProvider flags.DecryptionProvider
|
decryptionProvider flags.DecryptionProvider
|
||||||
decryptionSecret string
|
decryptionSecret string
|
||||||
targetNamespace string
|
targetNamespace string
|
||||||
wait bool
|
wait bool
|
||||||
|
kubeConfigSecretRef string
|
||||||
}
|
}
|
||||||
|
|
||||||
var kustomizationArgs = NewKustomizationFlags()
|
var kustomizationArgs = NewKustomizationFlags()
|
||||||
@@ -107,6 +114,7 @@ func init() {
|
|||||||
createKsCmd.Flags().Var(&kustomizationArgs.decryptionProvider, "decryption-provider", kustomizationArgs.decryptionProvider.Description())
|
createKsCmd.Flags().Var(&kustomizationArgs.decryptionProvider, "decryption-provider", kustomizationArgs.decryptionProvider.Description())
|
||||||
createKsCmd.Flags().StringVar(&kustomizationArgs.decryptionSecret, "decryption-secret", "", "set the Kubernetes secret name that contains the OpenPGP private keys used for sops decryption")
|
createKsCmd.Flags().StringVar(&kustomizationArgs.decryptionSecret, "decryption-secret", "", "set the Kubernetes secret name that contains the OpenPGP private keys used for sops decryption")
|
||||||
createKsCmd.Flags().StringVar(&kustomizationArgs.targetNamespace, "target-namespace", "", "overrides the namespace of all Kustomization objects reconciled by this Kustomization")
|
createKsCmd.Flags().StringVar(&kustomizationArgs.targetNamespace, "target-namespace", "", "overrides the namespace of all Kustomization objects reconciled by this Kustomization")
|
||||||
|
createKsCmd.Flags().StringVar(&kustomizationArgs.kubeConfigSecretRef, "kubeconfig-secret-ref", "", "the name of the Kubernetes Secret that contains a key with the kubeconfig file for connecting to a remote cluster")
|
||||||
createKsCmd.Flags().MarkDeprecated("validation", "this arg is no longer used, all resources are validated using server-side apply dry-run")
|
createKsCmd.Flags().MarkDeprecated("validation", "this arg is no longer used, all resources are validated using server-side apply dry-run")
|
||||||
|
|
||||||
createCmd.AddCommand(createKsCmd)
|
createCmd.AddCommand(createKsCmd)
|
||||||
@@ -160,6 +168,14 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if kustomizationArgs.kubeConfigSecretRef != "" {
|
||||||
|
kustomization.Spec.KubeConfig = &meta.KubeConfigReference{
|
||||||
|
SecretRef: meta.SecretKeyReference{
|
||||||
|
Name: kustomizationArgs.kubeConfigSecretRef,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(kustomizationArgs.healthCheck) > 0 && !kustomizationArgs.wait {
|
if len(kustomizationArgs.healthCheck) > 0 && !kustomizationArgs.wait {
|
||||||
healthChecks := make([]meta.NamespacedObjectKindReference, 0)
|
healthChecks := make([]meta.NamespacedObjectKindReference, 0)
|
||||||
for _, w := range kustomizationArgs.healthCheck {
|
for _, w := range kustomizationArgs.healthCheck {
|
||||||
@@ -229,7 +245,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
"github.com/fluxcd/pkg/apis/meta"
|
"github.com/fluxcd/pkg/apis/meta"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
@@ -127,7 +127,7 @@ func createReceiverCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
@@ -135,8 +136,12 @@ func createSecretGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
switch u.Scheme {
|
switch u.Scheme {
|
||||||
case "ssh":
|
case "ssh":
|
||||||
|
keypair, err := sourcesecret.LoadKeyPairFromPath(secretGitArgs.privateKeyFile, secretGitArgs.password)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
opts.Keypair = keypair
|
||||||
opts.SSHHostname = u.Host
|
opts.SSHHostname = u.Host
|
||||||
opts.PrivateKeyPath = secretGitArgs.privateKeyFile
|
|
||||||
opts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(secretGitArgs.keyAlgorithm)
|
opts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(secretGitArgs.keyAlgorithm)
|
||||||
opts.RSAKeyBits = int(secretGitArgs.rsaBits)
|
opts.RSAKeyBits = int(secretGitArgs.rsaBits)
|
||||||
opts.ECDSACurve = secretGitArgs.ecdsaCurve.Curve
|
opts.ECDSACurve = secretGitArgs.ecdsaCurve.Curve
|
||||||
@@ -147,7 +152,13 @@ func createSecretGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
opts.Username = secretGitArgs.username
|
opts.Username = secretGitArgs.username
|
||||||
opts.Password = secretGitArgs.password
|
opts.Password = secretGitArgs.password
|
||||||
opts.CAFilePath = secretGitArgs.caFile
|
if secretGitArgs.caFile != "" {
|
||||||
|
caBundle, err := os.ReadFile(secretGitArgs.caFile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to read TLS CA file: %w", err)
|
||||||
|
}
|
||||||
|
opts.CAFile = caBundle
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("git URL scheme '%s' not supported, can be: ssh, http and https", u.Scheme)
|
return fmt.Errorf("git URL scheme '%s' not supported, can be: ssh, http and https", u.Scheme)
|
||||||
}
|
}
|
||||||
@@ -173,7 +184,7 @@ func createSecretGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
@@ -74,15 +76,34 @@ func createSecretHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
caBundle := []byte{}
|
||||||
|
if secretHelmArgs.caFile != "" {
|
||||||
|
var err error
|
||||||
|
caBundle, err = os.ReadFile(secretHelmArgs.caFile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to read TLS CA file: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var certFile, keyFile []byte
|
||||||
|
if secretHelmArgs.certFile != "" && secretHelmArgs.keyFile != "" {
|
||||||
|
if certFile, err = os.ReadFile(secretHelmArgs.certFile); err != nil {
|
||||||
|
return fmt.Errorf("failed to read cert file: %w", err)
|
||||||
|
}
|
||||||
|
if keyFile, err = os.ReadFile(secretHelmArgs.keyFile); err != nil {
|
||||||
|
return fmt.Errorf("failed to read key file: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
opts := sourcesecret.Options{
|
opts := sourcesecret.Options{
|
||||||
Name: name,
|
Name: name,
|
||||||
Namespace: *kubeconfigArgs.Namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
Username: secretHelmArgs.username,
|
Username: secretHelmArgs.username,
|
||||||
Password: secretHelmArgs.password,
|
Password: secretHelmArgs.password,
|
||||||
CAFilePath: secretHelmArgs.caFile,
|
CAFile: caBundle,
|
||||||
CertFilePath: secretHelmArgs.certFile,
|
CertFile: certFile,
|
||||||
KeyFilePath: secretHelmArgs.keyFile,
|
KeyFile: keyFile,
|
||||||
}
|
}
|
||||||
secret, err := sourcesecret.Generate(opts)
|
secret, err := sourcesecret.Generate(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -96,7 +117,7 @@ func createSecretHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
121
cmd/flux/create_secret_oci.go
Normal file
121
cmd/flux/create_secret_oci.go
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||||
|
"github.com/google/go-containerregistry/pkg/name"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
"sigs.k8s.io/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
var createSecretOCICmd = &cobra.Command{
|
||||||
|
Use: "oci [name]",
|
||||||
|
Short: "Create or update a Kubernetes image pull secret",
|
||||||
|
Long: `The create secret oci command generates a Kubernetes secret that can be used for OCIRepository authentication`,
|
||||||
|
Example: ` # Create an OCI authentication secret on disk and encrypt it with Mozilla SOPS
|
||||||
|
flux create secret oci podinfo-auth \
|
||||||
|
--url=ghcr.io \
|
||||||
|
--username=username \
|
||||||
|
--password=password \
|
||||||
|
--export > repo-auth.yaml
|
||||||
|
|
||||||
|
sops --encrypt --encrypted-regex '^(data|stringData)$' \
|
||||||
|
--in-place repo-auth.yaml
|
||||||
|
`,
|
||||||
|
RunE: createSecretOCICmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
type secretOCIFlags struct {
|
||||||
|
url string
|
||||||
|
password string
|
||||||
|
username string
|
||||||
|
}
|
||||||
|
|
||||||
|
var secretOCIArgs = secretOCIFlags{}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
createSecretOCICmd.Flags().StringVar(&secretOCIArgs.url, "url", "", "oci repository address e.g ghcr.io/stefanprodan/charts")
|
||||||
|
createSecretOCICmd.Flags().StringVarP(&secretOCIArgs.username, "username", "u", "", "basic authentication username")
|
||||||
|
createSecretOCICmd.Flags().StringVarP(&secretOCIArgs.password, "password", "p", "", "basic authentication password")
|
||||||
|
|
||||||
|
createSecretCmd.AddCommand(createSecretOCICmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func createSecretOCICmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) < 1 {
|
||||||
|
return fmt.Errorf("name is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
secretName := args[0]
|
||||||
|
|
||||||
|
if secretOCIArgs.url == "" {
|
||||||
|
return fmt.Errorf("--url is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if secretOCIArgs.username == "" {
|
||||||
|
return fmt.Errorf("--username is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if secretOCIArgs.password == "" {
|
||||||
|
return fmt.Errorf("--password is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := name.ParseReference(secretOCIArgs.url); err != nil {
|
||||||
|
return fmt.Errorf("error parsing url: '%s'", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := sourcesecret.Options{
|
||||||
|
Name: secretName,
|
||||||
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
|
Registry: secretOCIArgs.url,
|
||||||
|
Password: secretOCIArgs.password,
|
||||||
|
Username: secretOCIArgs.username,
|
||||||
|
}
|
||||||
|
|
||||||
|
secret, err := sourcesecret.Generate(opts)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if createArgs.export {
|
||||||
|
rootCmd.Println(secret.Content)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var s corev1.Secret
|
||||||
|
if err := yaml.Unmarshal([]byte(secret.Content), &s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := upsertSecret(ctx, kubeClient, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Actionf("oci secret '%s' created in '%s' namespace", secretName, *kubeconfigArgs.Namespace)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
51
cmd/flux/create_secret_oci_test.go
Normal file
51
cmd/flux/create_secret_oci_test.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateSecretOCI(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
assert assertFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
args: "create secret oci",
|
||||||
|
assert: assertError("name is required"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: "create secret oci ghcr",
|
||||||
|
assert: assertError("--url is required"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: "create secret oci ghcr --namespace=my-namespace --url ghcr.io --username stefanprodan --password=password --export",
|
||||||
|
assert: assertGoldenFile("testdata/create_secret/oci/create-secret.yaml"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.args,
|
||||||
|
assert: tt.assert,
|
||||||
|
}
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
@@ -73,13 +75,32 @@ func createSecretTLSCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
caBundle := []byte{}
|
||||||
|
if secretTLSArgs.caFile != "" {
|
||||||
|
var err error
|
||||||
|
caBundle, err = os.ReadFile(secretTLSArgs.caFile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to read TLS CA file: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var certFile, keyFile []byte
|
||||||
|
if secretTLSArgs.certFile != "" && secretTLSArgs.keyFile != "" {
|
||||||
|
if certFile, err = os.ReadFile(secretTLSArgs.certFile); err != nil {
|
||||||
|
return fmt.Errorf("failed to read cert file: %w", err)
|
||||||
|
}
|
||||||
|
if keyFile, err = os.ReadFile(secretTLSArgs.keyFile); err != nil {
|
||||||
|
return fmt.Errorf("failed to read key file: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
opts := sourcesecret.Options{
|
opts := sourcesecret.Options{
|
||||||
Name: name,
|
Name: name,
|
||||||
Namespace: *kubeconfigArgs.Namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
CAFilePath: secretTLSArgs.caFile,
|
CAFile: caBundle,
|
||||||
CertFilePath: secretTLSArgs.certFile,
|
CertFile: certFile,
|
||||||
KeyFilePath: secretTLSArgs.keyFile,
|
KeyFile: keyFile,
|
||||||
}
|
}
|
||||||
secret, err := sourcesecret.Generate(opts)
|
secret, err := sourcesecret.Generate(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -93,7 +114,7 @@ func createSecretTLSCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
@@ -63,17 +64,18 @@ For Buckets with static authentication, the credentials are stored in a Kubernet
|
|||||||
}
|
}
|
||||||
|
|
||||||
type sourceBucketFlags struct {
|
type sourceBucketFlags struct {
|
||||||
name string
|
name string
|
||||||
provider flags.SourceBucketProvider
|
provider flags.SourceBucketProvider
|
||||||
endpoint string
|
endpoint string
|
||||||
accessKey string
|
accessKey string
|
||||||
secretKey string
|
secretKey string
|
||||||
region string
|
region string
|
||||||
insecure bool
|
insecure bool
|
||||||
secretRef string
|
secretRef string
|
||||||
|
ignorePaths []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var sourceBucketArgs = NewSourceBucketFlags()
|
var sourceBucketArgs = newSourceBucketFlags()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
createSourceBucketCmd.Flags().Var(&sourceBucketArgs.provider, "provider", sourceBucketArgs.provider.Description())
|
createSourceBucketCmd.Flags().Var(&sourceBucketArgs.provider, "provider", sourceBucketArgs.provider.Description())
|
||||||
@@ -84,11 +86,12 @@ func init() {
|
|||||||
createSourceBucketCmd.Flags().StringVar(&sourceBucketArgs.region, "region", "", "the bucket region")
|
createSourceBucketCmd.Flags().StringVar(&sourceBucketArgs.region, "region", "", "the bucket region")
|
||||||
createSourceBucketCmd.Flags().BoolVar(&sourceBucketArgs.insecure, "insecure", false, "for when connecting to a non-TLS S3 HTTP endpoint")
|
createSourceBucketCmd.Flags().BoolVar(&sourceBucketArgs.insecure, "insecure", false, "for when connecting to a non-TLS S3 HTTP endpoint")
|
||||||
createSourceBucketCmd.Flags().StringVar(&sourceBucketArgs.secretRef, "secret-ref", "", "the name of an existing secret containing credentials")
|
createSourceBucketCmd.Flags().StringVar(&sourceBucketArgs.secretRef, "secret-ref", "", "the name of an existing secret containing credentials")
|
||||||
|
createSourceBucketCmd.Flags().StringSliceVar(&sourceBucketArgs.ignorePaths, "ignore-paths", nil, "set paths to ignore in bucket resource (can specify multiple paths with commas: path1,path2)")
|
||||||
|
|
||||||
createSourceCmd.AddCommand(createSourceBucketCmd)
|
createSourceCmd.AddCommand(createSourceBucketCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSourceBucketFlags() sourceBucketFlags {
|
func newSourceBucketFlags() sourceBucketFlags {
|
||||||
return sourceBucketFlags{
|
return sourceBucketFlags{
|
||||||
provider: flags.SourceBucketProvider(sourcev1.GenericBucketProvider),
|
provider: flags.SourceBucketProvider(sourcev1.GenericBucketProvider),
|
||||||
}
|
}
|
||||||
@@ -116,6 +119,12 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
|
var ignorePaths *string
|
||||||
|
if len(sourceBucketArgs.ignorePaths) > 0 {
|
||||||
|
ignorePathsStr := strings.Join(sourceBucketArgs.ignorePaths, "\n")
|
||||||
|
ignorePaths = &ignorePathsStr
|
||||||
|
}
|
||||||
|
|
||||||
bucket := &sourcev1.Bucket{
|
bucket := &sourcev1.Bucket{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
@@ -131,6 +140,7 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
Interval: metav1.Duration{
|
Interval: metav1.Duration{
|
||||||
Duration: createArgs.interval,
|
Duration: createArgs.interval,
|
||||||
},
|
},
|
||||||
|
Ignore: ignorePaths,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +161,7 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/manifoldco/promptui"
|
"github.com/manifoldco/promptui"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -59,6 +60,7 @@ type sourceGitFlags struct {
|
|||||||
privateKeyFile string
|
privateKeyFile string
|
||||||
recurseSubmodules bool
|
recurseSubmodules bool
|
||||||
silent bool
|
silent bool
|
||||||
|
ignorePaths []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var createSourceGitCmd = &cobra.Command{
|
var createSourceGitCmd = &cobra.Command{
|
||||||
@@ -115,6 +117,7 @@ For private Git repositories, the basic authentication credentials are stored in
|
|||||||
# Create a source for a Git repository using basic authentication
|
# Create a source for a Git repository using basic authentication
|
||||||
flux create source git podinfo \
|
flux create source git podinfo \
|
||||||
--url=https://github.com/stefanprodan/podinfo \
|
--url=https://github.com/stefanprodan/podinfo \
|
||||||
|
--branch=master \
|
||||||
--username=username \
|
--username=username \
|
||||||
--password=password`,
|
--password=password`,
|
||||||
RunE: createSourceGitCmdRun,
|
RunE: createSourceGitCmdRun,
|
||||||
@@ -139,6 +142,7 @@ func init() {
|
|||||||
createSourceGitCmd.Flags().BoolVar(&sourceGitArgs.recurseSubmodules, "recurse-submodules", false,
|
createSourceGitCmd.Flags().BoolVar(&sourceGitArgs.recurseSubmodules, "recurse-submodules", false,
|
||||||
"when enabled, configures the GitRepository source to initialize and include Git submodules in the artifact it produces")
|
"when enabled, configures the GitRepository source to initialize and include Git submodules in the artifact it produces")
|
||||||
createSourceGitCmd.Flags().BoolVarP(&sourceGitArgs.silent, "silent", "s", false, "assumes the deploy key is already setup, skips confirmation")
|
createSourceGitCmd.Flags().BoolVarP(&sourceGitArgs.silent, "silent", "s", false, "assumes the deploy key is already setup, skips confirmation")
|
||||||
|
createSourceGitCmd.Flags().StringSliceVar(&sourceGitArgs.ignorePaths, "ignore-paths", nil, "set paths to ignore in git resource (can specify multiple paths with commas: path1,path2)")
|
||||||
|
|
||||||
createSourceCmd.AddCommand(createSourceGitCmd)
|
createSourceCmd.AddCommand(createSourceGitCmd)
|
||||||
}
|
}
|
||||||
@@ -189,6 +193,12 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ignorePaths *string
|
||||||
|
if len(sourceGitArgs.ignorePaths) > 0 {
|
||||||
|
ignorePathsStr := strings.Join(sourceGitArgs.ignorePaths, "\n")
|
||||||
|
ignorePaths = &ignorePathsStr
|
||||||
|
}
|
||||||
|
|
||||||
gitRepository := sourcev1.GitRepository{
|
gitRepository := sourcev1.GitRepository{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
@@ -202,6 +212,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
},
|
},
|
||||||
RecurseSubmodules: sourceGitArgs.recurseSubmodules,
|
RecurseSubmodules: sourceGitArgs.recurseSubmodules,
|
||||||
Reference: &sourcev1.GitRepositoryRef{},
|
Reference: &sourcev1.GitRepositoryRef{},
|
||||||
|
Ignore: ignorePaths,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +245,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -248,16 +259,26 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
switch u.Scheme {
|
switch u.Scheme {
|
||||||
case "ssh":
|
case "ssh":
|
||||||
|
keypair, err := sourcesecret.LoadKeyPairFromPath(sourceGitArgs.privateKeyFile, sourceGitArgs.password)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
secretOpts.Keypair = keypair
|
||||||
secretOpts.SSHHostname = u.Host
|
secretOpts.SSHHostname = u.Host
|
||||||
secretOpts.PrivateKeyPath = sourceGitArgs.privateKeyFile
|
|
||||||
secretOpts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(sourceGitArgs.keyAlgorithm)
|
secretOpts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(sourceGitArgs.keyAlgorithm)
|
||||||
secretOpts.RSAKeyBits = int(sourceGitArgs.keyRSABits)
|
secretOpts.RSAKeyBits = int(sourceGitArgs.keyRSABits)
|
||||||
secretOpts.ECDSACurve = sourceGitArgs.keyECDSACurve.Curve
|
secretOpts.ECDSACurve = sourceGitArgs.keyECDSACurve.Curve
|
||||||
secretOpts.Password = sourceGitArgs.password
|
secretOpts.Password = sourceGitArgs.password
|
||||||
case "https":
|
case "https":
|
||||||
|
if sourceGitArgs.caFile != "" {
|
||||||
|
caBundle, err := os.ReadFile(sourceGitArgs.caFile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to read TLS CA file: %w", err)
|
||||||
|
}
|
||||||
|
secretOpts.CAFile = caBundle
|
||||||
|
}
|
||||||
secretOpts.Username = sourceGitArgs.username
|
secretOpts.Username = sourceGitArgs.username
|
||||||
secretOpts.Password = sourceGitArgs.password
|
secretOpts.Password = sourceGitArgs.password
|
||||||
secretOpts.CAFilePath = sourceGitArgs.caFile
|
|
||||||
case "http":
|
case "http":
|
||||||
logger.Warningf("insecure configuration: credentials configured for an HTTP URL")
|
logger.Warningf("insecure configuration: credentials configured for an HTTP URL")
|
||||||
secretOpts.Username = sourceGitArgs.username
|
secretOpts.Username = sourceGitArgs.username
|
||||||
|
|||||||
@@ -85,6 +85,31 @@ func (r *reconciler) conditionFunc() (bool, error) {
|
|||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateSourceGitExport(t *testing.T) {
|
||||||
|
var command = "create source git podinfo --url=https://github.com/stefanprodan/podinfo --branch=master --ignore-paths .cosign,non-existent-dir/ -n default --interval 1m --export --timeout=" + testTimeout.String()
|
||||||
|
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
assert assertFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"ExportSucceeded",
|
||||||
|
command,
|
||||||
|
assertGoldenFile("testdata/create_source_git/export.golden"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tc.args,
|
||||||
|
assert: tc.assert,
|
||||||
|
}
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCreateSourceGit(t *testing.T) {
|
func TestCreateSourceGit(t *testing.T) {
|
||||||
// Default command used for multiple tests
|
// Default command used for multiple tests
|
||||||
var command = "create source git podinfo --url=https://github.com/stefanprodan/podinfo --branch=master --timeout=" + testTimeout.String()
|
var command = "create source git podinfo --url=https://github.com/stefanprodan/podinfo --branch=master --timeout=" + testTimeout.String()
|
||||||
|
|||||||
@@ -44,23 +44,34 @@ var createSourceHelmCmd = &cobra.Command{
|
|||||||
Short: "Create or update a HelmRepository source",
|
Short: "Create or update a HelmRepository source",
|
||||||
Long: `The create source helm command generates a HelmRepository resource and waits for it to fetch the index.
|
Long: `The create source helm command generates a HelmRepository resource and waits for it to fetch the index.
|
||||||
For private Helm repositories, the basic authentication credentials are stored in a Kubernetes secret.`,
|
For private Helm repositories, the basic authentication credentials are stored in a Kubernetes secret.`,
|
||||||
Example: ` # Create a source for a public Helm repository
|
Example: ` # Create a source for an HTTPS public Helm repository
|
||||||
flux create source helm podinfo \
|
flux create source helm podinfo \
|
||||||
--url=https://stefanprodan.github.io/podinfo \
|
--url=https://stefanprodan.github.io/podinfo \
|
||||||
--interval=10m
|
--interval=10m
|
||||||
|
|
||||||
# Create a source for a Helm repository using basic authentication
|
# Create a source for an HTTPS Helm repository using basic authentication
|
||||||
flux create source helm podinfo \
|
flux create source helm podinfo \
|
||||||
--url=https://stefanprodan.github.io/podinfo \
|
--url=https://stefanprodan.github.io/podinfo \
|
||||||
--username=username \
|
--username=username \
|
||||||
--password=password
|
--password=password
|
||||||
|
|
||||||
# Create a source for a Helm repository using TLS authentication
|
# Create a source for an HTTPS Helm repository using TLS authentication
|
||||||
flux create source helm podinfo \
|
flux create source helm podinfo \
|
||||||
--url=https://stefanprodan.github.io/podinfo \
|
--url=https://stefanprodan.github.io/podinfo \
|
||||||
--cert-file=./cert.crt \
|
--cert-file=./cert.crt \
|
||||||
--key-file=./key.crt \
|
--key-file=./key.crt \
|
||||||
--ca-file=./ca.crt`,
|
--ca-file=./ca.crt
|
||||||
|
|
||||||
|
# Create a source for an OCI Helm repository
|
||||||
|
flux create source helm podinfo \
|
||||||
|
--url=oci://ghcr.io/stefanprodan/charts/podinfo
|
||||||
|
--username=username \
|
||||||
|
--password=password
|
||||||
|
|
||||||
|
# Create a source for an OCI Helm repository using an existing secret with basic auth or dockerconfig credentials
|
||||||
|
flux create source helm podinfo \
|
||||||
|
--url=oci://ghcr.io/stefanprodan/charts/podinfo
|
||||||
|
--secret-ref=docker-config`,
|
||||||
RunE: createSourceHelmCmdRun,
|
RunE: createSourceHelmCmdRun,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +95,7 @@ func init() {
|
|||||||
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.certFile, "cert-file", "", "TLS authentication cert file path")
|
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.certFile, "cert-file", "", "TLS authentication cert file path")
|
||||||
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.keyFile, "key-file", "", "TLS authentication key file path")
|
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.keyFile, "key-file", "", "TLS authentication key file path")
|
||||||
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.caFile, "ca-file", "", "TLS authentication CA file path")
|
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.caFile, "ca-file", "", "TLS authentication CA file path")
|
||||||
createSourceHelmCmd.Flags().StringVarP(&sourceHelmArgs.secretRef, "secret-ref", "", "", "the name of an existing secret containing TLS or basic auth credentials")
|
createSourceHelmCmd.Flags().StringVarP(&sourceHelmArgs.secretRef, "secret-ref", "", "", "the name of an existing secret containing TLS, basic auth or docker-config credentials")
|
||||||
createSourceHelmCmd.Flags().BoolVarP(&sourceHelmArgs.passCredentials, "pass-credentials", "", false, "pass credentials to all domains")
|
createSourceHelmCmd.Flags().BoolVarP(&sourceHelmArgs.passCredentials, "pass-credentials", "", false, "pass credentials to all domains")
|
||||||
|
|
||||||
createSourceCmd.AddCommand(createSourceHelmCmd)
|
createSourceCmd.AddCommand(createSourceHelmCmd)
|
||||||
@@ -126,6 +137,14 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
url, err := url.Parse(sourceHelmArgs.url)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to parse URL: %w", err)
|
||||||
|
}
|
||||||
|
if url.Scheme == sourcev1.HelmRepositoryTypeOCI {
|
||||||
|
helmRepository.Spec.Type = sourcev1.HelmRepositoryTypeOCI
|
||||||
|
}
|
||||||
|
|
||||||
if createSourceArgs.fetchTimeout > 0 {
|
if createSourceArgs.fetchTimeout > 0 {
|
||||||
helmRepository.Spec.Timeout = &metav1.Duration{Duration: createSourceArgs.fetchTimeout}
|
helmRepository.Spec.Timeout = &metav1.Duration{Duration: createSourceArgs.fetchTimeout}
|
||||||
}
|
}
|
||||||
@@ -144,11 +163,30 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
caBundle := []byte{}
|
||||||
|
if sourceHelmArgs.caFile != "" {
|
||||||
|
var err error
|
||||||
|
caBundle, err = os.ReadFile(sourceHelmArgs.caFile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to read TLS CA file: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var certFile, keyFile []byte
|
||||||
|
if sourceHelmArgs.certFile != "" && sourceHelmArgs.keyFile != "" {
|
||||||
|
if certFile, err = os.ReadFile(sourceHelmArgs.certFile); err != nil {
|
||||||
|
return fmt.Errorf("failed to read cert file: %w", err)
|
||||||
|
}
|
||||||
|
if keyFile, err = os.ReadFile(sourceHelmArgs.keyFile); err != nil {
|
||||||
|
return fmt.Errorf("failed to read key file: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logger.Generatef("generating HelmRepository source")
|
logger.Generatef("generating HelmRepository source")
|
||||||
if sourceHelmArgs.secretRef == "" {
|
if sourceHelmArgs.secretRef == "" {
|
||||||
secretName := fmt.Sprintf("helm-%s", name)
|
secretName := fmt.Sprintf("helm-%s", name)
|
||||||
@@ -157,9 +195,9 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
Namespace: *kubeconfigArgs.Namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Username: sourceHelmArgs.username,
|
Username: sourceHelmArgs.username,
|
||||||
Password: sourceHelmArgs.password,
|
Password: sourceHelmArgs.password,
|
||||||
CertFilePath: sourceHelmArgs.certFile,
|
CAFile: caBundle,
|
||||||
KeyFilePath: sourceHelmArgs.keyFile,
|
CertFile: certFile,
|
||||||
CAFilePath: sourceHelmArgs.caFile,
|
KeyFile: keyFile,
|
||||||
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
||||||
}
|
}
|
||||||
secret, err := sourcesecret.Generate(secretOpts)
|
secret, err := sourcesecret.Generate(secretOpts)
|
||||||
@@ -196,6 +234,11 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
logger.Successf("HelmRepository source reconciliation completed")
|
logger.Successf("HelmRepository source reconciliation completed")
|
||||||
|
|
||||||
|
if helmRepository.Spec.Type == sourcev1.HelmRepositoryTypeOCI {
|
||||||
|
// OCI repos don't expose any artifact so we just return early here
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if helmRepository.Status.Artifact == nil {
|
if helmRepository.Status.Artifact == nil {
|
||||||
return fmt.Errorf("HelmRepository source reconciliation completed but no artifact was found")
|
return fmt.Errorf("HelmRepository source reconciliation completed but no artifact was found")
|
||||||
}
|
}
|
||||||
|
|||||||
81
cmd/flux/create_source_helm_test.go
Normal file
81
cmd/flux/create_source_helm_test.go
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
//go:build unit
|
||||||
|
// +build unit
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateSourceHelm(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
resultFile string
|
||||||
|
assertFunc string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "no args",
|
||||||
|
args: "create source helm",
|
||||||
|
resultFile: "name is required",
|
||||||
|
assertFunc: "assertError",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "OCI repo",
|
||||||
|
args: "create source helm podinfo --url=oci://ghcr.io/stefanprodan/charts/podinfo --interval 5m --export",
|
||||||
|
resultFile: "./testdata/create_source_helm/oci.golden",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "OCI repo with Secret ref",
|
||||||
|
args: "create source helm podinfo --url=oci://ghcr.io/stefanprodan/charts/podinfo --interval 5m --secret-ref=creds --export",
|
||||||
|
resultFile: "./testdata/create_source_helm/oci-with-secret.golden",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "HTTPS repo",
|
||||||
|
args: "create source helm podinfo --url=https://stefanprodan.github.io/charts/podinfo --interval 5m --export",
|
||||||
|
resultFile: "./testdata/create_source_helm/https.golden",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl := map[string]string{
|
||||||
|
"fluxns": allocateNamespace("flux-system"),
|
||||||
|
}
|
||||||
|
setup(t, tmpl)
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
var assert assertFunc
|
||||||
|
switch tt.assertFunc {
|
||||||
|
case "assertGoldenTemplateFile":
|
||||||
|
assert = assertGoldenTemplateFile(tt.resultFile, tmpl)
|
||||||
|
case "assertError":
|
||||||
|
assert = assertError(tt.resultFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.args + " -n " + tmpl["fluxns"],
|
||||||
|
assert: assert,
|
||||||
|
}
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
247
cmd/flux/create_source_oci.go
Normal file
247
cmd/flux/create_source_oci.go
Normal file
@@ -0,0 +1,247 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
|
"github.com/fluxcd/pkg/apis/meta"
|
||||||
|
"github.com/fluxcd/pkg/runtime/conditions"
|
||||||
|
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
var createSourceOCIRepositoryCmd = &cobra.Command{
|
||||||
|
Use: "oci [name]",
|
||||||
|
Short: "Create or update an OCIRepository",
|
||||||
|
Long: `The create source oci command generates an OCIRepository resource and waits for it to be ready.`,
|
||||||
|
Example: ` # Create an OCIRepository for a public container image
|
||||||
|
flux create source oci podinfo \
|
||||||
|
--url=oci://ghcr.io/stefanprodan/manifests/podinfo \
|
||||||
|
--tag=6.1.6 \
|
||||||
|
--interval=10m
|
||||||
|
`,
|
||||||
|
RunE: createSourceOCIRepositoryCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
type sourceOCIRepositoryFlags struct {
|
||||||
|
url string
|
||||||
|
tag string
|
||||||
|
semver string
|
||||||
|
digest string
|
||||||
|
secretRef string
|
||||||
|
serviceAccount string
|
||||||
|
certSecretRef string
|
||||||
|
ignorePaths []string
|
||||||
|
provider flags.SourceOCIProvider
|
||||||
|
insecure bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var sourceOCIRepositoryArgs = newSourceOCIFlags()
|
||||||
|
|
||||||
|
func newSourceOCIFlags() sourceOCIRepositoryFlags {
|
||||||
|
return sourceOCIRepositoryFlags{
|
||||||
|
provider: flags.SourceOCIProvider(sourcev1.GenericOCIProvider),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
createSourceOCIRepositoryCmd.Flags().Var(&sourceOCIRepositoryArgs.provider, "provider", sourceOCIRepositoryArgs.provider.Description())
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.url, "url", "", "the OCI repository URL")
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.tag, "tag", "", "the OCI artifact tag")
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.semver, "tag-semver", "", "the OCI artifact tag semver range")
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.digest, "digest", "", "the OCI artifact digest")
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.secretRef, "secret-ref", "", "the name of the Kubernetes image pull secret (type 'kubernetes.io/dockerconfigjson')")
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.serviceAccount, "service-account", "", "the name of the Kubernetes service account that refers to an image pull secret")
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.certSecretRef, "cert-ref", "", "the name of a secret to use for TLS certificates")
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringSliceVar(&sourceOCIRepositoryArgs.ignorePaths, "ignore-paths", nil, "set paths to ignore resources (can specify multiple paths with commas: path1,path2)")
|
||||||
|
createSourceOCIRepositoryCmd.Flags().BoolVar(&sourceOCIRepositoryArgs.insecure, "insecure", false, "for when connecting to a non-TLS registries over plain HTTP")
|
||||||
|
|
||||||
|
createSourceCmd.AddCommand(createSourceOCIRepositoryCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func createSourceOCIRepositoryCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
name := args[0]
|
||||||
|
|
||||||
|
if sourceOCIRepositoryArgs.url == "" {
|
||||||
|
return fmt.Errorf("url is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if sourceOCIRepositoryArgs.semver == "" && sourceOCIRepositoryArgs.tag == "" && sourceOCIRepositoryArgs.digest == "" {
|
||||||
|
return fmt.Errorf("--tag, --tag-semver or --digest is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceLabels, err := parseLabels()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var ignorePaths *string
|
||||||
|
if len(sourceOCIRepositoryArgs.ignorePaths) > 0 {
|
||||||
|
ignorePathsStr := strings.Join(sourceOCIRepositoryArgs.ignorePaths, "\n")
|
||||||
|
ignorePaths = &ignorePathsStr
|
||||||
|
}
|
||||||
|
|
||||||
|
repository := &sourcev1.OCIRepository{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: name,
|
||||||
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
|
Labels: sourceLabels,
|
||||||
|
},
|
||||||
|
Spec: sourcev1.OCIRepositorySpec{
|
||||||
|
Provider: sourceOCIRepositoryArgs.provider.String(),
|
||||||
|
URL: sourceOCIRepositoryArgs.url,
|
||||||
|
Insecure: sourceOCIRepositoryArgs.insecure,
|
||||||
|
Interval: metav1.Duration{
|
||||||
|
Duration: createArgs.interval,
|
||||||
|
},
|
||||||
|
Reference: &sourcev1.OCIRepositoryRef{},
|
||||||
|
Ignore: ignorePaths,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if digest := sourceOCIRepositoryArgs.digest; digest != "" {
|
||||||
|
repository.Spec.Reference.Digest = digest
|
||||||
|
}
|
||||||
|
if semver := sourceOCIRepositoryArgs.semver; semver != "" {
|
||||||
|
repository.Spec.Reference.SemVer = semver
|
||||||
|
}
|
||||||
|
if tag := sourceOCIRepositoryArgs.tag; tag != "" {
|
||||||
|
repository.Spec.Reference.Tag = tag
|
||||||
|
}
|
||||||
|
|
||||||
|
if createSourceArgs.fetchTimeout > 0 {
|
||||||
|
repository.Spec.Timeout = &metav1.Duration{Duration: createSourceArgs.fetchTimeout}
|
||||||
|
}
|
||||||
|
|
||||||
|
if saName := sourceOCIRepositoryArgs.serviceAccount; saName != "" {
|
||||||
|
repository.Spec.ServiceAccountName = saName
|
||||||
|
}
|
||||||
|
|
||||||
|
if secretName := sourceOCIRepositoryArgs.secretRef; secretName != "" {
|
||||||
|
repository.Spec.SecretRef = &meta.LocalObjectReference{
|
||||||
|
Name: secretName,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if secretName := sourceOCIRepositoryArgs.certSecretRef; secretName != "" {
|
||||||
|
repository.Spec.CertSecretRef = &meta.LocalObjectReference{
|
||||||
|
Name: secretName,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if createArgs.export {
|
||||||
|
return printExport(exportOCIRepository(repository))
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Actionf("applying OCIRepository")
|
||||||
|
namespacedName, err := upsertOCIRepository(ctx, kubeClient, repository)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Waitingf("waiting for OCIRepository reconciliation")
|
||||||
|
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
|
||||||
|
isOCIRepositoryReady(ctx, kubeClient, namespacedName, repository)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Successf("OCIRepository reconciliation completed")
|
||||||
|
|
||||||
|
if repository.Status.Artifact == nil {
|
||||||
|
return fmt.Errorf("no artifact was found")
|
||||||
|
}
|
||||||
|
logger.Successf("fetched revision: %s", repository.Status.Artifact.Revision)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func upsertOCIRepository(ctx context.Context, kubeClient client.Client,
|
||||||
|
ociRepository *sourcev1.OCIRepository) (types.NamespacedName, error) {
|
||||||
|
namespacedName := types.NamespacedName{
|
||||||
|
Namespace: ociRepository.GetNamespace(),
|
||||||
|
Name: ociRepository.GetName(),
|
||||||
|
}
|
||||||
|
|
||||||
|
var existing sourcev1.OCIRepository
|
||||||
|
err := kubeClient.Get(ctx, namespacedName, &existing)
|
||||||
|
if err != nil {
|
||||||
|
if errors.IsNotFound(err) {
|
||||||
|
if err := kubeClient.Create(ctx, ociRepository); err != nil {
|
||||||
|
return namespacedName, err
|
||||||
|
} else {
|
||||||
|
logger.Successf("OCIRepository created")
|
||||||
|
return namespacedName, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return namespacedName, err
|
||||||
|
}
|
||||||
|
|
||||||
|
existing.Labels = ociRepository.Labels
|
||||||
|
existing.Spec = ociRepository.Spec
|
||||||
|
if err := kubeClient.Update(ctx, &existing); err != nil {
|
||||||
|
return namespacedName, err
|
||||||
|
}
|
||||||
|
ociRepository = &existing
|
||||||
|
logger.Successf("OCIRepository updated")
|
||||||
|
return namespacedName, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func isOCIRepositoryReady(ctx context.Context, kubeClient client.Client,
|
||||||
|
namespacedName types.NamespacedName, ociRepository *sourcev1.OCIRepository) wait.ConditionFunc {
|
||||||
|
return func() (bool, error) {
|
||||||
|
err := kubeClient.Get(ctx, namespacedName, ociRepository)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if c := conditions.Get(ociRepository, meta.ReadyCondition); c != nil {
|
||||||
|
// Confirm the Ready condition we are observing is for the
|
||||||
|
// current generation
|
||||||
|
if c.ObservedGeneration != ociRepository.GetGeneration() {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Further check the Status
|
||||||
|
switch c.Status {
|
||||||
|
case metav1.ConditionTrue:
|
||||||
|
return true, nil
|
||||||
|
case metav1.ConditionFalse:
|
||||||
|
return false, fmt.Errorf(c.Message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
61
cmd/flux/create_source_oci_test.go
Normal file
61
cmd/flux/create_source_oci_test.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateSourceOCI(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
assertFunc assertFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "NoArgs",
|
||||||
|
args: "create source oci",
|
||||||
|
assertFunc: assertError("name is required"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "NoURL",
|
||||||
|
args: "create source oci podinfo",
|
||||||
|
assertFunc: assertError("url is required"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "export manifest",
|
||||||
|
args: "create source oci podinfo --url=oci://ghcr.io/stefanprodan/manifests/podinfo --tag=6.1.6 --interval 10m --export",
|
||||||
|
assertFunc: assertGoldenFile("./testdata/oci/export.golden"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "export manifest with secret",
|
||||||
|
args: "create source oci podinfo --url=oci://ghcr.io/stefanprodan/manifests/podinfo --tag=6.1.6 --interval 10m --secret-ref=creds --export",
|
||||||
|
assertFunc: assertGoldenFile("./testdata/oci/export_with_secret.golden"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.args,
|
||||||
|
assert: tt.assertFunc,
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -156,7 +156,7 @@ func createTenantCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func (del deleteCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var deleteAlertCmd = &cobra.Command{
|
var deleteAlertCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var deleteAlertProviderCmd = &cobra.Command{
|
var deleteAlertProviderCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ var deleteKsCmd = &cobra.Command{
|
|||||||
Aliases: []string{"ks"},
|
Aliases: []string{"ks"},
|
||||||
Short: "Delete a Kustomization resource",
|
Short: "Delete a Kustomization resource",
|
||||||
Long: "The delete kustomization command deletes the given Kustomization from the cluster.",
|
Long: "The delete kustomization command deletes the given Kustomization from the cluster.",
|
||||||
Example: ` # Delete a kustomization and the Kubernetes resources created by it
|
Example: ` # Delete a kustomization and the Kubernetes resources created by it when prune is enabled
|
||||||
flux delete kustomization podinfo`,
|
flux delete kustomization podinfo`,
|
||||||
ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)),
|
ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)),
|
||||||
RunE: deleteCommand{
|
RunE: deleteCommand{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var deleteReceiverCmd = &cobra.Command{
|
var deleteReceiverCmd = &cobra.Command{
|
||||||
|
|||||||
40
cmd/flux/delete_source_oci.go
Normal file
40
cmd/flux/delete_source_oci.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var deleteSourceOCIRepositoryCmd = &cobra.Command{
|
||||||
|
Use: "oci [name]",
|
||||||
|
Short: "Delete an OCIRepository source",
|
||||||
|
Long: "The delete source oci command deletes the given OCIRepository from the cluster.",
|
||||||
|
Example: ` # Delete an OCIRepository
|
||||||
|
flux delete source oci podinfo`,
|
||||||
|
ValidArgsFunction: resourceNamesCompletionFunc(sourcev1.GroupVersion.WithKind(sourcev1.OCIRepositoryKind)),
|
||||||
|
RunE: deleteCommand{
|
||||||
|
apiType: ociRepositoryType,
|
||||||
|
object: universalAdapter{&sourcev1.OCIRepository{}},
|
||||||
|
}.run,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
deleteSourceCmd.AddCommand(deleteSourceOCIRepositoryCmd)
|
||||||
|
}
|
||||||
111
cmd/flux/diff_artifact.go
Normal file
111
cmd/flux/diff_artifact.go
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
|
oci "github.com/fluxcd/pkg/oci/client"
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var diffArtifactCmd = &cobra.Command{
|
||||||
|
Use: "artifact",
|
||||||
|
Short: "Diff Artifact",
|
||||||
|
Long: `The diff artifact command computes the diff between the remote OCI artifact and a local directory or file`,
|
||||||
|
Example: `# Check if local files differ from remote
|
||||||
|
flux diff artifact oci://ghcr.io/stefanprodan/manifests:podinfo:6.2.0 --path=./kustomize`,
|
||||||
|
RunE: diffArtifactCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
type diffArtifactFlags struct {
|
||||||
|
path string
|
||||||
|
creds string
|
||||||
|
provider flags.SourceOCIProvider
|
||||||
|
ignorePaths []string
|
||||||
|
}
|
||||||
|
|
||||||
|
var diffArtifactArgs = newDiffArtifactArgs()
|
||||||
|
|
||||||
|
func newDiffArtifactArgs() diffArtifactFlags {
|
||||||
|
return diffArtifactFlags{
|
||||||
|
provider: flags.SourceOCIProvider(sourcev1.GenericOCIProvider),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
diffArtifactCmd.Flags().StringVar(&diffArtifactArgs.path, "path", "", "path to the directory where the Kubernetes manifests are located")
|
||||||
|
diffArtifactCmd.Flags().StringVar(&diffArtifactArgs.creds, "creds", "", "credentials for OCI registry in the format <username>[:<password>] if --provider is generic")
|
||||||
|
diffArtifactCmd.Flags().Var(&diffArtifactArgs.provider, "provider", sourceOCIRepositoryArgs.provider.Description())
|
||||||
|
diffArtifactCmd.Flags().StringSliceVar(&diffArtifactArgs.ignorePaths, "ignore-paths", excludeOCI, "set paths to ignore in .gitignore format")
|
||||||
|
diffCmd.AddCommand(diffArtifactCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func diffArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) < 1 {
|
||||||
|
return fmt.Errorf("artifact URL is required")
|
||||||
|
}
|
||||||
|
ociURL := args[0]
|
||||||
|
|
||||||
|
if diffArtifactArgs.path == "" {
|
||||||
|
return fmt.Errorf("invalid path %q", diffArtifactArgs.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
url, err := oci.ParseArtifactURL(ociURL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(diffArtifactArgs.path); err != nil {
|
||||||
|
return fmt.Errorf("invalid path '%s', must point to an existing directory or file", diffArtifactArgs.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
ociClient := oci.NewLocalClient()
|
||||||
|
|
||||||
|
if diffArtifactArgs.provider.String() == sourcev1.GenericOCIProvider && diffArtifactArgs.creds != "" {
|
||||||
|
logger.Actionf("logging in to registry with credentials")
|
||||||
|
if err := ociClient.LoginWithCredentials(diffArtifactArgs.creds); err != nil {
|
||||||
|
return fmt.Errorf("could not login with credentials: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if diffArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
|
||||||
|
logger.Actionf("logging in to registry with provider credentials")
|
||||||
|
ociProvider, err := diffArtifactArgs.provider.ToOCIProvider()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("provider not supported: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ociClient.LoginWithProvider(ctx, url, ociProvider); err != nil {
|
||||||
|
return fmt.Errorf("error during login with provider: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ociClient.Diff(ctx, url, diffArtifactArgs.path, diffArtifactArgs.ignorePaths); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Successf("no changes detected")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
109
cmd/flux/diff_artifact_test.go
Normal file
109
cmd/flux/diff_artifact_test.go
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
//go:build unit
|
||||||
|
// +build unit
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2021 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/distribution/distribution/v3/configuration"
|
||||||
|
"github.com/distribution/distribution/v3/registry"
|
||||||
|
_ "github.com/distribution/distribution/v3/registry/auth/htpasswd"
|
||||||
|
_ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
|
||||||
|
"github.com/phayes/freeport"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
var dockerReg string
|
||||||
|
|
||||||
|
func setupRegistryServer(ctx context.Context) error {
|
||||||
|
// Registry config
|
||||||
|
config := &configuration.Configuration{}
|
||||||
|
port, err := freeport.GetFreePort()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get free port: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
dockerReg = fmt.Sprintf("localhost:%d", port)
|
||||||
|
config.HTTP.Addr = fmt.Sprintf("127.0.0.1:%d", port)
|
||||||
|
config.HTTP.DrainTimeout = time.Duration(10) * time.Second
|
||||||
|
config.Storage = map[string]configuration.Parameters{"inmemory": map[string]interface{}{}}
|
||||||
|
dockerRegistry, err := registry.NewRegistry(ctx, config)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create docker registry: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start Docker registry
|
||||||
|
go dockerRegistry.ListenAndServe()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDiffArtifact(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
url string
|
||||||
|
argsTpl string
|
||||||
|
pushFile string
|
||||||
|
diffFile string
|
||||||
|
assert assertFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "should not fail if there is no diff",
|
||||||
|
url: "oci://%s/podinfo:1.0.0",
|
||||||
|
argsTpl: "diff artifact %s --path=%s",
|
||||||
|
pushFile: "./testdata/diff-artifact/deployment.yaml",
|
||||||
|
diffFile: "./testdata/diff-artifact/deployment.yaml",
|
||||||
|
assert: assertGoldenFile("testdata/diff-artifact/success.golden"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "should fail if there is a diff",
|
||||||
|
url: "oci://%s/podinfo:2.0.0",
|
||||||
|
argsTpl: "diff artifact %s --path=%s",
|
||||||
|
pushFile: "./testdata/diff-artifact/deployment.yaml",
|
||||||
|
diffFile: "./testdata/diff-artifact/deployment-diff.yaml",
|
||||||
|
assert: assertError("the remote artifact contents differs from the local one"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := ctrl.SetupSignalHandler()
|
||||||
|
err := setupRegistryServer(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("failed to start docker registry: %s", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
tt.url = fmt.Sprintf(tt.url, dockerReg)
|
||||||
|
_, err := executeCommand("push artifact " + tt.url + " --path=" + tt.pushFile + " --source=test --revision=test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf(fmt.Errorf("failed to push image: %w", err).Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: fmt.Sprintf(tt.argsTpl, tt.url, tt.diffFile),
|
||||||
|
assert: tt.assert,
|
||||||
|
}
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,21 +34,26 @@ var diffKsCmd = &cobra.Command{
|
|||||||
Long: `The diff command does a build, then it performs a server-side dry-run and prints the diff.
|
Long: `The diff command does a build, then it performs a server-side dry-run and prints the diff.
|
||||||
Exit status: 0 No differences were found. 1 Differences were found. >1 diff failed with an error.`,
|
Exit status: 0 No differences were found. 1 Differences were found. >1 diff failed with an error.`,
|
||||||
Example: `# Preview local changes as they were applied on the cluster
|
Example: `# Preview local changes as they were applied on the cluster
|
||||||
flux diff kustomization my-app --path ./path/to/local/manifests`,
|
flux diff kustomization my-app --path ./path/to/local/manifests
|
||||||
|
|
||||||
|
# Preview using a local flux kustomization file
|
||||||
|
flux diff kustomization my-app --path ./path/to/local/manifests --kustomization-file ./path/to/local/my-app.yaml`,
|
||||||
ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)),
|
ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)),
|
||||||
RunE: diffKsCmdRun,
|
RunE: diffKsCmdRun,
|
||||||
}
|
}
|
||||||
|
|
||||||
type diffKsFlags struct {
|
type diffKsFlags struct {
|
||||||
path string
|
kustomizationFile string
|
||||||
progressBar bool
|
path string
|
||||||
|
progressBar bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var diffKsArgs diffKsFlags
|
var diffKsArgs diffKsFlags
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
diffKsCmd.Flags().StringVar(&diffKsArgs.path, "path", "", "Path to a local directory that matches the specified Kustomization.spec.path.)")
|
diffKsCmd.Flags().StringVar(&diffKsArgs.path, "path", "", "Path to a local directory that matches the specified Kustomization.spec.path.")
|
||||||
diffKsCmd.Flags().BoolVar(&diffKsArgs.progressBar, "progress-bar", true, "Boolean to set the progress bar. The default value is true.")
|
diffKsCmd.Flags().BoolVar(&diffKsArgs.progressBar, "progress-bar", true, "Boolean to set the progress bar. The default value is true.")
|
||||||
|
diffKsCmd.Flags().StringVar(&diffKsArgs.kustomizationFile, "kustomization-file", "", "Path to the Flux Kustomization YAML file.")
|
||||||
diffCmd.AddCommand(diffKsCmd)
|
diffCmd.AddCommand(diffKsCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,12 +71,27 @@ func diffKsCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return &RequestError{StatusCode: 2, Err: fmt.Errorf("invalid resource path %q", diffKsArgs.path)}
|
return &RequestError{StatusCode: 2, Err: fmt.Errorf("invalid resource path %q", diffKsArgs.path)}
|
||||||
}
|
}
|
||||||
|
|
||||||
var builder *build.Builder
|
if diffKsArgs.kustomizationFile != "" {
|
||||||
var err error
|
if fs, err := os.Stat(diffKsArgs.kustomizationFile); os.IsNotExist(err) || fs.IsDir() {
|
||||||
|
return fmt.Errorf("invalid kustomization file %q", diffKsArgs.kustomizationFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
builder *build.Builder
|
||||||
|
err error
|
||||||
|
)
|
||||||
if diffKsArgs.progressBar {
|
if diffKsArgs.progressBar {
|
||||||
builder, err = build.NewBuilder(kubeconfigArgs, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout), build.WithProgressBar())
|
builder, err = build.NewBuilder(name, diffKsArgs.path,
|
||||||
|
build.WithClientConfig(kubeconfigArgs, kubeclientOptions),
|
||||||
|
build.WithTimeout(rootArgs.timeout),
|
||||||
|
build.WithKustomizationFile(diffKsArgs.kustomizationFile),
|
||||||
|
build.WithProgressBar())
|
||||||
} else {
|
} else {
|
||||||
builder, err = build.NewBuilder(kubeconfigArgs, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout))
|
builder, err = build.NewBuilder(name, diffKsArgs.path,
|
||||||
|
build.WithClientConfig(kubeconfigArgs, kubeclientOptions),
|
||||||
|
build.WithTimeout(rootArgs.timeout),
|
||||||
|
build.WithKustomizationFile(diffKsArgs.kustomizationFile))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ func TestDiffKustomization(t *testing.T) {
|
|||||||
"fluxns": allocateNamespace("flux-system"),
|
"fluxns": allocateNamespace("flux-system"),
|
||||||
}
|
}
|
||||||
|
|
||||||
b, _ := build.NewBuilder(kubeconfigArgs, "podinfo", "")
|
b, _ := build.NewBuilder("podinfo", "", build.WithClientConfig(kubeconfigArgs, kubeclientOptions))
|
||||||
|
|
||||||
resourceManager, err := b.Manager()
|
resourceManager, err := b.Manager()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ func (export exportCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var exportAlertCmd = &cobra.Command{
|
var exportAlertCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var exportAlertProviderCmd = &cobra.Command{
|
var exportAlertProviderCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var exportReceiverCmd = &cobra.Command{
|
var exportReceiverCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func (export exportWithSecretCommand) run(cmd *cobra.Command, args []string) err
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
92
cmd/flux/export_source_oci.go
Normal file
92
cmd/flux/export_source_oci.go
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var exportSourceOCIRepositoryCmd = &cobra.Command{
|
||||||
|
Use: "oci [name]",
|
||||||
|
Short: "Export OCIRepository sources in YAML format",
|
||||||
|
Long: "The export source oci command exports one or all OCIRepository sources in YAML format.",
|
||||||
|
Example: ` # Export all OCIRepository sources
|
||||||
|
flux export source oci --all > sources.yaml
|
||||||
|
|
||||||
|
# Export a OCIRepository including the static credentials
|
||||||
|
flux export source oci my-app --with-credentials > source.yaml`,
|
||||||
|
ValidArgsFunction: resourceNamesCompletionFunc(sourcev1.GroupVersion.WithKind(sourcev1.OCIRepositoryKind)),
|
||||||
|
RunE: exportWithSecretCommand{
|
||||||
|
list: ociRepositoryListAdapter{&sourcev1.OCIRepositoryList{}},
|
||||||
|
object: ociRepositoryAdapter{&sourcev1.OCIRepository{}},
|
||||||
|
}.run,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
exportSourceCmd.AddCommand(exportSourceOCIRepositoryCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func exportOCIRepository(source *sourcev1.OCIRepository) interface{} {
|
||||||
|
gvk := sourcev1.GroupVersion.WithKind(sourcev1.OCIRepositoryKind)
|
||||||
|
export := sourcev1.OCIRepository{
|
||||||
|
TypeMeta: metav1.TypeMeta{
|
||||||
|
Kind: gvk.Kind,
|
||||||
|
APIVersion: gvk.GroupVersion().String(),
|
||||||
|
},
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: source.Name,
|
||||||
|
Namespace: source.Namespace,
|
||||||
|
Labels: source.Labels,
|
||||||
|
Annotations: source.Annotations,
|
||||||
|
},
|
||||||
|
Spec: source.Spec,
|
||||||
|
}
|
||||||
|
return export
|
||||||
|
}
|
||||||
|
|
||||||
|
func getOCIRepositorySecret(source *sourcev1.OCIRepository) *types.NamespacedName {
|
||||||
|
if source.Spec.SecretRef != nil {
|
||||||
|
namespacedName := types.NamespacedName{
|
||||||
|
Namespace: source.Namespace,
|
||||||
|
Name: source.Spec.SecretRef.Name,
|
||||||
|
}
|
||||||
|
|
||||||
|
return &namespacedName
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ex ociRepositoryAdapter) secret() *types.NamespacedName {
|
||||||
|
return getOCIRepositorySecret(ex.OCIRepository)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ex ociRepositoryListAdapter) secretItem(i int) *types.NamespacedName {
|
||||||
|
return getOCIRepositorySecret(&ex.OCIRepositoryList.Items[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ex ociRepositoryAdapter) export() interface{} {
|
||||||
|
return exportOCIRepository(ex.OCIRepository)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ex ociRepositoryListAdapter) exportItem(i int) interface{} {
|
||||||
|
return exportOCIRepository(&ex.OCIRepositoryList.Items[i])
|
||||||
|
}
|
||||||
@@ -136,7 +136,7 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -162,8 +162,17 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if get.list.len() == 0 {
|
if get.list.len() == 0 {
|
||||||
if !getAll {
|
if len(args) > 0 {
|
||||||
logger.Failuref("no %s objects found in %s namespace", get.kind, *kubeconfigArgs.Namespace)
|
logger.Failuref("%s object '%s' not found in %s namespace",
|
||||||
|
get.kind,
|
||||||
|
args[0],
|
||||||
|
namespaceNameOrAny(getArgs.allNamespaces, *kubeconfigArgs.Namespace),
|
||||||
|
)
|
||||||
|
} else if !getAll {
|
||||||
|
logger.Failuref("no %s objects found in %s namespace",
|
||||||
|
get.kind,
|
||||||
|
namespaceNameOrAny(getArgs.allNamespaces, *kubeconfigArgs.Namespace),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -190,6 +199,13 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func namespaceNameOrAny(allNamespaces bool, namespaceName string) string {
|
||||||
|
if allNamespaces {
|
||||||
|
return "any"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%q", namespaceName)
|
||||||
|
}
|
||||||
|
|
||||||
func getRowsToPrint(getAll bool, list summarisable) ([][]string, error) {
|
func getRowsToPrint(getAll bool, list summarisable) ([][]string, error) {
|
||||||
noFilter := true
|
noFilter := true
|
||||||
var conditionType, conditionStatus string
|
var conditionType, conditionStatus string
|
||||||
@@ -212,7 +228,6 @@ func getRowsToPrint(getAll bool, list summarisable) ([][]string, error) {
|
|||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// watch starts a client-side watch of one or more resources.
|
// watch starts a client-side watch of one or more resources.
|
||||||
func (get *getCommand) watch(ctx context.Context, kubeClient client.WithWatch, cmd *cobra.Command, args []string, listOpts []client.ListOption) error {
|
func (get *getCommand) watch(ctx context.Context, kubeClient client.WithWatch, cmd *cobra.Command, args []string, listOpts []client.ListOption) error {
|
||||||
w, err := kubeClient.Watch(ctx, get.list.asClientList(), listOpts...)
|
w, err := kubeClient.Watch(ctx, get.list.asClientList(), listOpts...)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var getAlertCmd = &cobra.Command{
|
var getAlertCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var getAlertProviderCmd = &cobra.Command{
|
var getAlertProviderCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
|
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
|
||||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var getAllCmd = &cobra.Command{
|
var getAllCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var getReceiverCmd = &cobra.Command{
|
var getReceiverCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ var getSourceAllCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var allSourceCmd = []getCommand{
|
var allSourceCmd = []getCommand{
|
||||||
|
{
|
||||||
|
apiType: ociRepositoryType,
|
||||||
|
list: &ociRepositoryListAdapter{&sourcev1.OCIRepositoryList{}},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
apiType: bucketType,
|
apiType: bucketType,
|
||||||
list: &bucketListAdapter{&sourcev1.BucketList{}},
|
list: &bucketListAdapter{&sourcev1.BucketList{}},
|
||||||
|
|||||||
98
cmd/flux/get_source_oci.go
Normal file
98
cmd/flux/get_source_oci.go
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var getSourceOCIRepositoryCmd = &cobra.Command{
|
||||||
|
Use: "oci",
|
||||||
|
Short: "Get OCIRepository status",
|
||||||
|
Long: "The get sources oci command prints the status of the OCIRepository sources.",
|
||||||
|
Example: ` # List all OCIRepositories and their status
|
||||||
|
flux get sources oci
|
||||||
|
|
||||||
|
# List OCIRepositories from all namespaces
|
||||||
|
flux get sources oci --all-namespaces`,
|
||||||
|
ValidArgsFunction: resourceNamesCompletionFunc(sourcev1.GroupVersion.WithKind(sourcev1.OCIRepositoryKind)),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
get := getCommand{
|
||||||
|
apiType: ociRepositoryType,
|
||||||
|
list: &ociRepositoryListAdapter{&sourcev1.OCIRepositoryList{}},
|
||||||
|
funcMap: make(typeMap),
|
||||||
|
}
|
||||||
|
|
||||||
|
err := get.funcMap.registerCommand(get.apiType.kind, func(obj runtime.Object) (summarisable, error) {
|
||||||
|
o, ok := obj.(*sourcev1.OCIRepository)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("impossible to cast type %#v to OCIRepository", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
sink := &ociRepositoryListAdapter{&sourcev1.OCIRepositoryList{
|
||||||
|
Items: []sourcev1.OCIRepository{
|
||||||
|
*o,
|
||||||
|
}}}
|
||||||
|
return sink, nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := get.run(cmd, args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
getSourceCmd.AddCommand(getSourceOCIRepositoryCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ociRepositoryListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
|
||||||
|
item := a.Items[i]
|
||||||
|
var revision string
|
||||||
|
if item.GetArtifact() != nil {
|
||||||
|
revision = item.GetArtifact().Revision
|
||||||
|
}
|
||||||
|
status, msg := statusAndMessage(item.Status.Conditions)
|
||||||
|
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||||
|
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a ociRepositoryListAdapter) headers(includeNamespace bool) []string {
|
||||||
|
headers := []string{"Name", "Revision", "Suspended", "Ready", "Message"}
|
||||||
|
if includeNamespace {
|
||||||
|
headers = append([]string{"Namespace"}, headers...)
|
||||||
|
}
|
||||||
|
return headers
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a ociRepositoryListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool {
|
||||||
|
item := a.Items[i]
|
||||||
|
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||||
|
}
|
||||||
@@ -1,6 +1,22 @@
|
|||||||
//go:build e2e
|
//go:build e2e
|
||||||
// +build e2e
|
// +build e2e
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||||
"github.com/fluxcd/flux2/pkg/status"
|
"github.com/fluxcd/flux2/pkg/status"
|
||||||
)
|
)
|
||||||
@@ -134,7 +135,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
logger.Generatef("generating manifests")
|
logger.Generatef("generating manifests")
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpDir, err := os.MkdirTemp("", *kubeconfigArgs.Namespace)
|
tmpDir, err := manifestgen.MkdirTempAbs("", *kubeconfigArgs.Namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -193,14 +194,14 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
applyOutput, err := utils.Apply(ctx, kubeconfigArgs, filepath.Join(tmpDir, manifest.Path))
|
applyOutput, err := utils.Apply(ctx, kubeconfigArgs, kubeclientOptions, tmpDir, filepath.Join(tmpDir, manifest.Path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("install failed: %w", err)
|
return fmt.Errorf("install failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintln(os.Stderr, applyOutput)
|
fmt.Fprintln(os.Stderr, applyOutput)
|
||||||
|
|
||||||
kubeConfig, err := utils.KubeConfig(kubeconfigArgs)
|
kubeConfig, err := utils.KubeConfig(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("install failed: %w", err)
|
return fmt.Errorf("install failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
53
cmd/flux/install_test.go
Normal file
53
cmd/flux/install_test.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestInstall(t *testing.T) {
|
||||||
|
// The pointer to kubeconfigArgs.Namespace is shared across
|
||||||
|
// the tests. When a new value is set, it will linger and
|
||||||
|
// impact subsequent tests.
|
||||||
|
// Given that this test uses an invalid namespace, it ensures
|
||||||
|
// to restore whatever value it had previously.
|
||||||
|
currentNamespace := *kubeconfigArgs.Namespace
|
||||||
|
defer func() {
|
||||||
|
*kubeconfigArgs.Namespace = currentNamespace
|
||||||
|
}()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
assert assertFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "invalid namespace",
|
||||||
|
args: "install --namespace='@#[]'",
|
||||||
|
assert: assertError("namespace must be a valid DNS label: \"@#[]\""),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.args,
|
||||||
|
assert: tt.assert,
|
||||||
|
}
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2021 The Flux authors
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -14,22 +14,18 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package test
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"github.com/spf13/cobra"
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type whichTerraform struct{}
|
var listCmd = &cobra.Command{
|
||||||
|
Use: "list",
|
||||||
func (w *whichTerraform) ExecPath(ctx context.Context) (string, error) {
|
Short: "List artifacts",
|
||||||
cmd := exec.CommandContext(ctx, "which", "terraform")
|
Long: "The list command is used for printing the OCI artifacts metadata.",
|
||||||
output, err := cmd.Output()
|
}
|
||||||
if err != nil {
|
|
||||||
return "", err
|
func init() {
|
||||||
}
|
rootCmd.AddCommand(listCmd)
|
||||||
path := strings.TrimSuffix(string(output), "\n")
|
|
||||||
return path, nil
|
|
||||||
}
|
}
|
||||||
123
cmd/flux/list_artifact.go
Normal file
123
cmd/flux/list_artifact.go
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
oci "github.com/fluxcd/pkg/oci/client"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/pkg/printers"
|
||||||
|
)
|
||||||
|
|
||||||
|
type listArtifactFlags struct {
|
||||||
|
semverFilter string
|
||||||
|
regexFilter string
|
||||||
|
creds string
|
||||||
|
provider flags.SourceOCIProvider
|
||||||
|
}
|
||||||
|
|
||||||
|
var listArtifactArgs = newListArtifactFlags()
|
||||||
|
|
||||||
|
func newListArtifactFlags() listArtifactFlags {
|
||||||
|
return listArtifactFlags{
|
||||||
|
provider: flags.SourceOCIProvider(sourcev1.GenericOCIProvider),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var listArtifactsCmd = &cobra.Command{
|
||||||
|
Use: "artifacts",
|
||||||
|
Short: "list artifacts",
|
||||||
|
Long: `The list command fetches the tags and their metadata from a remote OCI repository.
|
||||||
|
The command can read the credentials from '~/.docker/config.json' but they can also be passed with --creds. It can also login to a supported provider with the --provider flag.`,
|
||||||
|
Example: ` # List the artifacts stored in an OCI repository
|
||||||
|
flux list artifact oci://ghcr.io/org/config/app
|
||||||
|
`,
|
||||||
|
RunE: listArtifactsCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
listArtifactsCmd.Flags().StringVar(&listArtifactArgs.semverFilter, "filter-semver", "", "filter tags returned from the oci repository using semver")
|
||||||
|
listArtifactsCmd.Flags().StringVar(&listArtifactArgs.regexFilter, "filter-regex", "", "filter tags returned from the oci repository using regex")
|
||||||
|
listArtifactsCmd.Flags().StringVar(&listArtifactArgs.creds, "creds", "", "credentials for OCI registry in the format <username>[:<password>] if --provider is generic")
|
||||||
|
listArtifactsCmd.Flags().Var(&listArtifactArgs.provider, "provider", listArtifactArgs.provider.Description())
|
||||||
|
|
||||||
|
listCmd.AddCommand(listArtifactsCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func listArtifactsCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) < 1 {
|
||||||
|
return fmt.Errorf("artifact repository URL is required")
|
||||||
|
}
|
||||||
|
ociURL := args[0]
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
url, err := oci.ParseArtifactURL(ociURL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ociClient := oci.NewLocalClient()
|
||||||
|
|
||||||
|
if listArtifactArgs.provider.String() == sourcev1.GenericOCIProvider && listArtifactArgs.creds != "" {
|
||||||
|
logger.Actionf("logging in to registry with credentials")
|
||||||
|
if err := ociClient.LoginWithCredentials(listArtifactArgs.creds); err != nil {
|
||||||
|
return fmt.Errorf("could not login with credentials: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if listArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
|
||||||
|
logger.Actionf("logging in to registry with provider credentials")
|
||||||
|
ociProvider, err := listArtifactArgs.provider.ToOCIProvider()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("provider not supported: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ociClient.LoginWithProvider(ctx, url, ociProvider); err != nil {
|
||||||
|
return fmt.Errorf("error during login with provider: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := oci.ListOptions{
|
||||||
|
RegexFilter: listArtifactArgs.regexFilter,
|
||||||
|
SemverFilter: listArtifactArgs.semverFilter,
|
||||||
|
}
|
||||||
|
|
||||||
|
metas, err := ociClient.List(ctx, url, opts)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows [][]string
|
||||||
|
for _, meta := range metas {
|
||||||
|
rows = append(rows, []string{meta.URL, meta.Digest, meta.Source, meta.Revision})
|
||||||
|
}
|
||||||
|
|
||||||
|
err = printers.TablePrinter([]string{"artifact", "digest", "source", "revision"}).Print(cmd.OutOrStdout(), rows)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -80,6 +80,8 @@ var logsArgs = &logsFlags{
|
|||||||
tail: -1,
|
tail: -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const controllerContainer = "manager"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
logsCmd.Flags().Var(&logsArgs.logLevel, "level", logsArgs.logLevel.Description())
|
logsCmd.Flags().Var(&logsArgs.logLevel, "level", logsArgs.logLevel.Description())
|
||||||
logsCmd.Flags().StringVarP(&logsArgs.kind, "kind", "", logsArgs.kind, "displays errors of a particular toolkit kind e.g GitRepository")
|
logsCmd.Flags().StringVarP(&logsArgs.kind, "kind", "", logsArgs.kind, "displays errors of a particular toolkit kind e.g GitRepository")
|
||||||
@@ -99,7 +101,7 @@ func logsCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
cfg, err := utils.KubeConfig(kubeconfigArgs)
|
cfg, err := utils.KubeConfig(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -146,6 +148,10 @@ func logsCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
var requests []rest.ResponseWrapper
|
var requests []rest.ResponseWrapper
|
||||||
for _, pod := range pods {
|
for _, pod := range pods {
|
||||||
|
logOpts := logOpts.DeepCopy()
|
||||||
|
if len(pod.Spec.Containers) > 1 {
|
||||||
|
logOpts.Container = controllerContainer
|
||||||
|
}
|
||||||
req := clientset.CoreV1().Pods(logsArgs.fluxNamespace).GetLogs(pod.Name, logOpts)
|
req := clientset.CoreV1().Pods(logsArgs.fluxNamespace).GetLogs(pod.Name, logOpts)
|
||||||
requests = append(requests, req)
|
requests = append(requests, req)
|
||||||
}
|
}
|
||||||
@@ -198,12 +204,10 @@ func parallelPodLogs(ctx context.Context, requests []rest.ResponseWrapper) error
|
|||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
wg.Add(len(requests))
|
wg.Add(len(requests))
|
||||||
|
|
||||||
var mutex = &sync.Mutex{}
|
|
||||||
|
|
||||||
for _, request := range requests {
|
for _, request := range requests {
|
||||||
go func(req rest.ResponseWrapper) {
|
go func(req rest.ResponseWrapper) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if err := logRequest(mutex, ctx, req, os.Stdout); err != nil {
|
if err := logRequest(ctx, req, writer); err != nil {
|
||||||
writer.CloseWithError(err)
|
writer.CloseWithError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -220,9 +224,8 @@ func parallelPodLogs(ctx context.Context, requests []rest.ResponseWrapper) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func podLogs(ctx context.Context, requests []rest.ResponseWrapper) error {
|
func podLogs(ctx context.Context, requests []rest.ResponseWrapper) error {
|
||||||
mutex := &sync.Mutex{}
|
|
||||||
for _, req := range requests {
|
for _, req := range requests {
|
||||||
if err := logRequest(mutex, ctx, req, os.Stdout); err != nil {
|
if err := logRequest(ctx, req, os.Stdout); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,7 +243,7 @@ func createLabelStringFromMap(m map[string]string) string {
|
|||||||
return strings.Join(strArr, ",")
|
return strings.Join(strArr, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
func logRequest(mu *sync.Mutex, ctx context.Context, request rest.ResponseWrapper, w io.Writer) error {
|
func logRequest(ctx context.Context, request rest.ResponseWrapper, w io.Writer) error {
|
||||||
stream, err := request.Stream(ctx)
|
stream, err := request.Stream(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -249,12 +252,13 @@ func logRequest(mu *sync.Mutex, ctx context.Context, request rest.ResponseWrappe
|
|||||||
|
|
||||||
scanner := bufio.NewScanner(stream)
|
scanner := bufio.NewScanner(stream)
|
||||||
|
|
||||||
const logTmpl = "{{.Timestamp}} {{.Level}} {{.Kind}}{{if .Name}}/{{.Name}}.{{.Namespace}}{{end}} - {{.Message}} {{.Error}}\n"
|
const logTmpl = "{{.Timestamp}} {{.Level}} {{or .Kind .ControllerKind}}{{if .Name}}/{{.Name}}.{{.Namespace}}{{end}} - {{.Message}} {{.Error}}\n"
|
||||||
t, err := template.New("log").Parse(logTmpl)
|
t, err := template.New("log").Parse(logTmpl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create template, err: %s", err)
|
return fmt.Errorf("unable to create template, err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bw := bufio.NewWriter(w)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
if !strings.HasPrefix(line, "{") {
|
if !strings.HasPrefix(line, "{") {
|
||||||
@@ -265,36 +269,33 @@ func logRequest(mu *sync.Mutex, ctx context.Context, request rest.ResponseWrappe
|
|||||||
logger.Failuref("parse error: %s", err)
|
logger.Failuref("parse error: %s", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
filterPrintLog(t, &l, bw)
|
||||||
mu.Lock()
|
bw.Flush()
|
||||||
filterPrintLog(t, &l)
|
|
||||||
mu.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterPrintLog(t *template.Template, l *ControllerLogEntry) {
|
func filterPrintLog(t *template.Template, l *ControllerLogEntry, w io.Writer) {
|
||||||
if logsArgs.logLevel != "" && logsArgs.logLevel != l.Level ||
|
if (logsArgs.logLevel == "" || logsArgs.logLevel == l.Level) &&
|
||||||
logsArgs.kind != "" && strings.ToLower(logsArgs.kind) != strings.ToLower(l.Kind) ||
|
(logsArgs.kind == "" || strings.EqualFold(logsArgs.kind, l.Kind) || strings.EqualFold(logsArgs.kind, l.ControllerKind)) &&
|
||||||
logsArgs.name != "" && strings.ToLower(logsArgs.name) != strings.ToLower(l.Name) ||
|
(logsArgs.name == "" || strings.EqualFold(logsArgs.name, l.Name)) &&
|
||||||
!logsArgs.allNamespaces && strings.ToLower(*kubeconfigArgs.Namespace) != strings.ToLower(l.Namespace) {
|
(logsArgs.allNamespaces || strings.EqualFold(*kubeconfigArgs.Namespace, l.Namespace)) {
|
||||||
return
|
err := t.Execute(w, l)
|
||||||
}
|
if err != nil {
|
||||||
|
logger.Failuref("log template error: %s", err)
|
||||||
err := t.Execute(os.Stdout, l)
|
}
|
||||||
if err != nil {
|
|
||||||
logger.Failuref("log template error: %s", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ControllerLogEntry struct {
|
type ControllerLogEntry struct {
|
||||||
Timestamp string `json:"ts"`
|
Timestamp string `json:"ts"`
|
||||||
Level flags.LogLevel `json:"level"`
|
Level flags.LogLevel `json:"level"`
|
||||||
Message string `json:"msg"`
|
Message string `json:"msg"`
|
||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
Logger string `json:"logger"`
|
Logger string `json:"logger"`
|
||||||
Kind string `json:"reconciler kind,omitempty"`
|
Kind string `json:"reconciler kind,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
ControllerKind string `json:"controllerKind,omitempty"`
|
||||||
Namespace string `json:"namespace,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
|
Namespace string `json:"namespace,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,14 @@ limitations under the License.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLogsNoArgs(t *testing.T) {
|
func TestLogsNoArgs(t *testing.T) {
|
||||||
@@ -78,3 +85,106 @@ func TestLogsSinceOnlyOneAllowed(t *testing.T) {
|
|||||||
}
|
}
|
||||||
cmd.runTestCmd(t)
|
cmd.runTestCmd(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLogRequest(t *testing.T) {
|
||||||
|
mapper := &testResponseMapper{}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
namespace string
|
||||||
|
flags *logsFlags
|
||||||
|
assertFile string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "all logs",
|
||||||
|
flags: &logsFlags{
|
||||||
|
tail: -1,
|
||||||
|
allNamespaces: true,
|
||||||
|
},
|
||||||
|
assertFile: "testdata/logs/all-logs.txt",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filter by namespace",
|
||||||
|
namespace: "default",
|
||||||
|
flags: &logsFlags{
|
||||||
|
tail: -1,
|
||||||
|
},
|
||||||
|
assertFile: "testdata/logs/namespace.txt",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filter by kind and namespace",
|
||||||
|
flags: &logsFlags{
|
||||||
|
tail: -1,
|
||||||
|
kind: "Kustomization",
|
||||||
|
},
|
||||||
|
assertFile: "testdata/logs/kind.txt",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filter by loglevel",
|
||||||
|
flags: &logsFlags{
|
||||||
|
tail: -1,
|
||||||
|
logLevel: "error",
|
||||||
|
allNamespaces: true,
|
||||||
|
},
|
||||||
|
assertFile: "testdata/logs/log-level.txt",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filter by namespace, name, loglevel and kind",
|
||||||
|
namespace: "flux-system",
|
||||||
|
flags: &logsFlags{
|
||||||
|
tail: -1,
|
||||||
|
logLevel: "error",
|
||||||
|
kind: "Kustomization",
|
||||||
|
name: "podinfo",
|
||||||
|
},
|
||||||
|
assertFile: "testdata/logs/multiple-filters.txt",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
g := NewWithT(t)
|
||||||
|
|
||||||
|
logsArgs = tt.flags
|
||||||
|
if tt.namespace != "" {
|
||||||
|
*kubeconfigArgs.Namespace = tt.namespace
|
||||||
|
}
|
||||||
|
w := bytes.NewBuffer([]byte{})
|
||||||
|
err := logRequest(context.Background(), mapper, w)
|
||||||
|
g.Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
got := make([]byte, w.Len())
|
||||||
|
_, err = w.Read(got)
|
||||||
|
g.Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
expected, err := os.ReadFile(tt.assertFile)
|
||||||
|
g.Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
g.Expect(string(got)).To(Equal(string(expected)))
|
||||||
|
|
||||||
|
// reset flags to default
|
||||||
|
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
||||||
|
logsArgs = &logsFlags{
|
||||||
|
tail: -1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var testPodLogs = `{"level":"info","ts":"2022-08-02T12:55:34.419Z","msg":"no changes since last reconcilation: observed revision","controller":"gitrepository","controllerGroup":"source.toolkit.fluxcd.io","controllerKind":"GitRepository","gitRepository":{"name":"podinfo","namespace":"default"},"namespace":"default","name":"podinfo","reconcileID":"5ef9b2ef-4ea5-47b7-b887-a247cafc1bce"}
|
||||||
|
{"level":"error","ts":"2022-08-02T12:56:04.679Z","logger":"controller.gitrepository","msg":"no changes since last reconcilation: observed revision","controllerGroup":"source.toolkit.fluxcd.io","controllerKind":"GitRepository","gitRepository":{"name":"podinfo","namespace":"flux-system"},"name":"flux-system","namespace":"flux-system","reconcileID":"543ef9b2ef-4ea5-47b7-b887-a247cafc1bce"}
|
||||||
|
{"level":"error","ts":"2022-08-02T12:56:34.961Z","logger":"controller.kustomization","msg":"no changes since last reconcilation: observed revision","reconciler group":"kustomize.toolkit.fluxcd.io","reconciler kind":"Kustomization","name":"flux-system","namespace":"flux-system"}
|
||||||
|
{"level":"info","ts":"2022-08-02T12:56:34.961Z","logger":"controller.kustomization","msg":"no changes since last reconcilation: observed revision","reconciler group":"kustomize.toolkit.fluxcd.io","reconciler kind":"Kustomization","name":"podinfo","namespace":"default"}
|
||||||
|
{"level":"info","ts":"2022-08-02T12:56:34.961Z","logger":"controller.gitrepository","msg":"no changes since last reconcilation: observed revision","reconciler group":"source.toolkit.fluxcd.io","reconciler kind":"GitRepository","name":"podinfo","namespace":"default"}
|
||||||
|
{"level":"error","ts":"2022-08-02T12:56:34.961Z","logger":"controller.kustomization","msg":"no changes since last reconcilation: observed revision","reconciler group":"kustomize.toolkit.fluxcd.io","reconciler kind":"Kustomization","name":"podinfo","namespace":"flux-system"}
|
||||||
|
`
|
||||||
|
|
||||||
|
type testResponseMapper struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *testResponseMapper) DoRaw(_ context.Context) ([]byte, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *testResponseMapper) Stream(_ context.Context) (io.ReadCloser, error) {
|
||||||
|
return io.NopCloser(strings.NewReader(testPodLogs)), nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,9 +27,12 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/util/validation"
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||||
|
|
||||||
|
runclient "github.com/fluxcd/pkg/runtime/client"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -94,6 +97,18 @@ Command line utility for assembling Kubernetes CD pipelines the GitOps way.`,
|
|||||||
|
|
||||||
# Uninstall Flux and delete CRDs
|
# Uninstall Flux and delete CRDs
|
||||||
flux uninstall`,
|
flux uninstall`,
|
||||||
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
ns, err := cmd.Flags().GetString("namespace")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error getting namespace: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e := validation.IsDNS1123Label(ns); len(e) > 0 {
|
||||||
|
return fmt.Errorf("namespace must be a valid DNS label: %q", ns)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var logger = stderrLogger{stderr: os.Stderr}
|
var logger = stderrLogger{stderr: os.Stderr}
|
||||||
@@ -117,6 +132,7 @@ func (r *RequestError) Error() string {
|
|||||||
|
|
||||||
var rootArgs = NewRootFlags()
|
var rootArgs = NewRootFlags()
|
||||||
var kubeconfigArgs = genericclioptions.NewConfigFlags(false)
|
var kubeconfigArgs = genericclioptions.NewConfigFlags(false)
|
||||||
|
var kubeclientOptions = new(runclient.Options)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.PersistentFlags().DurationVar(&rootArgs.timeout, "timeout", 5*time.Minute, "timeout for this operation")
|
rootCmd.PersistentFlags().DurationVar(&rootArgs.timeout, "timeout", 5*time.Minute, "timeout for this operation")
|
||||||
@@ -134,6 +150,8 @@ func init() {
|
|||||||
kubeconfigArgs.APIServer = &apiServer
|
kubeconfigArgs.APIServer = &apiServer
|
||||||
rootCmd.PersistentFlags().StringVar(kubeconfigArgs.APIServer, "server", *kubeconfigArgs.APIServer, "The address and port of the Kubernetes API server")
|
rootCmd.PersistentFlags().StringVar(kubeconfigArgs.APIServer, "server", *kubeconfigArgs.APIServer, "The address and port of the Kubernetes API server")
|
||||||
|
|
||||||
|
kubeclientOptions.BindFlags(rootCmd.PersistentFlags())
|
||||||
|
|
||||||
rootCmd.RegisterFlagCompletionFunc("context", contextsCompletionFunc)
|
rootCmd.RegisterFlagCompletionFunc("context", contextsCompletionFunc)
|
||||||
rootCmd.RegisterFlagCompletionFunc("namespace", resourceNamesCompletionFunc(corev1.SchemeGroupVersion.WithKind("Namespace")))
|
rootCmd.RegisterFlagCompletionFunc("namespace", resourceNamesCompletionFunc(corev1.SchemeGroupVersion.WithKind("Namespace")))
|
||||||
|
|
||||||
@@ -173,17 +191,18 @@ func configureDefaultNamespace() {
|
|||||||
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
||||||
fromEnv := os.Getenv("FLUX_SYSTEM_NAMESPACE")
|
fromEnv := os.Getenv("FLUX_SYSTEM_NAMESPACE")
|
||||||
if fromEnv != "" {
|
if fromEnv != "" {
|
||||||
|
// namespace must be a valid DNS label. Assess against validation
|
||||||
|
// used upstream, and ignore invalid values as environment vars
|
||||||
|
// may not be actively provided by end-user.
|
||||||
|
if e := validation.IsDNS1123Label(fromEnv); len(e) > 0 {
|
||||||
|
logger.Warningf(" ignoring invalid FLUX_SYSTEM_NAMESPACE: %q", fromEnv)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
kubeconfigArgs.Namespace = &fromEnv
|
kubeconfigArgs.Namespace = &fromEnv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func homeDir() string {
|
|
||||||
if h := os.Getenv("HOME"); h != "" {
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
return os.Getenv("USERPROFILE") // windows
|
|
||||||
}
|
|
||||||
|
|
||||||
// readPasswordFromStdin reads a password from stdin and returns the input
|
// readPasswordFromStdin reads a password from stdin and returns the input
|
||||||
// with trailing newline and/or carriage return removed. It also makes sure that terminal
|
// with trailing newline and/or carriage return removed. It also makes sure that terminal
|
||||||
// echoing is turned off if stdin is a terminal.
|
// echoing is turned off if stdin is a terminal.
|
||||||
|
|||||||
@@ -288,36 +288,38 @@ func assertGoldenFile(goldenFile string) assertFunc {
|
|||||||
// is pre-processed with the specified templateValues.
|
// is pre-processed with the specified templateValues.
|
||||||
func assertGoldenTemplateFile(goldenFile string, templateValues map[string]string) assertFunc {
|
func assertGoldenTemplateFile(goldenFile string, templateValues map[string]string) assertFunc {
|
||||||
goldenFileContents, fileErr := os.ReadFile(goldenFile)
|
goldenFileContents, fileErr := os.ReadFile(goldenFile)
|
||||||
return func(output string, err error) error {
|
return assert(
|
||||||
if fileErr != nil {
|
assertSuccess(),
|
||||||
return fmt.Errorf("Error reading golden file '%s': %s", goldenFile, fileErr)
|
func(output string, err error) error {
|
||||||
}
|
if fileErr != nil {
|
||||||
var expectedOutput string
|
return fmt.Errorf("Error reading golden file '%s': %s", goldenFile, fileErr)
|
||||||
if len(templateValues) > 0 {
|
|
||||||
expectedOutput, err = executeTemplate(string(goldenFileContents), templateValues)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Error executing golden template file '%s': %s", goldenFile, err)
|
|
||||||
}
|
}
|
||||||
} else {
|
var expectedOutput string
|
||||||
expectedOutput = string(goldenFileContents)
|
if len(templateValues) > 0 {
|
||||||
}
|
expectedOutput, err = executeTemplate(string(goldenFileContents), templateValues)
|
||||||
if assertErr := assertGoldenValue(expectedOutput)(output, err); assertErr != nil {
|
if err != nil {
|
||||||
// Update the golden files if comparison fails and the update flag is set.
|
return fmt.Errorf("Error executing golden template file '%s': %s", goldenFile, err)
|
||||||
if *update && output != "" {
|
|
||||||
// Skip update if there are template values.
|
|
||||||
if len(templateValues) > 0 {
|
|
||||||
fmt.Println("NOTE: -update flag passed but golden template files can't be updated, please update it manually")
|
|
||||||
} else {
|
|
||||||
if err := os.WriteFile(goldenFile, []byte(output), 0644); err != nil {
|
|
||||||
return fmt.Errorf("failed to update golden file '%s': %v", goldenFile, err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
expectedOutput = string(goldenFileContents)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Mismatch from golden file '%s': %v", goldenFile, assertErr)
|
if assertErr := assertGoldenValue(expectedOutput)(output, err); assertErr != nil {
|
||||||
}
|
// Update the golden files if comparison fails and the update flag is set.
|
||||||
return nil
|
if *update && output != "" {
|
||||||
}
|
// Skip update if there are template values.
|
||||||
|
if len(templateValues) > 0 {
|
||||||
|
fmt.Println("NOTE: -update flag passed but golden template files can't be updated, please update it manually")
|
||||||
|
} else {
|
||||||
|
if err := os.WriteFile(goldenFile, []byte(output), 0644); err != nil {
|
||||||
|
return fmt.Errorf("failed to update golden file '%s': %v", goldenFile, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fmt.Errorf("Mismatch from golden file '%s': %v", goldenFile, assertErr)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestClusterMode int
|
type TestClusterMode int
|
||||||
@@ -341,7 +343,6 @@ type cmdTestCase struct {
|
|||||||
|
|
||||||
func (cmd *cmdTestCase) runTestCmd(t *testing.T) {
|
func (cmd *cmdTestCase) runTestCmd(t *testing.T) {
|
||||||
actual, testErr := executeCommand(cmd.args)
|
actual, testErr := executeCommand(cmd.args)
|
||||||
|
|
||||||
// If the cmd error is a change, discard it
|
// If the cmd error is a change, discard it
|
||||||
if isChangeError(testErr) {
|
if isChangeError(testErr) {
|
||||||
testErr = nil
|
testErr = nil
|
||||||
@@ -383,10 +384,51 @@ func executeCommand(cmd string) (string, error) {
|
|||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resetCmdArgs resets the flags for various cmd
|
||||||
|
// Note: this will also clear default value of the flags set in init()
|
||||||
func resetCmdArgs() {
|
func resetCmdArgs() {
|
||||||
|
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
||||||
|
alertArgs = alertFlags{}
|
||||||
|
alertProviderArgs = alertProviderFlags{}
|
||||||
|
bootstrapArgs = NewBootstrapFlags()
|
||||||
|
bServerArgs = bServerFlags{}
|
||||||
|
buildKsArgs = buildKsFlags{}
|
||||||
|
checkArgs = checkFlags{}
|
||||||
createArgs = createFlags{}
|
createArgs = createFlags{}
|
||||||
|
deleteArgs = deleteFlags{}
|
||||||
|
diffKsArgs = diffKsFlags{}
|
||||||
|
exportArgs = exportFlags{}
|
||||||
getArgs = GetFlags{}
|
getArgs = GetFlags{}
|
||||||
|
gitArgs = gitFlags{}
|
||||||
|
githubArgs = githubFlags{}
|
||||||
|
gitlabArgs = gitlabFlags{}
|
||||||
|
helmReleaseArgs = helmReleaseFlags{
|
||||||
|
reconcileStrategy: "ChartVersion",
|
||||||
|
}
|
||||||
|
imagePolicyArgs = imagePolicyFlags{}
|
||||||
|
imageRepoArgs = imageRepoFlags{}
|
||||||
|
imageUpdateArgs = imageUpdateFlags{}
|
||||||
|
kustomizationArgs = NewKustomizationFlags()
|
||||||
|
receiverArgs = receiverFlags{}
|
||||||
|
resumeArgs = ResumeFlags{}
|
||||||
|
rhrArgs = reconcileHelmReleaseFlags{}
|
||||||
|
rksArgs = reconcileKsFlags{}
|
||||||
secretGitArgs = NewSecretGitFlags()
|
secretGitArgs = NewSecretGitFlags()
|
||||||
|
secretHelmArgs = secretHelmFlags{}
|
||||||
|
secretTLSArgs = secretTLSFlags{}
|
||||||
|
sourceBucketArgs = sourceBucketFlags{}
|
||||||
|
sourceGitArgs = newSourceGitFlags()
|
||||||
|
sourceHelmArgs = sourceHelmFlags{}
|
||||||
|
sourceOCIRepositoryArgs = sourceOCIRepositoryFlags{}
|
||||||
|
suspendArgs = SuspendFlags{}
|
||||||
|
tenantArgs = tenantFlags{}
|
||||||
|
traceArgs = traceFlags{}
|
||||||
|
treeKsArgs = TreeKsFlags{}
|
||||||
|
uninstallArgs = uninstallFlags{}
|
||||||
|
versionArgs = versionFlags{
|
||||||
|
output: "yaml",
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func isChangeError(err error) bool {
|
func isChangeError(err error) bool {
|
||||||
|
|||||||
31
cmd/flux/pull.go
Normal file
31
cmd/flux/pull.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var pullCmd = &cobra.Command{
|
||||||
|
Use: "pull",
|
||||||
|
Short: "Pull artifacts",
|
||||||
|
Long: "The pull command is used to download OCI artifacts.",
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(pullCmd)
|
||||||
|
}
|
||||||
119
cmd/flux/pull_artifact.go
Normal file
119
cmd/flux/pull_artifact.go
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
oci "github.com/fluxcd/pkg/oci/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
var pullArtifactCmd = &cobra.Command{
|
||||||
|
Use: "artifact",
|
||||||
|
Short: "Pull artifact",
|
||||||
|
Long: `The pull artifact command downloads and extracts the OCI artifact content to the given path.
|
||||||
|
The command can read the credentials from '~/.docker/config.json' but they can also be passed with --creds. It can also login to a supported provider with the --provider flag.`,
|
||||||
|
Example: ` # Pull an OCI artifact created by flux from GHCR
|
||||||
|
flux pull artifact oci://ghcr.io/org/manifests/app:v0.0.1 --output ./path/to/local/manifests
|
||||||
|
`,
|
||||||
|
RunE: pullArtifactCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
type pullArtifactFlags struct {
|
||||||
|
output string
|
||||||
|
creds string
|
||||||
|
provider flags.SourceOCIProvider
|
||||||
|
}
|
||||||
|
|
||||||
|
var pullArtifactArgs = newPullArtifactFlags()
|
||||||
|
|
||||||
|
func newPullArtifactFlags() pullArtifactFlags {
|
||||||
|
return pullArtifactFlags{
|
||||||
|
provider: flags.SourceOCIProvider(sourcev1.GenericOCIProvider),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
pullArtifactCmd.Flags().StringVarP(&pullArtifactArgs.output, "output", "o", "", "path where the artifact content should be extracted.")
|
||||||
|
pullArtifactCmd.Flags().StringVar(&pullArtifactArgs.creds, "creds", "", "credentials for OCI registry in the format <username>[:<password>] if --provider is generic")
|
||||||
|
pullArtifactCmd.Flags().Var(&pullArtifactArgs.provider, "provider", sourceOCIRepositoryArgs.provider.Description())
|
||||||
|
pullCmd.AddCommand(pullArtifactCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func pullArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) < 1 {
|
||||||
|
return fmt.Errorf("artifact URL is required")
|
||||||
|
}
|
||||||
|
ociURL := args[0]
|
||||||
|
|
||||||
|
if pullArtifactArgs.output == "" {
|
||||||
|
return fmt.Errorf("invalid output path %s", pullArtifactArgs.output)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fs, err := os.Stat(pullArtifactArgs.output); err != nil || !fs.IsDir() {
|
||||||
|
return fmt.Errorf("invalid output path %s", pullArtifactArgs.output)
|
||||||
|
}
|
||||||
|
|
||||||
|
url, err := oci.ParseArtifactURL(ociURL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
ociClient := oci.NewLocalClient()
|
||||||
|
|
||||||
|
if pullArtifactArgs.provider.String() == sourcev1.GenericOCIProvider && pullArtifactArgs.creds != "" {
|
||||||
|
logger.Actionf("logging in to registry with credentials")
|
||||||
|
if err := ociClient.LoginWithCredentials(pullArtifactArgs.creds); err != nil {
|
||||||
|
return fmt.Errorf("could not login with credentials: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if pullArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
|
||||||
|
logger.Actionf("logging in to registry with provider credentials")
|
||||||
|
ociProvider, err := pullArtifactArgs.provider.ToOCIProvider()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("provider not supported: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ociClient.LoginWithProvider(ctx, url, ociProvider); err != nil {
|
||||||
|
return fmt.Errorf("error during login with provider: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Actionf("pulling artifact from %s", url)
|
||||||
|
|
||||||
|
meta, err := ociClient.Pull(ctx, url, pullArtifactArgs.output)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Successf("source %s", meta.Source)
|
||||||
|
logger.Successf("revision %s", meta.Revision)
|
||||||
|
logger.Successf("digest %s", meta.Digest)
|
||||||
|
logger.Successf("artifact content extracted to %s", pullArtifactArgs.output)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
31
cmd/flux/push.go
Normal file
31
cmd/flux/push.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var pushCmd = &cobra.Command{
|
||||||
|
Use: "push",
|
||||||
|
Short: "Push artifacts",
|
||||||
|
Long: "The push command is used to publish OCI artifacts.",
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(pushCmd)
|
||||||
|
}
|
||||||
241
cmd/flux/push_artifact.go
Normal file
241
cmd/flux/push_artifact.go
Normal file
@@ -0,0 +1,241 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
reg "github.com/google/go-containerregistry/pkg/name"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
|
oci "github.com/fluxcd/pkg/oci/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
var pushArtifactCmd = &cobra.Command{
|
||||||
|
Use: "artifact",
|
||||||
|
Short: "Push artifact",
|
||||||
|
Long: `The push artifact command creates a tarball from the given directory or the single file and uploads the artifact to an OCI repository.
|
||||||
|
The command can read the credentials from '~/.docker/config.json' but they can also be passed with --creds. It can also login to a supported provider with the --provider flag.`,
|
||||||
|
Example: ` # Push manifests to GHCR using the short Git SHA as the OCI artifact tag
|
||||||
|
echo $GITHUB_PAT | docker login ghcr.io --username flux --password-stdin
|
||||||
|
flux push artifact oci://ghcr.io/org/config/app:$(git rev-parse --short HEAD) \
|
||||||
|
--path="./path/to/local/manifests" \
|
||||||
|
--source="$(git config --get remote.origin.url)" \
|
||||||
|
--revision="$(git branch --show-current)/$(git rev-parse HEAD)"
|
||||||
|
|
||||||
|
# Push and sign artifact with cosign
|
||||||
|
digest_url = $(flux push artifact \
|
||||||
|
oci://ghcr.io/org/config/app:$(git rev-parse --short HEAD) \
|
||||||
|
--source="$(git config --get remote.origin.url)" \
|
||||||
|
--revision="$(git branch --show-current)/$(git rev-parse HEAD)" \
|
||||||
|
--path="./path/to/local/manifest.yaml" \
|
||||||
|
--output json | \
|
||||||
|
jq -r '. | .repository + "@" + .digest')
|
||||||
|
cosign sign $digest_url
|
||||||
|
|
||||||
|
# Push manifests passed into stdin to GHCR
|
||||||
|
kustomize build . | flux push artifact oci://ghcr.io/org/config/app:$(git rev-parse --short HEAD) -p - \
|
||||||
|
--source="$(git config --get remote.origin.url)" \
|
||||||
|
--revision="$(git branch --show-current)/$(git rev-parse HEAD)"
|
||||||
|
|
||||||
|
# Push single manifest file to GHCR using the short Git SHA as the OCI artifact tag
|
||||||
|
echo $GITHUB_PAT | docker login ghcr.io --username flux --password-stdin
|
||||||
|
flux push artifact oci://ghcr.io/org/config/app:$(git rev-parse --short HEAD) \
|
||||||
|
--path="./path/to/local/manifest.yaml" \
|
||||||
|
--source="$(git config --get remote.origin.url)" \
|
||||||
|
--revision="$(git branch --show-current)/$(git rev-parse HEAD)"
|
||||||
|
|
||||||
|
# Push manifests to Docker Hub using the Git tag as the OCI artifact tag
|
||||||
|
echo $DOCKER_PAT | docker login --username flux --password-stdin
|
||||||
|
flux push artifact oci://docker.io/org/app-config:$(git tag --points-at HEAD) \
|
||||||
|
--path="./path/to/local/manifests" \
|
||||||
|
--source="$(git config --get remote.origin.url)" \
|
||||||
|
--revision="$(git tag --points-at HEAD)/$(git rev-parse HEAD)"
|
||||||
|
|
||||||
|
# Login directly to the registry provider
|
||||||
|
# You might need to export the following variable if you use local config files for AWS:
|
||||||
|
# export AWS_SDK_LOAD_CONFIG=1
|
||||||
|
flux push artifact oci://<account>.dkr.ecr.<region>.amazonaws.com/foo:v1:$(git tag --points-at HEAD) \
|
||||||
|
--path="./path/to/local/manifests" \
|
||||||
|
--source="$(git config --get remote.origin.url)" \
|
||||||
|
--revision="$(git tag --points-at HEAD)/$(git rev-parse HEAD)" \
|
||||||
|
--provider aws
|
||||||
|
|
||||||
|
# Or pass credentials directly
|
||||||
|
flux push artifact oci://docker.io/org/app-config:$(git tag --points-at HEAD) \
|
||||||
|
--path="./path/to/local/manifests" \
|
||||||
|
--source="$(git config --get remote.origin.url)" \
|
||||||
|
--revision="$(git tag --points-at HEAD)/$(git rev-parse HEAD)" \
|
||||||
|
--creds flux:$DOCKER_PAT
|
||||||
|
`,
|
||||||
|
RunE: pushArtifactCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
type pushArtifactFlags struct {
|
||||||
|
path string
|
||||||
|
source string
|
||||||
|
revision string
|
||||||
|
creds string
|
||||||
|
provider flags.SourceOCIProvider
|
||||||
|
ignorePaths []string
|
||||||
|
output string
|
||||||
|
}
|
||||||
|
|
||||||
|
var pushArtifactArgs = newPushArtifactFlags()
|
||||||
|
|
||||||
|
func newPushArtifactFlags() pushArtifactFlags {
|
||||||
|
return pushArtifactFlags{
|
||||||
|
provider: flags.SourceOCIProvider(sourcev1.GenericOCIProvider),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
pushArtifactCmd.Flags().StringVar(&pushArtifactArgs.path, "path", "", "path to the directory where the Kubernetes manifests are located")
|
||||||
|
pushArtifactCmd.Flags().StringVar(&pushArtifactArgs.source, "source", "", "the source address, e.g. the Git URL")
|
||||||
|
pushArtifactCmd.Flags().StringVar(&pushArtifactArgs.revision, "revision", "", "the source revision in the format '<branch|tag>/<commit-sha>'")
|
||||||
|
pushArtifactCmd.Flags().StringVar(&pushArtifactArgs.creds, "creds", "", "credentials for OCI registry in the format <username>[:<password>] if --provider is generic")
|
||||||
|
pushArtifactCmd.Flags().Var(&pushArtifactArgs.provider, "provider", pushArtifactArgs.provider.Description())
|
||||||
|
pushArtifactCmd.Flags().StringSliceVar(&pushArtifactArgs.ignorePaths, "ignore-paths", excludeOCI, "set paths to ignore in .gitignore format")
|
||||||
|
pushArtifactCmd.Flags().StringVarP(&pushArtifactArgs.output, "output", "o", "",
|
||||||
|
"the format in which the artifact digest should be printed, can be 'json' or 'yaml'")
|
||||||
|
|
||||||
|
pushCmd.AddCommand(pushArtifactCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func pushArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) < 1 {
|
||||||
|
return fmt.Errorf("artifact URL is required")
|
||||||
|
}
|
||||||
|
ociURL := args[0]
|
||||||
|
|
||||||
|
if pushArtifactArgs.source == "" {
|
||||||
|
return fmt.Errorf("--source is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if pushArtifactArgs.revision == "" {
|
||||||
|
return fmt.Errorf("--revision is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if pushArtifactArgs.path == "" {
|
||||||
|
return fmt.Errorf("invalid path %q", pushArtifactArgs.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
url, err := oci.ParseArtifactURL(ociURL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
path := pushArtifactArgs.path
|
||||||
|
if pushArtifactArgs.path == "-" {
|
||||||
|
path, err = saveReaderToFile(os.Stdin)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer os.Remove(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(path); err != nil {
|
||||||
|
return fmt.Errorf("invalid path '%s', must point to an existing directory or file: %w", path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
meta := oci.Metadata{
|
||||||
|
Source: pushArtifactArgs.source,
|
||||||
|
Revision: pushArtifactArgs.revision,
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
ociClient := oci.NewLocalClient()
|
||||||
|
|
||||||
|
if pushArtifactArgs.provider.String() == sourcev1.GenericOCIProvider && pushArtifactArgs.creds != "" {
|
||||||
|
logger.Actionf("logging in to registry with credentials")
|
||||||
|
if err := ociClient.LoginWithCredentials(pushArtifactArgs.creds); err != nil {
|
||||||
|
return fmt.Errorf("could not login with credentials: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if pushArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
|
||||||
|
logger.Actionf("logging in to registry with provider credentials")
|
||||||
|
ociProvider, err := pushArtifactArgs.provider.ToOCIProvider()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("provider not supported: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ociClient.LoginWithProvider(ctx, url, ociProvider); err != nil {
|
||||||
|
return fmt.Errorf("error during login with provider: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if pushArtifactArgs.output == "" {
|
||||||
|
logger.Actionf("pushing artifact to %s", url)
|
||||||
|
}
|
||||||
|
|
||||||
|
digestURL, err := ociClient.Push(ctx, url, path, meta, pushArtifactArgs.ignorePaths)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("pushing artifact failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
digest, err := reg.NewDigest(digestURL)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("artifact digest parsing failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tag, err := reg.NewTag(url)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("artifact tag parsing failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
info := struct {
|
||||||
|
URL string `json:"url"`
|
||||||
|
Repository string `json:"repository"`
|
||||||
|
Tag string `json:"tag"`
|
||||||
|
Digest string `json:"digest"`
|
||||||
|
}{
|
||||||
|
URL: fmt.Sprintf("oci://%s", digestURL),
|
||||||
|
Repository: digest.Repository.Name(),
|
||||||
|
Tag: tag.TagStr(),
|
||||||
|
Digest: digest.DigestStr(),
|
||||||
|
}
|
||||||
|
|
||||||
|
switch pushArtifactArgs.output {
|
||||||
|
case "json":
|
||||||
|
marshalled, err := json.MarshalIndent(&info, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("artifact digest JSON conversion failed: %w", err)
|
||||||
|
}
|
||||||
|
marshalled = append(marshalled, "\n"...)
|
||||||
|
rootCmd.Print(string(marshalled))
|
||||||
|
case "yaml":
|
||||||
|
marshalled, err := yaml.Marshal(&info)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("artifact digest YAML conversion failed: %w", err)
|
||||||
|
}
|
||||||
|
rootCmd.Print(string(marshalled))
|
||||||
|
default:
|
||||||
|
logger.Successf("artifact successfully pushed to %s", digestURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -19,7 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// notificationv1.Receiver
|
// notificationv1.Receiver
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import (
|
|||||||
"k8s.io/client-go/util/retry"
|
"k8s.io/client-go/util/retry"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
"github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
"github.com/fluxcd/pkg/apis/meta"
|
"github.com/fluxcd/pkg/apis/meta"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
@@ -85,7 +85,7 @@ func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
logger.Successf("%s annotated", reconcile.kind)
|
logger.Successf("%s annotated", reconcile.kind)
|
||||||
|
|
||||||
if reconcile.kind == v1beta1.AlertKind || reconcile.kind == v1beta1.ReceiverKind {
|
if reconcile.kind == notificationv1.AlertKind || reconcile.kind == notificationv1.ReceiverKind {
|
||||||
if err = wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
|
if err = wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
|
||||||
isReconcileReady(ctx, kubeClient, namespacedName, reconcile.object)); err != nil {
|
isReconcileReady(ctx, kubeClient, namespacedName, reconcile.object)); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var reconcileAlertCmd = &cobra.Command{
|
var reconcileAlertCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
"github.com/fluxcd/pkg/apis/meta"
|
"github.com/fluxcd/pkg/apis/meta"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
@@ -54,7 +54,7 @@ func reconcileAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ func (obj kustomizationAdapter) reconcileSource() bool {
|
|||||||
func (obj kustomizationAdapter) getSource() (reconcileCommand, types.NamespacedName) {
|
func (obj kustomizationAdapter) getSource() (reconcileCommand, types.NamespacedName) {
|
||||||
var cmd reconcileCommand
|
var cmd reconcileCommand
|
||||||
switch obj.Spec.SourceRef.Kind {
|
switch obj.Spec.SourceRef.Kind {
|
||||||
|
case sourcev1.OCIRepositoryKind:
|
||||||
|
cmd = reconcileCommand{
|
||||||
|
apiType: ociRepositoryType,
|
||||||
|
object: ociRepositoryAdapter{&sourcev1.OCIRepository{}},
|
||||||
|
}
|
||||||
case sourcev1.GitRepositoryKind:
|
case sourcev1.GitRepositoryKind:
|
||||||
cmd = reconcileCommand{
|
cmd = reconcileCommand{
|
||||||
apiType: gitRepositoryType,
|
apiType: gitRepositoryType,
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
|
|
||||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
"github.com/fluxcd/pkg/apis/meta"
|
"github.com/fluxcd/pkg/apis/meta"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
@@ -54,7 +54,7 @@ func reconcileReceiverCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/fluxcd/pkg/apis/meta"
|
||||||
|
"github.com/fluxcd/pkg/runtime/conditions"
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -46,5 +48,15 @@ func (obj helmRepositoryAdapter) lastHandledReconcileRequest() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (obj helmRepositoryAdapter) successMessage() string {
|
func (obj helmRepositoryAdapter) successMessage() string {
|
||||||
|
// HelmRepository of type OCI don't set an Artifact
|
||||||
|
if obj.Spec.Type == sourcev1.HelmRepositoryTypeOCI {
|
||||||
|
readyCondition := conditions.Get(obj.HelmRepository, meta.ReadyCondition)
|
||||||
|
// This shouldn't happen, successMessage shouldn't be called if
|
||||||
|
// object isn't ready
|
||||||
|
if readyCondition == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return readyCondition.Message
|
||||||
|
}
|
||||||
return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision)
|
return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision)
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user