Compare commits
129 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3dfd0bc2e1 | ||
|
|
10ff99542f | ||
|
|
2449030ab8 | ||
|
|
3e85901f40 | ||
|
|
73b1576f81 | ||
|
|
cdb5b7c9a2 | ||
|
|
d9331b0c91 | ||
|
|
b6a8163dd9 | ||
|
|
185252ba48 | ||
|
|
043d37921b | ||
|
|
02fb8d9958 | ||
|
|
cfa6c0a178 | ||
|
|
e8b52bf2fc | ||
|
|
85fbb780bf | ||
|
|
bd9f9bf518 | ||
|
|
077860fff1 | ||
|
|
d29a4ee4d2 | ||
|
|
6d2e34e9b2 | ||
|
|
0b6969537b | ||
|
|
dc6b0d0f0d | ||
|
|
b4dbb178fe | ||
|
|
4cf5290989 | ||
|
|
6ffd2222c2 | ||
|
|
e7725911a7 | ||
|
|
0c1664cd01 | ||
|
|
0239307d8e | ||
|
|
9f10b6be1b | ||
|
|
01f613b39e | ||
|
|
b775d11a70 | ||
|
|
022576697f | ||
|
|
065d0b2c06 | ||
|
|
ed4718205a | ||
|
|
a29d0c536d | ||
|
|
eaeb8ca5c1 | ||
|
|
2092c14aca | ||
|
|
69f38b8c77 | ||
|
|
d2cdd02a57 | ||
|
|
095c8323a1 | ||
|
|
accb4c915e | ||
|
|
242809f61d | ||
|
|
c4907cf6c6 | ||
|
|
a4b9191fa3 | ||
|
|
5fd3d0bd41 | ||
|
|
ba6da23323 | ||
|
|
0328bb14ce | ||
|
|
2b7a0f3fd4 | ||
|
|
527886bea0 | ||
|
|
98078a0c65 | ||
|
|
ca660b7ba5 | ||
|
|
ed93e93b81 | ||
|
|
80419f00db | ||
|
|
01946facb3 | ||
|
|
08c1bd7653 | ||
|
|
ebf9188c6a | ||
|
|
382c6d5885 | ||
|
|
384c60a988 | ||
|
|
0078147587 | ||
|
|
d79bedf2bc | ||
|
|
14b31b321c | ||
|
|
309b9b52f8 | ||
|
|
5d063e7390 | ||
|
|
e7ba9b5624 | ||
|
|
81f6fa598f | ||
|
|
d9eabcdbf7 | ||
|
|
bb3562427b | ||
|
|
8a5bba80bf | ||
|
|
ff2833c4d1 | ||
|
|
45ba845f23 | ||
|
|
771a14fcf6 | ||
|
|
c8ff861d00 | ||
|
|
0f05ce3605 | ||
|
|
38a3f3ba11 | ||
|
|
659a19cd80 | ||
|
|
baaa466c0f | ||
|
|
168c65bb6e | ||
|
|
6003d11156 | ||
|
|
1f16b6d639 | ||
|
|
54bb4b2efd | ||
|
|
f54770c21a | ||
|
|
1244a62deb | ||
|
|
2fe55bcdde | ||
|
|
9943690855 | ||
|
|
89c46a6379 | ||
|
|
a0d4530cc0 | ||
|
|
6db84269af | ||
|
|
2cd3c32ca7 | ||
|
|
9740fecc35 | ||
|
|
433492791b | ||
|
|
7d3c63ad74 | ||
|
|
a6538b117e | ||
|
|
d54e7559a5 | ||
|
|
bb9eca7232 | ||
|
|
b5027d8f3f | ||
|
|
00a134e23f | ||
|
|
aab3452773 | ||
|
|
5903dfc627 | ||
|
|
a5272b2b39 | ||
|
|
771fc20bb2 | ||
|
|
b5f48bee78 | ||
|
|
ff78af5808 | ||
|
|
7eab649abc | ||
|
|
1b5db157b1 | ||
|
|
0fa9aebf7a | ||
|
|
9fb9965ffe | ||
|
|
02c9f29499 | ||
|
|
c6243ad002 | ||
|
|
f4650c7a84 | ||
|
|
6df691598e | ||
|
|
26964b7f88 | ||
|
|
71712ae1c3 | ||
|
|
0b6c979e47 | ||
|
|
cc2cbc2519 | ||
|
|
8043ae961a | ||
|
|
b1d1d30cdb | ||
|
|
28d606cb0e | ||
|
|
e9c5b6e917 | ||
|
|
68f96235fc | ||
|
|
12f22ddeba | ||
|
|
9db5c644a6 | ||
|
|
ef6a1fb09b | ||
|
|
99002f92f4 | ||
|
|
298d6a1a15 | ||
|
|
5a21f50230 | ||
|
|
5263dabd22 | ||
|
|
9b649f6c72 | ||
|
|
b903cd5b68 | ||
|
|
890b5c5202 | ||
|
|
a14e88d04d | ||
|
|
58e09b4c68 |
19
.github/aur/flux-bin/PKGBUILD.template
vendored
19
.github/aur/flux-bin/PKGBUILD.template
vendored
@@ -8,18 +8,20 @@ pkgdesc="Open and extensible continuous delivery solution for Kubernetes"
|
||||
url="https://fluxcd.io/"
|
||||
arch=("x86_64" "armv6h" "armv7h" "aarch64")
|
||||
license=("APACHE")
|
||||
optdepends=("kubectl")
|
||||
optdepends=('kubectl: for apply actions on the Kubernetes cluster',
|
||||
'bash-completion: auto-completion for flux in Bash',
|
||||
'zsh-completions: auto-completion for flux in ZSH')
|
||||
source_x86_64=(
|
||||
"$pkgname-$pkgver.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${pkgver}/flux_${pkgver}_linux_amd64.tar.gz"
|
||||
"${pkgname}-${pkgver}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${pkgver}/flux_${pkgver}_linux_amd64.tar.gz"
|
||||
)
|
||||
source_armv6h=(
|
||||
"$pkgname-$pkgver.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${pkgver}/flux_${pkgver}_linux_arm.tar.gz"
|
||||
"${pkgname}-${pkgver}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${pkgver}/flux_${pkgver}_linux_arm.tar.gz"
|
||||
)
|
||||
source_armv7h=(
|
||||
"$pkgname-$pkgver.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${pkgver}/flux_${pkgver}_linux_arm.tar.gz"
|
||||
"${pkgname}-${pkgver}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${pkgver}/flux_${pkgver}_linux_arm.tar.gz"
|
||||
)
|
||||
source_aarch64=(
|
||||
"$pkgname-$pkgver.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${pkgver}/flux_${pkgver}_linux_arm64.tar.gz"
|
||||
"${pkgname}-${pkgver}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${pkgver}/flux_${pkgver}_linux_arm64.tar.gz"
|
||||
)
|
||||
sha256sums_x86_64=(
|
||||
${SHA256SUM_AMD64}
|
||||
@@ -33,7 +35,12 @@ sha256sums_armv7h=(
|
||||
sha256sums_aarch64=(
|
||||
${SHA256SUM_ARM64}
|
||||
)
|
||||
_srcname=flux
|
||||
|
||||
package() {
|
||||
install -Dm755 flux "$pkgdir/usr/bin/flux"
|
||||
install -Dm755 ${_srcname} "${pkgdir}/usr/bin/${_srcname}"
|
||||
|
||||
"${pkgdir}/usr/bin/${_srcname}" completion bash | install -Dm644 /dev/stdin "${pkgdir}/usr/share/bash-completion/completions/${_srcname}"
|
||||
"${pkgdir}/usr/bin/${_srcname}" completion fish | install -Dm644 /dev/stdin "${pkgdir}/usr/share/fish/vendor_completions.d/${_srcname}.fish"
|
||||
"${pkgdir}/usr/bin/${_srcname}" completion zsh | install -Dm644 /dev/stdin "${pkgdir}/usr/share/zsh/site-functions/_${_srcname}"
|
||||
}
|
||||
|
||||
28
.github/aur/flux-go/PKGBUILD.template
vendored
28
.github/aur/flux-go/PKGBUILD.template
vendored
@@ -12,32 +12,40 @@ provides=("flux-bin")
|
||||
conflicts=("flux-bin")
|
||||
replaces=("flux-cli")
|
||||
depends=("glibc")
|
||||
makedepends=("go")
|
||||
optdepends=("kubectl")
|
||||
makedepends=('go>=1.16', 'kustomize>=3.0')
|
||||
optdepends=('kubectl: for apply actions on the Kubernetes cluster',
|
||||
'bash-completion: auto-completion for flux in Bash',
|
||||
'zsh-completions: auto-completion for flux in ZSH')
|
||||
source=(
|
||||
"$pkgname-$pkgver.tar.gz::https://github.com/fluxcd/flux2/archive/v$pkgver.tar.gz"
|
||||
"${pkgname}-${pkgver}.tar.gz::https://github.com/fluxcd/flux2/archive/v${pkgver}.tar.gz"
|
||||
)
|
||||
sha256sums=(
|
||||
${SHA256SUM}
|
||||
)
|
||||
_srcname=flux
|
||||
|
||||
build() {
|
||||
cd "flux2-$pkgver"
|
||||
cd "flux2-${pkgver}"
|
||||
export CGO_LDFLAGS="$LDFLAGS"
|
||||
export CGO_CFLAGS="$CFLAGS"
|
||||
export CGO_CXXFLAGS="$CXXFLAGS"
|
||||
export CGO_CPPFLAGS="$CPPFLAGS"
|
||||
export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw"
|
||||
go build -ldflags "-X main.VERSION=$pkgver" -o flux-bin ./cmd/flux
|
||||
export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
|
||||
./manifests/scripts/bundle.sh "${PWD}/manifests" "${PWD}/cmd/flux/manifests"
|
||||
go build -ldflags "-linkmode=external -X main.VERSION=${pkgver}" -o ${_srcname} ./cmd/flux
|
||||
}
|
||||
|
||||
check() {
|
||||
cd "flux2-$pkgver"
|
||||
cd "flux2-${pkgver}"
|
||||
make test
|
||||
}
|
||||
|
||||
package() {
|
||||
cd "flux2-$pkgver"
|
||||
install -Dm755 flux-bin "$pkgdir/usr/bin/flux"
|
||||
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
|
||||
cd "flux2-${pkgver}"
|
||||
install -Dm755 ${_srcname} "${pkgdir}/usr/bin/${_srcname}"
|
||||
install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
|
||||
|
||||
"${pkgdir}/usr/bin/${_srcname}" completion bash | install -Dm644 /dev/stdin "${pkgdir}/usr/share/bash-completion/completions/${_srcname}"
|
||||
"${pkgdir}/usr/bin/${_srcname}" completion fish | install -Dm644 /dev/stdin "${pkgdir}/usr/share/fish/vendor_completions.d/${_srcname}.fish"
|
||||
"${pkgdir}/usr/bin/${_srcname}" completion zsh | install -Dm644 /dev/stdin "${pkgdir}/usr/share/zsh/site-functions/_${_srcname}"
|
||||
}
|
||||
|
||||
20
.github/aur/flux-scm/PKGBUILD.template
vendored
20
.github/aur/flux-scm/PKGBUILD.template
vendored
@@ -11,12 +11,15 @@ license=("APACHE")
|
||||
provides=("flux-bin")
|
||||
conflicts=("flux-bin")
|
||||
depends=("glibc")
|
||||
makedepends=("go")
|
||||
optdepends=("kubectl")
|
||||
makedepends=('go>=1.16', 'kustomize>=3.0')
|
||||
optdepends=('kubectl: for apply actions on the Kubernetes cluster',
|
||||
'bash-completion: auto-completion for flux in Bash',
|
||||
'zsh-completions: auto-completion for flux in ZSH')
|
||||
source=(
|
||||
"git+https://github.com/fluxcd/flux2.git"
|
||||
)
|
||||
md5sums=('SKIP')
|
||||
_srcname=flux
|
||||
|
||||
pkgver() {
|
||||
cd "flux2"
|
||||
@@ -29,8 +32,9 @@ build() {
|
||||
export CGO_CFLAGS="$CFLAGS"
|
||||
export CGO_CXXFLAGS="$CXXFLAGS"
|
||||
export CGO_CPPFLAGS="$CPPFLAGS"
|
||||
export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw"
|
||||
go build -ldflags "-X main.VERSION=$pkgver" -o flux-bin ./cmd/flux
|
||||
export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
|
||||
make cmd/flux/manifests
|
||||
go build -ldflags "-linkmode=external -X main.VERSION=${pkgver}" -o ${_srcname} ./cmd/flux
|
||||
}
|
||||
|
||||
check() {
|
||||
@@ -40,6 +44,10 @@ check() {
|
||||
|
||||
package() {
|
||||
cd "flux2"
|
||||
install -Dm755 flux-bin "$pkgdir/usr/bin/flux"
|
||||
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
|
||||
install -Dm755 ${_srcname} "${pkgdir}/usr/bin/${_srcname}"
|
||||
install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
|
||||
|
||||
"${pkgdir}/usr/bin/${_srcname}" completion bash | install -Dm644 /dev/stdin "${pkgdir}/usr/share/bash-completion/completions/${_srcname}"
|
||||
"${pkgdir}/usr/bin/${_srcname}" completion fish | install -Dm644 /dev/stdin "${pkgdir}/usr/share/fish/vendor_completions.d/${_srcname}.fish"
|
||||
"${pkgdir}/usr/bin/${_srcname}" completion zsh | install -Dm644 /dev/stdin "${pkgdir}/usr/share/zsh/site-functions/_${_srcname}"
|
||||
}
|
||||
|
||||
54
.github/workflows/bootstrap.yaml
vendored
54
.github/workflows/bootstrap.yaml
vendored
@@ -2,12 +2,14 @@ name: bootstrap
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
github:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
@@ -15,59 +17,69 @@ jobs:
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
key: ${{ runner.os }}-go1.16-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
${{ runner.os }}-go1.16-
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.15.x
|
||||
go-version: 1.16.x
|
||||
- name: Setup Kubernetes
|
||||
uses: engineerd/setup-kind@v0.5.0
|
||||
- name: Setup Kustomize
|
||||
uses: fluxcd/pkg//actions/kustomize@main
|
||||
- name: Build
|
||||
run: |
|
||||
make cmd/flux/manifests
|
||||
go build -o /tmp/flux ./cmd/flux
|
||||
- name: Set outputs
|
||||
id: vars
|
||||
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
|
||||
- name: Build
|
||||
run: sudo go build -o ./bin/flux ./cmd/flux
|
||||
run: |
|
||||
REPOSITORY_NAME=${{ github.event.repository.name }}
|
||||
BRANCH_NAME=${GITHUB_REF##*/}
|
||||
COMMIT_SHA=$(git rev-parse HEAD)
|
||||
PSEUDO_RAND_SUFFIX=$(echo "${BRANCH_NAME}-${COMMIT_SHA}" | shasum | awk '{print $1}')
|
||||
TEST_REPO_NAME="${REPOSITORY_NAME}-${PSEUDO_RAND_SUFFIX}"
|
||||
echo "::set-output name=test_repo_name::$TEST_REPO_NAME"
|
||||
- name: bootstrap init
|
||||
run: |
|
||||
./bin/flux bootstrap github --manifests ./manifests/install/ \
|
||||
/tmp/flux bootstrap github --manifests ./manifests/install/ \
|
||||
--owner=fluxcd-testing \
|
||||
--repository=flux-test-${{ steps.vars.outputs.sha_short }} \
|
||||
--repository=${{ steps.vars.outputs.test_repo_name }} \
|
||||
--branch=main \
|
||||
--path=test-cluster
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
|
||||
- name: bootstrap no-op
|
||||
run: |
|
||||
./bin/flux bootstrap github --manifests ./manifests/install/ \
|
||||
/tmp/flux bootstrap github --manifests ./manifests/install/ \
|
||||
--owner=fluxcd-testing \
|
||||
--repository=flux-test-${{ steps.vars.outputs.sha_short }} \
|
||||
--repository=${{ steps.vars.outputs.test_repo_name }} \
|
||||
--branch=main \
|
||||
--path=test-cluster
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
|
||||
- name: uninstall
|
||||
run: |
|
||||
./bin/flux uninstall -s --keep-namespace
|
||||
/tmp/flux uninstall -s --keep-namespace
|
||||
kubectl delete ns flux-system --timeout=10m --wait=true
|
||||
- name: bootstrap reinstall
|
||||
run: |
|
||||
./bin/flux bootstrap github --manifests ./manifests/install/ \
|
||||
/tmp/flux bootstrap github --manifests ./manifests/install/ \
|
||||
--owner=fluxcd-testing \
|
||||
--repository=flux-test-${{ steps.vars.outputs.sha_short }} \
|
||||
--repository=${{ steps.vars.outputs.test_repo_name }} \
|
||||
--branch=main \
|
||||
--path=test-cluster
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
|
||||
- name: delete repository
|
||||
run: |
|
||||
./bin/flux bootstrap github --manifests ./manifests/install/ \
|
||||
--owner=fluxcd-testing \
|
||||
--repository=flux-test-${{ steps.vars.outputs.sha_short }} \
|
||||
--branch=main \
|
||||
--path=test-cluster \
|
||||
--delete
|
||||
curl \
|
||||
-X DELETE \
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
--fail --silent \
|
||||
https://api.github.com/repos/fluxcd-testing/${{ steps.vars.outputs.test_repo_name }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
|
||||
- name: Debug failure
|
||||
|
||||
7
.github/workflows/docs.yaml
vendored
7
.github/workflows/docs.yaml
vendored
@@ -1,9 +1,8 @@
|
||||
name: Publish docs via GitHub Pages
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- docs*
|
||||
- main
|
||||
branches: [ 'docs*', main ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -17,7 +16,7 @@ jobs:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
controller_version() {
|
||||
sed -n "s/.*$1\/archive\/\(.*\).zip.*/\1/p;n" manifests/bases/$1/kustomization.yaml
|
||||
sed -n "s/.*$1\/releases\/download\/\(.*\)\/.*/\1/p;n" manifests/bases/$1/kustomization.yaml
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
99
.github/workflows/e2e.yaml
vendored
99
.github/workflows/e2e.yaml
vendored
@@ -1,10 +1,10 @@
|
||||
name: e2e
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
kind:
|
||||
@@ -16,13 +16,13 @@ jobs:
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
key: ${{ runner.os }}-go1.16-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
${{ runner.os }}-go1.16-
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.15.x
|
||||
go-version: 1.16.x
|
||||
- name: Setup Kubernetes
|
||||
uses: engineerd/setup-kind@v0.5.0
|
||||
with:
|
||||
@@ -33,6 +33,8 @@ jobs:
|
||||
run: |
|
||||
kubectl apply -f https://docs.projectcalico.org/v3.16/manifests/calico.yaml
|
||||
kubectl -n kube-system set env daemonset/calico-node FELIX_IGNORELOOSERPF=true
|
||||
- name: Setup Kustomize
|
||||
uses: fluxcd/pkg//actions/kustomize@main
|
||||
- name: Run test
|
||||
run: make test
|
||||
- name: Check if working tree is dirty
|
||||
@@ -43,43 +45,44 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
- name: Build
|
||||
run: sudo go build -o ./bin/flux ./cmd/flux
|
||||
run: |
|
||||
go build -o /tmp/flux ./cmd/flux
|
||||
- name: flux check --pre
|
||||
run: |
|
||||
./bin/flux check --pre
|
||||
/tmp/flux check --pre
|
||||
- name: flux install --manifests
|
||||
run: |
|
||||
./bin/flux install --manifests ./manifests/install/
|
||||
/tmp/flux install --manifests ./manifests/install/
|
||||
- name: flux create secret
|
||||
run: |
|
||||
./bin/flux create secret git git-ssh-test \
|
||||
/tmp/flux create secret git git-ssh-test \
|
||||
--url ssh://git@github.com/stefanprodan/podinfo
|
||||
./bin/flux create secret git git-https-test \
|
||||
/tmp/flux create secret git git-https-test \
|
||||
--url https://github.com/stefanprodan/podinfo \
|
||||
--username=test --password=test
|
||||
./bin/flux create secret helm helm-test \
|
||||
/tmp/flux create secret helm helm-test \
|
||||
--username=test --password=test
|
||||
- name: flux create source git
|
||||
run: |
|
||||
./bin/flux create source git podinfo \
|
||||
/tmp/flux create source git podinfo \
|
||||
--url https://github.com/stefanprodan/podinfo \
|
||||
--tag-semver=">=3.2.3"
|
||||
- name: flux create source git export apply
|
||||
run: |
|
||||
./bin/flux create source git podinfo-export \
|
||||
/tmp/flux create source git podinfo-export \
|
||||
--url https://github.com/stefanprodan/podinfo \
|
||||
--tag-semver=">=3.2.3" \
|
||||
--export | kubectl apply -f -
|
||||
./bin/flux delete source git podinfo-export --silent
|
||||
/tmp/flux delete source git podinfo-export --silent
|
||||
- name: flux get sources git
|
||||
run: |
|
||||
./bin/flux get sources git
|
||||
/tmp/flux get sources git
|
||||
- name: flux get sources git --all-namespaces
|
||||
run: |
|
||||
./bin/flux get sources git --all-namespaces
|
||||
/tmp/flux get sources git --all-namespaces
|
||||
- name: flux create kustomization
|
||||
run: |
|
||||
./bin/flux create kustomization podinfo \
|
||||
/tmp/flux create kustomization podinfo \
|
||||
--source=podinfo \
|
||||
--path="./deploy/overlays/dev" \
|
||||
--prune=true \
|
||||
@@ -90,112 +93,112 @@ jobs:
|
||||
--health-check-timeout=3m
|
||||
- name: flux reconcile kustomization --with-source
|
||||
run: |
|
||||
./bin/flux reconcile kustomization podinfo --with-source
|
||||
/tmp/flux reconcile kustomization podinfo --with-source
|
||||
- name: flux get kustomizations
|
||||
run: |
|
||||
./bin/flux get kustomizations
|
||||
/tmp/flux get kustomizations
|
||||
- name: flux get kustomizations --all-namespaces
|
||||
run: |
|
||||
./bin/flux get kustomizations --all-namespaces
|
||||
/tmp/flux get kustomizations --all-namespaces
|
||||
- name: flux suspend kustomization
|
||||
run: |
|
||||
./bin/flux suspend kustomization podinfo
|
||||
/tmp/flux suspend kustomization podinfo
|
||||
- name: flux resume kustomization
|
||||
run: |
|
||||
./bin/flux resume kustomization podinfo
|
||||
/tmp/flux resume kustomization podinfo
|
||||
- name: flux export
|
||||
run: |
|
||||
./bin/flux export source git --all
|
||||
./bin/flux export kustomization --all
|
||||
/tmp/flux export source git --all
|
||||
/tmp/flux export kustomization --all
|
||||
- name: flux delete kustomization
|
||||
run: |
|
||||
./bin/flux delete kustomization podinfo --silent
|
||||
/tmp/flux delete kustomization podinfo --silent
|
||||
- name: flux create source helm
|
||||
run: |
|
||||
./bin/flux create source helm podinfo \
|
||||
/tmp/flux create source helm podinfo \
|
||||
--url https://stefanprodan.github.io/podinfo
|
||||
- name: flux create helmrelease --source=HelmRepository/podinfo
|
||||
run: |
|
||||
./bin/flux create hr podinfo-helm \
|
||||
/tmp/flux create hr podinfo-helm \
|
||||
--target-namespace=default \
|
||||
--source=HelmRepository/podinfo \
|
||||
--chart=podinfo \
|
||||
--chart-version=">4.0.0 <5.0.0"
|
||||
- name: flux create helmrelease --source=GitRepository/podinfo
|
||||
run: |
|
||||
./bin/flux create hr podinfo-git \
|
||||
/tmp/flux create hr podinfo-git \
|
||||
--target-namespace=default \
|
||||
--source=GitRepository/podinfo \
|
||||
--chart=./charts/podinfo
|
||||
- name: flux reconcile helmrelease --with-source
|
||||
run: |
|
||||
./bin/flux reconcile helmrelease podinfo-git --with-source
|
||||
/tmp/flux reconcile helmrelease podinfo-git --with-source
|
||||
- name: flux get helmreleases
|
||||
run: |
|
||||
./bin/flux get helmreleases
|
||||
/tmp/flux get helmreleases
|
||||
- name: flux get helmreleases --all-namespaces
|
||||
run: |
|
||||
./bin/flux get helmreleases --all-namespaces
|
||||
/tmp/flux get helmreleases --all-namespaces
|
||||
- name: flux export helmrelease
|
||||
run: |
|
||||
./bin/flux export hr --all
|
||||
/tmp/flux export hr --all
|
||||
- name: flux delete helmrelease podinfo-helm
|
||||
run: |
|
||||
./bin/flux delete hr podinfo-helm --silent
|
||||
/tmp/flux delete hr podinfo-helm --silent
|
||||
- name: flux delete helmrelease podinfo-git
|
||||
run: |
|
||||
./bin/flux delete hr podinfo-git --silent
|
||||
/tmp/flux delete hr podinfo-git --silent
|
||||
- name: flux delete source helm
|
||||
run: |
|
||||
./bin/flux delete source helm podinfo --silent
|
||||
/tmp/flux delete source helm podinfo --silent
|
||||
- name: flux delete source git
|
||||
run: |
|
||||
./bin/flux delete source git podinfo --silent
|
||||
/tmp/flux delete source git podinfo --silent
|
||||
- name: flux create tenant
|
||||
run: |
|
||||
./bin/flux create tenant dev-team --with-namespace=apps
|
||||
./bin/flux -n apps create source helm podinfo \
|
||||
/tmp/flux create tenant dev-team --with-namespace=apps
|
||||
/tmp/flux -n apps create source helm podinfo \
|
||||
--url https://stefanprodan.github.io/podinfo
|
||||
./bin/flux -n apps create hr podinfo-helm \
|
||||
/tmp/flux -n apps create hr podinfo-helm \
|
||||
--source=HelmRepository/podinfo \
|
||||
--chart=podinfo \
|
||||
--chart-version="5.0.x" \
|
||||
--service-account=dev-team
|
||||
- name: flux create image repository
|
||||
run: |
|
||||
./bin/flux create image repository podinfo \
|
||||
/tmp/flux create image repository podinfo \
|
||||
--image=ghcr.io/stefanprodan/podinfo \
|
||||
--interval=1m
|
||||
- name: flux create image policy
|
||||
run: |
|
||||
./bin/flux create image policy podinfo \
|
||||
/tmp/flux create image policy podinfo \
|
||||
--image-ref=podinfo \
|
||||
--interval=1m \
|
||||
--select-semver=5.0.x
|
||||
- name: flux create image policy podinfo-select-alpha
|
||||
run: |
|
||||
./bin/flux create image policy podinfo-alpha \
|
||||
/tmp/flux create image policy podinfo-alpha \
|
||||
--image-ref=podinfo \
|
||||
--interval=1m \
|
||||
--select-alpha=desc
|
||||
- name: flux get image policy
|
||||
run: |
|
||||
./bin/flux get image policy podinfo | grep '5.0.3'
|
||||
/tmp/flux get image policy podinfo | grep '5.0.3'
|
||||
- name: flux2-kustomize-helm-example
|
||||
run: |
|
||||
./bin/flux create source git flux-system \
|
||||
/tmp/flux create source git flux-system \
|
||||
--url=https://github.com/fluxcd/flux2-kustomize-helm-example \
|
||||
--branch=main
|
||||
./bin/flux create kustomization flux-system \
|
||||
/tmp/flux create kustomization flux-system \
|
||||
--source=flux-system \
|
||||
--path=./clusters/staging
|
||||
kubectl -n flux-system wait kustomization/apps --for=condition=ready --timeout=2m
|
||||
- name: flux check
|
||||
run: |
|
||||
./bin/flux check
|
||||
/tmp/flux check
|
||||
- name: flux uninstall
|
||||
run: |
|
||||
./bin/flux uninstall --silent
|
||||
/tmp/flux uninstall --silent
|
||||
- name: Debug failure
|
||||
if: failure()
|
||||
run: |
|
||||
|
||||
25
.github/workflows/fossa.yml
vendored
25
.github/workflows/fossa.yml
vendored
@@ -1,25 +0,0 @@
|
||||
name: FOSSA
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: "^1.14.x"
|
||||
- name: Add GOPATH to GITHUB_ENV
|
||||
run: echo "GOPATH=$(go env GOPATH)" >>"$GITHUB_ENV"
|
||||
- name: Add GOPATH to GITHUB_PATH
|
||||
run: echo "$GOPATH/bin" >>"$GITHUB_PATH"
|
||||
- name: Run FOSSA scan and upload build data
|
||||
uses: fossa-contrib/fossa-action@v1
|
||||
with:
|
||||
# FOSSA Push-Only API Token
|
||||
fossa-api-key: 5ee8bf422db1471e0bcf2bcb289185de
|
||||
github-token: ${{ github.token }}
|
||||
@@ -2,9 +2,9 @@ name: rebase
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened]
|
||||
types: [ opened ]
|
||||
issue_comment:
|
||||
types: [created]
|
||||
types: [ created ]
|
||||
|
||||
jobs:
|
||||
rebase:
|
||||
39
.github/workflows/release.yaml
vendored
39
.github/workflows/release.yaml
vendored
@@ -2,8 +2,7 @@ name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
tags: [ 'v*' ]
|
||||
|
||||
jobs:
|
||||
goreleaser:
|
||||
@@ -16,7 +15,7 @@ jobs:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.15.x
|
||||
go-version: 1.16.x
|
||||
- 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
|
||||
@@ -29,38 +28,10 @@ jobs:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Setup Kustomize
|
||||
uses: fluxcd/pkg//actions/kustomize@main
|
||||
- name: Generate manifests tarball
|
||||
run: |
|
||||
mkdir -p ./output
|
||||
files=""
|
||||
|
||||
# build controllers
|
||||
for controller in ./manifests/bases/*/; do
|
||||
output_path="./output/$(basename $controller).yaml"
|
||||
echo "building $controller to $output_path"
|
||||
|
||||
kustomize build $controller > $output_path
|
||||
files+=" $(basename $output_path)"
|
||||
done
|
||||
|
||||
# build rbac
|
||||
rbac_path="./manifests/rbac"
|
||||
rbac_output_path="./output/rbac.yaml"
|
||||
echo "building $rbac_path to $rbac_output_path"
|
||||
kustomize build $rbac_path > $rbac_output_path
|
||||
files+=" $(basename $rbac_output_path)"
|
||||
|
||||
# build policies
|
||||
policies_path="./manifests/policies"
|
||||
policies_output_path="./output/policies.yaml"
|
||||
echo "building $policies_path to $policies_output_path"
|
||||
kustomize build $policies_path > $policies_output_path
|
||||
files+=" $(basename $policies_output_path)"
|
||||
|
||||
# create tarball
|
||||
cd ./output && tar -cvzf manifests.tar.gz $files
|
||||
- name: Generate install manifest
|
||||
- name: Generate manifests
|
||||
run: |
|
||||
make cmd/flux/manifests
|
||||
./manifests/scripts/bundle.sh "" ./output manifests.tar.gz
|
||||
kustomize build ./manifests/install > ./output/install.yaml
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v1
|
||||
|
||||
60
.github/workflows/scan.yaml
vendored
Normal file
60
.github/workflows/scan.yaml
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
name: Scan
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
schedule:
|
||||
- cron: '18 10 * * 3'
|
||||
|
||||
jobs:
|
||||
fossa:
|
||||
name: FOSSA
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Run FOSSA scan and upload build data
|
||||
uses: fossa-contrib/fossa-action@v1
|
||||
with:
|
||||
# FOSSA Push-Only API Token
|
||||
fossa-api-key: 5ee8bf422db1471e0bcf2bcb289185de
|
||||
github-token: ${{ github.token }}
|
||||
|
||||
snyk:
|
||||
name: Snyk
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup Kustomize
|
||||
uses: fluxcd/pkg//actions/kustomize@main
|
||||
- name: Build manifests
|
||||
run: |
|
||||
make cmd/flux/manifests
|
||||
- name: Run Snyk to check for vulnerabilities
|
||||
uses: snyk/actions/golang@master
|
||||
continue-on-error: true
|
||||
env:
|
||||
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
|
||||
with:
|
||||
args: --sarif-file-output=snyk.sarif
|
||||
- name: Upload result to GitHub Code Scanning
|
||||
uses: github/codeql-action/upload-sarif@v1
|
||||
with:
|
||||
sarif_file: snyk.sarif
|
||||
|
||||
codeql:
|
||||
name: CodeQL
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: go
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
@@ -13,7 +13,10 @@ jobs:
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.16.x
|
||||
- name: Update component versions
|
||||
id: update
|
||||
run: |
|
||||
@@ -21,13 +24,13 @@ jobs:
|
||||
|
||||
bump_version() {
|
||||
local RELEASE_VERSION=$(curl -s https://api.github.com/repos/fluxcd/$1/releases | jq -r 'sort_by(.published_at) | .[-1] | .tag_name')
|
||||
local CURRENT_VERSION=$(sed -n "s/.*$1\/archive\/\(.*\).zip.*/\1/p;n" manifests/bases/$1/kustomization.yaml)
|
||||
local CURRENT_VERSION=$(sed -n "s/.*$1\/releases\/download\/\(.*\)\/.*/\1/p;n" manifests/bases/$1/kustomization.yaml)
|
||||
|
||||
if [[ "${RELEASE_VERSION}" != "${CURRENT_VERSION}" ]]; then
|
||||
# bump kustomize
|
||||
sed -i "s/\($1\/archive\/\)v.*\(.zip\/\/$1-\).*\(\/config.*\)/\1${RELEASE_VERSION}\2${RELEASE_VERSION/v}\3/g" "manifests/bases/$1/kustomization.yaml"
|
||||
sed -i "s/\($1\/releases\/download\/\)v.*\(\/.*\)/\1${RELEASE_VERSION}\2/g" "manifests/bases/$1/kustomization.yaml"
|
||||
|
||||
if [[ ! -z $(go list -m all | grep "github.com/fluxcd/$1/api" | awk '{print $2}') ]]; then
|
||||
if [[ ! -z $(grep "github.com/fluxcd/$1/api" go.mod | awk '{print $2}') ]]; then
|
||||
# bump go mod
|
||||
go mod edit -require="github.com/fluxcd/$1/api@${RELEASE_VERSION}"
|
||||
fi
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -14,4 +14,5 @@
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
bin/
|
||||
output/
|
||||
output/
|
||||
cmd/flux/manifests/
|
||||
|
||||
@@ -20,6 +20,9 @@ builds:
|
||||
id: darwin
|
||||
goos:
|
||||
- darwin
|
||||
goarch:
|
||||
- amd64
|
||||
- arm64
|
||||
- <<: *build_defaults
|
||||
id: windows
|
||||
goos:
|
||||
|
||||
@@ -48,11 +48,13 @@ you might want to take a look at the [introductory talk and demo](https://www.yo
|
||||
|
||||
This project is composed of:
|
||||
|
||||
- [/f/flux2](https://github.com/fluxcd/flux2): The Flux CLI
|
||||
- [/f/source-manager](https://github.com/fluxcd/source-controller): Kubernetes operator for managing sources
|
||||
- [/f/kustomize-controller](https://github.com/fluxcd/kustomize-controller): Kubernetes operator for building GitOps pipelines with Kustomize
|
||||
- [/f/helm-controller](https://github.com/fluxcd/helm-controller): Kubernetes operator for building GitOps pipelines with Helm
|
||||
- [/f/notification-controller](https://github.com/fluxcd/notification-controller): Kubernetes operator for handling inbound and outbound events
|
||||
- [flux2](https://github.com/fluxcd/flux2): The Flux CLI
|
||||
- [source-manager](https://github.com/fluxcd/source-controller): Kubernetes operator for managing sources (Git and Helm repositories, S3-compatible Buckets)
|
||||
- [kustomize-controller](https://github.com/fluxcd/kustomize-controller): Kubernetes operator for building GitOps pipelines with Kustomize
|
||||
- [helm-controller](https://github.com/fluxcd/helm-controller): Kubernetes operator for building GitOps pipelines with Helm
|
||||
- [notification-controller](https://github.com/fluxcd/notification-controller): Kubernetes operator for handling inbound and outbound events
|
||||
- [image-reflector-controller](https://github.com/fluxcd/image-reflector-controller): Kubernetes operator for scanning container registries
|
||||
- [image-automation-controller](https://github.com/fluxcd/image-automation-controller): Kubernetes operator for patches container image tags in Git
|
||||
|
||||
### Understanding the code
|
||||
|
||||
@@ -63,6 +65,12 @@ for source changes.
|
||||
|
||||
### How to run the test suite
|
||||
|
||||
Prerequisites:
|
||||
|
||||
* go >= 1.16
|
||||
* kubectl >= 1.18
|
||||
* kustomize >= 3.1
|
||||
|
||||
You can run the unit tests by simply doing
|
||||
|
||||
```bash
|
||||
|
||||
12
Makefile
12
Makefile
@@ -1,4 +1,7 @@
|
||||
VERSION?=$(shell grep 'VERSION' cmd/flux/main.go | awk '{ print $$4 }' | tr -d '"')
|
||||
EMBEDDED_MANIFESTS_TARGET=cmd/flux/manifests
|
||||
|
||||
rwildcard=$(foreach d,$(wildcard $(addsuffix *,$(1))),$(call rwildcard,$(d)/,$(2)) $(filter $(subst *,%,$(2)),$(d)))
|
||||
|
||||
all: test build
|
||||
|
||||
@@ -11,10 +14,13 @@ fmt:
|
||||
vet:
|
||||
go vet ./...
|
||||
|
||||
test: tidy fmt vet docs
|
||||
test: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet docs
|
||||
go test ./... -coverprofile cover.out
|
||||
|
||||
build:
|
||||
$(EMBEDDED_MANIFESTS_TARGET): $(call rwildcard,manifests/,*.yaml *.json)
|
||||
./manifests/scripts/bundle.sh
|
||||
|
||||
build: $(EMBEDDED_MANIFESTS_TARGET)
|
||||
CGO_ENABLED=0 go build -o ./bin/flux ./cmd/flux
|
||||
|
||||
install:
|
||||
@@ -22,7 +28,7 @@ install:
|
||||
|
||||
.PHONY: docs
|
||||
docs:
|
||||
rm docs/cmd/*
|
||||
rm -rf docs/cmd/*
|
||||
mkdir -p ./docs/cmd && go run ./cmd/flux/ docgen
|
||||
|
||||
install-dev:
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
FROM stefanprodan/alpine-base:latest
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
@@ -10,15 +10,20 @@ Usage:
|
||||
run: flux -v
|
||||
```
|
||||
|
||||
This action places the `flux` binary inside your repository root under `bin/flux`.
|
||||
You should add `bin/flux` to your `.gitignore` file, as in the following example:
|
||||
|
||||
```gitignore
|
||||
# ignore flux binary
|
||||
bin/flux
|
||||
```
|
||||
|
||||
Note that this action can only be used on GitHub **Linux AMD64** runners.
|
||||
The latest stable version of the `flux` binary is downloaded from
|
||||
GitHub [releases](https://github.com/fluxcd/flux2/releases)
|
||||
and placed at `/usr/local/bin/flux`.
|
||||
|
||||
You can download a specific version with:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- name: Setup Flux CLI
|
||||
uses: fluxcd/flux2/action@main
|
||||
with:
|
||||
version: 0.8.0
|
||||
```
|
||||
|
||||
### Automate Flux updates
|
||||
|
||||
|
||||
@@ -1,15 +1,38 @@
|
||||
name: 'kustomize'
|
||||
description: 'A GitHub Action for running Flux commands'
|
||||
author: 'Flux project'
|
||||
name: Setup Flux CLI
|
||||
description: A GitHub Action for running Flux commands
|
||||
author: Stefan Prodan
|
||||
branding:
|
||||
icon: 'command'
|
||||
color: 'blue'
|
||||
color: blue
|
||||
icon: command
|
||||
inputs:
|
||||
version:
|
||||
description: 'strict semver'
|
||||
description: "Flux version e.g. 0.8.0 (defaults to latest stable release)"
|
||||
required: false
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
args:
|
||||
- ${{ inputs.version }}
|
||||
using: composite
|
||||
steps:
|
||||
- name: "Download flux binary to tmp"
|
||||
shell: bash
|
||||
run: |
|
||||
VERSION=${{ inputs.version }}
|
||||
|
||||
if [ -z $VERSION ]; then
|
||||
VERSION=$(curl https://api.github.com/repos/fluxcd/flux2/releases/latest -sL | grep tag_name | sed -E 's/.*"([^"]+)".*/\1/' | cut -c 2-)
|
||||
fi
|
||||
|
||||
BIN_URL="https://github.com/fluxcd/flux2/releases/download/v${VERSION}/flux_${VERSION}_linux_amd64.tar.gz"
|
||||
curl -sL ${BIN_URL} -o /tmp/flux.tar.gz
|
||||
mkdir -p /tmp/flux
|
||||
tar -C /tmp/flux/ -zxvf /tmp/flux.tar.gz
|
||||
- name: "Add flux binary to /usr/local/bin"
|
||||
shell: bash
|
||||
run: |
|
||||
sudo cp /tmp/flux/flux /usr/local/bin
|
||||
- name: "Cleanup tmp"
|
||||
shell: bash
|
||||
run: |
|
||||
rm -rf /tmp/flux/ /tmp/flux.tar.gz
|
||||
- name: "Verify correct installation of binary"
|
||||
shell: bash
|
||||
run: |
|
||||
flux -v
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2020 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.
|
||||
|
||||
set -e
|
||||
|
||||
VERSION=$1
|
||||
|
||||
if [ -z $VERSION ]; then
|
||||
# Find latest release if no version is specified
|
||||
VERSION=$(curl https://api.github.com/repos/fluxcd/flux2/releases/latest -sL | grep tag_name | sed -E 's/.*"([^"]+)".*/\1/' | cut -c 2-)
|
||||
fi
|
||||
|
||||
# Download linux binary
|
||||
BIN_URL="https://github.com/fluxcd/flux2/releases/download/v${VERSION}/flux_${VERSION}_linux_amd64.tar.gz"
|
||||
curl -sL $BIN_URL | tar xz
|
||||
|
||||
# Copy binary to GitHub runner
|
||||
mkdir -p $GITHUB_WORKSPACE/bin
|
||||
mv ./flux $GITHUB_WORKSPACE/bin
|
||||
chmod +x $GITHUB_WORKSPACE/bin/flux
|
||||
|
||||
# Print version
|
||||
$GITHUB_WORKSPACE/bin/flux -v
|
||||
|
||||
# Add binary to GitHub runner path
|
||||
echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH
|
||||
echo "$RUNNER_WORKSPACE/$(basename $GITHUB_REPOSITORY)/bin" >> $GITHUB_PATH
|
||||
@@ -19,13 +19,11 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
@@ -36,7 +34,9 @@ import (
|
||||
"github.com/fluxcd/flux2/internal/flags"
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||
kus "github.com/fluxcd/flux2/pkg/manifestgen/kustomization"
|
||||
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
||||
"github.com/fluxcd/flux2/pkg/status"
|
||||
)
|
||||
|
||||
var bootstrapCmd = &cobra.Command{
|
||||
@@ -70,8 +70,8 @@ const (
|
||||
var bootstrapArgs = NewBootstrapFlags()
|
||||
|
||||
func init() {
|
||||
bootstrapCmd.PersistentFlags().StringVarP(&bootstrapArgs.version, "version", "v", rootArgs.defaults.Version,
|
||||
"toolkit version")
|
||||
bootstrapCmd.PersistentFlags().StringVarP(&bootstrapArgs.version, "version", "v", "",
|
||||
"toolkit version, when specified the manifests are downloaded from https://github.com/fluxcd/flux2/releases")
|
||||
bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapArgs.defaultComponents, "components", rootArgs.defaults.Components,
|
||||
"list of components, accepts comma-separated values")
|
||||
bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapArgs.extraComponents, "components-extra", nil,
|
||||
@@ -126,12 +126,18 @@ func bootstrapValidate() error {
|
||||
}
|
||||
|
||||
func generateInstallManifests(targetPath, namespace, tmpDir string, localManifests string) (string, error) {
|
||||
if bootstrapArgs.version == install.MakeDefaultOptions().Version {
|
||||
version, err := install.GetLatestVersion()
|
||||
if err != nil {
|
||||
if ver, err := getVersion(bootstrapArgs.version); err != nil {
|
||||
return "", err
|
||||
} else {
|
||||
bootstrapArgs.version = ver
|
||||
}
|
||||
|
||||
manifestsBase := ""
|
||||
if isEmbeddedVersion(bootstrapArgs.version) {
|
||||
if err := writeEmbeddedManifests(tmpDir); err != nil {
|
||||
return "", err
|
||||
}
|
||||
bootstrapArgs.version = version
|
||||
manifestsBase = tmpDir
|
||||
}
|
||||
|
||||
opts := install.Options{
|
||||
@@ -156,7 +162,7 @@ func generateInstallManifests(targetPath, namespace, tmpDir string, localManifes
|
||||
opts.BaseURL = rootArgs.defaults.BaseURL
|
||||
}
|
||||
|
||||
output, err := install.Generate(opts)
|
||||
output, err := install.Generate(opts, manifestsBase)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("generating install manifests failed: %w", err)
|
||||
}
|
||||
@@ -171,19 +177,24 @@ func generateInstallManifests(targetPath, namespace, tmpDir string, localManifes
|
||||
func applyInstallManifests(ctx context.Context, manifestPath string, components []string) error {
|
||||
kubectlArgs := []string{"apply", "-f", manifestPath}
|
||||
if _, err := utils.ExecKubectlCommand(ctx, utils.ModeOS, rootArgs.kubeconfig, rootArgs.kubecontext, kubectlArgs...); err != nil {
|
||||
return fmt.Errorf("install failed")
|
||||
return fmt.Errorf("install failed: %w", err)
|
||||
}
|
||||
|
||||
statusChecker, err := NewStatusChecker(time.Second, rootArgs.timeout)
|
||||
kubeConfig, err := utils.KubeConfig(rootArgs.kubeconfig, rootArgs.kubecontext)
|
||||
if err != nil {
|
||||
return fmt.Errorf("install failed: %w", err)
|
||||
}
|
||||
statusChecker, err := status.NewStatusChecker(kubeConfig, time.Second, rootArgs.timeout, logger)
|
||||
if err != nil {
|
||||
return fmt.Errorf("install failed: %w", err)
|
||||
}
|
||||
componentRefs, err := buildComponentObjectRefs(components...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("install failed: %w", err)
|
||||
}
|
||||
|
||||
logger.Waitingf("verifying installation")
|
||||
if err := statusChecker.Assess(components...); err != nil {
|
||||
if err := statusChecker.Assess(componentRefs...); err != nil {
|
||||
return fmt.Errorf("install failed")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -194,6 +205,7 @@ func generateSyncManifests(url, branch, name, namespace, targetPath, tmpDir stri
|
||||
URL: url,
|
||||
Branch: branch,
|
||||
Interval: interval,
|
||||
Secret: namespace,
|
||||
TargetPath: targetPath,
|
||||
ManifestFile: sync.MakeDefaultOptions().ManifestFile,
|
||||
}
|
||||
@@ -208,9 +220,19 @@ func generateSyncManifests(url, branch, name, namespace, targetPath, tmpDir stri
|
||||
return "", err
|
||||
}
|
||||
outputDir := filepath.Dir(output)
|
||||
if err := utils.GenerateKustomizationYaml(outputDir); err != nil {
|
||||
|
||||
kusOpts := kus.MakeDefaultOptions()
|
||||
kusOpts.BaseDir = tmpDir
|
||||
kusOpts.TargetPath = filepath.Dir(manifest.Path)
|
||||
|
||||
kustomization, err := kus.Generate(kusOpts)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if _, err = kustomization.WriteFile(tmpDir); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return outputDir, nil
|
||||
}
|
||||
|
||||
@@ -263,35 +285,6 @@ func shouldCreateDeployKey(ctx context.Context, kubeClient client.Client, namesp
|
||||
return false
|
||||
}
|
||||
|
||||
func generateDeployKey(ctx context.Context, kubeClient client.Client, url *url.URL, namespace string) (string, error) {
|
||||
pair, err := generateKeyPair(ctx, sourceGitArgs.keyAlgorithm, sourceGitArgs.keyRSABits, sourceGitArgs.keyECDSACurve)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
hostKey, err := scanHostKey(ctx, url)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
secret := corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: namespace,
|
||||
Namespace: namespace,
|
||||
},
|
||||
StringData: map[string]string{
|
||||
"identity": string(pair.PrivateKey),
|
||||
"identity.pub": string(pair.PublicKey),
|
||||
"known_hosts": string(hostKey),
|
||||
},
|
||||
}
|
||||
if err := upsertSecret(ctx, kubeClient, secret); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(pair.PublicKey), nil
|
||||
}
|
||||
|
||||
func checkIfBootstrapPathDiffers(ctx context.Context, kubeClient client.Client, namespace string, path string) (string, bool) {
|
||||
namespacedName := types.NamespacedName{
|
||||
Name: namespace,
|
||||
|
||||
@@ -26,14 +26,14 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/fluxcd/pkg/git"
|
||||
"github.com/spf13/cobra"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/fluxcd/pkg/git"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/flags"
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||
)
|
||||
|
||||
var bootstrapGitHubCmd = &cobra.Command{
|
||||
@@ -80,7 +80,6 @@ type githubFlags struct {
|
||||
hostname string
|
||||
path flags.SafeRelativePath
|
||||
teams []string
|
||||
delete bool
|
||||
sshHostname string
|
||||
}
|
||||
|
||||
@@ -101,9 +100,6 @@ func init() {
|
||||
bootstrapGitHubCmd.Flags().StringVar(&githubArgs.sshHostname, "ssh-hostname", "", "GitHub SSH hostname, to be used when the SSH host differs from the HTTPS one")
|
||||
bootstrapGitHubCmd.Flags().Var(&githubArgs.path, "path", "path relative to the repository root, when specified the cluster sync will be scoped to this path")
|
||||
|
||||
bootstrapGitHubCmd.Flags().BoolVar(&githubArgs.delete, "delete", false, "delete repository (used for testing only)")
|
||||
bootstrapGitHubCmd.Flags().MarkHidden("delete")
|
||||
|
||||
bootstrapCmd.AddCommand(bootstrapGitHubCmd)
|
||||
}
|
||||
|
||||
@@ -163,14 +159,6 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
if githubArgs.delete {
|
||||
if err := provider.DeleteRepository(ctx, repository); err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Successf("repository deleted")
|
||||
return nil
|
||||
}
|
||||
|
||||
// create GitHub repository if doesn't exists
|
||||
logger.Actionf("connecting to %s", githubArgs.hostname)
|
||||
changed, err := provider.CreateRepository(ctx, repository)
|
||||
@@ -244,44 +232,48 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
||||
logger.Successf("install completed")
|
||||
}
|
||||
|
||||
repoURL := repository.GetURL()
|
||||
|
||||
repoURL := repository.GetSSH()
|
||||
secretOpts := sourcesecret.Options{
|
||||
Name: rootArgs.namespace,
|
||||
Namespace: rootArgs.namespace,
|
||||
}
|
||||
if bootstrapArgs.tokenAuth {
|
||||
// setup HTTPS token auth
|
||||
secret := corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: rootArgs.namespace,
|
||||
Namespace: rootArgs.namespace,
|
||||
},
|
||||
StringData: map[string]string{
|
||||
"username": "git",
|
||||
"password": ghToken,
|
||||
},
|
||||
// Setup HTTPS token auth
|
||||
repoURL = repository.GetURL()
|
||||
secretOpts.Username = "git"
|
||||
secretOpts.Password = ghToken
|
||||
} else if shouldCreateDeployKey(ctx, kubeClient, rootArgs.namespace) {
|
||||
// Setup SSH auth
|
||||
u, err := url.Parse(repoURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("git URL parse failed: %w", err)
|
||||
}
|
||||
if err := upsertSecret(ctx, kubeClient, secret); err != nil {
|
||||
secretOpts.SSHHostname = u.Host
|
||||
secretOpts.PrivateKeyAlgorithm = sourcesecret.RSAPrivateKeyAlgorithm
|
||||
secretOpts.RSAKeyBits = 2048
|
||||
}
|
||||
|
||||
secret, err := sourcesecret.Generate(secretOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var s corev1.Secret
|
||||
if err := yaml.Unmarshal([]byte(secret.Content), &s); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(s.StringData) > 0 {
|
||||
logger.Actionf("configuring deploy key")
|
||||
if err := upsertSecret(ctx, kubeClient, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// setup SSH deploy key
|
||||
repoURL = repository.GetSSH()
|
||||
if shouldCreateDeployKey(ctx, kubeClient, rootArgs.namespace) {
|
||||
logger.Actionf("configuring deploy key")
|
||||
u, err := url.Parse(repository.GetSSH())
|
||||
if err != nil {
|
||||
return fmt.Errorf("git URL parse failed: %w", err)
|
||||
}
|
||||
|
||||
key, err := generateDeployKey(ctx, kubeClient, u, rootArgs.namespace)
|
||||
if err != nil {
|
||||
return fmt.Errorf("generating deploy key failed: %w", err)
|
||||
}
|
||||
|
||||
if ppk, ok := s.StringData[sourcesecret.PublicKeySecretKey]; ok {
|
||||
keyName := "flux"
|
||||
if githubArgs.path != "" {
|
||||
keyName = fmt.Sprintf("flux-%s", githubArgs.path)
|
||||
}
|
||||
|
||||
if changed, err := provider.AddDeployKey(ctx, repository, key, keyName); err != nil {
|
||||
if changed, err := provider.AddDeployKey(ctx, repository, ppk, keyName); err != nil {
|
||||
return err
|
||||
} else if changed {
|
||||
logger.Successf("deploy key configured")
|
||||
|
||||
@@ -29,12 +29,13 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/fluxcd/pkg/git"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/flags"
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||
)
|
||||
|
||||
var bootstrapGitLabCmd = &cobra.Command{
|
||||
@@ -218,44 +219,48 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
||||
logger.Successf("install completed")
|
||||
}
|
||||
|
||||
repoURL := repository.GetURL()
|
||||
|
||||
repoURL := repository.GetSSH()
|
||||
secretOpts := sourcesecret.Options{
|
||||
Name: rootArgs.namespace,
|
||||
Namespace: rootArgs.namespace,
|
||||
}
|
||||
if bootstrapArgs.tokenAuth {
|
||||
// setup HTTPS token auth
|
||||
secret := corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: rootArgs.namespace,
|
||||
Namespace: rootArgs.namespace,
|
||||
},
|
||||
StringData: map[string]string{
|
||||
"username": "git",
|
||||
"password": glToken,
|
||||
},
|
||||
// Setup HTTPS token auth
|
||||
repoURL = repository.GetURL()
|
||||
secretOpts.Username = "git"
|
||||
secretOpts.Password = glToken
|
||||
} else if shouldCreateDeployKey(ctx, kubeClient, rootArgs.namespace) {
|
||||
// Setup SSH auth
|
||||
u, err := url.Parse(repoURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("git URL parse failed: %w", err)
|
||||
}
|
||||
if err := upsertSecret(ctx, kubeClient, secret); err != nil {
|
||||
secretOpts.SSHHostname = u.Host
|
||||
secretOpts.PrivateKeyAlgorithm = sourcesecret.RSAPrivateKeyAlgorithm
|
||||
secretOpts.RSAKeyBits = 2048
|
||||
}
|
||||
|
||||
secret, err := sourcesecret.Generate(secretOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var s corev1.Secret
|
||||
if err := yaml.Unmarshal([]byte(secret.Content), &s); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(s.StringData) > 0 {
|
||||
logger.Actionf("configuring deploy key")
|
||||
if err := upsertSecret(ctx, kubeClient, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// setup SSH deploy key
|
||||
repoURL = repository.GetSSH()
|
||||
if shouldCreateDeployKey(ctx, kubeClient, rootArgs.namespace) {
|
||||
logger.Actionf("configuring deploy key")
|
||||
u, err := url.Parse(repoURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("git URL parse failed: %w", err)
|
||||
}
|
||||
|
||||
key, err := generateDeployKey(ctx, kubeClient, u, rootArgs.namespace)
|
||||
if err != nil {
|
||||
return fmt.Errorf("generating deploy key failed: %w", err)
|
||||
}
|
||||
|
||||
if ppk, ok := s.StringData[sourcesecret.PublicKeySecretKey]; ok {
|
||||
keyName := "flux"
|
||||
if gitlabArgs.path != "" {
|
||||
keyName = fmt.Sprintf("flux-%s", gitlabArgs.path)
|
||||
}
|
||||
|
||||
if changed, err := provider.AddDeployKey(ctx, repository, key, keyName); err != nil {
|
||||
if changed, err := provider.AddDeployKey(ctx, repository, ppk, keyName); err != nil {
|
||||
return err
|
||||
} else if changed {
|
||||
logger.Successf("deploy key configured")
|
||||
|
||||
@@ -21,14 +21,20 @@ import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/blang/semver/v4"
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
"github.com/Masterminds/semver/v3"
|
||||
"github.com/spf13/cobra"
|
||||
v1 "k8s.io/api/apps/v1"
|
||||
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
"github.com/fluxcd/pkg/version"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||
"github.com/fluxcd/flux2/pkg/status"
|
||||
)
|
||||
|
||||
var checkCmd = &cobra.Command{
|
||||
@@ -74,11 +80,13 @@ func runCheckCmd(cmd *cobra.Command, args []string) error {
|
||||
logger.Actionf("checking prerequisites")
|
||||
checkFailed := false
|
||||
|
||||
if !kubectlCheck(ctx, ">=1.18.0") {
|
||||
fluxCheck()
|
||||
|
||||
if !kubectlCheck(ctx, ">=1.18.0-0") {
|
||||
checkFailed = true
|
||||
}
|
||||
|
||||
if !kubernetesCheck(">=1.16.0") {
|
||||
if !kubernetesCheck(">=1.16.0-0") {
|
||||
checkFailed = true
|
||||
}
|
||||
|
||||
@@ -101,7 +109,29 @@ func runCheckCmd(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func kubectlCheck(ctx context.Context, version string) bool {
|
||||
func fluxCheck() {
|
||||
curSv, err := version.ParseVersion(VERSION)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// Exclude development builds.
|
||||
if curSv.Prerelease() != "" {
|
||||
return
|
||||
}
|
||||
latest, err := install.GetLatestVersion()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
latestSv, err := version.ParseVersion(latest)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if latestSv.GreaterThan(curSv) {
|
||||
logger.Failuref("flux %s <%s (new version is available, please upgrade)", curSv, latestSv)
|
||||
}
|
||||
}
|
||||
|
||||
func kubectlCheck(ctx context.Context, constraint string) bool {
|
||||
_, err := exec.LookPath("kubectl")
|
||||
if err != nil {
|
||||
logger.Failuref("kubectl not found")
|
||||
@@ -117,58 +147,58 @@ func kubectlCheck(ctx context.Context, version string) bool {
|
||||
|
||||
kv := &kubectlVersion{}
|
||||
if err = json.Unmarshal([]byte(output), kv); err != nil {
|
||||
logger.Failuref("kubectl version output can't be unmarshaled")
|
||||
logger.Failuref("kubectl version output can't be unmarshalled")
|
||||
return false
|
||||
}
|
||||
|
||||
v, err := semver.ParseTolerant(kv.ClientVersion.GitVersion)
|
||||
v, err := version.ParseVersion(kv.ClientVersion.GitVersion)
|
||||
if err != nil {
|
||||
logger.Failuref("kubectl version can't be parsed")
|
||||
return false
|
||||
}
|
||||
|
||||
rng, _ := semver.ParseRange(version)
|
||||
if !rng(v) {
|
||||
logger.Failuref("kubectl version must be %s", version)
|
||||
c, _ := semver.NewConstraint(constraint)
|
||||
if !c.Check(v) {
|
||||
logger.Failuref("kubectl version %s < %s", v.Original(), constraint)
|
||||
return false
|
||||
}
|
||||
|
||||
logger.Successf("kubectl %s %s", v.String(), version)
|
||||
logger.Successf("kubectl %s %s", v.String(), constraint)
|
||||
return true
|
||||
}
|
||||
|
||||
func kubernetesCheck(version string) bool {
|
||||
func kubernetesCheck(constraint string) bool {
|
||||
cfg, err := utils.KubeConfig(rootArgs.kubeconfig, rootArgs.kubecontext)
|
||||
if err != nil {
|
||||
logger.Failuref("Kubernetes client initialization failed: %s", err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
client, err := kubernetes.NewForConfig(cfg)
|
||||
clientSet, err := kubernetes.NewForConfig(cfg)
|
||||
if err != nil {
|
||||
logger.Failuref("Kubernetes client initialization failed: %s", err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
ver, err := client.Discovery().ServerVersion()
|
||||
kv, err := clientSet.Discovery().ServerVersion()
|
||||
if err != nil {
|
||||
logger.Failuref("Kubernetes API call failed: %s", err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
v, err := semver.ParseTolerant(ver.String())
|
||||
v, err := version.ParseVersion(kv.String())
|
||||
if err != nil {
|
||||
logger.Failuref("Kubernetes version can't be determined")
|
||||
return false
|
||||
}
|
||||
|
||||
rng, _ := semver.ParseRange(version)
|
||||
if !rng(v) {
|
||||
logger.Failuref("Kubernetes version must be %s", version)
|
||||
c, _ := semver.NewConstraint(constraint)
|
||||
if !c.Check(v) {
|
||||
logger.Failuref("Kubernetes version %s < %s", v.Original(), constraint)
|
||||
return false
|
||||
}
|
||||
|
||||
logger.Successf("Kubernetes %s %s", v.String(), version)
|
||||
logger.Successf("Kubernetes %s %s", v.String(), constraint)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -176,23 +206,34 @@ func componentsCheck() bool {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||
defer cancel()
|
||||
|
||||
statusChecker, err := NewStatusChecker(time.Second, 30*time.Second)
|
||||
kubeConfig, err := utils.KubeConfig(rootArgs.kubeconfig, rootArgs.kubecontext)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
statusChecker, err := status.NewStatusChecker(kubeConfig, time.Second, rootArgs.timeout, logger)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
ok := true
|
||||
deployments := append(checkArgs.components, checkArgs.extraComponents...)
|
||||
for _, deployment := range deployments {
|
||||
if err := statusChecker.Assess(deployment); err != nil {
|
||||
ok = false
|
||||
} else {
|
||||
logger.Successf("%s: healthy", deployment)
|
||||
}
|
||||
|
||||
kubectlArgs := []string{"-n", rootArgs.namespace, "get", "deployment", deployment, "-o", "jsonpath=\"{..image}\""}
|
||||
if output, err := utils.ExecKubectlCommand(ctx, utils.ModeCapture, rootArgs.kubeconfig, rootArgs.kubecontext, kubectlArgs...); err == nil {
|
||||
logger.Actionf(strings.TrimPrefix(strings.TrimSuffix(output, "\""), "\""))
|
||||
selector := client.MatchingLabels{"app.kubernetes.io/instance": rootArgs.namespace}
|
||||
var list v1.DeploymentList
|
||||
if err := kubeClient.List(ctx, &list, client.InNamespace(rootArgs.namespace), selector); err == nil {
|
||||
for _, d := range list.Items {
|
||||
if ref, err := buildComponentObjectRefs(d.Name); err == nil {
|
||||
if err := statusChecker.Assess(ref...); err != nil {
|
||||
ok = false
|
||||
}
|
||||
}
|
||||
for _, c := range d.Spec.Template.Spec.Containers {
|
||||
logger.Actionf(c.Image)
|
||||
}
|
||||
}
|
||||
}
|
||||
return ok
|
||||
|
||||
@@ -25,13 +25,9 @@ import (
|
||||
var completionFishCmd = &cobra.Command{
|
||||
Use: "fish",
|
||||
Short: "Generates fish completion scripts",
|
||||
Example: `To load completion run
|
||||
Example: `To configure your fish shell to load completions for each session write this script to your completions dir:
|
||||
|
||||
. <(flux completion fish)
|
||||
|
||||
To configure your fish shell to load completions for each session write this script to your completions dir:
|
||||
|
||||
flux completion fish > ~/.config/fish/completions/flux
|
||||
flux completion fish > ~/.config/fish/completions/flux.fish
|
||||
|
||||
See http://fishshell.com/docs/current/index.html#completion-own for more details
|
||||
`,
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/fluxcd/flux2/internal/flags"
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
"github.com/fluxcd/pkg/apis/meta"
|
||||
"github.com/fluxcd/pkg/runtime/transform"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
@@ -198,7 +199,7 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
||||
if valuesMap == nil {
|
||||
valuesMap = jsonMap
|
||||
} else {
|
||||
valuesMap = utils.MergeMaps(valuesMap, jsonMap)
|
||||
valuesMap = transform.MergeMaps(valuesMap, jsonMap)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import (
|
||||
)
|
||||
|
||||
var createImagePolicyCmd = &cobra.Command{
|
||||
Use: "policy <name>",
|
||||
Use: "policy [name]",
|
||||
Short: "Create or update an ImagePolicy object",
|
||||
Long: `The create image policy command generates an ImagePolicy resource.
|
||||
An ImagePolicy object calculates a "latest image" given an image
|
||||
@@ -40,6 +40,18 @@ repository and a policy, e.g., semver.
|
||||
|
||||
The image that sorts highest according to the policy is recorded in
|
||||
the status of the object.`,
|
||||
Example: ` # Create an ImagePolicy to select the latest stable release
|
||||
flux create image policy podinfo \
|
||||
--image-ref=podinfo \
|
||||
--select-semver=">=1.0.0"
|
||||
|
||||
# Create an ImagePolicy to select the latest main branch build tagged as "${GIT_BRANCH}-${GIT_SHA:0:7}-$(date +%s)"
|
||||
flux create image policy podinfo \
|
||||
--image-ref=podinfo \
|
||||
--select-numeric=asc \
|
||||
--filter-regex='^main-[a-f0-9]+-(?P<ts>[0-9]+)' \
|
||||
--filter-extract='$ts'
|
||||
`,
|
||||
RunE: createImagePolicyRun}
|
||||
|
||||
type imagePolicyFlags struct {
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
)
|
||||
|
||||
var createImageRepositoryCmd = &cobra.Command{
|
||||
Use: "repository <name>",
|
||||
Use: "repository [name]",
|
||||
Short: "Create or update an ImageRepository object",
|
||||
Long: `The create image repository command generates an ImageRepository resource.
|
||||
An ImageRepository object specifies an image repository to scan.`,
|
||||
|
||||
@@ -28,19 +28,38 @@ import (
|
||||
)
|
||||
|
||||
var createImageUpdateCmd = &cobra.Command{
|
||||
Use: "update <name>",
|
||||
Use: "update [name]",
|
||||
Short: "Create or update an ImageUpdateAutomation object",
|
||||
Long: `The create image update command generates an ImageUpdateAutomation resource.
|
||||
An ImageUpdateAutomation object specifies an automated update to images
|
||||
mentioned in YAMLs in a git repository.`,
|
||||
Example: ` # Configure image updates for the main repository created by flux bootstrap
|
||||
flux create image update flux-system \
|
||||
--git-repo-ref=flux-system \
|
||||
--git-repo-path="./clusters/my-cluster" \
|
||||
--checkout-branch=main \
|
||||
--author-name=flux \
|
||||
--author-email=flux@example.com \
|
||||
--commit-template="{{range .Updated.Images}}{{println .}}{{end}}"
|
||||
|
||||
# Configure image updates to push changes to a different branch, if the branch doesn't exists it will be created
|
||||
flux create image update flux-system \
|
||||
--git-repo-ref=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,
|
||||
}
|
||||
|
||||
type imageUpdateFlags struct {
|
||||
// git checkout spec
|
||||
gitRepoRef string
|
||||
branch string
|
||||
// commit spec
|
||||
gitRepoRef string
|
||||
gitRepoPath string
|
||||
checkoutBranch string
|
||||
pushBranch string
|
||||
commitTemplate string
|
||||
authorName string
|
||||
authorEmail string
|
||||
@@ -50,8 +69,10 @@ var imageUpdateArgs = imageUpdateFlags{}
|
||||
|
||||
func init() {
|
||||
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.branch, "branch", "", "the branch to checkout and push commits to")
|
||||
flags.StringVar(&imageUpdateArgs.gitRepoRef, "git-repo-ref", "", "the name of a GitRepository resource with details of the upstream Git repository")
|
||||
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.pushBranch, "push-branch", "", "the branch to push commits to, defaults to the checkout branch if not specified")
|
||||
flags.StringVar(&imageUpdateArgs.commitTemplate, "commit-template", "", "a template for commit messages")
|
||||
flags.StringVar(&imageUpdateArgs.authorName, "author-name", "", "the name to use for commit author")
|
||||
flags.StringVar(&imageUpdateArgs.authorEmail, "author-email", "", "the email to use for commit author")
|
||||
@@ -69,8 +90,16 @@ func createImageUpdateRun(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("a reference to a GitRepository is required (--git-repo-ref)")
|
||||
}
|
||||
|
||||
if imageUpdateArgs.branch == "" {
|
||||
return fmt.Errorf("the Git repository branch is required (--branch)")
|
||||
if imageUpdateArgs.checkoutBranch == "" {
|
||||
return fmt.Errorf("the Git repository branch is required (--checkout-branch)")
|
||||
}
|
||||
|
||||
if imageUpdateArgs.authorName == "" {
|
||||
return fmt.Errorf("the author name is required (--author-name)")
|
||||
}
|
||||
|
||||
if imageUpdateArgs.authorEmail == "" {
|
||||
return fmt.Errorf("the author email is required (--author-email)")
|
||||
}
|
||||
|
||||
labels, err := parseLabels()
|
||||
@@ -89,9 +118,11 @@ func createImageUpdateRun(cmd *cobra.Command, args []string) error {
|
||||
GitRepositoryRef: meta.LocalObjectReference{
|
||||
Name: imageUpdateArgs.gitRepoRef,
|
||||
},
|
||||
Branch: imageUpdateArgs.branch,
|
||||
Branch: imageUpdateArgs.checkoutBranch,
|
||||
},
|
||||
Interval: metav1.Duration{
|
||||
Duration: createArgs.interval,
|
||||
},
|
||||
Interval: metav1.Duration{Duration: createArgs.interval},
|
||||
Commit: autov1.CommitSpec{
|
||||
AuthorName: imageUpdateArgs.authorName,
|
||||
AuthorEmail: imageUpdateArgs.authorEmail,
|
||||
@@ -100,6 +131,19 @@ func createImageUpdateRun(cmd *cobra.Command, args []string) error {
|
||||
},
|
||||
}
|
||||
|
||||
if imageUpdateArgs.pushBranch != "" {
|
||||
update.Spec.Push = &autov1.PushSpec{
|
||||
Branch: imageUpdateArgs.pushBranch,
|
||||
}
|
||||
}
|
||||
|
||||
if imageUpdateArgs.gitRepoPath != "" {
|
||||
update.Spec.Update = &autov1.UpdateStrategy{
|
||||
Path: imageUpdateArgs.gitRepoPath,
|
||||
Strategy: autov1.UpdateStrategySetters,
|
||||
}
|
||||
}
|
||||
|
||||
if createArgs.export {
|
||||
return printExport(exportImageUpdate(&update))
|
||||
}
|
||||
@@ -19,6 +19,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -142,7 +143,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
|
||||
Interval: metav1.Duration{
|
||||
Duration: createArgs.interval,
|
||||
},
|
||||
Path: kustomizationArgs.path.String(),
|
||||
Path: filepath.ToSlash(kustomizationArgs.path.String()),
|
||||
Prune: kustomizationArgs.prune,
|
||||
SourceRef: kustomizev1.CrossNamespaceSourceReference{
|
||||
Kind: kustomizationArgs.source.Kind,
|
||||
|
||||
@@ -18,15 +18,12 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
var createSecretCmd = &cobra.Command{
|
||||
@@ -39,23 +36,6 @@ func init() {
|
||||
createCmd.AddCommand(createSecretCmd)
|
||||
}
|
||||
|
||||
func makeSecret(name string) (corev1.Secret, error) {
|
||||
secretLabels, err := parseLabels()
|
||||
if err != nil {
|
||||
return corev1.Secret{}, err
|
||||
}
|
||||
|
||||
return corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: rootArgs.namespace,
|
||||
Labels: secretLabels,
|
||||
},
|
||||
StringData: map[string]string{},
|
||||
Data: nil,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func upsertSecret(ctx context.Context, kubeClient client.Client, secret corev1.Secret) error {
|
||||
namespacedName := types.NamespacedName{
|
||||
Namespace: secret.GetNamespace(),
|
||||
@@ -81,19 +61,3 @@ func upsertSecret(ctx context.Context, kubeClient client.Client, secret corev1.S
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func exportSecret(secret corev1.Secret) error {
|
||||
secret.TypeMeta = metav1.TypeMeta{
|
||||
APIVersion: "v1",
|
||||
Kind: "Secret",
|
||||
}
|
||||
|
||||
data, err := yaml.Marshal(secret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println("---")
|
||||
fmt.Println(resourceToString(data))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -20,15 +20,15 @@ import (
|
||||
"context"
|
||||
"crypto/elliptic"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/flags"
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
"github.com/fluxcd/pkg/ssh"
|
||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||
)
|
||||
|
||||
var createSecretGitCmd = &cobra.Command{
|
||||
@@ -96,7 +96,7 @@ func init() {
|
||||
|
||||
func NewSecretGitFlags() secretGitFlags {
|
||||
return secretGitFlags{
|
||||
keyAlgorithm: "rsa",
|
||||
keyAlgorithm: flags.PublicKeyAlgorithm(sourcesecret.RSAPrivateKeyAlgorithm),
|
||||
rsaBits: 2048,
|
||||
ecdsaCurve: flags.ECDSACurve{Curve: elliptic.P384()},
|
||||
}
|
||||
@@ -107,11 +107,6 @@ func createSecretGitCmdRun(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("secret name is required")
|
||||
}
|
||||
name := args[0]
|
||||
secret, err := makeSecret(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if secretGitArgs.url == "" {
|
||||
return fmt.Errorf("url is required")
|
||||
}
|
||||
@@ -121,96 +116,63 @@ func createSecretGitCmdRun(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("git URL parse failed: %w", err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||
defer cancel()
|
||||
|
||||
switch u.Scheme {
|
||||
case "ssh":
|
||||
pair, err := generateKeyPair(ctx, secretGitArgs.keyAlgorithm, secretGitArgs.rsaBits, secretGitArgs.ecdsaCurve)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
hostKey, err := scanHostKey(ctx, u)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
secret.StringData = map[string]string{
|
||||
"identity": string(pair.PrivateKey),
|
||||
"identity.pub": string(pair.PublicKey),
|
||||
"known_hosts": string(hostKey),
|
||||
}
|
||||
|
||||
if !createArgs.export {
|
||||
logger.Generatef("deploy key: %s", string(pair.PublicKey))
|
||||
}
|
||||
case "http", "https":
|
||||
if secretGitArgs.username == "" || secretGitArgs.password == "" {
|
||||
return fmt.Errorf("for Git over HTTP/S the username and password are required")
|
||||
}
|
||||
|
||||
secret.StringData = map[string]string{
|
||||
"username": secretGitArgs.username,
|
||||
"password": secretGitArgs.password,
|
||||
}
|
||||
|
||||
if secretGitArgs.caFile != "" {
|
||||
ca, err := ioutil.ReadFile(secretGitArgs.caFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read CA file '%s': %w", secretGitArgs.caFile, err)
|
||||
}
|
||||
secret.StringData["caFile"] = string(ca)
|
||||
}
|
||||
|
||||
default:
|
||||
return fmt.Errorf("git URL scheme '%s' not supported, can be: ssh, http and https", u.Scheme)
|
||||
}
|
||||
|
||||
if createArgs.export {
|
||||
return exportSecret(secret)
|
||||
}
|
||||
|
||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
||||
labels, err := parseLabels()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := upsertSecret(ctx, kubeClient, secret); err != nil {
|
||||
opts := sourcesecret.Options{
|
||||
Name: name,
|
||||
Namespace: rootArgs.namespace,
|
||||
Labels: labels,
|
||||
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
||||
}
|
||||
switch u.Scheme {
|
||||
case "ssh":
|
||||
opts.SSHHostname = u.Host
|
||||
opts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(secretGitArgs.keyAlgorithm)
|
||||
opts.RSAKeyBits = int(secretGitArgs.rsaBits)
|
||||
opts.ECDSACurve = secretGitArgs.ecdsaCurve.Curve
|
||||
case "http", "https":
|
||||
if secretGitArgs.username == "" || secretGitArgs.password == "" {
|
||||
return fmt.Errorf("for Git over HTTP/S the username and password are required")
|
||||
}
|
||||
opts.Username = secretGitArgs.username
|
||||
opts.Password = secretGitArgs.password
|
||||
opts.CAFilePath = secretGitArgs.caFile
|
||||
default:
|
||||
return fmt.Errorf("git URL scheme '%s' not supported, can be: ssh, http and https", u.Scheme)
|
||||
}
|
||||
|
||||
secret, err := sourcesecret.Generate(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if createArgs.export {
|
||||
fmt.Println(secret.Content)
|
||||
return nil
|
||||
}
|
||||
|
||||
var s corev1.Secret
|
||||
if err := yaml.Unmarshal([]byte(secret.Content), &s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ppk, ok := s.StringData[sourcesecret.PublicKeySecretKey]; ok {
|
||||
logger.Generatef("deploy key: %s", ppk)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||
defer cancel()
|
||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := upsertSecret(ctx, kubeClient, s); err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Actionf("secret '%s' created in '%s' namespace", name, rootArgs.namespace)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func generateKeyPair(ctx context.Context, alg flags.PublicKeyAlgorithm, rsa flags.RSAKeyBits, ecdsa flags.ECDSACurve) (*ssh.KeyPair, error) {
|
||||
var keyGen ssh.KeyPairGenerator
|
||||
switch algorithm := alg.String(); algorithm {
|
||||
case "rsa":
|
||||
keyGen = ssh.NewRSAGenerator(int(rsa))
|
||||
case "ecdsa":
|
||||
keyGen = ssh.NewECDSAGenerator(ecdsa.Curve)
|
||||
case "ed25519":
|
||||
keyGen = ssh.NewEd25519Generator()
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported public key algorithm: %s", algorithm)
|
||||
}
|
||||
pair, err := keyGen.Generate()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("key pair generation failed, error: %w", err)
|
||||
}
|
||||
return pair, nil
|
||||
}
|
||||
|
||||
func scanHostKey(ctx context.Context, url *url.URL) ([]byte, error) {
|
||||
host := url.Host
|
||||
if url.Port() == "" {
|
||||
host = host + ":22"
|
||||
}
|
||||
hostKey, err := ssh.ScanHostKey(host, 30*time.Second)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("SSH key scan for host %s failed, error: %w", host, err)
|
||||
}
|
||||
return hostKey, nil
|
||||
}
|
||||
|
||||
@@ -21,8 +21,11 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||
)
|
||||
|
||||
var createSecretHelmCmd = &cobra.Command{
|
||||
@@ -30,8 +33,8 @@ var createSecretHelmCmd = &cobra.Command{
|
||||
Short: "Create or update a Kubernetes secret for Helm repository authentication",
|
||||
Long: `
|
||||
The create secret helm command generates a Kubernetes secret with basic authentication credentials.`,
|
||||
Example: ` # Create a Helm authentication secret on disk and encrypt it with Mozilla SOPS
|
||||
|
||||
Example: `
|
||||
# Create a Helm authentication secret on disk and encrypt it with Mozilla SOPS
|
||||
flux create secret helm repo-auth \
|
||||
--namespace=my-namespace \
|
||||
--username=my-username \
|
||||
@@ -72,36 +75,45 @@ func createSecretHelmCmdRun(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("secret name is required")
|
||||
}
|
||||
name := args[0]
|
||||
secret, err := makeSecret(name)
|
||||
|
||||
labels, err := parseLabels()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if secretHelmArgs.username != "" && secretHelmArgs.password != "" {
|
||||
secret.StringData["username"] = secretHelmArgs.username
|
||||
secret.StringData["password"] = secretHelmArgs.password
|
||||
opts := sourcesecret.Options{
|
||||
Name: name,
|
||||
Namespace: rootArgs.namespace,
|
||||
Labels: labels,
|
||||
Username: secretHelmArgs.username,
|
||||
Password: secretHelmArgs.password,
|
||||
CAFilePath: secretHelmArgs.caFile,
|
||||
CertFilePath: secretHelmArgs.certFile,
|
||||
KeyFilePath: secretHelmArgs.keyFile,
|
||||
}
|
||||
|
||||
if err = populateSecretTLS(&secret, secretHelmArgs.secretTLSFlags); err != nil {
|
||||
secret, err := sourcesecret.Generate(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if createArgs.export {
|
||||
return exportSecret(secret)
|
||||
fmt.Println(secret.Content)
|
||||
return nil
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||
defer cancel()
|
||||
|
||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := upsertSecret(ctx, kubeClient, secret); err != nil {
|
||||
var s corev1.Secret
|
||||
if err := yaml.Unmarshal([]byte(secret.Content), &s); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := upsertSecret(ctx, kubeClient, s); err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Actionf("secret '%s' created in '%s' namespace", name, rootArgs.namespace)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -19,13 +19,14 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||
)
|
||||
|
||||
var createSecretTLSCmd = &cobra.Command{
|
||||
@@ -68,61 +69,48 @@ func init() {
|
||||
createSecretCmd.AddCommand(createSecretTLSCmd)
|
||||
}
|
||||
|
||||
func populateSecretTLS(secret *corev1.Secret, args secretTLSFlags) error {
|
||||
if args.certFile != "" && args.keyFile != "" {
|
||||
cert, err := ioutil.ReadFile(args.certFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read repository cert file '%s': %w", args.certFile, err)
|
||||
}
|
||||
secret.StringData["certFile"] = string(cert)
|
||||
|
||||
key, err := ioutil.ReadFile(args.keyFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read repository key file '%s': %w", args.keyFile, err)
|
||||
}
|
||||
secret.StringData["keyFile"] = string(key)
|
||||
}
|
||||
|
||||
if args.caFile != "" {
|
||||
ca, err := ioutil.ReadFile(args.caFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read repository CA file '%s': %w", args.caFile, err)
|
||||
}
|
||||
secret.StringData["caFile"] = string(ca)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func createSecretTLSCmdRun(cmd *cobra.Command, args []string) error {
|
||||
if len(args) < 1 {
|
||||
return fmt.Errorf("secret name is required")
|
||||
}
|
||||
name := args[0]
|
||||
secret, err := makeSecret(name)
|
||||
|
||||
labels, err := parseLabels()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = populateSecretTLS(&secret, secretTLSArgs); err != nil {
|
||||
opts := sourcesecret.Options{
|
||||
Name: name,
|
||||
Namespace: rootArgs.namespace,
|
||||
Labels: labels,
|
||||
CAFilePath: secretTLSArgs.caFile,
|
||||
CertFilePath: secretTLSArgs.certFile,
|
||||
KeyFilePath: secretTLSArgs.keyFile,
|
||||
}
|
||||
secret, err := sourcesecret.Generate(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if createArgs.export {
|
||||
return exportSecret(secret)
|
||||
fmt.Println(secret.Content)
|
||||
return nil
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||
defer cancel()
|
||||
|
||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := upsertSecret(ctx, kubeClient, secret); err != nil {
|
||||
var s corev1.Secret
|
||||
if err := yaml.Unmarshal([]byte(secret.Content), &s); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := upsertSecret(ctx, kubeClient, s); err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Actionf("secret '%s' created in '%s' namespace", name, rootArgs.namespace)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"github.com/fluxcd/pkg/apis/meta"
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/spf13/cobra"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
@@ -33,12 +35,11 @@ import (
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
"github.com/fluxcd/pkg/apis/meta"
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/flags"
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||
)
|
||||
|
||||
type sourceGitFlags struct {
|
||||
@@ -121,7 +122,7 @@ func init() {
|
||||
|
||||
func newSourceGitFlags() sourceGitFlags {
|
||||
return sourceGitFlags{
|
||||
keyAlgorithm: "rsa",
|
||||
keyAlgorithm: flags.PublicKeyAlgorithm(sourcesecret.RSAPrivateKeyAlgorithm),
|
||||
keyRSABits: 2048,
|
||||
keyECDSACurve: flags.ECDSACurve{Curve: elliptic.P384()},
|
||||
}
|
||||
@@ -151,6 +152,9 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("git URL parse failed: %w", err)
|
||||
}
|
||||
if u.Scheme != "ssh" && u.Scheme != "http" && u.Scheme != "https" {
|
||||
return fmt.Errorf("git URL scheme '%s' not supported, can be: ssh, http and https", u.Scheme)
|
||||
}
|
||||
|
||||
sourceLabels, err := parseLabels()
|
||||
if err != nil {
|
||||
@@ -184,12 +188,13 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
||||
gitRepository.Spec.Reference.Branch = sourceGitArgs.branch
|
||||
}
|
||||
|
||||
if createArgs.export {
|
||||
if sourceGitArgs.secretRef != "" {
|
||||
gitRepository.Spec.SecretRef = &meta.LocalObjectReference{
|
||||
Name: sourceGitArgs.secretRef,
|
||||
}
|
||||
if sourceGitArgs.secretRef != "" {
|
||||
gitRepository.Spec.SecretRef = &meta.LocalObjectReference{
|
||||
Name: sourceGitArgs.secretRef,
|
||||
}
|
||||
}
|
||||
|
||||
if createArgs.export {
|
||||
return exportGit(gitRepository)
|
||||
}
|
||||
|
||||
@@ -201,91 +206,54 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
withAuth := false
|
||||
// TODO(hidde): move all auth prep to separate func?
|
||||
if sourceGitArgs.secretRef != "" {
|
||||
withAuth = true
|
||||
} else if u.Scheme == "ssh" {
|
||||
logger.Generatef("generating deploy key pair")
|
||||
pair, err := generateKeyPair(ctx, sourceGitArgs.keyAlgorithm, sourceGitArgs.keyRSABits, sourceGitArgs.keyECDSACurve)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Successf("deploy key: %s", pair.PublicKey)
|
||||
prompt := promptui.Prompt{
|
||||
Label: "Have you added the deploy key to your repository",
|
||||
IsConfirm: true,
|
||||
}
|
||||
if _, err := prompt.Run(); err != nil {
|
||||
return fmt.Errorf("aborting")
|
||||
}
|
||||
|
||||
logger.Actionf("collecting preferred public key from SSH server")
|
||||
hostKey, err := scanHostKey(ctx, u)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Successf("collected public key from SSH server:\n%s", hostKey)
|
||||
|
||||
logger.Actionf("applying secret with keys")
|
||||
secret := corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: rootArgs.namespace,
|
||||
Labels: sourceLabels,
|
||||
},
|
||||
StringData: map[string]string{
|
||||
"identity": string(pair.PrivateKey),
|
||||
"identity.pub": string(pair.PublicKey),
|
||||
"known_hosts": string(hostKey),
|
||||
},
|
||||
}
|
||||
if err := upsertSecret(ctx, kubeClient, secret); err != nil {
|
||||
return err
|
||||
}
|
||||
withAuth = true
|
||||
} else if sourceGitArgs.username != "" && sourceGitArgs.password != "" {
|
||||
logger.Actionf("applying secret with basic auth credentials")
|
||||
secret := corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: rootArgs.namespace,
|
||||
Labels: sourceLabels,
|
||||
},
|
||||
StringData: map[string]string{
|
||||
"username": sourceGitArgs.username,
|
||||
"password": sourceGitArgs.password,
|
||||
},
|
||||
}
|
||||
|
||||
if sourceGitArgs.caFile != "" {
|
||||
ca, err := ioutil.ReadFile(sourceGitArgs.caFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read CA file '%s': %w", sourceGitArgs.caFile, err)
|
||||
}
|
||||
secret.StringData["caFile"] = string(ca)
|
||||
}
|
||||
|
||||
if err := upsertSecret(ctx, kubeClient, secret); err != nil {
|
||||
return err
|
||||
}
|
||||
withAuth = true
|
||||
}
|
||||
|
||||
if withAuth {
|
||||
logger.Successf("authentication configured")
|
||||
}
|
||||
|
||||
logger.Generatef("generating GitRepository source")
|
||||
|
||||
if withAuth {
|
||||
secretName := name
|
||||
if sourceGitArgs.secretRef != "" {
|
||||
secretName = sourceGitArgs.secretRef
|
||||
if sourceGitArgs.secretRef == "" {
|
||||
secretOpts := sourcesecret.Options{
|
||||
Name: name,
|
||||
Namespace: rootArgs.namespace,
|
||||
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
||||
}
|
||||
gitRepository.Spec.SecretRef = &meta.LocalObjectReference{
|
||||
Name: secretName,
|
||||
switch u.Scheme {
|
||||
case "ssh":
|
||||
secretOpts.SSHHostname = u.Host
|
||||
secretOpts.PrivateKeyAlgorithm = sourcesecret.PrivateKeyAlgorithm(sourceGitArgs.keyAlgorithm)
|
||||
secretOpts.RSAKeyBits = int(sourceGitArgs.keyRSABits)
|
||||
secretOpts.ECDSACurve = sourceGitArgs.keyECDSACurve.Curve
|
||||
case "https":
|
||||
secretOpts.Username = sourceGitArgs.username
|
||||
secretOpts.Password = sourceGitArgs.password
|
||||
secretOpts.CAFilePath = sourceGitArgs.caFile
|
||||
}
|
||||
secret, err := sourcesecret.Generate(secretOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var s corev1.Secret
|
||||
if err = yaml.Unmarshal([]byte(secret.Content), &s); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(s.StringData) > 0 {
|
||||
if hk, ok := s.StringData[sourcesecret.KnownHostsSecretKey]; ok {
|
||||
logger.Successf("collected public key from SSH server:\n%s", hk)
|
||||
}
|
||||
if ppk, ok := s.StringData[sourcesecret.PublicKeySecretKey]; ok {
|
||||
logger.Generatef("deploy key: %s", ppk)
|
||||
prompt := promptui.Prompt{
|
||||
Label: "Have you added the deploy key to your repository",
|
||||
IsConfirm: true,
|
||||
}
|
||||
if _, err := prompt.Run(); err != nil {
|
||||
return fmt.Errorf("aborting")
|
||||
}
|
||||
}
|
||||
logger.Actionf("applying secret with repository credentials")
|
||||
if err := upsertSecret(ctx, kubeClient, s); err != nil {
|
||||
return err
|
||||
}
|
||||
gitRepository.Spec.SecretRef = &meta.LocalObjectReference{
|
||||
Name: s.Name,
|
||||
}
|
||||
logger.Successf("authentication configured")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,10 +32,12 @@ import (
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||
)
|
||||
|
||||
var createSourceHelmCmd = &cobra.Command{
|
||||
@@ -149,46 +151,27 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
||||
logger.Generatef("generating HelmRepository source")
|
||||
if sourceHelmArgs.secretRef == "" {
|
||||
secretName := fmt.Sprintf("helm-%s", name)
|
||||
|
||||
secret := corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: secretName,
|
||||
Namespace: rootArgs.namespace,
|
||||
Labels: sourceLabels,
|
||||
},
|
||||
StringData: map[string]string{},
|
||||
secretOpts := sourcesecret.Options{
|
||||
Name: secretName,
|
||||
Namespace: rootArgs.namespace,
|
||||
Username: sourceHelmArgs.username,
|
||||
Password: sourceHelmArgs.password,
|
||||
CertFilePath: sourceHelmArgs.certFile,
|
||||
KeyFilePath: sourceHelmArgs.keyFile,
|
||||
CAFilePath: sourceHelmArgs.caFile,
|
||||
ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile,
|
||||
}
|
||||
|
||||
if sourceHelmArgs.username != "" && sourceHelmArgs.password != "" {
|
||||
secret.StringData["username"] = sourceHelmArgs.username
|
||||
secret.StringData["password"] = sourceHelmArgs.password
|
||||
secret, err := sourcesecret.Generate(secretOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if sourceHelmArgs.certFile != "" && sourceHelmArgs.keyFile != "" {
|
||||
cert, err := ioutil.ReadFile(sourceHelmArgs.certFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read repository cert file '%s': %w", sourceHelmArgs.certFile, err)
|
||||
}
|
||||
secret.StringData["certFile"] = string(cert)
|
||||
|
||||
key, err := ioutil.ReadFile(sourceHelmArgs.keyFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read repository key file '%s': %w", sourceHelmArgs.keyFile, err)
|
||||
}
|
||||
secret.StringData["keyFile"] = string(key)
|
||||
var s corev1.Secret
|
||||
if err = yaml.Unmarshal([]byte(secret.Content), &s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if sourceHelmArgs.caFile != "" {
|
||||
ca, err := ioutil.ReadFile(sourceHelmArgs.caFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read repository CA file '%s': %w", sourceHelmArgs.caFile, err)
|
||||
}
|
||||
secret.StringData["caFile"] = string(ca)
|
||||
}
|
||||
|
||||
if len(secret.StringData) > 0 {
|
||||
if len(s.StringData) > 0 {
|
||||
logger.Actionf("applying secret with repository credentials")
|
||||
if err := upsertSecret(ctx, kubeClient, secret); err != nil {
|
||||
if err := upsertSecret(ctx, kubeClient, s); err != nil {
|
||||
return err
|
||||
}
|
||||
helmRepository.Spec.SecretRef = &meta.LocalObjectReference{
|
||||
|
||||
@@ -34,7 +34,7 @@ import (
|
||||
var exportSourceBucketCmd = &cobra.Command{
|
||||
Use: "bucket [name]",
|
||||
Short: "Export Bucket sources in YAML format",
|
||||
Long: "The export source git command exports on or all Bucket sources in YAML format.",
|
||||
Long: "The export source git command exports one or all Bucket sources in YAML format.",
|
||||
Example: ` # Export all Bucket sources
|
||||
flux export source bucket --all > sources.yaml
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import (
|
||||
var exportSourceGitCmd = &cobra.Command{
|
||||
Use: "git [name]",
|
||||
Short: "Export GitRepository sources in YAML format",
|
||||
Long: "The export source git command exports on or all GitRepository sources in YAML format.",
|
||||
Long: "The export source git command exports one or all GitRepository sources in YAML format.",
|
||||
Example: ` # Export all GitRepository sources
|
||||
flux export source git --all > sources.yaml
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import (
|
||||
var exportSourceHelmCmd = &cobra.Command{
|
||||
Use: "helm [name]",
|
||||
Short: "Export HelmRepository sources in YAML format",
|
||||
Long: "The export source git command exports on or all HelmRepository sources in YAML format.",
|
||||
Long: "The export source git command exports one or all HelmRepository sources in YAML format.",
|
||||
Example: ` # Export all HelmRepository sources
|
||||
flux export source helm --all > sources.yaml
|
||||
|
||||
|
||||
@@ -18,7 +18,9 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||
@@ -32,8 +34,8 @@ import (
|
||||
|
||||
var getCmd = &cobra.Command{
|
||||
Use: "get",
|
||||
Short: "Get sources and resources",
|
||||
Long: "The get sub-commands print the statuses of sources and resources.",
|
||||
Short: "Get the resources and their status",
|
||||
Long: "The get sub-commands print the statuses of Flux resources.",
|
||||
}
|
||||
|
||||
type GetFlags struct {
|
||||
@@ -50,7 +52,7 @@ func init() {
|
||||
|
||||
type summarisable interface {
|
||||
listAdapter
|
||||
summariseItem(i int, includeNamespace bool) []string
|
||||
summariseItem(i int, includeNamespace bool, includeKind bool) []string
|
||||
headers(includeNamespace bool) []string
|
||||
}
|
||||
|
||||
@@ -63,11 +65,17 @@ func statusAndMessage(conditions []metav1.Condition) (string, string) {
|
||||
return string(metav1.ConditionFalse), "waiting to be reconciled"
|
||||
}
|
||||
|
||||
func nameColumns(item named, includeNamespace bool) []string {
|
||||
if includeNamespace {
|
||||
return []string{item.GetNamespace(), item.GetName()}
|
||||
func nameColumns(item named, includeNamespace bool, includeKind bool) []string {
|
||||
name := item.GetName()
|
||||
if includeKind {
|
||||
name = fmt.Sprintf("%s/%s",
|
||||
strings.ToLower(item.GetObjectKind().GroupVersionKind().Kind),
|
||||
item.GetName())
|
||||
}
|
||||
return []string{item.GetName()}
|
||||
if includeNamespace {
|
||||
return []string{item.GetNamespace(), name}
|
||||
}
|
||||
return []string{name}
|
||||
}
|
||||
|
||||
var namespaceHeader = []string{"Namespace"}
|
||||
@@ -100,17 +108,25 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
getAll := cmd.Use == "all"
|
||||
|
||||
if get.list.len() == 0 {
|
||||
logger.Failuref("no %s objects found in %s namespace", get.kind, rootArgs.namespace)
|
||||
if !getAll {
|
||||
logger.Failuref("no %s objects found in %s namespace", get.kind, rootArgs.namespace)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
header := get.list.headers(getArgs.allNamespaces)
|
||||
var rows [][]string
|
||||
for i := 0; i < get.list.len(); i++ {
|
||||
row := get.list.summariseItem(i, getArgs.allNamespaces)
|
||||
row := get.list.summariseItem(i, getArgs.allNamespaces, getAll)
|
||||
rows = append(rows, row)
|
||||
}
|
||||
utils.PrintTable(os.Stdout, header, rows)
|
||||
|
||||
if getAll {
|
||||
fmt.Println()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -42,11 +42,11 @@ func init() {
|
||||
getCmd.AddCommand(getHelmReleaseCmd)
|
||||
}
|
||||
|
||||
func (a helmReleaseListAdapter) summariseItem(i int, includeNamespace bool) []string {
|
||||
func (a helmReleaseListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
|
||||
item := a.Items[i]
|
||||
revision := item.Status.LastAppliedRevision
|
||||
status, msg := statusAndMessage(item.Status.Conditions)
|
||||
return append(nameColumns(&item, includeNamespace),
|
||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
|
||||
}
|
||||
|
||||
|
||||
66
cmd/flux/get_image_all.go
Normal file
66
cmd/flux/get_image_all.go
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
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 (
|
||||
autov1 "github.com/fluxcd/image-automation-controller/api/v1alpha1"
|
||||
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1alpha1"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var getImageAllCmd = &cobra.Command{
|
||||
Use: "all",
|
||||
Short: "Get all image statuses",
|
||||
Long: "The get image sub-commands print the statuses of all image objects.",
|
||||
Example: ` # List all image objects in a namespace
|
||||
flux get images all --namespace=flux-system
|
||||
|
||||
# List all image objects in all namespaces
|
||||
flux get images all --all-namespaces
|
||||
`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c := getCommand{
|
||||
apiType: imageRepositoryType,
|
||||
list: imageRepositoryListAdapter{&imagev1.ImageRepositoryList{}},
|
||||
}
|
||||
if err := c.run(cmd, args); err != nil {
|
||||
logger.Failuref(err.Error())
|
||||
}
|
||||
|
||||
c = getCommand{
|
||||
apiType: imagePolicyType,
|
||||
list: &imagePolicyListAdapter{&imagev1.ImagePolicyList{}},
|
||||
}
|
||||
if err := c.run(cmd, args); err != nil {
|
||||
logger.Failuref(err.Error())
|
||||
}
|
||||
|
||||
c = getCommand{
|
||||
apiType: imageUpdateAutomationType,
|
||||
list: &imageUpdateAutomationListAdapter{&autov1.ImageUpdateAutomationList{}},
|
||||
}
|
||||
if err := c.run(cmd, args); err != nil {
|
||||
logger.Failuref(err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
getImageCmd.AddCommand(getImageAllCmd)
|
||||
}
|
||||
@@ -42,10 +42,10 @@ func init() {
|
||||
getImageCmd.AddCommand(getImagePolicyCmd)
|
||||
}
|
||||
|
||||
func (s imagePolicyListAdapter) summariseItem(i int, includeNamespace bool) []string {
|
||||
func (s imagePolicyListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
|
||||
item := s.Items[i]
|
||||
status, msg := statusAndMessage(item.Status.Conditions)
|
||||
return append(nameColumns(&item, includeNamespace), status, msg, item.Status.LatestImage)
|
||||
return append(nameColumns(&item, includeNamespace, includeKind), status, msg, item.Status.LatestImage)
|
||||
}
|
||||
|
||||
func (s imagePolicyListAdapter) headers(includeNamespace bool) []string {
|
||||
|
||||
@@ -46,14 +46,14 @@ func init() {
|
||||
getImageCmd.AddCommand(getImageRepositoryCmd)
|
||||
}
|
||||
|
||||
func (s imageRepositoryListAdapter) summariseItem(i int, includeNamespace bool) []string {
|
||||
func (s imageRepositoryListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
|
||||
item := s.Items[i]
|
||||
status, msg := statusAndMessage(item.Status.Conditions)
|
||||
var lastScan string
|
||||
if item.Status.LastScanResult != nil {
|
||||
lastScan = item.Status.LastScanResult.ScanTime.Time.Format(time.RFC3339)
|
||||
}
|
||||
return append(nameColumns(&item, includeNamespace),
|
||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||
status, msg, lastScan, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
|
||||
}
|
||||
|
||||
|
||||
@@ -46,14 +46,14 @@ func init() {
|
||||
getImageCmd.AddCommand(getImageUpdateCmd)
|
||||
}
|
||||
|
||||
func (s imageUpdateAutomationListAdapter) summariseItem(i int, includeNamespace bool) []string {
|
||||
func (s imageUpdateAutomationListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
|
||||
item := s.Items[i]
|
||||
status, msg := statusAndMessage(item.Status.Conditions)
|
||||
var lastRun string
|
||||
if item.Status.LastAutomationRunTime != nil {
|
||||
lastRun = item.Status.LastAutomationRunTime.Time.Format(time.RFC3339)
|
||||
}
|
||||
return append(nameColumns(&item, includeNamespace), status, msg, lastRun, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
|
||||
return append(nameColumns(&item, includeNamespace, includeKind), status, msg, lastRun, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
|
||||
}
|
||||
|
||||
func (s imageUpdateAutomationListAdapter) headers(includeNamespace bool) []string {
|
||||
@@ -42,11 +42,11 @@ func init() {
|
||||
getCmd.AddCommand(getKsCmd)
|
||||
}
|
||||
|
||||
func (a kustomizationListAdapter) summariseItem(i int, includeNamespace bool) []string {
|
||||
func (a kustomizationListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
|
||||
item := a.Items[i]
|
||||
revision := item.Status.LastAppliedRevision
|
||||
status, msg := statusAndMessage(item.Status.Conditions)
|
||||
return append(nameColumns(&item, includeNamespace),
|
||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ func getReceiverCmdRun(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
var rows [][]string
|
||||
for _, receiver := range list.Items {
|
||||
row := []string{}
|
||||
var row []string
|
||||
if c := apimeta.FindStatusCondition(receiver.Status.Conditions, meta.ReadyCondition); c != nil {
|
||||
row = []string{
|
||||
receiver.GetName(),
|
||||
|
||||
73
cmd/flux/get_source_all.go
Normal file
73
cmd/flux/get_source_all.go
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
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 (
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var getSourceAllCmd = &cobra.Command{
|
||||
Use: "all",
|
||||
Short: "Get all source statuses",
|
||||
Long: "The get sources all command print the statuses of all sources.",
|
||||
Example: ` # List all sources in a namespace
|
||||
flux get sources all --namespace=flux-system
|
||||
|
||||
# List all sources in all namespaces
|
||||
flux get sources all --all-namespaces
|
||||
`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c := getCommand{
|
||||
apiType: bucketType,
|
||||
list: &bucketListAdapter{&sourcev1.BucketList{}},
|
||||
}
|
||||
if err := c.run(cmd, args); err != nil {
|
||||
logger.Failuref(err.Error())
|
||||
}
|
||||
|
||||
c = getCommand{
|
||||
apiType: gitRepositoryType,
|
||||
list: &gitRepositoryListAdapter{&sourcev1.GitRepositoryList{}},
|
||||
}
|
||||
if err := c.run(cmd, args); err != nil {
|
||||
logger.Failuref(err.Error())
|
||||
}
|
||||
|
||||
c = getCommand{
|
||||
apiType: helmRepositoryType,
|
||||
list: &helmRepositoryListAdapter{&sourcev1.HelmRepositoryList{}},
|
||||
}
|
||||
if err := c.run(cmd, args); err != nil {
|
||||
logger.Failuref(err.Error())
|
||||
}
|
||||
|
||||
c = getCommand{
|
||||
apiType: helmChartType,
|
||||
list: &helmChartListAdapter{&sourcev1.HelmChartList{}},
|
||||
}
|
||||
if err := c.run(cmd, args); err != nil {
|
||||
logger.Failuref(err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
getSourceCmd.AddCommand(getSourceAllCmd)
|
||||
}
|
||||
@@ -44,14 +44,14 @@ func init() {
|
||||
getSourceCmd.AddCommand(getSourceBucketCmd)
|
||||
}
|
||||
|
||||
func (a *bucketListAdapter) summariseItem(i int, includeNamespace bool) []string {
|
||||
func (a *bucketListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
|
||||
item := a.Items[i]
|
||||
var revision string
|
||||
if item.GetArtifact() != nil {
|
||||
revision = item.GetArtifact().Revision
|
||||
}
|
||||
status, msg := statusAndMessage(item.Status.Conditions)
|
||||
return append(nameColumns(&item, includeNamespace),
|
||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
|
||||
}
|
||||
|
||||
|
||||
@@ -44,14 +44,14 @@ func init() {
|
||||
getSourceCmd.AddCommand(getSourceHelmChartCmd)
|
||||
}
|
||||
|
||||
func (a *helmChartListAdapter) summariseItem(i int, includeNamespace bool) []string {
|
||||
func (a *helmChartListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
|
||||
item := a.Items[i]
|
||||
var revision string
|
||||
if item.GetArtifact() != nil {
|
||||
revision = item.GetArtifact().Revision
|
||||
}
|
||||
status, msg := statusAndMessage(item.Status.Conditions)
|
||||
return append(nameColumns(&item, includeNamespace),
|
||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
|
||||
}
|
||||
|
||||
|
||||
@@ -44,14 +44,14 @@ func init() {
|
||||
getSourceCmd.AddCommand(getSourceGitCmd)
|
||||
}
|
||||
|
||||
func (a *gitRepositoryListAdapter) summariseItem(i int, includeNamespace bool) []string {
|
||||
func (a *gitRepositoryListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
|
||||
item := a.Items[i]
|
||||
var revision string
|
||||
if item.GetArtifact() != nil {
|
||||
revision = item.GetArtifact().Revision
|
||||
}
|
||||
status, msg := statusAndMessage(item.Status.Conditions)
|
||||
return append(nameColumns(&item, includeNamespace),
|
||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
|
||||
}
|
||||
|
||||
|
||||
@@ -44,14 +44,14 @@ func init() {
|
||||
getSourceCmd.AddCommand(getSourceHelmCmd)
|
||||
}
|
||||
|
||||
func (a *helmRepositoryListAdapter) summariseItem(i int, includeNamespace bool) []string {
|
||||
func (a *helmRepositoryListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
|
||||
item := a.Items[i]
|
||||
var revision string
|
||||
if item.GetArtifact() != nil {
|
||||
revision = item.GetArtifact().Revision
|
||||
}
|
||||
status, msg := statusAndMessage(item.Status.Conditions)
|
||||
return append(nameColumns(&item, includeNamespace),
|
||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"github.com/fluxcd/flux2/internal/flags"
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||
"github.com/fluxcd/flux2/pkg/status"
|
||||
)
|
||||
|
||||
var installCmd = &cobra.Command{
|
||||
@@ -55,102 +56,119 @@ If a previous version is installed, then an in-place upgrade will be performed.`
|
||||
RunE: installCmdRun,
|
||||
}
|
||||
|
||||
var (
|
||||
installExport bool
|
||||
installDryRun bool
|
||||
installManifestsPath string
|
||||
installVersion string
|
||||
installDefaultComponents []string
|
||||
installExtraComponents []string
|
||||
installRegistry string
|
||||
installImagePullSecret string
|
||||
installWatchAllNamespaces bool
|
||||
installNetworkPolicy bool
|
||||
installArch flags.Arch
|
||||
installLogLevel = flags.LogLevel(rootArgs.defaults.LogLevel)
|
||||
installClusterDomain string
|
||||
installTolerationKeys []string
|
||||
)
|
||||
type installFlags struct {
|
||||
export bool
|
||||
dryRun bool
|
||||
version string
|
||||
defaultComponents []string
|
||||
extraComponents []string
|
||||
registry string
|
||||
imagePullSecret string
|
||||
branch string
|
||||
watchAllNamespaces bool
|
||||
networkPolicy bool
|
||||
manifestsPath string
|
||||
arch flags.Arch
|
||||
logLevel flags.LogLevel
|
||||
tokenAuth bool
|
||||
clusterDomain string
|
||||
tolerationKeys []string
|
||||
}
|
||||
|
||||
var installArgs = NewInstallFlags()
|
||||
|
||||
func init() {
|
||||
installCmd.Flags().BoolVar(&installExport, "export", false,
|
||||
installCmd.Flags().BoolVar(&installArgs.export, "export", false,
|
||||
"write the install manifests to stdout and exit")
|
||||
installCmd.Flags().BoolVarP(&installDryRun, "dry-run", "", false,
|
||||
installCmd.Flags().BoolVarP(&installArgs.dryRun, "dry-run", "", false,
|
||||
"only print the object that would be applied")
|
||||
installCmd.Flags().StringVarP(&installVersion, "version", "v", rootArgs.defaults.Version,
|
||||
"toolkit version")
|
||||
installCmd.Flags().StringSliceVar(&installDefaultComponents, "components", rootArgs.defaults.Components,
|
||||
installCmd.Flags().StringVarP(&installArgs.version, "version", "v", "",
|
||||
"toolkit version, when specified the manifests are downloaded from https://github.com/fluxcd/flux2/releases")
|
||||
installCmd.Flags().StringSliceVar(&installArgs.defaultComponents, "components", rootArgs.defaults.Components,
|
||||
"list of components, accepts comma-separated values")
|
||||
installCmd.Flags().StringSliceVar(&installExtraComponents, "components-extra", nil,
|
||||
installCmd.Flags().StringSliceVar(&installArgs.extraComponents, "components-extra", nil,
|
||||
"list of components in addition to those supplied or defaulted, accepts comma-separated values")
|
||||
installCmd.Flags().StringVar(&installManifestsPath, "manifests", "", "path to the manifest directory")
|
||||
installCmd.Flags().StringVar(&installRegistry, "registry", rootArgs.defaults.Registry,
|
||||
installCmd.Flags().StringVar(&installArgs.manifestsPath, "manifests", "", "path to the manifest directory")
|
||||
installCmd.Flags().StringVar(&installArgs.registry, "registry", rootArgs.defaults.Registry,
|
||||
"container registry where the toolkit images are published")
|
||||
installCmd.Flags().StringVar(&installImagePullSecret, "image-pull-secret", "",
|
||||
installCmd.Flags().StringVar(&installArgs.imagePullSecret, "image-pull-secret", "",
|
||||
"Kubernetes secret name used for pulling the toolkit images from a private registry")
|
||||
installCmd.Flags().Var(&installArch, "arch", installArch.Description())
|
||||
installCmd.Flags().BoolVar(&installWatchAllNamespaces, "watch-all-namespaces", rootArgs.defaults.WatchAllNamespaces,
|
||||
installCmd.Flags().Var(&installArgs.arch, "arch", installArgs.arch.Description())
|
||||
installCmd.Flags().BoolVar(&installArgs.watchAllNamespaces, "watch-all-namespaces", rootArgs.defaults.WatchAllNamespaces,
|
||||
"watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed")
|
||||
installCmd.Flags().Var(&installLogLevel, "log-level", installLogLevel.Description())
|
||||
installCmd.Flags().BoolVar(&installNetworkPolicy, "network-policy", rootArgs.defaults.NetworkPolicy,
|
||||
installCmd.Flags().Var(&installArgs.logLevel, "log-level", installArgs.logLevel.Description())
|
||||
installCmd.Flags().BoolVar(&installArgs.networkPolicy, "network-policy", rootArgs.defaults.NetworkPolicy,
|
||||
"deny ingress access to the toolkit controllers from other namespaces using network policies")
|
||||
installCmd.Flags().StringVar(&installClusterDomain, "cluster-domain", rootArgs.defaults.ClusterDomain, "internal cluster domain")
|
||||
installCmd.Flags().StringSliceVar(&installTolerationKeys, "toleration-keys", nil,
|
||||
installCmd.Flags().StringVar(&installArgs.clusterDomain, "cluster-domain", rootArgs.defaults.ClusterDomain, "internal cluster domain")
|
||||
installCmd.Flags().StringSliceVar(&installArgs.tolerationKeys, "toleration-keys", nil,
|
||||
"list of toleration keys used to schedule the components pods onto nodes with matching taints")
|
||||
installCmd.Flags().MarkHidden("manifests")
|
||||
installCmd.Flags().MarkDeprecated("arch", "multi-arch container image is now available for AMD64, ARMv7 and ARM64")
|
||||
rootCmd.AddCommand(installCmd)
|
||||
}
|
||||
|
||||
func NewInstallFlags() installFlags {
|
||||
return installFlags{
|
||||
logLevel: flags.LogLevel(rootArgs.defaults.LogLevel),
|
||||
}
|
||||
}
|
||||
|
||||
func installCmdRun(cmd *cobra.Command, args []string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||
defer cancel()
|
||||
|
||||
components := append(installArgs.defaultComponents, installArgs.extraComponents...)
|
||||
err := utils.ValidateComponents(components)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ver, err := getVersion(installArgs.version); err != nil {
|
||||
return err
|
||||
} else {
|
||||
installArgs.version = ver
|
||||
}
|
||||
|
||||
if !installArgs.export {
|
||||
logger.Generatef("generating manifests")
|
||||
}
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", rootArgs.namespace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
if !installExport {
|
||||
logger.Generatef("generating manifests")
|
||||
}
|
||||
|
||||
components := append(installDefaultComponents, installExtraComponents...)
|
||||
|
||||
if err := utils.ValidateComponents(components); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if installVersion == install.MakeDefaultOptions().Version {
|
||||
installVersion, err = install.GetLatestVersion()
|
||||
if err != nil {
|
||||
manifestsBase := ""
|
||||
if isEmbeddedVersion(installArgs.version) {
|
||||
if err := writeEmbeddedManifests(tmpDir); err != nil {
|
||||
return err
|
||||
}
|
||||
manifestsBase = tmpDir
|
||||
}
|
||||
|
||||
opts := install.Options{
|
||||
BaseURL: installManifestsPath,
|
||||
Version: installVersion,
|
||||
BaseURL: installArgs.manifestsPath,
|
||||
Version: installArgs.version,
|
||||
Namespace: rootArgs.namespace,
|
||||
Components: components,
|
||||
Registry: installRegistry,
|
||||
ImagePullSecret: installImagePullSecret,
|
||||
WatchAllNamespaces: installWatchAllNamespaces,
|
||||
NetworkPolicy: installNetworkPolicy,
|
||||
LogLevel: installLogLevel.String(),
|
||||
Registry: installArgs.registry,
|
||||
ImagePullSecret: installArgs.imagePullSecret,
|
||||
WatchAllNamespaces: installArgs.watchAllNamespaces,
|
||||
NetworkPolicy: installArgs.networkPolicy,
|
||||
LogLevel: installArgs.logLevel.String(),
|
||||
NotificationController: rootArgs.defaults.NotificationController,
|
||||
ManifestFile: fmt.Sprintf("%s.yaml", rootArgs.namespace),
|
||||
Timeout: rootArgs.timeout,
|
||||
ClusterDomain: installClusterDomain,
|
||||
TolerationKeys: installTolerationKeys,
|
||||
ClusterDomain: installArgs.clusterDomain,
|
||||
TolerationKeys: installArgs.tolerationKeys,
|
||||
}
|
||||
|
||||
if installManifestsPath == "" {
|
||||
if installArgs.manifestsPath == "" {
|
||||
opts.BaseURL = install.MakeDefaultOptions().BaseURL
|
||||
}
|
||||
|
||||
manifest, err := install.Generate(opts)
|
||||
manifest, err := install.Generate(opts, manifestsBase)
|
||||
if err != nil {
|
||||
return fmt.Errorf("install failed: %w", err)
|
||||
}
|
||||
@@ -161,9 +179,9 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
||||
|
||||
if rootArgs.verbose {
|
||||
fmt.Print(manifest.Content)
|
||||
} else if installExport {
|
||||
} else if installArgs.export {
|
||||
fmt.Println("---")
|
||||
fmt.Println("# Flux version:", installVersion)
|
||||
fmt.Println("# Flux version:", installArgs.version)
|
||||
fmt.Println("# Components:", strings.Join(components, ","))
|
||||
fmt.Print(manifest.Content)
|
||||
fmt.Println("---")
|
||||
@@ -178,26 +196,33 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
kubectlArgs := []string{"apply", "-f", filepath.Join(tmpDir, manifest.Path)}
|
||||
if installDryRun {
|
||||
if installArgs.dryRun {
|
||||
kubectlArgs = append(kubectlArgs, "--dry-run=client")
|
||||
applyOutput = utils.ModeOS
|
||||
}
|
||||
if _, err := utils.ExecKubectlCommand(ctx, applyOutput, rootArgs.kubeconfig, rootArgs.kubecontext, kubectlArgs...); err != nil {
|
||||
return fmt.Errorf("install failed")
|
||||
return fmt.Errorf("install failed: %w", err)
|
||||
}
|
||||
|
||||
if installDryRun {
|
||||
if installArgs.dryRun {
|
||||
logger.Successf("install dry-run finished")
|
||||
return nil
|
||||
}
|
||||
|
||||
statusChecker, err := NewStatusChecker(time.Second, time.Minute)
|
||||
kubeConfig, err := utils.KubeConfig(rootArgs.kubeconfig, rootArgs.kubecontext)
|
||||
if err != nil {
|
||||
return fmt.Errorf("install failed: %w", err)
|
||||
}
|
||||
statusChecker, err := status.NewStatusChecker(kubeConfig, time.Second, rootArgs.timeout, logger)
|
||||
if err != nil {
|
||||
return fmt.Errorf("install failed: %w", err)
|
||||
}
|
||||
componentRefs, err := buildComponentObjectRefs(components...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("install failed: %w", err)
|
||||
}
|
||||
|
||||
logger.Waitingf("verifying installation")
|
||||
if err := statusChecker.Assess(components...); err != nil {
|
||||
if err := statusChecker.Assess(componentRefs...); err != nil {
|
||||
return fmt.Errorf("install failed")
|
||||
}
|
||||
|
||||
|
||||
261
cmd/flux/logs.go
Normal file
261
cmd/flux/logs.go
Normal file
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
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 (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/flags"
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
)
|
||||
|
||||
var logsCmd = &cobra.Command{
|
||||
Use: "logs",
|
||||
Short: "Display formatted logs for Flux components",
|
||||
Long: "The logs command displays formatted logs from various Flux components.",
|
||||
Example: ` # Print the reconciliation logs of all Flux custom resources in your cluster
|
||||
flux logs --all-namespaces
|
||||
|
||||
# Stream logs for a particular log level
|
||||
flux logs --follow --level=error --all-namespaces
|
||||
|
||||
# Filter logs by kind, name and namespace
|
||||
flux logs --kind=Kustomization --name=podinfo --namespace=default
|
||||
|
||||
# Print logs when Flux is installed in a different namespace than flux-system
|
||||
flux logs --flux-namespace=my-namespace
|
||||
`,
|
||||
RunE: logsCmdRun,
|
||||
}
|
||||
|
||||
type logsFlags struct {
|
||||
logLevel flags.LogLevel
|
||||
follow bool
|
||||
tail int64
|
||||
kind string
|
||||
name string
|
||||
fluxNamespace string
|
||||
allNamespaces bool
|
||||
}
|
||||
|
||||
var logsArgs = &logsFlags{
|
||||
tail: -1,
|
||||
}
|
||||
|
||||
func init() {
|
||||
logsCmd.Flags().Var(&logsArgs.logLevel, "level", logsArgs.logLevel.Description())
|
||||
logsCmd.Flags().StringVarP(&logsArgs.kind, "kind", "", logsArgs.kind, "displays errors of a particular toolkit kind e.g GitRepository")
|
||||
logsCmd.Flags().StringVarP(&logsArgs.name, "name", "", logsArgs.name, "specifies the name of the object logs to be displayed")
|
||||
logsCmd.Flags().BoolVarP(&logsArgs.follow, "follow", "f", logsArgs.follow, "specifies if the logs should be streamed")
|
||||
logsCmd.Flags().Int64VarP(&logsArgs.tail, "tail", "", logsArgs.tail, "lines of recent log file to display")
|
||||
logsCmd.Flags().StringVarP(&logsArgs.fluxNamespace, "flux-namespace", "", rootArgs.defaults.Namespace, "the namespace where the Flux components are running")
|
||||
logsCmd.Flags().BoolVarP(&logsArgs.allNamespaces, "all-namespaces", "A", false, "displays logs for objects across all namespaces")
|
||||
rootCmd.AddCommand(logsCmd)
|
||||
}
|
||||
|
||||
func logsCmdRun(cmd *cobra.Command, args []string) error {
|
||||
fluxSelector := fmt.Sprintf("app.kubernetes.io/instance=%s", logsArgs.fluxNamespace)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||
defer cancel()
|
||||
|
||||
var pods []corev1.Pod
|
||||
cfg, err := utils.KubeConfig(rootArgs.kubeconfig, rootArgs.kubecontext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clientset, err := kubernetes.NewForConfig(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
return fmt.Errorf("no argument required")
|
||||
}
|
||||
|
||||
pods, err = getPods(ctx, clientset, fluxSelector)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logOpts := &corev1.PodLogOptions{
|
||||
Follow: logsArgs.follow,
|
||||
}
|
||||
|
||||
if logsArgs.tail > -1 {
|
||||
logOpts.TailLines = &logsArgs.tail
|
||||
}
|
||||
|
||||
var requests []rest.ResponseWrapper
|
||||
for _, pod := range pods {
|
||||
req := clientset.CoreV1().Pods(logsArgs.fluxNamespace).GetLogs(pod.Name, logOpts)
|
||||
requests = append(requests, req)
|
||||
}
|
||||
|
||||
if logsArgs.follow && len(requests) > 1 {
|
||||
return parallelPodLogs(ctx, requests)
|
||||
}
|
||||
|
||||
return podLogs(ctx, requests)
|
||||
}
|
||||
|
||||
func getPods(ctx context.Context, c *kubernetes.Clientset, label string) ([]corev1.Pod, error) {
|
||||
var ret []corev1.Pod
|
||||
|
||||
opts := metav1.ListOptions{
|
||||
LabelSelector: label,
|
||||
}
|
||||
deployList, err := c.AppsV1().Deployments(logsArgs.fluxNamespace).List(ctx, opts)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
for _, deploy := range deployList.Items {
|
||||
label := deploy.Spec.Template.Labels
|
||||
opts := metav1.ListOptions{
|
||||
LabelSelector: createLabelStringFromMap(label),
|
||||
}
|
||||
podList, err := c.CoreV1().Pods(logsArgs.fluxNamespace).List(ctx, opts)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
ret = append(ret, podList.Items...)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func parallelPodLogs(ctx context.Context, requests []rest.ResponseWrapper) error {
|
||||
reader, writer := io.Pipe()
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(len(requests))
|
||||
|
||||
var mutex = &sync.Mutex{}
|
||||
|
||||
for _, request := range requests {
|
||||
go func(req rest.ResponseWrapper) {
|
||||
defer wg.Done()
|
||||
if err := logRequest(mutex, ctx, req, os.Stdout); err != nil {
|
||||
writer.CloseWithError(err)
|
||||
return
|
||||
}
|
||||
}(request)
|
||||
}
|
||||
|
||||
go func() {
|
||||
wg.Wait()
|
||||
writer.Close()
|
||||
}()
|
||||
|
||||
_, err := io.Copy(os.Stdout, reader)
|
||||
return err
|
||||
}
|
||||
|
||||
func podLogs(ctx context.Context, requests []rest.ResponseWrapper) error {
|
||||
mutex := &sync.Mutex{}
|
||||
for _, req := range requests {
|
||||
if err := logRequest(mutex, ctx, req, os.Stdout); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func createLabelStringFromMap(m map[string]string) string {
|
||||
var strArr []string
|
||||
for key, val := range m {
|
||||
pair := fmt.Sprintf("%v=%v", key, val)
|
||||
strArr = append(strArr, pair)
|
||||
}
|
||||
|
||||
return strings.Join(strArr, ",")
|
||||
}
|
||||
|
||||
func logRequest(mu *sync.Mutex, ctx context.Context, request rest.ResponseWrapper, w io.Writer) error {
|
||||
stream, err := request.Stream(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer stream.Close()
|
||||
|
||||
scanner := bufio.NewScanner(stream)
|
||||
|
||||
const logTmpl = "{{.Timestamp}} {{.Level}} {{.Kind}}{{if .Name}}/{{.Name}}.{{.Namespace}}{{end}} - {{.Message}} {{.Error}}\n"
|
||||
t, err := template.New("log").Parse(logTmpl)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create template, err: %s", err)
|
||||
}
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if !strings.HasPrefix(line, "{") {
|
||||
continue
|
||||
}
|
||||
var l ControllerLogEntry
|
||||
if err := json.Unmarshal([]byte(line), &l); err != nil {
|
||||
logger.Failuref("parse error: %s", err)
|
||||
break
|
||||
}
|
||||
|
||||
mu.Lock()
|
||||
filterPrintLog(t, &l)
|
||||
mu.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func filterPrintLog(t *template.Template, l *ControllerLogEntry) {
|
||||
if logsArgs.logLevel != "" && logsArgs.logLevel != l.Level ||
|
||||
logsArgs.kind != "" && strings.ToLower(logsArgs.kind) != strings.ToLower(l.Kind) ||
|
||||
logsArgs.name != "" && strings.ToLower(logsArgs.name) != strings.ToLower(l.Name) ||
|
||||
!logsArgs.allNamespaces && strings.ToLower(rootArgs.namespace) != strings.ToLower(l.Namespace) {
|
||||
return
|
||||
}
|
||||
|
||||
err := t.Execute(os.Stdout, l)
|
||||
if err != nil {
|
||||
logger.Failuref("log template error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
type ControllerLogEntry struct {
|
||||
Timestamp string `json:"ts"`
|
||||
Level flags.LogLevel `json:"level"`
|
||||
Message string `json:"msg"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Logger string `json:"logger"`
|
||||
Kind string `json:"reconciler kind,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Namespace string `json:"namespace,omitempty"`
|
||||
}
|
||||
@@ -115,10 +115,12 @@ func init() {
|
||||
}
|
||||
|
||||
func NewRootFlags() rootFlags {
|
||||
return rootFlags{
|
||||
rf := rootFlags{
|
||||
pollInterval: 2 * time.Second,
|
||||
defaults: install.MakeDefaultOptions(),
|
||||
}
|
||||
rf.defaults.Version = "v" + VERSION
|
||||
return rf
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
31
cmd/flux/manifests.embed.go
Normal file
31
cmd/flux/manifests.embed.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
//go:embed manifests/*.yaml
|
||||
var embeddedManifests embed.FS
|
||||
|
||||
func writeEmbeddedManifests(dir string) error {
|
||||
manifests, err := fs.ReadDir(embeddedManifests, "manifests")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, manifest := range manifests {
|
||||
data, err := fs.ReadFile(embeddedManifests, path.Join("manifests", manifest.Name()))
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading file failed: %w", err)
|
||||
}
|
||||
|
||||
err = os.WriteFile(path.Join(dir, manifest.Name()), data, 0666)
|
||||
if err != nil {
|
||||
return fmt.Errorf("writing file failed: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package main
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
@@ -62,6 +63,7 @@ func (c universalAdapter) asClientObject() client.Object {
|
||||
type named interface {
|
||||
GetName() string
|
||||
GetNamespace() string
|
||||
GetObjectKind() schema.ObjectKind
|
||||
SetName(string)
|
||||
SetNamespace(string)
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func (a helmChartAdapter) asClientObject() client.Object {
|
||||
return a.HelmChart
|
||||
}
|
||||
|
||||
// sourcev1.ImagePolicyList
|
||||
// sourcev1.HelmChartList
|
||||
|
||||
type helmChartListAdapter struct {
|
||||
*sourcev1.HelmChartList
|
||||
|
||||
@@ -19,24 +19,15 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"sigs.k8s.io/cli-utils/pkg/kstatus/polling"
|
||||
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/aggregator"
|
||||
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/collector"
|
||||
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/event"
|
||||
"sigs.k8s.io/cli-utils/pkg/kstatus/status"
|
||||
"sigs.k8s.io/cli-utils/pkg/object"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
"github.com/fluxcd/pkg/apis/meta"
|
||||
)
|
||||
|
||||
@@ -50,13 +41,6 @@ type statusable interface {
|
||||
GetStatusConditions() *[]metav1.Condition
|
||||
}
|
||||
|
||||
type StatusChecker struct {
|
||||
pollInterval time.Duration
|
||||
timeout time.Duration
|
||||
client client.Client
|
||||
statusPoller *polling.StatusPoller
|
||||
}
|
||||
|
||||
func isReady(ctx context.Context, kubeClient client.Client,
|
||||
namespacedName types.NamespacedName, object statusable) wait.ConditionFunc {
|
||||
return func() (bool, error) {
|
||||
@@ -82,74 +66,7 @@ func isReady(ctx context.Context, kubeClient client.Client,
|
||||
}
|
||||
}
|
||||
|
||||
func NewStatusChecker(pollInterval time.Duration, timeout time.Duration) (*StatusChecker, error) {
|
||||
kubeConfig, err := utils.KubeConfig(rootArgs.kubeconfig, rootArgs.kubecontext)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
restMapper, err := apiutil.NewDynamicRESTMapper(kubeConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client, err := client.New(kubeConfig, client.Options{Mapper: restMapper})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &StatusChecker{
|
||||
pollInterval: pollInterval,
|
||||
timeout: timeout,
|
||||
client: client,
|
||||
statusPoller: polling.NewStatusPoller(client, restMapper),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (sc *StatusChecker) Assess(components ...string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), sc.timeout)
|
||||
defer cancel()
|
||||
|
||||
objRefs, err := sc.getObjectRefs(components)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
opts := polling.Options{PollInterval: sc.pollInterval, UseCache: true}
|
||||
eventsChan := sc.statusPoller.Poll(ctx, objRefs, opts)
|
||||
|
||||
coll := collector.NewResourceStatusCollector(objRefs)
|
||||
done := coll.ListenWithObserver(eventsChan, collector.ObserverFunc(
|
||||
func(statusCollector *collector.ResourceStatusCollector, e event.Event) {
|
||||
var rss []*event.ResourceStatus
|
||||
for _, rs := range statusCollector.ResourceStatuses {
|
||||
rss = append(rss, rs)
|
||||
}
|
||||
desired := status.CurrentStatus
|
||||
aggStatus := aggregator.AggregateStatus(rss, desired)
|
||||
if aggStatus == desired {
|
||||
cancel()
|
||||
return
|
||||
}
|
||||
}),
|
||||
)
|
||||
<-done
|
||||
|
||||
if coll.Error != nil || ctx.Err() == context.DeadlineExceeded {
|
||||
for _, rs := range coll.ResourceStatuses {
|
||||
if rs.Status != status.CurrentStatus {
|
||||
if !sc.deploymentExists(rs.Identifier) {
|
||||
logger.Failuref("%s: deployment not found", rs.Identifier.Name)
|
||||
} else {
|
||||
logger.Failuref("%s: unhealthy (timed out waiting for rollout)", rs.Identifier.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("timed out waiting for condition")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sc *StatusChecker) getObjectRefs(components []string) ([]object.ObjMetadata, error) {
|
||||
func buildComponentObjectRefs(components ...string) ([]object.ObjMetadata, error) {
|
||||
var objRefs []object.ObjMetadata
|
||||
for _, deployment := range components {
|
||||
objMeta, err := object.CreateObjMetadata(rootArgs.namespace, deployment, schema.GroupKind{Group: "apps", Kind: "Deployment"})
|
||||
@@ -160,20 +77,3 @@ func (sc *StatusChecker) getObjectRefs(components []string) ([]object.ObjMetadat
|
||||
}
|
||||
return objRefs, nil
|
||||
}
|
||||
|
||||
func (sc *StatusChecker) objMetadataToString(om object.ObjMetadata) string {
|
||||
return fmt.Sprintf("%s '%s/%s'", om.GroupKind.Kind, om.Namespace, om.Name)
|
||||
}
|
||||
|
||||
func (sc *StatusChecker) deploymentExists(om object.ObjMetadata) bool {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), sc.timeout)
|
||||
defer cancel()
|
||||
|
||||
namespacedName := types.NamespacedName{
|
||||
Namespace: om.Namespace,
|
||||
Name: om.Name,
|
||||
}
|
||||
var existing appsv1.Deployment
|
||||
err := sc.client.Get(ctx, namespacedName, &existing)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
42
cmd/flux/version.go
Normal file
42
cmd/flux/version.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||
)
|
||||
|
||||
func getVersion(input string) (string, error) {
|
||||
if input == "" {
|
||||
return rootArgs.defaults.Version, nil
|
||||
}
|
||||
|
||||
if isEmbeddedVersion(input) {
|
||||
return input, nil
|
||||
}
|
||||
|
||||
var err error
|
||||
if input == install.MakeDefaultOptions().Version {
|
||||
input, err = install.GetLatestVersion()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
} else {
|
||||
if ok, err := install.ExistingVersion(input); err != nil || !ok {
|
||||
if err == nil {
|
||||
err = fmt.Errorf("targeted version '%s' does not exist", input)
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
if !utils.CompatibleVersion(VERSION, input) {
|
||||
return "", fmt.Errorf("targeted version '%s' is not compatible with your current version of flux (%s)", input, VERSION)
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func isEmbeddedVersion(input string) bool {
|
||||
return input == rootArgs.defaults.Version
|
||||
}
|
||||
BIN
docs/_files/image-update-automation.png
Normal file
BIN
docs/_files/image-update-automation.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
27
docs/_static/custom.css
vendored
27
docs/_static/custom.css
vendored
@@ -94,4 +94,29 @@ body {
|
||||
|
||||
.progress-0plus .progress-bar {
|
||||
background-color: #ff1744;
|
||||
}
|
||||
}
|
||||
|
||||
/* Custom admonitions */
|
||||
/* See https://squidfunk.github.io/mkdocs-material/reference/admonitions */
|
||||
:root {
|
||||
--md-admonition-icon--heart: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M14 20.408c-.492.308-.903.546-1.192.709-.153.086-.308.17-.463.252h-.002a.75.75 0 0 1-.686 0 16.709 16.709 0 0 1-.465-.252 31.147 31.147 0 0 1-4.803-3.34C3.8 15.572 1 12.331 1 8.513 1 5.052 3.829 2.5 6.736 2.5 9.03 2.5 10.881 3.726 12 5.605 13.12 3.726 14.97 2.5 17.264 2.5 20.17 2.5 23 5.052 23 8.514c0 3.818-2.801 7.06-5.389 9.262A31.146 31.146 0 0 1 14 20.408z"/></svg>')
|
||||
}
|
||||
.md-typeset .admonition.heart,
|
||||
.md-typeset details.heart {
|
||||
border-color: rgb(233, 30, 99);
|
||||
}
|
||||
.md-typeset .heart > .admonition-title,
|
||||
.md-typeset .heart > summary {
|
||||
background-color: rgba(233, 30, 99, 0.1);
|
||||
}
|
||||
.md-typeset .heart > .admonition-title::before,
|
||||
.md-typeset .heart > summary::before {
|
||||
background-color: rgb(233, 30, 99);
|
||||
-webkit-mask-image: var(--md-admonition-icon--heart);
|
||||
mask-image: var(--md-admonition-icon--heart);
|
||||
}
|
||||
|
||||
.timetable-explicit-col-widths th:nth-child(1) { width: 4%; }
|
||||
.timetable-explicit-col-widths th:nth-child(2) { width: 32%; }
|
||||
.timetable-explicit-col-widths th:nth-child(3) { width: 32%; }
|
||||
.timetable-explicit-col-widths th:nth-child(4) { width: 32%; }
|
||||
|
||||
@@ -83,8 +83,9 @@ Command line utility for assembling Kubernetes CD pipelines the GitOps way.
|
||||
* [flux create](flux_create.md) - Create or update sources and resources
|
||||
* [flux delete](flux_delete.md) - Delete sources and resources
|
||||
* [flux export](flux_export.md) - Export resources in YAML format
|
||||
* [flux get](flux_get.md) - Get sources and resources
|
||||
* [flux get](flux_get.md) - Get the resources and their status
|
||||
* [flux install](flux_install.md) - Install or upgrade Flux
|
||||
* [flux logs](flux_logs.md) - Display formatted logs for Flux components
|
||||
* [flux reconcile](flux_reconcile.md) - Reconcile sources and resources
|
||||
* [flux resume](flux_resume.md) - Resume suspended resources
|
||||
* [flux suspend](flux_suspend.md) - Suspend resources
|
||||
|
||||
@@ -20,7 +20,7 @@ The bootstrap sub-commands bootstrap the toolkit components on the targeted Git
|
||||
--registry string container registry where the toolkit images are published (default "ghcr.io/fluxcd")
|
||||
--token-auth when enabled, the personal access token will be used instead of SSH deploy key
|
||||
--toleration-keys strings list of toleration keys used to schedule the components pods onto nodes with matching taints
|
||||
-v, --version string toolkit version (default "latest")
|
||||
-v, --version string toolkit version, when specified the manifests are downloaded from https://github.com/fluxcd/flux2/releases
|
||||
--watch-all-namespaces watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed (default true)
|
||||
```
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ flux bootstrap github [flags]
|
||||
--token-auth when enabled, the personal access token will be used instead of SSH deploy key
|
||||
--toleration-keys strings list of toleration keys used to schedule the components pods onto nodes with matching taints
|
||||
--verbose print generated objects
|
||||
-v, --version string toolkit version (default "latest")
|
||||
-v, --version string toolkit version, when specified the manifests are downloaded from https://github.com/fluxcd/flux2/releases
|
||||
--watch-all-namespaces watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed (default true)
|
||||
```
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ flux bootstrap gitlab [flags]
|
||||
--token-auth when enabled, the personal access token will be used instead of SSH deploy key
|
||||
--toleration-keys strings list of toleration keys used to schedule the components pods onto nodes with matching taints
|
||||
--verbose print generated objects
|
||||
-v, --version string toolkit version (default "latest")
|
||||
-v, --version string toolkit version, when specified the manifests are downloaded from https://github.com/fluxcd/flux2/releases
|
||||
--watch-all-namespaces watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed (default true)
|
||||
```
|
||||
|
||||
|
||||
@@ -9,13 +9,9 @@ flux completion fish [flags]
|
||||
### Examples
|
||||
|
||||
```
|
||||
To load completion run
|
||||
|
||||
. <(flux completion fish)
|
||||
|
||||
To configure your fish shell to load completions for each session write this script to your completions dir:
|
||||
|
||||
flux completion fish > ~/.config/fish/completions/flux
|
||||
flux completion fish > ~/.config/fish/completions/flux.fish
|
||||
|
||||
See http://fishshell.com/docs/current/index.html#completion-own for more details
|
||||
|
||||
|
||||
@@ -12,7 +12,24 @@ The image that sorts highest according to the policy is recorded in
|
||||
the status of the object.
|
||||
|
||||
```
|
||||
flux create image policy <name> [flags]
|
||||
flux create image policy [name] [flags]
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
```
|
||||
# Create an ImagePolicy to select the latest stable release
|
||||
flux create image policy podinfo \
|
||||
--image-ref=podinfo \
|
||||
--select-semver=">=1.0.0"
|
||||
|
||||
# Create an ImagePolicy to select the latest main branch build tagged as "${GIT_BRANCH}-${GIT_SHA:0:7}-$(date +%s)"
|
||||
flux create image policy podinfo \
|
||||
--image-ref=podinfo \
|
||||
--select-numeric=asc \
|
||||
--filter-regex='^main-[a-f0-9]+-(?P<ts>[0-9]+)' \
|
||||
--filter-extract='$ts'
|
||||
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
@@ -8,7 +8,7 @@ The create image repository command generates an ImageRepository resource.
|
||||
An ImageRepository object specifies an image repository to scan.
|
||||
|
||||
```
|
||||
flux create image repository <name> [flags]
|
||||
flux create image repository [name] [flags]
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
@@ -9,7 +9,31 @@ An ImageUpdateAutomation object specifies an automated update to images
|
||||
mentioned in YAMLs in a git repository.
|
||||
|
||||
```
|
||||
flux create image update <name> [flags]
|
||||
flux create image update [name] [flags]
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
```
|
||||
# Configure image updates for the main repository created by flux bootstrap
|
||||
flux create image update flux-system \
|
||||
--git-repo-ref=flux-system \
|
||||
--git-repo-path="./clusters/my-cluster" \
|
||||
--checkout-branch=main \
|
||||
--author-name=flux \
|
||||
--author-email=flux@example.com \
|
||||
--commit-template="{{range .Updated.Images}}{{println .}}{{end}}"
|
||||
|
||||
# Configure image updates to push changes to a different branch, if the branch doesn't exists it will be created
|
||||
flux create image update flux-system \
|
||||
--git-repo-ref=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}}"
|
||||
|
||||
```
|
||||
|
||||
### Options
|
||||
@@ -17,10 +41,12 @@ flux create image update <name> [flags]
|
||||
```
|
||||
--author-email string the email to use for commit author
|
||||
--author-name string the name to use for commit author
|
||||
--branch string the branch to checkout and push commits to
|
||||
--checkout-branch string the branch to checkout
|
||||
--commit-template string a template for commit messages
|
||||
--git-repo-ref string the name of a GitRepository resource with details of the upstream git repository
|
||||
--git-repo-path string path to the directory containing the manifests to be updated, defaults to the repository root
|
||||
--git-repo-ref string the name of a GitRepository resource with details of the upstream Git repository
|
||||
-h, --help help for update
|
||||
--push-branch string the branch to push commits to, defaults to the checkout branch if not specified
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
||||
@@ -14,8 +14,8 @@ flux create secret helm [name] [flags]
|
||||
### Examples
|
||||
|
||||
```
|
||||
# Create a Helm authentication secret on disk and encrypt it with Mozilla SOPS
|
||||
|
||||
# Create a Helm authentication secret on disk and encrypt it with Mozilla SOPS
|
||||
flux create secret helm repo-auth \
|
||||
--namespace=my-namespace \
|
||||
--username=my-username \
|
||||
|
||||
@@ -4,7 +4,7 @@ Export Bucket sources in YAML format
|
||||
|
||||
### Synopsis
|
||||
|
||||
The export source git command exports on or all Bucket sources in YAML format.
|
||||
The export source git command exports one or all Bucket sources in YAML format.
|
||||
|
||||
```
|
||||
flux export source bucket [name] [flags]
|
||||
|
||||
@@ -4,7 +4,7 @@ Export GitRepository sources in YAML format
|
||||
|
||||
### Synopsis
|
||||
|
||||
The export source git command exports on or all GitRepository sources in YAML format.
|
||||
The export source git command exports one or all GitRepository sources in YAML format.
|
||||
|
||||
```
|
||||
flux export source git [name] [flags]
|
||||
|
||||
@@ -4,7 +4,7 @@ Export HelmRepository sources in YAML format
|
||||
|
||||
### Synopsis
|
||||
|
||||
The export source git command exports on or all HelmRepository sources in YAML format.
|
||||
The export source git command exports one or all HelmRepository sources in YAML format.
|
||||
|
||||
```
|
||||
flux export source helm [name] [flags]
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
## flux get
|
||||
|
||||
Get sources and resources
|
||||
Get the resources and their status
|
||||
|
||||
### Synopsis
|
||||
|
||||
The get sub-commands print the statuses of sources and resources.
|
||||
The get sub-commands print the statuses of Flux resources.
|
||||
|
||||
### Options
|
||||
|
||||
|
||||
@@ -37,5 +37,5 @@ flux get alert-providers [flags]
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [flux get](flux_get.md) - Get sources and resources
|
||||
* [flux get](flux_get.md) - Get the resources and their status
|
||||
|
||||
|
||||
@@ -37,5 +37,5 @@ flux get alerts [flags]
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [flux get](flux_get.md) - Get sources and resources
|
||||
* [flux get](flux_get.md) - Get the resources and their status
|
||||
|
||||
|
||||
@@ -37,5 +37,5 @@ flux get helmreleases [flags]
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [flux get](flux_get.md) - Get sources and resources
|
||||
* [flux get](flux_get.md) - Get the resources and their status
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@ The get image sub-commands print the status of image automation objects.
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [flux get](flux_get.md) - Get sources and resources
|
||||
* [flux get](flux_get.md) - Get the resources and their status
|
||||
* [flux get images all](flux_get_images_all.md) - Get all image statuses
|
||||
* [flux get images policy](flux_get_images_policy.md) - Get ImagePolicy status
|
||||
* [flux get images repository](flux_get_images_repository.md) - Get ImageRepository status
|
||||
* [flux get images update](flux_get_images_update.md) - Get ImageUpdateAutomation status
|
||||
|
||||
44
docs/cmd/flux_get_images_all.md
Normal file
44
docs/cmd/flux_get_images_all.md
Normal file
@@ -0,0 +1,44 @@
|
||||
## flux get images all
|
||||
|
||||
Get all image statuses
|
||||
|
||||
### Synopsis
|
||||
|
||||
The get image sub-commands print the statuses of all image objects.
|
||||
|
||||
```
|
||||
flux get images all [flags]
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
```
|
||||
# List all image objects in a namespace
|
||||
flux get images all --namespace=flux-system
|
||||
|
||||
# List all image objects in all namespaces
|
||||
flux get images all --all-namespaces
|
||||
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
```
|
||||
-h, --help help for all
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
||||
```
|
||||
-A, --all-namespaces list the requested object(s) across all namespaces
|
||||
--context string kubernetes context to use
|
||||
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||
-n, --namespace string the namespace scope for this operation (default "flux-system")
|
||||
--timeout duration timeout for this operation (default 5m0s)
|
||||
--verbose print generated objects
|
||||
```
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [flux get images](flux_get_images.md) - Get image automation object status
|
||||
|
||||
@@ -37,5 +37,5 @@ flux get kustomizations [flags]
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [flux get](flux_get.md) - Get sources and resources
|
||||
* [flux get](flux_get.md) - Get the resources and their status
|
||||
|
||||
|
||||
@@ -37,5 +37,5 @@ flux get receivers [flags]
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [flux get](flux_get.md) - Get sources and resources
|
||||
* [flux get](flux_get.md) - Get the resources and their status
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@ The get source sub-commands print the statuses of the sources.
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [flux get](flux_get.md) - Get sources and resources
|
||||
* [flux get](flux_get.md) - Get the resources and their status
|
||||
* [flux get sources all](flux_get_sources_all.md) - Get all source statuses
|
||||
* [flux get sources bucket](flux_get_sources_bucket.md) - Get Bucket source statuses
|
||||
* [flux get sources chart](flux_get_sources_chart.md) - Get HelmChart statuses
|
||||
* [flux get sources git](flux_get_sources_git.md) - Get GitRepository source statuses
|
||||
|
||||
44
docs/cmd/flux_get_sources_all.md
Normal file
44
docs/cmd/flux_get_sources_all.md
Normal file
@@ -0,0 +1,44 @@
|
||||
## flux get sources all
|
||||
|
||||
Get all source statuses
|
||||
|
||||
### Synopsis
|
||||
|
||||
The get sources all command print the statuses of all sources.
|
||||
|
||||
```
|
||||
flux get sources all [flags]
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
```
|
||||
# List all sources in a namespace
|
||||
flux get sources all --namespace=flux-system
|
||||
|
||||
# List all sources in all namespaces
|
||||
flux get sources all --all-namespaces
|
||||
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
```
|
||||
-h, --help help for all
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
||||
```
|
||||
-A, --all-namespaces list the requested object(s) across all namespaces
|
||||
--context string kubernetes context to use
|
||||
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||
-n, --namespace string the namespace scope for this operation (default "flux-system")
|
||||
--timeout duration timeout for this operation (default 5m0s)
|
||||
--verbose print generated objects
|
||||
```
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [flux get sources](flux_get_sources.md) - Get source statuses
|
||||
|
||||
@@ -45,7 +45,7 @@ flux install [flags]
|
||||
--network-policy deny ingress access to the toolkit controllers from other namespaces using network policies (default true)
|
||||
--registry string container registry where the toolkit images are published (default "ghcr.io/fluxcd")
|
||||
--toleration-keys strings list of toleration keys used to schedule the components pods onto nodes with matching taints
|
||||
-v, --version string toolkit version (default "latest")
|
||||
-v, --version string toolkit version, when specified the manifests are downloaded from https://github.com/fluxcd/flux2/releases
|
||||
--watch-all-namespaces watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed (default true)
|
||||
```
|
||||
|
||||
|
||||
56
docs/cmd/flux_logs.md
Normal file
56
docs/cmd/flux_logs.md
Normal file
@@ -0,0 +1,56 @@
|
||||
## flux logs
|
||||
|
||||
Display formatted logs for Flux components
|
||||
|
||||
### Synopsis
|
||||
|
||||
The logs command displays formatted logs from various Flux components.
|
||||
|
||||
```
|
||||
flux logs [flags]
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
```
|
||||
# Print the reconciliation logs of all Flux custom resources in your cluster
|
||||
flux logs --all-namespaces
|
||||
|
||||
# Stream logs for a particular log level
|
||||
flux logs --follow --level=error --all-namespaces
|
||||
|
||||
# Filter logs by kind, name and namespace
|
||||
flux logs --kind=Kustomization --name=podinfo --namespace=default
|
||||
|
||||
# Print logs when Flux is installed in a different namespace than flux-system
|
||||
flux logs --flux-namespace=my-namespace
|
||||
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
```
|
||||
-A, --all-namespaces displays logs for objects across all namespaces
|
||||
--flux-namespace string the namespace where the Flux components are running (default "flux-system")
|
||||
-f, --follow specifies if the logs should be streamed
|
||||
-h, --help help for logs
|
||||
--kind string displays errors of a particular toolkit kind e.g GitRepository
|
||||
--level logLevel log level, available options are: (debug, info, error)
|
||||
--name string specifies the name of the object logs to be displayed
|
||||
--tail int lines of recent log file to display (default -1)
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
||||
```
|
||||
--context string kubernetes context to use
|
||||
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||
-n, --namespace string the namespace scope for this operation (default "flux-system")
|
||||
--timeout duration timeout for this operation (default 5m0s)
|
||||
--verbose print generated objects
|
||||
```
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [flux](flux.md) - Command line utility for assembling Kubernetes CD pipelines
|
||||
|
||||
@@ -20,6 +20,7 @@ Features:
|
||||
- Runs Helm install/upgrade in a specific order, taking into account the depends-on relationship defined in a set of `HelmRelease` objects
|
||||
- Prunes Helm releases removed from cluster (garbage collection)
|
||||
- Reports Helm releases statuses (alerting provided by [notification-controller](../notification/controller.md))
|
||||
- Built-in Kustomize compatible Helm post renderer, providing support for strategic merge, JSON 6902 and images patches
|
||||
|
||||
Links:
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ repository when new container images are available.
|
||||
- The image-automation-controller updates YAML files based on the latest images scanned, and commits
|
||||
the changes to a given Git repository.
|
||||
|
||||

|
||||
|
||||
Links:
|
||||
|
||||
- Source code [fluxcd/image-reflector-controller](https://github.com/fluxcd/image-reflector-controller)
|
||||
|
||||
@@ -28,7 +28,7 @@ is produced.
|
||||
All sources are specified as Custom Resources in a Kubernetes cluster, examples
|
||||
of sources are `GitRepository`, `HelmRepository` and `Bucket` resources.
|
||||
|
||||
For more information, take a look at [the source controller documentation](../components/source/source.md).
|
||||
For more information, take a look at [the source controller documentation](../components/source/controller.md).
|
||||
|
||||
## Reconciliation
|
||||
|
||||
|
||||
@@ -152,7 +152,8 @@ cd ./deploy/prod && kustomize create --autodetect --recursive
|
||||
|
||||
### What is the behavior of Kustomize used by Flux
|
||||
|
||||
We referred to the Kustomization CLI flags here, so that you can replicate the same behavior using the CLI. The behavior of Kustomize used by the controller is currently configured as following:
|
||||
We referred to the Kustomization CLI flags here, so that you can replicate the same behavior using the CLI.
|
||||
The behavior of Kustomize used by the controller is currently configured as following:
|
||||
|
||||
- `--allow_id_changes` is set to false, so it does not change any resource IDs.
|
||||
- `--enable_kyaml` is disabled by default, so it currently used `k8sdeps` to process YAMLs.
|
||||
@@ -197,95 +198,76 @@ NAMESPACE NAME READY MESSAGE
|
||||
default default-podinfo False no chart version found for podinfo-9.0.0
|
||||
```
|
||||
|
||||
### Can I use Flux HelmReleases without GitOps?
|
||||
|
||||
Yes, you can install the Flux components directly on a cluster
|
||||
and manage Helm releases with `kubectl`.
|
||||
|
||||
Install the controllers needed for Helm operations with `flux`:
|
||||
|
||||
```sh
|
||||
flux install \
|
||||
--namespace=flux-system \
|
||||
--network-policy=false \
|
||||
--components=source-controller,helm-controller
|
||||
```
|
||||
|
||||
Create a Helm release with `kubectl`:
|
||||
|
||||
```sh
|
||||
cat << EOF | kubectl apply -f -
|
||||
---
|
||||
apiVersion: source.toolkit.fluxcd.io/v1beta1
|
||||
kind: HelmRepository
|
||||
metadata:
|
||||
name: bitnami
|
||||
namespace: flux-system
|
||||
spec:
|
||||
interval: 30m
|
||||
url: https://charts.bitnami.com/bitnami
|
||||
---
|
||||
apiVersion: helm.toolkit.fluxcd.io/v2beta1
|
||||
kind: HelmRelease
|
||||
metadata:
|
||||
name: metrics-server
|
||||
namespace: kube-system
|
||||
spec:
|
||||
interval: 60m
|
||||
releaseName: metrics-server
|
||||
chart:
|
||||
spec:
|
||||
chart: metrics-server
|
||||
version: "^5.x"
|
||||
sourceRef:
|
||||
kind: HelmRepository
|
||||
name: bitnami
|
||||
namespace: flux-system
|
||||
values:
|
||||
apiService:
|
||||
create: true
|
||||
EOF
|
||||
```
|
||||
|
||||
Based on the above definition, Flux will upgrade the release automatically
|
||||
when Bitnami publishes a new version of the metrics-server chart.
|
||||
|
||||
## Flux v1 vs v2 questions
|
||||
|
||||
### What does Flux v2 mean for Flux?
|
||||
### What are the differences between v1 and v2?
|
||||
|
||||
Flux v1 is a monolithic do-it-all operator; Flux v2 separates the functionalities into specialized controllers, collectively called the GitOps Toolkit.
|
||||
Flux v1 is a monolithic do-it-all operator;
|
||||
Flux v2 separates the functionalities into specialized controllers, collectively called the GitOps Toolkit.
|
||||
|
||||
You can install and operate Flux v2 simply using the `flux` command. You can easily pick and choose the functionality you need and extend it to serve your own purposes.
|
||||
You can find a detailed comparison of Flux v1 and v2 features in the [migration FAQ](../guides/faq-migration.md).
|
||||
|
||||
The timeline we are looking at right now is:
|
||||
### How can I migrate from v1 to v2?
|
||||
|
||||
1. Put Flux v1 into maintenance mode (no new features being added; bugfixes and CVEs patched only).
|
||||
1. Continue work on the [Flux v2 roadmap](https://toolkit.fluxcd.io/roadmap/).
|
||||
1. We will provide transition guides for specific user groups, e.g. users of Flux v1 in read-only mode, or of Helm Operator v1, etc. once the functionality is integrated into Flux v2 and it's deemed "ready".
|
||||
1. Once the use-cases of Flux v1 are covered, we will continue supporting Flux v1 for 6 months. This will be the transition period before it's considered unsupported.
|
||||
The Flux community has created guides and example repositories
|
||||
to help you migrate to Flux v2:
|
||||
|
||||
### Why did you rewrite Flux?
|
||||
|
||||
Flux v2 implements its functionality in individual controllers, which allowed us to address long-standing feature requests much more easily.
|
||||
|
||||
By basing these controllers on modern Kubernetes tooling (`controller-runtime` libraries), they can be dynamically configured with Kubernetes custom resources either by cluster admins or by other automated tools -- and you get greatly increased observability.
|
||||
|
||||
This gave us the opportunity to build Flux v2 with the top Flux v1 feature requests in mind:
|
||||
|
||||
- Supporting multiple source Git repositories
|
||||
- Operational insight through health checks, events and alerts
|
||||
- Multi-tenancy capabilities, like applying each source repository with its own set of permissions
|
||||
|
||||
On top of that, testing the individual components and understanding the codebase becomes a lot easier.
|
||||
|
||||
### What are significant new differences between Flux v1 and Flux v2?
|
||||
|
||||
#### Reconciliation
|
||||
|
||||
Flux v1 | Flux v2
|
||||
---------------------------------- | ----------------------------------
|
||||
Limited to a single Git repository | Multiple Git repositories
|
||||
Declarative config via arguments in the Flux deployment | `GitRepository` custom resource, which produces an artifact which can be reconciled by other controllers
|
||||
Follow `HEAD` of Git branches | Supports Git branches, pinning on commits and tags, follow SemVer tag ranges
|
||||
Suspending of reconciliation by downscaling Flux deployment | Reconciliation can be paused per resource by suspending the `GitRepository`
|
||||
Credentials config via Arguments and/or Secret volume mounts in the Flux pod | Credentials config per `GitRepository` resource: SSH private key, HTTP/S username/password/token, OpenPGP public keys
|
||||
|
||||
#### `kustomize` support
|
||||
|
||||
Flux v1 | Flux v2
|
||||
---------------------------------- | ----------------------------------
|
||||
Declarative config through `.flux.yaml` files in the Git repository | Declarative config through a `Kustomization` custom resource, consuming the artifact from the GitRepository
|
||||
Manifests are generated via shell exec and then reconciled by `fluxd` | Generation, server-side validation, and reconciliation is handled by a specialised `kustomize-controller`
|
||||
Reconciliation using the service account of the Flux deployment | Support for service account impersonation
|
||||
Garbage collection needs cluster role binding for Flux to query the Kubernetes discovery API | Garbage collection needs no cluster role binding or access to Kubernetes discovery API
|
||||
Support for custom commands and generators executed by fluxd in a POSIX shell | No support for custom commands
|
||||
|
||||
#### Helm integration
|
||||
|
||||
Flux v1 | Flux v2
|
||||
---------------------------------- | ----------------------------------
|
||||
Declarative config in a single Helm custom resource | Declarative config through `HelmRepository`, `GitRepository`, `Bucket`, `HelmChart` and `HelmRelease` custom resources
|
||||
Chart synchronisation embedded in the operator | Extensive release configuration options, and a reconciliation interval per source
|
||||
Support for fixed SemVer versions from Helm repositories | Support for SemVer ranges for `HelmChart` resources
|
||||
Git repository synchronisation on a global interval | Planned support for charts from GitRepository sources
|
||||
Limited observability via the status object of the HelmRelease resource | Better observability via the HelmRelease status object, Kubernetes events, and notifications
|
||||
Resource heavy, relatively slow | Better performance
|
||||
Chart changes from Git sources are determined from Git metadata | Chart changes must be accompanied by a version bump in `Chart.yaml` to produce a new artifact
|
||||
|
||||
#### Notifications, webhooks, observability
|
||||
|
||||
Flux v1 | Flux v2
|
||||
---------------------------------- | ----------------------------------
|
||||
Emits "custom Flux events" to a webhook endpoint | Emits Kubernetes events for included custom resources
|
||||
RPC endpoint can be configured to a 3rd party solution like FluxCloud to be forwarded as notifications to e.g. Slack | Flux v2 components can be configured to POST the events to a `notification-controller` endpoint. Selective forwarding of POSTed events as notifications using `Provider` and `Alert` custom resources.
|
||||
Webhook receiver is a side-project | Webhook receiver, handling a wide range of platforms, is included
|
||||
Unstructured logging | Structured logging for all components
|
||||
Custom Prometheus metrics | Generic / common `controller-runtime` Prometheus metrics
|
||||
|
||||
### How can I get involved?
|
||||
|
||||
There are a variety of ways and we look forward to having you on board building the future of GitOps together:
|
||||
|
||||
- [Discuss the direction](https://github.com/fluxcd/flux2/discussions) of Flux v2 with us
|
||||
- Join us in #flux-dev on the [CNCF Slack](https://slack.cncf.io)
|
||||
- Check out our [contributor docs](https://toolkit.fluxcd.io/contributing/)
|
||||
- Take a look at the [roadmap for Flux v2](https://toolkit.fluxcd.io/roadmap/)
|
||||
|
||||
### Are there any breaking changes?
|
||||
|
||||
- In Flux v1 Kustomize support was implemented through `.flux.yaml` files in the Git repository. As indicated in the comparison table above, while this approach worked, we found it to be error-prone and hard to debug. The new [Kustomization CR](https://github.com/fluxcd/kustomize-controller/blob/master/docs/spec/v1alpha1/kustomization.md) should make troubleshooting much easier. Unfortunately we needed to drop the support for custom commands as running arbitrary shell scripts in-cluster poses serious security concerns.
|
||||
- Helm users: we redesigned the `HelmRelease` API and the automation will work quite differently, so upgrading to `HelmRelease` v2 will require a little work from you, but you will gain more flexibility, better observability and performance.
|
||||
|
||||
### Is the GitOps Toolkit related to the GitOps Engine?
|
||||
|
||||
In an announcement in August 2019, the expectation was set that the Flux project would integrate the GitOps Engine, then being factored out of ArgoCD. Since the result would be backward-incompatible, it would require a major version bump: Flux v2.
|
||||
|
||||
After experimentation and considerable thought, we (the maintainers) have found a path to Flux v2 that we think better serves our vision of GitOps: the GitOps Toolkit. In consequence, we do not now plan to integrate GitOps Engine into Flux.
|
||||
- [Migrate from Flux v1](https://toolkit.fluxcd.io/guides/flux-v1-migration/)
|
||||
- [Migrate from `.flux.yaml` and kustomize](https://toolkit.fluxcd.io/guides/flux-v1-migration/#flux-with-kustomize)
|
||||
- [Migrate from Flux v1 automated container image updates](https://toolkit.fluxcd.io/guides/flux-v1-automation-migration/)
|
||||
- [How to manage multi-tenant clusters with Flux v2](https://github.com/fluxcd/flux2-multi-tenancy)
|
||||
- [Migrate from Helm Operator to Flux v2](https://toolkit.fluxcd.io/guides/helm-operator-migration/)
|
||||
- [How to structure your HelmReleases](https://github.com/fluxcd/flux2-kustomize-helm-example)
|
||||
|
||||
92
docs/guides/faq-migration.md
Normal file
92
docs/guides/faq-migration.md
Normal file
@@ -0,0 +1,92 @@
|
||||
## Flux v1 vs v2 questions
|
||||
|
||||
### What does Flux v2 mean for Flux?
|
||||
|
||||
Flux v1 is a monolithic do-it-all operator; Flux v2 separates the functionalities into specialized controllers, collectively called the GitOps Toolkit.
|
||||
|
||||
You can install and operate Flux v2 simply using the `flux` command. You can easily pick and choose the functionality you need and extend it to serve your own purposes.
|
||||
|
||||
The timeline we are looking at right now is:
|
||||
|
||||
1. Put Flux v1 into maintenance mode (no new features being added; bugfixes and CVEs patched only).
|
||||
1. Continue work on the [Flux v2 roadmap](https://toolkit.fluxcd.io/roadmap/).
|
||||
1. We will provide transition guides for specific user groups, e.g. users of Flux v1 in read-only mode, or of Helm Operator v1, etc. once the functionality is integrated into Flux v2 and it's deemed "ready".
|
||||
1. Once the use-cases of Flux v1 are covered, we will continue supporting Flux v1 for 6 months. This will be the transition period before it's considered unsupported.
|
||||
|
||||
### Why did you rewrite Flux?
|
||||
|
||||
Flux v2 implements its functionality in individual controllers, which allowed us to address long-standing feature requests much more easily.
|
||||
|
||||
By basing these controllers on modern Kubernetes tooling (`controller-runtime` libraries), they can be dynamically configured with Kubernetes custom resources either by cluster admins or by other automated tools -- and you get greatly increased observability.
|
||||
|
||||
This gave us the opportunity to build Flux v2 with the top Flux v1 feature requests in mind:
|
||||
|
||||
- Supporting multiple source Git repositories
|
||||
- Operational insight through health checks, events and alerts
|
||||
- Multi-tenancy capabilities, like applying each source repository with its own set of permissions
|
||||
|
||||
On top of that, testing the individual components and understanding the codebase becomes a lot easier.
|
||||
|
||||
### What are significant new differences between Flux v1 and Flux v2?
|
||||
|
||||
#### Reconciliation
|
||||
|
||||
Flux v1 | Flux v2
|
||||
---------------------------------- | ----------------------------------
|
||||
Limited to a single Git repository | Multiple Git repositories
|
||||
Declarative config via arguments in the Flux deployment | `GitRepository` custom resource, which produces an artifact which can be reconciled by other controllers
|
||||
Follow `HEAD` of Git branches | Supports Git branches, pinning on commits and tags, follow SemVer tag ranges
|
||||
Suspending of reconciliation by downscaling Flux deployment | Reconciliation can be paused per resource by suspending the `GitRepository`
|
||||
Credentials config via Arguments and/or Secret volume mounts in the Flux pod | Credentials config per `GitRepository` resource: SSH private key, HTTP/S username/password/token, OpenPGP public keys
|
||||
|
||||
#### `kustomize` support
|
||||
|
||||
Flux v1 | Flux v2
|
||||
---------------------------------- | ----------------------------------
|
||||
Declarative config through `.flux.yaml` files in the Git repository | Declarative config through a `Kustomization` custom resource, consuming the artifact from the GitRepository
|
||||
Manifests are generated via shell exec and then reconciled by `fluxd` | Generation, server-side validation, and reconciliation is handled by a specialised `kustomize-controller`
|
||||
Reconciliation using the service account of the Flux deployment | Support for service account impersonation
|
||||
Garbage collection needs cluster role binding for Flux to query the Kubernetes discovery API | Garbage collection needs no cluster role binding or access to Kubernetes discovery API
|
||||
Support for custom commands and generators executed by fluxd in a POSIX shell | No support for custom commands
|
||||
|
||||
#### Helm integration
|
||||
|
||||
Flux v1 | Flux v2
|
||||
---------------------------------- | ----------------------------------
|
||||
Declarative config in a single Helm custom resource | Declarative config through `HelmRepository`, `GitRepository`, `Bucket`, `HelmChart` and `HelmRelease` custom resources
|
||||
Chart synchronisation embedded in the operator | Extensive release configuration options, and a reconciliation interval per source
|
||||
Support for fixed SemVer versions from Helm repositories | Support for SemVer ranges for `HelmChart` resources
|
||||
Git repository synchronisation on a global interval | Planned support for charts from GitRepository sources
|
||||
Limited observability via the status object of the HelmRelease resource | Better observability via the HelmRelease status object, Kubernetes events, and notifications
|
||||
Resource heavy, relatively slow | Better performance
|
||||
Chart changes from Git sources are determined from Git metadata | Chart changes must be accompanied by a version bump in `Chart.yaml` to produce a new artifact
|
||||
|
||||
#### Notifications, webhooks, observability
|
||||
|
||||
Flux v1 | Flux v2
|
||||
---------------------------------- | ----------------------------------
|
||||
Emits "custom Flux events" to a webhook endpoint | Emits Kubernetes events for included custom resources
|
||||
RPC endpoint can be configured to a 3rd party solution like FluxCloud to be forwarded as notifications to e.g. Slack | Flux v2 components can be configured to POST the events to a `notification-controller` endpoint. Selective forwarding of POSTed events as notifications using `Provider` and `Alert` custom resources.
|
||||
Webhook receiver is a side-project | Webhook receiver, handling a wide range of platforms, is included
|
||||
Unstructured logging | Structured logging for all components
|
||||
Custom Prometheus metrics | Generic / common `controller-runtime` Prometheus metrics
|
||||
|
||||
### Are there any breaking changes?
|
||||
|
||||
- In Flux v1 Kustomize support was implemented through `.flux.yaml` files in the Git repository. As indicated in the comparison table above, while this approach worked, we found it to be error-prone and hard to debug. The new [Kustomization CR](https://github.com/fluxcd/kustomize-controller/blob/master/docs/spec/v1alpha1/kustomization.md) should make troubleshooting much easier. Unfortunately we needed to drop the support for custom commands as running arbitrary shell scripts in-cluster poses serious security concerns.
|
||||
- Helm users: we redesigned the `HelmRelease` API and the automation will work quite differently, so upgrading to `HelmRelease` v2 will require a little work from you, but you will gain more flexibility, better observability and performance.
|
||||
|
||||
### Is the GitOps Toolkit related to the GitOps Engine?
|
||||
|
||||
In an announcement in August 2019, the expectation was set that the Flux project would integrate the GitOps Engine, then being factored out of ArgoCD. Since the result would be backward-incompatible, it would require a major version bump: Flux v2.
|
||||
|
||||
After experimentation and considerable thought, we (the maintainers) have found a path to Flux v2 that we think better serves our vision of GitOps: the GitOps Toolkit. In consequence, we do not now plan to integrate GitOps Engine into Flux.
|
||||
|
||||
### How can I get involved?
|
||||
|
||||
There are a variety of ways and we look forward to having you on board building the future of GitOps together:
|
||||
|
||||
- [Discuss the direction](https://github.com/fluxcd/flux2/discussions) of Flux v2 with us
|
||||
- Join us in #flux-dev on the [CNCF Slack](https://slack.cncf.io)
|
||||
- Check out our [contributor docs](https://toolkit.fluxcd.io/contributing/)
|
||||
- Take a look at the [roadmap for Flux v2](https://toolkit.fluxcd.io/roadmap/)
|
||||
@@ -431,8 +431,8 @@ spec:
|
||||
```
|
||||
|
||||
!!! hint
|
||||
If you are using the same image repository in several manifests, you only need one
|
||||
`ImageRepository` object for it.
|
||||
If you are using the same image repository in several manifests, you only need one
|
||||
`ImageRepository` object for it.
|
||||
|
||||
##### Using image registry credentials for scanning
|
||||
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
# Migrate from Flux v1 to v2
|
||||
|
||||
This guide walks you through migrating from Flux v1 to v2.
|
||||
Read the [FAQ](../faq/index.md) to find out what differences are between v1 and v2.
|
||||
Read the [FAQ](faq-migration.md) to find out what differences are between v1 and v2.
|
||||
|
||||
!!! info "Automated image updates"
|
||||
The image automation feature is under development in Flux v2.
|
||||
Please consult the [roadmap](../roadmap/index.md) for more details.
|
||||
|
||||
|
||||
!!! info "Feature parity"
|
||||
"Feature parity" does not mean Flux v2 works exactly the same as v1 (or is
|
||||
backward-compatible); it means you can accomplish the same results, while
|
||||
accounting for the fact that it's a system with a substantially different
|
||||
design.
|
||||
This may at times mean that you have to make adjustments to the way your
|
||||
current cluster configuration is structured. If you are in this situation
|
||||
and need help, please refer to the [support page](https://fluxcd.io/support/).
|
||||
|
||||
## Prerequisites
|
||||
|
||||
You will need a Kubernetes cluster version **1.16** or newer
|
||||
@@ -53,6 +62,13 @@ to define the state of your fleet of Kubernetes clusters.
|
||||
|
||||
For a detailed walk-through of the bootstrap procedure please see the [installation guide](installation.md).
|
||||
|
||||
!!! warning "`flux bootstrap` target"
|
||||
`flux bootstrap` should not be run against a Git branch or path
|
||||
that is already being synchronized by Flux v1, as this will make
|
||||
them fight over the resources. Instead, bootstrap to a **new Git
|
||||
repository, branch or path**, and continue with moving the
|
||||
manifests.
|
||||
|
||||
After you've installed Flux v2 on your cluster using bootstrap,
|
||||
you can delete the Flux v1 from your clusters and move the manifests from the
|
||||
Flux v1 repository to the bootstrap one.
|
||||
@@ -109,7 +125,6 @@ Install Flux v2 in the `flux-system` namespace:
|
||||
|
||||
```console
|
||||
$ flux install \
|
||||
--arch=amd64 \
|
||||
--network-policy=true \
|
||||
--watch-all-namespaces=true \
|
||||
--namespace=flux-system
|
||||
@@ -227,7 +242,7 @@ Configure the reconciliation of the `prod` overlay on your cluster:
|
||||
|
||||
```sh
|
||||
flux create kustomization app \
|
||||
--source=app \
|
||||
--source=GitRepository/app \
|
||||
--path="./overlays/prod" \
|
||||
--prune=true \
|
||||
--interval=10m
|
||||
|
||||
@@ -773,6 +773,12 @@ Probably, but with some side notes:
|
||||
1. It is still under active development, and while our focus has been to stabilize the API as much as we can during the first development phase, we do not guarantee there will not be any breaking changes before we reach General Availability. We are however committed to provide [conversion webhooks](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/#webhook-conversion) for upcoming API versions.
|
||||
1. There may be (internal) behavioral changes in upcoming releases, but they should be aimed at further stabilizing the Helm Controller itself, solving edge case issues, providing better logging, observability, and/or other improvements.
|
||||
|
||||
### Can I use Helm Controller standalone?
|
||||
|
||||
Helm Controller depends on [Source Controller](../components/source/controller.md), you can install both controllers
|
||||
and manager Helm releases in a declarative way without GitOps.
|
||||
For more details please see this [answer](../faq/index.md#can-i-use-flux-helmreleases-without-gitops).
|
||||
|
||||
### I have another question
|
||||
|
||||
Given the amount of changes, it is quite possible that this document did not provide you with a clear answer for you specific setup. If this applies to you, do not hestitate to ask for help in the [GitHub Discussions](https://github.com/fluxcd/flux2/discussions/new?category_id=31999889) or on the [`#flux` CNCF Slack channel](https://slack.cncf.io)!
|
||||
|
||||
@@ -232,7 +232,7 @@ podinfo True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to: 5
|
||||
|
||||
## Configure image updates
|
||||
|
||||
Edit the `podinfo-deploy.yaml` and add a marker to tell Flux which policy to use when updating the container image:
|
||||
Edit the `podinfo-deployment.yaml` and add a marker to tell Flux which policy to use when updating the container image:
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
@@ -247,9 +247,12 @@ Create an `ImageUpdateAutomation` to tell Flux which Git repository to write ima
|
||||
flux create image update flux-system \
|
||||
--git-repo-ref=flux-system \
|
||||
--branch=main \
|
||||
--git-repo-path="./clusters/my-cluster" \
|
||||
--checkout-branch=main \
|
||||
--push-branch=main \
|
||||
--author-name=fluxcdbot \
|
||||
--author-email=fluxcdbot@users.noreply.github.com \
|
||||
--commit-template="[ci skip] update image" \
|
||||
--commit-template="{{range .Updated.Images}}{{println .}}{{end}}" \
|
||||
--export > ./clusters/my-cluster/flux-system-automation.yaml
|
||||
```
|
||||
|
||||
@@ -269,9 +272,12 @@ spec:
|
||||
commit:
|
||||
authorEmail: fluxcdbot@users.noreply.github.com
|
||||
authorName: fluxcdbot
|
||||
messageTemplate: '[ci skip] update image'
|
||||
messageTemplate: '{{range .Updated.Images}}{{println .}}{{end}}'
|
||||
interval: 1m0s
|
||||
push:
|
||||
branch: main
|
||||
update:
|
||||
path: ./clusters/my-cluster
|
||||
strategy: Setters
|
||||
```
|
||||
|
||||
@@ -306,6 +312,12 @@ $ watch "kubectl get deployment/podinfo -oyaml | grep 'image:'"
|
||||
image: ghcr.io/stefanprodan/podinfo:5.0.3
|
||||
```
|
||||
|
||||
You can check the status of the image automation objects with:
|
||||
|
||||
```sh
|
||||
flux get images all --all-namespaces
|
||||
```
|
||||
|
||||
## Configure image update for custom resources
|
||||
|
||||
Besides Kubernetes native kinds (Deployment, StatefulSet, DaemonSet, CronJob),
|
||||
@@ -374,6 +386,68 @@ images:
|
||||
newTag: 5.0.0 # {"$imagepolicy": "flux-system:podinfo:tag"}
|
||||
```
|
||||
|
||||
## Push updates to a different branch
|
||||
|
||||
With `.spec.push.branch` you can configure Flux to push the image updates to different branch
|
||||
than the one used for checkout. If the specified branch doesn't exist, Flux will create it for you.
|
||||
|
||||
```yaml
|
||||
apiVersion: image.toolkit.fluxcd.io/v1alpha1
|
||||
kind: ImageUpdateAutomation
|
||||
metadata:
|
||||
name: flux-system
|
||||
spec:
|
||||
checkout:
|
||||
branch: main
|
||||
gitRepositoryRef:
|
||||
name: flux-system
|
||||
push:
|
||||
branch: image-updates
|
||||
```
|
||||
|
||||
You can use CI automation e.g. GitHub Actions such as
|
||||
[create-pull-request](https://github.com/peter-evans/create-pull-request)
|
||||
to open a pull request against the checkout branch.
|
||||
|
||||
This way you can manually approve the image updates before they are applied on your clusters.
|
||||
|
||||
## Configure the commit message
|
||||
|
||||
The `.spec.commit.messageTemplate` field is a string which is used as a template for the commit message.
|
||||
|
||||
The message template is a [Go text template](https://golang.org/pkg/text/template/) that
|
||||
lets you range over the objects and images e.g.:
|
||||
|
||||
```yaml
|
||||
apiVersion: image.toolkit.fluxcd.io/v1alpha1
|
||||
kind: ImageUpdateAutomation
|
||||
metadata:
|
||||
name: flux-system
|
||||
spec:
|
||||
commit:
|
||||
messsageTemplate: |
|
||||
Automated image update
|
||||
|
||||
Automation name: {{ .AutomationObject }}
|
||||
|
||||
Files:
|
||||
{{ range $filename, $_ := .Updated.Files -}}
|
||||
- {{ $filename }}
|
||||
{{ end -}}
|
||||
|
||||
Objects:
|
||||
{{ range $resource, $_ := .Updated.Objects -}}
|
||||
- {{ $resource.Kind }} {{ $resource.Name }}
|
||||
{{ end -}}
|
||||
|
||||
Images:
|
||||
{{ range .Updated.Images -}}
|
||||
- {{.}}
|
||||
{{ end -}}
|
||||
authorEmail: flux@example.com
|
||||
authorName: flux
|
||||
```
|
||||
|
||||
## Trigger image updates with webhooks
|
||||
|
||||
You may want to trigger a deployment
|
||||
@@ -819,7 +893,7 @@ Create a directory in your control repository and save this `kustomization.yaml`
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- https://github.com/fluxcd/flux2/archive/main.zip//manifests/integrations/registry-credentials-sync/azure
|
||||
- git@github.com/fluxcd/flux2//manifests/integrations/registry-credentials-sync/azure
|
||||
patchesStrategicMerge:
|
||||
- config-patches.yaml
|
||||
```
|
||||
|
||||
@@ -58,8 +58,7 @@ You can choose what components to install and for which cluster with:
|
||||
flux bootstrap <GIT-PROVIDER> \
|
||||
--components=source-controller,kustomize-controller,helm-controller,notification-controller \
|
||||
--components-extra=image-reflector-controller,image-automation-controller \
|
||||
--path=clusters/my-cluster \
|
||||
--version=latest
|
||||
--path=clusters/my-cluster
|
||||
```
|
||||
|
||||
!!! hint "Multi-arch images"
|
||||
@@ -68,7 +67,7 @@ flux bootstrap <GIT-PROVIDER> \
|
||||
architectures.
|
||||
|
||||
If you wish to install a specific version, use the Flux
|
||||
[release tag](https://github.com/fluxcd/flux2/releases) e.g. `--version=v0.2.0`.
|
||||
[release tag](https://github.com/fluxcd/flux2/releases) e.g. `--version=v0.9.0`.
|
||||
|
||||
If you wish to deploy the Flux components onto
|
||||
[tainted Kubernetes nodes](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/),
|
||||
@@ -226,9 +225,59 @@ flux bootstrap gitlab \
|
||||
--path=clusters/my-cluster
|
||||
```
|
||||
|
||||
### Air-gapped Environments
|
||||
|
||||
To bootstrap Flux on air-gapped environments without access to github.com and ghcr.io, first you'll need
|
||||
to download the `flux` binary, and the container images from a computer with access to internet.
|
||||
|
||||
List all container images:
|
||||
|
||||
```console
|
||||
$ flux install --export | grep ghcr.io
|
||||
|
||||
image: ghcr.io/fluxcd/helm-controller:v0.8.0
|
||||
image: ghcr.io/fluxcd/kustomize-controller:v0.9.0
|
||||
image: ghcr.io/fluxcd/notification-controller:v0.9.0
|
||||
image: ghcr.io/fluxcd/source-controller:v0.9.0
|
||||
```
|
||||
|
||||
Pull the images locally and push them to your container registry:
|
||||
|
||||
```sh
|
||||
docker pull ghcr.io/fluxcd/source-controller:v0.9.0
|
||||
docker tag ghcr.io/fluxcd/source-controller:v0.9.0 registry.internal/fluxcd/source-controller:v0.9.0
|
||||
docker push registry.internal/fluxcd/source-controller:v0.9.0
|
||||
```
|
||||
|
||||
Copy `flux` binary to a computer with access to your air-gapped cluster,
|
||||
and create the pull secret in the `flux-system` namespace:
|
||||
|
||||
```sh
|
||||
kubectl create ns flux-system
|
||||
|
||||
kubectl -n flux-system create secret generic regcred \
|
||||
--from-file=.dockerconfigjson=/.docker/config.json \
|
||||
--type=kubernetes.io/dockerconfigjson
|
||||
```
|
||||
|
||||
Finally, bootstrap Flux using the images from your private registry:
|
||||
|
||||
```sh
|
||||
flux bootstrap <GIT-PROVIDER> \
|
||||
--registry=registry.internal/fluxcd \
|
||||
--image-pull-secret=regcred \
|
||||
--hostname=my-git-server.internal
|
||||
```
|
||||
|
||||
Note that when running `flux bootstrap` without specifying a `--version`,
|
||||
the CLI will use the manifests embedded in its binary instead of downloading
|
||||
them from GitHub. You can determine which version you'll be installing,
|
||||
with `flux --version`.
|
||||
|
||||
### Generic Git Server
|
||||
|
||||
For other Git providers such as Bitbucket, Gogs, Gitea, Azure DevOps, etc you can manually setup the repository and the deploy key.
|
||||
For other Git providers such as Bitbucket, Gogs, Gitea, Azure DevOps, etc
|
||||
you can manually setup the repository and deploy key.
|
||||
|
||||
Create a Git repository and clone it locally:
|
||||
|
||||
@@ -246,35 +295,7 @@ mkdir -p ./clusters/my-cluster/flux-system
|
||||
Generate the Flux manifests with:
|
||||
|
||||
```sh
|
||||
flux install --version=latest \
|
||||
--export > ./clusters/my-cluster/flux-system/gotk-components.yaml
|
||||
```
|
||||
|
||||
If your cluster must pull images from a private container registry, first you should pull
|
||||
the toolkit images from GitHub Container Registry and push them to your registry, for example:
|
||||
|
||||
```sh
|
||||
docker pull ghcr.io/fluxcd/source-controller:v0.2.0
|
||||
docker tag ghcr.io/fluxcd/source-controller:v0.2.0 registry.internal/fluxcd/source-controller:v0.2.0
|
||||
docker push registry.internal/fluxcd/source-controller:v0.2.0
|
||||
```
|
||||
|
||||
Create the pull secret in the `flux-system` namespace:
|
||||
|
||||
```sh
|
||||
kubectl create ns flux-system
|
||||
|
||||
kubectl -n flux-system create secret generic regcred \
|
||||
--from-file=.dockerconfigjson=/.docker/config.json \
|
||||
--type=kubernetes.io/dockerconfigjson
|
||||
```
|
||||
|
||||
Set your registry domain, and the pull secret when generating the manifests:
|
||||
|
||||
```sh
|
||||
flux install --version=latest \
|
||||
--registry=registry.internal/fluxcd \
|
||||
--image-pull-secret=regcred \
|
||||
flux install \
|
||||
--export > ./clusters/my-cluster/flux-system/gotk-components.yaml
|
||||
```
|
||||
|
||||
@@ -380,10 +401,11 @@ cd ./clusters/my-cluster/flux-system && kustomize create --autodetect
|
||||
git add -A && git commit -m "add sync manifests" && git push
|
||||
```
|
||||
|
||||
To upgrade the Flux components to a newer version, run the install command and commit the changes:
|
||||
To upgrade the Flux components to a newer version, download the latest `flux` binary,
|
||||
run the install command and commit the changes:
|
||||
|
||||
```sh
|
||||
flux install --version=latest \
|
||||
flux install \
|
||||
--export > ./clusters/my-cluster/flux-system/gotk-components.yaml
|
||||
|
||||
git add -A && git commit -m "update flux" && git push
|
||||
@@ -484,7 +506,7 @@ Flux will detect the change and will update itself on the production cluster.
|
||||
For testing purposes you can install Flux without storing its manifests in a Git repository:
|
||||
|
||||
```sh
|
||||
flux install --arch=amd64
|
||||
flux install
|
||||
```
|
||||
|
||||
Or using kubectl:
|
||||
@@ -592,11 +614,10 @@ kubectl annotate --overwrite gitrepository/flux-system reconcile.fluxcd.io/reque
|
||||
If you've installed Flux directly on the cluster, then rerun the install command:
|
||||
|
||||
```sh
|
||||
flux install --version=latest
|
||||
flux install
|
||||
```
|
||||
|
||||
The above command will download the latest manifests from
|
||||
[GitHub](https://github.com/fluxcd/flux2/releases) and it will apply them on your cluster.
|
||||
The above command will apply the new manifests on your cluster.
|
||||
You can verify that the controllers have been upgraded to the latest version with `flux check`.
|
||||
|
||||
If you've installed Flux directly on the cluster with kubectl,
|
||||
|
||||
@@ -54,7 +54,24 @@ If you wish to use your own Prometheus and Grafana instances, then you can impor
|
||||
|
||||
!!! hint
|
||||
Note that the toolkit controllers expose the `/metrics` endpoint on port `8080`.
|
||||
When using Prometheus Operator you should create `PodMonitor` objects to configure scraping.
|
||||
When using Prometheus Operator you should create a `PodMonitor` object for each controller to configure scraping.
|
||||
|
||||
```yaml
|
||||
apiVersion: monitoring.coreos.com/v1
|
||||
kind: PodMonitor
|
||||
metadata:
|
||||
name: source-controller
|
||||
namespace: flux-system
|
||||
spec:
|
||||
namespaceSelector:
|
||||
matchNames:
|
||||
- flux-system
|
||||
selector:
|
||||
matchLabels:
|
||||
app: source-controller
|
||||
podMetricsEndpoints:
|
||||
- port: http-prom
|
||||
```
|
||||
|
||||
## Metrics
|
||||
|
||||
@@ -67,7 +84,7 @@ Ready status metrics:
|
||||
```sh
|
||||
gotk_reconcile_condition{kind, name, namespace, type="Ready", status="True"}
|
||||
gotk_reconcile_condition{kind, name, namespace, type="Ready", status="False"}
|
||||
gotk_reconcile_condition{kind, name, namespace, type="Ready", status="Unkown"}
|
||||
gotk_reconcile_condition{kind, name, namespace, type="Ready", status="Unknown"}
|
||||
gotk_reconcile_condition{kind, name, namespace, type="Ready", status="Deleted"}
|
||||
```
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ toolkit controllers installed on it.
|
||||
Please see the [get started guide](../get-started/index.md)
|
||||
or the [installation guide](installation.md).
|
||||
|
||||
Install [gnupg](https://www.gnupg.org/) and [sops](https://github.com/mozilla/sops):
|
||||
Install [gnupg](https://www.gnupg.org/) and [SOPS](https://github.com/mozilla/sops):
|
||||
|
||||
```sh
|
||||
brew install gnupg sops
|
||||
@@ -19,38 +19,144 @@ brew install gnupg sops
|
||||
|
||||
## Generate a GPG key
|
||||
|
||||
Generate a GPG key with OpenPGP without specifying a passphrase:
|
||||
Generate a GPG/OpenPGP key with no passphrase (`%no-protection`):
|
||||
|
||||
```console
|
||||
$ gpg --full-generate-key
|
||||
```sh
|
||||
export KEY_NAME="cluster0.yourdomain.com"
|
||||
export KEY_COMMENT="flux secrets"
|
||||
|
||||
Real name: stefanprodan
|
||||
Email address: stefanprodan@users.noreply.github.com
|
||||
Comment:
|
||||
You selected this USER-ID:
|
||||
"stefanprodan <stefanprodan@users.noreply.github.com>"
|
||||
gpg --batch --full-generate-key <<EOF
|
||||
%no-protection
|
||||
Key-Type: 1
|
||||
Key-Length: 4096
|
||||
Subkey-Type: 1
|
||||
Subkey-Length: 4096
|
||||
Expire-Date: 0
|
||||
Name-Comment: ${KEY_COMMENT}
|
||||
Name-Real: ${KEY_NAME}
|
||||
EOF
|
||||
```
|
||||
|
||||
Retrieve the GPG key ID (second row of the sec column):
|
||||
The above configuration creates an rsa4096 key that does not expire.
|
||||
For a full list of options to consider for your environment, see [Unattended GPG key generation](https://www.gnupg.org/documentation/manuals/gnupg/Unattended-GPG-key-generation.html).
|
||||
|
||||
```console
|
||||
$ gpg --list-secret-keys stefanprodan@users.noreply.github.com
|
||||
Retrieve the GPG key fingerprint (second row of the sec column):
|
||||
|
||||
sec rsa3072 2020-09-06 [SC]
|
||||
```sh
|
||||
gpg --list-secret-keys "${KEY_NAME}"
|
||||
|
||||
sec rsa4096 2020-09-06 [SC]
|
||||
1F3D1CED2F865F5E59CA564553241F147E7C5FA4
|
||||
```
|
||||
|
||||
Store the key fingerprint as an environment variable:
|
||||
|
||||
```sh
|
||||
export KEY_FP=1F3D1CED2F865F5E59CA564553241F147E7C5FA4
|
||||
```
|
||||
|
||||
Export the public and private keypair from your local GPG keyring and
|
||||
create a Kubernetes secret named `sops-gpg` in the `flux-system` namespace:
|
||||
|
||||
```sh
|
||||
gpg --export-secret-keys \
|
||||
--armor 1F3D1CED2F865F5E59CA564553241F147E7C5FA4 |
|
||||
gpg --export-secret-keys --armor "${KEY_FP}" |
|
||||
kubectl create secret generic sops-gpg \
|
||||
--namespace=flux-system \
|
||||
--from-file=sops.asc=/dev/stdin
|
||||
```
|
||||
|
||||
It's a good idea to back up this secret-key/K8s-Secret with a password manager or offline storage.
|
||||
Also consider deleting the secret decryption key from you machine:
|
||||
|
||||
```sh
|
||||
gpg --delete-secret-keys "${KEY_FP}"
|
||||
```
|
||||
|
||||
## Configure in-cluster secrets decryption
|
||||
|
||||
Register the Git repository on your cluster:
|
||||
|
||||
```sh
|
||||
flux create source git my-secrets \
|
||||
--url=https://github.com/my-org/my-secrets
|
||||
```
|
||||
|
||||
Create a kustomization for reconciling the secrets on the cluster:
|
||||
|
||||
```sh
|
||||
flux create kustomization my-secrets \
|
||||
--source=my-secrets \
|
||||
--path=./clusters/cluster0 \
|
||||
--prune=true \
|
||||
--interval=10m \
|
||||
--decryption-provider=sops \
|
||||
--decryption-secret=sops-gpg
|
||||
```
|
||||
|
||||
Note that the `sops-gpg` can contain more than one key, SOPS will try to decrypt the
|
||||
secrets by iterating over all the private keys until it finds one that works.
|
||||
|
||||
## Optional: Export the public key into the Git directory
|
||||
|
||||
Commit the public key to the repository so that team members who clone the repo can encrypt new files:
|
||||
|
||||
```sh
|
||||
gpg --export --armor "${KEY_FP}" > ./clusters/cluster0/.sops.pub.asc
|
||||
```
|
||||
|
||||
Check the file contents to ensure it's the public key before adding it to the repo and committing.
|
||||
|
||||
```sh
|
||||
git add ./clusters/cluster0/.sops.pub.asc
|
||||
git commit -am 'Share GPG public key for secrets generation'
|
||||
```
|
||||
|
||||
Team members can then import this key when they pull the Git repository:
|
||||
|
||||
```sh
|
||||
gpg --import ./clusters/cluster0/.sops.pub.asc
|
||||
```
|
||||
|
||||
!!! hint
|
||||
The public key is sufficient for creating brand new files.
|
||||
The secret key is required for decrypting and editing existing files because SOPS computes a MAC on all values.
|
||||
When using solely the public key to add or remove a field, the whole file should be deleted and recreated.
|
||||
|
||||
## Configure the Git directory for encryption
|
||||
|
||||
Write a [SOPS config file](https://github.com/mozilla/sops#using-sops-yaml-conf-to-select-kms-pgp-for-new-files) to the specific cluster or namespace directory used
|
||||
to store encrypted objects with this particular GPG key's fingerprint.
|
||||
|
||||
```yaml
|
||||
cat <<EOF > ./clusters/cluster0/.sops.yaml
|
||||
creation_rules:
|
||||
- path_regex: .*.yaml
|
||||
encrypted_regex: ^(data|stringData)$
|
||||
pgp: ${KEY_FP}
|
||||
EOF
|
||||
```
|
||||
|
||||
This config applies recursively to all sub-directories.
|
||||
Multiple directories can use separate SOPS configs.
|
||||
Contributors using the `sops` CLI to create and encrypt files
|
||||
won't have to worry about specifying the proper key for the target cluster or namespace.
|
||||
|
||||
`encrypted_regex` helps encrypt the the proper `data` and `stringData` fields for Secrets.
|
||||
You may wish to add other fields if you are encrypting other types of Objects.
|
||||
|
||||
!!! hint
|
||||
Note that you should encrypt only the `data` or `stringData` section. Encrypting the Kubernetes
|
||||
secret metadata, kind or apiVersion is not supported by kustomize-controller.
|
||||
|
||||
Ignore all `.sops.yaml` files in a [`.sourceignore`](../components/source/gitrepositories#excluding-files) file at the root of your repo.
|
||||
|
||||
```sh
|
||||
touch .sourceignore
|
||||
echo '**/.sops.yaml' >> .sourceignore
|
||||
```
|
||||
|
||||
You can now commit your SOPS config.
|
||||
|
||||
## Encrypt secrets
|
||||
|
||||
Generate a Kubernetes secret manifest with kubectl:
|
||||
@@ -63,47 +169,17 @@ kubectl -n default create secret generic basic-auth \
|
||||
-o yaml > basic-auth.yaml
|
||||
```
|
||||
|
||||
Encrypt the secret with sops using your GPG key:
|
||||
Encrypt the secret with SOPS using your GPG key:
|
||||
|
||||
```sh
|
||||
sops --encrypt \
|
||||
--pgp=1F3D1CED2F865F5E59CA564553241F147E7C5FA4 \
|
||||
--encrypted-regex '^(data|stringData)$' \
|
||||
--in-place basic-auth.yaml
|
||||
sops --encrypt --in-place basic-auth.yaml
|
||||
```
|
||||
|
||||
!!! hint
|
||||
Note that you should encrypt only the `data` section. Encrypting the Kubernetes
|
||||
secret metadata, kind or apiVersion is not supported by kustomize-controller.
|
||||
|
||||
You can now commit the encrypted secret to your Git repository.
|
||||
|
||||
!!! hint
|
||||
Note that you shouldn't apply the encrypted secrets onto the cluster with kubectl. SOPS encrypted secrets are designed to be consumed by kustomize-controller.
|
||||
|
||||
## Configure secrets decryption
|
||||
|
||||
Registry the Git repository on your cluster:
|
||||
|
||||
```sh
|
||||
flux create source git my-secrets \
|
||||
--url=https://github.com/my-org/my-secrets
|
||||
```
|
||||
|
||||
Create a kustomization for reconciling the secrets on the cluster:
|
||||
|
||||
```sh
|
||||
flux create kustomization my-secrets \
|
||||
--source=my-secrets \
|
||||
--prune=true \
|
||||
--interval=10m \
|
||||
--decryption-provider=sops \
|
||||
--decryption-secret=sops-gpg
|
||||
```
|
||||
|
||||
Note that the `sops-gpg` can contain more than one key, sops will try to decrypt the
|
||||
secrets by iterating over all the private keys until it finds one that works.
|
||||
|
||||
### Using various cloud providers
|
||||
|
||||
When using AWS/GCP KMS, you don't have to include the gpg `secretRef` under
|
||||
@@ -210,5 +286,5 @@ Once the manifests have been pushed to the Git repository, the following happens
|
||||
|
||||
* source-controller pulls the changes from Git
|
||||
* kustomize-controller loads the GPG keys from the `sops-pgp` secret
|
||||
* kustomize-controller decrypts the Kubernetes secrets with sops and applies them on the cluster
|
||||
* kustomize-controller decrypts the Kubernetes secrets with SOPS and applies them on the cluster
|
||||
* kubelet creates the pods and mounts the secret as a volume or env variable inside the app container
|
||||
|
||||
@@ -52,10 +52,10 @@ flux create helmrelease sealed-secrets \
|
||||
--target-namespace=flux-system \
|
||||
--source=HelmRepository/sealed-secrets \
|
||||
--chart=sealed-secrets \
|
||||
--chart-version="1.10.x"
|
||||
--chart-version="1.13.x"
|
||||
```
|
||||
|
||||
With chart version `1.10.x` we configure helm-controller to automatically upgrade the release
|
||||
With chart version `1.13.x` we configure helm-controller to automatically upgrade the release
|
||||
when a new chart patch version is fetched by source-controller.
|
||||
|
||||
At startup, the sealed-secrets controller generates a 4096-bit RSA key pair and
|
||||
@@ -81,7 +81,7 @@ Generate a Kubernetes secret manifest with kubectl:
|
||||
kubectl -n default create secret generic basic-auth \
|
||||
--from-literal=user=admin \
|
||||
--from-literal=password=change-me \
|
||||
--dry-run \
|
||||
--dry-run=client \
|
||||
-o yaml > basic-auth.yaml
|
||||
```
|
||||
|
||||
@@ -141,7 +141,7 @@ spec:
|
||||
sourceRef:
|
||||
kind: HelmRepository
|
||||
name: stable
|
||||
version: "1.10.x"
|
||||
version: "1.13.x"
|
||||
interval: 1h0m0s
|
||||
releaseName: sealed-secrets
|
||||
targetNamespace: flux-system
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user