Compare commits
338 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
865f172e33 | ||
|
|
5607754702 | ||
|
|
17d134766d | ||
|
|
06ed881e37 | ||
|
|
eabd250ed2 | ||
|
|
af153ea0cf | ||
|
|
3f3d68a33a | ||
|
|
c0916edc44 | ||
|
|
34220fd514 | ||
|
|
5b8f673baa | ||
|
|
5b18289808 | ||
|
|
2589c90c25 | ||
|
|
16e0b93bec | ||
|
|
9274e80d71 | ||
|
|
66deeec9f1 | ||
|
|
59ca6548ea | ||
|
|
267d2314e0 | ||
|
|
0b5502963e | ||
|
|
4431aa2dd0 | ||
|
|
26aafa1b6f | ||
|
|
d29f1c062f | ||
|
|
879558fe20 | ||
|
|
940b5c4fb9 | ||
|
|
5ab9c01378 | ||
|
|
db67d2c4df | ||
|
|
47867cd80b | ||
|
|
fe0baa4de9 | ||
|
|
262e6bb543 | ||
|
|
18760acaa8 | ||
|
|
a62404c16f | ||
|
|
44db4e100a | ||
|
|
62d8448b9c | ||
|
|
1cc7682d44 | ||
|
|
6eb3fdf863 | ||
|
|
2e4de673b2 | ||
|
|
a64913f2f0 | ||
|
|
2c7d650d44 | ||
|
|
c05b540518 | ||
|
|
c8bd8d0f26 | ||
|
|
a4cd8095a1 | ||
|
|
79485c99ab | ||
|
|
e29f171844 | ||
|
|
c16cca891f | ||
|
|
68ef3a464e | ||
|
|
a5958b494d | ||
|
|
c88a2f4137 | ||
|
|
349bad9240 | ||
|
|
8c7b534544 | ||
|
|
3028897392 | ||
|
|
b28d80e752 | ||
|
|
76552855bb | ||
|
|
e4d19c84eb | ||
|
|
737d615fbc | ||
|
|
2cac6ce281 | ||
|
|
7490d4d4b8 | ||
|
|
3cb9e7cbee | ||
|
|
7b731f7777 | ||
|
|
7e5cbdaea5 | ||
|
|
6e81e82c8c | ||
|
|
a4e1b80ba7 | ||
|
|
e0131f22dd | ||
|
|
caf55ccb7f | ||
|
|
04afc09d58 | ||
|
|
b67c432bc1 | ||
|
|
a59aaa4dfb | ||
|
|
1302fb17c2 | ||
|
|
2e1e4106fd | ||
|
|
e4df6c9d14 | ||
|
|
bca26ebf0a | ||
|
|
2827171dd8 | ||
|
|
b44a3d36ba | ||
|
|
ea04bc8e47 | ||
|
|
0f7b903ace | ||
|
|
71d59e36cc | ||
|
|
7f99655a2b | ||
|
|
d56844010f | ||
|
|
218a661449 | ||
|
|
873950dc55 | ||
|
|
b445013d25 | ||
|
|
65055c273f | ||
|
|
3c14f8beb0 | ||
|
|
9dd98fb2b2 | ||
|
|
4a871cdf10 | ||
|
|
bb6a7b8f07 | ||
|
|
ae9728685c | ||
|
|
662f0d8cae | ||
|
|
1f5961d2ad | ||
|
|
b263e14fa8 | ||
|
|
1e67d75848 | ||
|
|
f4acc0cfc9 | ||
|
|
e5c9132d1d | ||
|
|
3c330b71aa | ||
|
|
f3f6c373fc | ||
|
|
577d4e71af | ||
|
|
a80325995d | ||
|
|
c093714597 | ||
|
|
fa9d42d7bf | ||
|
|
e93b3d8d75 | ||
|
|
6ea3e5b4da | ||
|
|
ae5294f010 | ||
|
|
8571f9e1f8 | ||
|
|
0cd0bf3b58 | ||
|
|
d62cc90f51 | ||
|
|
3fc5f34344 | ||
|
|
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 |
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
|
||||||
|
|||||||
12
.github/runners/prereq.sh
vendored
12
.github/runners/prereq.sh
vendored
@@ -18,11 +18,11 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
KIND_VERSION=0.14.0
|
KIND_VERSION=0.17.0
|
||||||
KUBECTL_VERSION=1.24.0
|
KUBECTL_VERSION=1.24.0
|
||||||
KUSTOMIZE_VERSION=4.5.4
|
KUSTOMIZE_VERSION=4.5.7
|
||||||
HELM_VERSION=3.8.2
|
HELM_VERSION=3.10.1
|
||||||
GITHUB_RUNNER_VERSION=2.291.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/> |
|
||||||
81
.github/workflows/e2e-arm64.yaml
vendored
81
.github/workflows/e2e-arm64.yaml
vendored
@@ -3,33 +3,98 @@ name: e2e-arm64
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches: [ main, update-components ]
|
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
|
||||||
|
# Check which versions are available on DockerHub with 'crane ls kindest/node'
|
||||||
|
KUBERNETES_VERSION: [ 1.24.7, 1.25.3, 1.26.0 ]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
|
||||||
with:
|
with:
|
||||||
go-version: 1.18.x
|
go-version: 1.20.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: |
|
||||||
|
|||||||
29
.github/workflows/e2e-azure.yaml
vendored
29
.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@v3
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
||||||
- name: Restore Go cache
|
- name: Restore Go cache
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go1.18-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go1.20-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go1.18-
|
${{ runner.os }}-go1.20-
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
|
||||||
with:
|
with:
|
||||||
go-version: 1.18.x
|
go-version: 1.20.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,7 +39,7 @@ 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.2.8
|
terraform_version: 1.2.8
|
||||||
terraform_wrapper: false
|
terraform_wrapper: false
|
||||||
|
|||||||
@@ -1,36 +1,44 @@
|
|||||||
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@v3
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
||||||
- name: Restore Go cache
|
- name: Restore Go cache
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go1.18-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go1.20-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go1.18-
|
${{ runner.os }}-go1.20-
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
|
||||||
with:
|
with:
|
||||||
go-version: 1.18.x
|
go-version: 1.20.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
|
||||||
|
# The versions below should target the newest Kubernetes version
|
||||||
|
# Keep this up-to-date with https://endoflife.date/kubernetes
|
||||||
|
node_image: kindest/node:v1.26.0
|
||||||
|
kubectl_version: v1.26.2
|
||||||
- name: Setup Kustomize
|
- name: Setup Kustomize
|
||||||
uses: fluxcd/pkg//actions/kustomize@main
|
uses: fluxcd/pkg/actions/kustomize@main
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
make cmd/flux/.manifests.done
|
make cmd/flux/.manifests.done
|
||||||
@@ -43,7 +51,7 @@ jobs:
|
|||||||
COMMIT_SHA=$(git rev-parse HEAD)
|
COMMIT_SHA=$(git rev-parse HEAD)
|
||||||
PSEUDO_RAND_SUFFIX=$(echo "${BRANCH_NAME}-${COMMIT_SHA}" | shasum | awk '{print $1}')
|
PSEUDO_RAND_SUFFIX=$(echo "${BRANCH_NAME}-${COMMIT_SHA}" | shasum | awk '{print $1}')
|
||||||
TEST_REPO_NAME="${REPOSITORY_NAME}-${PSEUDO_RAND_SUFFIX}"
|
TEST_REPO_NAME="${REPOSITORY_NAME}-${PSEUDO_RAND_SUFFIX}"
|
||||||
echo "::set-output name=test_repo_name::$TEST_REPO_NAME"
|
echo "test_repo_name=$TEST_REPO_NAME" >> $GITHUB_OUTPUT
|
||||||
- name: bootstrap init
|
- name: bootstrap init
|
||||||
run: |
|
run: |
|
||||||
/tmp/flux bootstrap github --manifests ./manifests/install/ \
|
/tmp/flux bootstrap github --manifests ./manifests/install/ \
|
||||||
@@ -80,13 +88,6 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
|
||||||
GITHUB_REPO_NAME: ${{ steps.vars.outputs.test_repo_name }}
|
GITHUB_REPO_NAME: ${{ steps.vars.outputs.test_repo_name }}
|
||||||
GITHUB_ORG_NAME: fluxcd-testing
|
GITHUB_ORG_NAME: fluxcd-testing
|
||||||
- name: libgit2
|
|
||||||
run: |
|
|
||||||
/tmp/flux create source git test-libgit2 \
|
|
||||||
--url=ssh://git@github.com/fluxcd-testing/${{ steps.vars.outputs.test_repo_name }} \
|
|
||||||
--git-implementation=libgit2 \
|
|
||||||
--secret-ref=flux-system \
|
|
||||||
--branch=main
|
|
||||||
- name: uninstall
|
- name: uninstall
|
||||||
run: |
|
run: |
|
||||||
/tmp/flux uninstall -s --keep-namespace
|
/tmp/flux uninstall -s --keep-namespace
|
||||||
58
.github/workflows/e2e.yaml
vendored
58
.github/workflows/e2e.yaml
vendored
@@ -1,13 +1,17 @@
|
|||||||
name: e2e
|
name: e2e
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ main, oci ]
|
branches: [ main, oci ]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
kind:
|
e2e-amd64-kubernetes:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
services:
|
services:
|
||||||
registry:
|
registry:
|
||||||
@@ -16,30 +20,34 @@ jobs:
|
|||||||
- 5000:5000
|
- 5000:5000
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
||||||
- name: Restore Go cache
|
- name: Restore Go cache
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go1.18-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go1.20-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go1.18-
|
${{ runner.os }}-go1.20-
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
|
||||||
with:
|
with:
|
||||||
go-version: 1.18.x
|
go-version: 1.20.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
|
||||||
|
# The versions below should target the newest Kubernetes version
|
||||||
|
# Keep this up-to-date with https://endoflife.date/kubernetes
|
||||||
|
node_image: kindest/node:v1.26.0
|
||||||
|
kubectl_version: v1.26.2
|
||||||
- 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.25/manifests/calico.yaml
|
||||||
kubectl -n kube-system set env daemonset/calico-node FELIX_IGNORELOOSERPF=true
|
kubectl -n kube-system set env daemonset/calico-node FELIX_IGNORELOOSERPF=true
|
||||||
- name: Setup Kustomize
|
- name: Setup Kustomize
|
||||||
uses: fluxcd/pkg//actions/kustomize@main
|
uses: fluxcd/pkg/actions/kustomize@main
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: make test
|
run: make test
|
||||||
- name: Run e2e tests
|
- name: Run e2e tests
|
||||||
@@ -73,21 +81,14 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
/tmp/flux create source git podinfo \
|
/tmp/flux create source git podinfo \
|
||||||
--url https://github.com/stefanprodan/podinfo \
|
--url https://github.com/stefanprodan/podinfo \
|
||||||
--tag-semver=">=3.2.3"
|
--tag-semver=">=6.3.5"
|
||||||
- name: flux create source git export apply
|
- name: flux create source git export apply
|
||||||
run: |
|
run: |
|
||||||
/tmp/flux create source git podinfo-export \
|
/tmp/flux create source git podinfo-export \
|
||||||
--url https://github.com/stefanprodan/podinfo \
|
--url https://github.com/stefanprodan/podinfo \
|
||||||
--tag-semver=">=3.2.3" \
|
--tag-semver=">=6.3.5" \
|
||||||
--export | kubectl apply -f -
|
--export | kubectl apply -f -
|
||||||
/tmp/flux delete source git podinfo-export --silent
|
/tmp/flux delete source git podinfo-export --silent
|
||||||
- name: flux create source git libgit2 semver
|
|
||||||
run: |
|
|
||||||
/tmp/flux create source git podinfo-libgit2 \
|
|
||||||
--url https://github.com/stefanprodan/podinfo \
|
|
||||||
--tag-semver=">=3.2.3" \
|
|
||||||
--git-implementation=libgit2
|
|
||||||
/tmp/flux delete source git podinfo-libgit2 --silent
|
|
||||||
- name: flux get sources git
|
- name: flux get sources git
|
||||||
run: |
|
run: |
|
||||||
/tmp/flux get sources git
|
/tmp/flux get sources git
|
||||||
@@ -142,7 +143,7 @@ jobs:
|
|||||||
--target-namespace=default \
|
--target-namespace=default \
|
||||||
--source=HelmRepository/podinfo.flux-system \
|
--source=HelmRepository/podinfo.flux-system \
|
||||||
--chart=podinfo \
|
--chart=podinfo \
|
||||||
--chart-version=">4.0.0 <5.0.0"
|
--chart-version=">6.0.0 <7.0.0"
|
||||||
- name: flux create helmrelease --source=GitRepository/podinfo
|
- name: flux create helmrelease --source=GitRepository/podinfo
|
||||||
run: |
|
run: |
|
||||||
/tmp/flux create hr podinfo-git \
|
/tmp/flux create hr podinfo-git \
|
||||||
@@ -178,7 +179,7 @@ jobs:
|
|||||||
/tmp/flux push artifact oci://localhost:5000/fluxcd/flux:${{ github.sha }} \
|
/tmp/flux push artifact oci://localhost:5000/fluxcd/flux:${{ github.sha }} \
|
||||||
--path="./manifests" \
|
--path="./manifests" \
|
||||||
--source="${{ github.repositoryUrl }}" \
|
--source="${{ github.repositoryUrl }}" \
|
||||||
--revision="${{ github.ref }}/${{ github.sha }}"
|
--revision="${{ github.ref }}@sha1:${{ github.sha }}"
|
||||||
/tmp/flux tag artifact oci://localhost:5000/fluxcd/flux:${{ github.sha }} \
|
/tmp/flux tag artifact oci://localhost:5000/fluxcd/flux:${{ github.sha }} \
|
||||||
--tag latest
|
--tag latest
|
||||||
/tmp/flux list artifacts oci://localhost:5000/fluxcd/flux
|
/tmp/flux list artifacts oci://localhost:5000/fluxcd/flux
|
||||||
@@ -186,11 +187,11 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
/tmp/flux create source oci podinfo-oci \
|
/tmp/flux create source oci podinfo-oci \
|
||||||
--url oci://ghcr.io/stefanprodan/manifests/podinfo \
|
--url oci://ghcr.io/stefanprodan/manifests/podinfo \
|
||||||
--tag-semver 6.1.x \
|
--tag-semver 6.3.x \
|
||||||
--interval 10m
|
--interval 10m
|
||||||
/tmp/flux create kustomization podinfo-oci \
|
/tmp/flux create kustomization podinfo-oci \
|
||||||
--source=OCIRepository/podinfo-oci \
|
--source=OCIRepository/podinfo-oci \
|
||||||
--path="./kustomize" \
|
--path="./" \
|
||||||
--prune=true \
|
--prune=true \
|
||||||
--interval=5m \
|
--interval=5m \
|
||||||
--target-namespace=default \
|
--target-namespace=default \
|
||||||
@@ -211,21 +212,20 @@ jobs:
|
|||||||
/tmp/flux -n apps create hr podinfo-helm \
|
/tmp/flux -n apps create hr podinfo-helm \
|
||||||
--source=HelmRepository/podinfo \
|
--source=HelmRepository/podinfo \
|
||||||
--chart=podinfo \
|
--chart=podinfo \
|
||||||
--chart-version="5.0.x" \
|
--chart-version="6.3.x" \
|
||||||
--service-account=dev-team
|
--service-account=dev-team
|
||||||
- name: flux2-kustomize-helm-example
|
- name: flux2-kustomize-helm-example
|
||||||
run: |
|
run: |
|
||||||
/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: |
|
||||||
|
|||||||
73
.github/workflows/release-manifests.yml
vendored
73
.github/workflows/release-manifests.yml
vendored
@@ -1,73 +0,0 @@
|
|||||||
name: release-manifests
|
|
||||||
on:
|
|
||||||
release:
|
|
||||||
types: [published]
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
id-token: write # needed for keyless signing
|
|
||||||
packages: write # needed for ghcr access
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-push:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- 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@v2
|
|
||||||
with:
|
|
||||||
registry: ghcr.io
|
|
||||||
username: fluxcdbot
|
|
||||||
password: ${{ secrets.GHCR_TOKEN }}
|
|
||||||
- name: Login to DockerHub
|
|
||||||
uses: docker/login-action@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@main
|
|
||||||
- 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
|
|
||||||
102
.github/workflows/release.yaml
vendored
102
.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@v3
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
||||||
- name: Unshallow
|
- name: Unshallow
|
||||||
run: git fetch --prune --unshallow
|
run: git fetch --prune --unshallow
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
|
||||||
with:
|
with:
|
||||||
go-version: 1.18.x
|
go-version: 1.20.x
|
||||||
- name: Setup QEMU
|
- name: Setup QEMU
|
||||||
uses: docker/setup-qemu-action@v2
|
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2.1.0
|
||||||
- name: Setup Docker Buildx
|
- name: Setup Docker Buildx
|
||||||
id: buildx
|
id: buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@f03ac48505955848960e80bbb68046aa35c7b9e7 # v2.4.1
|
||||||
- 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@c3667d99424e7e6047999fb6246c0da843953c65 # v3.0.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@v2
|
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
|
||||||
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@v2
|
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
|
||||||
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@v3
|
uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0
|
||||||
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 # v3.3.0
|
||||||
|
- 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 "version=${VERSION}" >> $GITHUB_OUTPUT
|
||||||
|
- name: Login to GHCR
|
||||||
|
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: fluxcdbot
|
||||||
|
password: ${{ secrets.GHCR_TOKEN }}
|
||||||
|
- name: Login to DockerHub
|
||||||
|
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
|
||||||
|
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 }}@sha1:${{ 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 }}@sha1:${{ github.sha }}"
|
||||||
|
- uses: sigstore/cosign-installer@c3667d99424e7e6047999fb6246c0da843953c65 # v3.0.1
|
||||||
|
- name: Sign manifests
|
||||||
|
env:
|
||||||
|
COSIGN_EXPERIMENTAL: 1
|
||||||
|
run: |
|
||||||
|
cosign sign --yes ghcr.io/fluxcd/flux-manifests:${{ steps.prep.outputs.version }}
|
||||||
|
cosign sign --yes 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
|
||||||
|
|||||||
58
.github/workflows/scan.yaml
vendored
58
.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:
|
||||||
@@ -9,60 +10,67 @@ on:
|
|||||||
- cron: '18 10 * * 3'
|
- cron: '18 10 * * 3'
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read # for actions/checkout to fetch code
|
contents: read
|
||||||
security-events: write # for codeQL to write security events
|
|
||||||
|
|
||||||
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@v3
|
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
||||||
- 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@6728dc6fe9a068c648d080c33829ffbe56565023 # v2.0.0
|
||||||
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@v3
|
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
||||||
- name: Setup Kustomize
|
- name: Setup Kustomize
|
||||||
uses: fluxcd/pkg//actions/kustomize@main
|
uses: fluxcd/pkg/actions/kustomize@main
|
||||||
- name: Build manifests
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
|
||||||
|
with:
|
||||||
|
go-version: 1.20.x
|
||||||
|
- name: Download modules and build manifests
|
||||||
run: |
|
run: |
|
||||||
|
make tidy
|
||||||
make cmd/flux/.manifests.done
|
make cmd/flux/.manifests.done
|
||||||
- name: Run Snyk to check for vulnerabilities
|
- uses: snyk/actions/setup@806182742461562b67788a64410098c9d9b96adb
|
||||||
uses: snyk/actions/golang@master
|
- name: Run Snyk to check for vulnerabilities
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
run: |
|
||||||
|
snyk test --sarif-file-output=snyk.sarif
|
||||||
env:
|
env:
|
||||||
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
|
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
|
||||||
with:
|
|
||||||
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@32dc499307d133bb5085bae78498c0ac2cf762d5 # v2.2.5
|
||||||
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@v3
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
|
||||||
with:
|
with:
|
||||||
go-version: 1.18
|
go-version: 1.20.x
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v2
|
uses: github/codeql-action/init@32dc499307d133bb5085bae78498c0ac2cf762d5 # v2.2.5
|
||||||
with:
|
with:
|
||||||
languages: go
|
languages: go
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v2
|
uses: github/codeql-action/autobuild@32dc499307d133bb5085bae78498c0ac2cf762d5 # v2.2.5
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v2
|
uses: github/codeql-action/analyze@32dc499307d133bb5085bae78498c0ac2cf762d5 # v2.2.5
|
||||||
|
|||||||
28
.github/workflows/update.yaml
vendored
28
.github/workflows/update.yaml
vendored
@@ -1,4 +1,4 @@
|
|||||||
name: Update Components
|
name: update
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
@@ -7,20 +7,26 @@ 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@v3
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
|
||||||
with:
|
with:
|
||||||
go-version: 1.18.x
|
go-version: 1.20.x
|
||||||
- name: Update component versions
|
- name: Update component versions
|
||||||
id: update
|
id: update
|
||||||
run: |
|
run: |
|
||||||
PR_BODY=""
|
PR_BODY=$(mktemp)
|
||||||
|
|
||||||
bump_version() {
|
bump_version() {
|
||||||
local LATEST_VERSION=$(curl -s https://api.github.com/repos/fluxcd/$1/releases | jq -r 'sort_by(.published_at) | .[-1] | .tag_name')
|
local LATEST_VERSION=$(curl -s https://api.github.com/repos/fluxcd/$1/releases | jq -r 'sort_by(.published_at) | .[-1] | .tag_name')
|
||||||
@@ -47,7 +53,8 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$changed" == true ]]; then
|
if [[ "$changed" == true ]]; then
|
||||||
PR_BODY="$PR_BODY- $1 to ${LATEST_VERSION}%0A https://github.com/fluxcd/$1/blob/${LATEST_VERSION}/CHANGELOG.md%0A"
|
echo "- $1 to ${LATEST_VERSION}" >> $PR_BODY
|
||||||
|
echo " https://github.com/fluxcd/$1/blob/${LATEST_VERSION}/CHANGELOG.md" >> $PR_BODY
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,12 +71,17 @@ jobs:
|
|||||||
git diff
|
git diff
|
||||||
|
|
||||||
# export PR_BODY for PR and commit
|
# export PR_BODY for PR and commit
|
||||||
echo "::set-output name=pr_body::$PR_BODY"
|
# NB: this may look strange but it is the way it should be done to
|
||||||
|
# maintain our precious newlines
|
||||||
|
# Ref: https://github.com/github/docs/issues/21529
|
||||||
|
echo 'pr_body<<EOF' >> $GITHUB_OUTPUT
|
||||||
|
cat $PR_BODY >> $GITHUB_OUTPUT
|
||||||
|
echo 'EOF' >> $GITHUB_OUTPUT
|
||||||
}
|
}
|
||||||
|
|
||||||
- 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.2.3
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.BOT_GITHUB_TOKEN }}
|
token: ${{ secrets.BOT_GITHUB_TOKEN }}
|
||||||
commit-message: |
|
commit-message: |
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ signs:
|
|||||||
certificate: '${artifact}.pem'
|
certificate: '${artifact}.pem'
|
||||||
args:
|
args:
|
||||||
- sign-blob
|
- sign-blob
|
||||||
|
- "--yes"
|
||||||
- '--output-certificate=${certificate}'
|
- '--output-certificate=${certificate}'
|
||||||
- '--output-signature=${signature}'
|
- '--output-signature=${signature}'
|
||||||
- '${artifact}'
|
- '${artifact}'
|
||||||
@@ -175,6 +176,7 @@ docker_signs:
|
|||||||
- COSIGN_EXPERIMENTAL=1
|
- COSIGN_EXPERIMENTAL=1
|
||||||
args:
|
args:
|
||||||
- sign
|
- sign
|
||||||
|
- "--yes"
|
||||||
- '${artifact}'
|
- '${artifact}'
|
||||||
artifacts: all
|
artifacts: all
|
||||||
output: true
|
output: true
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ for source changes.
|
|||||||
|
|
||||||
Prerequisites:
|
Prerequisites:
|
||||||
|
|
||||||
* go >= 1.17
|
* go >= 1.20
|
||||||
* kubectl >= 1.20
|
* kubectl >= 1.20
|
||||||
* kustomize >= 4.4
|
* kustomize >= 4.4
|
||||||
* coreutils (on Mac OS)
|
* coreutils (on Mac OS)
|
||||||
|
|||||||
10
Dockerfile
10
Dockerfile
@@ -1,19 +1,15 @@
|
|||||||
FROM alpine:3.16 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.25.0
|
ARG KUBECTL_VER=1.26.2
|
||||||
|
|
||||||
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.16 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
|
||||||
|
|
||||||
|
|||||||
4
Makefile
4
Makefile
@@ -17,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.18
|
go mod tidy -compat=1.20
|
||||||
cd tests/azure && go mod tidy -compat=1.18
|
cd tests/azure && go mod tidy -compat=1.20
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
|
|||||||
25
README.md
25
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,7 +19,8 @@ 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
|
||||||
|
|
||||||
@@ -77,16 +77,17 @@ 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/flux/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
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,20 @@ You can download a specific version with:
|
|||||||
version: 0.32.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`:
|
||||||
@@ -47,12 +61,16 @@ on:
|
|||||||
schedule:
|
schedule:
|
||||||
- cron: "0 * * * *"
|
- cron: "0 * * * *"
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
components:
|
components:
|
||||||
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 +80,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
|
||||||
@@ -114,24 +132,31 @@ jobs:
|
|||||||
flux push artifact $OCI_REPO:$(git rev-parse --short HEAD) \
|
flux push artifact $OCI_REPO:$(git rev-parse --short HEAD) \
|
||||||
--path="./deploy" \
|
--path="./deploy" \
|
||||||
--source="$(git config --get remote.origin.url)" \
|
--source="$(git config --get remote.origin.url)" \
|
||||||
--revision="$(git branch --show-current)/$(git rev-parse HEAD)"
|
--revision="$(git branch --show-current)@sha1:$(git rev-parse HEAD)"
|
||||||
- name: Deploy manifests to staging
|
- name: Deploy manifests to staging
|
||||||
run: |
|
run: |
|
||||||
flux tag artifact $OCI_REPO:$(git rev-parse --short HEAD) --tag staging
|
flux tag artifact $OCI_REPO:$(git rev-parse --short HEAD) --tag staging
|
||||||
```
|
```
|
||||||
|
|
||||||
Example workflow for publishing Kubernetes manifests bundled as OCI artifacts to Docker Hub:
|
### 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
|
```yaml
|
||||||
name: push-artifact-production
|
name: push-sign-artifact
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
branches:
|
||||||
- '*'
|
- 'main'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
packages: write # needed for ghcr.io access
|
||||||
|
id-token: write # needed for keyless signing
|
||||||
|
|
||||||
env:
|
env:
|
||||||
OCI_REPO: "oci://docker.io/my-org/app-config"
|
OCI_REPO: "oci://ghcr.io/my-org/manifests/${{ github.event.repository.name }}"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
kubernetes:
|
kubernetes:
|
||||||
@@ -141,23 +166,24 @@ jobs:
|
|||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: Setup Flux CLI
|
- name: Setup Flux CLI
|
||||||
uses: fluxcd/flux2/action@main
|
uses: fluxcd/flux2/action@main
|
||||||
- name: Login to Docker Hub
|
- name: Setup Cosign
|
||||||
|
uses: sigstore/cosign-installer@main
|
||||||
|
- name: Login to GHCR
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
registry: ghcr.io
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
username: ${{ github.actor }}
|
||||||
- name: Generate manifests
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Push and sign manifests
|
||||||
run: |
|
run: |
|
||||||
kustomize build ./manifests/production > ./deploy/app.yaml
|
digest_url=$(flux push artifact \
|
||||||
- name: Push manifests
|
$OCI_REPO:$(git rev-parse --short HEAD) \
|
||||||
run: |
|
--path="./manifests" \
|
||||||
flux push artifact $OCI_REPO:$(git tag --points-at HEAD) \
|
--source="$(git config --get remote.origin.url)" \
|
||||||
--path="./deploy" \
|
--revision="$(git branch --show-current)@sha1:$(git rev-parse HEAD)" |\
|
||||||
--source="$(git config --get remote.origin.url)" \
|
jq -r '. | .repository + "@" + .digest')
|
||||||
--revision="$(git tag --points-at HEAD)/$(git rev-parse HEAD)"
|
|
||||||
- name: Deploy manifests to production
|
cosign sign $digest_url
|
||||||
run: |
|
|
||||||
flux tag artifact $OCI_REPO:$(git tag --points-at HEAD) --tag production
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### End-to-end testing
|
### End-to-end testing
|
||||||
@@ -177,7 +203,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
|
||||||
|
|||||||
@@ -31,13 +31,13 @@ import (
|
|||||||
|
|
||||||
var bootstrapCmd = &cobra.Command{
|
var bootstrapCmd = &cobra.Command{
|
||||||
Use: "bootstrap",
|
Use: "bootstrap",
|
||||||
Short: "Bootstrap toolkit components",
|
Short: "Deploy Flux on a cluster the GitOps way.",
|
||||||
Long: "The bootstrap sub-commands bootstrap the toolkit components on the targeted Git provider.",
|
Long: `The bootstrap sub-commands push the Flux manifests to a Git repository
|
||||||
|
and deploy Flux on the cluster.`,
|
||||||
}
|
}
|
||||||
|
|
||||||
type bootstrapFlags struct {
|
type bootstrapFlags struct {
|
||||||
version string
|
version string
|
||||||
arch flags.Arch
|
|
||||||
logLevel flags.LogLevel
|
logLevel flags.LogLevel
|
||||||
|
|
||||||
branch string
|
branch string
|
||||||
@@ -91,9 +91,9 @@ func init() {
|
|||||||
"list of components in addition to those supplied or defaulted, accepts values such as 'image-reflector-controller,image-automation-controller'")
|
"list of components in addition to those supplied or defaulted, accepts values such as 'image-reflector-controller,image-automation-controller'")
|
||||||
|
|
||||||
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.registry, "registry", "ghcr.io/fluxcd",
|
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.registry, "registry", "ghcr.io/fluxcd",
|
||||||
"container registry where the toolkit images are published")
|
"container registry where the Flux controller images are published")
|
||||||
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.imagePullSecret, "image-pull-secret", "",
|
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.imagePullSecret, "image-pull-secret", "",
|
||||||
"Kubernetes secret name used for pulling the toolkit images from a private registry")
|
"Kubernetes secret name used for pulling the controller images from a private registry")
|
||||||
|
|
||||||
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.branch, "branch", bootstrapDefaultBranch, "Git branch")
|
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.branch, "branch", bootstrapDefaultBranch, "Git branch")
|
||||||
bootstrapCmd.PersistentFlags().BoolVar(&bootstrapArgs.recurseSubmodules, "recurse-submodules", false,
|
bootstrapCmd.PersistentFlags().BoolVar(&bootstrapArgs.recurseSubmodules, "recurse-submodules", false,
|
||||||
@@ -102,15 +102,15 @@ func init() {
|
|||||||
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.manifestsPath, "manifests", "", "path to the manifest directory")
|
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.manifestsPath, "manifests", "", "path to the manifest directory")
|
||||||
|
|
||||||
bootstrapCmd.PersistentFlags().BoolVar(&bootstrapArgs.watchAllNamespaces, "watch-all-namespaces", true,
|
bootstrapCmd.PersistentFlags().BoolVar(&bootstrapArgs.watchAllNamespaces, "watch-all-namespaces", true,
|
||||||
"watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed")
|
"watch for custom resources in all namespaces, if set to false it will only watch the namespace where the Flux controllers are installed")
|
||||||
bootstrapCmd.PersistentFlags().BoolVar(&bootstrapArgs.networkPolicy, "network-policy", true,
|
bootstrapCmd.PersistentFlags().BoolVar(&bootstrapArgs.networkPolicy, "network-policy", true,
|
||||||
"deny ingress access to the toolkit controllers from other namespaces using network policies")
|
"setup Kubernetes network policies to deny ingress access to the Flux controllers from other namespaces")
|
||||||
bootstrapCmd.PersistentFlags().BoolVar(&bootstrapArgs.tokenAuth, "token-auth", false,
|
bootstrapCmd.PersistentFlags().BoolVar(&bootstrapArgs.tokenAuth, "token-auth", false,
|
||||||
"when enabled, the personal access token will be used instead of SSH deploy key")
|
"when enabled, the personal access token will be used instead of the SSH deploy key")
|
||||||
bootstrapCmd.PersistentFlags().Var(&bootstrapArgs.logLevel, "log-level", bootstrapArgs.logLevel.Description())
|
bootstrapCmd.PersistentFlags().Var(&bootstrapArgs.logLevel, "log-level", bootstrapArgs.logLevel.Description())
|
||||||
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.clusterDomain, "cluster-domain", rootArgs.defaults.ClusterDomain, "internal cluster domain")
|
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.clusterDomain, "cluster-domain", rootArgs.defaults.ClusterDomain, "internal cluster domain")
|
||||||
bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapArgs.tolerationKeys, "toleration-keys", nil,
|
bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapArgs.tolerationKeys, "toleration-keys", nil,
|
||||||
"list of toleration keys used to schedule the components pods onto nodes with matching taints")
|
"list of toleration keys used to schedule the controller pods onto nodes with matching taints")
|
||||||
|
|
||||||
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.secretName, "secret-name", rootArgs.defaults.Namespace, "name of the secret the sync credentials can be found in or stored to")
|
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.secretName, "secret-name", rootArgs.defaults.Namespace, "name of the secret the sync credentials can be found in or stored to")
|
||||||
bootstrapCmd.PersistentFlags().Var(&bootstrapArgs.keyAlgorithm, "ssh-key-algorithm", bootstrapArgs.keyAlgorithm.Description())
|
bootstrapCmd.PersistentFlags().Var(&bootstrapArgs.keyAlgorithm, "ssh-key-algorithm", bootstrapArgs.keyAlgorithm.Description())
|
||||||
@@ -129,8 +129,6 @@ func init() {
|
|||||||
|
|
||||||
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.commitMessageAppendix, "commit-message-appendix", "", "string to add to the commit messages, e.g. '[ci skip]'")
|
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.commitMessageAppendix, "commit-message-appendix", "", "string to add to the commit messages, e.g. '[ci skip]'")
|
||||||
|
|
||||||
bootstrapCmd.PersistentFlags().Var(&bootstrapArgs.arch, "arch", bootstrapArgs.arch.Description())
|
|
||||||
bootstrapCmd.PersistentFlags().MarkDeprecated("arch", "multi-arch container image is now available for AMD64, ARMv7 and ARM64")
|
|
||||||
bootstrapCmd.PersistentFlags().MarkHidden("manifests")
|
bootstrapCmd.PersistentFlags().MarkHidden("manifests")
|
||||||
|
|
||||||
rootCmd.AddCommand(bootstrapCmd)
|
rootCmd.AddCommand(bootstrapCmd)
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ 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"
|
||||||
"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"
|
||||||
@@ -38,29 +38,26 @@ import (
|
|||||||
|
|
||||||
var bootstrapBServerCmd = &cobra.Command{
|
var bootstrapBServerCmd = &cobra.Command{
|
||||||
Use: "bitbucket-server",
|
Use: "bitbucket-server",
|
||||||
Short: "Bootstrap toolkit components in a Bitbucket Server repository",
|
Short: "Deploy Flux on a cluster connected to a Bitbucket Server repository",
|
||||||
Long: `The bootstrap bitbucket-server command creates the Bitbucket Server repository if it doesn't exists and
|
Long: `The bootstrap bitbucket-server command creates the Bitbucket Server repository if it doesn't exists and
|
||||||
commits the toolkit components manifests to the master branch.
|
commits the Flux manifests to the master branch.
|
||||||
Then it configures the target cluster to synchronize with the repository.
|
Then it configures the target cluster to synchronize with the repository.
|
||||||
If the toolkit components are present on the cluster,
|
If the Flux components are present on the cluster,
|
||||||
the bootstrap command will perform an upgrade if needed.`,
|
the bootstrap command will perform an upgrade if needed.`,
|
||||||
Example: ` # Create a Bitbucket Server API token and export it as an env var
|
Example: ` # Create a Bitbucket Server API token and export it as an env var
|
||||||
export BITBUCKET_TOKEN=<my-token>
|
export BITBUCKET_TOKEN=<my-token>
|
||||||
|
|
||||||
# Run bootstrap for a private repository using HTTPS token authentication
|
# Run bootstrap for a private repository using HTTPS token authentication
|
||||||
flux bootstrap bitbucket-server --owner=<project> --username=<user> --repository=<repository name> --hostname=<domain> --token-auth
|
flux bootstrap bitbucket-server --owner=<project> --username=<user> --repository=<repository name> --hostname=<domain> --token-auth --path=clusters/my-cluster
|
||||||
|
|
||||||
# Run bootstrap for a private repository using SSH authentication
|
# Run bootstrap for a private repository using SSH authentication
|
||||||
flux bootstrap bitbucket-server --owner=<project> --username=<user> --repository=<repository name> --hostname=<domain>
|
flux bootstrap bitbucket-server --owner=<project> --username=<user> --repository=<repository name> --hostname=<domain> --path=clusters/my-cluster
|
||||||
|
|
||||||
# Run bootstrap for a repository path
|
|
||||||
flux bootstrap bitbucket-server --owner=<project> --username=<user> --repository=<repository name> --path=dev-cluster --hostname=<domain>
|
|
||||||
|
|
||||||
# Run bootstrap for a public repository on a personal account
|
# Run bootstrap for a public repository on a personal account
|
||||||
flux bootstrap bitbucket-server --owner=<user> --repository=<repository name> --private=false --personal --hostname=<domain> --token-auth
|
flux bootstrap bitbucket-server --owner=<user> --repository=<repository name> --private=false --personal --hostname=<domain> --token-auth --path=clusters/my-cluster
|
||||||
|
|
||||||
# Run bootstrap for a an existing repository with a branch named main
|
# Run bootstrap for a an existing repository with a branch named main
|
||||||
flux bootstrap bitbucket-server --owner=<project> --username=<user> --repository=<repository name> --branch=main --hostname=<domain> --token-auth`,
|
flux bootstrap bitbucket-server --owner=<project> --username=<user> --repository=<repository name> --branch=main --hostname=<domain> --token-auth --path=clusters/my-cluster`,
|
||||||
RunE: bootstrapBServerCmdRun,
|
RunE: bootstrapBServerCmdRun,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +125,9 @@ func bootstrapBServerCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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()
|
||||||
@@ -171,10 +170,17 @@ func bootstrapBServerCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
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{
|
||||||
@@ -212,19 +218,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
|
||||||
}
|
}
|
||||||
@@ -239,23 +244,27 @@ func bootstrapBServerCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
Secret: bootstrapArgs.secretName,
|
Secret: bootstrapArgs.secretName,
|
||||||
TargetPath: bServerArgs.path.ToSlash(),
|
TargetPath: bServerArgs.path.ToSlash(),
|
||||||
ManifestFile: sync.MakeDefaultOptions().ManifestFile,
|
ManifestFile: sync.MakeDefaultOptions().ManifestFile,
|
||||||
GitImplementation: sourceGitArgs.gitImplementation.String(),
|
|
||||||
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, kubeclientOptions),
|
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,44 +24,48 @@ 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"
|
||||||
"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{
|
||||||
Use: "git",
|
Use: "git",
|
||||||
Short: "Bootstrap toolkit components in a Git repository",
|
Short: "Deploy Flux on a cluster connected to a Git repository",
|
||||||
Long: `The bootstrap git command commits the toolkit components manifests to the
|
Long: `The bootstrap git command commits the Flux manifests to the
|
||||||
branch of a Git repository. It then configures the target cluster to synchronize with
|
branch of a Git repository. And then it configures the target cluster to synchronize with
|
||||||
the repository. If the toolkit components are present on the cluster, the bootstrap
|
that repository. If the Flux components are present on the cluster, the bootstrap
|
||||||
command will perform an upgrade if needed.`,
|
command will perform an upgrade if needed.`,
|
||||||
Example: ` # Run bootstrap for a Git repository and authenticate with your SSH agent
|
Example: ` # Run bootstrap for a Git repository and authenticate with your SSH agent
|
||||||
flux bootstrap git --url=ssh://git@example.com/repository.git
|
flux bootstrap git --url=ssh://git@example.com/repository.git --path=clusters/my-cluster
|
||||||
|
|
||||||
# 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> --path=clusters/my-cluster
|
||||||
|
|
||||||
# Run bootstrap for a Git repository and authenticate using a password from environment variable
|
# 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
|
GIT_PASSWORD=<password> && flux bootstrap git --url=https://example.com/repository.git --path=clusters/my-cluster
|
||||||
|
|
||||||
# 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> --path=clusters/my-cluster
|
||||||
|
|
||||||
# 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> --path=clusters/my-cluster
|
||||||
|
|
||||||
|
# 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> --path=clusters/my-cluster
|
||||||
|
|
||||||
|
# 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 --path=clusters/my-cluster
|
||||||
`,
|
`,
|
||||||
RunE: bootstrapGitCmdRun,
|
RunE: bootstrapGitCmdRun,
|
||||||
}
|
}
|
||||||
@@ -89,7 +93,7 @@ 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")
|
bootstrapGitCmd.Flags().BoolVar(&gitArgs.insecureHttpAllowed, "allow-insecure-http", false, "allows insecure HTTP connections")
|
||||||
|
|
||||||
bootstrapCmd.AddCommand(bootstrapGitCmd)
|
bootstrapCmd.AddCommand(bootstrapGitCmd)
|
||||||
}
|
}
|
||||||
@@ -116,9 +120,22 @@ 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)
|
||||||
@@ -130,7 +147,9 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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()
|
||||||
@@ -145,7 +164,28 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
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{
|
||||||
@@ -179,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
|
||||||
@@ -192,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
|
||||||
@@ -211,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
|
||||||
@@ -229,30 +271,24 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
Secret: bootstrapArgs.secretName,
|
Secret: bootstrapArgs.secretName,
|
||||||
TargetPath: gitArgs.path.ToSlash(),
|
TargetPath: gitArgs.path.ToSlash(),
|
||||||
ManifestFile: sync.MakeDefaultOptions().ManifestFile,
|
ManifestFile: sync.MakeDefaultOptions().ManifestFile,
|
||||||
GitImplementation: sourceGitArgs.gitImplementation.String(),
|
|
||||||
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, kubeclientOptions),
|
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
|
||||||
@@ -265,30 +301,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":
|
case "http":
|
||||||
if !gitArgs.insecureHttpAllowed {
|
if !gitArgs.insecureHttpAllowed {
|
||||||
return nil, fmt.Errorf("scheme http is insecure, pass --allow-insecure-http=true to allow it")
|
return nil, fmt.Errorf("scheme http is insecure, pass --allow-insecure-http=true to allow it")
|
||||||
}
|
}
|
||||||
return &http.BasicAuth{
|
return &git.AuthOptions{
|
||||||
Username: gitArgs.username,
|
Transport: git.HTTP,
|
||||||
Password: gitArgs.password,
|
Username: gitArgs.username,
|
||||||
|
Password: gitArgs.password,
|
||||||
}, nil
|
}, 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,14 @@ 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"
|
||||||
"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"
|
||||||
@@ -38,38 +38,35 @@ import (
|
|||||||
|
|
||||||
var bootstrapGitHubCmd = &cobra.Command{
|
var bootstrapGitHubCmd = &cobra.Command{
|
||||||
Use: "github",
|
Use: "github",
|
||||||
Short: "Bootstrap toolkit components in a GitHub repository",
|
Short: "Deploy Flux on a cluster connected to a GitHub repository",
|
||||||
Long: `The bootstrap github command creates the GitHub repository if it doesn't exists and
|
Long: `The bootstrap github command creates the GitHub repository if it doesn't exists and
|
||||||
commits the toolkit components manifests to the main branch.
|
commits the Flux manifests to the specified branch.
|
||||||
Then it configures the target cluster to synchronize with the repository.
|
Then it configures the target cluster to synchronize with that repository.
|
||||||
If the toolkit components are present on the cluster,
|
If the Flux components are present on the cluster,
|
||||||
the bootstrap command will perform an upgrade if needed.`,
|
the bootstrap command will perform an upgrade if needed.`,
|
||||||
Example: ` # Create a GitHub personal access token and export it as an env var
|
Example: ` # Create a GitHub personal access token and export it as an env var
|
||||||
export GITHUB_TOKEN=<my-token>
|
export GITHUB_TOKEN=<my-token>
|
||||||
|
|
||||||
# Run bootstrap for a private repository owned by a GitHub organization
|
# Run bootstrap for a private repository owned by a GitHub organization
|
||||||
flux bootstrap github --owner=<organization> --repository=<repository name>
|
flux bootstrap github --owner=<organization> --repository=<repository name> --path=clusters/my-cluster
|
||||||
|
|
||||||
# Run bootstrap for a private repository and assign organization teams to it
|
# Run bootstrap for a private repository and assign organization teams to it
|
||||||
flux bootstrap github --owner=<organization> --repository=<repository name> --team=<team1 slug> --team=<team2 slug>
|
flux bootstrap github --owner=<organization> --repository=<repository name> --team=<team1 slug> --team=<team2 slug> --path=clusters/my-cluster
|
||||||
|
|
||||||
# Run bootstrap for a private repository and assign organization teams with their access level(e.g maintain, admin) to it
|
# Run bootstrap for a private repository and assign organization teams with their access level(e.g maintain, admin) to it
|
||||||
flux bootstrap github --owner=<organization> --repository=<repository name> --team=<team1 slug>:<access-level>
|
flux bootstrap github --owner=<organization> --repository=<repository name> --team=<team1 slug>:<access-level> --path=clusters/my-cluster
|
||||||
|
|
||||||
# Run bootstrap for a repository path
|
|
||||||
flux bootstrap github --owner=<organization> --repository=<repository name> --path=dev-cluster
|
|
||||||
|
|
||||||
# Run bootstrap for a public repository on a personal account
|
# Run bootstrap for a public repository on a personal account
|
||||||
flux bootstrap github --owner=<user> --repository=<repository name> --private=false --personal=true
|
flux bootstrap github --owner=<user> --repository=<repository name> --private=false --personal=true --path=clusters/my-cluster
|
||||||
|
|
||||||
# Run bootstrap for a private repository hosted on GitHub Enterprise using SSH auth
|
# Run bootstrap for a private repository hosted on GitHub Enterprise using SSH auth
|
||||||
flux bootstrap github --owner=<organization> --repository=<repository name> --hostname=<domain> --ssh-hostname=<domain>
|
flux bootstrap github --owner=<organization> --repository=<repository name> --hostname=<domain> --ssh-hostname=<domain> --path=clusters/my-cluster
|
||||||
|
|
||||||
# Run bootstrap for a private repository hosted on GitHub Enterprise using HTTPS auth
|
# Run bootstrap for a private repository hosted on GitHub Enterprise using HTTPS auth
|
||||||
flux bootstrap github --owner=<organization> --repository=<repository name> --hostname=<domain> --token-auth
|
flux bootstrap github --owner=<organization> --repository=<repository name> --hostname=<domain> --token-auth --path=clusters/my-cluster
|
||||||
|
|
||||||
# Run bootstrap for an existing repository with a branch named main
|
# Run bootstrap for an existing repository with a branch named main
|
||||||
flux bootstrap github --owner=<organization> --repository=<repository name> --branch=main`,
|
flux bootstrap github --owner=<organization> --repository=<repository name> --branch=main --path=clusters/my-cluster`,
|
||||||
RunE: bootstrapGitHubCmdRun,
|
RunE: bootstrapGitHubCmdRun,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +129,9 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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()
|
||||||
@@ -161,16 +160,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 := 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: 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{
|
||||||
@@ -204,16 +209,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
|
||||||
}
|
}
|
||||||
@@ -228,23 +230,26 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
Secret: bootstrapArgs.secretName,
|
Secret: bootstrapArgs.secretName,
|
||||||
TargetPath: githubArgs.path.ToSlash(),
|
TargetPath: githubArgs.path.ToSlash(),
|
||||||
ManifestFile: sync.MakeDefaultOptions().ManifestFile,
|
ManifestFile: sync.MakeDefaultOptions().ManifestFile,
|
||||||
GitImplementation: sourceGitArgs.gitImplementation.String(),
|
|
||||||
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, kubeclientOptions),
|
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,14 @@ 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"
|
||||||
"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"
|
||||||
@@ -40,11 +40,11 @@ import (
|
|||||||
|
|
||||||
var bootstrapGitLabCmd = &cobra.Command{
|
var bootstrapGitLabCmd = &cobra.Command{
|
||||||
Use: "gitlab",
|
Use: "gitlab",
|
||||||
Short: "Bootstrap toolkit components in a GitLab repository",
|
Short: "Deploy Flux on a cluster connected to a GitLab repository",
|
||||||
Long: `The bootstrap gitlab command creates the GitLab repository if it doesn't exists and
|
Long: `The bootstrap gitlab command creates the GitLab repository if it doesn't exists and
|
||||||
commits the toolkit components manifests to the master branch.
|
commits the Flux manifests to the specified branch.
|
||||||
Then it configures the target cluster to synchronize with the repository.
|
Then it configures the target cluster to synchronize with that repository.
|
||||||
If the toolkit components are present on the cluster,
|
If the Flux components are present on the cluster,
|
||||||
the bootstrap command will perform an upgrade if needed.`,
|
the bootstrap command will perform an upgrade if needed.`,
|
||||||
Example: ` # Create a GitLab API token and export it as an env var
|
Example: ` # Create a GitLab API token and export it as an env var
|
||||||
export GITLAB_TOKEN=<my-token>
|
export GITLAB_TOKEN=<my-token>
|
||||||
@@ -136,7 +136,9 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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()
|
||||||
@@ -178,10 +180,17 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
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{
|
||||||
@@ -215,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
|
||||||
}
|
}
|
||||||
@@ -242,23 +250,26 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
Secret: bootstrapArgs.secretName,
|
Secret: bootstrapArgs.secretName,
|
||||||
TargetPath: gitlabArgs.path.ToSlash(),
|
TargetPath: gitlabArgs.path.ToSlash(),
|
||||||
ManifestFile: sync.MakeDefaultOptions().ManifestFile,
|
ManifestFile: sync.MakeDefaultOptions().ManifestFile,
|
||||||
GitImplementation: sourceGitArgs.gitImplementation.String(),
|
|
||||||
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, kubeclientOptions),
|
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))
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ limitations under the License.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -30,10 +33,13 @@ import (
|
|||||||
var buildArtifactCmd = &cobra.Command{
|
var buildArtifactCmd = &cobra.Command{
|
||||||
Use: "artifact",
|
Use: "artifact",
|
||||||
Short: "Build artifact",
|
Short: "Build artifact",
|
||||||
Long: `The build artifact command creates a tgz file with the manifests from the given directory.`,
|
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
|
Example: ` # Build the given manifests directory into an artifact
|
||||||
flux build artifact --path ./path/to/local/manifests --output ./path/to/artifact.tgz
|
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
|
# List the files bundled in the artifact
|
||||||
tar -ztvf ./path/to/artifact.tgz
|
tar -ztvf ./path/to/artifact.tgz
|
||||||
`,
|
`,
|
||||||
@@ -51,7 +57,7 @@ var excludeOCI = append(strings.Split(sourceignore.ExcludeVCS, ","), strings.Spl
|
|||||||
var buildArtifactArgs buildArtifactFlags
|
var buildArtifactArgs buildArtifactFlags
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
buildArtifactCmd.Flags().StringVar(&buildArtifactArgs.path, "path", "", "Path to the directory where the Kubernetes manifests are located.")
|
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().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")
|
buildArtifactCmd.Flags().StringSliceVar(&buildArtifactArgs.ignorePaths, "ignore-paths", excludeOCI, "set paths to ignore in .gitignore format")
|
||||||
|
|
||||||
@@ -63,18 +69,48 @@ func buildArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return fmt.Errorf("invalid path %q", buildArtifactArgs.path)
|
return fmt.Errorf("invalid path %q", buildArtifactArgs.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fs, err := os.Stat(buildArtifactArgs.path); err != nil || !fs.IsDir() {
|
path := buildArtifactArgs.path
|
||||||
return fmt.Errorf("invalid path '%s', must point to an existing directory", buildArtifactArgs.path)
|
var err error
|
||||||
|
if buildArtifactArgs.path == "-" {
|
||||||
|
path, err = saveReaderToFile(os.Stdin)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer os.Remove(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Actionf("building artifact from %s", buildArtifactArgs.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()
|
ociClient := oci.NewLocalClient()
|
||||||
if err := ociClient.Build(buildArtifactArgs.output, buildArtifactArgs.path, buildArtifactArgs.ignorePaths); err != nil {
|
if err := ociClient.Build(buildArtifactArgs.output, path, buildArtifactArgs.ignorePaths); err != nil {
|
||||||
return fmt.Errorf("bulding artifact failed, error: %w", err)
|
return fmt.Errorf("bulding artifact failed, error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Successf("artifact created at %s", buildArtifactArgs.output)
|
logger.Successf("artifact created at %s", buildArtifactArgs.output)
|
||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
70
cmd/flux/build_artifact_test.go
Normal file
70
cmd/flux/build_artifact_test.go
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
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 (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_saveReaderToFile(t *testing.T) {
|
||||||
|
g := NewWithT(t)
|
||||||
|
|
||||||
|
testString := `apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: myapp
|
||||||
|
data:
|
||||||
|
foo: bar`
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
string string
|
||||||
|
expectErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "yaml",
|
||||||
|
string: testString,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "yaml with carriage return",
|
||||||
|
string: testString + "\r\n",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
tmpFile, err := saveReaderToFile(strings.NewReader(tt.string))
|
||||||
|
g.Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
t.Cleanup(func() { _ = os.Remove(tmpFile) })
|
||||||
|
|
||||||
|
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))
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,7 +40,11 @@ It is possible to specify a Flux kustomization file using --kustomization-file.`
|
|||||||
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
|
# 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`,
|
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,
|
||||||
}
|
}
|
||||||
@@ -48,6 +52,7 @@ flux build kustomization my-app --path ./path/to/local/manifests --kustomization
|
|||||||
type buildKsFlags struct {
|
type buildKsFlags struct {
|
||||||
kustomizationFile string
|
kustomizationFile string
|
||||||
path string
|
path string
|
||||||
|
dryRun bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var buildKsArgs buildKsFlags
|
var buildKsArgs buildKsFlags
|
||||||
@@ -55,10 +60,11 @@ 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().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)
|
||||||
}
|
}
|
||||||
@@ -72,13 +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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if buildKsArgs.dryRun && buildKsArgs.kustomizationFile == "" {
|
||||||
|
return fmt.Errorf("dry-run mode requires a kustomization file")
|
||||||
|
}
|
||||||
|
|
||||||
if buildKsArgs.kustomizationFile != "" {
|
if buildKsArgs.kustomizationFile != "" {
|
||||||
if fs, err := os.Stat(buildKsArgs.kustomizationFile); os.IsNotExist(err) || fs.IsDir() {
|
if fs, err := os.Stat(buildKsArgs.kustomizationFile); os.IsNotExist(err) || fs.IsDir() {
|
||||||
return fmt.Errorf("invalid kustomization file %q", buildKsArgs.kustomizationFile)
|
return fmt.Errorf("invalid kustomization file %q", buildKsArgs.kustomizationFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder, err := build.NewBuilder(kubeconfigArgs, kubeclientOptions, name, buildKsArgs.path, build.WithTimeout(rootArgs.timeout), build.WithKustomizationFile(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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,6 +142,12 @@ spec:
|
|||||||
resultFile: "./testdata/build-kustomization/podinfo-with-var-substitution-result.yaml",
|
resultFile: "./testdata/build-kustomization/podinfo-with-var-substitution-result.yaml",
|
||||||
assertFunc: "assertGoldenTemplateFile",
|
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{
|
tmpl := map[string]string{
|
||||||
@@ -165,8 +171,7 @@ spec:
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
t.Cleanup(func() { _ = os.Remove("./testdata/build-kustomization/podinfo.yaml") })
|
||||||
defer os.Remove("./testdata/build-kustomization/podinfo.yaml")
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|||||||
@@ -242,8 +242,9 @@ func crdsCheck() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, crd := range list.Items {
|
for _, crd := range list.Items {
|
||||||
if len(crd.Status.StoredVersions) > 0 {
|
versions := crd.Status.StoredVersions
|
||||||
logger.Successf(crd.Name + "/" + crd.Status.StoredVersions[0])
|
if len(versions) > 0 {
|
||||||
|
logger.Successf(crd.Name + "/" + versions[len(versions)-1])
|
||||||
} else {
|
} else {
|
||||||
ok = false
|
ok = false
|
||||||
logger.Failuref("no stored versions for %s", crd.Name)
|
logger.Failuref("no stored versions for %s", crd.Name)
|
||||||
|
|||||||
@@ -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(),
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if helmReleaseArgs.kubeConfigSecretRef != "" {
|
if helmReleaseArgs.kubeConfigSecretRef != "" {
|
||||||
helmRelease.Spec.KubeConfig = &helmv2.KubeConfig{
|
helmRelease.Spec.KubeConfig = &meta.KubeConfigReference{
|
||||||
SecretRef: meta.SecretKeyReference{
|
SecretRef: meta.SecretKeyReference{
|
||||||
Name: helmReleaseArgs.kubeConfigSecretRef,
|
Name: helmReleaseArgs.kubeConfigSecretRef,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fluxcd/pkg/apis/meta"
|
"github.com/fluxcd/pkg/apis/meta"
|
||||||
|
|
||||||
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var createImagePolicyCmd = &cobra.Command{
|
var createImagePolicyCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fluxcd/pkg/apis/meta"
|
"github.com/fluxcd/pkg/apis/meta"
|
||||||
|
|
||||||
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var createImageRepositoryCmd = &cobra.Command{
|
var createImageRepositoryCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if kustomizationArgs.kubeConfigSecretRef != "" {
|
if kustomizationArgs.kubeConfigSecretRef != "" {
|
||||||
kustomization.Spec.KubeConfig = &kustomizev1.KubeConfig{
|
kustomization.Spec.KubeConfig = &meta.KubeConfigReference{
|
||||||
SecretRef: meta.SecretKeyReference{
|
SecretRef: meta.SecretKeyReference{
|
||||||
Name: kustomizationArgs.kubeConfigSecretRef,
|
Name: kustomizationArgs.kubeConfigSecretRef,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ type sourceGitFlags struct {
|
|||||||
keyRSABits flags.RSAKeyBits
|
keyRSABits flags.RSAKeyBits
|
||||||
keyECDSACurve flags.ECDSACurve
|
keyECDSACurve flags.ECDSACurve
|
||||||
secretRef string
|
secretRef string
|
||||||
gitImplementation flags.GitImplementation
|
|
||||||
caFile string
|
caFile string
|
||||||
privateKeyFile string
|
privateKeyFile string
|
||||||
recurseSubmodules bool
|
recurseSubmodules bool
|
||||||
@@ -136,7 +135,6 @@ func init() {
|
|||||||
createSourceGitCmd.Flags().Var(&sourceGitArgs.keyRSABits, "ssh-rsa-bits", sourceGitArgs.keyRSABits.Description())
|
createSourceGitCmd.Flags().Var(&sourceGitArgs.keyRSABits, "ssh-rsa-bits", sourceGitArgs.keyRSABits.Description())
|
||||||
createSourceGitCmd.Flags().Var(&sourceGitArgs.keyECDSACurve, "ssh-ecdsa-curve", sourceGitArgs.keyECDSACurve.Description())
|
createSourceGitCmd.Flags().Var(&sourceGitArgs.keyECDSACurve, "ssh-ecdsa-curve", sourceGitArgs.keyECDSACurve.Description())
|
||||||
createSourceGitCmd.Flags().StringVar(&sourceGitArgs.secretRef, "secret-ref", "", "the name of an existing secret containing SSH or basic credentials")
|
createSourceGitCmd.Flags().StringVar(&sourceGitArgs.secretRef, "secret-ref", "", "the name of an existing secret containing SSH or basic credentials")
|
||||||
createSourceGitCmd.Flags().Var(&sourceGitArgs.gitImplementation, "git-implementation", sourceGitArgs.gitImplementation.Description())
|
|
||||||
createSourceGitCmd.Flags().StringVar(&sourceGitArgs.caFile, "ca-file", "", "path to TLS CA file used for validating self-signed certificates")
|
createSourceGitCmd.Flags().StringVar(&sourceGitArgs.caFile, "ca-file", "", "path to TLS CA file used for validating self-signed certificates")
|
||||||
createSourceGitCmd.Flags().StringVar(&sourceGitArgs.privateKeyFile, "private-key-file", "", "path to a passwordless private key file used for authenticating to the Git SSH server")
|
createSourceGitCmd.Flags().StringVar(&sourceGitArgs.privateKeyFile, "private-key-file", "", "path to a passwordless private key file used for authenticating to the Git SSH server")
|
||||||
createSourceGitCmd.Flags().BoolVar(&sourceGitArgs.recurseSubmodules, "recurse-submodules", false,
|
createSourceGitCmd.Flags().BoolVar(&sourceGitArgs.recurseSubmodules, "recurse-submodules", false,
|
||||||
@@ -178,10 +176,6 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return fmt.Errorf("specifying a CA file is not supported for Git over SSH")
|
return fmt.Errorf("specifying a CA file is not supported for Git over SSH")
|
||||||
}
|
}
|
||||||
|
|
||||||
if sourceGitArgs.recurseSubmodules && sourceGitArgs.gitImplementation == sourcev1.LibGit2Implementation {
|
|
||||||
return fmt.Errorf("recurse submodules requires --git-implementation=%s", sourcev1.GoGitImplementation)
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpDir, err := os.MkdirTemp("", name)
|
tmpDir, err := os.MkdirTemp("", name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -220,10 +214,6 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
gitRepository.Spec.Timeout = &metav1.Duration{Duration: createSourceArgs.fetchTimeout}
|
gitRepository.Spec.Timeout = &metav1.Duration{Duration: createSourceArgs.fetchTimeout}
|
||||||
}
|
}
|
||||||
|
|
||||||
if sourceGitArgs.gitImplementation != "" {
|
|
||||||
gitRepository.Spec.GitImplementation = sourceGitArgs.gitImplementation.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
if sourceGitArgs.semver != "" {
|
if sourceGitArgs.semver != "" {
|
||||||
gitRepository.Spec.Reference.SemVer = sourceGitArgs.semver
|
gitRepository.Spec.Reference.SemVer = sourceGitArgs.semver
|
||||||
} else if sourceGitArgs.tag != "" {
|
} else if sourceGitArgs.tag != "" {
|
||||||
@@ -259,16 +249,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
|
||||||
|
|||||||
@@ -168,6 +168,25 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
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)
|
||||||
@@ -176,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)
|
||||||
|
|||||||
@@ -38,12 +38,12 @@ func TestCreateSourceOCI(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "export manifest",
|
name: "export manifest",
|
||||||
args: "create source oci podinfo --url=oci://ghcr.io/stefanprodan/manifests/podinfo --tag=6.1.6 --interval 10m --export",
|
args: "create source oci podinfo --url=oci://ghcr.io/stefanprodan/manifests/podinfo --tag=6.3.5 --interval 10m --export",
|
||||||
assertFunc: assertGoldenFile("./testdata/oci/export.golden"),
|
assertFunc: assertGoldenFile("./testdata/oci/export.golden"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "export manifest with secret",
|
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",
|
args: "create source oci podinfo --url=oci://ghcr.io/stefanprodan/manifests/podinfo --tag=6.3.5 --interval 10m --secret-ref=creds --export",
|
||||||
assertFunc: assertGoldenFile("./testdata/oci/export_with_secret.golden"),
|
assertFunc: assertGoldenFile("./testdata/oci/export_with_secret.golden"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var deleteImagePolicyCmd = &cobra.Command{
|
var deleteImagePolicyCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var deleteImageRepositoryCmd = &cobra.Command{
|
var deleteImageRepositoryCmd = &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 deleteReceiverCmd = &cobra.Command{
|
var deleteReceiverCmd = &cobra.Command{
|
||||||
|
|||||||
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -77,12 +77,21 @@ func diffKsCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var builder *build.Builder
|
var (
|
||||||
var err error
|
builder *build.Builder
|
||||||
|
err error
|
||||||
|
)
|
||||||
if diffKsArgs.progressBar {
|
if diffKsArgs.progressBar {
|
||||||
builder, err = build.NewBuilder(kubeconfigArgs, kubeclientOptions, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout), build.WithKustomizationFile(diffKsArgs.kustomizationFile), 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, kubeclientOptions, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout), build.WithKustomizationFile(diffKsArgs.kustomizationFile))
|
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, kubeclientOptions, "podinfo", "")
|
b, _ := build.NewBuilder("podinfo", "", build.WithClientConfig(kubeconfigArgs, kubeclientOptions))
|
||||||
|
|
||||||
resourceManager, err := b.Manager()
|
resourceManager, err := b.Manager()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -109,7 +109,9 @@ func TestDiffKustomization(t *testing.T) {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if tt.objectFile != "" {
|
if tt.objectFile != "" {
|
||||||
resourceManager.ApplyAll(context.Background(), createObjectFromFile(tt.objectFile, tmpl, t), ssa.DefaultApplyOptions())
|
if _, err := resourceManager.ApplyAll(context.Background(), createObjectFromFile(tt.objectFile, tmpl, t), ssa.DefaultApplyOptions()); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cmd := cmdTestCase{
|
cmd := cmdTestCase{
|
||||||
args: tt.args + " -n " + tmpl["fluxns"],
|
args: tt.args + " -n " + tmpl["fluxns"],
|
||||||
|
|||||||
499
cmd/flux/events.go
Normal file
499
cmd/flux/events.go
Normal file
@@ -0,0 +1,499 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2023 The Kubernetes Authors.
|
||||||
|
Copyright 2023 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"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
|
"k8s.io/apimachinery/pkg/fields"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"k8s.io/apimachinery/pkg/util/duration"
|
||||||
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
|
runtimeresource "k8s.io/cli-runtime/pkg/resource"
|
||||||
|
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
|
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
|
||||||
|
autov1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
|
||||||
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
|
||||||
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||||
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/printers"
|
||||||
|
)
|
||||||
|
|
||||||
|
var eventsCmd = &cobra.Command{
|
||||||
|
Use: "events",
|
||||||
|
Short: "Display Kubernetes events for Flux resources",
|
||||||
|
Long: "The events sub-command shows Kubernetes events from Flux resources",
|
||||||
|
Example: ` # Display events for flux resources in default namespace
|
||||||
|
flux events -n default
|
||||||
|
|
||||||
|
# Display events for flux resources in all namespaces
|
||||||
|
flux events -A
|
||||||
|
|
||||||
|
# Display events for flux resources
|
||||||
|
flux events --for Kustomization/podinfo
|
||||||
|
`,
|
||||||
|
RunE: eventsCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
type eventFlags struct {
|
||||||
|
allNamespaces bool
|
||||||
|
watch bool
|
||||||
|
forSelector string
|
||||||
|
filterTypes []string
|
||||||
|
}
|
||||||
|
|
||||||
|
var eventArgs eventFlags
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
eventsCmd.Flags().BoolVarP(&eventArgs.allNamespaces, "all-namespaces", "A", false,
|
||||||
|
"display events from Flux resources across all namespaces")
|
||||||
|
eventsCmd.Flags().BoolVarP(&eventArgs.watch, "watch", "w", false,
|
||||||
|
"indicate if the events should be streamed")
|
||||||
|
eventsCmd.Flags().StringVar(&eventArgs.forSelector, "for", "",
|
||||||
|
"get events for a particular object")
|
||||||
|
eventsCmd.Flags().StringSliceVar(&eventArgs.filterTypes, "types", []string{}, "filter events for certain types")
|
||||||
|
rootCmd.AddCommand(eventsCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func eventsCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
kubeclient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace := *kubeconfigArgs.Namespace
|
||||||
|
if eventArgs.allNamespaces {
|
||||||
|
namespace = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
var diffRefNs bool
|
||||||
|
clientListOpts := getListOpt(namespace, eventArgs.forSelector)
|
||||||
|
var refListOpts [][]client.ListOption
|
||||||
|
if eventArgs.forSelector != "" {
|
||||||
|
refs, err := getObjectRef(ctx, kubeclient, eventArgs.forSelector, *kubeconfigArgs.Namespace)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ref := range refs {
|
||||||
|
kind, name, refNs := utils.ParseObjectKindNameNamespace(ref)
|
||||||
|
if refNs != namespace {
|
||||||
|
diffRefNs = true
|
||||||
|
}
|
||||||
|
refSelector := fmt.Sprintf("%s/%s", kind, name)
|
||||||
|
refListOpts = append(refListOpts, getListOpt(refNs, refSelector))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
showNamespace := namespace == "" || diffRefNs
|
||||||
|
if eventArgs.watch {
|
||||||
|
return eventsCmdWatchRun(ctx, kubeclient, clientListOpts, refListOpts, showNamespace)
|
||||||
|
}
|
||||||
|
|
||||||
|
rows, err := getRows(ctx, kubeclient, clientListOpts, refListOpts, showNamespace)
|
||||||
|
if len(rows) == 0 {
|
||||||
|
if eventArgs.allNamespaces {
|
||||||
|
logger.Failuref("No events found.")
|
||||||
|
} else {
|
||||||
|
logger.Failuref("No events found in %s namespace.", *kubeconfigArgs.Namespace)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
headers := getHeaders(showNamespace)
|
||||||
|
err = printers.TablePrinter(headers).Print(cmd.OutOrStdout(), rows)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRows(ctx context.Context, kubeclient client.Client, clientListOpts []client.ListOption, refListOpts [][]client.ListOption, showNs bool) ([][]string, error) {
|
||||||
|
el := &corev1.EventList{}
|
||||||
|
if err := addEventsToList(ctx, kubeclient, el, clientListOpts); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, refOpts := range refListOpts {
|
||||||
|
if err := addEventsToList(ctx, kubeclient, el, refOpts); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Sort(SortableEvents(el.Items))
|
||||||
|
|
||||||
|
var rows [][]string
|
||||||
|
for _, item := range el.Items {
|
||||||
|
if ignoreEvent(item) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
rows = append(rows, getEventRow(item, showNs))
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func addEventsToList(ctx context.Context, kubeclient client.Client, el *corev1.EventList, clientListOpts []client.ListOption) error {
|
||||||
|
listOpts := &metav1.ListOptions{}
|
||||||
|
err := runtimeresource.FollowContinue(listOpts,
|
||||||
|
func(options metav1.ListOptions) (runtime.Object, error) {
|
||||||
|
newEvents := &corev1.EventList{}
|
||||||
|
err := kubeclient.List(ctx, newEvents, clientListOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting events: %w", err)
|
||||||
|
}
|
||||||
|
el.Items = append(el.Items, newEvents.Items...)
|
||||||
|
return newEvents, nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func getListOpt(namespace, selector string) []client.ListOption {
|
||||||
|
clientListOpts := []client.ListOption{client.Limit(cmdutil.DefaultChunkSize), client.InNamespace(namespace)}
|
||||||
|
if selector != "" {
|
||||||
|
kind, name := utils.ParseObjectKindName(selector)
|
||||||
|
sel := fields.AndSelectors(
|
||||||
|
fields.OneTermEqualSelector("involvedObject.kind", kind),
|
||||||
|
fields.OneTermEqualSelector("involvedObject.name", name))
|
||||||
|
clientListOpts = append(clientListOpts, client.MatchingFieldsSelector{Selector: sel})
|
||||||
|
}
|
||||||
|
|
||||||
|
return clientListOpts
|
||||||
|
}
|
||||||
|
|
||||||
|
func eventsCmdWatchRun(ctx context.Context, kubeclient client.WithWatch, listOpts []client.ListOption, refListOpts [][]client.ListOption, showNs bool) error {
|
||||||
|
event := &corev1.EventList{}
|
||||||
|
eventWatch, err := kubeclient.Watch(ctx, event, listOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
firstIteration := true
|
||||||
|
|
||||||
|
handleEvent := func(e watch.Event) error {
|
||||||
|
if e.Type == watch.Deleted {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
event, ok := e.Object.(*corev1.Event)
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if ignoreEvent(*event) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
rows := getEventRow(*event, showNs)
|
||||||
|
var hdr []string
|
||||||
|
if firstIteration {
|
||||||
|
hdr = getHeaders(showNs)
|
||||||
|
firstIteration = false
|
||||||
|
}
|
||||||
|
err = printers.TablePrinter(hdr).Print(os.Stdout, [][]string{rows})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, refOpts := range refListOpts {
|
||||||
|
refEventWatch, err := kubeclient.Watch(ctx, event, refOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
err := receiveEventChan(ctx, refEventWatch, handleEvent)
|
||||||
|
if err != nil {
|
||||||
|
logger.Failuref("error watching events: %s", err.Error())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
return receiveEventChan(ctx, eventWatch, handleEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func receiveEventChan(ctx context.Context, eventWatch watch.Interface, f func(e watch.Event) error) error {
|
||||||
|
defer eventWatch.Stop()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case e, ok := <-eventWatch.ResultChan():
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
err := f(e)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getHeaders(showNs bool) []string {
|
||||||
|
headers := []string{"Last seen", "Type", "Reason", "Object", "Message"}
|
||||||
|
if showNs {
|
||||||
|
headers = append(namespaceHeader, headers...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return headers
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEventRow(e corev1.Event, showNs bool) []string {
|
||||||
|
var row []string
|
||||||
|
if showNs {
|
||||||
|
row = []string{e.Namespace}
|
||||||
|
}
|
||||||
|
row = append(row, getLastSeen(e), e.Type, e.Reason, fmt.Sprintf("%s/%s", e.InvolvedObject.Kind, e.InvolvedObject.Name), e.Message)
|
||||||
|
|
||||||
|
return row
|
||||||
|
}
|
||||||
|
|
||||||
|
// getObjectRef is used to get the metadata of a resource that the selector(in the format <kind/name>) references.
|
||||||
|
// It returns an empty string if the resource doesn't reference any resource
|
||||||
|
// and a string with the format `<kind>/<name>.<namespace>` if it does.
|
||||||
|
func getObjectRef(ctx context.Context, kubeclient client.Client, selector string, ns string) ([]string, error) {
|
||||||
|
kind, name := utils.ParseObjectKindName(selector)
|
||||||
|
ref, err := fluxKindMap.getRefInfo(kind)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting groupversion: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// the resource has no source ref
|
||||||
|
if len(ref.field) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
obj := &unstructured.Unstructured{}
|
||||||
|
obj.SetGroupVersionKind(schema.GroupVersionKind{
|
||||||
|
Kind: kind,
|
||||||
|
Version: ref.gv.Version,
|
||||||
|
Group: ref.gv.Group,
|
||||||
|
})
|
||||||
|
objName := types.NamespacedName{
|
||||||
|
Namespace: ns,
|
||||||
|
Name: name,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = kubeclient.Get(ctx, objName, obj)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var ok bool
|
||||||
|
refKind := ref.kind
|
||||||
|
if refKind == "" {
|
||||||
|
kindField := append(ref.field, "kind")
|
||||||
|
refKind, ok, err = unstructured.NestedString(obj.Object, kindField...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("field '%s' for '%s' not found", strings.Join(kindField, "."), objName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nameField := append(ref.field, "name")
|
||||||
|
refName, ok, err := unstructured.NestedString(obj.Object, nameField...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("field '%s' for '%s' not found", strings.Join(nameField, "."), objName)
|
||||||
|
}
|
||||||
|
|
||||||
|
var allRefs []string
|
||||||
|
refNamespace := ns
|
||||||
|
if ref.crossNamespaced {
|
||||||
|
namespaceField := append(ref.field, "namespace")
|
||||||
|
namespace, ok, err := unstructured.NestedString(obj.Object, namespaceField...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
refNamespace = namespace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allRefs = append(allRefs, fmt.Sprintf("%s/%s.%s", refKind, refName, refNamespace))
|
||||||
|
if ref.otherRefs != nil {
|
||||||
|
for _, otherRef := range ref.otherRefs(ns, name) {
|
||||||
|
allRefs = append(allRefs, fmt.Sprintf("%s.%s", otherRef, refNamespace))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return allRefs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type refMap map[string]refInfo
|
||||||
|
|
||||||
|
func (r refMap) getRefInfo(kind string) (refInfo, error) {
|
||||||
|
for key, ref := range r {
|
||||||
|
if strings.EqualFold(key, kind) {
|
||||||
|
return ref, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return refInfo{}, fmt.Errorf("'%s' is not a recognized Flux kind", kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r refMap) hasKind(kind string) bool {
|
||||||
|
_, err := r.getRefInfo(kind)
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type refInfo struct {
|
||||||
|
gv schema.GroupVersion
|
||||||
|
kind string
|
||||||
|
crossNamespaced bool
|
||||||
|
otherRefs func(namespace, name string) []string
|
||||||
|
field []string
|
||||||
|
}
|
||||||
|
|
||||||
|
var fluxKindMap = refMap{
|
||||||
|
kustomizev1.KustomizationKind: {
|
||||||
|
gv: kustomizev1.GroupVersion,
|
||||||
|
crossNamespaced: true,
|
||||||
|
field: []string{"spec", "sourceRef"},
|
||||||
|
},
|
||||||
|
helmv2.HelmReleaseKind: {
|
||||||
|
gv: helmv2.GroupVersion,
|
||||||
|
crossNamespaced: true,
|
||||||
|
otherRefs: func(namespace, name string) []string {
|
||||||
|
return []string{fmt.Sprintf("%s/%s-%s", sourcev1.HelmChartKind, namespace, name)}
|
||||||
|
},
|
||||||
|
field: []string{"spec", "chart", "spec", "sourceRef"},
|
||||||
|
},
|
||||||
|
notificationv1.AlertKind: {
|
||||||
|
gv: notificationv1.GroupVersion,
|
||||||
|
kind: notificationv1.ProviderKind,
|
||||||
|
crossNamespaced: false,
|
||||||
|
field: []string{"spec", "providerRef"},
|
||||||
|
},
|
||||||
|
notificationv1.ReceiverKind: {gv: notificationv1.GroupVersion},
|
||||||
|
notificationv1.ProviderKind: {gv: notificationv1.GroupVersion},
|
||||||
|
imagev1.ImagePolicyKind: {
|
||||||
|
gv: imagev1.GroupVersion,
|
||||||
|
kind: imagev1.ImageRepositoryKind,
|
||||||
|
crossNamespaced: true,
|
||||||
|
field: []string{"spec", "imageRepositoryRef"},
|
||||||
|
},
|
||||||
|
sourcev1.GitRepositoryKind: {gv: sourcev1.GroupVersion},
|
||||||
|
sourcev1.OCIRepositoryKind: {gv: sourcev1.GroupVersion},
|
||||||
|
sourcev1.BucketKind: {gv: sourcev1.GroupVersion},
|
||||||
|
sourcev1.HelmRepositoryKind: {gv: sourcev1.GroupVersion},
|
||||||
|
sourcev1.HelmChartKind: {gv: sourcev1.GroupVersion},
|
||||||
|
autov1.ImageUpdateAutomationKind: {gv: autov1.GroupVersion},
|
||||||
|
imagev1.ImageRepositoryKind: {gv: imagev1.GroupVersion},
|
||||||
|
}
|
||||||
|
|
||||||
|
func ignoreEvent(e corev1.Event) bool {
|
||||||
|
if !fluxKindMap.hasKind(e.InvolvedObject.Kind) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(eventArgs.filterTypes) > 0 {
|
||||||
|
_, equal := utils.ContainsEqualFoldItemString(eventArgs.filterTypes, e.Type)
|
||||||
|
if !equal {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// The functions below are copied from: https://github.com/kubernetes/kubectl/blob/master/pkg/cmd/events/events.go#L347
|
||||||
|
|
||||||
|
// SortableEvents implements sort.Interface for []api.Event by time
|
||||||
|
type SortableEvents []corev1.Event
|
||||||
|
|
||||||
|
func (list SortableEvents) Len() int {
|
||||||
|
return len(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (list SortableEvents) Swap(i, j int) {
|
||||||
|
list[i], list[j] = list[j], list[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the time that should be used for sorting, which can come from
|
||||||
|
// various places in corev1.Event.
|
||||||
|
func eventTime(event corev1.Event) time.Time {
|
||||||
|
if event.Series != nil {
|
||||||
|
return event.Series.LastObservedTime.Time
|
||||||
|
}
|
||||||
|
if !event.LastTimestamp.Time.IsZero() {
|
||||||
|
return event.LastTimestamp.Time
|
||||||
|
}
|
||||||
|
return event.EventTime.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func (list SortableEvents) Less(i, j int) bool {
|
||||||
|
return eventTime(list[i]).Before(eventTime(list[j]))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLastSeen(e corev1.Event) string {
|
||||||
|
var interval string
|
||||||
|
firstTimestampSince := translateMicroTimestampSince(e.EventTime)
|
||||||
|
if e.EventTime.IsZero() {
|
||||||
|
firstTimestampSince = translateTimestampSince(e.FirstTimestamp)
|
||||||
|
}
|
||||||
|
if e.Series != nil {
|
||||||
|
interval = fmt.Sprintf("%s (x%d over %s)", translateMicroTimestampSince(e.Series.LastObservedTime), e.Series.Count, firstTimestampSince)
|
||||||
|
} else if e.Count > 1 {
|
||||||
|
interval = fmt.Sprintf("%s (x%d over %s)", translateTimestampSince(e.LastTimestamp), e.Count, firstTimestampSince)
|
||||||
|
} else {
|
||||||
|
interval = firstTimestampSince
|
||||||
|
}
|
||||||
|
|
||||||
|
return interval
|
||||||
|
}
|
||||||
|
|
||||||
|
// translateMicroTimestampSince returns the elapsed time since timestamp in
|
||||||
|
// human-readable approximation.
|
||||||
|
func translateMicroTimestampSince(timestamp metav1.MicroTime) string {
|
||||||
|
if timestamp.IsZero() {
|
||||||
|
return "<unknown>"
|
||||||
|
}
|
||||||
|
|
||||||
|
return duration.HumanDuration(time.Since(timestamp.Time))
|
||||||
|
}
|
||||||
|
|
||||||
|
// translateTimestampSince returns the elapsed time since timestamp in
|
||||||
|
// human-readable approximation.
|
||||||
|
func translateTimestampSince(timestamp metav1.Time) string {
|
||||||
|
if timestamp.IsZero() {
|
||||||
|
return "<unknown>"
|
||||||
|
}
|
||||||
|
|
||||||
|
return duration.HumanDuration(time.Since(timestamp.Time))
|
||||||
|
}
|
||||||
411
cmd/flux/events_test.go
Normal file
411
cmd/flux/events_test.go
Normal file
@@ -0,0 +1,411 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2023 The Kubernetes Authors.
|
||||||
|
Copyright 2023 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"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
helmv2beta1 "github.com/fluxcd/helm-controller/api/v2beta1"
|
||||||
|
autov1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
|
||||||
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
|
||||||
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||||
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
|
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
|
||||||
|
"github.com/fluxcd/pkg/ssa"
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/fields"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||||
|
)
|
||||||
|
|
||||||
|
var objects = `
|
||||||
|
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: Kustomization
|
||||||
|
metadata:
|
||||||
|
name: flux-system
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
interval: 5m0s
|
||||||
|
path: ./infrastructure/
|
||||||
|
prune: true
|
||||||
|
sourceRef:
|
||||||
|
kind: GitRepository
|
||||||
|
name: flux-system
|
||||||
|
---
|
||||||
|
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: Kustomization
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
interval: 5m0s
|
||||||
|
path: ./infrastructure/
|
||||||
|
prune: true
|
||||||
|
sourceRef:
|
||||||
|
kind: GitRepository
|
||||||
|
name: flux-system
|
||||||
|
namespace: flux-system
|
||||||
|
---
|
||||||
|
apiVersion: source.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: GitRepository
|
||||||
|
metadata:
|
||||||
|
name: flux-system
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
interval: 5m0s
|
||||||
|
ref:
|
||||||
|
branch: main
|
||||||
|
secretRef:
|
||||||
|
name: flux-system
|
||||||
|
timeout: 1m0s
|
||||||
|
url: ssh://git@github.com/example/repo
|
||||||
|
---
|
||||||
|
apiVersion: helm.toolkit.fluxcd.io/v2beta1
|
||||||
|
kind: HelmRelease
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
chart:
|
||||||
|
spec:
|
||||||
|
chart: podinfo
|
||||||
|
reconcileStrategy: ChartVersion
|
||||||
|
sourceRef:
|
||||||
|
kind: HelmRepository
|
||||||
|
name: podinfo
|
||||||
|
namespace: flux-system
|
||||||
|
version: '*'
|
||||||
|
interval: 5m0s
|
||||||
|
---
|
||||||
|
apiVersion: source.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: HelmRepository
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
interval: 1m0s
|
||||||
|
url: https://stefanprodan.github.io/podinfo
|
||||||
|
---
|
||||||
|
apiVersion: source.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: HelmChart
|
||||||
|
metadata:
|
||||||
|
name: default-podinfo
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
chart: podinfo
|
||||||
|
interval: 1m0s
|
||||||
|
reconcileStrategy: ChartVersion
|
||||||
|
sourceRef:
|
||||||
|
kind: HelmRepository
|
||||||
|
name: podinfo-chart
|
||||||
|
version: '*'
|
||||||
|
---
|
||||||
|
apiVersion: notification.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: Alert
|
||||||
|
metadata:
|
||||||
|
name: webapp
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
eventSeverity: info
|
||||||
|
eventSources:
|
||||||
|
- kind: GitRepository
|
||||||
|
name: '*'
|
||||||
|
providerRef:
|
||||||
|
name: slack
|
||||||
|
---
|
||||||
|
apiVersion: notification.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: Provider
|
||||||
|
metadata:
|
||||||
|
name: slack
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
address: https://hooks.slack.com/services/mock
|
||||||
|
type: slack
|
||||||
|
---
|
||||||
|
apiVersion: image.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: ImagePolicy
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
imageRepositoryRef:
|
||||||
|
name: acr-podinfo
|
||||||
|
namespace: flux-system
|
||||||
|
policy:
|
||||||
|
semver:
|
||||||
|
range: 5.0.x
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: flux-system`
|
||||||
|
|
||||||
|
func Test_getObjectRef(t *testing.T) {
|
||||||
|
g := NewWithT(t)
|
||||||
|
objs, err := ssa.ReadObjects(strings.NewReader(objects))
|
||||||
|
g.Expect(err).To(Not(HaveOccurred()))
|
||||||
|
|
||||||
|
builder := fake.NewClientBuilder().WithScheme(getScheme())
|
||||||
|
for _, obj := range objs {
|
||||||
|
builder = builder.WithObjects(obj)
|
||||||
|
}
|
||||||
|
c := builder.Build()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
selector string
|
||||||
|
namespace string
|
||||||
|
want []string
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Source Ref for Kustomization",
|
||||||
|
selector: "Kustomization/flux-system",
|
||||||
|
namespace: "flux-system",
|
||||||
|
want: []string{"GitRepository/flux-system.flux-system"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Crossnamespace Source Ref for Kustomization",
|
||||||
|
selector: "Kustomization/podinfo",
|
||||||
|
namespace: "default",
|
||||||
|
want: []string{"GitRepository/flux-system.flux-system"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Source Ref for HelmRelease",
|
||||||
|
selector: "HelmRelease/podinfo",
|
||||||
|
namespace: "default",
|
||||||
|
want: []string{"HelmRepository/podinfo.flux-system", "HelmChart/default-podinfo.flux-system"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Source Ref for Alert",
|
||||||
|
selector: "Alert/webapp",
|
||||||
|
namespace: "flux-system",
|
||||||
|
want: []string{"Provider/slack.flux-system"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Source Ref for ImagePolicy",
|
||||||
|
selector: "ImagePolicy/podinfo",
|
||||||
|
namespace: "default",
|
||||||
|
want: []string{"ImageRepository/acr-podinfo.flux-system"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Empty Ref for Provider",
|
||||||
|
selector: "Provider/slack",
|
||||||
|
namespace: "flux-system",
|
||||||
|
want: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Non flux resource",
|
||||||
|
selector: "Namespace/flux-system",
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
g := NewWithT(t)
|
||||||
|
got, err := getObjectRef(context.Background(), c, tt.selector, tt.namespace)
|
||||||
|
if tt.wantErr {
|
||||||
|
g.Expect(err).To(HaveOccurred())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
g.Expect(err).To(Not(HaveOccurred()))
|
||||||
|
g.Expect(got).To(Equal(tt.want))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_getRows(t *testing.T) {
|
||||||
|
g := NewWithT(t)
|
||||||
|
objs, err := ssa.ReadObjects(strings.NewReader(objects))
|
||||||
|
g.Expect(err).To(Not(HaveOccurred()))
|
||||||
|
|
||||||
|
builder := fake.NewClientBuilder().WithScheme(getScheme())
|
||||||
|
for _, obj := range objs {
|
||||||
|
builder = builder.WithObjects(obj)
|
||||||
|
}
|
||||||
|
eventList := &corev1.EventList{}
|
||||||
|
for _, obj := range objs {
|
||||||
|
infoEvent := createEvent(obj, eventv1.EventSeverityInfo, "Info Message", "Info Reason")
|
||||||
|
warningEvent := createEvent(obj, eventv1.EventSeverityError, "Error Message", "Error Reason")
|
||||||
|
eventList.Items = append(eventList.Items, infoEvent, warningEvent)
|
||||||
|
}
|
||||||
|
builder = builder.WithLists(eventList)
|
||||||
|
builder.WithIndex(&corev1.Event{}, "involvedObject.kind/name", kindNameIndexer)
|
||||||
|
c := builder.Build()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
selector string
|
||||||
|
refSelector string
|
||||||
|
namespace string
|
||||||
|
refNs string
|
||||||
|
expected [][]string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "events from all namespaces",
|
||||||
|
selector: "",
|
||||||
|
namespace: "",
|
||||||
|
expected: [][]string{
|
||||||
|
{"default", "<unknown>", "error", "Error Reason", "HelmRelease/podinfo", "Error Message"},
|
||||||
|
{"default", "<unknown>", "info", "Info Reason", "HelmRelease/podinfo", "Info Message"},
|
||||||
|
{"default", "<unknown>", "error", "Error Reason", "ImagePolicy/podinfo", "Error Message"},
|
||||||
|
{"default", "<unknown>", "info", "Info Reason", "ImagePolicy/podinfo", "Info Message"},
|
||||||
|
{"default", "<unknown>", "error", "Error Reason", "Kustomization/podinfo", "Error Message"},
|
||||||
|
{"default", "<unknown>", "info", "Info Reason", "Kustomization/podinfo", "Info Message"},
|
||||||
|
{"flux-system", "<unknown>", "error", "Error Reason", "Alert/webapp", "Error Message"},
|
||||||
|
{"flux-system", "<unknown>", "info", "Info Reason", "Alert/webapp", "Info Message"},
|
||||||
|
{"flux-system", "<unknown>", "error", "Error Reason", "GitRepository/flux-system", "Error Message"},
|
||||||
|
{"flux-system", "<unknown>", "info", "Info Reason", "GitRepository/flux-system", "Info Message"},
|
||||||
|
{"flux-system", "<unknown>", "error", "Error Reason", "HelmChart/default-podinfo", "Error Message"},
|
||||||
|
{"flux-system", "<unknown>", "info", "Info Reason", "HelmChart/default-podinfo", "Info Message"},
|
||||||
|
{"flux-system", "<unknown>", "error", "Error Reason", "HelmRepository/podinfo", "Error Message"},
|
||||||
|
{"flux-system", "<unknown>", "info", "Info Reason", "HelmRepository/podinfo", "Info Message"},
|
||||||
|
{"flux-system", "<unknown>", "error", "Error Reason", "Kustomization/flux-system", "Error Message"},
|
||||||
|
{"flux-system", "<unknown>", "info", "Info Reason", "Kustomization/flux-system", "Info Message"},
|
||||||
|
{"flux-system", "<unknown>", "error", "Error Reason", "Provider/slack", "Error Message"},
|
||||||
|
{"flux-system", "<unknown>", "info", "Info Reason", "Provider/slack", "Info Message"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "events from default namespaces",
|
||||||
|
selector: "",
|
||||||
|
namespace: "default",
|
||||||
|
expected: [][]string{
|
||||||
|
{"<unknown>", "error", "Error Reason", "HelmRelease/podinfo", "Error Message"},
|
||||||
|
{"<unknown>", "info", "Info Reason", "HelmRelease/podinfo", "Info Message"},
|
||||||
|
{"<unknown>", "error", "Error Reason", "ImagePolicy/podinfo", "Error Message"},
|
||||||
|
{"<unknown>", "info", "Info Reason", "ImagePolicy/podinfo", "Info Message"},
|
||||||
|
{"<unknown>", "error", "Error Reason", "Kustomization/podinfo", "Error Message"},
|
||||||
|
{"<unknown>", "info", "Info Reason", "Kustomization/podinfo", "Info Message"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Kustomization with crossnamespaced GitRepository",
|
||||||
|
selector: "Kustomization/podinfo",
|
||||||
|
namespace: "default",
|
||||||
|
expected: [][]string{
|
||||||
|
{"default", "<unknown>", "error", "Error Reason", "Kustomization/podinfo", "Error Message"},
|
||||||
|
{"default", "<unknown>", "info", "Info Reason", "Kustomization/podinfo", "Info Message"},
|
||||||
|
{"flux-system", "<unknown>", "error", "Error Reason", "GitRepository/flux-system", "Error Message"},
|
||||||
|
{"flux-system", "<unknown>", "info", "Info Reason", "GitRepository/flux-system", "Info Message"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "HelmRelease with crossnamespaced HelmRepository",
|
||||||
|
selector: "HelmRelease/podinfo",
|
||||||
|
namespace: "default",
|
||||||
|
expected: [][]string{
|
||||||
|
{"default", "<unknown>", "error", "Error Reason", "HelmRelease/podinfo", "Error Message"},
|
||||||
|
{"default", "<unknown>", "info", "Info Reason", "HelmRelease/podinfo", "Info Message"},
|
||||||
|
{"flux-system", "<unknown>", "error", "Error Reason", "HelmRepository/podinfo", "Error Message"},
|
||||||
|
{"flux-system", "<unknown>", "info", "Info Reason", "HelmRepository/podinfo", "Info Message"},
|
||||||
|
{"flux-system", "<unknown>", "error", "Error Reason", "HelmChart/default-podinfo", "Error Message"},
|
||||||
|
{"flux-system", "<unknown>", "info", "Info Reason", "HelmChart/default-podinfo", "Info Message"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
g := NewWithT(t)
|
||||||
|
|
||||||
|
var refs []string
|
||||||
|
var refNs, refKind, refName string
|
||||||
|
if tt.selector != "" {
|
||||||
|
refs, err = getObjectRef(context.Background(), c, tt.selector, tt.namespace)
|
||||||
|
g.Expect(err).To(Not(HaveOccurred()))
|
||||||
|
}
|
||||||
|
|
||||||
|
g.Expect(err).To(Not(HaveOccurred()))
|
||||||
|
|
||||||
|
clientOpts := getTestListOpt(tt.namespace, tt.selector)
|
||||||
|
var refOpts [][]client.ListOption
|
||||||
|
for _, ref := range refs {
|
||||||
|
refKind, refName, refNs = utils.ParseObjectKindNameNamespace(ref)
|
||||||
|
refSelector := fmt.Sprintf("%s/%s", refKind, refName)
|
||||||
|
refOpts = append(refOpts, getTestListOpt(refNs, refSelector))
|
||||||
|
}
|
||||||
|
|
||||||
|
showNs := tt.namespace == "" || (refNs != "" && refNs != tt.namespace)
|
||||||
|
rows, err := getRows(context.Background(), c, clientOpts, refOpts, showNs)
|
||||||
|
g.Expect(err).To(Not(HaveOccurred()))
|
||||||
|
g.Expect(rows).To(Equal(tt.expected))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTestListOpt(namespace, selector string) []client.ListOption {
|
||||||
|
clientListOpts := []client.ListOption{client.Limit(cmdutil.DefaultChunkSize), client.InNamespace(namespace)}
|
||||||
|
if selector != "" {
|
||||||
|
sel := fields.OneTermEqualSelector("involvedObject.kind/name", selector)
|
||||||
|
clientListOpts = append(clientListOpts, client.MatchingFieldsSelector{Selector: sel})
|
||||||
|
}
|
||||||
|
|
||||||
|
return clientListOpts
|
||||||
|
}
|
||||||
|
|
||||||
|
func getScheme() *runtime.Scheme {
|
||||||
|
newscheme := runtime.NewScheme()
|
||||||
|
corev1.AddToScheme(newscheme)
|
||||||
|
kustomizev1.AddToScheme(newscheme)
|
||||||
|
helmv2beta1.AddToScheme(newscheme)
|
||||||
|
notificationv1.AddToScheme(newscheme)
|
||||||
|
imagev1.AddToScheme(newscheme)
|
||||||
|
autov1.AddToScheme(newscheme)
|
||||||
|
sourcev1.AddToScheme(newscheme)
|
||||||
|
|
||||||
|
return newscheme
|
||||||
|
}
|
||||||
|
|
||||||
|
func createEvent(obj client.Object, eventType, msg, reason string) corev1.Event {
|
||||||
|
return corev1.Event{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Namespace: obj.GetNamespace(),
|
||||||
|
// name of event needs to be unique so fak
|
||||||
|
Name: obj.GetNamespace() + obj.GetNamespace() + obj.GetObjectKind().GroupVersionKind().Kind + eventType,
|
||||||
|
},
|
||||||
|
Reason: reason,
|
||||||
|
Message: msg,
|
||||||
|
Type: eventType,
|
||||||
|
InvolvedObject: corev1.ObjectReference{
|
||||||
|
Kind: obj.GetObjectKind().GroupVersionKind().Kind,
|
||||||
|
Namespace: obj.GetNamespace(),
|
||||||
|
Name: obj.GetName(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func kindNameIndexer(obj client.Object) []string {
|
||||||
|
e, ok := obj.(*corev1.Event)
|
||||||
|
if !ok {
|
||||||
|
panic(fmt.Sprintf("Expected a Event, got %T", e))
|
||||||
|
}
|
||||||
|
|
||||||
|
return []string{fmt.Sprintf("%s/%s", e.InvolvedObject.Kind, e.InvolvedObject.Name)}
|
||||||
|
}
|
||||||
@@ -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"
|
||||||
|
|
||||||
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var exportImagePolicyCmd = &cobra.Command{
|
var exportImagePolicyCmd = &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"
|
||||||
|
|
||||||
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var exportImageRepositoryCmd = &cobra.Command{
|
var exportImageRepositoryCmd = &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{
|
||||||
|
|||||||
@@ -8,78 +8,92 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestExport(t *testing.T) {
|
func TestExport(t *testing.T) {
|
||||||
|
namespace := allocateNamespace("flux-system")
|
||||||
|
|
||||||
|
objectFile := "testdata/export/objects.yaml"
|
||||||
|
tmpl := map[string]string{
|
||||||
|
"fluxns": namespace,
|
||||||
|
}
|
||||||
|
testEnv.CreateObjectFile(objectFile, tmpl, t)
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
arg string
|
arg string
|
||||||
goldenFile string
|
goldenFile string
|
||||||
|
tmpl map[string]string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"alert-provider",
|
"alert-provider",
|
||||||
"export alert-provider slack",
|
"export alert-provider slack",
|
||||||
"testdata/export/provider.yaml",
|
"testdata/export/provider.yaml",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"alert",
|
"alert",
|
||||||
"export alert flux-system",
|
"export alert flux-system",
|
||||||
"testdata/export/alert.yaml",
|
"testdata/export/alert.yaml",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"image policy",
|
"image policy",
|
||||||
"export image policy flux-system",
|
"export image policy flux-system",
|
||||||
"testdata/export/image-policy.yaml",
|
"testdata/export/image-policy.yaml",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"image repository",
|
"image repository",
|
||||||
"export image repository flux-system",
|
"export image repository flux-system",
|
||||||
"testdata/export/image-repo.yaml",
|
"testdata/export/image-repo.yaml",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"image update",
|
"image update",
|
||||||
"export image update flux-system",
|
"export image update flux-system",
|
||||||
"testdata/export/image-update.yaml",
|
"testdata/export/image-update.yaml",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"source git",
|
"source git",
|
||||||
"export source git flux-system",
|
"export source git flux-system",
|
||||||
"testdata/export/git-repo.yaml",
|
"testdata/export/git-repo.yaml",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"source helm",
|
"source helm",
|
||||||
"export source helm flux-system",
|
"export source helm flux-system",
|
||||||
"testdata/export/helm-repo.yaml",
|
"testdata/export/helm-repo.yaml",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"receiver",
|
"receiver",
|
||||||
"export receiver flux-system",
|
"export receiver flux-system",
|
||||||
"testdata/export/receiver.yaml",
|
"testdata/export/receiver.yaml",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"kustomization",
|
"kustomization",
|
||||||
"export kustomization flux-system",
|
"export kustomization flux-system",
|
||||||
"testdata/export/ks.yaml",
|
"testdata/export/ks.yaml",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"helmrelease",
|
"helmrelease",
|
||||||
"export helmrelease flux-system",
|
"export helmrelease flux-system",
|
||||||
"testdata/export/helm-release.yaml",
|
"testdata/export/helm-release.yaml",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bucket",
|
"bucket",
|
||||||
"export source bucket flux-system",
|
"export source bucket flux-system",
|
||||||
"testdata/export/bucket.yaml",
|
"testdata/export/bucket.yaml",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
objectFile := "testdata/export/objects.yaml"
|
|
||||||
tmpl := map[string]string{
|
|
||||||
"fluxns": allocateNamespace("flux-system"),
|
|
||||||
}
|
|
||||||
testEnv.CreateObjectFile(objectFile, tmpl, t)
|
|
||||||
|
|
||||||
for _, tt := range cases {
|
for _, tt := range cases {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
cmd := cmdTestCase{
|
cmd := cmdTestCase{
|
||||||
args: tt.arg + " -n=" + tmpl["fluxns"],
|
args: tt.arg + " -n=" + namespace,
|
||||||
assert: assertGoldenTemplateFile(tt.goldenFile, tmpl),
|
assert: assertGoldenTemplateFile(tt.goldenFile, tmpl),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -163,9 +163,16 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
if get.list.len() == 0 {
|
if get.list.len() == 0 {
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
logger.Failuref("%s object '%s' not found in '%s' namespace", get.kind, args[0], *kubeconfigArgs.Namespace)
|
logger.Failuref("%s object '%s' not found in %s namespace",
|
||||||
|
get.kind,
|
||||||
|
args[0],
|
||||||
|
namespaceNameOrAny(getArgs.allNamespaces, *kubeconfigArgs.Namespace),
|
||||||
|
)
|
||||||
} else if !getAll {
|
} else if !getAll {
|
||||||
logger.Failuref("no %s objects found in %s namespace", get.kind, *kubeconfigArgs.Namespace)
|
logger.Failuref("no %s objects found in %s namespace",
|
||||||
|
get.kind,
|
||||||
|
namespaceNameOrAny(getArgs.allNamespaces, *kubeconfigArgs.Namespace),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -192,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
|
||||||
@@ -214,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{
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
autov1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
|
autov1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
|
||||||
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var getImageAllCmd = &cobra.Command{
|
var getImageAllCmd = &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"
|
||||||
|
|
||||||
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var getImagePolicyCmd = &cobra.Command{
|
var getImagePolicyCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
|
||||||
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var getImageRepositoryCmd = &cobra.Command{
|
var getImageRepositoryCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -18,15 +18,15 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
|
||||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var getKsCmd = &cobra.Command{
|
var getKsCmd = &cobra.Command{
|
||||||
@@ -80,10 +80,8 @@ func (a kustomizationListAdapter) summariseItem(i int, includeNamespace bool, in
|
|||||||
item := a.Items[i]
|
item := a.Items[i]
|
||||||
revision := item.Status.LastAppliedRevision
|
revision := item.Status.LastAppliedRevision
|
||||||
status, msg := statusAndMessage(item.Status.Conditions)
|
status, msg := statusAndMessage(item.Status.Conditions)
|
||||||
if status == string(metav1.ConditionTrue) {
|
revision = utils.TruncateHex(revision)
|
||||||
revision = shortenCommitSha(revision)
|
msg = utils.TruncateHex(msg)
|
||||||
msg = shortenCommitSha(msg)
|
|
||||||
}
|
|
||||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||||
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
|
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
|
||||||
}
|
}
|
||||||
@@ -100,13 +98,3 @@ func (a kustomizationListAdapter) statusSelectorMatches(i int, conditionType, co
|
|||||||
item := a.Items[i]
|
item := a.Items[i]
|
||||||
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||||
}
|
}
|
||||||
|
|
||||||
func shortenCommitSha(msg string) string {
|
|
||||||
r := regexp.MustCompile("/([a-f0-9]{40})$")
|
|
||||||
sha := r.FindString(msg)
|
|
||||||
if sha != "" {
|
|
||||||
msg = strings.Replace(msg, sha, string([]rune(sha)[:8]), -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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{
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var getSourceBucketCmd = &cobra.Command{
|
var getSourceBucketCmd = &cobra.Command{
|
||||||
@@ -80,6 +82,8 @@ func (a *bucketListAdapter) summariseItem(i int, includeNamespace bool, includeK
|
|||||||
revision = item.GetArtifact().Revision
|
revision = item.GetArtifact().Revision
|
||||||
}
|
}
|
||||||
status, msg := statusAndMessage(item.Status.Conditions)
|
status, msg := statusAndMessage(item.Status.Conditions)
|
||||||
|
revision = utils.TruncateHex(revision)
|
||||||
|
msg = utils.TruncateHex(msg)
|
||||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||||
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
|
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var getSourceHelmChartCmd = &cobra.Command{
|
var getSourceHelmChartCmd = &cobra.Command{
|
||||||
@@ -80,6 +82,9 @@ func (a *helmChartListAdapter) summariseItem(i int, includeNamespace bool, inclu
|
|||||||
revision = item.GetArtifact().Revision
|
revision = item.GetArtifact().Revision
|
||||||
}
|
}
|
||||||
status, msg := statusAndMessage(item.Status.Conditions)
|
status, msg := statusAndMessage(item.Status.Conditions)
|
||||||
|
// NB: do not shorten revision as it contains a SemVer
|
||||||
|
// Message may still contain reference of e.g. commit chart was build from
|
||||||
|
msg = utils.TruncateHex(msg)
|
||||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||||
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
|
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var getSourceGitCmd = &cobra.Command{
|
var getSourceGitCmd = &cobra.Command{
|
||||||
@@ -81,10 +82,8 @@ func (a *gitRepositoryListAdapter) summariseItem(i int, includeNamespace bool, i
|
|||||||
revision = item.GetArtifact().Revision
|
revision = item.GetArtifact().Revision
|
||||||
}
|
}
|
||||||
status, msg := statusAndMessage(item.Status.Conditions)
|
status, msg := statusAndMessage(item.Status.Conditions)
|
||||||
if status == string(metav1.ConditionTrue) {
|
revision = utils.TruncateHex(revision)
|
||||||
revision = shortenCommitSha(revision)
|
msg = utils.TruncateHex(msg)
|
||||||
msg = shortenCommitSha(msg)
|
|
||||||
}
|
|
||||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||||
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
|
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var getSourceHelmCmd = &cobra.Command{
|
var getSourceHelmCmd = &cobra.Command{
|
||||||
@@ -80,6 +82,8 @@ func (a *helmRepositoryListAdapter) summariseItem(i int, includeNamespace bool,
|
|||||||
revision = item.GetArtifact().Revision
|
revision = item.GetArtifact().Revision
|
||||||
}
|
}
|
||||||
status, msg := statusAndMessage(item.Status.Conditions)
|
status, msg := statusAndMessage(item.Status.Conditions)
|
||||||
|
revision = utils.TruncateHex(revision)
|
||||||
|
msg = utils.TruncateHex(msg)
|
||||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||||
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
|
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var getSourceOCIRepositoryCmd = &cobra.Command{
|
var getSourceOCIRepositoryCmd = &cobra.Command{
|
||||||
@@ -80,6 +82,8 @@ func (a *ociRepositoryListAdapter) summariseItem(i int, includeNamespace bool, i
|
|||||||
revision = item.GetArtifact().Revision
|
revision = item.GetArtifact().Revision
|
||||||
}
|
}
|
||||||
status, msg := statusAndMessage(item.Status.Conditions)
|
status, msg := statusAndMessage(item.Status.Conditions)
|
||||||
|
revision = utils.TruncateHex(revision)
|
||||||
|
msg = utils.TruncateHex(msg)
|
||||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||||
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
|
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,51 +22,61 @@ package main
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestHelmReleaseFromGit(t *testing.T) {
|
func TestHelmReleaseFromGit(t *testing.T) {
|
||||||
|
namespace := allocateNamespace("thrfg")
|
||||||
|
del, err := execSetupTestNamespace(namespace)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Cleanup(del)
|
||||||
|
|
||||||
|
tmpl := map[string]string{"ns": namespace}
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
args string
|
args string
|
||||||
goldenFile string
|
goldenFile string
|
||||||
|
tmpl map[string]string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"create source git thrfg --url=https://github.com/stefanprodan/podinfo --branch=main --tag=6.0.0",
|
"create source git thrfg --url=https://github.com/stefanprodan/podinfo --branch=main --tag=6.3.5",
|
||||||
"testdata/helmrelease/create_source_git.golden",
|
"testdata/helmrelease/create_source_git.golden",
|
||||||
|
nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"create helmrelease thrfg --source=GitRepository/thrfg --chart=./charts/podinfo",
|
"create helmrelease thrfg --source=GitRepository/thrfg --chart=./charts/podinfo",
|
||||||
"testdata/helmrelease/create_helmrelease_from_git.golden",
|
"testdata/helmrelease/create_helmrelease_from_git.golden",
|
||||||
|
nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get helmrelease thrfg",
|
"get helmrelease thrfg",
|
||||||
"testdata/helmrelease/get_helmrelease_from_git.golden",
|
"testdata/helmrelease/get_helmrelease_from_git.golden",
|
||||||
|
nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"reconcile helmrelease thrfg --with-source",
|
"reconcile helmrelease thrfg --with-source",
|
||||||
"testdata/helmrelease/reconcile_helmrelease_from_git.golden",
|
"testdata/helmrelease/reconcile_helmrelease_from_git.golden",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"suspend helmrelease thrfg",
|
"suspend helmrelease thrfg",
|
||||||
"testdata/helmrelease/suspend_helmrelease_from_git.golden",
|
"testdata/helmrelease/suspend_helmrelease_from_git.golden",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"resume helmrelease thrfg",
|
"resume helmrelease thrfg",
|
||||||
"testdata/helmrelease/resume_helmrelease_from_git.golden",
|
"testdata/helmrelease/resume_helmrelease_from_git.golden",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"delete helmrelease thrfg --silent",
|
"delete helmrelease thrfg --silent",
|
||||||
"testdata/helmrelease/delete_helmrelease_from_git.golden",
|
"testdata/helmrelease/delete_helmrelease_from_git.golden",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace := allocateNamespace("thrfg")
|
|
||||||
del, err := setupTestNamespace(namespace)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer del()
|
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
cmd := cmdTestCase{
|
cmd := cmdTestCase{
|
||||||
args: tc.args + " -n=" + namespace,
|
args: tc.args + " -n=" + namespace,
|
||||||
assert: assertGoldenTemplateFile(tc.goldenFile, map[string]string{"ns": namespace}),
|
assert: assertGoldenTemplateFile(tc.goldenFile, tc.tmpl),
|
||||||
}
|
}
|
||||||
cmd.runTestCmd(t)
|
cmd.runTestCmd(t)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
autov1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
|
autov1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
|
||||||
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// These are general-purpose adapters for attaching methods to, for
|
// These are general-purpose adapters for attaching methods to, for
|
||||||
|
|||||||
@@ -22,6 +22,13 @@ package main
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestImageScanning(t *testing.T) {
|
func TestImageScanning(t *testing.T) {
|
||||||
|
namespace := allocateNamespace("tis")
|
||||||
|
del, err := execSetupTestNamespace(namespace)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Cleanup(del)
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
args string
|
args string
|
||||||
goldenFile string
|
goldenFile string
|
||||||
@@ -48,13 +55,6 @@ func TestImageScanning(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace := allocateNamespace("tis")
|
|
||||||
del, err := setupTestNamespace(namespace)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer del()
|
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
cmd := cmdTestCase{
|
cmd := cmdTestCase{
|
||||||
args: tc.args + " -n=" + namespace,
|
args: tc.args + " -n=" + namespace,
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ If a previous version is installed, then an in-place upgrade will be performed.`
|
|||||||
|
|
||||||
type installFlags struct {
|
type installFlags struct {
|
||||||
export bool
|
export bool
|
||||||
dryRun bool
|
|
||||||
version string
|
version string
|
||||||
defaultComponents []string
|
defaultComponents []string
|
||||||
extraComponents []string
|
extraComponents []string
|
||||||
@@ -69,7 +68,6 @@ type installFlags struct {
|
|||||||
watchAllNamespaces bool
|
watchAllNamespaces bool
|
||||||
networkPolicy bool
|
networkPolicy bool
|
||||||
manifestsPath string
|
manifestsPath string
|
||||||
arch flags.Arch
|
|
||||||
logLevel flags.LogLevel
|
logLevel flags.LogLevel
|
||||||
tokenAuth bool
|
tokenAuth bool
|
||||||
clusterDomain string
|
clusterDomain string
|
||||||
@@ -81,8 +79,6 @@ var installArgs = NewInstallFlags()
|
|||||||
func init() {
|
func init() {
|
||||||
installCmd.Flags().BoolVar(&installArgs.export, "export", false,
|
installCmd.Flags().BoolVar(&installArgs.export, "export", false,
|
||||||
"write the install manifests to stdout and exit")
|
"write the install manifests to stdout and exit")
|
||||||
installCmd.Flags().BoolVarP(&installArgs.dryRun, "dry-run", "", false,
|
|
||||||
"only print the object that would be applied")
|
|
||||||
installCmd.Flags().StringVarP(&installArgs.version, "version", "v", "",
|
installCmd.Flags().StringVarP(&installArgs.version, "version", "v", "",
|
||||||
"toolkit version, when specified the manifests are downloaded from https://github.com/fluxcd/flux2/releases")
|
"toolkit version, when specified the manifests are downloaded from https://github.com/fluxcd/flux2/releases")
|
||||||
installCmd.Flags().StringSliceVar(&installArgs.defaultComponents, "components", rootArgs.defaults.Components,
|
installCmd.Flags().StringSliceVar(&installArgs.defaultComponents, "components", rootArgs.defaults.Components,
|
||||||
@@ -94,7 +90,6 @@ func init() {
|
|||||||
"container registry where the toolkit images are published")
|
"container registry where the toolkit images are published")
|
||||||
installCmd.Flags().StringVar(&installArgs.imagePullSecret, "image-pull-secret", "",
|
installCmd.Flags().StringVar(&installArgs.imagePullSecret, "image-pull-secret", "",
|
||||||
"Kubernetes secret name used for pulling the toolkit images from a private registry")
|
"Kubernetes secret name used for pulling the toolkit images from a private registry")
|
||||||
installCmd.Flags().Var(&installArgs.arch, "arch", installArgs.arch.Description())
|
|
||||||
installCmd.Flags().BoolVar(&installArgs.watchAllNamespaces, "watch-all-namespaces", rootArgs.defaults.WatchAllNamespaces,
|
installCmd.Flags().BoolVar(&installArgs.watchAllNamespaces, "watch-all-namespaces", rootArgs.defaults.WatchAllNamespaces,
|
||||||
"watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed")
|
"watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed")
|
||||||
installCmd.Flags().Var(&installArgs.logLevel, "log-level", installArgs.logLevel.Description())
|
installCmd.Flags().Var(&installArgs.logLevel, "log-level", installArgs.logLevel.Description())
|
||||||
@@ -104,8 +99,7 @@ func init() {
|
|||||||
installCmd.Flags().StringSliceVar(&installArgs.tolerationKeys, "toleration-keys", nil,
|
installCmd.Flags().StringSliceVar(&installArgs.tolerationKeys, "toleration-keys", nil,
|
||||||
"list of toleration keys used to schedule the components pods onto nodes with matching taints")
|
"list of toleration keys used to schedule the components pods onto nodes with matching taints")
|
||||||
installCmd.Flags().MarkHidden("manifests")
|
installCmd.Flags().MarkHidden("manifests")
|
||||||
installCmd.Flags().MarkDeprecated("arch", "multi-arch container image is now available for AMD64, ARMv7 and ARM64")
|
|
||||||
installCmd.Flags().MarkDeprecated("dry-run", "use 'flux install --export | kubectl apply --dry-run=client -f-'")
|
|
||||||
rootCmd.AddCommand(installCmd)
|
rootCmd.AddCommand(installCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,11 +183,6 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
logger.Successf("manifests build completed")
|
logger.Successf("manifests build completed")
|
||||||
logger.Actionf("installing components in %s namespace", *kubeconfigArgs.Namespace)
|
logger.Actionf("installing components in %s namespace", *kubeconfigArgs.Namespace)
|
||||||
|
|
||||||
if installArgs.dryRun {
|
|
||||||
logger.Successf("install dry-run finished")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
applyOutput, err := utils.Apply(ctx, kubeconfigArgs, kubeclientOptions, tmpDir, 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)
|
||||||
|
|||||||
@@ -25,9 +25,7 @@ func TestInstall(t *testing.T) {
|
|||||||
// Given that this test uses an invalid namespace, it ensures
|
// Given that this test uses an invalid namespace, it ensures
|
||||||
// to restore whatever value it had previously.
|
// to restore whatever value it had previously.
|
||||||
currentNamespace := *kubeconfigArgs.Namespace
|
currentNamespace := *kubeconfigArgs.Namespace
|
||||||
defer func() {
|
t.Cleanup(func() { *kubeconfigArgs.Namespace = currentNamespace })
|
||||||
*kubeconfigArgs.Namespace = currentNamespace
|
|
||||||
}()
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
@@ -22,51 +22,61 @@ package main
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestKustomizationFromGit(t *testing.T) {
|
func TestKustomizationFromGit(t *testing.T) {
|
||||||
|
namespace := allocateNamespace("tkfg")
|
||||||
|
del, err := execSetupTestNamespace(namespace)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Cleanup(del)
|
||||||
|
|
||||||
|
tmpl := map[string]string{"ns": namespace}
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
args string
|
args string
|
||||||
goldenFile string
|
goldenFile string
|
||||||
|
tmpl map[string]string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"create source git tkfg --url=https://github.com/stefanprodan/podinfo --branch=main --tag=6.0.0",
|
"create source git tkfg --url=https://github.com/stefanprodan/podinfo --branch=main --tag=6.3.5",
|
||||||
"testdata/kustomization/create_source_git.golden",
|
"testdata/kustomization/create_source_git.golden",
|
||||||
|
nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"create kustomization tkfg --source=tkfg --path=./deploy/overlays/dev --prune=true --interval=5m --health-check=Deployment/frontend.dev --health-check=Deployment/backend.dev --health-check-timeout=3m",
|
"create kustomization tkfg --source=tkfg --path=./deploy/overlays/dev --prune=true --interval=5m --health-check=Deployment/frontend.dev --health-check=Deployment/backend.dev --health-check-timeout=3m",
|
||||||
"testdata/kustomization/create_kustomization_from_git.golden",
|
"testdata/kustomization/create_kustomization_from_git.golden",
|
||||||
|
nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get kustomization tkfg",
|
"get kustomization tkfg",
|
||||||
"testdata/kustomization/get_kustomization_from_git.golden",
|
"testdata/kustomization/get_kustomization_from_git.golden",
|
||||||
|
nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"reconcile kustomization tkfg --with-source",
|
"reconcile kustomization tkfg --with-source",
|
||||||
"testdata/kustomization/reconcile_kustomization_from_git.golden",
|
"testdata/kustomization/reconcile_kustomization_from_git.golden",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"suspend kustomization tkfg",
|
"suspend kustomization tkfg",
|
||||||
"testdata/kustomization/suspend_kustomization_from_git.golden",
|
"testdata/kustomization/suspend_kustomization_from_git.golden",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"resume kustomization tkfg",
|
"resume kustomization tkfg",
|
||||||
"testdata/kustomization/resume_kustomization_from_git.golden",
|
"testdata/kustomization/resume_kustomization_from_git.golden",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"delete kustomization tkfg --silent",
|
"delete kustomization tkfg --silent",
|
||||||
"testdata/kustomization/delete_kustomization_from_git.golden",
|
"testdata/kustomization/delete_kustomization_from_git.golden",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace := allocateNamespace("tkfg")
|
|
||||||
del, err := setupTestNamespace(namespace)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer del()
|
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
cmd := cmdTestCase{
|
cmd := cmdTestCase{
|
||||||
args: tc.args + " -n=" + namespace,
|
args: tc.args + " -n=" + namespace,
|
||||||
assert: assertGoldenTemplateFile(tc.goldenFile, map[string]string{"ns": namespace}),
|
assert: assertGoldenTemplateFile(tc.goldenFile, tc.tmpl),
|
||||||
}
|
}
|
||||||
cmd.runTestCmd(t)
|
cmd.runTestCmd(t)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ func TestMain(m *testing.M) {
|
|||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupTestNamespace(namespace string) (func(), error) {
|
func execSetupTestNamespace(namespace string) (func(), error) {
|
||||||
kubectlArgs := []string{"create", "namespace", namespace}
|
kubectlArgs := []string{"create", "namespace", namespace}
|
||||||
_, err := utils.ExecKubectlCommand(context.TODO(), utils.ModeStderrOS, *kubeconfigArgs.KubeConfig, *kubeconfigArgs.Context, kubectlArgs...)
|
_, err := utils.ExecKubectlCommand(context.TODO(), utils.ModeStderrOS, *kubeconfigArgs.KubeConfig, *kubeconfigArgs.Context, kubectlArgs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -18,12 +18,16 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
reg "github.com/google/go-containerregistry/pkg/name"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
oci "github.com/fluxcd/pkg/oci/client"
|
oci "github.com/fluxcd/pkg/oci/client"
|
||||||
)
|
)
|
||||||
@@ -31,21 +35,46 @@ import (
|
|||||||
var pushArtifactCmd = &cobra.Command{
|
var pushArtifactCmd = &cobra.Command{
|
||||||
Use: "artifact",
|
Use: "artifact",
|
||||||
Short: "Push artifact",
|
Short: "Push artifact",
|
||||||
Long: `The push artifact command creates a tarball from the given directory and uploads the artifact to an OCI repository.
|
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.`,
|
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
|
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
|
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) \
|
flux push artifact oci://ghcr.io/org/config/app:$(git rev-parse --short HEAD) \
|
||||||
--path="./path/to/local/manifests" \
|
--path="./path/to/local/manifests" \
|
||||||
--source="$(git config --get remote.origin.url)" \
|
--source="$(git config --get remote.origin.url)" \
|
||||||
--revision="$(git branch --show-current)/$(git rev-parse HEAD)"
|
--revision="$(git branch --show-current)@sha1:$(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)@sha1:$(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 and set custom OCI annotations
|
||||||
|
kustomize build . | flux push artifact oci://ghcr.io/org/config/app:$(git rev-parse --short HEAD) -f - \
|
||||||
|
--source="$(git config --get remote.origin.url)" \
|
||||||
|
--revision="$(git branch --show-current)@sha1:$(git rev-parse HEAD)" \
|
||||||
|
--annotations='org.opencontainers.image.licenses=Apache-2.0' \
|
||||||
|
--annotations='org.opencontainers.image.documentation=https://app.org/docs' \
|
||||||
|
--annotations='org.opencontainers.image.description=Production config.'
|
||||||
|
|
||||||
|
# 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)@sha1:$(git rev-parse HEAD)"
|
||||||
|
|
||||||
# Push manifests to Docker Hub using the Git tag as the OCI artifact tag
|
# Push manifests to Docker Hub using the Git tag as the OCI artifact tag
|
||||||
echo $DOCKER_PAT | docker login --username flux --password-stdin
|
echo $DOCKER_PAT | docker login --username flux --password-stdin
|
||||||
flux push artifact oci://docker.io/org/app-config:$(git tag --points-at HEAD) \
|
flux push artifact oci://docker.io/org/app-config:$(git tag --points-at HEAD) \
|
||||||
--path="./path/to/local/manifests" \
|
--path="./path/to/local/manifests" \
|
||||||
--source="$(git config --get remote.origin.url)" \
|
--source="$(git config --get remote.origin.url)" \
|
||||||
--revision="$(git tag --points-at HEAD)/$(git rev-parse HEAD)"
|
--revision="$(git tag --points-at HEAD)@sha1:$(git rev-parse HEAD)"
|
||||||
|
|
||||||
# Login directly to the registry provider
|
# Login directly to the registry provider
|
||||||
# You might need to export the following variable if you use local config files for AWS:
|
# You might need to export the following variable if you use local config files for AWS:
|
||||||
@@ -53,14 +82,14 @@ The command can read the credentials from '~/.docker/config.json' but they can a
|
|||||||
flux push artifact oci://<account>.dkr.ecr.<region>.amazonaws.com/foo:v1:$(git tag --points-at HEAD) \
|
flux push artifact oci://<account>.dkr.ecr.<region>.amazonaws.com/foo:v1:$(git tag --points-at HEAD) \
|
||||||
--path="./path/to/local/manifests" \
|
--path="./path/to/local/manifests" \
|
||||||
--source="$(git config --get remote.origin.url)" \
|
--source="$(git config --get remote.origin.url)" \
|
||||||
--revision="$(git tag --points-at HEAD)/$(git rev-parse HEAD)" \
|
--revision="$(git tag --points-at HEAD)@sha1:$(git rev-parse HEAD)" \
|
||||||
--provider aws
|
--provider aws
|
||||||
|
|
||||||
# Or pass credentials directly
|
# Login by passing credentials directly
|
||||||
flux push artifact oci://docker.io/org/app-config:$(git tag --points-at HEAD) \
|
flux push artifact oci://docker.io/org/app-config:$(git tag --points-at HEAD) \
|
||||||
--path="./path/to/local/manifests" \
|
--path="./path/to/local/manifests" \
|
||||||
--source="$(git config --get remote.origin.url)" \
|
--source="$(git config --get remote.origin.url)" \
|
||||||
--revision="$(git tag --points-at HEAD)/$(git rev-parse HEAD)" \
|
--revision="$(git tag --points-at HEAD)@sha1:$(git rev-parse HEAD)" \
|
||||||
--creds flux:$DOCKER_PAT
|
--creds flux:$DOCKER_PAT
|
||||||
`,
|
`,
|
||||||
RunE: pushArtifactCmdRun,
|
RunE: pushArtifactCmdRun,
|
||||||
@@ -73,6 +102,8 @@ type pushArtifactFlags struct {
|
|||||||
creds string
|
creds string
|
||||||
provider flags.SourceOCIProvider
|
provider flags.SourceOCIProvider
|
||||||
ignorePaths []string
|
ignorePaths []string
|
||||||
|
annotations []string
|
||||||
|
output string
|
||||||
}
|
}
|
||||||
|
|
||||||
var pushArtifactArgs = newPushArtifactFlags()
|
var pushArtifactArgs = newPushArtifactFlags()
|
||||||
@@ -84,12 +115,15 @@ func newPushArtifactFlags() pushArtifactFlags {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
pushArtifactCmd.Flags().StringVar(&pushArtifactArgs.path, "path", "", "path to the directory where the Kubernetes manifests are located")
|
pushArtifactCmd.Flags().StringVarP(&pushArtifactArgs.path, "path", "f", "", "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.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.revision, "revision", "", "the source revision in the format '<branch|tag>@sha1:<commit-sha>'")
|
||||||
pushArtifactCmd.Flags().StringVar(&pushArtifactArgs.creds, "creds", "", "credentials for OCI registry in the format <username>[:<password>] if --provider is generic")
|
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().Var(&pushArtifactArgs.provider, "provider", pushArtifactArgs.provider.Description())
|
||||||
pushArtifactCmd.Flags().StringSliceVar(&pushArtifactArgs.ignorePaths, "ignore-paths", excludeOCI, "set paths to ignore in .gitignore format")
|
pushArtifactCmd.Flags().StringSliceVar(&pushArtifactArgs.ignorePaths, "ignore-paths", excludeOCI, "set paths to ignore in .gitignore format")
|
||||||
|
pushArtifactCmd.Flags().StringArrayVarP(&pushArtifactArgs.annotations, "annotations", "a", nil, "Set custom OCI annotations in the format '<key>=<value>'")
|
||||||
|
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)
|
pushCmd.AddCommand(pushArtifactCmd)
|
||||||
}
|
}
|
||||||
@@ -117,13 +151,33 @@ func pushArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if fs, err := os.Stat(pushArtifactArgs.path); err != nil || !fs.IsDir() {
|
path := pushArtifactArgs.path
|
||||||
return fmt.Errorf("invalid path %q", 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
annotations := map[string]string{}
|
||||||
|
for _, annotation := range pushArtifactArgs.annotations {
|
||||||
|
kv := strings.Split(annotation, "=")
|
||||||
|
if len(kv) != 2 {
|
||||||
|
return fmt.Errorf("invalid annotation %s, must be in the format key=value", annotation)
|
||||||
|
}
|
||||||
|
annotations[kv[0]] = kv[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
meta := oci.Metadata{
|
meta := oci.Metadata{
|
||||||
Source: pushArtifactArgs.source,
|
Source: pushArtifactArgs.source,
|
||||||
Revision: pushArtifactArgs.revision,
|
Revision: pushArtifactArgs.revision,
|
||||||
|
Annotations: annotations,
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
@@ -150,14 +204,54 @@ func pushArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Actionf("pushing artifact to %s", url)
|
if pushArtifactArgs.output == "" {
|
||||||
|
logger.Actionf("pushing artifact to %s", url)
|
||||||
|
}
|
||||||
|
|
||||||
digest, err := ociClient.Push(ctx, url, pushArtifactArgs.path, meta, pushArtifactArgs.ignorePaths)
|
digestURL, err := ociClient.Push(ctx, url, path, meta, pushArtifactArgs.ignorePaths)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("pushing artifact failed: %w", err)
|
return fmt.Errorf("pushing artifact failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Successf("artifact successfully pushed to %s", digest)
|
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
|
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"
|
||||||
@@ -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"
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var reconcileImageRepositoryCmd = &cobra.Command{
|
var reconcileImageRepositoryCmd = &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"
|
||||||
|
|||||||
@@ -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 resumeAlertCmd = &cobra.Command{
|
var resumeAlertCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var resumeImageRepositoryCmd = &cobra.Command{
|
var resumeImageRepositoryCmd = &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 resumeReceiverCmd = &cobra.Command{
|
var resumeReceiverCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -24,47 +24,56 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestSourceOCI(t *testing.T) {
|
func TestSourceOCI(t *testing.T) {
|
||||||
|
namespace := allocateNamespace("oci-test")
|
||||||
|
del, err := execSetupTestNamespace(namespace)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Cleanup(del)
|
||||||
|
|
||||||
|
tmpl := map[string]string{"ns": namespace}
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
args string
|
args string
|
||||||
goldenFile string
|
goldenFile string
|
||||||
|
tmpl map[string]string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"create source oci thrfg --url=oci://ghcr.io/stefanprodan/manifests/podinfo --tag=6.1.6 --interval 10m",
|
"create source oci thrfg --url=oci://ghcr.io/stefanprodan/manifests/podinfo --tag=6.3.5 --interval 10m",
|
||||||
"testdata/oci/create_source_oci.golden",
|
"testdata/oci/create_source_oci.golden",
|
||||||
|
nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get source oci thrfg",
|
"get source oci thrfg",
|
||||||
"testdata/oci/get_oci.golden",
|
"testdata/oci/get_oci.golden",
|
||||||
|
nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"reconcile source oci thrfg",
|
"reconcile source oci thrfg",
|
||||||
"testdata/oci/reconcile_oci.golden",
|
"testdata/oci/reconcile_oci.golden",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"suspend source oci thrfg",
|
"suspend source oci thrfg",
|
||||||
"testdata/oci/suspend_oci.golden",
|
"testdata/oci/suspend_oci.golden",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"resume source oci thrfg",
|
"resume source oci thrfg",
|
||||||
"testdata/oci/resume_oci.golden",
|
"testdata/oci/resume_oci.golden",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"delete source oci thrfg --silent",
|
"delete source oci thrfg --silent",
|
||||||
"testdata/oci/delete_oci.golden",
|
"testdata/oci/delete_oci.golden",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace := allocateNamespace("oci-test")
|
|
||||||
del, err := setupTestNamespace(namespace)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer del()
|
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
cmd := cmdTestCase{
|
cmd := cmdTestCase{
|
||||||
args: tc.args + " -n=" + namespace,
|
args: tc.args + " -n=" + namespace,
|
||||||
assert: assertGoldenTemplateFile(tc.goldenFile, map[string]string{"ns": namespace}),
|
assert: assertGoldenTemplateFile(tc.goldenFile, tc.tmpl),
|
||||||
}
|
}
|
||||||
cmd.runTestCmd(t)
|
cmd.runTestCmd(t)
|
||||||
}
|
}
|
||||||
|
|||||||
219
cmd/flux/stats.go
Normal file
219
cmd/flux/stats.go
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2023 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/printers"
|
||||||
|
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
|
||||||
|
autov1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
|
||||||
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
||||||
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||||
|
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
|
"sigs.k8s.io/cli-utils/pkg/kstatus/status"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
var statsCmd = &cobra.Command{
|
||||||
|
Use: "stats",
|
||||||
|
Short: "Stats of Flux reconciles",
|
||||||
|
Long: `The stats command prints a report of Flux custom resources present on a cluster,
|
||||||
|
including their reconcile status and the amount of cumulative storage used for each source type`,
|
||||||
|
Example: ` # Print the stats report for a namespace
|
||||||
|
flux stats --namespace default
|
||||||
|
|
||||||
|
# Print the stats report for the whole cluster
|
||||||
|
flux stats -A`,
|
||||||
|
RunE: runStatsCmd,
|
||||||
|
}
|
||||||
|
|
||||||
|
type StatsFlags struct {
|
||||||
|
allNamespaces bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var statsArgs StatsFlags
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
statsCmd.PersistentFlags().BoolVarP(&statsArgs.allNamespaces, "all-namespaces", "A", false,
|
||||||
|
"list the statistics for objects across all namespaces")
|
||||||
|
rootCmd.AddCommand(statsCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func runStatsCmd(cmd *cobra.Command, args []string) error {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
types := []metav1.GroupVersionKind{
|
||||||
|
{
|
||||||
|
Kind: sourcev1.GitRepositoryKind,
|
||||||
|
Version: sourcev1.GroupVersion.Version,
|
||||||
|
Group: sourcev1.GroupVersion.Group,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: sourcev1.OCIRepositoryKind,
|
||||||
|
Version: sourcev1.GroupVersion.Version,
|
||||||
|
Group: sourcev1.GroupVersion.Group,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: sourcev1.HelmRepositoryKind,
|
||||||
|
Version: sourcev1.GroupVersion.Version,
|
||||||
|
Group: sourcev1.GroupVersion.Group,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: sourcev1.HelmChartKind,
|
||||||
|
Version: sourcev1.GroupVersion.Version,
|
||||||
|
Group: sourcev1.GroupVersion.Group,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: sourcev1.BucketKind,
|
||||||
|
Version: sourcev1.GroupVersion.Version,
|
||||||
|
Group: sourcev1.GroupVersion.Group,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: kustomizev1.KustomizationKind,
|
||||||
|
Version: kustomizev1.GroupVersion.Version,
|
||||||
|
Group: kustomizev1.GroupVersion.Group,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: helmv2.HelmReleaseKind,
|
||||||
|
Version: helmv2.GroupVersion.Version,
|
||||||
|
Group: helmv2.GroupVersion.Group,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: notificationv1.AlertKind,
|
||||||
|
Version: notificationv1.GroupVersion.Version,
|
||||||
|
Group: notificationv1.GroupVersion.Group,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: notificationv1.ProviderKind,
|
||||||
|
Version: notificationv1.GroupVersion.Version,
|
||||||
|
Group: notificationv1.GroupVersion.Group,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: notificationv1.ReceiverKind,
|
||||||
|
Version: notificationv1.GroupVersion.Version,
|
||||||
|
Group: notificationv1.GroupVersion.Group,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: autov1.ImageUpdateAutomationKind,
|
||||||
|
Version: autov1.GroupVersion.Version,
|
||||||
|
Group: autov1.GroupVersion.Group,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: imagev1.ImagePolicyKind,
|
||||||
|
Version: imagev1.GroupVersion.Version,
|
||||||
|
Group: imagev1.GroupVersion.Group,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: imagev1.ImageRepositoryKind,
|
||||||
|
Version: imagev1.GroupVersion.Version,
|
||||||
|
Group: imagev1.GroupVersion.Group,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
header := []string{"Reconcilers", "Running", "Failing", "Suspended", "Storage"}
|
||||||
|
var rows [][]string
|
||||||
|
|
||||||
|
for _, t := range types {
|
||||||
|
var total int
|
||||||
|
var suspended int
|
||||||
|
var failing int
|
||||||
|
var totalSize int64
|
||||||
|
|
||||||
|
list := unstructured.UnstructuredList{
|
||||||
|
Object: map[string]interface{}{
|
||||||
|
"apiVersion": t.Group + "/" + t.Version,
|
||||||
|
"kind": t.Kind,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
scope := client.InNamespace("")
|
||||||
|
if !statsArgs.allNamespaces {
|
||||||
|
scope = client.InNamespace(*kubeconfigArgs.Namespace)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := kubeClient.List(ctx, &list, scope); err == nil {
|
||||||
|
total = len(list.Items)
|
||||||
|
|
||||||
|
for _, item := range list.Items {
|
||||||
|
if s, _, _ := unstructured.NestedBool(item.Object, "spec", "suspend"); s {
|
||||||
|
suspended++
|
||||||
|
}
|
||||||
|
|
||||||
|
if obj, err := status.GetObjectWithConditions(item.Object); err == nil {
|
||||||
|
for _, cond := range obj.Status.Conditions {
|
||||||
|
if cond.Type == "Ready" && cond.Status == corev1.ConditionFalse {
|
||||||
|
failing++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if size, found, _ := unstructured.NestedInt64(item.Object, "status", "artifact", "size"); found {
|
||||||
|
totalSize += size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rows = append(rows, []string{
|
||||||
|
t.Kind,
|
||||||
|
formatInt(total - suspended),
|
||||||
|
formatInt(failing),
|
||||||
|
formatInt(suspended),
|
||||||
|
formatSize(totalSize),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
err = printers.TablePrinter(header).Print(cmd.OutOrStdout(), rows)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatInt(i int) string {
|
||||||
|
return fmt.Sprintf("%d", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatSize(b int64) string {
|
||||||
|
if b == 0 {
|
||||||
|
return "-"
|
||||||
|
}
|
||||||
|
const unit = 1024
|
||||||
|
if b < unit {
|
||||||
|
return fmt.Sprintf("%d B", b)
|
||||||
|
}
|
||||||
|
div, exp := int64(unit), 0
|
||||||
|
for n := b / unit; n >= unit; n /= unit {
|
||||||
|
div *= unit
|
||||||
|
exp++
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%.1f %ciB",
|
||||||
|
float64(b)/float64(div), "KMGTPE"[exp])
|
||||||
|
}
|
||||||
@@ -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 suspendAlertCmd = &cobra.Command{
|
var suspendAlertCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var suspendImageRepositoryCmd = &cobra.Command{
|
var suspendImageRepositoryCmd = &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 suspendReceiverCmd = &cobra.Command{
|
var suspendReceiverCmd = &cobra.Command{
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user