Compare commits
293 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
059751b3c9 | ||
|
|
05479756d8 | ||
|
|
34e19cb638 | ||
|
|
5312f81c8e | ||
|
|
7f02898539 | ||
|
|
8aabc544f1 | ||
|
|
3b62955e81 | ||
|
|
9c76ba903b | ||
|
|
b4118b73ed | ||
|
|
82a8697f28 | ||
|
|
5b9a1ce5c6 | ||
|
|
32ad462ebe | ||
|
|
1ff8c2806c | ||
|
|
437a7a2852 | ||
|
|
412db70773 | ||
|
|
a1bb6babed | ||
|
|
568c536c3c | ||
|
|
d7129d6b55 | ||
|
|
4a893b13f8 | ||
|
|
8c2983c958 | ||
|
|
a30ffdb176 | ||
|
|
7a306e69ab | ||
|
|
23c4c2f1aa | ||
|
|
aac07f03d8 | ||
|
|
f4418920fb | ||
|
|
7752206152 | ||
|
|
c950f8f817 | ||
|
|
9276345fe7 | ||
|
|
01f910e257 | ||
|
|
de5f00016b | ||
|
|
877729aca3 | ||
|
|
f65d87b191 | ||
|
|
3b1d706b05 | ||
|
|
b0552fa0de | ||
|
|
cbca583f4b | ||
|
|
a0520de7aa | ||
|
|
4602b72778 | ||
|
|
e69a6ed91a | ||
|
|
9d6a037935 | ||
|
|
41df03f600 | ||
|
|
ca92464ef6 | ||
|
|
2e9fd33ce5 | ||
|
|
cf3f729f98 | ||
|
|
8b444283e6 | ||
|
|
4b4e6b1be3 | ||
|
|
d3d271defe | ||
|
|
9bddabf4ff | ||
|
|
959ea6875a | ||
|
|
7b7eb011b0 | ||
|
|
997e6be3a2 | ||
|
|
51af4bbf52 | ||
|
|
e33198e750 | ||
|
|
e3f5a8fee3 | ||
|
|
f8b58f8be9 | ||
|
|
55542a8086 | ||
|
|
70c8c0445c | ||
|
|
29c0bb4ce2 | ||
|
|
b86b195450 | ||
|
|
edf15894f8 | ||
|
|
74878a9aef | ||
|
|
82824b4fc6 | ||
|
|
141d71c39d | ||
|
|
e9d6f271b5 | ||
|
|
8d4dee2aee | ||
|
|
246af92386 | ||
|
|
7c9957a18f | ||
|
|
9e7018383a | ||
|
|
920d6e5404 | ||
|
|
57962347f2 | ||
|
|
6f053c45df | ||
|
|
f154326391 | ||
|
|
776a7fc9c0 | ||
|
|
08412b72bc | ||
|
|
030e166f43 | ||
|
|
d92dfc56b8 | ||
|
|
365d2d102d | ||
|
|
f7853c4ddf | ||
|
|
0a6d5d9267 | ||
|
|
10b761e4e7 | ||
|
|
c6f2b410bc | ||
|
|
306f8f5715 | ||
|
|
f7d9ee90cd | ||
|
|
9376c9a946 | ||
|
|
70fb87bc93 | ||
|
|
63e54f3575 | ||
|
|
1e2a497108 | ||
|
|
5d95a6e750 | ||
|
|
af00610a61 | ||
|
|
809cb79828 | ||
|
|
e44a58cba0 | ||
|
|
10046187a6 | ||
|
|
a402461f9c | ||
|
|
8a6771c9a9 | ||
|
|
7173bd5945 | ||
|
|
8e09ade41c | ||
|
|
6ceb8d8338 | ||
|
|
11296cd94f | ||
|
|
677dca0bc4 | ||
|
|
8e7b957164 | ||
|
|
8f93e2a9d4 | ||
|
|
62755b4b75 | ||
|
|
dcfb745b1f | ||
|
|
f38b83231c | ||
|
|
269f5e2575 | ||
|
|
893596383a | ||
|
|
8c67708829 | ||
|
|
c1528503b6 | ||
|
|
d3c56eb3d3 | ||
|
|
b10eee87ee | ||
|
|
83de469967 | ||
|
|
192978125f | ||
|
|
b4b3551e39 | ||
|
|
7f580e89d0 | ||
|
|
81a087095a | ||
|
|
bcabde3bdb | ||
|
|
c190d80d4a | ||
|
|
11081e8cb2 | ||
|
|
c5890f08ef | ||
|
|
926d8a1c37 | ||
|
|
da6dfd5a1b | ||
|
|
4318152141 | ||
|
|
759145704f | ||
|
|
5cab8f4b11 | ||
|
|
a0ce4b23d2 | ||
|
|
6d88a0c3ac | ||
|
|
db44bcd88e | ||
|
|
585ae5090d | ||
|
|
fe46793c40 | ||
|
|
be146b1cc9 | ||
|
|
e46c7bd519 | ||
|
|
f3d143e5ee | ||
|
|
fc059df8ff | ||
|
|
6c047d1e2a | ||
|
|
f6afe7f0ec | ||
|
|
ca7d2e783f | ||
|
|
0b133ca9f2 | ||
|
|
ede6785e6b | ||
|
|
6d9f39d8ea | ||
|
|
fb637ea955 | ||
|
|
e07558f5b7 | ||
|
|
b75dbf8c70 | ||
|
|
062c1e59a9 | ||
|
|
ba5eea861e | ||
|
|
ff7df54899 | ||
|
|
b75ce95086 | ||
|
|
a86d94745a | ||
|
|
c13de6089a | ||
|
|
3cb748a47e | ||
|
|
3e6e93fab4 | ||
|
|
5832811930 | ||
|
|
6f0ea04ff3 | ||
|
|
26ea167524 | ||
|
|
1393e7a62b | ||
|
|
7e1fd499ca | ||
|
|
309fd86b45 | ||
|
|
e14357f694 | ||
|
|
29f0adc587 | ||
|
|
3ab578747d | ||
|
|
2c3cb1a664 | ||
|
|
99a0c47277 | ||
|
|
c5b2c6709a | ||
|
|
8354ac937c | ||
|
|
aa5ad65286 | ||
|
|
05adb44416 | ||
|
|
adf5a5278f | ||
|
|
bb04ca36b2 | ||
|
|
fc94b1af7a | ||
|
|
d9886035c8 | ||
|
|
0e122863dd | ||
|
|
3089f67946 | ||
|
|
3654e221a9 | ||
|
|
a26dd05c49 | ||
|
|
6c844369be | ||
|
|
a03574f8c3 | ||
|
|
43c6a1531a | ||
|
|
aed7341b34 | ||
|
|
8731f00347 | ||
|
|
75a18b4548 | ||
|
|
716b41e91b | ||
|
|
e72214e266 | ||
|
|
46f9fc194c | ||
|
|
6c5f27be02 | ||
|
|
e96652bdaa | ||
|
|
b7007a35d7 | ||
|
|
e4dc56b59d | ||
|
|
b05059a9c4 | ||
|
|
121783976a | ||
|
|
5a9424d0b1 | ||
|
|
e2a3800664 | ||
|
|
56815a3624 | ||
|
|
ca6e0ff36e | ||
|
|
4c60d1657d | ||
|
|
cdd90cfa75 | ||
|
|
05b053e2e9 | ||
|
|
46c75c1af2 | ||
|
|
80cf5fa729 | ||
|
|
789aa322f1 | ||
|
|
f03c24565f | ||
|
|
b6a95be5d0 | ||
|
|
0f9e8ed3f7 | ||
|
|
50af0ba93c | ||
|
|
923a5882de | ||
|
|
83dc3e6093 | ||
|
|
43edb62f87 | ||
|
|
21e5acc0e0 | ||
|
|
be1ce74dc5 | ||
|
|
31771f3575 | ||
|
|
ffcd7d8059 | ||
|
|
4bc4aa1397 | ||
|
|
04faba95cd | ||
|
|
f712dadab5 | ||
|
|
58b3150ce3 | ||
|
|
e7225db397 | ||
|
|
8ec5492d87 | ||
|
|
c2c64a70c4 | ||
|
|
4621576f40 | ||
|
|
3b609e9b03 | ||
|
|
4f2ebd78be | ||
|
|
88dacebc94 | ||
|
|
92e7d1ad1e | ||
|
|
d5d8c340c8 | ||
|
|
b8a85b809a | ||
|
|
61be0775af | ||
|
|
404ffa5a91 | ||
|
|
f2de7e04b8 | ||
|
|
8b3e3b1dd7 | ||
|
|
81e91ac3f5 | ||
|
|
b9bde94d08 | ||
|
|
37746023c1 | ||
|
|
d3e529b8a4 | ||
|
|
eb69083ef5 | ||
|
|
96aac387c9 | ||
|
|
870f18c621 | ||
|
|
57b33e29f7 | ||
|
|
94b7917679 | ||
|
|
98fa0c4271 | ||
|
|
8282907bce | ||
|
|
323f4f5e5f | ||
|
|
744b3ebd0a | ||
|
|
3fdba35993 | ||
|
|
ebdf9ed379 | ||
|
|
a572274c5c | ||
|
|
6a6bba8669 | ||
|
|
1d1d4bbf4b | ||
|
|
d9bb4c631e | ||
|
|
722962c138 | ||
|
|
c98ff6ae87 | ||
|
|
cbef6a4cad | ||
|
|
f887a2c029 | ||
|
|
078cfe92c2 | ||
|
|
80ef184b60 | ||
|
|
f2475988bd | ||
|
|
45526108e0 | ||
|
|
414c0bbbdc | ||
|
|
6873a710d9 | ||
|
|
8a44006384 | ||
|
|
1b6061066a | ||
|
|
3a8a5982c6 | ||
|
|
ccff578492 | ||
|
|
e2402e3d84 | ||
|
|
f13b1629cf | ||
|
|
72a97bb70a | ||
|
|
67b393ce09 | ||
|
|
48e89b95bb | ||
|
|
2159ed62d0 | ||
|
|
8bb65719cd | ||
|
|
4352915945 | ||
|
|
ebd145f7f7 | ||
|
|
cd52a0eef3 | ||
|
|
69e4a86fe2 | ||
|
|
52d89a2ee1 | ||
|
|
5c60e792d9 | ||
|
|
77c9611784 | ||
|
|
66780bbf54 | ||
|
|
a8932e677e | ||
|
|
e12988a8f9 | ||
|
|
6ee4abe79e | ||
|
|
948e050d60 | ||
|
|
87feb45751 | ||
|
|
77aa81a064 | ||
|
|
a4a1db0915 | ||
|
|
57b9610af7 | ||
|
|
c3384c6499 | ||
|
|
5389859260 | ||
|
|
84c585cf61 | ||
|
|
ca496d393d | ||
|
|
3d4ca831dc | ||
|
|
7ace8de753 | ||
|
|
928d3e2185 | ||
|
|
cbf2b90320 | ||
|
|
69dce73e51 | ||
|
|
75d4f87dec | ||
|
|
4f7d89e825 |
9
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
9
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
@@ -48,19 +48,18 @@ body:
|
|||||||
required: true
|
required: true
|
||||||
attributes:
|
attributes:
|
||||||
label: Flux version
|
label: Flux version
|
||||||
description: Run `flux --version` to check. If not applicable, write `N/A`.
|
description: Run `flux version --client`. If not applicable, write `N/A`.
|
||||||
placeholder: e.g. 0.16.1
|
placeholder: e.g. v0.20.1
|
||||||
- type: textarea
|
- type: textarea
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
attributes:
|
attributes:
|
||||||
label: Flux check
|
label: Flux check
|
||||||
description: Run `flux check` to check. If not applicable, write `N/A`.
|
description: Run `flux check`. If not applicable, write `N/A`.
|
||||||
placeholder: |
|
placeholder: |
|
||||||
For example:
|
For example:
|
||||||
► checking prerequisites
|
► checking prerequisites
|
||||||
✔ kubectl 1.21.0 >=1.18.0-0
|
✔ Kubernetes 1.21.1 >=1.19.0-0
|
||||||
✔ Kubernetes 1.21.1 >=1.16.0-0
|
|
||||||
► checking controllers
|
► checking controllers
|
||||||
✔ all checks passed
|
✔ all checks passed
|
||||||
- type: input
|
- type: input
|
||||||
|
|||||||
12
.github/aur/flux-go/PKGBUILD.template
vendored
12
.github/aur/flux-go/PKGBUILD.template
vendored
@@ -12,7 +12,7 @@ provides=("flux-bin")
|
|||||||
conflicts=("flux-bin")
|
conflicts=("flux-bin")
|
||||||
replaces=("flux-cli")
|
replaces=("flux-cli")
|
||||||
depends=("glibc")
|
depends=("glibc")
|
||||||
makedepends=('go>=1.16', 'kustomize>=3.0')
|
makedepends=('go>=1.17', 'kustomize>=3.0')
|
||||||
optdepends=('bash-completion: auto-completion for flux in Bash',
|
optdepends=('bash-completion: auto-completion for flux in Bash',
|
||||||
'zsh-completions: auto-completion for flux in ZSH')
|
'zsh-completions: auto-completion for flux in ZSH')
|
||||||
source=(
|
source=(
|
||||||
@@ -30,12 +30,20 @@ build() {
|
|||||||
export CGO_CXXFLAGS="$CXXFLAGS"
|
export CGO_CXXFLAGS="$CXXFLAGS"
|
||||||
export CGO_CPPFLAGS="$CPPFLAGS"
|
export CGO_CPPFLAGS="$CPPFLAGS"
|
||||||
export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
|
export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
|
||||||
./manifests/scripts/bundle.sh "${PWD}/manifests" "${PWD}/cmd/flux/manifests"
|
make cmd/flux/.manifests.done
|
||||||
go build -ldflags "-linkmode=external -X main.VERSION=${pkgver}" -o ${_srcname} ./cmd/flux
|
go build -ldflags "-linkmode=external -X main.VERSION=${pkgver}" -o ${_srcname} ./cmd/flux
|
||||||
}
|
}
|
||||||
|
|
||||||
check() {
|
check() {
|
||||||
cd "flux2-${pkgver}"
|
cd "flux2-${pkgver}"
|
||||||
|
case $CARCH in
|
||||||
|
aarch64)
|
||||||
|
export ENVTEST_ARCH=arm64
|
||||||
|
;;
|
||||||
|
armv6h|armv7h)
|
||||||
|
export ENVTEST_ARCH=arm
|
||||||
|
;;
|
||||||
|
esac
|
||||||
make test
|
make test
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
.github/aur/flux-scm/PKGBUILD.template
vendored
12
.github/aur/flux-scm/PKGBUILD.template
vendored
@@ -11,7 +11,7 @@ license=("APACHE")
|
|||||||
provides=("flux-bin")
|
provides=("flux-bin")
|
||||||
conflicts=("flux-bin")
|
conflicts=("flux-bin")
|
||||||
depends=("glibc")
|
depends=("glibc")
|
||||||
makedepends=('go>=1.16', 'kustomize>=3.0')
|
makedepends=('go>=1.17', 'kustomize>=3.0', 'git')
|
||||||
optdepends=('bash-completion: auto-completion for flux in Bash',
|
optdepends=('bash-completion: auto-completion for flux in Bash',
|
||||||
'zsh-completions: auto-completion for flux in ZSH')
|
'zsh-completions: auto-completion for flux in ZSH')
|
||||||
source=(
|
source=(
|
||||||
@@ -32,12 +32,20 @@ build() {
|
|||||||
export CGO_CXXFLAGS="$CXXFLAGS"
|
export CGO_CXXFLAGS="$CXXFLAGS"
|
||||||
export CGO_CPPFLAGS="$CPPFLAGS"
|
export CGO_CPPFLAGS="$CPPFLAGS"
|
||||||
export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
|
export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
|
||||||
make cmd/flux/manifests
|
make cmd/flux/.manifests.done
|
||||||
go build -ldflags "-linkmode=external -X main.VERSION=${pkgver}" -o ${_srcname} ./cmd/flux
|
go build -ldflags "-linkmode=external -X main.VERSION=${pkgver}" -o ${_srcname} ./cmd/flux
|
||||||
}
|
}
|
||||||
|
|
||||||
check() {
|
check() {
|
||||||
cd "flux2"
|
cd "flux2"
|
||||||
|
case $CARCH in
|
||||||
|
aarch64)
|
||||||
|
export ENVTEST_ARCH=arm64
|
||||||
|
;;
|
||||||
|
armv6h|armv7h)
|
||||||
|
export ENVTEST_ARCH=arm
|
||||||
|
;;
|
||||||
|
esac
|
||||||
make test
|
make test
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
74
.github/runners/README.md
vendored
74
.github/runners/README.md
vendored
@@ -1,42 +1,72 @@
|
|||||||
# Flux GitHub runners
|
# Flux ARM64 GitHub runners
|
||||||
|
|
||||||
How to provision GitHub Actions self-hosted runners for Flux conformance testing.
|
The Flux ARM64 end-to-end tests run on Equinix instances provisioned with Docker and GitHub self-hosted runners.
|
||||||
|
|
||||||
## ARM64 Instance specs
|
## Current instances
|
||||||
|
|
||||||
|
| Runner | Instance | Region |
|
||||||
|
|---------------|---------------------|--------|
|
||||||
|
| equinix-arm-1 | flux-equinix-arm-01 | AMS1 |
|
||||||
|
| equinix-arm-2 | flux-equinix-arm-01 | AMS1 |
|
||||||
|
| equinix-arm-3 | flux-equinix-arm-01 | AMS1 |
|
||||||
|
| equinix-arm-4 | flux-equinix-arm-02 | DFW2 |
|
||||||
|
| equinix-arm-5 | flux-equinix-arm-02 | DFW2 |
|
||||||
|
| equinix-arm-6 | flux-equinix-arm-02 | DFW2 |
|
||||||
|
|
||||||
|
## 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 an instance on Oracle Cloud with the following configuration:
|
first create a server on Equinix with the following configuration:
|
||||||
- OS: Canonical Ubuntu 20.04
|
- Type: c2.large.arm
|
||||||
- Shape: VM.Standard.A1.Flex
|
- OS: Ubuntu 20.04
|
||||||
- OCPU Count: 2
|
|
||||||
- Memory (GB): 12
|
|
||||||
- Network Bandwidth (Gbps): 2
|
|
||||||
- Local Disk: Block Storage Only
|
|
||||||
|
|
||||||
Note that the instance image source must be **Canonical Ubuntu** instead of the default Oracle Linux.
|
### Install prerequisites
|
||||||
|
|
||||||
## ARM64 Instance setup
|
|
||||||
|
|
||||||
- SSH into a newly created instance
|
- SSH into a newly created instance
|
||||||
```shell
|
```shell
|
||||||
ssh ubuntu@<instance-public-IP>
|
ssh root@<instance-public-IP>
|
||||||
```
|
```
|
||||||
- Create the action runner dir
|
|
||||||
|
- Create the ubuntu user
|
||||||
```shell
|
```shell
|
||||||
mkdir -p actions-runner && cd actions-runner
|
adduser ubuntu
|
||||||
|
usermod -aG sudo ubuntu
|
||||||
|
su - ubuntu
|
||||||
```
|
```
|
||||||
- Download the provisioning script
|
|
||||||
|
- Create the prerequisites dir
|
||||||
```shell
|
```shell
|
||||||
curl -sL https://raw.githubusercontent.com/fluxcd/flux2/main/.github/runners/arm64.sh > arm64.sh \
|
mkdir -p prereq && cd prereq
|
||||||
&& chmod +x ./arm64.sh
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- Download the prerequisites script
|
||||||
|
```shell
|
||||||
|
curl -sL https://raw.githubusercontent.com/fluxcd/flux2/main/.github/runners/prereq.sh > prereq.sh \
|
||||||
|
&& chmod +x ./prereq.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
- Install the prerequisites
|
||||||
|
```shell
|
||||||
|
sudo ./prereq.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Install runners
|
||||||
|
|
||||||
- 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)
|
||||||
- Run the provisioning script passing the token as the first argument
|
|
||||||
|
- Create 3 directories `runner1`, `runner2`, `runner3`
|
||||||
|
|
||||||
|
- In each dir run:
|
||||||
```shell
|
```shell
|
||||||
sudo ./arm64.sh <TOKEN>
|
curl -sL https://raw.githubusercontent.com/fluxcd/flux2/main/.github/runners/runner-setup.sh > runner-setup.sh \
|
||||||
|
&& chmod +x ./runner-setup.sh
|
||||||
|
|
||||||
|
./runner-setup.sh equinix-arm-<NUMBER> <TOKEN>
|
||||||
```
|
```
|
||||||
|
|
||||||
- Reboot the instance
|
- Reboot the instance
|
||||||
```shell
|
```shell
|
||||||
sudo reboot
|
sudo reboot
|
||||||
```
|
```
|
||||||
|
|
||||||
- Navigate to the GitHub repository [runners page](https://github.com/fluxcd/flux2/settings/actions/runners) and check the runner status
|
- Navigate to the GitHub repository [runners page](https://github.com/fluxcd/flux2/settings/actions/runners) and check the runner status
|
||||||
|
|||||||
@@ -14,20 +14,16 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
# This script is meant to be run locally and in CI to validate the Kubernetes
|
# This script installs the prerequisites for running Flux end-to-end tests with Docker and GitHub self-hosted runners.
|
||||||
# manifests (including Flux custom resources) before changes are merged into
|
|
||||||
# the branch synced by Flux in-cluster.
|
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
REPOSITORY_TOKEN=$1
|
|
||||||
REPOSITORY_URL=${2:-https://github.com/fluxcd/flux2}
|
|
||||||
|
|
||||||
KIND_VERSION=0.11.1
|
KIND_VERSION=0.11.1
|
||||||
KUBECTL_VERSION=1.21.2
|
KUBECTL_VERSION=1.21.2
|
||||||
KUSTOMIZE_VERSION=4.1.3
|
KUSTOMIZE_VERSION=4.1.3
|
||||||
GITHUB_RUNNER_VERSION=2.278.0
|
HELM_VERSION=3.7.2
|
||||||
PACKAGES="apt-transport-https ca-certificates software-properties-common build-essential libssl-dev gnupg lsb-release jq"
|
GITHUB_RUNNER_VERSION=2.285.1
|
||||||
|
PACKAGES="apt-transport-https ca-certificates software-properties-common build-essential libssl-dev gnupg lsb-release jq pkg-config"
|
||||||
|
|
||||||
# install prerequisites
|
# install prerequisites
|
||||||
apt-get update \
|
apt-get update \
|
||||||
@@ -57,6 +53,12 @@ curl -Lo ./kustomize.tar.gz https://github.com/kubernetes-sigs/kustomize/release
|
|||||||
&& rm kustomize.tar.gz
|
&& rm kustomize.tar.gz
|
||||||
install -o root -g root -m 0755 kustomize /usr/local/bin/kustomize
|
install -o root -g root -m 0755 kustomize /usr/local/bin/kustomize
|
||||||
|
|
||||||
|
# install helm
|
||||||
|
curl -Lo ./helm.tar.gz https://get.helm.sh/helm-v${HELM_VERSION}-linux-arm64.tar.gz \
|
||||||
|
&& tar -zxvf helm.tar.gz \
|
||||||
|
&& rm helm.tar.gz
|
||||||
|
install -o root -g root -m 0755 linux-arm64/helm /usr/local/bin/helm
|
||||||
|
|
||||||
# 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 \
|
||||||
&& tar xzf actions-runner-linux-arm64.tar.gz \
|
&& tar xzf actions-runner-linux-arm64.tar.gz \
|
||||||
@@ -64,10 +66,3 @@ curl -o actions-runner-linux-arm64.tar.gz -L https://github.com/actions/runner/r
|
|||||||
|
|
||||||
# install runner dependencies
|
# install runner dependencies
|
||||||
./bin/installdependencies.sh
|
./bin/installdependencies.sh
|
||||||
|
|
||||||
# register runner with GitHub
|
|
||||||
sudo -u ubuntu ./config.sh --unattended --url ${REPOSITORY_URL} --token ${REPOSITORY_TOKEN}
|
|
||||||
|
|
||||||
# start runner
|
|
||||||
./svc.sh install
|
|
||||||
./svc.sh start
|
|
||||||
37
.github/runners/runner-setup.sh
vendored
Executable file
37
.github/runners/runner-setup.sh
vendored
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Copyright 2021 The Flux authors. All rights reserved.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
# This script installs a GitHub self-hosted ARM64 runner for running Flux end-to-end tests.
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
RUNNER_NAME=$1
|
||||||
|
REPOSITORY_TOKEN=$2
|
||||||
|
REPOSITORY_URL=${3:-https://github.com/fluxcd/flux2}
|
||||||
|
|
||||||
|
GITHUB_RUNNER_VERSION=2.285.1
|
||||||
|
|
||||||
|
# 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 \
|
||||||
|
&& tar xzf actions-runner-linux-arm64.tar.gz \
|
||||||
|
&& rm actions-runner-linux-arm64.tar.gz
|
||||||
|
|
||||||
|
# register runner with GitHub
|
||||||
|
./config.sh --unattended --url ${REPOSITORY_URL} --token ${REPOSITORY_TOKEN} --name ${RUNNER_NAME}
|
||||||
|
|
||||||
|
# start runner
|
||||||
|
sudo ./svc.sh install
|
||||||
|
sudo ./svc.sh start
|
||||||
47
.github/workflows/bootstrap.yaml
vendored
47
.github/workflows/bootstrap.yaml
vendored
@@ -17,13 +17,13 @@ jobs:
|
|||||||
uses: actions/cache@v1
|
uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go1.16-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go1.17-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go1.16-
|
${{ runner.os }}-go1.17-
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.16.x
|
go-version: 1.17.x
|
||||||
- name: Setup Kubernetes
|
- name: Setup Kubernetes
|
||||||
uses: engineerd/setup-kind@v0.5.0
|
uses: engineerd/setup-kind@v0.5.0
|
||||||
with:
|
with:
|
||||||
@@ -64,6 +64,22 @@ jobs:
|
|||||||
--team=team-z
|
--team=team-z
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
|
||||||
|
- name: bootstrap customize
|
||||||
|
run: |
|
||||||
|
make setup-bootstrap-patch
|
||||||
|
/tmp/flux bootstrap github --manifests ./manifests/install/ \
|
||||||
|
--owner=fluxcd-testing \
|
||||||
|
--repository=${{ steps.vars.outputs.test_repo_name }} \
|
||||||
|
--branch=main \
|
||||||
|
--path=test-cluster \
|
||||||
|
--team=team-z
|
||||||
|
if [ $(kubectl get deployments.apps source-controller -o jsonpath='{.spec.template.spec.securityContext.runAsUser}') != "10000" ]; then
|
||||||
|
echo "Bootstrap not customized as controller is not running as user 10000" && exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
|
||||||
|
GITHUB_REPO_NAME: ${{ steps.vars.outputs.test_repo_name }}
|
||||||
|
GITHUB_ORG_NAME: fluxcd-testing
|
||||||
- name: libgit2
|
- name: libgit2
|
||||||
run: |
|
run: |
|
||||||
/tmp/flux create source git test-libgit2 \
|
/tmp/flux create source git test-libgit2 \
|
||||||
@@ -75,17 +91,38 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
/tmp/flux uninstall -s --keep-namespace
|
/tmp/flux uninstall -s --keep-namespace
|
||||||
kubectl delete ns flux-system --timeout=10m --wait=true
|
kubectl delete ns flux-system --timeout=10m --wait=true
|
||||||
- name: bootstrap reinstall
|
- name: test image automation
|
||||||
run: |
|
run: |
|
||||||
|
make setup-image-automation
|
||||||
/tmp/flux bootstrap github --manifests ./manifests/install/ \
|
/tmp/flux bootstrap github --manifests ./manifests/install/ \
|
||||||
--owner=fluxcd-testing \
|
--owner=fluxcd-testing \
|
||||||
--repository=${{ steps.vars.outputs.test_repo_name }} \
|
--repository=${{ steps.vars.outputs.test_repo_name }} \
|
||||||
--branch=main \
|
--branch=main \
|
||||||
--path=test-cluster \
|
--path=test-cluster \
|
||||||
--team=team-z
|
--read-write-key
|
||||||
|
/tmp/flux reconcile image repository podinfo
|
||||||
|
/tmp/flux reconcile image update flux-system
|
||||||
|
/tmp/flux get images all
|
||||||
|
|
||||||
|
retries=10
|
||||||
|
count=0
|
||||||
|
ok=false
|
||||||
|
until ${ok}; do
|
||||||
|
/tmp/flux get image update flux-system | grep 'commit' && ok=true || ok=false
|
||||||
|
count=$(($count + 1))
|
||||||
|
if [[ ${count} -eq ${retries} ]]; then
|
||||||
|
echo "No more retries left"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sleep 6
|
||||||
|
/tmp/flux reconcile image update flux-system
|
||||||
|
done
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
|
||||||
|
GITHUB_REPO_NAME: ${{ steps.vars.outputs.test_repo_name }}
|
||||||
|
GITHUB_ORG_NAME: fluxcd-testing
|
||||||
- name: delete repository
|
- name: delete repository
|
||||||
|
if: ${{ always() }}
|
||||||
run: |
|
run: |
|
||||||
curl \
|
curl \
|
||||||
-X DELETE \
|
-X DELETE \
|
||||||
|
|||||||
11
.github/workflows/e2e-arm64.yaml
vendored
11
.github/workflows/e2e-arm64.yaml
vendored
@@ -3,21 +3,20 @@ name: e2e-arm64
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches: [ main, update-components, arm64-e2e ]
|
branches: [ main, update-components, equinix-runners ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
ampere:
|
test:
|
||||||
# Runner info
|
# Hosted on Equinix
|
||||||
# Owner: Stefan Prodan
|
|
||||||
# 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]
|
runs-on: [self-hosted, Linux, ARM64, equinix]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.16.x
|
go-version: 1.17.x
|
||||||
- name: Prepare
|
- name: Prepare
|
||||||
id: prep
|
id: prep
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
6
.github/workflows/e2e-azure.yaml
vendored
6
.github/workflows/e2e-azure.yaml
vendored
@@ -17,13 +17,13 @@ jobs:
|
|||||||
uses: actions/cache@v1
|
uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go1.16-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go1.17-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go1.16-
|
${{ runner.os }}-go1.17-
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.16.x
|
go-version: 1.17.x
|
||||||
- name: Install libgit2
|
- name: Install libgit2
|
||||||
run: |
|
run: |
|
||||||
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138
|
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138
|
||||||
|
|||||||
30
.github/workflows/e2e.yaml
vendored
30
.github/workflows/e2e.yaml
vendored
@@ -2,7 +2,7 @@ name: e2e
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ main, e2e* ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
|
|
||||||
@@ -16,26 +16,22 @@ jobs:
|
|||||||
uses: actions/cache@v1
|
uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go1.16-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go1.17-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go1.16-
|
${{ runner.os }}-go1.17-
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.16.x
|
go-version: 1.17.x
|
||||||
- name: Setup Kubernetes
|
- name: Setup Kubernetes
|
||||||
uses: engineerd/setup-kind@v0.5.0
|
uses: engineerd/setup-kind@v0.5.0
|
||||||
with:
|
with:
|
||||||
version: v0.11.1
|
version: v0.11.1
|
||||||
image: kindest/node:v1.19.11@sha256:07db187ae84b4b7de440a73886f008cf903fcf5764ba8106a9fd5243d6f32729
|
image: kindest/node:v1.20.7
|
||||||
config: .github/kind/config.yaml # disable KIND-net
|
config: .github/kind/config.yaml # disable KIND-net
|
||||||
- name: Setup envtest
|
|
||||||
uses: fluxcd/pkg/actions/envtest@main
|
|
||||||
with:
|
|
||||||
version: "1.21.x"
|
|
||||||
- name: Setup Calico for network policy
|
- name: Setup Calico for network policy
|
||||||
run: |
|
run: |
|
||||||
kubectl apply -f https://docs.projectcalico.org/v3.16/manifests/calico.yaml
|
kubectl apply -f https://docs.projectcalico.org/v3.20/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
|
||||||
@@ -80,6 +76,13 @@ jobs:
|
|||||||
--tag-semver=">=3.2.3" \
|
--tag-semver=">=3.2.3" \
|
||||||
--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
|
||||||
@@ -184,7 +187,14 @@ jobs:
|
|||||||
/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/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
|
||||||
|
- name: flux tree
|
||||||
|
run: |
|
||||||
|
/tmp/flux tree kustomization flux-system | grep Service/podinfo
|
||||||
- name: flux check
|
- name: flux check
|
||||||
run: |
|
run: |
|
||||||
/tmp/flux check
|
/tmp/flux check
|
||||||
|
|||||||
46
.github/workflows/release.yaml
vendored
46
.github/workflows/release.yaml
vendored
@@ -4,6 +4,11 @@ on:
|
|||||||
push:
|
push:
|
||||||
tags: [ 'v*' ]
|
tags: [ 'v*' ]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write # needed to write releases
|
||||||
|
id-token: write # needed for keyless signing
|
||||||
|
packages: write # needed for ghcr access
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
goreleaser:
|
goreleaser:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -15,16 +20,18 @@ jobs:
|
|||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.16.x
|
go-version: 1.17.x
|
||||||
- name: Setup QEMU
|
- name: Setup QEMU
|
||||||
uses: docker/setup-qemu-action@v1
|
uses: docker/setup-qemu-action@v1
|
||||||
with:
|
|
||||||
platforms: all
|
|
||||||
- name: Setup Docker Buildx
|
- name: Setup Docker Buildx
|
||||||
id: buildx
|
id: buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v1
|
||||||
with:
|
- name: Setup Syft
|
||||||
buildkitd-flags: "--debug"
|
uses: anchore/sbom-action/download-syft@v0
|
||||||
|
- name: Setup Cosign
|
||||||
|
uses: sigstore/cosign-installer@main
|
||||||
|
- name: Setup Kustomize
|
||||||
|
uses: fluxcd/pkg//actions/kustomize@main
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v1
|
||||||
with:
|
with:
|
||||||
@@ -36,18 +43,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
username: fluxcdbot
|
username: fluxcdbot
|
||||||
password: ${{ secrets.DOCKER_FLUXCD_PASSWORD }}
|
password: ${{ secrets.DOCKER_FLUXCD_PASSWORD }}
|
||||||
- name: Download release notes utility
|
|
||||||
env:
|
|
||||||
GH_REL_URL: https://github.com/buchanae/github-release-notes/releases/download/0.2.0/github-release-notes-linux-amd64-0.2.0.tar.gz
|
|
||||||
run: cd /tmp && curl -sSL ${GH_REL_URL} | tar xz && sudo mv github-release-notes /usr/local/bin/
|
|
||||||
- name: Generate release notes
|
|
||||||
run: |
|
|
||||||
echo 'CHANGELOG' > /tmp/release.txt
|
|
||||||
github-release-notes -org fluxcd -repo toolkit -since-latest-release -include-author >> /tmp/release.txt
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
- name: Setup Kustomize
|
|
||||||
uses: fluxcd/pkg//actions/kustomize@main
|
|
||||||
- name: Generate manifests
|
- name: Generate manifests
|
||||||
run: |
|
run: |
|
||||||
make cmd/flux/.manifests.done
|
make cmd/flux/.manifests.done
|
||||||
@@ -56,19 +51,32 @@ 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@main
|
uses: fluxcd/pkg//actions/crdjsonschema@49e26aa2ee9e734c3233c560253fd9542afe18ae
|
||||||
with:
|
with:
|
||||||
crd: all-crds.yaml
|
crd: all-crds.yaml
|
||||||
output: schemas
|
output: schemas
|
||||||
- name: Archive the OpenAPI JSON schemas
|
- name: Archive the OpenAPI JSON schemas
|
||||||
run: |
|
run: |
|
||||||
tar -czvf ./output/crd-schemas.tar.gz -C schemas .
|
tar -czvf ./output/crd-schemas.tar.gz -C schemas .
|
||||||
|
- name: Download release notes utility
|
||||||
|
env:
|
||||||
|
GH_REL_URL: https://github.com/buchanae/github-release-notes/releases/download/0.2.0/github-release-notes-linux-amd64-0.2.0.tar.gz
|
||||||
|
run: cd /tmp && curl -sSL ${GH_REL_URL} | tar xz && sudo mv github-release-notes /usr/local/bin/
|
||||||
|
- name: Generate release notes
|
||||||
|
run: |
|
||||||
|
NOTES="./output/notes.md"
|
||||||
|
echo '## CLI Changelog' > ${NOTES}
|
||||||
|
github-release-notes -org fluxcd -repo flux2 -since-latest-release -include-author >> ${NOTES}
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Run GoReleaser
|
- name: Run GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@v1
|
uses: goreleaser/goreleaser-action@v1
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
args: release --release-notes=/tmp/release.txt --skip-validate
|
args: release --release-notes=output/notes.md --skip-validate
|
||||||
env:
|
env:
|
||||||
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 }}
|
||||||
|
|||||||
2
.github/workflows/update.yaml
vendored
2
.github/workflows/update.yaml
vendored
@@ -16,7 +16,7 @@ jobs:
|
|||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.16.x
|
go-version: 1.17.x
|
||||||
- name: Update component versions
|
- name: Update component versions
|
||||||
id: update
|
id: update
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -20,6 +20,7 @@ bin/
|
|||||||
output/
|
output/
|
||||||
cmd/flux/manifests/
|
cmd/flux/manifests/
|
||||||
cmd/flux/.manifests.done
|
cmd/flux/.manifests.done
|
||||||
|
testbin/
|
||||||
|
|
||||||
# Docs
|
# Docs
|
||||||
site/
|
site/
|
||||||
|
|||||||
@@ -40,6 +40,36 @@ archives:
|
|||||||
format: zip
|
format: zip
|
||||||
files:
|
files:
|
||||||
- none*
|
- none*
|
||||||
|
source:
|
||||||
|
enabled: true
|
||||||
|
name_template: '{{ .ProjectName }}_{{ .Version }}_source_code'
|
||||||
|
sboms:
|
||||||
|
- id: source
|
||||||
|
artifacts: source
|
||||||
|
documents:
|
||||||
|
- "{{ .ProjectName }}_{{ .Version }}_sbom.spdx.json"
|
||||||
|
release:
|
||||||
|
extra_files:
|
||||||
|
- glob: output/crd-schemas.tar.gz
|
||||||
|
- glob: output/manifests.tar.gz
|
||||||
|
- glob: output/install.yaml
|
||||||
|
checksum:
|
||||||
|
extra_files:
|
||||||
|
- glob: output/crd-schemas.tar.gz
|
||||||
|
- glob: output/manifests.tar.gz
|
||||||
|
- glob: output/install.yaml
|
||||||
|
signs:
|
||||||
|
- cmd: cosign
|
||||||
|
env:
|
||||||
|
- COSIGN_EXPERIMENTAL=1
|
||||||
|
certificate: '${artifact}.pem'
|
||||||
|
args:
|
||||||
|
- sign-blob
|
||||||
|
- '--output-certificate=${certificate}'
|
||||||
|
- '--output-signature=${signature}'
|
||||||
|
- '${artifact}'
|
||||||
|
artifacts: checksum
|
||||||
|
output: true
|
||||||
brews:
|
brews:
|
||||||
- name: flux
|
- name: flux
|
||||||
tap:
|
tap:
|
||||||
@@ -78,17 +108,12 @@ publishers:
|
|||||||
- AUR_BOT_SSH_PRIVATE_KEY={{ .Env.AUR_BOT_SSH_PRIVATE_KEY }}
|
- AUR_BOT_SSH_PRIVATE_KEY={{ .Env.AUR_BOT_SSH_PRIVATE_KEY }}
|
||||||
cmd: |
|
cmd: |
|
||||||
.github/aur/flux-go/publish.sh {{ .Version }}
|
.github/aur/flux-go/publish.sh {{ .Version }}
|
||||||
release:
|
|
||||||
extra_files:
|
|
||||||
- glob: ./output/crd-schemas.tar.gz
|
|
||||||
- glob: ./output/manifests.tar.gz
|
|
||||||
- glob: ./output/install.yaml
|
|
||||||
dockers:
|
dockers:
|
||||||
- image_templates:
|
- image_templates:
|
||||||
- 'fluxcd/flux-cli:{{ .Tag }}-amd64'
|
- 'fluxcd/flux-cli:{{ .Tag }}-amd64'
|
||||||
- 'ghcr.io/fluxcd/flux-cli:{{ .Tag }}-amd64'
|
- 'ghcr.io/fluxcd/flux-cli:{{ .Tag }}-amd64'
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
use_buildx: true
|
use: buildx
|
||||||
goos: linux
|
goos: linux
|
||||||
goarch: amd64
|
goarch: amd64
|
||||||
build_flag_templates:
|
build_flag_templates:
|
||||||
@@ -104,7 +129,7 @@ dockers:
|
|||||||
- 'fluxcd/flux-cli:{{ .Tag }}-arm64'
|
- 'fluxcd/flux-cli:{{ .Tag }}-arm64'
|
||||||
- 'ghcr.io/fluxcd/flux-cli:{{ .Tag }}-arm64'
|
- 'ghcr.io/fluxcd/flux-cli:{{ .Tag }}-arm64'
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
use_buildx: true
|
use: buildx
|
||||||
goos: linux
|
goos: linux
|
||||||
goarch: arm64
|
goarch: arm64
|
||||||
build_flag_templates:
|
build_flag_templates:
|
||||||
@@ -120,7 +145,7 @@ dockers:
|
|||||||
- 'fluxcd/flux-cli:{{ .Tag }}-arm'
|
- 'fluxcd/flux-cli:{{ .Tag }}-arm'
|
||||||
- 'ghcr.io/fluxcd/flux-cli:{{ .Tag }}-arm'
|
- 'ghcr.io/fluxcd/flux-cli:{{ .Tag }}-arm'
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
use_buildx: true
|
use: buildx
|
||||||
goos: linux
|
goos: linux
|
||||||
goarch: arm
|
goarch: arm
|
||||||
goarm: 7
|
goarm: 7
|
||||||
@@ -144,3 +169,12 @@ docker_manifests:
|
|||||||
- 'ghcr.io/fluxcd/flux-cli:{{ .Tag }}-amd64'
|
- 'ghcr.io/fluxcd/flux-cli:{{ .Tag }}-amd64'
|
||||||
- 'ghcr.io/fluxcd/flux-cli:{{ .Tag }}-arm64'
|
- 'ghcr.io/fluxcd/flux-cli:{{ .Tag }}-arm64'
|
||||||
- 'ghcr.io/fluxcd/flux-cli:{{ .Tag }}-arm'
|
- 'ghcr.io/fluxcd/flux-cli:{{ .Tag }}-arm'
|
||||||
|
docker_signs:
|
||||||
|
- cmd: cosign
|
||||||
|
env:
|
||||||
|
- COSIGN_EXPERIMENTAL=1
|
||||||
|
args:
|
||||||
|
- sign
|
||||||
|
- '${artifact}'
|
||||||
|
artifacts: all
|
||||||
|
output: true
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ you can sign your commit automatically with `git commit -s`.
|
|||||||
|
|
||||||
For realtime communications we use Slack: To join the conversation, simply
|
For realtime communications we use Slack: To join the conversation, simply
|
||||||
join the [CNCF](https://slack.cncf.io/) Slack workspace and use the
|
join the [CNCF](https://slack.cncf.io/) Slack workspace and use the
|
||||||
[#flux-dev](https://cloud-native.slack.com/messages/flux-dev/) channel.
|
[#flux-contributors](https://cloud-native.slack.com/messages/flux-contributors/) channel.
|
||||||
|
|
||||||
To discuss ideas and specifications we use [Github
|
To discuss ideas and specifications we use [Github
|
||||||
Discussions](https://github.com/fluxcd/flux2/discussions).
|
Discussions](https://github.com/fluxcd/flux2/discussions).
|
||||||
@@ -63,27 +63,42 @@ To get started with developing controllers, you might want to review
|
|||||||
walks you through writing a short and concise controller that watches out
|
walks you through writing a short and concise controller that watches out
|
||||||
for source changes.
|
for source changes.
|
||||||
|
|
||||||
### How to run the test suite
|
## How to run the test suite
|
||||||
|
|
||||||
Prerequisites:
|
Prerequisites:
|
||||||
|
|
||||||
* go >= 1.16
|
* go >= 1.17
|
||||||
* kubectl >= 1.18
|
* kubectl >= 1.20
|
||||||
* kustomize >= 3.1
|
* kustomize >= 4.4
|
||||||
|
|
||||||
You can run the unit tests by simply doing
|
Install the [controller-runtime/envtest](https://github.com/kubernetes-sigs/controller-runtime/tree/master/tools/setup-envtest) binaries with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make install-envtest
|
||||||
|
```
|
||||||
|
|
||||||
|
Then you can run the unit tests with:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make test
|
make test
|
||||||
```
|
```
|
||||||
|
|
||||||
The e2e test suite uses [kind](https://kind.sigs.k8s.io/) for running kubernetes cluster inside docker containers. You can run the e2e tests by simply doing
|
After [installing Kubernetes kind](https://kind.sigs.k8s.io/docs/user/quick-start#installation) on your machine,
|
||||||
|
create a cluster for testing with:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make setup-kind
|
make setup-kind
|
||||||
make e2e
|
```
|
||||||
|
|
||||||
# When done
|
Then you can run the end-to-end tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make e2e
|
||||||
|
```
|
||||||
|
|
||||||
|
Teardown the e2e environment with:
|
||||||
|
|
||||||
|
```bash
|
||||||
make cleanup-kind
|
make cleanup-kind
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
FROM alpine:3.13 as builder
|
FROM alpine:3.15 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.22.2
|
ARG KUBECTL_VER=1.23.1
|
||||||
|
|
||||||
RUN curl -sL https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VER}/bin/${ARCH}/kubectl \
|
RUN curl -sL https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VER}/bin/${ARCH}/kubectl \
|
||||||
-o /usr/local/bin/kubectl && chmod +x /usr/local/bin/kubectl && \
|
-o /usr/local/bin/kubectl && chmod +x /usr/local/bin/kubectl && \
|
||||||
kubectl version --client=true
|
kubectl version --client=true
|
||||||
|
|
||||||
FROM alpine:3.13 as flux-cli
|
FROM alpine:3.15 as flux-cli
|
||||||
|
|
||||||
# Create minimal nsswitch.conf file to prioritize the usage of /etc/hosts over DNS queries.
|
# 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
|
# https://github.com/gliderlabs/docker-alpine/issues/367#issuecomment-354316460
|
||||||
@@ -20,4 +20,5 @@ RUN apk add --no-cache ca-certificates
|
|||||||
COPY --from=builder /usr/local/bin/kubectl /usr/local/bin/
|
COPY --from=builder /usr/local/bin/kubectl /usr/local/bin/
|
||||||
COPY --chmod=755 flux /usr/local/bin/
|
COPY --chmod=755 flux /usr/local/bin/
|
||||||
|
|
||||||
|
USER 65534:65534
|
||||||
ENTRYPOINT [ "flux" ]
|
ENTRYPOINT [ "flux" ]
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ should.
|
|||||||
|
|
||||||
In alphabetical order:
|
In alphabetical order:
|
||||||
|
|
||||||
Aurel Canciu, Sortlist <aurel@sortlist.com> (github: @relu, slack: relu)
|
Aurel Canciu, NexHealth <aurel.canciu@nexhealth.com> (github: @relu, slack: relu)
|
||||||
Hidde Beydals, Weaveworks <hidde@weave.works> (github: @hiddeco, slack: hidde)
|
Hidde Beydals, Weaveworks <hidde@weave.works> (github: @hiddeco, slack: hidde)
|
||||||
|
Max Jonas Werner, D2iQ <max@e13.dev> (github: @makkes, slack: max)
|
||||||
Philip Laine, Xenit <philip.laine@xenit.se> (github: @phillebaba, slack: phillebaba)
|
Philip Laine, Xenit <philip.laine@xenit.se> (github: @phillebaba, slack: phillebaba)
|
||||||
Stefan Prodan, Weaveworks <stefan@weave.works> (github: @stefanprodan, slack: stefanprodan)
|
Stefan Prodan, Weaveworks <stefan@weave.works> (github: @stefanprodan, slack: stefanprodan)
|
||||||
|
Sunny, Weaveworks <sunny@weave.works> (github: @darkowlzz, slack: darkowlzz)
|
||||||
|
|||||||
60
Makefile
60
Makefile
@@ -1,8 +1,8 @@
|
|||||||
VERSION?=$(shell grep 'VERSION' cmd/flux/main.go | awk '{ print $$4 }' | head -n 1 | tr -d '"')
|
VERSION?=$(shell grep 'VERSION' cmd/flux/main.go | awk '{ print $$4 }' | head -n 1 | tr -d '"')
|
||||||
EMBEDDED_MANIFESTS_TARGET=cmd/flux/.manifests.done
|
EMBEDDED_MANIFESTS_TARGET=cmd/flux/.manifests.done
|
||||||
TEST_KUBECONFIG?=/tmp/flux-e2e-test-kubeconfig
|
TEST_KUBECONFIG?=/tmp/flux-e2e-test-kubeconfig
|
||||||
ENVTEST_BIN_VERSION?=latest
|
# Architecture to use envtest with
|
||||||
KUBEBUILDER_ASSETS?="$(shell $(SETUP_ENVTEST) use -i $(ENVTEST_BIN_VERSION) -p path)"
|
ENVTEST_ARCH ?= amd64
|
||||||
|
|
||||||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
|
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
|
||||||
ifeq (,$(shell go env GOBIN))
|
ifeq (,$(shell go env GOBIN))
|
||||||
@@ -17,6 +17,7 @@ all: test build
|
|||||||
|
|
||||||
tidy:
|
tidy:
|
||||||
go mod tidy
|
go mod tidy
|
||||||
|
cd tests/azure && go mod tidy
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
@@ -33,13 +34,14 @@ cleanup-kind:
|
|||||||
kind delete cluster --name=flux-e2e-test
|
kind delete cluster --name=flux-e2e-test
|
||||||
rm $(TEST_KUBECONFIG)
|
rm $(TEST_KUBECONFIG)
|
||||||
|
|
||||||
test: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet setup-envtest
|
KUBEBUILDER_ASSETS?="$(shell $(ENVTEST) --arch=$(ENVTEST_ARCH) use -i $(ENVTEST_KUBERNETES_VERSION) --bin-dir=$(ENVTEST_ASSETS_DIR) -p path)"
|
||||||
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./... -coverprofile cover.out --tags=unit
|
test: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet install-envtest
|
||||||
|
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... -coverprofile cover.out --tags=unit
|
||||||
|
|
||||||
e2e: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet
|
e2e: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet
|
||||||
TEST_KUBECONFIG=$(TEST_KUBECONFIG) go test ./cmd/flux/... -coverprofile e2e.cover.out --tags=e2e -v -failfast
|
TEST_KUBECONFIG=$(TEST_KUBECONFIG) go test ./cmd/flux/... -coverprofile e2e.cover.out --tags=e2e -v -failfast
|
||||||
|
|
||||||
test-with-kind: setup-envtest
|
test-with-kind: install-envtest
|
||||||
make setup-kind
|
make setup-kind
|
||||||
make e2e
|
make e2e
|
||||||
make cleanup-kind
|
make cleanup-kind
|
||||||
@@ -51,24 +53,40 @@ $(EMBEDDED_MANIFESTS_TARGET): $(call rwildcard,manifests/,*.yaml *.json)
|
|||||||
build: $(EMBEDDED_MANIFESTS_TARGET)
|
build: $(EMBEDDED_MANIFESTS_TARGET)
|
||||||
CGO_ENABLED=0 go build -ldflags="-s -w -X main.VERSION=$(VERSION)" -o ./bin/flux ./cmd/flux
|
CGO_ENABLED=0 go build -ldflags="-s -w -X main.VERSION=$(VERSION)" -o ./bin/flux ./cmd/flux
|
||||||
|
|
||||||
|
.PHONY: install
|
||||||
install:
|
install:
|
||||||
go install cmd/flux
|
CGO_ENABLED=0 go install ./cmd/flux
|
||||||
|
|
||||||
install-dev:
|
install-dev:
|
||||||
CGO_ENABLED=0 go build -o /usr/local/bin ./cmd/flux
|
CGO_ENABLED=0 go build -o /usr/local/bin ./cmd/flux
|
||||||
|
|
||||||
# Find or download setup-envtest
|
setup-bootstrap-patch:
|
||||||
setup-envtest:
|
go run ./tests/bootstrap/main.go
|
||||||
ifeq (, $(shell which setup-envtest))
|
|
||||||
@{ \
|
setup-image-automation:
|
||||||
set -e ;\
|
cd tests/image-automation && go run main.go
|
||||||
SETUP_ENVTEST_TMP_DIR=$$(mktemp -d) ;\
|
|
||||||
cd $$SETUP_ENVTEST_TMP_DIR ;\
|
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
|
||||||
go mod init tmp ;\
|
ENVTEST_KUBERNETES_VERSION?=latest
|
||||||
go get sigs.k8s.io/controller-runtime/tools/setup-envtest@latest ;\
|
install-envtest: setup-envtest
|
||||||
rm -rf $$SETUP_ENVTEST_TMP_DIR ;\
|
mkdir -p ${ENVTEST_ASSETS_DIR}
|
||||||
}
|
$(ENVTEST) use $(ENVTEST_KUBERNETES_VERSION) --arch=$(ENVTEST_ARCH) --bin-dir=$(ENVTEST_ASSETS_DIR)
|
||||||
SETUP_ENVTEST=$(GOBIN)/setup-envtest
|
|
||||||
else
|
ENVTEST = $(shell pwd)/bin/setup-envtest
|
||||||
SETUP_ENVTEST=$(shell which setup-envtest)
|
.PHONY: envtest
|
||||||
endif
|
setup-envtest: ## Download envtest-setup locally if necessary.
|
||||||
|
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
|
||||||
|
|
||||||
|
# go-install-tool will 'go install' any package $2 and install it to $1.
|
||||||
|
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
|
||||||
|
define go-install-tool
|
||||||
|
@[ -f $(1) ] || { \
|
||||||
|
set -e ;\
|
||||||
|
TMP_DIR=$$(mktemp -d) ;\
|
||||||
|
cd $$TMP_DIR ;\
|
||||||
|
go mod init tmp ;\
|
||||||
|
echo "Downloading $(2)" ;\
|
||||||
|
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
|
||||||
|
rm -rf $$TMP_DIR ;\
|
||||||
|
}
|
||||||
|
endef
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ inputs:
|
|||||||
description: "arch can be amd64, arm64 or arm"
|
description: "arch can be amd64, arm64 or arm"
|
||||||
required: true
|
required: true
|
||||||
default: "amd64"
|
default: "amd64"
|
||||||
|
bindir:
|
||||||
|
description: "Optional location of the Flux binary. Will not use sudo if set. Updates System Path."
|
||||||
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
@@ -29,10 +32,16 @@ runs:
|
|||||||
curl -sL ${BIN_URL} -o /tmp/flux.tar.gz
|
curl -sL ${BIN_URL} -o /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: "Add flux binary to /usr/local/bin"
|
- name: "Copy Flux binary to execute location"
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
sudo cp /tmp/flux/flux /usr/local/bin
|
BINDIR=${{ inputs.bindir }}
|
||||||
|
if [ -z $BINDIR ]; then
|
||||||
|
sudo cp /tmp/flux/flux /usr/local/bin
|
||||||
|
else
|
||||||
|
cp /tmp/flux/flux "${BINDIR}"
|
||||||
|
echo "${BINDIR}" >> $GITHUB_PATH
|
||||||
|
fi
|
||||||
- name: "Cleanup tmp"
|
- name: "Cleanup tmp"
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ import (
|
|||||||
// notificationv1.Alert
|
// notificationv1.Alert
|
||||||
|
|
||||||
var alertType = apiType{
|
var alertType = apiType{
|
||||||
kind: notificationv1.AlertKind,
|
kind: notificationv1.AlertKind,
|
||||||
humanKind: "alert",
|
humanKind: "alert",
|
||||||
|
groupVersion: notificationv1.GroupVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
type alertAdapter struct {
|
type alertAdapter struct {
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ import (
|
|||||||
// notificationv1.Provider
|
// notificationv1.Provider
|
||||||
|
|
||||||
var alertProviderType = apiType{
|
var alertProviderType = apiType{
|
||||||
kind: notificationv1.ProviderKind,
|
kind: notificationv1.ProviderKind,
|
||||||
humanKind: "alert provider",
|
humanKind: "alert provider",
|
||||||
|
groupVersion: notificationv1.GroupVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
type alertProviderAdapter struct {
|
type alertProviderAdapter struct {
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ func NewBootstrapFlags() bootstrapFlags {
|
|||||||
return bootstrapFlags{
|
return bootstrapFlags{
|
||||||
logLevel: flags.LogLevel(rootArgs.defaults.LogLevel),
|
logLevel: flags.LogLevel(rootArgs.defaults.LogLevel),
|
||||||
requiredComponents: []string{"source-controller", "kustomize-controller"},
|
requiredComponents: []string{"source-controller", "kustomize-controller"},
|
||||||
keyAlgorithm: flags.PublicKeyAlgorithm(sourcesecret.RSAPrivateKeyAlgorithm),
|
keyAlgorithm: flags.PublicKeyAlgorithm(sourcesecret.ECDSAPrivateKeyAlgorithm),
|
||||||
keyRSABits: 2048,
|
keyRSABits: 2048,
|
||||||
keyECDSACurve: flags.ECDSACurve{Curve: elliptic.P384()},
|
keyECDSACurve: flags.ECDSACurve{Curve: elliptic.P384()},
|
||||||
}
|
}
|
||||||
|
|||||||
280
cmd/flux/bootstrap_bitbucket_server.go
Normal file
280
cmd/flux/bootstrap_bitbucket_server.go
Normal file
@@ -0,0 +1,280 @@
|
|||||||
|
/*
|
||||||
|
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"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
||||||
|
"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/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
var bootstrapBServerCmd = &cobra.Command{
|
||||||
|
Use: "bitbucket-server",
|
||||||
|
Short: "Bootstrap toolkit components in a Bitbucket Server repository",
|
||||||
|
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.
|
||||||
|
Then it configures the target cluster to synchronize with the repository.
|
||||||
|
If the toolkit components are present on the cluster,
|
||||||
|
the bootstrap command will perform an upgrade if needed.`,
|
||||||
|
Example: ` # Create a Bitbucket Server API token and export it as an env var
|
||||||
|
export BITBUCKET_TOKEN=<my-token>
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Run bootstrap for a private repository using SSH authentication
|
||||||
|
flux bootstrap bitbucket-server --owner=<project> --username=<user> --repository=<repository name> --hostname=<domain>
|
||||||
|
|
||||||
|
# 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
|
||||||
|
flux bootstrap bitbucket-server --owner=<user> --repository=<repository name> --private=false --personal --hostname=<domain> --token-auth
|
||||||
|
|
||||||
|
# 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`,
|
||||||
|
RunE: bootstrapBServerCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
bServerDefaultPermission = "push"
|
||||||
|
bServerTokenEnvVar = "BITBUCKET_TOKEN"
|
||||||
|
)
|
||||||
|
|
||||||
|
type bServerFlags struct {
|
||||||
|
owner string
|
||||||
|
repository string
|
||||||
|
interval time.Duration
|
||||||
|
personal bool
|
||||||
|
username string
|
||||||
|
private bool
|
||||||
|
hostname string
|
||||||
|
path flags.SafeRelativePath
|
||||||
|
teams []string
|
||||||
|
readWriteKey bool
|
||||||
|
reconcile bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var bServerArgs bServerFlags
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
bootstrapBServerCmd.Flags().StringVar(&bServerArgs.owner, "owner", "", "Bitbucket Server user or project name")
|
||||||
|
bootstrapBServerCmd.Flags().StringVar(&bServerArgs.repository, "repository", "", "Bitbucket Server repository name")
|
||||||
|
bootstrapBServerCmd.Flags().StringSliceVar(&bServerArgs.teams, "group", []string{}, "Bitbucket Server groups to be given write access (also accepts comma-separated values)")
|
||||||
|
bootstrapBServerCmd.Flags().BoolVar(&bServerArgs.personal, "personal", false, "if true, the owner is assumed to be a Bitbucket Server user; otherwise a group")
|
||||||
|
bootstrapBServerCmd.Flags().StringVarP(&bServerArgs.username, "username", "u", "git", "authentication username")
|
||||||
|
bootstrapBServerCmd.Flags().BoolVar(&bServerArgs.private, "private", true, "if true, the repository is setup or configured as private")
|
||||||
|
bootstrapBServerCmd.Flags().DurationVar(&bServerArgs.interval, "interval", time.Minute, "sync interval")
|
||||||
|
bootstrapBServerCmd.Flags().StringVar(&bServerArgs.hostname, "hostname", "", "Bitbucket Server hostname")
|
||||||
|
bootstrapBServerCmd.Flags().Var(&bServerArgs.path, "path", "path relative to the repository root, when specified the cluster sync will be scoped to this path")
|
||||||
|
bootstrapBServerCmd.Flags().BoolVar(&bServerArgs.readWriteKey, "read-write-key", false, "if true, the deploy key is configured with read/write permissions")
|
||||||
|
bootstrapBServerCmd.Flags().BoolVar(&bServerArgs.reconcile, "reconcile", false, "if true, the configured options are also reconciled if the repository already exists")
|
||||||
|
|
||||||
|
bootstrapCmd.AddCommand(bootstrapBServerCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func bootstrapBServerCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
bitbucketToken := os.Getenv(bServerTokenEnvVar)
|
||||||
|
if bitbucketToken == "" {
|
||||||
|
var err error
|
||||||
|
bitbucketToken, err = readPasswordFromStdin("Please enter your Bitbucket personal access token (PAT): ")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not read token: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if bServerArgs.hostname == "" {
|
||||||
|
return fmt.Errorf("invalid hostname %q", bServerArgs.hostname)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := bootstrapValidate(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Manifest base
|
||||||
|
if ver, err := getVersion(bootstrapArgs.version); err == nil {
|
||||||
|
bootstrapArgs.version = ver
|
||||||
|
}
|
||||||
|
manifestsBase, err := buildEmbeddedManifestBase()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(manifestsBase)
|
||||||
|
|
||||||
|
user := bServerArgs.username
|
||||||
|
if bServerArgs.personal {
|
||||||
|
user = bServerArgs.owner
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build Bitbucket Server provider
|
||||||
|
providerCfg := provider.Config{
|
||||||
|
Provider: provider.GitProviderStash,
|
||||||
|
Hostname: bServerArgs.hostname,
|
||||||
|
Username: user,
|
||||||
|
Token: bitbucketToken,
|
||||||
|
CaBundle: caBundle,
|
||||||
|
}
|
||||||
|
|
||||||
|
providerClient, err := provider.BuildGitProvider(providerCfg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lazy go-git repository
|
||||||
|
tmpDir, err := os.MkdirTemp("", "flux-bootstrap-")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
gitClient := gogit.New(tmpDir, &http.BasicAuth{
|
||||||
|
Username: user,
|
||||||
|
Password: bitbucketToken,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Install manifest config
|
||||||
|
installOptions := install.Options{
|
||||||
|
BaseURL: rootArgs.defaults.BaseURL,
|
||||||
|
Version: bootstrapArgs.version,
|
||||||
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
|
Components: bootstrapComponents(),
|
||||||
|
Registry: bootstrapArgs.registry,
|
||||||
|
ImagePullSecret: bootstrapArgs.imagePullSecret,
|
||||||
|
WatchAllNamespaces: bootstrapArgs.watchAllNamespaces,
|
||||||
|
NetworkPolicy: bootstrapArgs.networkPolicy,
|
||||||
|
LogLevel: bootstrapArgs.logLevel.String(),
|
||||||
|
NotificationController: rootArgs.defaults.NotificationController,
|
||||||
|
ManifestFile: rootArgs.defaults.ManifestFile,
|
||||||
|
Timeout: rootArgs.timeout,
|
||||||
|
TargetPath: bServerArgs.path.ToSlash(),
|
||||||
|
ClusterDomain: bootstrapArgs.clusterDomain,
|
||||||
|
TolerationKeys: bootstrapArgs.tolerationKeys,
|
||||||
|
}
|
||||||
|
if customBaseURL := bootstrapArgs.manifestsPath; customBaseURL != "" {
|
||||||
|
installOptions.BaseURL = customBaseURL
|
||||||
|
}
|
||||||
|
|
||||||
|
// Source generation and secret config
|
||||||
|
secretOpts := sourcesecret.Options{
|
||||||
|
Name: bootstrapArgs.secretName,
|
||||||
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
|
TargetPath: bServerArgs.path.String(),
|
||||||
|
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
||||||
|
}
|
||||||
|
if bootstrapArgs.tokenAuth {
|
||||||
|
if bServerArgs.personal {
|
||||||
|
secretOpts.Username = bServerArgs.owner
|
||||||
|
} else {
|
||||||
|
secretOpts.Username = bServerArgs.username
|
||||||
|
}
|
||||||
|
secretOpts.Password = bitbucketToken
|
||||||
|
|
||||||
|
if bootstrapArgs.caFile != "" {
|
||||||
|
secretOpts.CAFilePath = bootstrapArgs.caFile
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
secretOpts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(bootstrapArgs.keyAlgorithm)
|
||||||
|
secretOpts.RSAKeyBits = int(bootstrapArgs.keyRSABits)
|
||||||
|
secretOpts.ECDSACurve = bootstrapArgs.keyECDSACurve.Curve
|
||||||
|
secretOpts.SSHHostname = bServerArgs.hostname
|
||||||
|
|
||||||
|
if bootstrapArgs.privateKeyFile != "" {
|
||||||
|
secretOpts.PrivateKeyPath = bootstrapArgs.privateKeyFile
|
||||||
|
}
|
||||||
|
if bootstrapArgs.sshHostname != "" {
|
||||||
|
secretOpts.SSHHostname = bootstrapArgs.sshHostname
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sync manifest config
|
||||||
|
syncOpts := sync.Options{
|
||||||
|
Interval: bServerArgs.interval,
|
||||||
|
Name: *kubeconfigArgs.Namespace,
|
||||||
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
|
Branch: bootstrapArgs.branch,
|
||||||
|
Secret: bootstrapArgs.secretName,
|
||||||
|
TargetPath: bServerArgs.path.ToSlash(),
|
||||||
|
ManifestFile: sync.MakeDefaultOptions().ManifestFile,
|
||||||
|
GitImplementation: sourceGitArgs.gitImplementation.String(),
|
||||||
|
RecurseSubmodules: bootstrapArgs.recurseSubmodules,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bootstrap config
|
||||||
|
bootstrapOpts := []bootstrap.GitProviderOption{
|
||||||
|
bootstrap.WithProviderRepository(bServerArgs.owner, bServerArgs.repository, bServerArgs.personal),
|
||||||
|
bootstrap.WithBranch(bootstrapArgs.branch),
|
||||||
|
bootstrap.WithBootstrapTransportType("https"),
|
||||||
|
bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail),
|
||||||
|
bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix),
|
||||||
|
bootstrap.WithProviderTeamPermissions(mapTeamSlice(bServerArgs.teams, bServerDefaultPermission)),
|
||||||
|
bootstrap.WithReadWriteKeyPermissions(bServerArgs.readWriteKey),
|
||||||
|
bootstrap.WithKubeconfig(kubeconfigArgs),
|
||||||
|
bootstrap.WithLogger(logger),
|
||||||
|
bootstrap.WithCABundle(caBundle),
|
||||||
|
bootstrap.WithGitCommitSigning(bootstrapArgs.gpgKeyRingPath, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID),
|
||||||
|
}
|
||||||
|
if bootstrapArgs.sshHostname != "" {
|
||||||
|
bootstrapOpts = append(bootstrapOpts, bootstrap.WithSSHHostname(bootstrapArgs.sshHostname))
|
||||||
|
}
|
||||||
|
if bootstrapArgs.tokenAuth {
|
||||||
|
bootstrapOpts = append(bootstrapOpts, bootstrap.WithSyncTransportType("https"))
|
||||||
|
}
|
||||||
|
if !bServerArgs.private {
|
||||||
|
bootstrapOpts = append(bootstrapOpts, bootstrap.WithProviderRepositoryConfig("", "", "public"))
|
||||||
|
}
|
||||||
|
if bServerArgs.reconcile {
|
||||||
|
bootstrapOpts = append(bootstrapOpts, bootstrap.WithReconcile())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup bootstrapper with constructed configs
|
||||||
|
b, err := bootstrap.NewGitProviderBootstrapper(gitClient, providerClient, kubeClient, bootstrapOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run
|
||||||
|
return bootstrap.Run(ctx, b, manifestsBase, installOptions, secretOpts, syncOpts, rootArgs.pollInterval, rootArgs.timeout)
|
||||||
|
}
|
||||||
@@ -101,7 +101,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
installOptions := install.Options{
|
installOptions := install.Options{
|
||||||
BaseURL: rootArgs.defaults.BaseURL,
|
BaseURL: rootArgs.defaults.BaseURL,
|
||||||
Version: bootstrapArgs.version,
|
Version: bootstrapArgs.version,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Components: bootstrapComponents(),
|
Components: bootstrapComponents(),
|
||||||
Registry: bootstrapArgs.registry,
|
Registry: bootstrapArgs.registry,
|
||||||
ImagePullSecret: bootstrapArgs.imagePullSecret,
|
ImagePullSecret: bootstrapArgs.imagePullSecret,
|
||||||
@@ -149,7 +149,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
// Source generation and secret config
|
// Source generation and secret config
|
||||||
secretOpts := sourcesecret.Options{
|
secretOpts := sourcesecret.Options{
|
||||||
Name: bootstrapArgs.secretName,
|
Name: bootstrapArgs.secretName,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
TargetPath: gitArgs.path.String(),
|
TargetPath: gitArgs.path.String(),
|
||||||
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
||||||
}
|
}
|
||||||
@@ -161,10 +161,15 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
secretOpts.CAFilePath = bootstrapArgs.caFile
|
secretOpts.CAFilePath = bootstrapArgs.caFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
if repositoryURL.Scheme != "https" && repositoryURL.Scheme != "http" {
|
||||||
|
repositoryURL.Host = repositoryURL.Hostname()
|
||||||
|
}
|
||||||
|
|
||||||
// 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"
|
repositoryURL.Scheme = "https"
|
||||||
repositoryURL.Host = repositoryURL.Hostname()
|
|
||||||
} else {
|
} else {
|
||||||
secretOpts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(bootstrapArgs.keyAlgorithm)
|
secretOpts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(bootstrapArgs.keyAlgorithm)
|
||||||
secretOpts.Password = gitArgs.password
|
secretOpts.Password = gitArgs.password
|
||||||
@@ -194,8 +199,8 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
// Sync manifest config
|
// Sync manifest config
|
||||||
syncOpts := sync.Options{
|
syncOpts := sync.Options{
|
||||||
Interval: gitArgs.interval,
|
Interval: gitArgs.interval,
|
||||||
Name: rootArgs.namespace,
|
Name: *kubeconfigArgs.Namespace,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
URL: repositoryURL.String(),
|
URL: repositoryURL.String(),
|
||||||
Branch: bootstrapArgs.branch,
|
Branch: bootstrapArgs.branch,
|
||||||
Secret: bootstrapArgs.secretName,
|
Secret: bootstrapArgs.secretName,
|
||||||
@@ -220,7 +225,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
bootstrap.WithBranch(bootstrapArgs.branch),
|
bootstrap.WithBranch(bootstrapArgs.branch),
|
||||||
bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail),
|
bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail),
|
||||||
bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix),
|
bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix),
|
||||||
bootstrap.WithKubeconfig(rootArgs.kubeconfig, rootArgs.kubecontext),
|
bootstrap.WithKubeconfig(kubeconfigArgs),
|
||||||
bootstrap.WithPostGenerateSecretFunc(promptPublicKey),
|
bootstrap.WithPostGenerateSecretFunc(promptPublicKey),
|
||||||
bootstrap.WithLogger(logger),
|
bootstrap.WithLogger(logger),
|
||||||
bootstrap.WithCABundle(caBundle),
|
bootstrap.WithCABundle(caBundle),
|
||||||
|
|||||||
@@ -111,7 +111,11 @@ func init() {
|
|||||||
func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
ghToken := os.Getenv(ghTokenEnvVar)
|
ghToken := os.Getenv(ghTokenEnvVar)
|
||||||
if ghToken == "" {
|
if ghToken == "" {
|
||||||
return fmt.Errorf("%s environment variable not found", ghTokenEnvVar)
|
var err error
|
||||||
|
ghToken, err = readPasswordFromStdin("Please enter your GitHub personal access token (PAT): ")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not read token: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := bootstrapValidate(); err != nil {
|
if err := bootstrapValidate(); err != nil {
|
||||||
@@ -121,7 +125,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -136,11 +140,20 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(manifestsBase)
|
defer os.RemoveAll(manifestsBase)
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
// Build GitHub provider
|
// Build GitHub provider
|
||||||
providerCfg := provider.Config{
|
providerCfg := provider.Config{
|
||||||
Provider: provider.GitProviderGitHub,
|
Provider: provider.GitProviderGitHub,
|
||||||
Hostname: githubArgs.hostname,
|
Hostname: githubArgs.hostname,
|
||||||
Token: ghToken,
|
Token: ghToken,
|
||||||
|
CaBundle: caBundle,
|
||||||
}
|
}
|
||||||
providerClient, err := provider.BuildGitProvider(providerCfg)
|
providerClient, err := provider.BuildGitProvider(providerCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -162,7 +175,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
installOptions := install.Options{
|
installOptions := install.Options{
|
||||||
BaseURL: rootArgs.defaults.BaseURL,
|
BaseURL: rootArgs.defaults.BaseURL,
|
||||||
Version: bootstrapArgs.version,
|
Version: bootstrapArgs.version,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Components: bootstrapComponents(),
|
Components: bootstrapComponents(),
|
||||||
Registry: bootstrapArgs.registry,
|
Registry: bootstrapArgs.registry,
|
||||||
ImagePullSecret: bootstrapArgs.imagePullSecret,
|
ImagePullSecret: bootstrapArgs.imagePullSecret,
|
||||||
@@ -183,7 +196,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
// Source generation and secret config
|
// Source generation and secret config
|
||||||
secretOpts := sourcesecret.Options{
|
secretOpts := sourcesecret.Options{
|
||||||
Name: bootstrapArgs.secretName,
|
Name: bootstrapArgs.secretName,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
TargetPath: githubArgs.path.ToSlash(),
|
TargetPath: githubArgs.path.ToSlash(),
|
||||||
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
||||||
}
|
}
|
||||||
@@ -208,8 +221,8 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
// Sync manifest config
|
// Sync manifest config
|
||||||
syncOpts := sync.Options{
|
syncOpts := sync.Options{
|
||||||
Interval: githubArgs.interval,
|
Interval: githubArgs.interval,
|
||||||
Name: rootArgs.namespace,
|
Name: *kubeconfigArgs.Namespace,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Branch: bootstrapArgs.branch,
|
Branch: bootstrapArgs.branch,
|
||||||
Secret: bootstrapArgs.secretName,
|
Secret: bootstrapArgs.secretName,
|
||||||
TargetPath: githubArgs.path.ToSlash(),
|
TargetPath: githubArgs.path.ToSlash(),
|
||||||
@@ -227,8 +240,10 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
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(rootArgs.kubeconfig, rootArgs.kubecontext),
|
bootstrap.WithKubeconfig(kubeconfigArgs),
|
||||||
bootstrap.WithLogger(logger),
|
bootstrap.WithLogger(logger),
|
||||||
|
bootstrap.WithCABundle(caBundle),
|
||||||
|
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))
|
||||||
|
|||||||
@@ -108,7 +108,11 @@ func init() {
|
|||||||
func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
glToken := os.Getenv(glTokenEnvVar)
|
glToken := os.Getenv(glTokenEnvVar)
|
||||||
if glToken == "" {
|
if glToken == "" {
|
||||||
return fmt.Errorf("%s environment variable not found", glTokenEnvVar)
|
var err error
|
||||||
|
glToken, err = readPasswordFromStdin("Please enter your GitLab personal access token (PAT): ")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not read token: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if projectNameIsValid, err := regexp.MatchString(gitlabProjectRegex, gitlabArgs.repository); err != nil || !projectNameIsValid {
|
if projectNameIsValid, err := regexp.MatchString(gitlabProjectRegex, gitlabArgs.repository); err != nil || !projectNameIsValid {
|
||||||
@@ -125,7 +129,7 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -140,11 +144,21 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(manifestsBase)
|
defer os.RemoveAll(manifestsBase)
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Build GitLab provider
|
// Build GitLab provider
|
||||||
providerCfg := provider.Config{
|
providerCfg := provider.Config{
|
||||||
Provider: provider.GitProviderGitLab,
|
Provider: provider.GitProviderGitLab,
|
||||||
Hostname: gitlabArgs.hostname,
|
Hostname: gitlabArgs.hostname,
|
||||||
Token: glToken,
|
Token: glToken,
|
||||||
|
CaBundle: caBundle,
|
||||||
}
|
}
|
||||||
// Workaround for: https://github.com/fluxcd/go-git-providers/issues/55
|
// Workaround for: https://github.com/fluxcd/go-git-providers/issues/55
|
||||||
if hostname := providerCfg.Hostname; hostname != glDefaultDomain &&
|
if hostname := providerCfg.Hostname; hostname != glDefaultDomain &&
|
||||||
@@ -172,7 +186,7 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
installOptions := install.Options{
|
installOptions := install.Options{
|
||||||
BaseURL: rootArgs.defaults.BaseURL,
|
BaseURL: rootArgs.defaults.BaseURL,
|
||||||
Version: bootstrapArgs.version,
|
Version: bootstrapArgs.version,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Components: bootstrapComponents(),
|
Components: bootstrapComponents(),
|
||||||
Registry: bootstrapArgs.registry,
|
Registry: bootstrapArgs.registry,
|
||||||
ImagePullSecret: bootstrapArgs.imagePullSecret,
|
ImagePullSecret: bootstrapArgs.imagePullSecret,
|
||||||
@@ -193,7 +207,7 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
// Source generation and secret config
|
// Source generation and secret config
|
||||||
secretOpts := sourcesecret.Options{
|
secretOpts := sourcesecret.Options{
|
||||||
Name: bootstrapArgs.secretName,
|
Name: bootstrapArgs.secretName,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
TargetPath: gitlabArgs.path.String(),
|
TargetPath: gitlabArgs.path.String(),
|
||||||
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
||||||
}
|
}
|
||||||
@@ -221,8 +235,8 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
// Sync manifest config
|
// Sync manifest config
|
||||||
syncOpts := sync.Options{
|
syncOpts := sync.Options{
|
||||||
Interval: gitlabArgs.interval,
|
Interval: gitlabArgs.interval,
|
||||||
Name: rootArgs.namespace,
|
Name: *kubeconfigArgs.Namespace,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Branch: bootstrapArgs.branch,
|
Branch: bootstrapArgs.branch,
|
||||||
Secret: bootstrapArgs.secretName,
|
Secret: bootstrapArgs.secretName,
|
||||||
TargetPath: gitlabArgs.path.ToSlash(),
|
TargetPath: gitlabArgs.path.ToSlash(),
|
||||||
@@ -240,8 +254,10 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
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(rootArgs.kubeconfig, rootArgs.kubecontext),
|
bootstrap.WithKubeconfig(kubeconfigArgs),
|
||||||
bootstrap.WithLogger(logger),
|
bootstrap.WithLogger(logger),
|
||||||
|
bootstrap.WithCABundle(caBundle),
|
||||||
|
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))
|
||||||
|
|||||||
31
cmd/flux/build.go
Normal file
31
cmd/flux/build.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
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 (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var buildCmd = &cobra.Command{
|
||||||
|
Use: "build",
|
||||||
|
Short: "Build a flux resource",
|
||||||
|
Long: "The build command is used to build flux resources.",
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(buildCmd)
|
||||||
|
}
|
||||||
100
cmd/flux/build_kustomization.go
Normal file
100
cmd/flux/build_kustomization.go
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
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 (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/build"
|
||||||
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var buildKsCmd = &cobra.Command{
|
||||||
|
Use: "kustomization",
|
||||||
|
Aliases: []string{"ks"},
|
||||||
|
Short: "Build Kustomization",
|
||||||
|
Long: `The build command queries the Kubernetes API and fetches the specified Flux Kustomization.
|
||||||
|
It then uses the fetched in cluster flux kustomization to perform needed transformation on the local kustomization.yaml
|
||||||
|
pointed at by --path. The local kustomization.yaml is generated if it does not exist. Finally it builds the overlays using the local kustomization.yaml, and write the resulting multi-doc YAML to stdout.`,
|
||||||
|
Example: `# Build the local manifests as they were built on the cluster
|
||||||
|
flux build kustomization my-app --path ./path/to/local/manifests`,
|
||||||
|
ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)),
|
||||||
|
RunE: buildKsCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
type buildKsFlags struct {
|
||||||
|
path string
|
||||||
|
}
|
||||||
|
|
||||||
|
var buildKsArgs buildKsFlags
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
buildKsCmd.Flags().StringVar(&buildKsArgs.path, "path", "", "Path to the manifests location.)")
|
||||||
|
buildCmd.AddCommand(buildKsCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildKsCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) < 1 {
|
||||||
|
return fmt.Errorf("%s name is required", kustomizationType.humanKind)
|
||||||
|
}
|
||||||
|
name := args[0]
|
||||||
|
|
||||||
|
if buildKsArgs.path == "" {
|
||||||
|
return fmt.Errorf("invalid resource path %q", buildKsArgs.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fs, err := os.Stat(buildKsArgs.path); err != nil || !fs.IsDir() {
|
||||||
|
return fmt.Errorf("invalid resource path %q", buildKsArgs.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
builder, err := build.NewBuilder(kubeconfigArgs, name, buildKsArgs.path, build.WithTimeout(rootArgs.timeout))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a signal channel
|
||||||
|
sigc := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigc, os.Interrupt)
|
||||||
|
|
||||||
|
errChan := make(chan error)
|
||||||
|
go func() {
|
||||||
|
manifests, err := builder.Build()
|
||||||
|
if err != nil {
|
||||||
|
errChan <- err
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Print(string(manifests))
|
||||||
|
errChan <- nil
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-sigc:
|
||||||
|
fmt.Println("Build cancelled... exiting.")
|
||||||
|
return builder.Cancel()
|
||||||
|
case err := <-errChan:
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
83
cmd/flux/build_kustomization_test.go
Normal file
83
cmd/flux/build_kustomization_test.go
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
//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 (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func setup(t *testing.T, tmpl map[string]string) {
|
||||||
|
t.Helper()
|
||||||
|
testEnv.CreateObjectFile("./testdata/build-kustomization/podinfo-source.yaml", tmpl, t)
|
||||||
|
testEnv.CreateObjectFile("./testdata/build-kustomization/podinfo-kustomization.yaml", tmpl, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildKustomization(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
resultFile string
|
||||||
|
assertFunc string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "no args",
|
||||||
|
args: "build kustomization podinfo",
|
||||||
|
resultFile: "invalid resource path \"\"",
|
||||||
|
assertFunc: "assertError",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "build podinfo",
|
||||||
|
args: "build kustomization podinfo --path ./testdata/build-kustomization/podinfo",
|
||||||
|
resultFile: "./testdata/build-kustomization/podinfo-result.yaml",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "build podinfo without service",
|
||||||
|
args: "build kustomization podinfo --path ./testdata/build-kustomization/delete-service",
|
||||||
|
resultFile: "./testdata/build-kustomization/podinfo-without-service-result.yaml",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl := map[string]string{
|
||||||
|
"fluxns": allocateNamespace("flux-system"),
|
||||||
|
}
|
||||||
|
setup(t, tmpl)
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
var assert assertFunc
|
||||||
|
|
||||||
|
switch tt.assertFunc {
|
||||||
|
case "assertGoldenTemplateFile":
|
||||||
|
assert = assertGoldenTemplateFile(tt.resultFile, tmpl)
|
||||||
|
case "assertError":
|
||||||
|
assert = assertError(tt.resultFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.args + " -n " + tmpl["fluxns"],
|
||||||
|
assert: assert,
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,7 @@ import (
|
|||||||
"github.com/fluxcd/pkg/version"
|
"github.com/fluxcd/pkg/version"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||||
"github.com/fluxcd/flux2/pkg/status"
|
"github.com/fluxcd/flux2/pkg/status"
|
||||||
)
|
)
|
||||||
@@ -51,13 +52,11 @@ type checkFlags struct {
|
|||||||
pre bool
|
pre bool
|
||||||
components []string
|
components []string
|
||||||
extraComponents []string
|
extraComponents []string
|
||||||
|
pollInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
var kubernetesConstraints = []string{
|
var kubernetesConstraints = []string{
|
||||||
">=1.19.0-0",
|
">=1.20.6-0",
|
||||||
">=1.16.11-0 <=1.16.15-0",
|
|
||||||
">=1.17.7-0 <=1.17.17-0",
|
|
||||||
">=1.18.4-0 <=1.18.20-0",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var checkArgs checkFlags
|
var checkArgs checkFlags
|
||||||
@@ -69,6 +68,8 @@ func init() {
|
|||||||
"list of components, accepts comma-separated values")
|
"list of components, accepts comma-separated values")
|
||||||
checkCmd.Flags().StringSliceVar(&checkArgs.extraComponents, "components-extra", nil,
|
checkCmd.Flags().StringSliceVar(&checkArgs.extraComponents, "components-extra", nil,
|
||||||
"list of components in addition to those supplied or defaulted, accepts comma-separated values")
|
"list of components in addition to those supplied or defaulted, accepts comma-separated values")
|
||||||
|
checkCmd.Flags().DurationVar(&checkArgs.pollInterval, "poll-interval", 5*time.Second,
|
||||||
|
"how often the health checker should poll the cluster for the latest state of the resources.")
|
||||||
rootCmd.AddCommand(checkCmd)
|
rootCmd.AddCommand(checkCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +125,7 @@ func fluxCheck() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func kubernetesCheck(constraints []string) bool {
|
func kubernetesCheck(constraints []string) bool {
|
||||||
cfg, err := utils.KubeConfig(rootArgs.kubeconfig, rootArgs.kubecontext)
|
cfg, err := utils.KubeConfig(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Failuref("Kubernetes client initialization failed: %s", err.Error())
|
logger.Failuref("Kubernetes client initialization failed: %s", err.Error())
|
||||||
return false
|
return false
|
||||||
@@ -172,25 +173,25 @@ func componentsCheck() bool {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeConfig, err := utils.KubeConfig(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeConfig, err := utils.KubeConfig(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
statusChecker, err := status.NewStatusChecker(kubeConfig, time.Second, rootArgs.timeout, logger)
|
statusChecker, err := status.NewStatusChecker(kubeConfig, checkArgs.pollInterval, rootArgs.timeout, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
ok := true
|
ok := true
|
||||||
selector := client.MatchingLabels{"app.kubernetes.io/instance": rootArgs.namespace}
|
selector := client.MatchingLabels{manifestgen.PartOfLabelKey: manifestgen.PartOfLabelValue}
|
||||||
var list v1.DeploymentList
|
var list v1.DeploymentList
|
||||||
if err := kubeClient.List(ctx, &list, client.InNamespace(rootArgs.namespace), selector); err == nil {
|
if err := kubeClient.List(ctx, &list, client.InNamespace(*kubeconfigArgs.Namespace), selector); err == nil {
|
||||||
for _, d := range list.Items {
|
for _, d := range list.Items {
|
||||||
if ref, err := buildComponentObjectRefs(d.Name); err == nil {
|
if ref, err := buildComponentObjectRefs(d.Name); err == nil {
|
||||||
if err := statusChecker.Assess(ref...); err != nil {
|
if err := statusChecker.Assess(ref...); err != nil {
|
||||||
|
|||||||
@@ -1,5 +1,22 @@
|
|||||||
|
//go:build e2e
|
||||||
// +build e2e
|
// +build e2e
|
||||||
|
|
||||||
|
/*
|
||||||
|
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -13,7 +30,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestCheckPre(t *testing.T) {
|
func TestCheckPre(t *testing.T) {
|
||||||
jsonOutput, err := utils.ExecKubectlCommand(context.TODO(), utils.ModeCapture, rootArgs.kubeconfig, rootArgs.kubecontext, "version", "--output", "json")
|
jsonOutput, err := utils.ExecKubectlCommand(context.TODO(), utils.ModeCapture, *kubeconfigArgs.KubeConfig, *kubeconfigArgs.Context, "version", "--output", "json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error running utils.ExecKubectlCommand: %v", err.Error())
|
t.Fatalf("Error running utils.ExecKubectlCommand: %v", err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +25,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/client-go/discovery"
|
|
||||||
memory "k8s.io/client-go/discovery/cached"
|
|
||||||
"k8s.io/client-go/dynamic"
|
"k8s.io/client-go/dynamic"
|
||||||
"k8s.io/client-go/restmapper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var completionCmd = &cobra.Command{
|
var completionCmd = &cobra.Command{
|
||||||
@@ -42,7 +39,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func contextsCompletionFunc(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
func contextsCompletionFunc(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
rawConfig, err := utils.ClientConfig(rootArgs.kubeconfig, rootArgs.kubecontext).RawConfig()
|
rawConfig, err := kubeconfigArgs.ToRawKubeConfigLoader().RawConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return completionError(err)
|
return completionError(err)
|
||||||
}
|
}
|
||||||
@@ -63,16 +60,15 @@ func resourceNamesCompletionFunc(gvk schema.GroupVersionKind) func(cmd *cobra.Co
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
cfg, err := utils.KubeConfig(rootArgs.kubeconfig, rootArgs.kubecontext)
|
cfg, err := utils.KubeConfig(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return completionError(err)
|
return completionError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dc, err := discovery.NewDiscoveryClientForConfig(cfg)
|
mapper, err := kubeconfigArgs.ToRESTMapper()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return completionError(err)
|
return completionError(err)
|
||||||
}
|
}
|
||||||
mapper := restmapper.NewDeferredDiscoveryRESTMapper(memory.NewMemCacheClient(dc))
|
|
||||||
|
|
||||||
mapping, err := mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
|
mapping, err := mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -86,7 +82,7 @@ func resourceNamesCompletionFunc(gvk schema.GroupVersionKind) func(cmd *cobra.Co
|
|||||||
|
|
||||||
var dr dynamic.ResourceInterface
|
var dr dynamic.ResourceInterface
|
||||||
if mapping.Scope.Name() == meta.RESTScopeNameNamespace {
|
if mapping.Scope.Name() == meta.RESTScopeNameNamespace {
|
||||||
dr = client.Resource(mapping.Resource).Namespace(rootArgs.namespace)
|
dr = client.Resource(mapping.Resource).Namespace(*kubeconfigArgs.Namespace)
|
||||||
} else {
|
} else {
|
||||||
dr = client.Resource(mapping.Resource)
|
dr = client.Resource(mapping.Resource)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -51,6 +52,18 @@ func init() {
|
|||||||
createCmd.PersistentFlags().BoolVar(&createArgs.export, "export", false, "export in YAML format to stdout")
|
createCmd.PersistentFlags().BoolVar(&createArgs.export, "export", false, "export in YAML format to stdout")
|
||||||
createCmd.PersistentFlags().StringSliceVar(&createArgs.labels, "label", nil,
|
createCmd.PersistentFlags().StringSliceVar(&createArgs.labels, "label", nil,
|
||||||
"set labels on the resource (can specify multiple labels with commas: label1=value1,label2=value2)")
|
"set labels on the resource (can specify multiple labels with commas: label1=value1,label2=value2)")
|
||||||
|
createCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) < 1 {
|
||||||
|
return fmt.Errorf("name is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
name := args[0]
|
||||||
|
if !validateObjectName(name) {
|
||||||
|
return fmt.Errorf("name '%s' is invalid, it should adhere to standard defined in RFC 1123, the name can only contain alphanumeric characters or '-'", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
rootCmd.AddCommand(createCmd)
|
rootCmd.AddCommand(createCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +117,7 @@ func (names apiType) upsertAndWait(object upsertWaitable, mutate func() error) e
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext) // NB globals
|
kubeClient, err := utils.KubeClient(kubeconfigArgs) // NB globals
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -150,3 +163,8 @@ func parseLabels() (map[string]string, error) {
|
|||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateObjectName(name string) bool {
|
||||||
|
r := regexp.MustCompile("^[a-z0-9]([a-z0-9\\-]){0,61}[a-z0-9]$")
|
||||||
|
return r.MatchString(name)
|
||||||
|
}
|
||||||
|
|||||||
@@ -63,9 +63,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createAlertCmdRun(cmd *cobra.Command, args []string) error {
|
func createAlertCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
|
||||||
return fmt.Errorf("Alert name is required")
|
|
||||||
}
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
if alertArgs.providerRef == "" {
|
if alertArgs.providerRef == "" {
|
||||||
@@ -102,7 +99,7 @@ func createAlertCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
alert := notificationv1.Alert{
|
alert := notificationv1.Alert{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: sourceLabels,
|
Labels: sourceLabels,
|
||||||
},
|
},
|
||||||
Spec: notificationv1.AlertSpec{
|
Spec: notificationv1.AlertSpec{
|
||||||
@@ -122,7 +119,7 @@ func createAlertCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,9 +73,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
|
func createAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
|
||||||
return fmt.Errorf("Provider name is required")
|
|
||||||
}
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
if alertProviderArgs.alertType == "" {
|
if alertProviderArgs.alertType == "" {
|
||||||
@@ -94,7 +91,7 @@ func createAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
provider := notificationv1.Provider{
|
provider := notificationv1.Provider{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: sourceLabels,
|
Labels: sourceLabels,
|
||||||
},
|
},
|
||||||
Spec: notificationv1.ProviderSpec{
|
Spec: notificationv1.ProviderSpec{
|
||||||
@@ -118,7 +115,7 @@ func createAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,9 +139,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
|
||||||
return fmt.Errorf("HelmRelease name is required")
|
|
||||||
}
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
if helmReleaseArgs.chart == "" {
|
if helmReleaseArgs.chart == "" {
|
||||||
@@ -160,7 +157,7 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
helmRelease := helmv2.HelmRelease{
|
helmRelease := helmv2.HelmRelease{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: sourceLabels,
|
Labels: sourceLabels,
|
||||||
},
|
},
|
||||||
Spec: helmv2.HelmReleaseSpec{
|
Spec: helmv2.HelmReleaseSpec{
|
||||||
@@ -250,7 +247,7 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,9 +84,6 @@ func (obj imagePolicyAdapter) getObservedGeneration() int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createImagePolicyRun(cmd *cobra.Command, args []string) error {
|
func createImagePolicyRun(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
|
||||||
return fmt.Errorf("ImagePolicy name is required")
|
|
||||||
}
|
|
||||||
objectName := args[0]
|
objectName := args[0]
|
||||||
|
|
||||||
if imagePolicyArgs.imageRef == "" {
|
if imagePolicyArgs.imageRef == "" {
|
||||||
@@ -101,7 +98,7 @@ func createImagePolicyRun(cmd *cobra.Command, args []string) error {
|
|||||||
var policy = imagev1.ImagePolicy{
|
var policy = imagev1.ImagePolicy{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: objectName,
|
Name: objectName,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
},
|
},
|
||||||
Spec: imagev1.ImagePolicySpec{
|
Spec: imagev1.ImagePolicySpec{
|
||||||
|
|||||||
@@ -83,9 +83,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createImageRepositoryRun(cmd *cobra.Command, args []string) error {
|
func createImageRepositoryRun(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
|
||||||
return fmt.Errorf("ImageRepository name is required")
|
|
||||||
}
|
|
||||||
objectName := args[0]
|
objectName := args[0]
|
||||||
|
|
||||||
if imageRepoArgs.image == "" {
|
if imageRepoArgs.image == "" {
|
||||||
@@ -104,7 +101,7 @@ func createImageRepositoryRun(cmd *cobra.Command, args []string) error {
|
|||||||
var repo = imagev1.ImageRepository{
|
var repo = imagev1.ImageRepository{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: objectName,
|
Name: objectName,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
},
|
},
|
||||||
Spec: imagev1.ImageRepositorySpec{
|
Spec: imagev1.ImageRepositorySpec{
|
||||||
|
|||||||
@@ -49,25 +49,40 @@ mentioned in YAMLs in a git repository.`,
|
|||||||
--push-branch=image-updates \
|
--push-branch=image-updates \
|
||||||
--author-name=flux \
|
--author-name=flux \
|
||||||
--author-email=flux@example.com \
|
--author-email=flux@example.com \
|
||||||
--commit-template="{{range .Updated.Images}}{{println .}}{{end}}"`,
|
--commit-template="{{range .Updated.Images}}{{println .}}{{end}}"
|
||||||
|
|
||||||
|
# Configure image updates for a Git repository in a different namespace
|
||||||
|
flux create image update apps \
|
||||||
|
--namespace=apps \
|
||||||
|
--git-repo-ref=flux-system \
|
||||||
|
--git-repo-namespace=flux-system \
|
||||||
|
--git-repo-path="./clusters/my-cluster" \
|
||||||
|
--checkout-branch=main \
|
||||||
|
--push-branch=image-updates \
|
||||||
|
--author-name=flux \
|
||||||
|
--author-email=flux@example.com \
|
||||||
|
--commit-template="{{range .Updated.Images}}{{println .}}{{end}}"
|
||||||
|
`,
|
||||||
RunE: createImageUpdateRun,
|
RunE: createImageUpdateRun,
|
||||||
}
|
}
|
||||||
|
|
||||||
type imageUpdateFlags struct {
|
type imageUpdateFlags struct {
|
||||||
gitRepoRef string
|
gitRepoName string
|
||||||
gitRepoPath string
|
gitRepoNamespace string
|
||||||
checkoutBranch string
|
gitRepoPath string
|
||||||
pushBranch string
|
checkoutBranch string
|
||||||
commitTemplate string
|
pushBranch string
|
||||||
authorName string
|
commitTemplate string
|
||||||
authorEmail string
|
authorName string
|
||||||
|
authorEmail string
|
||||||
}
|
}
|
||||||
|
|
||||||
var imageUpdateArgs = imageUpdateFlags{}
|
var imageUpdateArgs = imageUpdateFlags{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flags := createImageUpdateCmd.Flags()
|
flags := createImageUpdateCmd.Flags()
|
||||||
flags.StringVar(&imageUpdateArgs.gitRepoRef, "git-repo-ref", "", "the name of a GitRepository resource with details of the upstream Git repository")
|
flags.StringVar(&imageUpdateArgs.gitRepoName, "git-repo-ref", "", "the name of a GitRepository resource with details of the upstream Git repository")
|
||||||
|
flags.StringVar(&imageUpdateArgs.gitRepoNamespace, "git-repo-namespace", "", "the namespace of the GitRepository resource, defaults to the ImageUpdateAutomation namespace")
|
||||||
flags.StringVar(&imageUpdateArgs.gitRepoPath, "git-repo-path", "", "path to the directory containing the manifests to be updated, defaults to the repository root")
|
flags.StringVar(&imageUpdateArgs.gitRepoPath, "git-repo-path", "", "path to the directory containing the manifests to be updated, defaults to the repository root")
|
||||||
flags.StringVar(&imageUpdateArgs.checkoutBranch, "checkout-branch", "", "the branch to checkout")
|
flags.StringVar(&imageUpdateArgs.checkoutBranch, "checkout-branch", "", "the branch to checkout")
|
||||||
flags.StringVar(&imageUpdateArgs.pushBranch, "push-branch", "", "the branch to push commits to, defaults to the checkout branch if not specified")
|
flags.StringVar(&imageUpdateArgs.pushBranch, "push-branch", "", "the branch to push commits to, defaults to the checkout branch if not specified")
|
||||||
@@ -79,12 +94,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createImageUpdateRun(cmd *cobra.Command, args []string) error {
|
func createImageUpdateRun(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
|
||||||
return fmt.Errorf("ImageUpdateAutomation name is required")
|
|
||||||
}
|
|
||||||
objectName := args[0]
|
objectName := args[0]
|
||||||
|
|
||||||
if imageUpdateArgs.gitRepoRef == "" {
|
if imageUpdateArgs.gitRepoName == "" {
|
||||||
return fmt.Errorf("a reference to a GitRepository is required (--git-repo-ref)")
|
return fmt.Errorf("a reference to a GitRepository is required (--git-repo-ref)")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,13 +120,14 @@ func createImageUpdateRun(cmd *cobra.Command, args []string) error {
|
|||||||
var update = autov1.ImageUpdateAutomation{
|
var update = autov1.ImageUpdateAutomation{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: objectName,
|
Name: objectName,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
},
|
},
|
||||||
Spec: autov1.ImageUpdateAutomationSpec{
|
Spec: autov1.ImageUpdateAutomationSpec{
|
||||||
SourceRef: autov1.SourceReference{
|
SourceRef: autov1.CrossNamespaceSourceReference{
|
||||||
Kind: sourcev1.GitRepositoryKind,
|
Kind: sourcev1.GitRepositoryKind,
|
||||||
Name: imageUpdateArgs.gitRepoRef,
|
Name: imageUpdateArgs.gitRepoName,
|
||||||
|
Namespace: imageUpdateArgs.gitRepoNamespace,
|
||||||
},
|
},
|
||||||
|
|
||||||
GitSpec: &autov1.GitSpec{
|
GitSpec: &autov1.GitSpec{
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ type kustomizationFlags struct {
|
|||||||
decryptionProvider flags.DecryptionProvider
|
decryptionProvider flags.DecryptionProvider
|
||||||
decryptionSecret string
|
decryptionSecret string
|
||||||
targetNamespace string
|
targetNamespace string
|
||||||
|
wait bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var kustomizationArgs = NewKustomizationFlags()
|
var kustomizationArgs = NewKustomizationFlags()
|
||||||
@@ -97,6 +98,7 @@ func init() {
|
|||||||
createKsCmd.Flags().Var(&kustomizationArgs.source, "source", kustomizationArgs.source.Description())
|
createKsCmd.Flags().Var(&kustomizationArgs.source, "source", kustomizationArgs.source.Description())
|
||||||
createKsCmd.Flags().Var(&kustomizationArgs.path, "path", "path to the directory containing a kustomization.yaml file")
|
createKsCmd.Flags().Var(&kustomizationArgs.path, "path", "path to the directory containing a kustomization.yaml file")
|
||||||
createKsCmd.Flags().BoolVar(&kustomizationArgs.prune, "prune", false, "enable garbage collection")
|
createKsCmd.Flags().BoolVar(&kustomizationArgs.prune, "prune", false, "enable garbage collection")
|
||||||
|
createKsCmd.Flags().BoolVar(&kustomizationArgs.wait, "wait", false, "enable health checking of all the applied resources")
|
||||||
createKsCmd.Flags().StringSliceVar(&kustomizationArgs.healthCheck, "health-check", nil, "workload to be included in the health assessment, in the format '<kind>/<name>.<namespace>'")
|
createKsCmd.Flags().StringSliceVar(&kustomizationArgs.healthCheck, "health-check", nil, "workload to be included in the health assessment, in the format '<kind>/<name>.<namespace>'")
|
||||||
createKsCmd.Flags().DurationVar(&kustomizationArgs.healthTimeout, "health-check-timeout", 2*time.Minute, "timeout of health checking operations")
|
createKsCmd.Flags().DurationVar(&kustomizationArgs.healthTimeout, "health-check-timeout", 2*time.Minute, "timeout of health checking operations")
|
||||||
createKsCmd.Flags().StringVar(&kustomizationArgs.validation, "validation", "", "validate the manifests before applying them on the cluster, can be 'client' or 'server'")
|
createKsCmd.Flags().StringVar(&kustomizationArgs.validation, "validation", "", "validate the manifests before applying them on the cluster, can be 'client' or 'server'")
|
||||||
@@ -117,9 +119,6 @@ func NewKustomizationFlags() kustomizationFlags {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createKsCmdRun(cmd *cobra.Command, args []string) error {
|
func createKsCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
|
||||||
return fmt.Errorf("Kustomization name is required")
|
|
||||||
}
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
if kustomizationArgs.path == "" {
|
if kustomizationArgs.path == "" {
|
||||||
@@ -141,7 +140,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
kustomization := kustomizev1.Kustomization{
|
kustomization := kustomizev1.Kustomization{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: kslabels,
|
Labels: kslabels,
|
||||||
},
|
},
|
||||||
Spec: kustomizev1.KustomizationSpec{
|
Spec: kustomizev1.KustomizationSpec{
|
||||||
@@ -161,7 +160,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(kustomizationArgs.healthCheck) > 0 {
|
if len(kustomizationArgs.healthCheck) > 0 && !kustomizationArgs.wait {
|
||||||
healthChecks := make([]meta.NamespacedObjectKindReference, 0)
|
healthChecks := make([]meta.NamespacedObjectKindReference, 0)
|
||||||
for _, w := range kustomizationArgs.healthCheck {
|
for _, w := range kustomizationArgs.healthCheck {
|
||||||
kindObj := strings.Split(w, "/")
|
kindObj := strings.Split(w, "/")
|
||||||
@@ -202,6 +201,13 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if kustomizationArgs.wait {
|
||||||
|
kustomization.Spec.Wait = true
|
||||||
|
kustomization.Spec.Timeout = &metav1.Duration{
|
||||||
|
Duration: kustomizationArgs.healthTimeout,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if kustomizationArgs.saName != "" {
|
if kustomizationArgs.saName != "" {
|
||||||
kustomization.Spec.ServiceAccountName = kustomizationArgs.saName
|
kustomization.Spec.ServiceAccountName = kustomizationArgs.saName
|
||||||
}
|
}
|
||||||
@@ -223,7 +229,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,9 +67,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createReceiverCmdRun(cmd *cobra.Command, args []string) error {
|
func createReceiverCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
|
||||||
return fmt.Errorf("Receiver name is required")
|
|
||||||
}
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
if receiverArgs.receiverType == "" {
|
if receiverArgs.receiverType == "" {
|
||||||
@@ -109,7 +106,7 @@ func createReceiverCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
receiver := notificationv1.Receiver{
|
receiver := notificationv1.Receiver{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: sourceLabels,
|
Labels: sourceLabels,
|
||||||
},
|
},
|
||||||
Spec: notificationv1.ReceiverSpec{
|
Spec: notificationv1.ReceiverSpec{
|
||||||
@@ -130,7 +127,7 @@ func createReceiverCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,16 +105,13 @@ func init() {
|
|||||||
|
|
||||||
func NewSecretGitFlags() secretGitFlags {
|
func NewSecretGitFlags() secretGitFlags {
|
||||||
return secretGitFlags{
|
return secretGitFlags{
|
||||||
keyAlgorithm: flags.PublicKeyAlgorithm(sourcesecret.RSAPrivateKeyAlgorithm),
|
keyAlgorithm: flags.PublicKeyAlgorithm(sourcesecret.ECDSAPrivateKeyAlgorithm),
|
||||||
rsaBits: 2048,
|
rsaBits: 2048,
|
||||||
ecdsaCurve: flags.ECDSACurve{Curve: elliptic.P384()},
|
ecdsaCurve: flags.ECDSACurve{Curve: elliptic.P384()},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSecretGitCmdRun(cmd *cobra.Command, args []string) error {
|
func createSecretGitCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
|
||||||
return fmt.Errorf("secret name is required")
|
|
||||||
}
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
if secretGitArgs.url == "" {
|
if secretGitArgs.url == "" {
|
||||||
return fmt.Errorf("url is required")
|
return fmt.Errorf("url is required")
|
||||||
@@ -132,7 +129,7 @@ func createSecretGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
opts := sourcesecret.Options{
|
opts := sourcesecret.Options{
|
||||||
Name: name,
|
Name: name,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
||||||
}
|
}
|
||||||
@@ -161,7 +158,7 @@ func createSecretGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if createArgs.export {
|
if createArgs.export {
|
||||||
fmt.Println(secret.Content)
|
rootCmd.Println(secret.Content)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,14 +173,14 @@ func createSecretGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := upsertSecret(ctx, kubeClient, s); err != nil {
|
if err := upsertSecret(ctx, kubeClient, s); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logger.Actionf("git secret '%s' created in '%s' namespace", name, rootArgs.namespace)
|
logger.Actionf("git secret '%s' created in '%s' namespace", name, *kubeconfigArgs.Namespace)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
44
cmd/flux/create_secret_git_test.go
Normal file
44
cmd/flux/create_secret_git_test.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateGitSecret(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
assert assertFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "no args",
|
||||||
|
args: "create secret git",
|
||||||
|
assert: assertError("name is required"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "basic secret",
|
||||||
|
args: "create secret git podinfo-auth --url=https://github.com/stefanprodan/podinfo --username=my-username --password=my-password --namespace=my-namespace --export",
|
||||||
|
assert: assertGoldenFile("./testdata/create_secret/git/secret-git-basic.yaml"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ssh key",
|
||||||
|
args: "create secret git podinfo-auth --url=ssh://git@github.com/stefanprodan/podinfo --private-key-file=./testdata/create_secret/git/ecdsa.private --namespace=my-namespace --export",
|
||||||
|
assert: assertGoldenFile("testdata/create_secret/git/git-ssh-secret.yaml"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ssh key with password",
|
||||||
|
args: "create secret git podinfo-auth --url=ssh://git@github.com/stefanprodan/podinfo --private-key-file=./testdata/create_secret/git/ecdsa-password.private --password=password --namespace=my-namespace --export",
|
||||||
|
assert: assertGoldenFile("testdata/create_secret/git/git-ssh-secret-password.yaml"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.args,
|
||||||
|
assert: tt.assert,
|
||||||
|
}
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
@@ -68,9 +67,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createSecretHelmCmdRun(cmd *cobra.Command, args []string) error {
|
func createSecretHelmCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
|
||||||
return fmt.Errorf("secret name is required")
|
|
||||||
}
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
labels, err := parseLabels()
|
labels, err := parseLabels()
|
||||||
@@ -80,7 +76,7 @@ func createSecretHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
opts := sourcesecret.Options{
|
opts := sourcesecret.Options{
|
||||||
Name: name,
|
Name: name,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
Username: secretHelmArgs.username,
|
Username: secretHelmArgs.username,
|
||||||
Password: secretHelmArgs.password,
|
Password: secretHelmArgs.password,
|
||||||
@@ -94,13 +90,13 @@ func createSecretHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if createArgs.export {
|
if createArgs.export {
|
||||||
fmt.Println(secret.Content)
|
rootCmd.Println(secret.Content)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -112,6 +108,6 @@ func createSecretHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Actionf("helm secret '%s' created in '%s' namespace", name, rootArgs.namespace)
|
logger.Actionf("helm secret '%s' created in '%s' namespace", name, *kubeconfigArgs.Namespace)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
31
cmd/flux/create_secret_helm_test.go
Normal file
31
cmd/flux/create_secret_helm_test.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateHelmSecret(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
assert assertFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
args: "create secret helm",
|
||||||
|
assert: assertError("name is required"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: "create secret helm helm-secret --username=my-username --password=my-password --namespace=my-namespace --export",
|
||||||
|
assert: assertGoldenFile("testdata/create_secret/helm/secret-helm.yaml"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.args,
|
||||||
|
assert: tt.assert,
|
||||||
|
}
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
@@ -67,9 +66,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createSecretTLSCmdRun(cmd *cobra.Command, args []string) error {
|
func createSecretTLSCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
|
||||||
return fmt.Errorf("secret name is required")
|
|
||||||
}
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
labels, err := parseLabels()
|
labels, err := parseLabels()
|
||||||
@@ -79,7 +75,7 @@ func createSecretTLSCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
opts := sourcesecret.Options{
|
opts := sourcesecret.Options{
|
||||||
Name: name,
|
Name: name,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
CAFilePath: secretTLSArgs.caFile,
|
CAFilePath: secretTLSArgs.caFile,
|
||||||
CertFilePath: secretTLSArgs.certFile,
|
CertFilePath: secretTLSArgs.certFile,
|
||||||
@@ -91,13 +87,13 @@ func createSecretTLSCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if createArgs.export {
|
if createArgs.export {
|
||||||
fmt.Println(secret.Content)
|
rootCmd.Print(secret.Content)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -109,6 +105,6 @@ func createSecretTLSCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Actionf("tls secret '%s' created in '%s' namespace", name, rootArgs.namespace)
|
logger.Actionf("tls secret '%s' created in '%s' namespace", name, *kubeconfigArgs.Namespace)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
31
cmd/flux/create_secret_tls_test.go
Normal file
31
cmd/flux/create_secret_tls_test.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateTlsSecretNoArgs(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
assert assertFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
args: "create secret tls",
|
||||||
|
assert: assertError("name is required"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: "create secret tls certs --namespace=my-namespace --cert-file=./testdata/create_secret/tls/test-cert.pem --key-file=./testdata/create_secret/tls/test-key.pem --export",
|
||||||
|
assert: assertGoldenFile("testdata/create_secret/tls/secret-tls.yaml"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.args,
|
||||||
|
assert: tt.assert,
|
||||||
|
}
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,8 @@ limitations under the License.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,6 +28,14 @@ var createSourceCmd = &cobra.Command{
|
|||||||
Long: "The create source sub-commands generate sources.",
|
Long: "The create source sub-commands generate sources.",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type createSourceFlags struct {
|
||||||
|
fetchTimeout time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
var createSourceArgs createSourceFlags
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
createSourceCmd.PersistentFlags().DurationVar(&createSourceArgs.fetchTimeout, "fetch-timeout", createSourceArgs.fetchTimeout,
|
||||||
|
"set a timeout for fetch operations performed by source-controller (e.g. 'git clone' or 'helm repo update')")
|
||||||
createCmd.AddCommand(createSourceCmd)
|
createCmd.AddCommand(createSourceCmd)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,9 +93,6 @@ func NewSourceBucketFlags() sourceBucketFlags {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
|
func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
|
||||||
return fmt.Errorf("Bucket source name is required")
|
|
||||||
}
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
if sourceBucketArgs.name == "" {
|
if sourceBucketArgs.name == "" {
|
||||||
@@ -120,7 +117,7 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
bucket := &sourcev1.Bucket{
|
bucket := &sourcev1.Bucket{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: sourceLabels,
|
Labels: sourceLabels,
|
||||||
},
|
},
|
||||||
Spec: sourcev1.BucketSpec{
|
Spec: sourcev1.BucketSpec{
|
||||||
@@ -134,6 +131,11 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if createSourceArgs.fetchTimeout > 0 {
|
||||||
|
bucket.Spec.Timeout = &metav1.Duration{Duration: createSourceArgs.fetchTimeout}
|
||||||
|
}
|
||||||
|
|
||||||
if sourceBucketArgs.secretRef != "" {
|
if sourceBucketArgs.secretRef != "" {
|
||||||
bucket.Spec.SecretRef = &meta.LocalObjectReference{
|
bucket.Spec.SecretRef = &meta.LocalObjectReference{
|
||||||
Name: sourceBucketArgs.secretRef,
|
Name: sourceBucketArgs.secretRef,
|
||||||
@@ -147,7 +149,7 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -160,7 +162,7 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
secret := corev1.Secret{
|
secret := corev1.Secret{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: secretName,
|
Name: secretName,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: sourceLabels,
|
Labels: sourceLabels,
|
||||||
},
|
},
|
||||||
StringData: map[string]string{},
|
StringData: map[string]string{},
|
||||||
|
|||||||
@@ -143,16 +143,13 @@ func init() {
|
|||||||
|
|
||||||
func newSourceGitFlags() sourceGitFlags {
|
func newSourceGitFlags() sourceGitFlags {
|
||||||
return sourceGitFlags{
|
return sourceGitFlags{
|
||||||
keyAlgorithm: flags.PublicKeyAlgorithm(sourcesecret.RSAPrivateKeyAlgorithm),
|
keyAlgorithm: flags.PublicKeyAlgorithm(sourcesecret.ECDSAPrivateKeyAlgorithm),
|
||||||
keyRSABits: 2048,
|
keyRSABits: 2048,
|
||||||
keyECDSACurve: flags.ECDSACurve{Curve: elliptic.P384()},
|
keyECDSACurve: flags.ECDSACurve{Curve: elliptic.P384()},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
|
||||||
return fmt.Errorf("GitRepository source name is required")
|
|
||||||
}
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
if sourceGitArgs.url == "" {
|
if sourceGitArgs.url == "" {
|
||||||
@@ -193,7 +190,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
gitRepository := sourcev1.GitRepository{
|
gitRepository := sourcev1.GitRepository{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: sourceLabels,
|
Labels: sourceLabels,
|
||||||
},
|
},
|
||||||
Spec: sourcev1.GitRepositorySpec{
|
Spec: sourcev1.GitRepositorySpec{
|
||||||
@@ -206,6 +203,10 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if createSourceArgs.fetchTimeout > 0 {
|
||||||
|
gitRepository.Spec.Timeout = &metav1.Duration{Duration: createSourceArgs.fetchTimeout}
|
||||||
|
}
|
||||||
|
|
||||||
if sourceGitArgs.gitImplementation != "" {
|
if sourceGitArgs.gitImplementation != "" {
|
||||||
gitRepository.Spec.GitImplementation = sourceGitArgs.gitImplementation.String()
|
gitRepository.Spec.GitImplementation = sourceGitArgs.gitImplementation.String()
|
||||||
}
|
}
|
||||||
@@ -231,7 +232,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -240,7 +241,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
if sourceGitArgs.secretRef == "" {
|
if sourceGitArgs.secretRef == "" {
|
||||||
secretOpts := sourcesecret.Options{
|
secretOpts := sourcesecret.Options{
|
||||||
Name: name,
|
Name: name,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
||||||
}
|
}
|
||||||
switch u.Scheme {
|
switch u.Scheme {
|
||||||
|
|||||||
@@ -1,5 +1,22 @@
|
|||||||
|
//go:build unit
|
||||||
// +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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -79,7 +96,7 @@ func TestCreateSourceGit(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"NoArgs",
|
"NoArgs",
|
||||||
"create source git",
|
"create source git",
|
||||||
assertError("GitRepository source name is required"),
|
assertError("name is required"),
|
||||||
nil,
|
nil,
|
||||||
}, {
|
}, {
|
||||||
"Succeeded",
|
"Succeeded",
|
||||||
|
|||||||
@@ -91,9 +91,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
|
||||||
return fmt.Errorf("HelmRepository source name is required")
|
|
||||||
}
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
if sourceHelmArgs.url == "" {
|
if sourceHelmArgs.url == "" {
|
||||||
@@ -118,7 +115,7 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
helmRepository := &sourcev1.HelmRepository{
|
helmRepository := &sourcev1.HelmRepository{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Labels: sourceLabels,
|
Labels: sourceLabels,
|
||||||
},
|
},
|
||||||
Spec: sourcev1.HelmRepositorySpec{
|
Spec: sourcev1.HelmRepositorySpec{
|
||||||
@@ -129,6 +126,10 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if createSourceArgs.fetchTimeout > 0 {
|
||||||
|
helmRepository.Spec.Timeout = &metav1.Duration{Duration: createSourceArgs.fetchTimeout}
|
||||||
|
}
|
||||||
|
|
||||||
if sourceHelmArgs.secretRef != "" {
|
if sourceHelmArgs.secretRef != "" {
|
||||||
helmRepository.Spec.SecretRef = &meta.LocalObjectReference{
|
helmRepository.Spec.SecretRef = &meta.LocalObjectReference{
|
||||||
Name: sourceHelmArgs.secretRef,
|
Name: sourceHelmArgs.secretRef,
|
||||||
@@ -143,7 +144,7 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -153,7 +154,7 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
secretName := fmt.Sprintf("helm-%s", name)
|
secretName := fmt.Sprintf("helm-%s", name)
|
||||||
secretOpts := sourcesecret.Options{
|
secretOpts := sourcesecret.Options{
|
||||||
Name: secretName,
|
Name: secretName,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Username: sourceHelmArgs.username,
|
Username: sourceHelmArgs.username,
|
||||||
Password: sourceHelmArgs.password,
|
Password: sourceHelmArgs.password,
|
||||||
CertFilePath: sourceHelmArgs.certFile,
|
CertFilePath: sourceHelmArgs.certFile,
|
||||||
|
|||||||
@@ -70,9 +70,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createTenantCmdRun(cmd *cobra.Command, args []string) error {
|
func createTenantCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
|
||||||
return fmt.Errorf("tenant name is required")
|
|
||||||
}
|
|
||||||
tenant := args[0]
|
tenant := args[0]
|
||||||
if err := validation.IsQualifiedName(tenant); len(err) > 0 {
|
if err := validation.IsQualifiedName(tenant); len(err) > 0 {
|
||||||
return fmt.Errorf("invalid tenant name '%s': %v", tenant, err)
|
return fmt.Errorf("invalid tenant name '%s': %v", tenant, err)
|
||||||
@@ -159,7 +156,7 @@ func createTenantCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
55
cmd/flux/create_test.go
Normal file
55
cmd/flux/create_test.go
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/util/rand"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_validateObjectName(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
valid bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "flux-system",
|
||||||
|
valid: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "-flux-system",
|
||||||
|
valid: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "-flux-system-",
|
||||||
|
valid: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "third.first",
|
||||||
|
valid: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "THirdfirst",
|
||||||
|
valid: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "THirdfirst",
|
||||||
|
valid: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: rand.String(63),
|
||||||
|
valid: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: rand.String(64),
|
||||||
|
valid: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
valid := validateObjectName(tt.name)
|
||||||
|
if valid != tt.valid {
|
||||||
|
t.Errorf("expected name %q to return %t for validateObjectName func but got %t",
|
||||||
|
tt.name, tt.valid, valid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,13 +60,13 @@ func (del deleteCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
namespacedName := types.NamespacedName{
|
namespacedName := types.NamespacedName{
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ func (del deleteCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Actionf("deleting %s %s in %s namespace", del.humanKind, name, rootArgs.namespace)
|
logger.Actionf("deleting %s %s in %s namespace", del.humanKind, name, *kubeconfigArgs.Namespace)
|
||||||
err = kubeClient.Delete(ctx, del.object.asClientObject())
|
err = kubeClient.Delete(ctx, del.object.asClientObject())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
31
cmd/flux/diff.go
Normal file
31
cmd/flux/diff.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
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 (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var diffCmd = &cobra.Command{
|
||||||
|
Use: "diff",
|
||||||
|
Short: "Diff a flux resource",
|
||||||
|
Long: "The diff command is used to do a server-side dry-run on flux resources, then prints the diff.",
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(diffCmd)
|
||||||
|
}
|
||||||
113
cmd/flux/diff_kustomization.go
Normal file
113
cmd/flux/diff_kustomization.go
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
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 (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/build"
|
||||||
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var diffKsCmd = &cobra.Command{
|
||||||
|
Use: "kustomization",
|
||||||
|
Aliases: []string{"ks"},
|
||||||
|
Short: "Diff Kustomization",
|
||||||
|
Long: `The diff command does a build, then it performs a server-side dry-run and prints the diff.
|
||||||
|
Exit status: 0 No differences were found. 1 Differences were found. >1 diff failed with an error.`,
|
||||||
|
Example: `# Preview local changes as they were applied on the cluster
|
||||||
|
flux diff kustomization my-app --path ./path/to/local/manifests`,
|
||||||
|
ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)),
|
||||||
|
RunE: diffKsCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
type diffKsFlags struct {
|
||||||
|
path string
|
||||||
|
progressBar bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var diffKsArgs diffKsFlags
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
diffKsCmd.Flags().StringVar(&diffKsArgs.path, "path", "", "Path to a local directory that matches the specified Kustomization.spec.path.)")
|
||||||
|
diffKsCmd.Flags().BoolVar(&diffKsArgs.progressBar, "progress-bar", true, "Boolean to set the progress bar. The default value is true.")
|
||||||
|
diffCmd.AddCommand(diffKsCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func diffKsCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) < 1 {
|
||||||
|
return fmt.Errorf("%s name is required", kustomizationType.humanKind)
|
||||||
|
}
|
||||||
|
name := args[0]
|
||||||
|
|
||||||
|
if diffKsArgs.path == "" {
|
||||||
|
return &RequestError{StatusCode: 2, Err: fmt.Errorf("invalid resource path %q", diffKsArgs.path)}
|
||||||
|
}
|
||||||
|
|
||||||
|
if fs, err := os.Stat(diffKsArgs.path); err != nil || !fs.IsDir() {
|
||||||
|
return &RequestError{StatusCode: 2, Err: fmt.Errorf("invalid resource path %q", diffKsArgs.path)}
|
||||||
|
}
|
||||||
|
|
||||||
|
var builder *build.Builder
|
||||||
|
var err error
|
||||||
|
if diffKsArgs.progressBar {
|
||||||
|
builder, err = build.NewBuilder(kubeconfigArgs, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout), build.WithProgressBar())
|
||||||
|
} else {
|
||||||
|
builder, err = build.NewBuilder(kubeconfigArgs, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return &RequestError{StatusCode: 2, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a signal channel
|
||||||
|
sigc := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigc, os.Interrupt)
|
||||||
|
|
||||||
|
errChan := make(chan error)
|
||||||
|
go func() {
|
||||||
|
output, hasChanged, err := builder.Diff()
|
||||||
|
if err != nil {
|
||||||
|
errChan <- &RequestError{StatusCode: 2, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Print(output)
|
||||||
|
|
||||||
|
if hasChanged {
|
||||||
|
errChan <- &RequestError{StatusCode: 1, Err: fmt.Errorf("identified at least one change, exiting with non-zero exit code")}
|
||||||
|
} else {
|
||||||
|
errChan <- nil
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-sigc:
|
||||||
|
fmt.Println("Build cancelled... exiting.")
|
||||||
|
return builder.Cancel()
|
||||||
|
case err := <-errChan:
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
145
cmd/flux/diff_kustomization_test.go
Normal file
145
cmd/flux/diff_kustomization_test.go
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
//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"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/build"
|
||||||
|
"github.com/fluxcd/pkg/ssa"
|
||||||
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDiffKustomization(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
objectFile string
|
||||||
|
assert assertFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "no args",
|
||||||
|
args: "diff kustomization podinfo",
|
||||||
|
objectFile: "",
|
||||||
|
assert: assertError("invalid resource path \"\""),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "diff nothing deployed",
|
||||||
|
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
|
||||||
|
objectFile: "",
|
||||||
|
assert: assertGoldenFile("./testdata/diff-kustomization/nothing-is-deployed.golden"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "diff with a deployment object",
|
||||||
|
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
|
||||||
|
objectFile: "./testdata/diff-kustomization/deployment.yaml",
|
||||||
|
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-deployment.golden"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "diff with a drifted service object",
|
||||||
|
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
|
||||||
|
objectFile: "./testdata/diff-kustomization/service.yaml",
|
||||||
|
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drifted-service.golden"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "diff with a drifted secret object",
|
||||||
|
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
|
||||||
|
objectFile: "./testdata/diff-kustomization/secret.yaml",
|
||||||
|
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drifted-secret.golden"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "diff with a drifted key in sops secret object",
|
||||||
|
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
|
||||||
|
objectFile: "./testdata/diff-kustomization/key-sops-secret.yaml",
|
||||||
|
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drifted-key-sops-secret.golden"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "diff with a drifted value in sops secret object",
|
||||||
|
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
|
||||||
|
objectFile: "./testdata/diff-kustomization/value-sops-secret.yaml",
|
||||||
|
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drifted-value-sops-secret.golden"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "diff with a sops dockerconfigjson secret object",
|
||||||
|
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
|
||||||
|
objectFile: "./testdata/diff-kustomization/dockerconfigjson-sops-secret.yaml",
|
||||||
|
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-dockerconfigjson-sops-secret.golden"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "diff with a sops stringdata secret object",
|
||||||
|
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
|
||||||
|
objectFile: "./testdata/diff-kustomization/stringdata-sops-secret.yaml",
|
||||||
|
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drifted-stringdata-sops-secret.golden"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl := map[string]string{
|
||||||
|
"fluxns": allocateNamespace("flux-system"),
|
||||||
|
}
|
||||||
|
|
||||||
|
b, _ := build.NewBuilder(kubeconfigArgs, "podinfo", "")
|
||||||
|
|
||||||
|
resourceManager, err := b.Manager()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
setup(t, tmpl)
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if tt.objectFile != "" {
|
||||||
|
resourceManager.ApplyAll(context.Background(), createObjectFromFile(tt.objectFile, tmpl, t), ssa.DefaultApplyOptions())
|
||||||
|
}
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.args + " -n " + tmpl["fluxns"],
|
||||||
|
assert: tt.assert,
|
||||||
|
}
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
if tt.objectFile != "" {
|
||||||
|
testEnv.DeleteObjectFile(tt.objectFile, tmpl, t)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func createObjectFromFile(objectFile string, templateValues map[string]string, t *testing.T) []*unstructured.Unstructured {
|
||||||
|
buf, err := os.ReadFile(objectFile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Error reading file '%s': %v", objectFile, err)
|
||||||
|
}
|
||||||
|
content, err := executeTemplate(string(buf), templateValues)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Error evaluating template file '%s': '%v'", objectFile, err)
|
||||||
|
}
|
||||||
|
clientObjects, err := readYamlObjects(strings.NewReader(content))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Error decoding yaml file '%s': %v", objectFile, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ssa.SetNativeKindsDefaults(clientObjects); err != nil {
|
||||||
|
t.Fatalf("Error setting native kinds defaults for '%s': %v", objectFile, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return clientObjects
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
@@ -73,19 +74,19 @@ func (export exportCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if exportArgs.all {
|
if exportArgs.all {
|
||||||
err = kubeClient.List(ctx, export.list.asClientList(), client.InNamespace(rootArgs.namespace))
|
err = kubeClient.List(ctx, export.list.asClientList(), client.InNamespace(*kubeconfigArgs.Namespace))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if export.list.len() == 0 {
|
if export.list.len() == 0 {
|
||||||
return fmt.Errorf("no objects found in %s namespace", rootArgs.namespace)
|
return fmt.Errorf("no objects found in %s namespace", *kubeconfigArgs.Namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < export.list.len(); i++ {
|
for i := 0; i < export.list.len(); i++ {
|
||||||
@@ -96,7 +97,7 @@ func (export exportCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
} else {
|
} else {
|
||||||
name := args[0]
|
name := args[0]
|
||||||
namespacedName := types.NamespacedName{
|
namespacedName := types.NamespacedName{
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
err = kubeClient.Get(ctx, namespacedName, export.object.asClientObject())
|
err = kubeClient.Get(ctx, namespacedName, export.object.asClientObject())
|
||||||
@@ -113,8 +114,8 @@ func printExport(export interface{}) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("---")
|
rootCmd.Println("---")
|
||||||
fmt.Println(resourceToString(data))
|
rootCmd.Println(resourceToString(data))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@@ -58,19 +59,19 @@ func (export exportWithSecretCommand) run(cmd *cobra.Command, args []string) err
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if exportArgs.all {
|
if exportArgs.all {
|
||||||
err = kubeClient.List(ctx, export.list.asClientList(), client.InNamespace(rootArgs.namespace))
|
err = kubeClient.List(ctx, export.list.asClientList(), client.InNamespace(*kubeconfigArgs.Namespace))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if export.list.len() == 0 {
|
if export.list.len() == 0 {
|
||||||
return fmt.Errorf("no objects found in %s namespace", rootArgs.namespace)
|
return fmt.Errorf("no objects found in %s namespace", *kubeconfigArgs.Namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < export.list.len(); i++ {
|
for i := 0; i < export.list.len(); i++ {
|
||||||
@@ -88,7 +89,7 @@ func (export exportWithSecretCommand) run(cmd *cobra.Command, args []string) err
|
|||||||
} else {
|
} else {
|
||||||
name := args[0]
|
name := args[0]
|
||||||
namespacedName := types.NamespacedName{
|
namespacedName := types.NamespacedName{
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
err = kubeClient.Get(ctx, namespacedName, export.object.asClientObject())
|
err = kubeClient.Get(ctx, namespacedName, export.object.asClientObject())
|
||||||
|
|||||||
89
cmd/flux/export_test.go
Normal file
89
cmd/flux/export_test.go
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
//go:build unit
|
||||||
|
// +build unit
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestExport(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
arg string
|
||||||
|
goldenFile string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"alert-provider",
|
||||||
|
"export alert-provider slack",
|
||||||
|
"testdata/export/provider.yaml",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alert",
|
||||||
|
"export alert flux-system",
|
||||||
|
"testdata/export/alert.yaml",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"image policy",
|
||||||
|
"export image policy flux-system",
|
||||||
|
"testdata/export/image-policy.yaml",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"image repository",
|
||||||
|
"export image repository flux-system",
|
||||||
|
"testdata/export/image-repo.yaml",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"image update",
|
||||||
|
"export image update flux-system",
|
||||||
|
"testdata/export/image-update.yaml",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"source git",
|
||||||
|
"export source git flux-system",
|
||||||
|
"testdata/export/git-repo.yaml",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"source helm",
|
||||||
|
"export source helm flux-system",
|
||||||
|
"testdata/export/helm-repo.yaml",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"receiver",
|
||||||
|
"export receiver flux-system",
|
||||||
|
"testdata/export/receiver.yaml",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kustomization",
|
||||||
|
"export kustomization flux-system",
|
||||||
|
"testdata/export/ks.yaml",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"helmrelease",
|
||||||
|
"export helmrelease flux-system",
|
||||||
|
"testdata/export/helm-release.yaml",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bucket",
|
||||||
|
"export source bucket flux-system",
|
||||||
|
"testdata/export/bucket.yaml",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
objectFile := "testdata/export/objects.yaml"
|
||||||
|
tmpl := map[string]string{
|
||||||
|
"fluxns": allocateNamespace("flux-system"),
|
||||||
|
}
|
||||||
|
testEnv.CreateObjectFile(objectFile, tmpl, t)
|
||||||
|
|
||||||
|
for _, tt := range cases {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.arg + " -n=" + tmpl["fluxns"],
|
||||||
|
assert: assertGoldenTemplateFile(tt.goldenFile, tmpl),
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -135,14 +135,14 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var listOpts []client.ListOption
|
var listOpts []client.ListOption
|
||||||
if !getArgs.allNamespaces {
|
if !getArgs.allNamespaces {
|
||||||
listOpts = append(listOpts, client.InNamespace(rootArgs.namespace))
|
listOpts = append(listOpts, client.InNamespace(*kubeconfigArgs.Namespace))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
@@ -162,7 +162,7 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
if get.list.len() == 0 {
|
if get.list.len() == 0 {
|
||||||
if !getAll {
|
if !getAll {
|
||||||
logger.Failuref("no %s objects found in %s namespace", get.kind, rootArgs.namespace)
|
logger.Failuref("no %s objects found in %s namespace", get.kind, *kubeconfigArgs.Namespace)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,9 +25,6 @@ var getImageCmd = &cobra.Command{
|
|||||||
Aliases: []string{"image"},
|
Aliases: []string{"image"},
|
||||||
Short: "Get image automation object status",
|
Short: "Get image automation object status",
|
||||||
Long: "The get image sub-commands print the status of image automation objects.",
|
Long: "The get image sub-commands print the status of image automation objects.",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
|
||||||
return validateWatchOption(cmd, "images")
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -18,10 +18,12 @@ 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"
|
||||||
@@ -78,6 +80,10 @@ 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 = shortenCommitSha(revision)
|
||||||
|
msg = shortenCommitSha(msg)
|
||||||
|
}
|
||||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||||
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
|
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
|
||||||
}
|
}
|
||||||
@@ -94,3 +100,13 @@ 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
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,10 +25,6 @@ var getSourceCmd = &cobra.Command{
|
|||||||
Aliases: []string{"source"},
|
Aliases: []string{"source"},
|
||||||
Short: "Get source statuses",
|
Short: "Get source statuses",
|
||||||
Long: "The get source sub-commands print the statuses of the sources.",
|
Long: "The get source sub-commands print the statuses of the sources.",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
|
||||||
|
|
||||||
return validateWatchOption(cmd, "sources")
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ 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/v1beta1"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||||
@@ -80,6 +81,10 @@ 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 = shortenCommitSha(revision)
|
||||||
|
msg = shortenCommitSha(msg)
|
||||||
|
}
|
||||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||||
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
|
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ import (
|
|||||||
// helmv2.HelmRelease
|
// helmv2.HelmRelease
|
||||||
|
|
||||||
var helmReleaseType = apiType{
|
var helmReleaseType = apiType{
|
||||||
kind: helmv2.HelmReleaseKind,
|
kind: helmv2.HelmReleaseKind,
|
||||||
humanKind: "helmreleases",
|
humanKind: "helmrelease",
|
||||||
|
groupVersion: helmv2.GroupVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
type helmReleaseAdapter struct {
|
type helmReleaseAdapter struct {
|
||||||
|
|||||||
@@ -1,5 +1,22 @@
|
|||||||
|
//go:build e2e
|
||||||
// +build e2e
|
// +build e2e
|
||||||
|
|
||||||
|
/*
|
||||||
|
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
|
package main
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|||||||
@@ -30,8 +30,9 @@ import (
|
|||||||
// imagev1.ImageRepository
|
// imagev1.ImageRepository
|
||||||
|
|
||||||
var imageRepositoryType = apiType{
|
var imageRepositoryType = apiType{
|
||||||
kind: imagev1.ImageRepositoryKind,
|
kind: imagev1.ImageRepositoryKind,
|
||||||
humanKind: "image repository",
|
humanKind: "image repository",
|
||||||
|
groupVersion: imagev1.GroupVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
type imageRepositoryAdapter struct {
|
type imageRepositoryAdapter struct {
|
||||||
@@ -63,8 +64,9 @@ func (a imageRepositoryListAdapter) len() int {
|
|||||||
// imagev1.ImagePolicy
|
// imagev1.ImagePolicy
|
||||||
|
|
||||||
var imagePolicyType = apiType{
|
var imagePolicyType = apiType{
|
||||||
kind: imagev1.ImagePolicyKind,
|
kind: imagev1.ImagePolicyKind,
|
||||||
humanKind: "image policy",
|
humanKind: "image policy",
|
||||||
|
groupVersion: imagev1.GroupVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
type imagePolicyAdapter struct {
|
type imagePolicyAdapter struct {
|
||||||
@@ -92,8 +94,9 @@ func (a imagePolicyListAdapter) len() int {
|
|||||||
// autov1.ImageUpdateAutomation
|
// autov1.ImageUpdateAutomation
|
||||||
|
|
||||||
var imageUpdateAutomationType = apiType{
|
var imageUpdateAutomationType = apiType{
|
||||||
kind: autov1.ImageUpdateAutomationKind,
|
kind: autov1.ImageUpdateAutomationKind,
|
||||||
humanKind: "image update automation",
|
humanKind: "image update automation",
|
||||||
|
groupVersion: autov1.GroupVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
type imageUpdateAutomationAdapter struct {
|
type imageUpdateAutomationAdapter struct {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build e2e
|
||||||
// +build e2e
|
// +build e2e
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -132,7 +131,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
logger.Generatef("generating manifests")
|
logger.Generatef("generating manifests")
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpDir, err := os.MkdirTemp("", rootArgs.namespace)
|
tmpDir, err := os.MkdirTemp("", *kubeconfigArgs.Namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -149,7 +148,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
opts := install.Options{
|
opts := install.Options{
|
||||||
BaseURL: installArgs.manifestsPath,
|
BaseURL: installArgs.manifestsPath,
|
||||||
Version: installArgs.version,
|
Version: installArgs.version,
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Components: components,
|
Components: components,
|
||||||
Registry: installArgs.registry,
|
Registry: installArgs.registry,
|
||||||
ImagePullSecret: installArgs.imagePullSecret,
|
ImagePullSecret: installArgs.imagePullSecret,
|
||||||
@@ -157,7 +156,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
NetworkPolicy: installArgs.networkPolicy,
|
NetworkPolicy: installArgs.networkPolicy,
|
||||||
LogLevel: installArgs.logLevel.String(),
|
LogLevel: installArgs.logLevel.String(),
|
||||||
NotificationController: rootArgs.defaults.NotificationController,
|
NotificationController: rootArgs.defaults.NotificationController,
|
||||||
ManifestFile: fmt.Sprintf("%s.yaml", rootArgs.namespace),
|
ManifestFile: fmt.Sprintf("%s.yaml", *kubeconfigArgs.Namespace),
|
||||||
Timeout: rootArgs.timeout,
|
Timeout: rootArgs.timeout,
|
||||||
ClusterDomain: installArgs.clusterDomain,
|
ClusterDomain: installArgs.clusterDomain,
|
||||||
TolerationKeys: installArgs.tolerationKeys,
|
TolerationKeys: installArgs.tolerationKeys,
|
||||||
@@ -177,36 +176,32 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if installArgs.export {
|
if installArgs.export {
|
||||||
fmt.Println("---")
|
|
||||||
fmt.Println("# Flux version:", installArgs.version)
|
|
||||||
fmt.Println("# Components:", strings.Join(components, ","))
|
|
||||||
fmt.Print(manifest.Content)
|
fmt.Print(manifest.Content)
|
||||||
fmt.Println("---")
|
|
||||||
return nil
|
return nil
|
||||||
} else if rootArgs.verbose {
|
} else if rootArgs.verbose {
|
||||||
fmt.Print(manifest.Content)
|
fmt.Print(manifest.Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Successf("manifests build completed")
|
logger.Successf("manifests build completed")
|
||||||
logger.Actionf("installing components in %s namespace", rootArgs.namespace)
|
logger.Actionf("installing components in %s namespace", *kubeconfigArgs.Namespace)
|
||||||
|
|
||||||
if installArgs.dryRun {
|
if installArgs.dryRun {
|
||||||
logger.Successf("install dry-run finished")
|
logger.Successf("install dry-run finished")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
applyOutput, err := utils.Apply(ctx, rootArgs.kubeconfig, rootArgs.kubecontext, filepath.Join(tmpDir, manifest.Path))
|
applyOutput, err := utils.Apply(ctx, kubeconfigArgs, filepath.Join(tmpDir, manifest.Path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("install failed: %w", err)
|
return fmt.Errorf("install failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintln(os.Stderr, applyOutput)
|
fmt.Fprintln(os.Stderr, applyOutput)
|
||||||
|
|
||||||
kubeConfig, err := utils.KubeConfig(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeConfig, err := utils.KubeConfig(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("install failed: %w", err)
|
return fmt.Errorf("install failed: %w", err)
|
||||||
}
|
}
|
||||||
statusChecker, err := status.NewStatusChecker(kubeConfig, time.Second, rootArgs.timeout, logger)
|
statusChecker, err := status.NewStatusChecker(kubeConfig, 5*time.Second, rootArgs.timeout, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("install failed: %w", err)
|
return fmt.Errorf("install failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ import (
|
|||||||
// kustomizev1.Kustomization
|
// kustomizev1.Kustomization
|
||||||
|
|
||||||
var kustomizationType = apiType{
|
var kustomizationType = apiType{
|
||||||
kind: kustomizev1.KustomizationKind,
|
kind: kustomizev1.KustomizationKind,
|
||||||
humanKind: "kustomizations",
|
humanKind: "kustomization",
|
||||||
|
groupVersion: kustomizev1.GroupVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
type kustomizationAdapter struct {
|
type kustomizationAdapter struct {
|
||||||
|
|||||||
@@ -1,5 +1,22 @@
|
|||||||
|
//go:build e2e
|
||||||
// +build e2e
|
// +build e2e
|
||||||
|
|
||||||
|
/*
|
||||||
|
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
|
package main
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -39,6 +39,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logsCmd = &cobra.Command{
|
var logsCmd = &cobra.Command{
|
||||||
@@ -93,12 +94,12 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func logsCmdRun(cmd *cobra.Command, args []string) error {
|
func logsCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
fluxSelector := fmt.Sprintf("app.kubernetes.io/instance=%s", logsArgs.fluxNamespace)
|
fluxSelector := fmt.Sprintf("%s=%s", manifestgen.PartOfLabelKey, manifestgen.PartOfLabelValue)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
cfg, err := utils.KubeConfig(rootArgs.kubeconfig, rootArgs.kubecontext)
|
cfg, err := utils.KubeConfig(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -277,7 +278,7 @@ func filterPrintLog(t *template.Template, l *ControllerLogEntry) {
|
|||||||
if logsArgs.logLevel != "" && logsArgs.logLevel != l.Level ||
|
if logsArgs.logLevel != "" && logsArgs.logLevel != l.Level ||
|
||||||
logsArgs.kind != "" && strings.ToLower(logsArgs.kind) != strings.ToLower(l.Kind) ||
|
logsArgs.kind != "" && strings.ToLower(logsArgs.kind) != strings.ToLower(l.Kind) ||
|
||||||
logsArgs.name != "" && strings.ToLower(logsArgs.name) != strings.ToLower(l.Name) ||
|
logsArgs.name != "" && strings.ToLower(logsArgs.name) != strings.ToLower(l.Name) ||
|
||||||
!logsArgs.allNamespaces && strings.ToLower(rootArgs.namespace) != strings.ToLower(l.Namespace) {
|
!logsArgs.allNamespaces && strings.ToLower(*kubeconfigArgs.Namespace) != strings.ToLower(l.Namespace) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,22 @@
|
|||||||
|
//go:build unit
|
||||||
// +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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -17,13 +17,17 @@ limitations under the License.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"golang.org/x/term"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||||
@@ -95,30 +99,46 @@ Command line utility for assembling Kubernetes CD pipelines the GitOps way.`,
|
|||||||
var logger = stderrLogger{stderr: os.Stderr}
|
var logger = stderrLogger{stderr: os.Stderr}
|
||||||
|
|
||||||
type rootFlags struct {
|
type rootFlags struct {
|
||||||
kubeconfig string
|
|
||||||
kubecontext string
|
|
||||||
namespace string
|
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
verbose bool
|
verbose bool
|
||||||
pollInterval time.Duration
|
pollInterval time.Duration
|
||||||
defaults install.Options
|
defaults install.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RequestError is a custom error type that wraps an error returned by the flux api.
|
||||||
|
type RequestError struct {
|
||||||
|
StatusCode int
|
||||||
|
Err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RequestError) Error() string {
|
||||||
|
return r.Err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
var rootArgs = NewRootFlags()
|
var rootArgs = NewRootFlags()
|
||||||
|
var kubeconfigArgs = genericclioptions.NewConfigFlags(false)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.PersistentFlags().StringVarP(&rootArgs.namespace, "namespace", "n", rootArgs.defaults.Namespace, "the namespace scope for this operation")
|
|
||||||
rootCmd.RegisterFlagCompletionFunc("namespace", resourceNamesCompletionFunc(corev1.SchemeGroupVersion.WithKind("Namespace")))
|
|
||||||
|
|
||||||
rootCmd.PersistentFlags().DurationVar(&rootArgs.timeout, "timeout", 5*time.Minute, "timeout for this operation")
|
rootCmd.PersistentFlags().DurationVar(&rootArgs.timeout, "timeout", 5*time.Minute, "timeout for this operation")
|
||||||
rootCmd.PersistentFlags().BoolVar(&rootArgs.verbose, "verbose", false, "print generated objects")
|
rootCmd.PersistentFlags().BoolVar(&rootArgs.verbose, "verbose", false, "print generated objects")
|
||||||
rootCmd.PersistentFlags().StringVarP(&rootArgs.kubeconfig, "kubeconfig", "", "",
|
|
||||||
"absolute path to the kubeconfig file")
|
|
||||||
|
|
||||||
rootCmd.PersistentFlags().StringVarP(&rootArgs.kubecontext, "context", "", "", "kubernetes context to use")
|
configureDefaultNamespace()
|
||||||
|
kubeconfigArgs.APIServer = nil // prevent AddFlags from configuring --server flag
|
||||||
|
kubeconfigArgs.Timeout = nil // prevent AddFlags from configuring --request-timeout flag, we have --timeout instead
|
||||||
|
kubeconfigArgs.AddFlags(rootCmd.PersistentFlags())
|
||||||
|
|
||||||
|
// Since some subcommands use the `-s` flag as a short version for `--silent`, we manually configure the server flag
|
||||||
|
// without the `-s` short version. While we're no longer on par with kubectl's flags, we maintain backwards compatibility
|
||||||
|
// on the CLI interface.
|
||||||
|
apiServer := ""
|
||||||
|
kubeconfigArgs.APIServer = &apiServer
|
||||||
|
rootCmd.PersistentFlags().StringVar(kubeconfigArgs.APIServer, "server", *kubeconfigArgs.APIServer, "The address and port of the Kubernetes API server")
|
||||||
|
|
||||||
rootCmd.RegisterFlagCompletionFunc("context", contextsCompletionFunc)
|
rootCmd.RegisterFlagCompletionFunc("context", contextsCompletionFunc)
|
||||||
|
rootCmd.RegisterFlagCompletionFunc("namespace", resourceNamesCompletionFunc(corev1.SchemeGroupVersion.WithKind("Namespace")))
|
||||||
|
|
||||||
rootCmd.DisableAutoGenTag = true
|
rootCmd.DisableAutoGenTag = true
|
||||||
|
rootCmd.SetOut(os.Stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRootFlags() rootFlags {
|
func NewRootFlags() rootFlags {
|
||||||
@@ -132,22 +152,28 @@ func NewRootFlags() rootFlags {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
configureKubeconfig()
|
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
|
|
||||||
|
if err, ok := err.(*RequestError); ok {
|
||||||
|
if err.StatusCode == 1 {
|
||||||
|
logger.Warningf("%v", err)
|
||||||
|
} else {
|
||||||
|
logger.Failuref("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Exit(err.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
logger.Failuref("%v", err)
|
logger.Failuref("%v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func configureKubeconfig() {
|
func configureDefaultNamespace() {
|
||||||
switch {
|
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
||||||
case len(rootArgs.kubeconfig) > 0:
|
fromEnv := os.Getenv("FLUX_SYSTEM_NAMESPACE")
|
||||||
case len(os.Getenv("KUBECONFIG")) > 0:
|
if fromEnv != "" {
|
||||||
rootArgs.kubeconfig = os.Getenv("KUBECONFIG")
|
kubeconfigArgs.Namespace = &fromEnv
|
||||||
default:
|
|
||||||
if home := homeDir(); len(home) > 0 {
|
|
||||||
rootArgs.kubeconfig = filepath.Join(home, ".kube", "config")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,3 +183,25 @@ func homeDir() string {
|
|||||||
}
|
}
|
||||||
return os.Getenv("USERPROFILE") // windows
|
return os.Getenv("USERPROFILE") // windows
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// readPasswordFromStdin reads a password from stdin and returns the input
|
||||||
|
// with trailing newline and/or carriage return removed. It also makes sure that terminal
|
||||||
|
// echoing is turned off if stdin is a terminal.
|
||||||
|
func readPasswordFromStdin(prompt string) (string, error) {
|
||||||
|
var out string
|
||||||
|
var err error
|
||||||
|
fmt.Fprint(os.Stdout, prompt)
|
||||||
|
stdinFD := int(os.Stdin.Fd())
|
||||||
|
if term.IsTerminal(stdinFD) {
|
||||||
|
var inBytes []byte
|
||||||
|
inBytes, err = term.ReadPassword(int(os.Stdin.Fd()))
|
||||||
|
out = string(inBytes)
|
||||||
|
} else {
|
||||||
|
out, err = bufio.NewReader(os.Stdin).ReadString('\n')
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("could not read from stdin: %w", err)
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
return strings.TrimRight(out, "\r\n"), nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,22 @@
|
|||||||
|
//go:build e2e
|
||||||
// +build e2e
|
// +build e2e
|
||||||
|
|
||||||
|
/*
|
||||||
|
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -19,7 +36,7 @@ func TestMain(m *testing.M) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("error creating kube manager: '%w'", err))
|
panic(fmt.Errorf("error creating kube manager: '%w'", err))
|
||||||
}
|
}
|
||||||
rootArgs.kubeconfig = testEnv.kubeConfigPath
|
kubeconfigArgs.KubeConfig = &testEnv.kubeConfigPath
|
||||||
|
|
||||||
// Install Flux.
|
// Install Flux.
|
||||||
output, err := executeCommand("install --components-extra=image-reflector-controller,image-automation-controller")
|
output, err := executeCommand("install --components-extra=image-reflector-controller,image-automation-controller")
|
||||||
@@ -38,7 +55,7 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
// Delete namespace and wait for finalisation
|
// Delete namespace and wait for finalisation
|
||||||
kubectlArgs := []string{"delete", "namespace", "flux-system"}
|
kubectlArgs := []string{"delete", "namespace", "flux-system"}
|
||||||
_, err = utils.ExecKubectlCommand(context.TODO(), utils.ModeStderrOS, rootArgs.kubeconfig, rootArgs.kubecontext, kubectlArgs...)
|
_, err = utils.ExecKubectlCommand(context.TODO(), utils.ModeStderrOS, *kubeconfigArgs.KubeConfig, *kubeconfigArgs.Context, kubectlArgs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("delete namespace error:'%w'", err))
|
panic(fmt.Errorf("delete namespace error:'%w'", err))
|
||||||
}
|
}
|
||||||
@@ -50,13 +67,13 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
func setupTestNamespace(namespace string) (func(), error) {
|
func setupTestNamespace(namespace string) (func(), error) {
|
||||||
kubectlArgs := []string{"create", "namespace", namespace}
|
kubectlArgs := []string{"create", "namespace", namespace}
|
||||||
_, err := utils.ExecKubectlCommand(context.TODO(), utils.ModeStderrOS, rootArgs.kubeconfig, rootArgs.kubecontext, kubectlArgs...)
|
_, err := utils.ExecKubectlCommand(context.TODO(), utils.ModeStderrOS, *kubeconfigArgs.KubeConfig, *kubeconfigArgs.Context, kubectlArgs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return func() {
|
return func() {
|
||||||
kubectlArgs := []string{"delete", "namespace", namespace}
|
kubectlArgs := []string{"delete", "namespace", namespace}
|
||||||
utils.ExecKubectlCommand(context.TODO(), utils.ModeCapture, rootArgs.kubeconfig, rootArgs.kubecontext, kubectlArgs...)
|
utils.ExecKubectlCommand(context.TODO(), utils.ModeCapture, *kubeconfigArgs.KubeConfig, *kubeconfigArgs.Context, kubectlArgs...)
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -33,8 +49,8 @@ func allocateNamespace(prefix string) string {
|
|||||||
return fmt.Sprintf("%s-%d", prefix, id)
|
return fmt.Sprintf("%s-%d", prefix, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readYamlObjects(rdr io.Reader) ([]unstructured.Unstructured, error) {
|
func readYamlObjects(rdr io.Reader) ([]*unstructured.Unstructured, error) {
|
||||||
objects := []unstructured.Unstructured{}
|
objects := []*unstructured.Unstructured{}
|
||||||
reader := k8syaml.NewYAMLReader(bufio.NewReader(rdr))
|
reader := k8syaml.NewYAMLReader(bufio.NewReader(rdr))
|
||||||
for {
|
for {
|
||||||
doc, err := reader.Read()
|
doc, err := reader.Read()
|
||||||
@@ -49,7 +65,7 @@ func readYamlObjects(rdr io.Reader) ([]unstructured.Unstructured, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
objects = append(objects, *unstructuredObj)
|
objects = append(objects, unstructuredObj)
|
||||||
}
|
}
|
||||||
return objects, nil
|
return objects, nil
|
||||||
}
|
}
|
||||||
@@ -80,7 +96,7 @@ func (m *testEnvKubeManager) CreateObjectFile(objectFile string, templateValues
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testEnvKubeManager) CreateObjects(clientObjects []unstructured.Unstructured, t *testing.T) error {
|
func (m *testEnvKubeManager) CreateObjects(clientObjects []*unstructured.Unstructured, t *testing.T) error {
|
||||||
for _, obj := range clientObjects {
|
for _, obj := range clientObjects {
|
||||||
// First create the object then set its status if present in the
|
// First create the object then set its status if present in the
|
||||||
// yaml file. Make a copy first since creating an object may overwrite
|
// yaml file. Make a copy first since creating an object may overwrite
|
||||||
@@ -91,7 +107,7 @@ func (m *testEnvKubeManager) CreateObjects(clientObjects []unstructured.Unstruct
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
obj.SetResourceVersion(createObj.GetResourceVersion())
|
obj.SetResourceVersion(createObj.GetResourceVersion())
|
||||||
err = m.client.Status().Update(context.Background(), &obj)
|
err = m.client.Status().Update(context.Background(), obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -99,6 +115,36 @@ func (m *testEnvKubeManager) CreateObjects(clientObjects []unstructured.Unstruct
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *testEnvKubeManager) DeleteObjectFile(objectFile string, templateValues map[string]string, t *testing.T) {
|
||||||
|
buf, err := os.ReadFile(objectFile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Error reading file '%s': %v", objectFile, err)
|
||||||
|
}
|
||||||
|
content, err := executeTemplate(string(buf), templateValues)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Error evaluating template file '%s': '%v'", objectFile, err)
|
||||||
|
}
|
||||||
|
clientObjects, err := readYamlObjects(strings.NewReader(content))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Error decoding yaml file '%s': %v", objectFile, err)
|
||||||
|
}
|
||||||
|
err = m.DeleteObjects(clientObjects, t)
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("Error deleting test objects: '%v'", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *testEnvKubeManager) DeleteObjects(clientObjects []*unstructured.Unstructured, t *testing.T) error {
|
||||||
|
for _, obj := range clientObjects {
|
||||||
|
err := m.client.Delete(context.Background(), obj)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *testEnvKubeManager) Stop() error {
|
func (m *testEnvKubeManager) Stop() error {
|
||||||
if m.testEnv == nil {
|
if m.testEnv == nil {
|
||||||
return fmt.Errorf("do nothing because testEnv is nil")
|
return fmt.Errorf("do nothing because testEnv is nil")
|
||||||
@@ -279,6 +325,12 @@ type cmdTestCase struct {
|
|||||||
|
|
||||||
func (cmd *cmdTestCase) runTestCmd(t *testing.T) {
|
func (cmd *cmdTestCase) runTestCmd(t *testing.T) {
|
||||||
actual, testErr := executeCommand(cmd.args)
|
actual, testErr := executeCommand(cmd.args)
|
||||||
|
|
||||||
|
// If the cmd error is a change, discard it
|
||||||
|
if isChangeError(testErr) {
|
||||||
|
testErr = nil
|
||||||
|
}
|
||||||
|
|
||||||
if assertErr := cmd.assert(actual, testErr); assertErr != nil {
|
if assertErr := cmd.assert(actual, testErr); assertErr != nil {
|
||||||
t.Error(assertErr)
|
t.Error(assertErr)
|
||||||
}
|
}
|
||||||
@@ -295,6 +347,7 @@ func executeTemplate(content string, templateValues map[string]string) (string,
|
|||||||
|
|
||||||
// Run the command and return the captured output.
|
// Run the command and return the captured output.
|
||||||
func executeCommand(cmd string) (string, error) {
|
func executeCommand(cmd string) (string, error) {
|
||||||
|
defer resetCmdArgs()
|
||||||
args, err := shellwords.Parse(cmd)
|
args, err := shellwords.Parse(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -313,3 +366,18 @@ func executeCommand(cmd string) (string, error) {
|
|||||||
|
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resetCmdArgs() {
|
||||||
|
createArgs = createFlags{}
|
||||||
|
getArgs = GetFlags{}
|
||||||
|
secretGitArgs = NewSecretGitFlags()
|
||||||
|
}
|
||||||
|
|
||||||
|
func isChangeError(err error) bool {
|
||||||
|
if reqErr, ok := err.(*RequestError); ok {
|
||||||
|
if strings.Contains(err.Error(), "identified at least one change, exiting with non-zero exit code") && reqErr.StatusCode == 1 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,22 @@
|
|||||||
|
//go:build unit
|
||||||
// +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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -26,7 +43,8 @@ func TestMain(m *testing.M) {
|
|||||||
panic(fmt.Errorf("error creating kube manager: '%w'", err))
|
panic(fmt.Errorf("error creating kube manager: '%w'", err))
|
||||||
}
|
}
|
||||||
testEnv = km
|
testEnv = km
|
||||||
rootArgs.kubeconfig = testEnv.kubeConfigPath
|
// rootArgs.kubeconfig = testEnv.kubeConfigPath
|
||||||
|
kubeconfigArgs.KubeConfig = &testEnv.kubeConfigPath
|
||||||
|
|
||||||
// Run tests
|
// Run tests
|
||||||
code := m.Run()
|
code := m.Run()
|
||||||
|
|||||||
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import (
|
|||||||
// implementation can pick whichever it wants to use.
|
// implementation can pick whichever it wants to use.
|
||||||
type apiType struct {
|
type apiType struct {
|
||||||
kind, humanKind string
|
kind, humanKind string
|
||||||
|
groupVersion schema.GroupVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
// adapter is an interface for a wrapper or alias from which we can
|
// adapter is an interface for a wrapper or alias from which we can
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ import (
|
|||||||
// notificationv1.Receiver
|
// notificationv1.Receiver
|
||||||
|
|
||||||
var receiverType = apiType{
|
var receiverType = apiType{
|
||||||
kind: notificationv1.ReceiverKind,
|
kind: notificationv1.ReceiverKind,
|
||||||
humanKind: "receiver",
|
humanKind: "receiver",
|
||||||
|
groupVersion: notificationv1.GroupVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
type receiverAdapter struct {
|
type receiverAdapter struct {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/client-go/util/retry"
|
"k8s.io/client-go/util/retry"
|
||||||
@@ -75,13 +76,13 @@ func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
namespacedName := types.NamespacedName{
|
namespacedName := types.NamespacedName{
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,8 +95,9 @@ func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
return fmt.Errorf("resource is suspended")
|
return fmt.Errorf("resource is suspended")
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Actionf("annotating %s %s in %s namespace", reconcile.kind, name, rootArgs.namespace)
|
logger.Actionf("annotating %s %s in %s namespace", reconcile.kind, name, *kubeconfigArgs.Namespace)
|
||||||
if err := requestReconciliation(ctx, kubeClient, namespacedName, reconcile.object); err != nil {
|
if err := requestReconciliation(ctx, kubeClient, namespacedName,
|
||||||
|
reconcile.groupVersion.WithKind(reconcile.kind)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logger.Successf("%s annotated", reconcile.kind)
|
logger.Successf("%s annotated", reconcile.kind)
|
||||||
@@ -122,7 +124,7 @@ func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if readyCond.Status != metav1.ConditionTrue {
|
if readyCond.Status != metav1.ConditionTrue {
|
||||||
return fmt.Errorf("%s reconciliation failed: ''%s", reconcile.kind, readyCond.Message)
|
return fmt.Errorf("%s reconciliation failed: '%s'", reconcile.kind, readyCond.Message)
|
||||||
}
|
}
|
||||||
logger.Successf(reconcile.object.successMessage())
|
logger.Successf(reconcile.object.successMessage())
|
||||||
return nil
|
return nil
|
||||||
@@ -142,21 +144,25 @@ func reconciliationHandled(ctx context.Context, kubeClient client.Client,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func requestReconciliation(ctx context.Context, kubeClient client.Client,
|
func requestReconciliation(ctx context.Context, kubeClient client.Client,
|
||||||
namespacedName types.NamespacedName, obj reconcilable) error {
|
namespacedName types.NamespacedName, gvk schema.GroupVersionKind) error {
|
||||||
return retry.RetryOnConflict(retry.DefaultBackoff, func() (err error) {
|
return retry.RetryOnConflict(retry.DefaultBackoff, func() (err error) {
|
||||||
if err := kubeClient.Get(ctx, namespacedName, obj.asClientObject()); err != nil {
|
object := &metav1.PartialObjectMetadata{}
|
||||||
|
object.SetGroupVersionKind(gvk)
|
||||||
|
object.SetName(namespacedName.Name)
|
||||||
|
object.SetNamespace(namespacedName.Namespace)
|
||||||
|
if err := kubeClient.Get(ctx, namespacedName, object); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
patch := client.MergeFrom(obj.deepCopyClientObject())
|
patch := client.MergeFrom(object.DeepCopy())
|
||||||
if ann := obj.GetAnnotations(); ann == nil {
|
if ann := object.GetAnnotations(); ann == nil {
|
||||||
obj.SetAnnotations(map[string]string{
|
object.SetAnnotations(map[string]string{
|
||||||
meta.ReconcileRequestAnnotation: time.Now().Format(time.RFC3339Nano),
|
meta.ReconcileRequestAnnotation: time.Now().Format(time.RFC3339Nano),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
ann[meta.ReconcileRequestAnnotation] = time.Now().Format(time.RFC3339Nano)
|
ann[meta.ReconcileRequestAnnotation] = time.Now().Format(time.RFC3339Nano)
|
||||||
obj.SetAnnotations(ann)
|
object.SetAnnotations(ann)
|
||||||
}
|
}
|
||||||
return kubeClient.Patch(ctx, obj.asClientObject(), patch)
|
return kubeClient.Patch(ctx, object, patch)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,17 +54,17 @@ func reconcileAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
namespacedName := types.NamespacedName{
|
namespacedName := types.NamespacedName{
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Actionf("annotating Provider %s in %s namespace", name, rootArgs.namespace)
|
logger.Actionf("annotating Provider %s in %s namespace", name, *kubeconfigArgs.Namespace)
|
||||||
var alertProvider notificationv1.Provider
|
var alertProvider notificationv1.Provider
|
||||||
err = kubeClient.Get(ctx, namespacedName, &alertProvider)
|
err = kubeClient.Get(ctx, namespacedName, &alertProvider)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -54,13 +54,13 @@ func reconcileReceiverCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
namespacedName := types.NamespacedName{
|
namespacedName := types.NamespacedName{
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ func reconcileReceiverCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return fmt.Errorf("resource is suspended")
|
return fmt.Errorf("resource is suspended")
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Actionf("annotating Receiver %s in %s namespace", name, rootArgs.namespace)
|
logger.Actionf("annotating Receiver %s in %s namespace", name, *kubeconfigArgs.Namespace)
|
||||||
if receiver.Annotations == nil {
|
if receiver.Annotations == nil {
|
||||||
receiver.Annotations = map[string]string{
|
receiver.Annotations = map[string]string{
|
||||||
meta.ReconcileRequestAnnotation: time.Now().Format(time.RFC3339Nano),
|
meta.ReconcileRequestAnnotation: time.Now().Format(time.RFC3339Nano),
|
||||||
|
|||||||
@@ -36,13 +36,13 @@ func (reconcile reconcileWithSourceCommand) run(cmd *cobra.Command, args []strin
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
namespacedName := types.NamespacedName{
|
namespacedName := types.NamespacedName{
|
||||||
Namespace: rootArgs.namespace,
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,21 +57,22 @@ func (reconcile reconcileWithSourceCommand) run(cmd *cobra.Command, args []strin
|
|||||||
|
|
||||||
if reconcile.object.reconcileSource() {
|
if reconcile.object.reconcileSource() {
|
||||||
reconcileCmd, nsName := reconcile.object.getSource()
|
reconcileCmd, nsName := reconcile.object.getSource()
|
||||||
nsCopy := rootArgs.namespace
|
nsCopy := *kubeconfigArgs.Namespace
|
||||||
if nsName.Namespace != "" {
|
if nsName.Namespace != "" {
|
||||||
rootArgs.namespace = nsName.Namespace
|
*kubeconfigArgs.Namespace = nsName.Namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
err := reconcileCmd.run(nil, []string{nsName.Name})
|
err := reconcileCmd.run(nil, []string{nsName.Name})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
rootArgs.namespace = nsCopy
|
*kubeconfigArgs.Namespace = nsCopy
|
||||||
}
|
}
|
||||||
|
|
||||||
lastHandledReconcileAt := reconcile.object.lastHandledReconcileRequest()
|
lastHandledReconcileAt := reconcile.object.lastHandledReconcileRequest()
|
||||||
logger.Actionf("annotating %s %s in %s namespace", reconcile.kind, name, rootArgs.namespace)
|
logger.Actionf("annotating %s %s in %s namespace", reconcile.kind, name, *kubeconfigArgs.Namespace)
|
||||||
if err := requestReconciliation(ctx, kubeClient, namespacedName, reconcile.object); err != nil {
|
if err := requestReconciliation(ctx, kubeClient, namespacedName,
|
||||||
|
reconcile.groupVersion.WithKind(reconcile.kind)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logger.Successf("%s annotated", reconcile.kind)
|
logger.Successf("%s annotated", reconcile.kind)
|
||||||
|
|||||||
@@ -35,19 +35,23 @@ var resumeCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ResumeFlags struct {
|
type ResumeFlags struct {
|
||||||
all bool
|
all bool
|
||||||
|
wait bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var resumeArgs ResumeFlags
|
var resumeArgs ResumeFlags
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
resumeCmd.PersistentFlags().BoolVarP(&resumeArgs.all, "all", "", false,
|
resumeCmd.PersistentFlags().BoolVarP(&resumeArgs.all, "all", "", false,
|
||||||
"suspend all resources in that namespace")
|
"resume all resources in that namespace")
|
||||||
|
resumeCmd.PersistentFlags().BoolVarP(&resumeArgs.wait, "wait", "", false,
|
||||||
|
"waits for one resource to reconcile before moving to the next one")
|
||||||
rootCmd.AddCommand(resumeCmd)
|
rootCmd.AddCommand(resumeCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
type resumable interface {
|
type resumable interface {
|
||||||
adapter
|
adapter
|
||||||
|
copyable
|
||||||
statusable
|
statusable
|
||||||
setUnsuspended()
|
setUnsuspended()
|
||||||
successMessage() string
|
successMessage() string
|
||||||
@@ -72,13 +76,13 @@ func (resume resumeCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var listOpts []client.ListOption
|
var listOpts []client.ListOption
|
||||||
listOpts = append(listOpts, client.InNamespace(rootArgs.namespace))
|
listOpts = append(listOpts, client.InNamespace(*kubeconfigArgs.Namespace))
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
listOpts = append(listOpts, client.MatchingFields{
|
listOpts = append(listOpts, client.MatchingFields{
|
||||||
"metadata.name": args[0],
|
"metadata.name": args[0],
|
||||||
@@ -91,31 +95,36 @@ func (resume resumeCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resume.list.len() == 0 {
|
if resume.list.len() == 0 {
|
||||||
logger.Failuref("no %s objects found in %s namespace", resume.kind, rootArgs.namespace)
|
logger.Failuref("no %s objects found in %s namespace", resume.kind, *kubeconfigArgs.Namespace)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < resume.list.len(); i++ {
|
for i := 0; i < resume.list.len(); i++ {
|
||||||
logger.Actionf("resuming %s %s in %s namespace", resume.humanKind, resume.list.resumeItem(i).asClientObject().GetName(), rootArgs.namespace)
|
logger.Actionf("resuming %s %s in %s namespace", resume.humanKind, resume.list.resumeItem(i).asClientObject().GetName(), *kubeconfigArgs.Namespace)
|
||||||
resume.list.resumeItem(i).setUnsuspended()
|
obj := resume.list.resumeItem(i)
|
||||||
if err := kubeClient.Update(ctx, resume.list.resumeItem(i).asClientObject()); err != nil {
|
patch := client.MergeFrom(obj.deepCopyClientObject())
|
||||||
|
obj.setUnsuspended()
|
||||||
|
if err := kubeClient.Patch(ctx, obj.asClientObject(), patch); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Successf("%s resumed", resume.humanKind)
|
logger.Successf("%s resumed", resume.humanKind)
|
||||||
|
|
||||||
namespacedName := types.NamespacedName{
|
if resumeArgs.wait || !resumeArgs.all {
|
||||||
Name: resume.list.resumeItem(i).asClientObject().GetName(),
|
namespacedName := types.NamespacedName{
|
||||||
Namespace: rootArgs.namespace,
|
Name: resume.list.resumeItem(i).asClientObject().GetName(),
|
||||||
}
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
|
}
|
||||||
|
|
||||||
logger.Waitingf("waiting for %s reconciliation", resume.kind)
|
logger.Waitingf("waiting for %s reconciliation", resume.kind)
|
||||||
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
|
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
|
||||||
isReady(ctx, kubeClient, namespacedName, resume.list.resumeItem(i))); err != nil {
|
isReady(ctx, kubeClient, namespacedName, resume.list.resumeItem(i))); err != nil {
|
||||||
logger.Failuref(err.Error())
|
logger.Failuref(err.Error())
|
||||||
continue
|
continue
|
||||||
|
}
|
||||||
|
logger.Successf("%s reconciliation completed", resume.kind)
|
||||||
|
logger.Successf(resume.list.resumeItem(i).successMessage())
|
||||||
}
|
}
|
||||||
logger.Successf("%s reconciliation completed", resume.kind)
|
|
||||||
logger.Successf(resume.list.resumeItem(i).successMessage())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -29,8 +29,9 @@ import (
|
|||||||
// sourcev1.Bucket
|
// sourcev1.Bucket
|
||||||
|
|
||||||
var bucketType = apiType{
|
var bucketType = apiType{
|
||||||
kind: sourcev1.BucketKind,
|
kind: sourcev1.BucketKind,
|
||||||
humanKind: "source bucket",
|
humanKind: "source bucket",
|
||||||
|
groupVersion: sourcev1.GroupVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
type bucketAdapter struct {
|
type bucketAdapter struct {
|
||||||
@@ -62,8 +63,9 @@ func (a bucketListAdapter) len() int {
|
|||||||
// sourcev1.HelmChart
|
// sourcev1.HelmChart
|
||||||
|
|
||||||
var helmChartType = apiType{
|
var helmChartType = apiType{
|
||||||
kind: sourcev1.HelmChartKind,
|
kind: sourcev1.HelmChartKind,
|
||||||
humanKind: "source chart",
|
humanKind: "source chart",
|
||||||
|
groupVersion: sourcev1.GroupVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
type helmChartAdapter struct {
|
type helmChartAdapter struct {
|
||||||
@@ -95,8 +97,9 @@ func (a helmChartListAdapter) len() int {
|
|||||||
// sourcev1.GitRepository
|
// sourcev1.GitRepository
|
||||||
|
|
||||||
var gitRepositoryType = apiType{
|
var gitRepositoryType = apiType{
|
||||||
kind: sourcev1.GitRepositoryKind,
|
kind: sourcev1.GitRepositoryKind,
|
||||||
humanKind: "source git",
|
humanKind: "source git",
|
||||||
|
groupVersion: sourcev1.GroupVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
type gitRepositoryAdapter struct {
|
type gitRepositoryAdapter struct {
|
||||||
@@ -128,8 +131,9 @@ func (a gitRepositoryListAdapter) len() int {
|
|||||||
// sourcev1.HelmRepository
|
// sourcev1.HelmRepository
|
||||||
|
|
||||||
var helmRepositoryType = apiType{
|
var helmRepositoryType = apiType{
|
||||||
kind: sourcev1.HelmRepositoryKind,
|
kind: sourcev1.HelmRepositoryKind,
|
||||||
humanKind: "source helm",
|
humanKind: "source helm",
|
||||||
|
groupVersion: sourcev1.GroupVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
type helmRepositoryAdapter struct {
|
type helmRepositoryAdapter struct {
|
||||||
|
|||||||
@@ -69,11 +69,11 @@ func isReady(ctx context.Context, kubeClient client.Client,
|
|||||||
func buildComponentObjectRefs(components ...string) ([]object.ObjMetadata, error) {
|
func buildComponentObjectRefs(components ...string) ([]object.ObjMetadata, error) {
|
||||||
var objRefs []object.ObjMetadata
|
var objRefs []object.ObjMetadata
|
||||||
for _, deployment := range components {
|
for _, deployment := range components {
|
||||||
objMeta, err := object.CreateObjMetadata(rootArgs.namespace, deployment, schema.GroupKind{Group: "apps", Kind: "Deployment"})
|
objRefs = append(objRefs, object.ObjMetadata{
|
||||||
if err != nil {
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
return nil, err
|
Name: deployment,
|
||||||
}
|
GroupKind: schema.GroupKind{Group: "apps", Kind: "Deployment"},
|
||||||
objRefs = append(objRefs, objMeta)
|
})
|
||||||
}
|
}
|
||||||
return objRefs, nil
|
return objRefs, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ func init() {
|
|||||||
|
|
||||||
type suspendable interface {
|
type suspendable interface {
|
||||||
adapter
|
adapter
|
||||||
|
copyable
|
||||||
isSuspended() bool
|
isSuspended() bool
|
||||||
setSuspended()
|
setSuspended()
|
||||||
}
|
}
|
||||||
@@ -69,13 +70,13 @@ func (suspend suspendCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
kubeClient, err := utils.KubeClient(kubeconfigArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var listOpts []client.ListOption
|
var listOpts []client.ListOption
|
||||||
listOpts = append(listOpts, client.InNamespace(rootArgs.namespace))
|
listOpts = append(listOpts, client.InNamespace(*kubeconfigArgs.Namespace))
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
listOpts = append(listOpts, client.MatchingFields{
|
listOpts = append(listOpts, client.MatchingFields{
|
||||||
"metadata.name": args[0],
|
"metadata.name": args[0],
|
||||||
@@ -88,14 +89,17 @@ func (suspend suspendCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if suspend.list.len() == 0 {
|
if suspend.list.len() == 0 {
|
||||||
logger.Failuref("no %s objects found in %s namespace", suspend.kind, rootArgs.namespace)
|
logger.Failuref("no %s objects found in %s namespace", suspend.kind, *kubeconfigArgs.Namespace)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < suspend.list.len(); i++ {
|
for i := 0; i < suspend.list.len(); i++ {
|
||||||
logger.Actionf("suspending %s %s in %s namespace", suspend.humanKind, suspend.list.item(i).asClientObject().GetName(), rootArgs.namespace)
|
logger.Actionf("suspending %s %s in %s namespace", suspend.humanKind, suspend.list.item(i).asClientObject().GetName(), *kubeconfigArgs.Namespace)
|
||||||
suspend.list.item(i).setSuspended()
|
|
||||||
if err := kubeClient.Update(ctx, suspend.list.item(i).asClientObject()); err != nil {
|
obj := suspend.list.item(i)
|
||||||
|
patch := client.MergeFrom(obj.deepCopyClientObject())
|
||||||
|
obj.setSuspended()
|
||||||
|
if err := kubeClient.Patch(ctx, obj.asClientObject(), patch); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logger.Successf("%s suspended", suspend.humanKind)
|
logger.Successf("%s suspended", suspend.humanKind)
|
||||||
|
|||||||
74
cmd/flux/testdata/build-kustomization/delete-service/deployment.yaml
vendored
Normal file
74
cmd/flux/testdata/build-kustomization/delete-service/deployment.yaml
vendored
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
spec:
|
||||||
|
minReadySeconds: 3
|
||||||
|
revisionHistoryLimit: 5
|
||||||
|
progressDeadlineSeconds: 60
|
||||||
|
strategy:
|
||||||
|
rollingUpdate:
|
||||||
|
maxUnavailable: 0
|
||||||
|
type: RollingUpdate
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: podinfo
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
prometheus.io/scrape: "true"
|
||||||
|
prometheus.io/port: "9797"
|
||||||
|
labels:
|
||||||
|
app: podinfo
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: podinfod
|
||||||
|
image: ghcr.io/stefanprodan/podinfo:6.0.3
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
containerPort: 9898
|
||||||
|
protocol: TCP
|
||||||
|
- name: http-metrics
|
||||||
|
containerPort: 9797
|
||||||
|
protocol: TCP
|
||||||
|
- name: grpc
|
||||||
|
containerPort: 9999
|
||||||
|
protocol: TCP
|
||||||
|
command:
|
||||||
|
- ./podinfo
|
||||||
|
- --port=9898
|
||||||
|
- --port-metrics=9797
|
||||||
|
- --grpc-port=9999
|
||||||
|
- --grpc-service-name=podinfo
|
||||||
|
- --level=info
|
||||||
|
- --random-delay=false
|
||||||
|
- --random-error=false
|
||||||
|
env:
|
||||||
|
- name: PODINFO_UI_COLOR
|
||||||
|
value: "#34577c"
|
||||||
|
livenessProbe:
|
||||||
|
exec:
|
||||||
|
command:
|
||||||
|
- podcli
|
||||||
|
- check
|
||||||
|
- http
|
||||||
|
- localhost:9898/healthz
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
timeoutSeconds: 5
|
||||||
|
readinessProbe:
|
||||||
|
exec:
|
||||||
|
command:
|
||||||
|
- podcli
|
||||||
|
- check
|
||||||
|
- http
|
||||||
|
- localhost:9898/readyz
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
timeoutSeconds: 5
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpu: 2000m
|
||||||
|
memory: 512Mi
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 64Mi
|
||||||
20
cmd/flux/testdata/build-kustomization/delete-service/hpa.yaml
vendored
Normal file
20
cmd/flux/testdata/build-kustomization/delete-service/hpa.yaml
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
apiVersion: autoscaling/v2beta2
|
||||||
|
kind: HorizontalPodAutoscaler
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
spec:
|
||||||
|
scaleTargetRef:
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
name: podinfo
|
||||||
|
minReplicas: 2
|
||||||
|
maxReplicas: 4
|
||||||
|
metrics:
|
||||||
|
- type: Resource
|
||||||
|
resource:
|
||||||
|
name: cpu
|
||||||
|
target:
|
||||||
|
type: Utilization
|
||||||
|
# scale up if usage is above
|
||||||
|
# 99% of the requested CPU (100m)
|
||||||
|
averageUtilization: 99
|
||||||
5
cmd/flux/testdata/build-kustomization/delete-service/kustomization.yaml
vendored
Normal file
5
cmd/flux/testdata/build-kustomization/delete-service/kustomization.yaml
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
resources:
|
||||||
|
- ./deployment.yaml
|
||||||
|
- ./hpa.yaml
|
||||||
15
cmd/flux/testdata/build-kustomization/podinfo-kustomization.yaml
vendored
Normal file
15
cmd/flux/testdata/build-kustomization/podinfo-kustomization.yaml
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: Kustomization
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: {{ .fluxns }}
|
||||||
|
spec:
|
||||||
|
interval: 5m0s
|
||||||
|
path: ./kustomize
|
||||||
|
force: true
|
||||||
|
prune: true
|
||||||
|
sourceRef:
|
||||||
|
kind: GitRepository
|
||||||
|
name: podinfo
|
||||||
|
targetNamespace: default
|
||||||
173
cmd/flux/testdata/build-kustomization/podinfo-result.yaml
vendored
Normal file
173
cmd/flux/testdata/build-kustomization/podinfo-result.yaml
vendored
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
kustomize.toolkit.fluxcd.io/name: podinfo
|
||||||
|
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||||
|
name: podinfo
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
minReadySeconds: 3
|
||||||
|
progressDeadlineSeconds: 60
|
||||||
|
revisionHistoryLimit: 5
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: podinfo
|
||||||
|
strategy:
|
||||||
|
rollingUpdate:
|
||||||
|
maxUnavailable: 0
|
||||||
|
type: RollingUpdate
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
prometheus.io/port: "9797"
|
||||||
|
prometheus.io/scrape: "true"
|
||||||
|
labels:
|
||||||
|
app: podinfo
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- command:
|
||||||
|
- ./podinfo
|
||||||
|
- --port=9898
|
||||||
|
- --port-metrics=9797
|
||||||
|
- --grpc-port=9999
|
||||||
|
- --grpc-service-name=podinfo
|
||||||
|
- --level=info
|
||||||
|
- --random-delay=false
|
||||||
|
- --random-error=false
|
||||||
|
env:
|
||||||
|
- name: PODINFO_UI_COLOR
|
||||||
|
value: '#34577c'
|
||||||
|
image: ghcr.io/stefanprodan/podinfo:6.0.10
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
livenessProbe:
|
||||||
|
exec:
|
||||||
|
command:
|
||||||
|
- podcli
|
||||||
|
- check
|
||||||
|
- http
|
||||||
|
- localhost:9898/healthz
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
timeoutSeconds: 5
|
||||||
|
name: podinfod
|
||||||
|
ports:
|
||||||
|
- containerPort: 9898
|
||||||
|
name: http
|
||||||
|
protocol: TCP
|
||||||
|
- containerPort: 9797
|
||||||
|
name: http-metrics
|
||||||
|
protocol: TCP
|
||||||
|
- containerPort: 9999
|
||||||
|
name: grpc
|
||||||
|
protocol: TCP
|
||||||
|
readinessProbe:
|
||||||
|
exec:
|
||||||
|
command:
|
||||||
|
- podcli
|
||||||
|
- check
|
||||||
|
- http
|
||||||
|
- localhost:9898/readyz
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
timeoutSeconds: 5
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpu: 2000m
|
||||||
|
memory: 512Mi
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 64Mi
|
||||||
|
---
|
||||||
|
apiVersion: autoscaling/v2beta2
|
||||||
|
kind: HorizontalPodAutoscaler
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
kustomize.toolkit.fluxcd.io/name: podinfo
|
||||||
|
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||||
|
name: podinfo
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
maxReplicas: 4
|
||||||
|
metrics:
|
||||||
|
- resource:
|
||||||
|
name: cpu
|
||||||
|
target:
|
||||||
|
averageUtilization: 99
|
||||||
|
type: Utilization
|
||||||
|
type: Resource
|
||||||
|
minReplicas: 2
|
||||||
|
scaleTargetRef:
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
name: podinfo
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
kustomize.toolkit.fluxcd.io/name: podinfo
|
||||||
|
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||||
|
name: podinfo
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
port: 9898
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: http
|
||||||
|
- name: grpc
|
||||||
|
port: 9999
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: grpc
|
||||||
|
selector:
|
||||||
|
app: podinfo
|
||||||
|
type: ClusterIP
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
.dockerconfigjson: eyJtYXNrIjoiKipTT1BTKioifQ==
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
kustomize.toolkit.fluxcd.io/name: podinfo
|
||||||
|
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||||
|
name: docker-secret
|
||||||
|
namespace: default
|
||||||
|
type: kubernetes.io/dockerconfigjson
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
kustomize.toolkit.fluxcd.io/name: podinfo
|
||||||
|
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||||
|
name: secret-basic-auth-stringdata
|
||||||
|
namespace: default
|
||||||
|
stringData:
|
||||||
|
password: '**SOPS**'
|
||||||
|
username: '**SOPS**'
|
||||||
|
type: kubernetes.io/basic-auth
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
token: KipTT1BTKio=
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
kustomize.toolkit.fluxcd.io/name: podinfo
|
||||||
|
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||||
|
name: podinfo-token-77t89m9b67
|
||||||
|
namespace: default
|
||||||
|
type: Opaque
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
password: MWYyZDFlMmU2N2Rm
|
||||||
|
username: YWRtaW4=
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
kustomize.toolkit.fluxcd.io/name: podinfo
|
||||||
|
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||||
|
name: db-user-pass-bkbd782d2c
|
||||||
|
namespace: default
|
||||||
|
type: Opaque
|
||||||
16
cmd/flux/testdata/build-kustomization/podinfo-source.yaml
vendored
Normal file
16
cmd/flux/testdata/build-kustomization/podinfo-source.yaml
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: {{ .fluxns }}
|
||||||
|
---
|
||||||
|
apiVersion: source.toolkit.fluxcd.io/v1beta1
|
||||||
|
kind: GitRepository
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: {{ .fluxns }}
|
||||||
|
spec:
|
||||||
|
interval: 30s
|
||||||
|
ref:
|
||||||
|
branch: master
|
||||||
|
url: https://github.com/stefanprodan/podinfo
|
||||||
101
cmd/flux/testdata/build-kustomization/podinfo-without-service-result.yaml
vendored
Normal file
101
cmd/flux/testdata/build-kustomization/podinfo-without-service-result.yaml
vendored
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
kustomize.toolkit.fluxcd.io/name: podinfo
|
||||||
|
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||||
|
name: podinfo
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
minReadySeconds: 3
|
||||||
|
progressDeadlineSeconds: 60
|
||||||
|
revisionHistoryLimit: 5
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: podinfo
|
||||||
|
strategy:
|
||||||
|
rollingUpdate:
|
||||||
|
maxUnavailable: 0
|
||||||
|
type: RollingUpdate
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
prometheus.io/port: "9797"
|
||||||
|
prometheus.io/scrape: "true"
|
||||||
|
labels:
|
||||||
|
app: podinfo
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- command:
|
||||||
|
- ./podinfo
|
||||||
|
- --port=9898
|
||||||
|
- --port-metrics=9797
|
||||||
|
- --grpc-port=9999
|
||||||
|
- --grpc-service-name=podinfo
|
||||||
|
- --level=info
|
||||||
|
- --random-delay=false
|
||||||
|
- --random-error=false
|
||||||
|
env:
|
||||||
|
- name: PODINFO_UI_COLOR
|
||||||
|
value: '#34577c'
|
||||||
|
image: ghcr.io/stefanprodan/podinfo:6.0.3
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
livenessProbe:
|
||||||
|
exec:
|
||||||
|
command:
|
||||||
|
- podcli
|
||||||
|
- check
|
||||||
|
- http
|
||||||
|
- localhost:9898/healthz
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
timeoutSeconds: 5
|
||||||
|
name: podinfod
|
||||||
|
ports:
|
||||||
|
- containerPort: 9898
|
||||||
|
name: http
|
||||||
|
protocol: TCP
|
||||||
|
- containerPort: 9797
|
||||||
|
name: http-metrics
|
||||||
|
protocol: TCP
|
||||||
|
- containerPort: 9999
|
||||||
|
name: grpc
|
||||||
|
protocol: TCP
|
||||||
|
readinessProbe:
|
||||||
|
exec:
|
||||||
|
command:
|
||||||
|
- podcli
|
||||||
|
- check
|
||||||
|
- http
|
||||||
|
- localhost:9898/readyz
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
timeoutSeconds: 5
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpu: 2000m
|
||||||
|
memory: 512Mi
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 64Mi
|
||||||
|
---
|
||||||
|
apiVersion: autoscaling/v2beta2
|
||||||
|
kind: HorizontalPodAutoscaler
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
kustomize.toolkit.fluxcd.io/name: podinfo
|
||||||
|
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||||
|
name: podinfo
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
maxReplicas: 4
|
||||||
|
metrics:
|
||||||
|
- resource:
|
||||||
|
name: cpu
|
||||||
|
target:
|
||||||
|
averageUtilization: 99
|
||||||
|
type: Utilization
|
||||||
|
type: Resource
|
||||||
|
minReplicas: 2
|
||||||
|
scaleTargetRef:
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
name: podinfo
|
||||||
74
cmd/flux/testdata/build-kustomization/podinfo/deployment.yaml
vendored
Normal file
74
cmd/flux/testdata/build-kustomization/podinfo/deployment.yaml
vendored
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
spec:
|
||||||
|
minReadySeconds: 3
|
||||||
|
revisionHistoryLimit: 5
|
||||||
|
progressDeadlineSeconds: 60
|
||||||
|
strategy:
|
||||||
|
rollingUpdate:
|
||||||
|
maxUnavailable: 0
|
||||||
|
type: RollingUpdate
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: podinfo
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
prometheus.io/scrape: "true"
|
||||||
|
prometheus.io/port: "9797"
|
||||||
|
labels:
|
||||||
|
app: podinfo
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: podinfod
|
||||||
|
image: ghcr.io/stefanprodan/podinfo:6.0.10
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
containerPort: 9898
|
||||||
|
protocol: TCP
|
||||||
|
- name: http-metrics
|
||||||
|
containerPort: 9797
|
||||||
|
protocol: TCP
|
||||||
|
- name: grpc
|
||||||
|
containerPort: 9999
|
||||||
|
protocol: TCP
|
||||||
|
command:
|
||||||
|
- ./podinfo
|
||||||
|
- --port=9898
|
||||||
|
- --port-metrics=9797
|
||||||
|
- --grpc-port=9999
|
||||||
|
- --grpc-service-name=podinfo
|
||||||
|
- --level=info
|
||||||
|
- --random-delay=false
|
||||||
|
- --random-error=false
|
||||||
|
env:
|
||||||
|
- name: PODINFO_UI_COLOR
|
||||||
|
value: "#34577c"
|
||||||
|
livenessProbe:
|
||||||
|
exec:
|
||||||
|
command:
|
||||||
|
- podcli
|
||||||
|
- check
|
||||||
|
- http
|
||||||
|
- localhost:9898/healthz
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
timeoutSeconds: 5
|
||||||
|
readinessProbe:
|
||||||
|
exec:
|
||||||
|
command:
|
||||||
|
- podcli
|
||||||
|
- check
|
||||||
|
- http
|
||||||
|
- localhost:9898/readyz
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
timeoutSeconds: 5
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpu: 2000m
|
||||||
|
memory: 512Mi
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 64Mi
|
||||||
27
cmd/flux/testdata/build-kustomization/podinfo/dockerconfigjson-sops-secret.yaml
vendored
Normal file
27
cmd/flux/testdata/build-kustomization/podinfo/dockerconfigjson-sops-secret.yaml
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
.dockerconfigjson: ENC[AES256_GCM,data:KHCFH3hNnc+PMfWLFEPjebf3W4z4WXbGFAANRZyZC+07z7wlrTALJM6rn8YslW4tMAWCoAYxblC5WRCszTy0h9rw0U/RGOv5H0qCgnNg/FILFUqhwo9pNfrUH+MEP4M9qxxbLKZwObpHUE7DUsKx1JYAxsI=,iv:q48lqUbUQD+0cbYcjNMZMJLRdGHi78ZmDhNAT2th9tg=,tag:QRI2SZZXQrAcdql3R5AH2g==,type:str]
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: docker-secret
|
||||||
|
type: kubernetes.io/dockerconfigjson
|
||||||
|
sops:
|
||||||
|
kms: []
|
||||||
|
gcp_kms: []
|
||||||
|
azure_kv: []
|
||||||
|
hc_vault: []
|
||||||
|
age:
|
||||||
|
- recipient: age10la2ge0wtvx3qr7datqf7rs4yngxszdal927fs9rukamr8u2pshsvtz7ce
|
||||||
|
enc: |
|
||||||
|
-----BEGIN AGE ENCRYPTED FILE-----
|
||||||
|
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSA3eU1CTEJhVXZ4eEVYYkVV
|
||||||
|
OU90TEcrR2pYckttN0pBanJoSUZWSW1RQXlRCkUydFJ3V1NZUTBuVFF0aC9GUEcw
|
||||||
|
bUdhNjJWTkoyL1FUVi9Dc1dxUDBkM0UKLS0tIE1sQXkwcWdGaEFuY0RHQTVXM0J6
|
||||||
|
dWpJcThEbW15V3dXYXpPZklBdW1Hd1kKoIAdmGNPrEctV8h1w8KuvQ5S+BGmgqN9
|
||||||
|
MgpNmUhJjWhgcQpb5BRYpQesBOgU5TBGK7j58A6DMDKlSiYZsdQchQ==
|
||||||
|
-----END AGE ENCRYPTED FILE-----
|
||||||
|
lastmodified: "2022-02-03T16:03:17Z"
|
||||||
|
mac: ENC[AES256_GCM,data:AHdYSawajwgAFwlmDN1IPNmT9vWaYKzyVIra2d6sPcjTbZ8/p+VRSRpVm4XZFFsaNnW5AUJaouwXnKYDTmJDXKlr/rQcu9kXqsssQgdzcXaA6l5uJlgsnml8ba7J3OK+iEKMax23mwQEx2EUskCd9ENOwFDkunP02sxqDNOz20k=,iv:8F5OamHt3fAVorf6p+SoIrWoqkcATSGWVoM0EK87S4M=,tag:E1mxXnc7wWkEX5BxhpLtng==,type:str]
|
||||||
|
pgp: []
|
||||||
|
encrypted_regex: ^(data|stringData)$
|
||||||
|
version: 3.7.1
|
||||||
20
cmd/flux/testdata/build-kustomization/podinfo/hpa.yaml
vendored
Normal file
20
cmd/flux/testdata/build-kustomization/podinfo/hpa.yaml
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
apiVersion: autoscaling/v2beta2
|
||||||
|
kind: HorizontalPodAutoscaler
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
spec:
|
||||||
|
scaleTargetRef:
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
name: podinfo
|
||||||
|
minReplicas: 2
|
||||||
|
maxReplicas: 4
|
||||||
|
metrics:
|
||||||
|
- type: Resource
|
||||||
|
resource:
|
||||||
|
name: cpu
|
||||||
|
target:
|
||||||
|
type: Utilization
|
||||||
|
# scale up if usage is above
|
||||||
|
# 99% of the requested CPU (100m)
|
||||||
|
averageUtilization: 99
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user