Compare commits
173 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2d749069e | ||
|
|
d4169aa4dd | ||
|
|
c06072d5cf | ||
|
|
7e2d235f53 | ||
|
|
b810aea6cc | ||
|
|
75a879c770 | ||
|
|
d4c5a137a1 | ||
|
|
d4718f6ff4 | ||
|
|
ac9b3d193d | ||
|
|
7c7e76f9f0 | ||
|
|
08401f62b2 | ||
|
|
69e26ca1d9 | ||
|
|
41aac68193 | ||
|
|
fcd38c9395 | ||
|
|
fe4b65972a | ||
|
|
4c576bf599 | ||
|
|
70d30fd52e | ||
|
|
803104578f | ||
|
|
030b6bc77c | ||
|
|
009413affd | ||
|
|
9e76787e9f | ||
|
|
b78bbd5b9d | ||
|
|
3e15e83926 | ||
|
|
1b327e9d4e | ||
|
|
7dd736954b | ||
|
|
6b98590461 | ||
|
|
8049634e4d | ||
|
|
adc7981f22 | ||
|
|
30e5389d02 | ||
|
|
b6a78f42ea | ||
|
|
e4fb8e75f9 | ||
|
|
2f35367a7f | ||
|
|
2d8db4f20d | ||
|
|
12a491f538 | ||
|
|
9503ecafb1 | ||
|
|
e927d39a27 | ||
|
|
ac50aea21f | ||
|
|
c45536723c | ||
|
|
fb1de8c649 | ||
|
|
e1c082e5ac | ||
|
|
1889b64b4e | ||
|
|
0cfdc5d674 | ||
|
|
96afee996a | ||
|
|
da9747a406 | ||
|
|
36d219e05c | ||
|
|
ea2de24ade | ||
|
|
f01911d0e2 | ||
|
|
43eb9327d5 | ||
|
|
ca212ac592 | ||
|
|
fe3e0efcf1 | ||
|
|
ed7a880287 | ||
|
|
e94853f023 | ||
|
|
cbecd8ab56 | ||
|
|
feaab54f70 | ||
|
|
02e12cf871 | ||
|
|
7aeec0a0c4 | ||
|
|
abeea06e72 | ||
|
|
4a55b828b1 | ||
|
|
6b9c0a5e48 | ||
|
|
e060873246 | ||
|
|
143609b9fb | ||
|
|
a22438b7fa | ||
|
|
34321983e7 | ||
|
|
44762933b3 | ||
|
|
2912d1d437 | ||
|
|
4885278691 | ||
|
|
8a7c94180b | ||
|
|
183b9a7ee0 | ||
|
|
0fc582d6fd | ||
|
|
c7a6ed53ca | ||
|
|
547e39d24c | ||
|
|
115b58fe49 | ||
|
|
613e270d00 | ||
|
|
c24e738973 | ||
|
|
e2fb6089c9 | ||
|
|
95eb7aede0 | ||
|
|
3cef177e24 | ||
|
|
c430556498 | ||
|
|
ff9c982df4 | ||
|
|
724c93c23d | ||
|
|
769e20423d | ||
|
|
d12e697769 | ||
|
|
874b05c5da | ||
|
|
1894b90d84 | ||
|
|
cdf5bf3c9e | ||
|
|
5f35bd4e00 | ||
|
|
12504c76d0 | ||
|
|
7346b1a762 | ||
|
|
f7d616d223 | ||
|
|
443e5b5539 | ||
|
|
f6c14c939d | ||
|
|
a602c57e5d | ||
|
|
9ae41899a8 | ||
|
|
cfdd5f0284 | ||
|
|
04b0a0a7ae | ||
|
|
83fcac1868 | ||
|
|
efb0ecb4f9 | ||
|
|
7498d516d4 | ||
|
|
2fe3362c3d | ||
|
|
6473331399 | ||
|
|
6f85363e58 | ||
|
|
02c0d3bd0d | ||
|
|
f1f4cc007a | ||
|
|
7293771766 | ||
|
|
25d065c211 | ||
|
|
bf14f47459 | ||
|
|
8576073b9d | ||
|
|
cbe1331815 | ||
|
|
998b763cf9 | ||
|
|
15e8f106ce | ||
|
|
9aee262054 | ||
|
|
c718336143 | ||
|
|
355ed94852 | ||
|
|
56c5e784fb | ||
|
|
0a30bc1024 | ||
|
|
a55548de07 | ||
|
|
b84e613b5e | ||
|
|
6b9e6cb9a5 | ||
|
|
f24c4034e2 | ||
|
|
797352e4fa | ||
|
|
7d742924f6 | ||
|
|
e19ea796b1 | ||
|
|
bcef28e80b | ||
|
|
4acef9d508 | ||
|
|
8128fc190d | ||
|
|
2ba0c4435e | ||
|
|
b8164717da | ||
|
|
ed88e9dec5 | ||
|
|
5ebb985b10 | ||
|
|
7f5f80286e | ||
|
|
3cd0bc9672 | ||
|
|
95f896e92c | ||
|
|
0b9e3d24ef | ||
|
|
3f0efc9435 | ||
|
|
64205cf523 | ||
|
|
38c62d46c7 | ||
|
|
b1ac3a26f4 | ||
|
|
b795e612f7 | ||
|
|
a1a2286794 | ||
|
|
8c5d83d9fe | ||
|
|
5130a154e4 | ||
|
|
938f2570ef | ||
|
|
97a7b4450f | ||
|
|
46fbc7c71b | ||
|
|
e35da1c890 | ||
|
|
9af6175302 | ||
|
|
e1def4f8ac | ||
|
|
e09078f697 | ||
|
|
7232ff9ea0 | ||
|
|
45876a723c | ||
|
|
1ece35e4c5 | ||
|
|
5dee903374 | ||
|
|
4dd20af7e0 | ||
|
|
b9fbdfc9a4 | ||
|
|
ab00e348a4 | ||
|
|
b5c0ae9d5a | ||
|
|
8e4044eed9 | ||
|
|
7034ef46af | ||
|
|
8dfbe952ae | ||
|
|
f1e9da56dc | ||
|
|
f924c5f76d | ||
|
|
57442e8faa | ||
|
|
95bfd3b3a4 | ||
|
|
2858e83fe1 | ||
|
|
5430152c7f | ||
|
|
3433079121 | ||
|
|
151b84b8fe | ||
|
|
e3e01cb5da | ||
|
|
c4c890d4e9 | ||
|
|
64a473db2e | ||
|
|
cc9bcbaefd | ||
|
|
787d491bd5 | ||
|
|
5c4991299c |
14
.github/aur/flux-bin/.SRCINFO.template
vendored
14
.github/aur/flux-bin/.SRCINFO.template
vendored
@@ -8,9 +8,15 @@ pkgbase = flux-bin
|
|||||||
arch = armv7h
|
arch = armv7h
|
||||||
arch = aarch64
|
arch = aarch64
|
||||||
license = APACHE
|
license = APACHE
|
||||||
source_x86_64 = flux-bin-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v1/flux_${PKGVER}_linux_amd64.tar.gz
|
optdepends = bash-completion: auto-completion for flux in Bash
|
||||||
source_armv6h = flux-bin-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v1/flux_${PKGVER}_linux_arm.tar.gz
|
optdepends = zsh-completions: auto-completion for flux in ZSH
|
||||||
source_armv7h = flux-bin-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v1/flux_${PKGVER}_linux_arm.tar.gz
|
source_x86_64 = ${PKGNAME}-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${PKGVER}/flux_${PKGVER}_linux_amd64.tar.gz
|
||||||
source_aarch64 = flux-bin-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v1/flux_${PKGVER}_linux_arm64.tar.gz
|
sha256sums_x86_64 = ${SHA256SUM_AMD64}
|
||||||
|
source_armv6h = ${PKGNAME}-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${PKGVER}/flux_${PKGVER}_linux_arm.tar.gz
|
||||||
|
sha256sums_armv6h = ${SHA256SUM_ARM}
|
||||||
|
source_armv7h = ${PKGNAME}-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${PKGVER}/flux_${PKGVER}_linux_arm.tar.gz
|
||||||
|
sha256sums_armv7h = ${SHA256SUM_ARM}
|
||||||
|
source_aarch64 = ${PKGNAME}-${PKGVER}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${PKGVER}/flux_${PKGVER}_linux_arm64.tar.gz
|
||||||
|
sha256sums_aarch64 = ${SHA256SUM_ARM64}
|
||||||
|
|
||||||
pkgname = flux-bin
|
pkgname = flux-bin
|
||||||
|
|||||||
4
.github/aur/flux-bin/PKGBUILD.template
vendored
4
.github/aur/flux-bin/PKGBUILD.template
vendored
@@ -8,8 +8,8 @@ pkgdesc="Open and extensible continuous delivery solution for Kubernetes"
|
|||||||
url="https://fluxcd.io/"
|
url="https://fluxcd.io/"
|
||||||
arch=("x86_64" "armv6h" "armv7h" "aarch64")
|
arch=("x86_64" "armv6h" "armv7h" "aarch64")
|
||||||
license=("APACHE")
|
license=("APACHE")
|
||||||
optdepends=('bash-completion: auto-completion for flux in Bash',
|
optdepends=('bash-completion: auto-completion for flux in Bash'
|
||||||
'zsh-completions: auto-completion for flux in ZSH')
|
'zsh-completions: auto-completion for flux in ZSH')
|
||||||
source_x86_64=(
|
source_x86_64=(
|
||||||
"${pkgname}-${pkgver}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${pkgver}/flux_${pkgver}_linux_amd64.tar.gz"
|
"${pkgname}-${pkgver}.tar.gz::https://github.com/fluxcd/flux2/releases/download/v${pkgver}/flux_${pkgver}_linux_amd64.tar.gz"
|
||||||
)
|
)
|
||||||
|
|||||||
10
.github/runners/prereq.sh
vendored
10
.github/runners/prereq.sh
vendored
@@ -18,11 +18,11 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
KIND_VERSION=0.11.1
|
KIND_VERSION=0.14.0
|
||||||
KUBECTL_VERSION=1.21.2
|
KUBECTL_VERSION=1.24.0
|
||||||
KUSTOMIZE_VERSION=4.1.3
|
KUSTOMIZE_VERSION=4.5.4
|
||||||
HELM_VERSION=3.7.2
|
HELM_VERSION=3.8.2
|
||||||
GITHUB_RUNNER_VERSION=2.285.1
|
GITHUB_RUNNER_VERSION=2.291.1
|
||||||
PACKAGES="apt-transport-https ca-certificates software-properties-common build-essential libssl-dev gnupg lsb-release jq pkg-config"
|
PACKAGES="apt-transport-https ca-certificates software-properties-common build-essential libssl-dev gnupg lsb-release jq pkg-config"
|
||||||
|
|
||||||
# install prerequisites
|
# install prerequisites
|
||||||
|
|||||||
12
.github/workflows/bootstrap.yaml
vendored
12
.github/workflows/bootstrap.yaml
vendored
@@ -12,18 +12,18 @@ jobs:
|
|||||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
|
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: Restore Go cache
|
- name: Restore Go cache
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go1.17-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go1.18-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go1.17-
|
${{ runner.os }}-go1.18-
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 1.17.x
|
go-version: 1.18.x
|
||||||
- name: Setup Kubernetes
|
- name: Setup Kubernetes
|
||||||
uses: engineerd/setup-kind@v0.5.0
|
uses: engineerd/setup-kind@v0.5.0
|
||||||
with:
|
with:
|
||||||
|
|||||||
8
.github/workflows/e2e-arm64.yaml
vendored
8
.github/workflows/e2e-arm64.yaml
vendored
@@ -3,7 +3,7 @@ name: e2e-arm64
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches: [ main, update-components, equinix-runners ]
|
branches: [ main, update-components ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
@@ -12,11 +12,11 @@ jobs:
|
|||||||
runs-on: [self-hosted, Linux, ARM64, equinix]
|
runs-on: [self-hosted, Linux, ARM64, equinix]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 1.17.x
|
go-version: 1.18.x
|
||||||
- name: Prepare
|
- name: Prepare
|
||||||
id: prep
|
id: prep
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
10
.github/workflows/e2e-azure.yaml
vendored
10
.github/workflows/e2e-azure.yaml
vendored
@@ -12,18 +12,18 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: Restore Go cache
|
- name: Restore Go cache
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go1.17-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go1.18-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go1.17-
|
${{ runner.os }}-go1.18-
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.17.x
|
go-version: 1.18.x
|
||||||
- name: Install libgit2
|
- name: Install libgit2
|
||||||
run: |
|
run: |
|
||||||
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138
|
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138
|
||||||
|
|||||||
51
.github/workflows/e2e.yaml
vendored
51
.github/workflows/e2e.yaml
vendored
@@ -2,27 +2,32 @@ name: e2e
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main, e2e* ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main, oci ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
kind:
|
kind:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
services:
|
||||||
|
registry:
|
||||||
|
image: registry:2
|
||||||
|
ports:
|
||||||
|
- 5000:5000
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: Restore Go cache
|
- name: Restore Go cache
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
path: ~/go/pkg/mod
|
||||||
key: ${{ runner.os }}-go1.17-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go1.18-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go1.17-
|
${{ runner.os }}-go1.18-
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 1.17.x
|
go-version: 1.18.x
|
||||||
- name: Setup Kubernetes
|
- name: Setup Kubernetes
|
||||||
uses: engineerd/setup-kind@v0.5.0
|
uses: engineerd/setup-kind@v0.5.0
|
||||||
with:
|
with:
|
||||||
@@ -168,6 +173,36 @@ jobs:
|
|||||||
- name: flux delete source git
|
- name: flux delete source git
|
||||||
run: |
|
run: |
|
||||||
/tmp/flux delete source git podinfo --silent
|
/tmp/flux delete source git podinfo --silent
|
||||||
|
- name: flux oci artifacts
|
||||||
|
run: |
|
||||||
|
/tmp/flux push artifact oci://localhost:5000/fluxcd/flux:${{ github.sha }} \
|
||||||
|
--path="./manifests" \
|
||||||
|
--source="${{ github.repositoryUrl }}" \
|
||||||
|
--revision="${{ github.ref }}/${{ github.sha }}"
|
||||||
|
/tmp/flux tag artifact oci://localhost:5000/fluxcd/flux:${{ github.sha }} \
|
||||||
|
--tag latest
|
||||||
|
/tmp/flux list artifacts oci://localhost:5000/fluxcd/flux
|
||||||
|
- name: flux oci repositories
|
||||||
|
run: |
|
||||||
|
/tmp/flux create source oci podinfo-oci \
|
||||||
|
--url oci://ghcr.io/stefanprodan/manifests/podinfo \
|
||||||
|
--tag-semver 6.1.x \
|
||||||
|
--interval 10m
|
||||||
|
/tmp/flux create kustomization podinfo-oci \
|
||||||
|
--source=OCIRepository/podinfo-oci \
|
||||||
|
--path="./kustomize" \
|
||||||
|
--prune=true \
|
||||||
|
--interval=5m \
|
||||||
|
--target-namespace=default \
|
||||||
|
--wait=true \
|
||||||
|
--health-check-timeout=3m
|
||||||
|
/tmp/flux reconcile source oci podinfo-oci
|
||||||
|
/tmp/flux suspend source oci podinfo-oci
|
||||||
|
/tmp/flux get sources oci
|
||||||
|
/tmp/flux resume source oci podinfo-oci
|
||||||
|
/tmp/flux export source oci podinfo-oci
|
||||||
|
/tmp/flux delete ks podinfo-oci --silent
|
||||||
|
/tmp/flux delete source oci podinfo-oci --silent
|
||||||
- name: flux create tenant
|
- name: flux create tenant
|
||||||
run: |
|
run: |
|
||||||
/tmp/flux create tenant dev-team --with-namespace=apps
|
/tmp/flux create tenant dev-team --with-namespace=apps
|
||||||
|
|||||||
21
.github/workflows/rebase.yaml
vendored
21
.github/workflows/rebase.yaml
vendored
@@ -1,21 +0,0 @@
|
|||||||
name: rebase
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
types: [ opened ]
|
|
||||||
issue_comment:
|
|
||||||
types: [ created ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
rebase:
|
|
||||||
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase') && (github.event.comment.author_association == 'CONTRIBUTOR' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER')
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout the latest code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- name: Automatic Rebase
|
|
||||||
uses: cirrus-actions/rebase@1.3.1
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
|
|
||||||
16
.github/workflows/release.yaml
vendored
16
.github/workflows/release.yaml
vendored
@@ -14,18 +14,18 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: Unshallow
|
- name: Unshallow
|
||||||
run: git fetch --prune --unshallow
|
run: git fetch --prune --unshallow
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 1.17.x
|
go-version: 1.18.x
|
||||||
- name: Setup QEMU
|
- name: Setup QEMU
|
||||||
uses: docker/setup-qemu-action@v1
|
uses: docker/setup-qemu-action@v2
|
||||||
- name: Setup Docker Buildx
|
- name: Setup Docker Buildx
|
||||||
id: buildx
|
id: buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v2
|
||||||
- name: Setup Syft
|
- name: Setup Syft
|
||||||
uses: anchore/sbom-action/download-syft@v0
|
uses: anchore/sbom-action/download-syft@v0
|
||||||
- name: Setup Cosign
|
- name: Setup Cosign
|
||||||
@@ -33,13 +33,13 @@ jobs:
|
|||||||
- name: Setup Kustomize
|
- name: Setup Kustomize
|
||||||
uses: fluxcd/pkg//actions/kustomize@main
|
uses: fluxcd/pkg//actions/kustomize@main
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: fluxcdbot
|
username: fluxcdbot
|
||||||
password: ${{ secrets.GHCR_TOKEN }}
|
password: ${{ secrets.GHCR_TOKEN }}
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
username: fluxcdbot
|
username: fluxcdbot
|
||||||
password: ${{ secrets.DOCKER_FLUXCD_PASSWORD }}
|
password: ${{ secrets.DOCKER_FLUXCD_PASSWORD }}
|
||||||
@@ -73,7 +73,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Run GoReleaser
|
- name: Run GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@v1
|
uses: goreleaser/goreleaser-action@v3
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
args: release --release-notes=output/notes.md --skip-validate
|
args: release --release-notes=output/notes.md --skip-validate
|
||||||
|
|||||||
18
.github/workflows/scan.yaml
vendored
18
.github/workflows/scan.yaml
vendored
@@ -1,4 +1,4 @@
|
|||||||
name: Scan
|
name: scan
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -8,12 +8,16 @@ on:
|
|||||||
schedule:
|
schedule:
|
||||||
- cron: '18 10 * * 3'
|
- cron: '18 10 * * 3'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read # for actions/checkout to fetch code
|
||||||
|
security-events: write # for codeQL to write security events
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
fossa:
|
fossa:
|
||||||
name: FOSSA
|
name: FOSSA
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Run FOSSA scan and upload build data
|
- name: Run FOSSA scan and upload build data
|
||||||
uses: fossa-contrib/fossa-action@v1
|
uses: fossa-contrib/fossa-action@v1
|
||||||
with:
|
with:
|
||||||
@@ -26,7 +30,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
|
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Kustomize
|
- name: Setup Kustomize
|
||||||
uses: fluxcd/pkg//actions/kustomize@main
|
uses: fluxcd/pkg//actions/kustomize@main
|
||||||
- name: Build manifests
|
- name: Build manifests
|
||||||
@@ -49,12 +53,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v1
|
uses: github/codeql-action/init@v2
|
||||||
with:
|
with:
|
||||||
languages: go
|
languages: go
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v1
|
uses: github/codeql-action/autobuild@v2
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v1
|
uses: github/codeql-action/analyze@v2
|
||||||
|
|||||||
6
.github/workflows/update.yaml
vendored
6
.github/workflows/update.yaml
vendored
@@ -12,11 +12,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code
|
- name: Check out code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 1.17.x
|
go-version: 1.18.x
|
||||||
- name: Update component versions
|
- name: Update component versions
|
||||||
id: update
|
id: update
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
FROM alpine:3.15 as builder
|
FROM alpine:3.16 as builder
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates curl
|
RUN apk add --no-cache ca-certificates curl
|
||||||
|
|
||||||
ARG ARCH=linux/amd64
|
ARG ARCH=linux/amd64
|
||||||
ARG KUBECTL_VER=1.23.1
|
ARG KUBECTL_VER=1.24.1
|
||||||
|
|
||||||
RUN curl -sL https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VER}/bin/${ARCH}/kubectl \
|
RUN curl -sL https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VER}/bin/${ARCH}/kubectl \
|
||||||
-o /usr/local/bin/kubectl && chmod +x /usr/local/bin/kubectl && \
|
-o /usr/local/bin/kubectl && chmod +x /usr/local/bin/kubectl && \
|
||||||
kubectl version --client=true
|
kubectl version --client=true
|
||||||
|
|
||||||
FROM alpine:3.15 as flux-cli
|
FROM alpine:3.16 as flux-cli
|
||||||
|
|
||||||
# Create minimal nsswitch.conf file to prioritize the usage of /etc/hosts over DNS queries.
|
# Create minimal nsswitch.conf file to prioritize the usage of /etc/hosts over DNS queries.
|
||||||
# https://github.com/gliderlabs/docker-alpine/issues/367#issuecomment-354316460
|
# https://github.com/gliderlabs/docker-alpine/issues/367#issuecomment-354316460
|
||||||
|
|||||||
18
MAINTAINERS
18
MAINTAINERS
@@ -2,19 +2,7 @@ The maintainers are generally available in Slack at
|
|||||||
https://cloud-native.slack.com in #flux (https://cloud-native.slack.com/messages/CLAJ40HV3)
|
https://cloud-native.slack.com in #flux (https://cloud-native.slack.com/messages/CLAJ40HV3)
|
||||||
(obtain an invitation at https://slack.cncf.io/).
|
(obtain an invitation at https://slack.cncf.io/).
|
||||||
|
|
||||||
These maintainers are shared with other Flux v2-related git
|
The Flux2 maintainers team is identical with the core maintainers of the project
|
||||||
repositories under https://github.com/fluxcd, as noted in their
|
as listed in
|
||||||
respective MAINTAINERS files.
|
|
||||||
|
|
||||||
For convenience, they are reflected in the GitHub team
|
https://github.com/fluxcd/community/blob/main/CORE-MAINTAINERS
|
||||||
@fluxcd/flux2-maintainers -- if the list here changes, that team also
|
|
||||||
should.
|
|
||||||
|
|
||||||
In alphabetical order:
|
|
||||||
|
|
||||||
Aurel Canciu, NexHealth <aurel.canciu@nexhealth.com> (github: @relu, slack: relu)
|
|
||||||
Hidde Beydals, Weaveworks <hidde@weave.works> (github: @hiddeco, slack: hidde)
|
|
||||||
Max Jonas Werner, D2iQ <max@e13.dev> (github: @makkes, slack: max)
|
|
||||||
Philip Laine, Xenit <philip.laine@xenit.se> (github: @phillebaba, slack: phillebaba)
|
|
||||||
Stefan Prodan, Weaveworks <stefan@weave.works> (github: @stefanprodan, slack: stefanprodan)
|
|
||||||
Sunny, Weaveworks <sunny@weave.works> (github: @darkowlzz, slack: darkowlzz)
|
|
||||||
|
|||||||
4
Makefile
4
Makefile
@@ -1,4 +1,5 @@
|
|||||||
VERSION?=$(shell grep 'VERSION' cmd/flux/main.go | awk '{ print $$4 }' | head -n 1 | tr -d '"')
|
VERSION?=$(shell grep 'VERSION' cmd/flux/main.go | awk '{ print $$4 }' | head -n 1 | tr -d '"')
|
||||||
|
DEV_VERSION?=0.0.0-$(shell git rev-parse --abbrev-ref HEAD)-$(shell git rev-parse --short HEAD)-$(shell date +%s)
|
||||||
EMBEDDED_MANIFESTS_TARGET=cmd/flux/.manifests.done
|
EMBEDDED_MANIFESTS_TARGET=cmd/flux/.manifests.done
|
||||||
TEST_KUBECONFIG?=/tmp/flux-e2e-test-kubeconfig
|
TEST_KUBECONFIG?=/tmp/flux-e2e-test-kubeconfig
|
||||||
# Architecture to use envtest with
|
# Architecture to use envtest with
|
||||||
@@ -55,6 +56,9 @@ $(EMBEDDED_MANIFESTS_TARGET): $(call rwildcard,manifests/,*.yaml *.json)
|
|||||||
build: $(EMBEDDED_MANIFESTS_TARGET)
|
build: $(EMBEDDED_MANIFESTS_TARGET)
|
||||||
CGO_ENABLED=0 go build -ldflags="-s -w -X main.VERSION=$(VERSION)" -o ./bin/flux ./cmd/flux
|
CGO_ENABLED=0 go build -ldflags="-s -w -X main.VERSION=$(VERSION)" -o ./bin/flux ./cmd/flux
|
||||||
|
|
||||||
|
build-dev: $(EMBEDDED_MANIFESTS_TARGET)
|
||||||
|
CGO_ENABLED=0 go build -ldflags="-s -w -X main.VERSION=$(DEV_VERSION)" -o ./bin/flux ./cmd/flux
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install:
|
install:
|
||||||
CGO_ENABLED=0 go install ./cmd/flux
|
CGO_ENABLED=0 go install ./cmd/flux
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ You can download a specific version with:
|
|||||||
- name: Setup Flux CLI
|
- name: Setup Flux CLI
|
||||||
uses: fluxcd/flux2/action@main
|
uses: fluxcd/flux2/action@main
|
||||||
with:
|
with:
|
||||||
version: 0.8.0
|
version: 0.32.0
|
||||||
```
|
```
|
||||||
|
|
||||||
### Automate Flux updates
|
### Automate Flux updates
|
||||||
@@ -74,6 +74,92 @@ jobs:
|
|||||||
${{ steps.update.outputs.flux_version }}
|
${{ steps.update.outputs.flux_version }}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Push Kubernetes manifests to container registries
|
||||||
|
|
||||||
|
Example workflow for publishing Kubernetes manifests bundled as OCI artifacts to GitHub Container Registry:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: push-artifact-staging
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'main'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
packages: write # needed for ghcr.io access
|
||||||
|
|
||||||
|
env:
|
||||||
|
OCI_REPO: "oci://ghcr.io/my-org/manifests/${{ github.event.repository.name }}"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
kubernetes:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Flux CLI
|
||||||
|
uses: fluxcd/flux2/action@main
|
||||||
|
- name: Login to GHCR
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Generate manifests
|
||||||
|
run: |
|
||||||
|
kustomize build ./manifests/staging > ./deploy/app.yaml
|
||||||
|
- name: Push manifests
|
||||||
|
run: |
|
||||||
|
flux push artifact $OCI_REPO:$(git rev-parse --short HEAD) \
|
||||||
|
--path="./deploy" \
|
||||||
|
--source="$(git config --get remote.origin.url)" \
|
||||||
|
--revision="$(git branch --show-current)/$(git rev-parse HEAD)"
|
||||||
|
- name: Deploy manifests to staging
|
||||||
|
run: |
|
||||||
|
flux tag artifact $OCI_REPO:$(git rev-parse --short HEAD) --tag staging
|
||||||
|
```
|
||||||
|
|
||||||
|
Example workflow for publishing Kubernetes manifests bundled as OCI artifacts to Docker Hub:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: push-artifact-production
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
OCI_REPO: "oci://docker.io/my-org/app-config"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
kubernetes:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Flux CLI
|
||||||
|
uses: fluxcd/flux2/action@main
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
- name: Generate manifests
|
||||||
|
run: |
|
||||||
|
kustomize build ./manifests/production > ./deploy/app.yaml
|
||||||
|
- name: Push manifests
|
||||||
|
run: |
|
||||||
|
flux push artifact $OCI_REPO:$(git tag --points-at HEAD) \
|
||||||
|
--path="./deploy" \
|
||||||
|
--source="$(git config --get remote.origin.url)" \
|
||||||
|
--revision="$(git tag --points-at HEAD)/$(git rev-parse HEAD)"
|
||||||
|
- name: Deploy manifests to production
|
||||||
|
run: |
|
||||||
|
flux tag artifact $OCI_REPO:$(git tag --points-at HEAD) --tag production
|
||||||
|
```
|
||||||
|
|
||||||
### End-to-end testing
|
### End-to-end testing
|
||||||
|
|
||||||
Example workflow for running Flux in Kubernetes Kind:
|
Example workflow for running Flux in Kubernetes Kind:
|
||||||
|
|||||||
Binary file not shown.
@@ -19,13 +19,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ func buildEmbeddedManifestBase() (string, error) {
|
|||||||
if !isEmbeddedVersion(bootstrapArgs.version) {
|
if !isEmbeddedVersion(bootstrapArgs.version) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
tmpBaseDir, err := os.MkdirTemp("", "flux-manifests-")
|
tmpBaseDir, err := manifestgen.MkdirTempAbs("", "flux-manifests-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import (
|
|||||||
"github.com/fluxcd/flux2/internal/bootstrap/provider"
|
"github.com/fluxcd/flux2/internal/bootstrap/provider"
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
||||||
@@ -165,7 +166,7 @@ func bootstrapBServerCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Lazy go-git repository
|
// Lazy go-git repository
|
||||||
tmpDir, err := os.MkdirTemp("", "flux-bootstrap-")
|
tmpDir, err := manifestgen.MkdirTempAbs("", "flux-bootstrap-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import (
|
|||||||
"github.com/fluxcd/flux2/internal/bootstrap/git/gogit"
|
"github.com/fluxcd/flux2/internal/bootstrap/git/gogit"
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
||||||
@@ -66,12 +67,13 @@ command will perform an upgrade if needed.`,
|
|||||||
}
|
}
|
||||||
|
|
||||||
type gitFlags struct {
|
type gitFlags struct {
|
||||||
url string
|
url string
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
path flags.SafeRelativePath
|
path flags.SafeRelativePath
|
||||||
username string
|
username string
|
||||||
password string
|
password string
|
||||||
silent bool
|
silent bool
|
||||||
|
insecureHttpAllowed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -87,6 +89,7 @@ func init() {
|
|||||||
bootstrapGitCmd.Flags().StringVarP(&gitArgs.username, "username", "u", "git", "basic authentication username")
|
bootstrapGitCmd.Flags().StringVarP(&gitArgs.username, "username", "u", "git", "basic authentication username")
|
||||||
bootstrapGitCmd.Flags().StringVarP(&gitArgs.password, "password", "p", "", "basic authentication password")
|
bootstrapGitCmd.Flags().StringVarP(&gitArgs.password, "password", "p", "", "basic authentication password")
|
||||||
bootstrapGitCmd.Flags().BoolVarP(&gitArgs.silent, "silent", "s", false, "assumes the deploy key is already setup, skips confirmation")
|
bootstrapGitCmd.Flags().BoolVarP(&gitArgs.silent, "silent", "s", false, "assumes the deploy key is already setup, skips confirmation")
|
||||||
|
bootstrapGitCmd.Flags().BoolVar(&gitArgs.insecureHttpAllowed, "allow-insecure-http", false, "allows http git url connections")
|
||||||
|
|
||||||
bootstrapCmd.AddCommand(bootstrapGitCmd)
|
bootstrapCmd.AddCommand(bootstrapGitCmd)
|
||||||
}
|
}
|
||||||
@@ -137,7 +140,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
defer os.RemoveAll(manifestsBase)
|
defer os.RemoveAll(manifestsBase)
|
||||||
|
|
||||||
// Lazy go-git repository
|
// Lazy go-git repository
|
||||||
tmpDir, err := os.MkdirTemp("", "flux-bootstrap-")
|
tmpDir, err := manifestgen.MkdirTempAbs("", "flux-bootstrap-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
||||||
}
|
}
|
||||||
@@ -268,6 +271,14 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
// SSH-agent is attempted.
|
// SSH-agent is attempted.
|
||||||
func transportForURL(u *url.URL) (transport.AuthMethod, error) {
|
func transportForURL(u *url.URL) (transport.AuthMethod, error) {
|
||||||
switch u.Scheme {
|
switch u.Scheme {
|
||||||
|
case "http":
|
||||||
|
if !gitArgs.insecureHttpAllowed {
|
||||||
|
return nil, fmt.Errorf("scheme http is insecure, pass --allow-insecure-http=true to allow it")
|
||||||
|
}
|
||||||
|
return &http.BasicAuth{
|
||||||
|
Username: gitArgs.username,
|
||||||
|
Password: gitArgs.password,
|
||||||
|
}, nil
|
||||||
case "https":
|
case "https":
|
||||||
return &http.BasicAuth{
|
return &http.BasicAuth{
|
||||||
Username: gitArgs.username,
|
Username: gitArgs.username,
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import (
|
|||||||
"github.com/fluxcd/flux2/internal/bootstrap/provider"
|
"github.com/fluxcd/flux2/internal/bootstrap/provider"
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
||||||
@@ -161,7 +162,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Lazy go-git repository
|
// Lazy go-git repository
|
||||||
tmpDir, err := os.MkdirTemp("", "flux-bootstrap-")
|
tmpDir, err := manifestgen.MkdirTempAbs("", "flux-bootstrap-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import (
|
|||||||
"github.com/fluxcd/flux2/internal/bootstrap/provider"
|
"github.com/fluxcd/flux2/internal/bootstrap/provider"
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
"github.com/fluxcd/flux2/pkg/manifestgen/sync"
|
||||||
@@ -172,7 +173,7 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Lazy go-git repository
|
// Lazy go-git repository
|
||||||
tmpDir, err := os.MkdirTemp("", "flux-bootstrap-")
|
tmpDir, err := manifestgen.MkdirTempAbs("", "flux-bootstrap-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
return fmt.Errorf("failed to create temporary working dir: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
73
cmd/flux/build_artifact.go
Normal file
73
cmd/flux/build_artifact.go
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
oci "github.com/fluxcd/pkg/oci/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
var buildArtifactCmd = &cobra.Command{
|
||||||
|
Use: "artifact",
|
||||||
|
Short: "Build artifact",
|
||||||
|
Long: `The build artifact command creates a tgz file with the manifests from the given directory.`,
|
||||||
|
Example: ` # Build the given manifests directory into an artifact
|
||||||
|
flux build artifact --path ./path/to/local/manifests --output ./path/to/artifact.tgz
|
||||||
|
|
||||||
|
# List the files bundled in the artifact
|
||||||
|
tar -ztvf ./path/to/artifact.tgz
|
||||||
|
`,
|
||||||
|
RunE: buildArtifactCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
type buildArtifactFlags struct {
|
||||||
|
output string
|
||||||
|
path string
|
||||||
|
}
|
||||||
|
|
||||||
|
var buildArtifactArgs buildArtifactFlags
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
buildArtifactCmd.Flags().StringVar(&buildArtifactArgs.path, "path", "", "Path to the directory where the Kubernetes manifests are located.")
|
||||||
|
buildArtifactCmd.Flags().StringVarP(&buildArtifactArgs.output, "output", "o", "artifact.tgz", "Path to where the artifact tgz file should be written.")
|
||||||
|
buildCmd.AddCommand(buildArtifactCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
if buildArtifactArgs.path == "" {
|
||||||
|
return fmt.Errorf("invalid path %q", buildArtifactArgs.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fs, err := os.Stat(buildArtifactArgs.path); err != nil || !fs.IsDir() {
|
||||||
|
return fmt.Errorf("invalid path '%s', must point to an existing directory", buildArtifactArgs.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Actionf("building artifact from %s", buildArtifactArgs.path)
|
||||||
|
|
||||||
|
ociClient := oci.NewLocalClient()
|
||||||
|
if err := ociClient.Build(buildArtifactArgs.output, buildArtifactArgs.path); err != nil {
|
||||||
|
return fmt.Errorf("bulding artifact failed, error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Successf("artifact created at %s", buildArtifactArgs.output)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/Masterminds/semver/v3"
|
"github.com/Masterminds/semver/v3"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
v1 "k8s.io/api/apps/v1"
|
v1 "k8s.io/api/apps/v1"
|
||||||
|
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
@@ -95,9 +96,17 @@ func runCheckCmd(cmd *cobra.Command, args []string) error {
|
|||||||
if !componentsCheck() {
|
if !componentsCheck() {
|
||||||
checkFailed = true
|
checkFailed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Actionf("checking crds")
|
||||||
|
if !crdsCheck() {
|
||||||
|
checkFailed = true
|
||||||
|
}
|
||||||
|
|
||||||
if checkFailed {
|
if checkFailed {
|
||||||
|
logger.Failuref("check failed")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Successf("all checks passed")
|
logger.Successf("all checks passed")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -191,7 +200,14 @@ func componentsCheck() bool {
|
|||||||
ok := true
|
ok := true
|
||||||
selector := client.MatchingLabels{manifestgen.PartOfLabelKey: manifestgen.PartOfLabelValue}
|
selector := client.MatchingLabels{manifestgen.PartOfLabelKey: manifestgen.PartOfLabelValue}
|
||||||
var list v1.DeploymentList
|
var list v1.DeploymentList
|
||||||
if err := kubeClient.List(ctx, &list, client.InNamespace(*kubeconfigArgs.Namespace), selector); err == nil {
|
ns := *kubeconfigArgs.Namespace
|
||||||
|
if err := kubeClient.List(ctx, &list, client.InNamespace(ns), selector); err == nil {
|
||||||
|
if len(list.Items) == 0 {
|
||||||
|
logger.Failuref("no controllers found in the '%s' namespace with the label selector '%s=%s'",
|
||||||
|
ns, manifestgen.PartOfLabelKey, manifestgen.PartOfLabelValue)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
for _, d := range list.Items {
|
for _, d := range list.Items {
|
||||||
if ref, err := buildComponentObjectRefs(d.Name); err == nil {
|
if ref, err := buildComponentObjectRefs(d.Name); err == nil {
|
||||||
if err := statusChecker.Assess(ref...); err != nil {
|
if err := statusChecker.Assess(ref...); err != nil {
|
||||||
@@ -205,3 +221,34 @@ func componentsCheck() bool {
|
|||||||
}
|
}
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func crdsCheck() bool {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
ok := true
|
||||||
|
selector := client.MatchingLabels{manifestgen.PartOfLabelKey: manifestgen.PartOfLabelValue}
|
||||||
|
var list apiextensionsv1.CustomResourceDefinitionList
|
||||||
|
if err := kubeClient.List(ctx, &list, client.InNamespace(*kubeconfigArgs.Namespace), selector); err == nil {
|
||||||
|
if len(list.Items) == 0 {
|
||||||
|
logger.Failuref("no crds found with the label selector '%s=%s'",
|
||||||
|
manifestgen.PartOfLabelKey, manifestgen.PartOfLabelValue)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, crd := range list.Items {
|
||||||
|
if len(crd.Status.StoredVersions) > 0 {
|
||||||
|
logger.Successf(crd.Name + "/" + crd.Status.StoredVersions[0])
|
||||||
|
} else {
|
||||||
|
ok = false
|
||||||
|
logger.Failuref("no stored versions for %s", crd.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
"k8s.io/apimachinery/pkg/version"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCheckPre(t *testing.T) {
|
func TestCheckPre(t *testing.T) {
|
||||||
@@ -35,17 +34,19 @@ func TestCheckPre(t *testing.T) {
|
|||||||
t.Fatalf("Error running utils.ExecKubectlCommand: %v", err.Error())
|
t.Fatalf("Error running utils.ExecKubectlCommand: %v", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var versions map[string]version.Info
|
var versions map[string]interface{}
|
||||||
if err := json.Unmarshal([]byte(jsonOutput), &versions); err != nil {
|
if err := json.Unmarshal([]byte(jsonOutput), &versions); err != nil {
|
||||||
t.Fatalf("Error unmarshalling: %v", err.Error())
|
t.Fatalf("Error unmarshalling '%s': %v", jsonOutput, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
serverVersion := strings.TrimPrefix(versions["serverVersion"].GitVersion, "v")
|
serverGitVersion := strings.TrimPrefix(
|
||||||
|
versions["serverVersion"].(map[string]interface{})["gitVersion"].(string),
|
||||||
|
"v")
|
||||||
|
|
||||||
cmd := cmdTestCase{
|
cmd := cmdTestCase{
|
||||||
args: "check --pre",
|
args: "check --pre",
|
||||||
assert: assertGoldenTemplateFile("testdata/check/check_pre.golden", map[string]string{
|
assert: assertGoldenTemplateFile("testdata/check/check_pre.golden", map[string]string{
|
||||||
"serverVersion": serverVersion,
|
"serverVersion": serverGitVersion,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
cmd.runTestCmd(t)
|
cmd.runTestCmd(t)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
@@ -109,23 +110,26 @@ var createHelmReleaseCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type helmReleaseFlags struct {
|
type helmReleaseFlags struct {
|
||||||
name string
|
name string
|
||||||
source flags.HelmChartSource
|
source flags.HelmChartSource
|
||||||
dependsOn []string
|
dependsOn []string
|
||||||
chart string
|
chart string
|
||||||
chartVersion string
|
chartVersion string
|
||||||
targetNamespace string
|
targetNamespace string
|
||||||
createNamespace bool
|
createNamespace bool
|
||||||
valuesFiles []string
|
valuesFiles []string
|
||||||
valuesFrom flags.HelmReleaseValuesFrom
|
valuesFrom []string
|
||||||
saName string
|
saName string
|
||||||
crds flags.CRDsPolicy
|
crds flags.CRDsPolicy
|
||||||
reconcileStrategy string
|
reconcileStrategy string
|
||||||
chartInterval time.Duration
|
chartInterval time.Duration
|
||||||
|
kubeConfigSecretRef string
|
||||||
}
|
}
|
||||||
|
|
||||||
var helmReleaseArgs helmReleaseFlags
|
var helmReleaseArgs helmReleaseFlags
|
||||||
|
|
||||||
|
var supportedHelmReleaseValuesFromKinds = []string{"Secret", "ConfigMap"}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.name, "release-name", "", "name used for the Helm release, defaults to a composition of '[<target-namespace>-]<HelmRelease-name>'")
|
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.name, "release-name", "", "name used for the Helm release, defaults to a composition of '[<target-namespace>-]<HelmRelease-name>'")
|
||||||
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.source, "source", helmReleaseArgs.source.Description())
|
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.source, "source", helmReleaseArgs.source.Description())
|
||||||
@@ -138,8 +142,9 @@ func init() {
|
|||||||
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.reconcileStrategy, "reconcile-strategy", "ChartVersion", "the reconcile strategy for helm chart created by the helm release(accepted values: Revision and ChartRevision)")
|
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.reconcileStrategy, "reconcile-strategy", "ChartVersion", "the reconcile strategy for helm chart created by the helm release(accepted values: Revision and ChartRevision)")
|
||||||
createHelmReleaseCmd.Flags().DurationVarP(&helmReleaseArgs.chartInterval, "chart-interval", "", 0, "the interval of which to check for new chart versions")
|
createHelmReleaseCmd.Flags().DurationVarP(&helmReleaseArgs.chartInterval, "chart-interval", "", 0, "the interval of which to check for new chart versions")
|
||||||
createHelmReleaseCmd.Flags().StringSliceVar(&helmReleaseArgs.valuesFiles, "values", nil, "local path to values.yaml files, also accepts comma-separated values")
|
createHelmReleaseCmd.Flags().StringSliceVar(&helmReleaseArgs.valuesFiles, "values", nil, "local path to values.yaml files, also accepts comma-separated values")
|
||||||
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.valuesFrom, "values-from", helmReleaseArgs.valuesFrom.Description())
|
createHelmReleaseCmd.Flags().StringSliceVar(&helmReleaseArgs.valuesFrom, "values-from", nil, "a Kubernetes object reference that contains the values.yaml data key in the format '<kind>/<name>', where kind must be one of: (Secret,ConfigMap)")
|
||||||
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.crds, "crds", helmReleaseArgs.crds.Description())
|
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.crds, "crds", helmReleaseArgs.crds.Description())
|
||||||
|
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.kubeConfigSecretRef, "kubeconfig-secret-ref", "", "the name of the Kubernetes Secret that contains a key with the kubeconfig file for connecting to a remote cluster")
|
||||||
createCmd.AddCommand(createHelmReleaseCmd)
|
createCmd.AddCommand(createHelmReleaseCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,6 +199,14 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if helmReleaseArgs.kubeConfigSecretRef != "" {
|
||||||
|
helmRelease.Spec.KubeConfig = &helmv2.KubeConfig{
|
||||||
|
SecretRef: meta.SecretKeyReference{
|
||||||
|
Name: helmReleaseArgs.kubeConfigSecretRef,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if helmReleaseArgs.chartInterval != 0 {
|
if helmReleaseArgs.chartInterval != 0 {
|
||||||
helmRelease.Spec.Chart.Spec.Interval = &metav1.Duration{
|
helmRelease.Spec.Chart.Spec.Interval = &metav1.Duration{
|
||||||
Duration: helmReleaseArgs.chartInterval,
|
Duration: helmReleaseArgs.chartInterval,
|
||||||
@@ -250,11 +263,25 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
helmRelease.Spec.Values = &apiextensionsv1.JSON{Raw: jsonRaw}
|
helmRelease.Spec.Values = &apiextensionsv1.JSON{Raw: jsonRaw}
|
||||||
}
|
}
|
||||||
|
|
||||||
if helmReleaseArgs.valuesFrom.String() != "" {
|
if len(helmReleaseArgs.valuesFrom) != 0 {
|
||||||
helmRelease.Spec.ValuesFrom = []helmv2.ValuesReference{{
|
values := []helmv2.ValuesReference{}
|
||||||
Kind: helmReleaseArgs.valuesFrom.Kind,
|
for _, value := range helmReleaseArgs.valuesFrom {
|
||||||
Name: helmReleaseArgs.valuesFrom.Name,
|
sourceKind, sourceName := utils.ParseObjectKindName(value)
|
||||||
}}
|
if sourceKind == "" {
|
||||||
|
return fmt.Errorf("invalid Kubernetes object reference '%s', must be in format <kind>/<name>", value)
|
||||||
|
}
|
||||||
|
cleanSourceKind, ok := utils.ContainsEqualFoldItemString(supportedHelmReleaseValuesFromKinds, sourceKind)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("reference kind '%s' is not supported, must be one of: %s",
|
||||||
|
sourceKind, strings.Join(supportedHelmReleaseValuesFromKinds, ", "))
|
||||||
|
}
|
||||||
|
|
||||||
|
values = append(values, helmv2.ValuesReference{
|
||||||
|
Name: sourceName,
|
||||||
|
Kind: cleanSourceKind,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
helmRelease.Spec.ValuesFrom = values
|
||||||
}
|
}
|
||||||
|
|
||||||
if createArgs.export {
|
if createArgs.export {
|
||||||
|
|||||||
@@ -42,22 +42,21 @@ var createKsCmd = &cobra.Command{
|
|||||||
Use: "kustomization [name]",
|
Use: "kustomization [name]",
|
||||||
Aliases: []string{"ks"},
|
Aliases: []string{"ks"},
|
||||||
Short: "Create or update a Kustomization resource",
|
Short: "Create or update a Kustomization resource",
|
||||||
Long: "The kustomization source create command generates a Kustomize resource for a given source.",
|
Long: "The create command generates a Kustomization resource for a given source.",
|
||||||
Example: ` # Create a Kustomization resource from a source at a given path
|
Example: ` # Create a Kustomization resource from a source at a given path
|
||||||
flux create kustomization contour \
|
flux create kustomization kyverno \
|
||||||
--source=GitRepository/contour \
|
--source=GitRepository/kyverno \
|
||||||
--path="./examples/contour/" \
|
--path="./config/release" \
|
||||||
--prune=true \
|
--prune=true \
|
||||||
--interval=10m \
|
--interval=60m \
|
||||||
--health-check="Deployment/contour.projectcontour" \
|
--wait=true \
|
||||||
--health-check="DaemonSet/envoy.projectcontour" \
|
|
||||||
--health-check-timeout=3m
|
--health-check-timeout=3m
|
||||||
|
|
||||||
# Create a Kustomization resource that depends on the previous one
|
# Create a Kustomization resource that depends on the previous one
|
||||||
flux create kustomization webapp \
|
flux create kustomization kyverno-policies \
|
||||||
--depends-on=contour \
|
--depends-on=kyverno \
|
||||||
--source=GitRepository/webapp \
|
--source=GitRepository/kyverno-policies \
|
||||||
--path="./deploy/overlays/dev" \
|
--path="./policies/flux" \
|
||||||
--prune=true \
|
--prune=true \
|
||||||
--interval=5m
|
--interval=5m
|
||||||
|
|
||||||
@@ -65,7 +64,14 @@ var createKsCmd = &cobra.Command{
|
|||||||
flux create kustomization podinfo \
|
flux create kustomization podinfo \
|
||||||
--namespace=default \
|
--namespace=default \
|
||||||
--source=GitRepository/podinfo.flux-system \
|
--source=GitRepository/podinfo.flux-system \
|
||||||
--path="./deploy/overlays/dev" \
|
--path="./kustomize" \
|
||||||
|
--prune=true \
|
||||||
|
--interval=5m
|
||||||
|
|
||||||
|
# Create a Kustomization resource that references an OCIRepository
|
||||||
|
flux create kustomization podinfo \
|
||||||
|
--source=OCIRepository/podinfo \
|
||||||
|
--target-namespace=default \
|
||||||
--prune=true \
|
--prune=true \
|
||||||
--interval=5m
|
--interval=5m
|
||||||
|
|
||||||
@@ -78,18 +84,19 @@ var createKsCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type kustomizationFlags struct {
|
type kustomizationFlags struct {
|
||||||
source flags.KustomizationSource
|
source flags.KustomizationSource
|
||||||
path flags.SafeRelativePath
|
path flags.SafeRelativePath
|
||||||
prune bool
|
prune bool
|
||||||
dependsOn []string
|
dependsOn []string
|
||||||
validation string
|
validation string
|
||||||
healthCheck []string
|
healthCheck []string
|
||||||
healthTimeout time.Duration
|
healthTimeout time.Duration
|
||||||
saName string
|
saName string
|
||||||
decryptionProvider flags.DecryptionProvider
|
decryptionProvider flags.DecryptionProvider
|
||||||
decryptionSecret string
|
decryptionSecret string
|
||||||
targetNamespace string
|
targetNamespace string
|
||||||
wait bool
|
wait bool
|
||||||
|
kubeConfigSecretRef string
|
||||||
}
|
}
|
||||||
|
|
||||||
var kustomizationArgs = NewKustomizationFlags()
|
var kustomizationArgs = NewKustomizationFlags()
|
||||||
@@ -107,6 +114,7 @@ func init() {
|
|||||||
createKsCmd.Flags().Var(&kustomizationArgs.decryptionProvider, "decryption-provider", kustomizationArgs.decryptionProvider.Description())
|
createKsCmd.Flags().Var(&kustomizationArgs.decryptionProvider, "decryption-provider", kustomizationArgs.decryptionProvider.Description())
|
||||||
createKsCmd.Flags().StringVar(&kustomizationArgs.decryptionSecret, "decryption-secret", "", "set the Kubernetes secret name that contains the OpenPGP private keys used for sops decryption")
|
createKsCmd.Flags().StringVar(&kustomizationArgs.decryptionSecret, "decryption-secret", "", "set the Kubernetes secret name that contains the OpenPGP private keys used for sops decryption")
|
||||||
createKsCmd.Flags().StringVar(&kustomizationArgs.targetNamespace, "target-namespace", "", "overrides the namespace of all Kustomization objects reconciled by this Kustomization")
|
createKsCmd.Flags().StringVar(&kustomizationArgs.targetNamespace, "target-namespace", "", "overrides the namespace of all Kustomization objects reconciled by this Kustomization")
|
||||||
|
createKsCmd.Flags().StringVar(&kustomizationArgs.kubeConfigSecretRef, "kubeconfig-secret-ref", "", "the name of the Kubernetes Secret that contains a key with the kubeconfig file for connecting to a remote cluster")
|
||||||
createKsCmd.Flags().MarkDeprecated("validation", "this arg is no longer used, all resources are validated using server-side apply dry-run")
|
createKsCmd.Flags().MarkDeprecated("validation", "this arg is no longer used, all resources are validated using server-side apply dry-run")
|
||||||
|
|
||||||
createCmd.AddCommand(createKsCmd)
|
createCmd.AddCommand(createKsCmd)
|
||||||
@@ -160,6 +168,14 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if kustomizationArgs.kubeConfigSecretRef != "" {
|
||||||
|
kustomization.Spec.KubeConfig = &kustomizev1.KubeConfig{
|
||||||
|
SecretRef: meta.SecretKeyReference{
|
||||||
|
Name: kustomizationArgs.kubeConfigSecretRef,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(kustomizationArgs.healthCheck) > 0 && !kustomizationArgs.wait {
|
if len(kustomizationArgs.healthCheck) > 0 && !kustomizationArgs.wait {
|
||||||
healthChecks := make([]meta.NamespacedObjectKindReference, 0)
|
healthChecks := make([]meta.NamespacedObjectKindReference, 0)
|
||||||
for _, w := range kustomizationArgs.healthCheck {
|
for _, w := range kustomizationArgs.healthCheck {
|
||||||
|
|||||||
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
121
cmd/flux/create_secret_oci.go
Normal file
121
cmd/flux/create_secret_oci.go
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
|
||||||
|
"github.com/google/go-containerregistry/pkg/name"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
"sigs.k8s.io/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
var createSecretOCICmd = &cobra.Command{
|
||||||
|
Use: "oci [name]",
|
||||||
|
Short: "Create or update a Kubernetes image pull secret",
|
||||||
|
Long: `The create secret oci command generates a Kubernetes secret that can be used for OCIRepository authentication`,
|
||||||
|
Example: ` # Create an OCI authentication secret on disk and encrypt it with Mozilla SOPS
|
||||||
|
flux create secret oci podinfo-auth \
|
||||||
|
--url=ghcr.io \
|
||||||
|
--username=username \
|
||||||
|
--password=password \
|
||||||
|
--export > repo-auth.yaml
|
||||||
|
|
||||||
|
sops --encrypt --encrypted-regex '^(data|stringData)$' \
|
||||||
|
--in-place repo-auth.yaml
|
||||||
|
`,
|
||||||
|
RunE: createSecretOCICmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
type secretOCIFlags struct {
|
||||||
|
url string
|
||||||
|
password string
|
||||||
|
username string
|
||||||
|
}
|
||||||
|
|
||||||
|
var secretOCIArgs = secretOCIFlags{}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
createSecretOCICmd.Flags().StringVar(&secretOCIArgs.url, "url", "", "oci repository address e.g ghcr.io/stefanprodan/charts")
|
||||||
|
createSecretOCICmd.Flags().StringVarP(&secretOCIArgs.username, "username", "u", "", "basic authentication username")
|
||||||
|
createSecretOCICmd.Flags().StringVarP(&secretOCIArgs.password, "password", "p", "", "basic authentication password")
|
||||||
|
|
||||||
|
createSecretCmd.AddCommand(createSecretOCICmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func createSecretOCICmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) < 1 {
|
||||||
|
return fmt.Errorf("name is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
secretName := args[0]
|
||||||
|
|
||||||
|
if secretOCIArgs.url == "" {
|
||||||
|
return fmt.Errorf("--url is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if secretOCIArgs.username == "" {
|
||||||
|
return fmt.Errorf("--username is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if secretOCIArgs.password == "" {
|
||||||
|
return fmt.Errorf("--password is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := name.ParseReference(secretOCIArgs.url); err != nil {
|
||||||
|
return fmt.Errorf("error parsing url: '%s'", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := sourcesecret.Options{
|
||||||
|
Name: secretName,
|
||||||
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
|
Registry: secretOCIArgs.url,
|
||||||
|
Password: secretOCIArgs.password,
|
||||||
|
Username: secretOCIArgs.username,
|
||||||
|
}
|
||||||
|
|
||||||
|
secret, err := sourcesecret.Generate(opts)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if createArgs.export {
|
||||||
|
rootCmd.Println(secret.Content)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var s corev1.Secret
|
||||||
|
if err := yaml.Unmarshal([]byte(secret.Content), &s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := upsertSecret(ctx, kubeClient, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Actionf("oci secret '%s' created in '%s' namespace", secretName, *kubeconfigArgs.Namespace)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
51
cmd/flux/create_secret_oci_test.go
Normal file
51
cmd/flux/create_secret_oci_test.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateSecretOCI(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
assert assertFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
args: "create secret oci",
|
||||||
|
assert: assertError("name is required"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: "create secret oci ghcr",
|
||||||
|
assert: assertError("--url is required"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: "create secret oci ghcr --namespace=my-namespace --url ghcr.io --username stefanprodan --password=password --export",
|
||||||
|
assert: assertGoldenFile("testdata/create_secret/oci/create-secret.yaml"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.args,
|
||||||
|
assert: tt.assert,
|
||||||
|
}
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
@@ -63,17 +64,18 @@ For Buckets with static authentication, the credentials are stored in a Kubernet
|
|||||||
}
|
}
|
||||||
|
|
||||||
type sourceBucketFlags struct {
|
type sourceBucketFlags struct {
|
||||||
name string
|
name string
|
||||||
provider flags.SourceBucketProvider
|
provider flags.SourceBucketProvider
|
||||||
endpoint string
|
endpoint string
|
||||||
accessKey string
|
accessKey string
|
||||||
secretKey string
|
secretKey string
|
||||||
region string
|
region string
|
||||||
insecure bool
|
insecure bool
|
||||||
secretRef string
|
secretRef string
|
||||||
|
ignorePaths []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var sourceBucketArgs = NewSourceBucketFlags()
|
var sourceBucketArgs = newSourceBucketFlags()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
createSourceBucketCmd.Flags().Var(&sourceBucketArgs.provider, "provider", sourceBucketArgs.provider.Description())
|
createSourceBucketCmd.Flags().Var(&sourceBucketArgs.provider, "provider", sourceBucketArgs.provider.Description())
|
||||||
@@ -84,11 +86,12 @@ func init() {
|
|||||||
createSourceBucketCmd.Flags().StringVar(&sourceBucketArgs.region, "region", "", "the bucket region")
|
createSourceBucketCmd.Flags().StringVar(&sourceBucketArgs.region, "region", "", "the bucket region")
|
||||||
createSourceBucketCmd.Flags().BoolVar(&sourceBucketArgs.insecure, "insecure", false, "for when connecting to a non-TLS S3 HTTP endpoint")
|
createSourceBucketCmd.Flags().BoolVar(&sourceBucketArgs.insecure, "insecure", false, "for when connecting to a non-TLS S3 HTTP endpoint")
|
||||||
createSourceBucketCmd.Flags().StringVar(&sourceBucketArgs.secretRef, "secret-ref", "", "the name of an existing secret containing credentials")
|
createSourceBucketCmd.Flags().StringVar(&sourceBucketArgs.secretRef, "secret-ref", "", "the name of an existing secret containing credentials")
|
||||||
|
createSourceBucketCmd.Flags().StringSliceVar(&sourceBucketArgs.ignorePaths, "ignore-paths", nil, "set paths to ignore in bucket resource (can specify multiple paths with commas: path1,path2)")
|
||||||
|
|
||||||
createSourceCmd.AddCommand(createSourceBucketCmd)
|
createSourceCmd.AddCommand(createSourceBucketCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSourceBucketFlags() sourceBucketFlags {
|
func newSourceBucketFlags() sourceBucketFlags {
|
||||||
return sourceBucketFlags{
|
return sourceBucketFlags{
|
||||||
provider: flags.SourceBucketProvider(sourcev1.GenericBucketProvider),
|
provider: flags.SourceBucketProvider(sourcev1.GenericBucketProvider),
|
||||||
}
|
}
|
||||||
@@ -116,6 +119,12 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
|
var ignorePaths *string
|
||||||
|
if len(sourceBucketArgs.ignorePaths) > 0 {
|
||||||
|
ignorePathsStr := strings.Join(sourceBucketArgs.ignorePaths, "\n")
|
||||||
|
ignorePaths = &ignorePathsStr
|
||||||
|
}
|
||||||
|
|
||||||
bucket := &sourcev1.Bucket{
|
bucket := &sourcev1.Bucket{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
@@ -131,6 +140,7 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
Interval: metav1.Duration{
|
Interval: metav1.Duration{
|
||||||
Duration: createArgs.interval,
|
Duration: createArgs.interval,
|
||||||
},
|
},
|
||||||
|
Ignore: ignorePaths,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/manifoldco/promptui"
|
"github.com/manifoldco/promptui"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -59,6 +60,7 @@ type sourceGitFlags struct {
|
|||||||
privateKeyFile string
|
privateKeyFile string
|
||||||
recurseSubmodules bool
|
recurseSubmodules bool
|
||||||
silent bool
|
silent bool
|
||||||
|
ignorePaths []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var createSourceGitCmd = &cobra.Command{
|
var createSourceGitCmd = &cobra.Command{
|
||||||
@@ -115,6 +117,7 @@ For private Git repositories, the basic authentication credentials are stored in
|
|||||||
# Create a source for a Git repository using basic authentication
|
# Create a source for a Git repository using basic authentication
|
||||||
flux create source git podinfo \
|
flux create source git podinfo \
|
||||||
--url=https://github.com/stefanprodan/podinfo \
|
--url=https://github.com/stefanprodan/podinfo \
|
||||||
|
--branch=master \
|
||||||
--username=username \
|
--username=username \
|
||||||
--password=password`,
|
--password=password`,
|
||||||
RunE: createSourceGitCmdRun,
|
RunE: createSourceGitCmdRun,
|
||||||
@@ -139,6 +142,7 @@ func init() {
|
|||||||
createSourceGitCmd.Flags().BoolVar(&sourceGitArgs.recurseSubmodules, "recurse-submodules", false,
|
createSourceGitCmd.Flags().BoolVar(&sourceGitArgs.recurseSubmodules, "recurse-submodules", false,
|
||||||
"when enabled, configures the GitRepository source to initialize and include Git submodules in the artifact it produces")
|
"when enabled, configures the GitRepository source to initialize and include Git submodules in the artifact it produces")
|
||||||
createSourceGitCmd.Flags().BoolVarP(&sourceGitArgs.silent, "silent", "s", false, "assumes the deploy key is already setup, skips confirmation")
|
createSourceGitCmd.Flags().BoolVarP(&sourceGitArgs.silent, "silent", "s", false, "assumes the deploy key is already setup, skips confirmation")
|
||||||
|
createSourceGitCmd.Flags().StringSliceVar(&sourceGitArgs.ignorePaths, "ignore-paths", nil, "set paths to ignore in git resource (can specify multiple paths with commas: path1,path2)")
|
||||||
|
|
||||||
createSourceCmd.AddCommand(createSourceGitCmd)
|
createSourceCmd.AddCommand(createSourceGitCmd)
|
||||||
}
|
}
|
||||||
@@ -189,6 +193,12 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ignorePaths *string
|
||||||
|
if len(sourceGitArgs.ignorePaths) > 0 {
|
||||||
|
ignorePathsStr := strings.Join(sourceGitArgs.ignorePaths, "\n")
|
||||||
|
ignorePaths = &ignorePathsStr
|
||||||
|
}
|
||||||
|
|
||||||
gitRepository := sourcev1.GitRepository{
|
gitRepository := sourcev1.GitRepository{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
@@ -202,6 +212,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
},
|
},
|
||||||
RecurseSubmodules: sourceGitArgs.recurseSubmodules,
|
RecurseSubmodules: sourceGitArgs.recurseSubmodules,
|
||||||
Reference: &sourcev1.GitRepositoryRef{},
|
Reference: &sourcev1.GitRepositoryRef{},
|
||||||
|
Ignore: ignorePaths,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,6 +85,31 @@ func (r *reconciler) conditionFunc() (bool, error) {
|
|||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateSourceGitExport(t *testing.T) {
|
||||||
|
var command = "create source git podinfo --url=https://github.com/stefanprodan/podinfo --branch=master --ignore-paths .cosign,non-existent-dir/ -n default --interval 1m --export --timeout=" + testTimeout.String()
|
||||||
|
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
assert assertFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"ExportSucceeded",
|
||||||
|
command,
|
||||||
|
assertGoldenFile("testdata/create_source_git/export.golden"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tc.args,
|
||||||
|
assert: tc.assert,
|
||||||
|
}
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCreateSourceGit(t *testing.T) {
|
func TestCreateSourceGit(t *testing.T) {
|
||||||
// Default command used for multiple tests
|
// Default command used for multiple tests
|
||||||
var command = "create source git podinfo --url=https://github.com/stefanprodan/podinfo --branch=master --timeout=" + testTimeout.String()
|
var command = "create source git podinfo --url=https://github.com/stefanprodan/podinfo --branch=master --timeout=" + testTimeout.String()
|
||||||
|
|||||||
@@ -44,23 +44,34 @@ var createSourceHelmCmd = &cobra.Command{
|
|||||||
Short: "Create or update a HelmRepository source",
|
Short: "Create or update a HelmRepository source",
|
||||||
Long: `The create source helm command generates a HelmRepository resource and waits for it to fetch the index.
|
Long: `The create source helm command generates a HelmRepository resource and waits for it to fetch the index.
|
||||||
For private Helm repositories, the basic authentication credentials are stored in a Kubernetes secret.`,
|
For private Helm repositories, the basic authentication credentials are stored in a Kubernetes secret.`,
|
||||||
Example: ` # Create a source for a public Helm repository
|
Example: ` # Create a source for an HTTPS public Helm repository
|
||||||
flux create source helm podinfo \
|
flux create source helm podinfo \
|
||||||
--url=https://stefanprodan.github.io/podinfo \
|
--url=https://stefanprodan.github.io/podinfo \
|
||||||
--interval=10m
|
--interval=10m
|
||||||
|
|
||||||
# Create a source for a Helm repository using basic authentication
|
# Create a source for an HTTPS Helm repository using basic authentication
|
||||||
flux create source helm podinfo \
|
flux create source helm podinfo \
|
||||||
--url=https://stefanprodan.github.io/podinfo \
|
--url=https://stefanprodan.github.io/podinfo \
|
||||||
--username=username \
|
--username=username \
|
||||||
--password=password
|
--password=password
|
||||||
|
|
||||||
# Create a source for a Helm repository using TLS authentication
|
# Create a source for an HTTPS Helm repository using TLS authentication
|
||||||
flux create source helm podinfo \
|
flux create source helm podinfo \
|
||||||
--url=https://stefanprodan.github.io/podinfo \
|
--url=https://stefanprodan.github.io/podinfo \
|
||||||
--cert-file=./cert.crt \
|
--cert-file=./cert.crt \
|
||||||
--key-file=./key.crt \
|
--key-file=./key.crt \
|
||||||
--ca-file=./ca.crt`,
|
--ca-file=./ca.crt
|
||||||
|
|
||||||
|
# Create a source for an OCI Helm repository
|
||||||
|
flux create source helm podinfo \
|
||||||
|
--url=oci://ghcr.io/stefanprodan/charts/podinfo
|
||||||
|
--username=username \
|
||||||
|
--password=password
|
||||||
|
|
||||||
|
# Create a source for an OCI Helm repository using an existing secret with basic auth or dockerconfig credentials
|
||||||
|
flux create source helm podinfo \
|
||||||
|
--url=oci://ghcr.io/stefanprodan/charts/podinfo
|
||||||
|
--secret-ref=docker-config`,
|
||||||
RunE: createSourceHelmCmdRun,
|
RunE: createSourceHelmCmdRun,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +95,7 @@ func init() {
|
|||||||
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.certFile, "cert-file", "", "TLS authentication cert file path")
|
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.certFile, "cert-file", "", "TLS authentication cert file path")
|
||||||
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.keyFile, "key-file", "", "TLS authentication key file path")
|
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.keyFile, "key-file", "", "TLS authentication key file path")
|
||||||
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.caFile, "ca-file", "", "TLS authentication CA file path")
|
createSourceHelmCmd.Flags().StringVar(&sourceHelmArgs.caFile, "ca-file", "", "TLS authentication CA file path")
|
||||||
createSourceHelmCmd.Flags().StringVarP(&sourceHelmArgs.secretRef, "secret-ref", "", "", "the name of an existing secret containing TLS or basic auth credentials")
|
createSourceHelmCmd.Flags().StringVarP(&sourceHelmArgs.secretRef, "secret-ref", "", "", "the name of an existing secret containing TLS, basic auth or docker-config credentials")
|
||||||
createSourceHelmCmd.Flags().BoolVarP(&sourceHelmArgs.passCredentials, "pass-credentials", "", false, "pass credentials to all domains")
|
createSourceHelmCmd.Flags().BoolVarP(&sourceHelmArgs.passCredentials, "pass-credentials", "", false, "pass credentials to all domains")
|
||||||
|
|
||||||
createSourceCmd.AddCommand(createSourceHelmCmd)
|
createSourceCmd.AddCommand(createSourceHelmCmd)
|
||||||
@@ -126,6 +137,14 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
url, err := url.Parse(sourceHelmArgs.url)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to parse URL: %w", err)
|
||||||
|
}
|
||||||
|
if url.Scheme == sourcev1.HelmRepositoryTypeOCI {
|
||||||
|
helmRepository.Spec.Type = sourcev1.HelmRepositoryTypeOCI
|
||||||
|
}
|
||||||
|
|
||||||
if createSourceArgs.fetchTimeout > 0 {
|
if createSourceArgs.fetchTimeout > 0 {
|
||||||
helmRepository.Spec.Timeout = &metav1.Duration{Duration: createSourceArgs.fetchTimeout}
|
helmRepository.Spec.Timeout = &metav1.Duration{Duration: createSourceArgs.fetchTimeout}
|
||||||
}
|
}
|
||||||
@@ -196,6 +215,11 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
logger.Successf("HelmRepository source reconciliation completed")
|
logger.Successf("HelmRepository source reconciliation completed")
|
||||||
|
|
||||||
|
if helmRepository.Spec.Type == sourcev1.HelmRepositoryTypeOCI {
|
||||||
|
// OCI repos don't expose any artifact so we just return early here
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if helmRepository.Status.Artifact == nil {
|
if helmRepository.Status.Artifact == nil {
|
||||||
return fmt.Errorf("HelmRepository source reconciliation completed but no artifact was found")
|
return fmt.Errorf("HelmRepository source reconciliation completed but no artifact was found")
|
||||||
}
|
}
|
||||||
|
|||||||
81
cmd/flux/create_source_helm_test.go
Normal file
81
cmd/flux/create_source_helm_test.go
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
//go:build unit
|
||||||
|
// +build unit
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateSourceHelm(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
resultFile string
|
||||||
|
assertFunc string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "no args",
|
||||||
|
args: "create source helm",
|
||||||
|
resultFile: "name is required",
|
||||||
|
assertFunc: "assertError",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "OCI repo",
|
||||||
|
args: "create source helm podinfo --url=oci://ghcr.io/stefanprodan/charts/podinfo --interval 5m --export",
|
||||||
|
resultFile: "./testdata/create_source_helm/oci.golden",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "OCI repo with Secret ref",
|
||||||
|
args: "create source helm podinfo --url=oci://ghcr.io/stefanprodan/charts/podinfo --interval 5m --secret-ref=creds --export",
|
||||||
|
resultFile: "./testdata/create_source_helm/oci-with-secret.golden",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "HTTPS repo",
|
||||||
|
args: "create source helm podinfo --url=https://stefanprodan.github.io/charts/podinfo --interval 5m --export",
|
||||||
|
resultFile: "./testdata/create_source_helm/https.golden",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl := map[string]string{
|
||||||
|
"fluxns": allocateNamespace("flux-system"),
|
||||||
|
}
|
||||||
|
setup(t, tmpl)
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
var assert assertFunc
|
||||||
|
switch tt.assertFunc {
|
||||||
|
case "assertGoldenTemplateFile":
|
||||||
|
assert = assertGoldenTemplateFile(tt.resultFile, tmpl)
|
||||||
|
case "assertError":
|
||||||
|
assert = assertError(tt.resultFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.args + " -n " + tmpl["fluxns"],
|
||||||
|
assert: assert,
|
||||||
|
}
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
244
cmd/flux/create_source_oci.go
Normal file
244
cmd/flux/create_source_oci.go
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
|
"github.com/fluxcd/pkg/apis/meta"
|
||||||
|
"github.com/fluxcd/pkg/runtime/conditions"
|
||||||
|
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
var createSourceOCIRepositoryCmd = &cobra.Command{
|
||||||
|
Use: "oci [name]",
|
||||||
|
Short: "Create or update an OCIRepository",
|
||||||
|
Long: `The create source oci command generates an OCIRepository resource and waits for it to be ready.`,
|
||||||
|
Example: ` # Create an OCIRepository for a public container image
|
||||||
|
flux create source oci podinfo \
|
||||||
|
--url=oci://ghcr.io/stefanprodan/manifests/podinfo \
|
||||||
|
--tag=6.1.6 \
|
||||||
|
--interval=10m
|
||||||
|
`,
|
||||||
|
RunE: createSourceOCIRepositoryCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
type sourceOCIRepositoryFlags struct {
|
||||||
|
url string
|
||||||
|
tag string
|
||||||
|
semver string
|
||||||
|
digest string
|
||||||
|
secretRef string
|
||||||
|
serviceAccount string
|
||||||
|
certSecretRef string
|
||||||
|
ignorePaths []string
|
||||||
|
provider flags.SourceOCIProvider
|
||||||
|
}
|
||||||
|
|
||||||
|
var sourceOCIRepositoryArgs = newSourceOCIFlags()
|
||||||
|
|
||||||
|
func newSourceOCIFlags() sourceOCIRepositoryFlags {
|
||||||
|
return sourceOCIRepositoryFlags{
|
||||||
|
provider: flags.SourceOCIProvider(sourcev1.GenericOCIProvider),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
createSourceOCIRepositoryCmd.Flags().Var(&sourceOCIRepositoryArgs.provider, "provider", sourceOCIRepositoryArgs.provider.Description())
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.url, "url", "", "the OCI repository URL")
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.tag, "tag", "", "the OCI artifact tag")
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.semver, "tag-semver", "", "the OCI artifact tag semver range")
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.digest, "digest", "", "the OCI artifact digest")
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.secretRef, "secret-ref", "", "the name of the Kubernetes image pull secret (type 'kubernetes.io/dockerconfigjson')")
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.serviceAccount, "service-account", "", "the name of the Kubernetes service account that refers to an image pull secret")
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.certSecretRef, "cert-ref", "", "the name of a secret to use for TLS certificates")
|
||||||
|
createSourceOCIRepositoryCmd.Flags().StringSliceVar(&sourceOCIRepositoryArgs.ignorePaths, "ignore-paths", nil, "set paths to ignore resources (can specify multiple paths with commas: path1,path2)")
|
||||||
|
|
||||||
|
createSourceCmd.AddCommand(createSourceOCIRepositoryCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func createSourceOCIRepositoryCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
name := args[0]
|
||||||
|
|
||||||
|
if sourceOCIRepositoryArgs.url == "" {
|
||||||
|
return fmt.Errorf("url is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if sourceOCIRepositoryArgs.semver == "" && sourceOCIRepositoryArgs.tag == "" && sourceOCIRepositoryArgs.digest == "" {
|
||||||
|
return fmt.Errorf("--tag, --tag-semver or --digest is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceLabels, err := parseLabels()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var ignorePaths *string
|
||||||
|
if len(sourceOCIRepositoryArgs.ignorePaths) > 0 {
|
||||||
|
ignorePathsStr := strings.Join(sourceOCIRepositoryArgs.ignorePaths, "\n")
|
||||||
|
ignorePaths = &ignorePathsStr
|
||||||
|
}
|
||||||
|
|
||||||
|
repository := &sourcev1.OCIRepository{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: name,
|
||||||
|
Namespace: *kubeconfigArgs.Namespace,
|
||||||
|
Labels: sourceLabels,
|
||||||
|
},
|
||||||
|
Spec: sourcev1.OCIRepositorySpec{
|
||||||
|
Provider: sourceOCIRepositoryArgs.provider.String(),
|
||||||
|
URL: sourceOCIRepositoryArgs.url,
|
||||||
|
Interval: metav1.Duration{
|
||||||
|
Duration: createArgs.interval,
|
||||||
|
},
|
||||||
|
Reference: &sourcev1.OCIRepositoryRef{},
|
||||||
|
Ignore: ignorePaths,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if digest := sourceOCIRepositoryArgs.digest; digest != "" {
|
||||||
|
repository.Spec.Reference.Digest = digest
|
||||||
|
}
|
||||||
|
if semver := sourceOCIRepositoryArgs.semver; semver != "" {
|
||||||
|
repository.Spec.Reference.SemVer = semver
|
||||||
|
}
|
||||||
|
if tag := sourceOCIRepositoryArgs.tag; tag != "" {
|
||||||
|
repository.Spec.Reference.Tag = tag
|
||||||
|
}
|
||||||
|
|
||||||
|
if createSourceArgs.fetchTimeout > 0 {
|
||||||
|
repository.Spec.Timeout = &metav1.Duration{Duration: createSourceArgs.fetchTimeout}
|
||||||
|
}
|
||||||
|
|
||||||
|
if saName := sourceOCIRepositoryArgs.serviceAccount; saName != "" {
|
||||||
|
repository.Spec.ServiceAccountName = saName
|
||||||
|
}
|
||||||
|
|
||||||
|
if secretName := sourceOCIRepositoryArgs.secretRef; secretName != "" {
|
||||||
|
repository.Spec.SecretRef = &meta.LocalObjectReference{
|
||||||
|
Name: secretName,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if secretName := sourceOCIRepositoryArgs.certSecretRef; secretName != "" {
|
||||||
|
repository.Spec.CertSecretRef = &meta.LocalObjectReference{
|
||||||
|
Name: secretName,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if createArgs.export {
|
||||||
|
return printExport(exportOCIRepository(repository))
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Actionf("applying OCIRepository")
|
||||||
|
namespacedName, err := upsertOCIRepository(ctx, kubeClient, repository)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Waitingf("waiting for OCIRepository reconciliation")
|
||||||
|
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
|
||||||
|
isOCIRepositoryReady(ctx, kubeClient, namespacedName, repository)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Successf("OCIRepository reconciliation completed")
|
||||||
|
|
||||||
|
if repository.Status.Artifact == nil {
|
||||||
|
return fmt.Errorf("no artifact was found")
|
||||||
|
}
|
||||||
|
logger.Successf("fetched revision: %s", repository.Status.Artifact.Revision)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func upsertOCIRepository(ctx context.Context, kubeClient client.Client,
|
||||||
|
ociRepository *sourcev1.OCIRepository) (types.NamespacedName, error) {
|
||||||
|
namespacedName := types.NamespacedName{
|
||||||
|
Namespace: ociRepository.GetNamespace(),
|
||||||
|
Name: ociRepository.GetName(),
|
||||||
|
}
|
||||||
|
|
||||||
|
var existing sourcev1.OCIRepository
|
||||||
|
err := kubeClient.Get(ctx, namespacedName, &existing)
|
||||||
|
if err != nil {
|
||||||
|
if errors.IsNotFound(err) {
|
||||||
|
if err := kubeClient.Create(ctx, ociRepository); err != nil {
|
||||||
|
return namespacedName, err
|
||||||
|
} else {
|
||||||
|
logger.Successf("OCIRepository created")
|
||||||
|
return namespacedName, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return namespacedName, err
|
||||||
|
}
|
||||||
|
|
||||||
|
existing.Labels = ociRepository.Labels
|
||||||
|
existing.Spec = ociRepository.Spec
|
||||||
|
if err := kubeClient.Update(ctx, &existing); err != nil {
|
||||||
|
return namespacedName, err
|
||||||
|
}
|
||||||
|
ociRepository = &existing
|
||||||
|
logger.Successf("OCIRepository updated")
|
||||||
|
return namespacedName, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func isOCIRepositoryReady(ctx context.Context, kubeClient client.Client,
|
||||||
|
namespacedName types.NamespacedName, ociRepository *sourcev1.OCIRepository) wait.ConditionFunc {
|
||||||
|
return func() (bool, error) {
|
||||||
|
err := kubeClient.Get(ctx, namespacedName, ociRepository)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if c := conditions.Get(ociRepository, meta.ReadyCondition); c != nil {
|
||||||
|
// Confirm the Ready condition we are observing is for the
|
||||||
|
// current generation
|
||||||
|
if c.ObservedGeneration != ociRepository.GetGeneration() {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Further check the Status
|
||||||
|
switch c.Status {
|
||||||
|
case metav1.ConditionTrue:
|
||||||
|
return true, nil
|
||||||
|
case metav1.ConditionFalse:
|
||||||
|
return false, fmt.Errorf(c.Message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
61
cmd/flux/create_source_oci_test.go
Normal file
61
cmd/flux/create_source_oci_test.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateSourceOCI(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
assertFunc assertFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "NoArgs",
|
||||||
|
args: "create source oci",
|
||||||
|
assertFunc: assertError("name is required"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "NoURL",
|
||||||
|
args: "create source oci podinfo",
|
||||||
|
assertFunc: assertError("url is required"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "export manifest",
|
||||||
|
args: "create source oci podinfo --url=oci://ghcr.io/stefanprodan/manifests/podinfo --tag=6.1.6 --interval 10m --export",
|
||||||
|
assertFunc: assertGoldenFile("./testdata/oci/export.golden"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "export manifest with secret",
|
||||||
|
args: "create source oci podinfo --url=oci://ghcr.io/stefanprodan/manifests/podinfo --tag=6.1.6 --interval 10m --secret-ref=creds --export",
|
||||||
|
assertFunc: assertGoldenFile("./testdata/oci/export_with_secret.golden"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.args,
|
||||||
|
assert: tt.assertFunc,
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
40
cmd/flux/delete_source_oci.go
Normal file
40
cmd/flux/delete_source_oci.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var deleteSourceOCIRepositoryCmd = &cobra.Command{
|
||||||
|
Use: "oci [name]",
|
||||||
|
Short: "Delete an OCIRepository source",
|
||||||
|
Long: "The delete source oci command deletes the given OCIRepository from the cluster.",
|
||||||
|
Example: ` # Delete an OCIRepository
|
||||||
|
flux delete source oci podinfo`,
|
||||||
|
ValidArgsFunction: resourceNamesCompletionFunc(sourcev1.GroupVersion.WithKind(sourcev1.OCIRepositoryKind)),
|
||||||
|
RunE: deleteCommand{
|
||||||
|
apiType: ociRepositoryType,
|
||||||
|
object: universalAdapter{&sourcev1.OCIRepository{}},
|
||||||
|
}.run,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
deleteSourceCmd.AddCommand(deleteSourceOCIRepositoryCmd)
|
||||||
|
}
|
||||||
92
cmd/flux/export_source_oci.go
Normal file
92
cmd/flux/export_source_oci.go
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var exportSourceOCIRepositoryCmd = &cobra.Command{
|
||||||
|
Use: "oci [name]",
|
||||||
|
Short: "Export OCIRepository sources in YAML format",
|
||||||
|
Long: "The export source oci command exports one or all OCIRepository sources in YAML format.",
|
||||||
|
Example: ` # Export all OCIRepository sources
|
||||||
|
flux export source oci --all > sources.yaml
|
||||||
|
|
||||||
|
# Export a OCIRepository including the static credentials
|
||||||
|
flux export source oci my-app --with-credentials > source.yaml`,
|
||||||
|
ValidArgsFunction: resourceNamesCompletionFunc(sourcev1.GroupVersion.WithKind(sourcev1.OCIRepositoryKind)),
|
||||||
|
RunE: exportWithSecretCommand{
|
||||||
|
list: ociRepositoryListAdapter{&sourcev1.OCIRepositoryList{}},
|
||||||
|
object: ociRepositoryAdapter{&sourcev1.OCIRepository{}},
|
||||||
|
}.run,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
exportSourceCmd.AddCommand(exportSourceOCIRepositoryCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func exportOCIRepository(source *sourcev1.OCIRepository) interface{} {
|
||||||
|
gvk := sourcev1.GroupVersion.WithKind(sourcev1.OCIRepositoryKind)
|
||||||
|
export := sourcev1.OCIRepository{
|
||||||
|
TypeMeta: metav1.TypeMeta{
|
||||||
|
Kind: gvk.Kind,
|
||||||
|
APIVersion: gvk.GroupVersion().String(),
|
||||||
|
},
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: source.Name,
|
||||||
|
Namespace: source.Namespace,
|
||||||
|
Labels: source.Labels,
|
||||||
|
Annotations: source.Annotations,
|
||||||
|
},
|
||||||
|
Spec: source.Spec,
|
||||||
|
}
|
||||||
|
return export
|
||||||
|
}
|
||||||
|
|
||||||
|
func getOCIRepositorySecret(source *sourcev1.OCIRepository) *types.NamespacedName {
|
||||||
|
if source.Spec.SecretRef != nil {
|
||||||
|
namespacedName := types.NamespacedName{
|
||||||
|
Namespace: source.Namespace,
|
||||||
|
Name: source.Spec.SecretRef.Name,
|
||||||
|
}
|
||||||
|
|
||||||
|
return &namespacedName
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ex ociRepositoryAdapter) secret() *types.NamespacedName {
|
||||||
|
return getOCIRepositorySecret(ex.OCIRepository)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ex ociRepositoryListAdapter) secretItem(i int) *types.NamespacedName {
|
||||||
|
return getOCIRepositorySecret(&ex.OCIRepositoryList.Items[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ex ociRepositoryAdapter) export() interface{} {
|
||||||
|
return exportOCIRepository(ex.OCIRepository)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ex ociRepositoryListAdapter) exportItem(i int) interface{} {
|
||||||
|
return exportOCIRepository(&ex.OCIRepositoryList.Items[i])
|
||||||
|
}
|
||||||
@@ -40,6 +40,10 @@ var getSourceAllCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var allSourceCmd = []getCommand{
|
var allSourceCmd = []getCommand{
|
||||||
|
{
|
||||||
|
apiType: ociRepositoryType,
|
||||||
|
list: &ociRepositoryListAdapter{&sourcev1.OCIRepositoryList{}},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
apiType: bucketType,
|
apiType: bucketType,
|
||||||
list: &bucketListAdapter{&sourcev1.BucketList{}},
|
list: &bucketListAdapter{&sourcev1.BucketList{}},
|
||||||
|
|||||||
98
cmd/flux/get_source_oci.go
Normal file
98
cmd/flux/get_source_oci.go
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var getSourceOCIRepositoryCmd = &cobra.Command{
|
||||||
|
Use: "oci",
|
||||||
|
Short: "Get OCIRepository status",
|
||||||
|
Long: "The get sources oci command prints the status of the OCIRepository sources.",
|
||||||
|
Example: ` # List all OCIRepositories and their status
|
||||||
|
flux get sources oci
|
||||||
|
|
||||||
|
# List OCIRepositories from all namespaces
|
||||||
|
flux get sources oci --all-namespaces`,
|
||||||
|
ValidArgsFunction: resourceNamesCompletionFunc(sourcev1.GroupVersion.WithKind(sourcev1.OCIRepositoryKind)),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
get := getCommand{
|
||||||
|
apiType: ociRepositoryType,
|
||||||
|
list: &ociRepositoryListAdapter{&sourcev1.OCIRepositoryList{}},
|
||||||
|
funcMap: make(typeMap),
|
||||||
|
}
|
||||||
|
|
||||||
|
err := get.funcMap.registerCommand(get.apiType.kind, func(obj runtime.Object) (summarisable, error) {
|
||||||
|
o, ok := obj.(*sourcev1.OCIRepository)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("impossible to cast type %#v to OCIRepository", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
sink := &ociRepositoryListAdapter{&sourcev1.OCIRepositoryList{
|
||||||
|
Items: []sourcev1.OCIRepository{
|
||||||
|
*o,
|
||||||
|
}}}
|
||||||
|
return sink, nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := get.run(cmd, args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
getSourceCmd.AddCommand(getSourceOCIRepositoryCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ociRepositoryListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
|
||||||
|
item := a.Items[i]
|
||||||
|
var revision string
|
||||||
|
if item.GetArtifact() != nil {
|
||||||
|
revision = item.GetArtifact().Revision
|
||||||
|
}
|
||||||
|
status, msg := statusAndMessage(item.Status.Conditions)
|
||||||
|
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||||
|
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a ociRepositoryListAdapter) headers(includeNamespace bool) []string {
|
||||||
|
headers := []string{"Name", "Revision", "Suspended", "Ready", "Message"}
|
||||||
|
if includeNamespace {
|
||||||
|
headers = append([]string{"Namespace"}, headers...)
|
||||||
|
}
|
||||||
|
return headers
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a ociRepositoryListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool {
|
||||||
|
item := a.Items[i]
|
||||||
|
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||||
|
}
|
||||||
@@ -1,6 +1,22 @@
|
|||||||
//go:build e2e
|
//go:build e2e
|
||||||
// +build e2e
|
// +build e2e
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
"github.com/fluxcd/flux2/pkg/manifestgen/install"
|
||||||
"github.com/fluxcd/flux2/pkg/status"
|
"github.com/fluxcd/flux2/pkg/status"
|
||||||
)
|
)
|
||||||
@@ -134,7 +135,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
logger.Generatef("generating manifests")
|
logger.Generatef("generating manifests")
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpDir, err := os.MkdirTemp("", *kubeconfigArgs.Namespace)
|
tmpDir, err := manifestgen.MkdirTempAbs("", *kubeconfigArgs.Namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -193,7 +194,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
applyOutput, err := utils.Apply(ctx, kubeconfigArgs, kubeclientOptions, filepath.Join(tmpDir, manifest.Path))
|
applyOutput, err := utils.Apply(ctx, kubeconfigArgs, kubeclientOptions, tmpDir, filepath.Join(tmpDir, manifest.Path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("install failed: %w", err)
|
return fmt.Errorf("install failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
53
cmd/flux/install_test.go
Normal file
53
cmd/flux/install_test.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestInstall(t *testing.T) {
|
||||||
|
// The pointer to kubeconfigArgs.Namespace is shared across
|
||||||
|
// the tests. When a new value is set, it will linger and
|
||||||
|
// impact subsequent tests.
|
||||||
|
// Given that this test uses an invalid namespace, it ensures
|
||||||
|
// to restore whatever value it had previously.
|
||||||
|
currentNamespace := *kubeconfigArgs.Namespace
|
||||||
|
defer func() {
|
||||||
|
*kubeconfigArgs.Namespace = currentNamespace
|
||||||
|
}()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
assert assertFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "invalid namespace",
|
||||||
|
args: "install --namespace='@#[]'",
|
||||||
|
assert: assertError("namespace must be a valid DNS label: \"@#[]\""),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.args,
|
||||||
|
assert: tt.assert,
|
||||||
|
}
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
31
cmd/flux/list.go
Normal file
31
cmd/flux/list.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var listCmd = &cobra.Command{
|
||||||
|
Use: "list",
|
||||||
|
Short: "List artifacts",
|
||||||
|
Long: "The list command is used for printing the OCI artifacts metadata.",
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(listCmd)
|
||||||
|
}
|
||||||
76
cmd/flux/list_artifact.go
Normal file
76
cmd/flux/list_artifact.go
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
oci "github.com/fluxcd/pkg/oci/client"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/pkg/printers"
|
||||||
|
)
|
||||||
|
|
||||||
|
var listArtifactsCmd = &cobra.Command{
|
||||||
|
Use: "artifacts",
|
||||||
|
Short: "list artifacts",
|
||||||
|
Long: `The list command fetches the tags and their metadata from a remote OCI repository.
|
||||||
|
The command uses the credentials from '~/.docker/config.json'.`,
|
||||||
|
Example: ` # List the artifacts stored in an OCI repository
|
||||||
|
flux list artifact oci://ghcr.io/org/config/app
|
||||||
|
`,
|
||||||
|
RunE: listArtifactsCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
listCmd.AddCommand(listArtifactsCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func listArtifactsCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) < 1 {
|
||||||
|
return fmt.Errorf("artifact repository URL is required")
|
||||||
|
}
|
||||||
|
ociURL := args[0]
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
ociClient := oci.NewLocalClient()
|
||||||
|
url, err := oci.ParseArtifactURL(ociURL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
metas, err := ociClient.List(ctx, url)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows [][]string
|
||||||
|
for _, meta := range metas {
|
||||||
|
rows = append(rows, []string{meta.URL, meta.Digest, meta.Source, meta.Revision})
|
||||||
|
}
|
||||||
|
|
||||||
|
err = printers.TablePrinter([]string{"artifact", "digest", "source", "revision"}).Print(cmd.OutOrStdout(), rows)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -80,6 +80,8 @@ var logsArgs = &logsFlags{
|
|||||||
tail: -1,
|
tail: -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const controllerContainer = "manager"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
logsCmd.Flags().Var(&logsArgs.logLevel, "level", logsArgs.logLevel.Description())
|
logsCmd.Flags().Var(&logsArgs.logLevel, "level", logsArgs.logLevel.Description())
|
||||||
logsCmd.Flags().StringVarP(&logsArgs.kind, "kind", "", logsArgs.kind, "displays errors of a particular toolkit kind e.g GitRepository")
|
logsCmd.Flags().StringVarP(&logsArgs.kind, "kind", "", logsArgs.kind, "displays errors of a particular toolkit kind e.g GitRepository")
|
||||||
@@ -146,6 +148,10 @@ func logsCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
var requests []rest.ResponseWrapper
|
var requests []rest.ResponseWrapper
|
||||||
for _, pod := range pods {
|
for _, pod := range pods {
|
||||||
|
logOpts := logOpts.DeepCopy()
|
||||||
|
if len(pod.Spec.Containers) > 1 {
|
||||||
|
logOpts.Container = controllerContainer
|
||||||
|
}
|
||||||
req := clientset.CoreV1().Pods(logsArgs.fluxNamespace).GetLogs(pod.Name, logOpts)
|
req := clientset.CoreV1().Pods(logsArgs.fluxNamespace).GetLogs(pod.Name, logOpts)
|
||||||
requests = append(requests, req)
|
requests = append(requests, req)
|
||||||
}
|
}
|
||||||
@@ -198,12 +204,10 @@ func parallelPodLogs(ctx context.Context, requests []rest.ResponseWrapper) error
|
|||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
wg.Add(len(requests))
|
wg.Add(len(requests))
|
||||||
|
|
||||||
var mutex = &sync.Mutex{}
|
|
||||||
|
|
||||||
for _, request := range requests {
|
for _, request := range requests {
|
||||||
go func(req rest.ResponseWrapper) {
|
go func(req rest.ResponseWrapper) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if err := logRequest(mutex, ctx, req, os.Stdout); err != nil {
|
if err := logRequest(ctx, req, writer); err != nil {
|
||||||
writer.CloseWithError(err)
|
writer.CloseWithError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -220,9 +224,8 @@ func parallelPodLogs(ctx context.Context, requests []rest.ResponseWrapper) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func podLogs(ctx context.Context, requests []rest.ResponseWrapper) error {
|
func podLogs(ctx context.Context, requests []rest.ResponseWrapper) error {
|
||||||
mutex := &sync.Mutex{}
|
|
||||||
for _, req := range requests {
|
for _, req := range requests {
|
||||||
if err := logRequest(mutex, ctx, req, os.Stdout); err != nil {
|
if err := logRequest(ctx, req, os.Stdout); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,7 +243,7 @@ func createLabelStringFromMap(m map[string]string) string {
|
|||||||
return strings.Join(strArr, ",")
|
return strings.Join(strArr, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
func logRequest(mu *sync.Mutex, ctx context.Context, request rest.ResponseWrapper, w io.Writer) error {
|
func logRequest(ctx context.Context, request rest.ResponseWrapper, w io.Writer) error {
|
||||||
stream, err := request.Stream(ctx)
|
stream, err := request.Stream(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -255,6 +258,7 @@ func logRequest(mu *sync.Mutex, ctx context.Context, request rest.ResponseWrappe
|
|||||||
return fmt.Errorf("unable to create template, err: %s", err)
|
return fmt.Errorf("unable to create template, err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bw := bufio.NewWriter(w)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
if !strings.HasPrefix(line, "{") {
|
if !strings.HasPrefix(line, "{") {
|
||||||
@@ -265,26 +269,22 @@ func logRequest(mu *sync.Mutex, ctx context.Context, request rest.ResponseWrappe
|
|||||||
logger.Failuref("parse error: %s", err)
|
logger.Failuref("parse error: %s", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
filterPrintLog(t, &l, bw)
|
||||||
mu.Lock()
|
bw.Flush()
|
||||||
filterPrintLog(t, &l)
|
|
||||||
mu.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterPrintLog(t *template.Template, l *ControllerLogEntry) {
|
func filterPrintLog(t *template.Template, l *ControllerLogEntry, w io.Writer) {
|
||||||
if logsArgs.logLevel != "" && logsArgs.logLevel != l.Level ||
|
if (logsArgs.logLevel == "" || logsArgs.logLevel == l.Level) &&
|
||||||
logsArgs.kind != "" && strings.ToLower(logsArgs.kind) != strings.ToLower(l.Kind) ||
|
(logsArgs.kind == "" || strings.EqualFold(logsArgs.kind, l.Kind)) &&
|
||||||
logsArgs.name != "" && strings.ToLower(logsArgs.name) != strings.ToLower(l.Name) ||
|
(logsArgs.name == "" || strings.EqualFold(logsArgs.name, l.Name)) &&
|
||||||
!logsArgs.allNamespaces && strings.ToLower(*kubeconfigArgs.Namespace) != strings.ToLower(l.Namespace) {
|
(logsArgs.allNamespaces || strings.EqualFold(*kubeconfigArgs.Namespace, l.Namespace)) {
|
||||||
return
|
err := t.Execute(w, l)
|
||||||
}
|
if err != nil {
|
||||||
|
logger.Failuref("log template error: %s", err)
|
||||||
err := t.Execute(os.Stdout, l)
|
}
|
||||||
if err != nil {
|
|
||||||
logger.Failuref("log template error: %s", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,14 @@ limitations under the License.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLogsNoArgs(t *testing.T) {
|
func TestLogsNoArgs(t *testing.T) {
|
||||||
@@ -78,3 +85,105 @@ func TestLogsSinceOnlyOneAllowed(t *testing.T) {
|
|||||||
}
|
}
|
||||||
cmd.runTestCmd(t)
|
cmd.runTestCmd(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLogRequest(t *testing.T) {
|
||||||
|
mapper := &testResponseMapper{}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
namespace string
|
||||||
|
flags *logsFlags
|
||||||
|
assertFile string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "all logs",
|
||||||
|
flags: &logsFlags{
|
||||||
|
tail: -1,
|
||||||
|
allNamespaces: true,
|
||||||
|
},
|
||||||
|
assertFile: "testdata/logs/all-logs.txt",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filter by namespace",
|
||||||
|
namespace: "default",
|
||||||
|
flags: &logsFlags{
|
||||||
|
tail: -1,
|
||||||
|
},
|
||||||
|
assertFile: "testdata/logs/namespace.txt",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filter by kind and namespace",
|
||||||
|
flags: &logsFlags{
|
||||||
|
tail: -1,
|
||||||
|
kind: "Kustomization",
|
||||||
|
},
|
||||||
|
assertFile: "testdata/logs/kind.txt",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filter by loglevel",
|
||||||
|
flags: &logsFlags{
|
||||||
|
tail: -1,
|
||||||
|
logLevel: "error",
|
||||||
|
allNamespaces: true,
|
||||||
|
},
|
||||||
|
assertFile: "testdata/logs/log-level.txt",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filter by namespace, name, loglevel and kind",
|
||||||
|
namespace: "flux-system",
|
||||||
|
flags: &logsFlags{
|
||||||
|
tail: -1,
|
||||||
|
logLevel: "error",
|
||||||
|
kind: "Kustomization",
|
||||||
|
name: "podinfo",
|
||||||
|
},
|
||||||
|
assertFile: "testdata/logs/multiple-filters.txt",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
g := NewWithT(t)
|
||||||
|
|
||||||
|
logsArgs = tt.flags
|
||||||
|
if tt.namespace != "" {
|
||||||
|
*kubeconfigArgs.Namespace = tt.namespace
|
||||||
|
}
|
||||||
|
w := bytes.NewBuffer([]byte{})
|
||||||
|
err := logRequest(context.Background(), mapper, w)
|
||||||
|
g.Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
got := make([]byte, w.Len())
|
||||||
|
_, err = w.Read(got)
|
||||||
|
g.Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
expected, err := os.ReadFile(tt.assertFile)
|
||||||
|
g.Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
g.Expect(string(got)).To(Equal(string(expected)))
|
||||||
|
|
||||||
|
// reset flags to default
|
||||||
|
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
||||||
|
logsArgs = &logsFlags{
|
||||||
|
tail: -1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var testPodLogs = `{"level":"info","ts":"2022-08-02T12:55:34.419Z","logger":"controller.gitrepository","msg":"no changes since last reconcilation: observed revision","reconciler group":"source.toolkit.fluxcd.io","reconciler kind":"GitRepository","name":"podinfo","namespace":"default"}
|
||||||
|
{"level":"error","ts":"2022-08-02T12:56:04.679Z","logger":"controller.gitrepository","msg":"no changes since last reconcilation: observed revision","reconciler group":"source.toolkit.fluxcd.io","reconciler kind":"GitRepository","name":"flux-system","namespace":"flux-system"}
|
||||||
|
{"level":"error","ts":"2022-08-02T12:56:34.961Z","logger":"controller.kustomization","msg":"no changes since last reconcilation: observed revision","reconciler group":"kustomize.toolkit.fluxcd.io","reconciler kind":"Kustomization","name":"flux-system","namespace":"flux-system"}
|
||||||
|
{"level":"info","ts":"2022-08-02T12:56:34.961Z","logger":"controller.kustomization","msg":"no changes since last reconcilation: observed revision","reconciler group":"kustomize.toolkit.fluxcd.io","reconciler kind":"Kustomization","name":"podinfo","namespace":"default"}
|
||||||
|
{"level":"info","ts":"2022-08-02T12:56:34.961Z","logger":"controller.gitrepository","msg":"no changes since last reconcilation: observed revision","reconciler group":"source.toolkit.fluxcd.io","reconciler kind":"GitRepository","name":"podinfo","namespace":"default"}
|
||||||
|
{"level":"error","ts":"2022-08-02T12:56:34.961Z","logger":"controller.kustomization","msg":"no changes since last reconcilation: observed revision","reconciler group":"kustomize.toolkit.fluxcd.io","reconciler kind":"Kustomization","name":"podinfo","namespace":"flux-system"}`
|
||||||
|
|
||||||
|
type testResponseMapper struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *testResponseMapper) DoRaw(_ context.Context) ([]byte, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *testResponseMapper) Stream(_ context.Context) (io.ReadCloser, error) {
|
||||||
|
return io.NopCloser(strings.NewReader(testPodLogs)), nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/util/validation"
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||||
|
|
||||||
@@ -96,6 +97,18 @@ Command line utility for assembling Kubernetes CD pipelines the GitOps way.`,
|
|||||||
|
|
||||||
# Uninstall Flux and delete CRDs
|
# Uninstall Flux and delete CRDs
|
||||||
flux uninstall`,
|
flux uninstall`,
|
||||||
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
ns, err := cmd.Flags().GetString("namespace")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error getting namespace: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e := validation.IsDNS1123Label(ns); len(e) > 0 {
|
||||||
|
return fmt.Errorf("namespace must be a valid DNS label: %q", ns)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var logger = stderrLogger{stderr: os.Stderr}
|
var logger = stderrLogger{stderr: os.Stderr}
|
||||||
@@ -178,17 +191,18 @@ func configureDefaultNamespace() {
|
|||||||
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
||||||
fromEnv := os.Getenv("FLUX_SYSTEM_NAMESPACE")
|
fromEnv := os.Getenv("FLUX_SYSTEM_NAMESPACE")
|
||||||
if fromEnv != "" {
|
if fromEnv != "" {
|
||||||
|
// namespace must be a valid DNS label. Assess against validation
|
||||||
|
// used upstream, and ignore invalid values as environment vars
|
||||||
|
// may not be actively provided by end-user.
|
||||||
|
if e := validation.IsDNS1123Label(fromEnv); len(e) > 0 {
|
||||||
|
logger.Warningf(" ignoring invalid FLUX_SYSTEM_NAMESPACE: %q", fromEnv)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
kubeconfigArgs.Namespace = &fromEnv
|
kubeconfigArgs.Namespace = &fromEnv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func homeDir() string {
|
|
||||||
if h := os.Getenv("HOME"); h != "" {
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
return os.Getenv("USERPROFILE") // windows
|
|
||||||
}
|
|
||||||
|
|
||||||
// readPasswordFromStdin reads a password from stdin and returns the input
|
// readPasswordFromStdin reads a password from stdin and returns the input
|
||||||
// with trailing newline and/or carriage return removed. It also makes sure that terminal
|
// with trailing newline and/or carriage return removed. It also makes sure that terminal
|
||||||
// echoing is turned off if stdin is a terminal.
|
// echoing is turned off if stdin is a terminal.
|
||||||
|
|||||||
@@ -386,7 +386,12 @@ func executeCommand(cmd string) (string, error) {
|
|||||||
func resetCmdArgs() {
|
func resetCmdArgs() {
|
||||||
createArgs = createFlags{}
|
createArgs = createFlags{}
|
||||||
getArgs = GetFlags{}
|
getArgs = GetFlags{}
|
||||||
|
sourceHelmArgs = sourceHelmFlags{}
|
||||||
|
sourceOCIRepositoryArgs = sourceOCIRepositoryFlags{}
|
||||||
|
sourceGitArgs = sourceGitFlags{}
|
||||||
|
sourceBucketArgs = sourceBucketFlags{}
|
||||||
secretGitArgs = NewSecretGitFlags()
|
secretGitArgs = NewSecretGitFlags()
|
||||||
|
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
func isChangeError(err error) bool {
|
func isChangeError(err error) bool {
|
||||||
|
|||||||
31
cmd/flux/pull.go
Normal file
31
cmd/flux/pull.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var pullCmd = &cobra.Command{
|
||||||
|
Use: "pull",
|
||||||
|
Short: "Pull artifacts",
|
||||||
|
Long: "The pull command is used to download OCI artifacts.",
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(pullCmd)
|
||||||
|
}
|
||||||
87
cmd/flux/pull_artifact.go
Normal file
87
cmd/flux/pull_artifact.go
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
oci "github.com/fluxcd/pkg/oci/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
var pullArtifactCmd = &cobra.Command{
|
||||||
|
Use: "artifact",
|
||||||
|
Short: "Pull artifact",
|
||||||
|
Long: `The pull artifact command downloads and extracts the OCI artifact content to the given path.
|
||||||
|
The pull command uses the credentials from '~/.docker/config.json'.`,
|
||||||
|
Example: ` # Pull an OCI artifact created by flux from GHCR
|
||||||
|
flux pull artifact oci://ghcr.io/org/manifests/app:v0.0.1 --output ./path/to/local/manifests
|
||||||
|
`,
|
||||||
|
RunE: pullArtifactCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
type pullArtifactFlags struct {
|
||||||
|
output string
|
||||||
|
}
|
||||||
|
|
||||||
|
var pullArtifactArgs pullArtifactFlags
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
pullArtifactCmd.Flags().StringVarP(&pullArtifactArgs.output, "output", "o", "", "path where the artifact content should be extracted.")
|
||||||
|
pullCmd.AddCommand(pullArtifactCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func pullArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) < 1 {
|
||||||
|
return fmt.Errorf("artifact URL is required")
|
||||||
|
}
|
||||||
|
ociURL := args[0]
|
||||||
|
|
||||||
|
if pullArtifactArgs.output == "" {
|
||||||
|
return fmt.Errorf("invalid output path %s", pullArtifactArgs.output)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fs, err := os.Stat(pullArtifactArgs.output); err != nil || !fs.IsDir() {
|
||||||
|
return fmt.Errorf("invalid output path %s", pullArtifactArgs.output)
|
||||||
|
}
|
||||||
|
|
||||||
|
ociClient := oci.NewLocalClient()
|
||||||
|
url, err := oci.ParseArtifactURL(ociURL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
logger.Actionf("pulling artifact from %s", url)
|
||||||
|
|
||||||
|
meta, err := ociClient.Pull(ctx, url, pullArtifactArgs.output)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Successf("source %s", meta.Source)
|
||||||
|
logger.Successf("revision %s", meta.Revision)
|
||||||
|
logger.Successf("digest %s", meta.Digest)
|
||||||
|
logger.Successf("artifact content extracted to %s", pullArtifactArgs.output)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
31
cmd/flux/push.go
Normal file
31
cmd/flux/push.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var pushCmd = &cobra.Command{
|
||||||
|
Use: "push",
|
||||||
|
Short: "Push artifacts",
|
||||||
|
Long: "The push command is used to publish OCI artifacts.",
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(pushCmd)
|
||||||
|
}
|
||||||
113
cmd/flux/push_artifact.go
Normal file
113
cmd/flux/push_artifact.go
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
oci "github.com/fluxcd/pkg/oci/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
var pushArtifactCmd = &cobra.Command{
|
||||||
|
Use: "artifact",
|
||||||
|
Short: "Push artifact",
|
||||||
|
Long: `The push artifact command creates a tarball from the given directory and uploads the artifact to an OCI repository.
|
||||||
|
The command uses the credentials from '~/.docker/config.json'.`,
|
||||||
|
Example: ` # Push manifests to GHCR using the short Git SHA as the OCI artifact tag
|
||||||
|
echo $GITHUB_PAT | docker login ghcr.io --username flux --password-stdin
|
||||||
|
flux push artifact oci://ghcr.io/org/config/app:$(git rev-parse --short HEAD) \
|
||||||
|
--path="./path/to/local/manifests" \
|
||||||
|
--source="$(git config --get remote.origin.url)" \
|
||||||
|
--revision="$(git branch --show-current)/$(git rev-parse HEAD)"
|
||||||
|
|
||||||
|
# Push manifests to Docker Hub using the Git tag as the OCI artifact tag
|
||||||
|
echo $DOCKER_PAT | docker login --username flux --password-stdin
|
||||||
|
flux push artifact oci://docker.io/org/app-config:$(git tag --points-at HEAD) \
|
||||||
|
--path="./path/to/local/manifests" \
|
||||||
|
--source="$(git config --get remote.origin.url)" \
|
||||||
|
--revision="$(git tag --points-at HEAD)/$(git rev-parse HEAD)"
|
||||||
|
`,
|
||||||
|
RunE: pushArtifactCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
type pushArtifactFlags struct {
|
||||||
|
path string
|
||||||
|
source string
|
||||||
|
revision string
|
||||||
|
}
|
||||||
|
|
||||||
|
var pushArtifactArgs pushArtifactFlags
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
pushArtifactCmd.Flags().StringVar(&pushArtifactArgs.path, "path", "", "path to the directory where the Kubernetes manifests are located")
|
||||||
|
pushArtifactCmd.Flags().StringVar(&pushArtifactArgs.source, "source", "", "the source address, e.g. the Git URL")
|
||||||
|
pushArtifactCmd.Flags().StringVar(&pushArtifactArgs.revision, "revision", "", "the source revision in the format '<branch|tag>/<commit-sha>'")
|
||||||
|
pushCmd.AddCommand(pushArtifactCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func pushArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) < 1 {
|
||||||
|
return fmt.Errorf("artifact URL is required")
|
||||||
|
}
|
||||||
|
ociURL := args[0]
|
||||||
|
|
||||||
|
if pushArtifactArgs.source == "" {
|
||||||
|
return fmt.Errorf("--source is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if pushArtifactArgs.revision == "" {
|
||||||
|
return fmt.Errorf("--revision is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if pushArtifactArgs.path == "" {
|
||||||
|
return fmt.Errorf("invalid path %q", pushArtifactArgs.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
ociClient := oci.NewLocalClient()
|
||||||
|
url, err := oci.ParseArtifactURL(ociURL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if fs, err := os.Stat(pushArtifactArgs.path); err != nil || !fs.IsDir() {
|
||||||
|
return fmt.Errorf("invalid path %q", pushArtifactArgs.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
meta := oci.Metadata{
|
||||||
|
Source: pushArtifactArgs.source,
|
||||||
|
Revision: pushArtifactArgs.revision,
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
logger.Actionf("pushing artifact to %s", url)
|
||||||
|
|
||||||
|
digest, err := ociClient.Push(ctx, url, pushArtifactArgs.path, meta)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("pushing artifact failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Successf("artifact successfully pushed to %s", digest)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
@@ -65,6 +65,11 @@ func (obj kustomizationAdapter) reconcileSource() bool {
|
|||||||
func (obj kustomizationAdapter) getSource() (reconcileCommand, types.NamespacedName) {
|
func (obj kustomizationAdapter) getSource() (reconcileCommand, types.NamespacedName) {
|
||||||
var cmd reconcileCommand
|
var cmd reconcileCommand
|
||||||
switch obj.Spec.SourceRef.Kind {
|
switch obj.Spec.SourceRef.Kind {
|
||||||
|
case sourcev1.OCIRepositoryKind:
|
||||||
|
cmd = reconcileCommand{
|
||||||
|
apiType: ociRepositoryType,
|
||||||
|
object: ociRepositoryAdapter{&sourcev1.OCIRepository{}},
|
||||||
|
}
|
||||||
case sourcev1.GitRepositoryKind:
|
case sourcev1.GitRepositoryKind:
|
||||||
cmd = reconcileCommand{
|
cmd = reconcileCommand{
|
||||||
apiType: gitRepositoryType,
|
apiType: gitRepositoryType,
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/fluxcd/pkg/apis/meta"
|
||||||
|
"github.com/fluxcd/pkg/runtime/conditions"
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -46,5 +48,15 @@ func (obj helmRepositoryAdapter) lastHandledReconcileRequest() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (obj helmRepositoryAdapter) successMessage() string {
|
func (obj helmRepositoryAdapter) successMessage() string {
|
||||||
|
// HelmRepository of type OCI don't set an Artifact
|
||||||
|
if obj.Spec.Type == sourcev1.HelmRepositoryTypeOCI {
|
||||||
|
readyCondition := conditions.Get(obj.HelmRepository, meta.ReadyCondition)
|
||||||
|
// This shouldn't happen, successMessage shouldn't be called if
|
||||||
|
// object isn't ready
|
||||||
|
if readyCondition == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return readyCondition.Message
|
||||||
|
}
|
||||||
return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision)
|
return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision)
|
||||||
}
|
}
|
||||||
|
|||||||
50
cmd/flux/reconcile_source_oci.go
Normal file
50
cmd/flux/reconcile_source_oci.go
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var reconcileSourceOCIRepositoryCmd = &cobra.Command{
|
||||||
|
Use: "oci [name]",
|
||||||
|
Short: "Reconcile an OCIRepository",
|
||||||
|
Long: `The reconcile source command triggers a reconciliation of an OCIRepository resource and waits for it to finish.`,
|
||||||
|
Example: ` # Trigger a reconciliation for an existing source
|
||||||
|
flux reconcile source oci podinfo`,
|
||||||
|
ValidArgsFunction: resourceNamesCompletionFunc(sourcev1.GroupVersion.WithKind(sourcev1.OCIRepositoryKind)),
|
||||||
|
RunE: reconcileCommand{
|
||||||
|
apiType: ociRepositoryType,
|
||||||
|
object: ociRepositoryAdapter{&sourcev1.OCIRepository{}},
|
||||||
|
}.run,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
reconcileSourceCmd.AddCommand(reconcileSourceOCIRepositoryCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (obj ociRepositoryAdapter) lastHandledReconcileRequest() string {
|
||||||
|
return obj.Status.GetLastHandledReconcileRequest()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (obj ociRepositoryAdapter) successMessage() string {
|
||||||
|
return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision)
|
||||||
|
}
|
||||||
53
cmd/flux/resume_source_oci.go
Normal file
53
cmd/flux/resume_source_oci.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var resumeSourceOCIRepositoryCmd = &cobra.Command{
|
||||||
|
Use: "oci [name]",
|
||||||
|
Short: "Resume a suspended OCIRepository",
|
||||||
|
Long: `The resume command marks a previously suspended OCIRepository resource for reconciliation and waits for it to finish.`,
|
||||||
|
Example: ` # Resume reconciliation for an existing OCIRepository
|
||||||
|
flux resume source oci podinfo`,
|
||||||
|
ValidArgsFunction: resourceNamesCompletionFunc(sourcev1.GroupVersion.WithKind(sourcev1.OCIRepositoryKind)),
|
||||||
|
RunE: resumeCommand{
|
||||||
|
apiType: ociRepositoryType,
|
||||||
|
object: ociRepositoryAdapter{&sourcev1.OCIRepository{}},
|
||||||
|
list: ociRepositoryListAdapter{&sourcev1.OCIRepositoryList{}},
|
||||||
|
}.run,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
resumeSourceCmd.AddCommand(resumeSourceOCIRepositoryCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (obj ociRepositoryAdapter) getObservedGeneration() int64 {
|
||||||
|
return obj.OCIRepository.Status.ObservedGeneration
|
||||||
|
}
|
||||||
|
|
||||||
|
func (obj ociRepositoryAdapter) setUnsuspended() {
|
||||||
|
obj.OCIRepository.Spec.Suspend = false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a ociRepositoryListAdapter) resumeItem(i int) resumable {
|
||||||
|
return &ociRepositoryAdapter{&a.OCIRepositoryList.Items[i]}
|
||||||
|
}
|
||||||
@@ -26,6 +26,40 @@ import (
|
|||||||
// the various commands. The *List adapters implement len(), since
|
// the various commands. The *List adapters implement len(), since
|
||||||
// it's used in at least a couple of commands.
|
// it's used in at least a couple of commands.
|
||||||
|
|
||||||
|
// sourcev1.ociRepository
|
||||||
|
|
||||||
|
var ociRepositoryType = apiType{
|
||||||
|
kind: sourcev1.OCIRepositoryKind,
|
||||||
|
humanKind: "source oci",
|
||||||
|
groupVersion: sourcev1.GroupVersion,
|
||||||
|
}
|
||||||
|
|
||||||
|
type ociRepositoryAdapter struct {
|
||||||
|
*sourcev1.OCIRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a ociRepositoryAdapter) asClientObject() client.Object {
|
||||||
|
return a.OCIRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a ociRepositoryAdapter) deepCopyClientObject() client.Object {
|
||||||
|
return a.OCIRepository.DeepCopy()
|
||||||
|
}
|
||||||
|
|
||||||
|
// sourcev1.OCIRepositoryList
|
||||||
|
|
||||||
|
type ociRepositoryListAdapter struct {
|
||||||
|
*sourcev1.OCIRepositoryList
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a ociRepositoryListAdapter) asClientList() client.ObjectList {
|
||||||
|
return a.OCIRepositoryList
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a ociRepositoryListAdapter) len() int {
|
||||||
|
return len(a.OCIRepositoryList.Items)
|
||||||
|
}
|
||||||
|
|
||||||
// sourcev1.Bucket
|
// sourcev1.Bucket
|
||||||
|
|
||||||
var bucketType = apiType{
|
var bucketType = apiType{
|
||||||
|
|||||||
71
cmd/flux/source_oci_test.go
Normal file
71
cmd/flux/source_oci_test.go
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
//go:build e2e
|
||||||
|
// +build e2e
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSourceOCI(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
args string
|
||||||
|
goldenFile string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"create source oci thrfg --url=oci://ghcr.io/stefanprodan/manifests/podinfo --tag=6.1.6 --interval 10m",
|
||||||
|
"testdata/oci/create_source_oci.golden",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"get source oci thrfg",
|
||||||
|
"testdata/oci/get_oci.golden",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reconcile source oci thrfg",
|
||||||
|
"testdata/oci/reconcile_oci.golden",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"suspend source oci thrfg",
|
||||||
|
"testdata/oci/suspend_oci.golden",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"resume source oci thrfg",
|
||||||
|
"testdata/oci/resume_oci.golden",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"delete source oci thrfg --silent",
|
||||||
|
"testdata/oci/delete_oci.golden",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace := allocateNamespace("oci-test")
|
||||||
|
del, err := setupTestNamespace(namespace)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer del()
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tc.args + " -n=" + namespace,
|
||||||
|
assert: assertGoldenTemplateFile(tc.goldenFile, map[string]string{"ns": namespace}),
|
||||||
|
}
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
53
cmd/flux/suspend_source_oci.go
Normal file
53
cmd/flux/suspend_source_oci.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var suspendSourceOCIRepositoryCmd = &cobra.Command{
|
||||||
|
Use: "oci [name]",
|
||||||
|
Short: "Suspend reconciliation of an OCIRepository",
|
||||||
|
Long: "The suspend command disables the reconciliation of an OCIRepository resource.",
|
||||||
|
Example: ` # Suspend reconciliation for an existing OCIRepository
|
||||||
|
flux suspend source oci podinfo`,
|
||||||
|
ValidArgsFunction: resourceNamesCompletionFunc(sourcev1.GroupVersion.WithKind(sourcev1.OCIRepositoryKind)),
|
||||||
|
RunE: suspendCommand{
|
||||||
|
apiType: ociRepositoryType,
|
||||||
|
object: ociRepositoryAdapter{&sourcev1.OCIRepository{}},
|
||||||
|
list: ociRepositoryListAdapter{&sourcev1.OCIRepositoryList{}},
|
||||||
|
}.run,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
suspendSourceCmd.AddCommand(suspendSourceOCIRepositoryCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (obj ociRepositoryAdapter) isSuspended() bool {
|
||||||
|
return obj.OCIRepository.Spec.Suspend
|
||||||
|
}
|
||||||
|
|
||||||
|
func (obj ociRepositoryAdapter) setSuspended() {
|
||||||
|
obj.OCIRepository.Spec.Suspend = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a ociRepositoryListAdapter) item(i int) suspendable {
|
||||||
|
return &ociRepositoryAdapter{&a.OCIRepositoryList.Items[i]}
|
||||||
|
}
|
||||||
31
cmd/flux/tag.go
Normal file
31
cmd/flux/tag.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var tagCmd = &cobra.Command{
|
||||||
|
Use: "tag",
|
||||||
|
Short: "Tag artifacts",
|
||||||
|
Long: "The tag command is used to tag OCI artifacts.",
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(tagCmd)
|
||||||
|
}
|
||||||
82
cmd/flux/tag_artifact.go
Normal file
82
cmd/flux/tag_artifact.go
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
oci "github.com/fluxcd/pkg/oci/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
var tagArtifactCmd = &cobra.Command{
|
||||||
|
Use: "artifact",
|
||||||
|
Short: "Tag artifact",
|
||||||
|
Long: `The tag artifact command creates tags for the given OCI artifact.
|
||||||
|
The command uses the credentials from '~/.docker/config.json'.`,
|
||||||
|
Example: ` # Tag an artifact version as latest
|
||||||
|
flux tag artifact oci://ghcr.io/org/manifests/app:v0.0.1 --tag latest
|
||||||
|
`,
|
||||||
|
RunE: tagArtifactCmdRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
type tagArtifactFlags struct {
|
||||||
|
tags []string
|
||||||
|
}
|
||||||
|
|
||||||
|
var tagArtifactArgs tagArtifactFlags
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
tagArtifactCmd.Flags().StringSliceVar(&tagArtifactArgs.tags, "tag", nil, "tag name")
|
||||||
|
tagCmd.AddCommand(tagArtifactCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func tagArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) < 1 {
|
||||||
|
return fmt.Errorf("artifact name is required")
|
||||||
|
}
|
||||||
|
ociURL := args[0]
|
||||||
|
|
||||||
|
if len(tagArtifactArgs.tags) < 1 {
|
||||||
|
return fmt.Errorf("--tag is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
ociClient := oci.NewLocalClient()
|
||||||
|
url, err := oci.ParseArtifactURL(ociURL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
logger.Actionf("tagging artifact")
|
||||||
|
|
||||||
|
for _, tag := range tagArtifactArgs.tags {
|
||||||
|
img, err := ociClient.Tag(ctx, url, tag)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("tagging artifact failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Successf("artifact tagged as %s", img)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
10
cmd/flux/testdata/create_secret/oci/create-secret.yaml
vendored
Normal file
10
cmd/flux/testdata/create_secret/oci/create-secret.yaml
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: ghcr
|
||||||
|
namespace: my-namespace
|
||||||
|
stringData:
|
||||||
|
.dockerconfigjson: '{"auths":{"ghcr.io":{"username":"stefanprodan","password":"password","auth":"c3RlZmFucHJvZGFuOnBhc3N3b3Jk"}}}'
|
||||||
|
type: kubernetes.io/dockerconfigjson
|
||||||
|
|
||||||
15
cmd/flux/testdata/create_source_git/export.golden
vendored
Normal file
15
cmd/flux/testdata/create_source_git/export.golden
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
apiVersion: source.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: GitRepository
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
ignore: |-
|
||||||
|
.cosign
|
||||||
|
non-existent-dir/
|
||||||
|
interval: 1m0s
|
||||||
|
ref:
|
||||||
|
branch: master
|
||||||
|
url: https://github.com/stefanprodan/podinfo
|
||||||
|
|
||||||
10
cmd/flux/testdata/create_source_helm/https.golden
vendored
Normal file
10
cmd/flux/testdata/create_source_helm/https.golden
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
apiVersion: source.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: HelmRepository
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: {{ .fluxns }}
|
||||||
|
spec:
|
||||||
|
interval: 5m0s
|
||||||
|
url: https://stefanprodan.github.io/charts/podinfo
|
||||||
|
|
||||||
13
cmd/flux/testdata/create_source_helm/oci-with-secret.golden
vendored
Normal file
13
cmd/flux/testdata/create_source_helm/oci-with-secret.golden
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
apiVersion: source.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: HelmRepository
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: {{ .fluxns }}
|
||||||
|
spec:
|
||||||
|
interval: 5m0s
|
||||||
|
secretRef:
|
||||||
|
name: creds
|
||||||
|
type: oci
|
||||||
|
url: oci://ghcr.io/stefanprodan/charts/podinfo
|
||||||
|
|
||||||
11
cmd/flux/testdata/create_source_helm/oci.golden
vendored
Normal file
11
cmd/flux/testdata/create_source_helm/oci.golden
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
apiVersion: source.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: HelmRepository
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: {{ .fluxns }}
|
||||||
|
spec:
|
||||||
|
interval: 5m0s
|
||||||
|
type: oci
|
||||||
|
url: oci://ghcr.io/stefanprodan/charts/podinfo
|
||||||
|
|
||||||
6
cmd/flux/testdata/logs/all-logs.txt
vendored
Normal file
6
cmd/flux/testdata/logs/all-logs.txt
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
2022-08-02T12:55:34.419Z info GitRepository/podinfo.default - no changes since last reconcilation: observed revision
|
||||||
|
2022-08-02T12:56:04.679Z error GitRepository/flux-system.flux-system - no changes since last reconcilation: observed revision
|
||||||
|
2022-08-02T12:56:34.961Z error Kustomization/flux-system.flux-system - no changes since last reconcilation: observed revision
|
||||||
|
2022-08-02T12:56:34.961Z info Kustomization/podinfo.default - no changes since last reconcilation: observed revision
|
||||||
|
2022-08-02T12:56:34.961Z info GitRepository/podinfo.default - no changes since last reconcilation: observed revision
|
||||||
|
2022-08-02T12:56:34.961Z error Kustomization/podinfo.flux-system - no changes since last reconcilation: observed revision
|
||||||
2
cmd/flux/testdata/logs/kind.txt
vendored
Normal file
2
cmd/flux/testdata/logs/kind.txt
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
2022-08-02T12:56:34.961Z error Kustomization/flux-system.flux-system - no changes since last reconcilation: observed revision
|
||||||
|
2022-08-02T12:56:34.961Z error Kustomization/podinfo.flux-system - no changes since last reconcilation: observed revision
|
||||||
3
cmd/flux/testdata/logs/log-level.txt
vendored
Normal file
3
cmd/flux/testdata/logs/log-level.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
2022-08-02T12:56:04.679Z error GitRepository/flux-system.flux-system - no changes since last reconcilation: observed revision
|
||||||
|
2022-08-02T12:56:34.961Z error Kustomization/flux-system.flux-system - no changes since last reconcilation: observed revision
|
||||||
|
2022-08-02T12:56:34.961Z error Kustomization/podinfo.flux-system - no changes since last reconcilation: observed revision
|
||||||
1
cmd/flux/testdata/logs/multiple-filters.txt
vendored
Normal file
1
cmd/flux/testdata/logs/multiple-filters.txt
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
2022-08-02T12:56:34.961Z error Kustomization/podinfo.flux-system - no changes since last reconcilation: observed revision
|
||||||
3
cmd/flux/testdata/logs/namespace.txt
vendored
Normal file
3
cmd/flux/testdata/logs/namespace.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
2022-08-02T12:55:34.419Z info GitRepository/podinfo.default - no changes since last reconcilation: observed revision
|
||||||
|
2022-08-02T12:56:34.961Z info Kustomization/podinfo.default - no changes since last reconcilation: observed revision
|
||||||
|
2022-08-02T12:56:34.961Z info GitRepository/podinfo.default - no changes since last reconcilation: observed revision
|
||||||
5
cmd/flux/testdata/oci/create_source_oci.golden
vendored
Normal file
5
cmd/flux/testdata/oci/create_source_oci.golden
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
► applying OCIRepository
|
||||||
|
✔ OCIRepository created
|
||||||
|
◎ waiting for OCIRepository reconciliation
|
||||||
|
✔ OCIRepository reconciliation completed
|
||||||
|
✔ fetched revision: dbdb109711ffb3be77504d2670dbe13c24dd63d8d7f1fb489d350e5bfe930dd3
|
||||||
2
cmd/flux/testdata/oci/delete_oci.golden
vendored
Normal file
2
cmd/flux/testdata/oci/delete_oci.golden
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
► deleting source oci thrfg in {{ .ns }} namespace
|
||||||
|
✔ source oci deleted
|
||||||
12
cmd/flux/testdata/oci/export.golden
vendored
Normal file
12
cmd/flux/testdata/oci/export.golden
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
apiVersion: source.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: OCIRepository
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
interval: 10m0s
|
||||||
|
ref:
|
||||||
|
tag: 6.1.6
|
||||||
|
url: oci://ghcr.io/stefanprodan/manifests/podinfo
|
||||||
|
|
||||||
14
cmd/flux/testdata/oci/export_with_secret.golden
vendored
Normal file
14
cmd/flux/testdata/oci/export_with_secret.golden
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
apiVersion: source.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: OCIRepository
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
interval: 10m0s
|
||||||
|
ref:
|
||||||
|
tag: 6.1.6
|
||||||
|
secretRef:
|
||||||
|
name: creds
|
||||||
|
url: oci://ghcr.io/stefanprodan/manifests/podinfo
|
||||||
|
|
||||||
2
cmd/flux/testdata/oci/get_oci.golden
vendored
Normal file
2
cmd/flux/testdata/oci/get_oci.golden
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
NAME REVISION SUSPENDED READY MESSAGE
|
||||||
|
thrfg dbdb109711ffb3be77504d2670dbe13c24dd63d8d7f1fb489d350e5bfe930dd3 False True stored artifact for digest 'dbdb109711ffb3be77504d2670dbe13c24dd63d8d7f1fb489d350e5bfe930dd3'
|
||||||
4
cmd/flux/testdata/oci/reconcile_oci.golden
vendored
Normal file
4
cmd/flux/testdata/oci/reconcile_oci.golden
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
► annotating OCIRepository thrfg in {{ .ns }} namespace
|
||||||
|
✔ OCIRepository annotated
|
||||||
|
◎ waiting for OCIRepository reconciliation
|
||||||
|
✔ fetched revision dbdb109711ffb3be77504d2670dbe13c24dd63d8d7f1fb489d350e5bfe930dd3
|
||||||
5
cmd/flux/testdata/oci/resume_oci.golden
vendored
Normal file
5
cmd/flux/testdata/oci/resume_oci.golden
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
► resuming source oci thrfg in {{ .ns }} namespace
|
||||||
|
✔ source oci resumed
|
||||||
|
◎ waiting for OCIRepository reconciliation
|
||||||
|
✔ OCIRepository reconciliation completed
|
||||||
|
✔ fetched revision dbdb109711ffb3be77504d2670dbe13c24dd63d8d7f1fb489d350e5bfe930dd3
|
||||||
2
cmd/flux/testdata/oci/suspend_oci.golden
vendored
Normal file
2
cmd/flux/testdata/oci/suspend_oci.golden
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
► suspending source oci thrfg in {{ .ns }} namespace
|
||||||
|
✔ source oci suspended
|
||||||
21
cmd/flux/testdata/trace/helmrelease-oci.golden
vendored
Normal file
21
cmd/flux/testdata/trace/helmrelease-oci.golden
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
Object: HelmRelease/podinfo
|
||||||
|
Namespace: {{ .ns }}
|
||||||
|
Status: Managed by Flux
|
||||||
|
---
|
||||||
|
Kustomization: infrastructure
|
||||||
|
Namespace: {{ .fluxns }}
|
||||||
|
Path: ./infrastructure
|
||||||
|
Revision: main/696f056df216eea4f9401adbee0ff744d4df390f
|
||||||
|
Status: Last reconciled at {{ .kustomizationLastReconcile }}
|
||||||
|
Message: Applied revision: main/696f056df216eea4f9401adbee0ff744d4df390f
|
||||||
|
---
|
||||||
|
OCIRepository: flux-system
|
||||||
|
Namespace: {{ .fluxns }}
|
||||||
|
URL: oci://ghcr.io/example/repo
|
||||||
|
Tag: 1.2.3
|
||||||
|
Revision: dbdb109711ffb3be77504d2670dbe13c24dd63d8d7f1fb489d350e5bfe930dd3
|
||||||
|
Origin Revision: 6.1.6/450796ddb2ab6724ee1cc32a4be56da032d1cca0
|
||||||
|
Origin Source: https://github.com/stefanprodan/podinfo.git
|
||||||
|
Status: Last reconciled at {{ .ociRepositoryLastReconcile }}
|
||||||
|
Message: stored artifact for digest 'dbdb109711ffb3be77504d2670dbe13c24dd63d8d7f1fb489d350e5bfe930dd3'
|
||||||
92
cmd/flux/testdata/trace/helmrelease-oci.yaml
vendored
Normal file
92
cmd/flux/testdata/trace/helmrelease-oci.yaml
vendored
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: {{ .fluxns }}
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: {{ .ns }}
|
||||||
|
---
|
||||||
|
apiVersion: helm.toolkit.fluxcd.io/v2beta1
|
||||||
|
kind: HelmRelease
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
kustomize.toolkit.fluxcd.io/name: infrastructure
|
||||||
|
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||||
|
name: podinfo
|
||||||
|
namespace: {{ .ns }}
|
||||||
|
spec:
|
||||||
|
chart:
|
||||||
|
spec:
|
||||||
|
chart: podinfo
|
||||||
|
sourceRef:
|
||||||
|
kind: HelmRepository
|
||||||
|
name: podinfo
|
||||||
|
namespace: {{ .fluxns }}
|
||||||
|
interval: 5m
|
||||||
|
status:
|
||||||
|
conditions:
|
||||||
|
- lastTransitionTime: "2021-07-16T15:42:20Z"
|
||||||
|
message: Release reconciliation succeeded
|
||||||
|
reason: ReconciliationSucceeded
|
||||||
|
status: "True"
|
||||||
|
type: Ready
|
||||||
|
helmChart: {{ .fluxns }}/podinfo-podinfo
|
||||||
|
lastAppliedRevision: 6.0.0
|
||||||
|
lastAttemptedRevision: 6.0.0
|
||||||
|
lastAttemptedValuesChecksum: c31db75d05b7515eba2eef47bd71038c74b2e531
|
||||||
|
---
|
||||||
|
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: Kustomization
|
||||||
|
metadata:
|
||||||
|
name: infrastructure
|
||||||
|
namespace: {{ .fluxns }}
|
||||||
|
spec:
|
||||||
|
path: ./infrastructure
|
||||||
|
sourceRef:
|
||||||
|
kind: OCIRepository
|
||||||
|
name: flux-system
|
||||||
|
validation: client
|
||||||
|
interval: 5m
|
||||||
|
prune: false
|
||||||
|
status:
|
||||||
|
conditions:
|
||||||
|
- lastTransitionTime: "2021-08-01T04:52:56Z"
|
||||||
|
message: 'Applied revision: main/696f056df216eea4f9401adbee0ff744d4df390f'
|
||||||
|
reason: ReconciliationSucceeded
|
||||||
|
status: "True"
|
||||||
|
type: Ready
|
||||||
|
lastAppliedRevision: main/696f056df216eea4f9401adbee0ff744d4df390f
|
||||||
|
---
|
||||||
|
apiVersion: source.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: OCIRepository
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
kustomize.toolkit.fluxcd.io/name: flux-system
|
||||||
|
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||||
|
name: flux-system
|
||||||
|
namespace: {{ .fluxns }}
|
||||||
|
spec:
|
||||||
|
interval: 10m0s
|
||||||
|
provider: generic
|
||||||
|
ref:
|
||||||
|
tag: 1.2.3
|
||||||
|
timeout: 60s
|
||||||
|
url: oci://ghcr.io/example/repo
|
||||||
|
status:
|
||||||
|
artifact:
|
||||||
|
lastUpdateTime: "2022-08-10T10:07:59Z"
|
||||||
|
metadata:
|
||||||
|
org.opencontainers.image.revision: 6.1.6/450796ddb2ab6724ee1cc32a4be56da032d1cca0
|
||||||
|
org.opencontainers.image.source: https://github.com/stefanprodan/podinfo.git
|
||||||
|
path: "example"
|
||||||
|
revision: dbdb109711ffb3be77504d2670dbe13c24dd63d8d7f1fb489d350e5bfe930dd3
|
||||||
|
url: "example"
|
||||||
|
conditions:
|
||||||
|
- lastTransitionTime: "2021-07-20T00:48:16Z"
|
||||||
|
message: "stored artifact for digest 'dbdb109711ffb3be77504d2670dbe13c24dd63d8d7f1fb489d350e5bfe930dd3'"
|
||||||
|
reason: Succeed
|
||||||
|
status: "True"
|
||||||
|
type: Ready
|
||||||
32
cmd/flux/testdata/trace/helmrelease.golden
vendored
32
cmd/flux/testdata/trace/helmrelease.golden
vendored
@@ -1,19 +1,19 @@
|
|||||||
|
|
||||||
Object: HelmRelease/podinfo
|
Object: HelmRelease/podinfo
|
||||||
Namespace: {{ .ns }}
|
Namespace: {{ .ns }}
|
||||||
Status: Managed by Flux
|
Status: Managed by Flux
|
||||||
---
|
---
|
||||||
Kustomization: infrastructure
|
Kustomization: infrastructure
|
||||||
Namespace: {{ .fluxns }}
|
Namespace: {{ .fluxns }}
|
||||||
Path: ./infrastructure
|
Path: ./infrastructure
|
||||||
Revision: main/696f056df216eea4f9401adbee0ff744d4df390f
|
Revision: main/696f056df216eea4f9401adbee0ff744d4df390f
|
||||||
Status: Last reconciled at {{ .kustomizationLastReconcile }}
|
Status: Last reconciled at {{ .kustomizationLastReconcile }}
|
||||||
Message: Applied revision: main/696f056df216eea4f9401adbee0ff744d4df390f
|
Message: Applied revision: main/696f056df216eea4f9401adbee0ff744d4df390f
|
||||||
---
|
---
|
||||||
GitRepository: flux-system
|
GitRepository: flux-system
|
||||||
Namespace: {{ .fluxns }}
|
Namespace: {{ .fluxns }}
|
||||||
URL: ssh://git@github.com/example/repo
|
URL: ssh://git@github.com/example/repo
|
||||||
Branch: main
|
Branch: main
|
||||||
Revision: main/696f056df216eea4f9401adbee0ff744d4df390f
|
Revision: main/696f056df216eea4f9401adbee0ff744d4df390f
|
||||||
Status: Last reconciled at {{ .gitRepositoryLastReconcile }}
|
Status: Last reconciled at {{ .gitRepositoryLastReconcile }}
|
||||||
Message: Fetched revision: main/696f056df216eea4f9401adbee0ff744d4df390f
|
Message: Fetched revision: main/696f056df216eea4f9401adbee0ff744d4df390f
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import (
|
|||||||
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
|
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
|
||||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||||
fluxmeta "github.com/fluxcd/pkg/apis/meta"
|
fluxmeta "github.com/fluxcd/pkg/apis/meta"
|
||||||
|
"github.com/fluxcd/pkg/oci"
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -219,10 +220,12 @@ func traceKustomization(ctx context.Context, kubeClient client.Client, ksName ty
|
|||||||
}
|
}
|
||||||
ksReady := meta.FindStatusCondition(ks.Status.Conditions, fluxmeta.ReadyCondition)
|
ksReady := meta.FindStatusCondition(ks.Status.Conditions, fluxmeta.ReadyCondition)
|
||||||
|
|
||||||
var ksRepository *sourcev1.GitRepository
|
var gitRepository *sourcev1.GitRepository
|
||||||
|
var ociRepository *sourcev1.OCIRepository
|
||||||
var ksRepositoryReady *metav1.Condition
|
var ksRepositoryReady *metav1.Condition
|
||||||
if ks.Spec.SourceRef.Kind == sourcev1.GitRepositoryKind {
|
switch ks.Spec.SourceRef.Kind {
|
||||||
ksRepository = &sourcev1.GitRepository{}
|
case sourcev1.GitRepositoryKind:
|
||||||
|
gitRepository = &sourcev1.GitRepository{}
|
||||||
sourceNamespace := ks.Namespace
|
sourceNamespace := ks.Namespace
|
||||||
if ks.Spec.SourceRef.Namespace != "" {
|
if ks.Spec.SourceRef.Namespace != "" {
|
||||||
sourceNamespace = ks.Spec.SourceRef.Namespace
|
sourceNamespace = ks.Spec.SourceRef.Namespace
|
||||||
@@ -230,61 +233,109 @@ func traceKustomization(ctx context.Context, kubeClient client.Client, ksName ty
|
|||||||
err = kubeClient.Get(ctx, types.NamespacedName{
|
err = kubeClient.Get(ctx, types.NamespacedName{
|
||||||
Namespace: sourceNamespace,
|
Namespace: sourceNamespace,
|
||||||
Name: ks.Spec.SourceRef.Name,
|
Name: ks.Spec.SourceRef.Name,
|
||||||
}, ksRepository)
|
}, gitRepository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to find GitRepository: %w", err)
|
return "", fmt.Errorf("failed to find GitRepository: %w", err)
|
||||||
}
|
}
|
||||||
ksRepositoryReady = meta.FindStatusCondition(ksRepository.Status.Conditions, fluxmeta.ReadyCondition)
|
ksRepositoryReady = meta.FindStatusCondition(gitRepository.Status.Conditions, fluxmeta.ReadyCondition)
|
||||||
|
case sourcev1.OCIRepositoryKind:
|
||||||
|
ociRepository = &sourcev1.OCIRepository{}
|
||||||
|
sourceNamespace := ks.Namespace
|
||||||
|
if ks.Spec.SourceRef.Namespace != "" {
|
||||||
|
sourceNamespace = ks.Spec.SourceRef.Namespace
|
||||||
|
}
|
||||||
|
err = kubeClient.Get(ctx, types.NamespacedName{
|
||||||
|
Namespace: sourceNamespace,
|
||||||
|
Name: ks.Spec.SourceRef.Name,
|
||||||
|
}, ociRepository)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to find OCIRepository: %w", err)
|
||||||
|
}
|
||||||
|
ksRepositoryReady = meta.FindStatusCondition(ociRepository.Status.Conditions, fluxmeta.ReadyCondition)
|
||||||
}
|
}
|
||||||
|
|
||||||
var traceTmpl = `
|
var traceTmpl = `
|
||||||
Object: {{.ObjectName}}
|
Object: {{.ObjectName}}
|
||||||
{{- if .ObjectNamespace }}
|
{{- if .ObjectNamespace }}
|
||||||
Namespace: {{.ObjectNamespace}}
|
Namespace: {{.ObjectNamespace}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
Status: Managed by Flux
|
Status: Managed by Flux
|
||||||
{{- if .Kustomization }}
|
{{- if .Kustomization }}
|
||||||
---
|
---
|
||||||
Kustomization: {{.Kustomization.Name}}
|
Kustomization: {{.Kustomization.Name}}
|
||||||
Namespace: {{.Kustomization.Namespace}}
|
Namespace: {{.Kustomization.Namespace}}
|
||||||
{{- if .Kustomization.Spec.TargetNamespace }}
|
{{- if .Kustomization.Spec.TargetNamespace }}
|
||||||
Target: {{.Kustomization.Spec.TargetNamespace}}
|
Target: {{.Kustomization.Spec.TargetNamespace}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
Path: {{.Kustomization.Spec.Path}}
|
Path: {{.Kustomization.Spec.Path}}
|
||||||
Revision: {{.Kustomization.Status.LastAppliedRevision}}
|
Revision: {{.Kustomization.Status.LastAppliedRevision}}
|
||||||
{{- if .KustomizationReady }}
|
{{- if .KustomizationReady }}
|
||||||
Status: Last reconciled at {{.KustomizationReady.LastTransitionTime}}
|
Status: Last reconciled at {{.KustomizationReady.LastTransitionTime}}
|
||||||
Message: {{.KustomizationReady.Message}}
|
Message: {{.KustomizationReady.Message}}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
Status: Unknown
|
Status: Unknown
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if .GitRepository }}
|
{{- if .GitRepository }}
|
||||||
---
|
---
|
||||||
GitRepository: {{.GitRepository.Name}}
|
GitRepository: {{.GitRepository.Name}}
|
||||||
Namespace: {{.GitRepository.Namespace}}
|
Namespace: {{.GitRepository.Namespace}}
|
||||||
URL: {{.GitRepository.Spec.URL}}
|
URL: {{.GitRepository.Spec.URL}}
|
||||||
{{- if .GitRepository.Spec.Reference }}
|
{{- if .GitRepository.Spec.Reference }}
|
||||||
{{- if .GitRepository.Spec.Reference.Tag }}
|
{{- if .GitRepository.Spec.Reference.Tag }}
|
||||||
Tag: {{.GitRepository.Spec.Reference.Tag}}
|
Tag: {{.GitRepository.Spec.Reference.Tag}}
|
||||||
{{- else if .GitRepository.Spec.Reference.SemVer }}
|
{{- else if .GitRepository.Spec.Reference.SemVer }}
|
||||||
Tag: {{.GitRepository.Spec.Reference.SemVer}}
|
Tag: {{.GitRepository.Spec.Reference.SemVer}}
|
||||||
{{- else if .GitRepository.Spec.Reference.Branch }}
|
{{- else if .GitRepository.Spec.Reference.Branch }}
|
||||||
Branch: {{.GitRepository.Spec.Reference.Branch}}
|
Branch: {{.GitRepository.Spec.Reference.Branch}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if .GitRepository.Status.Artifact }}
|
{{- if .GitRepository.Status.Artifact }}
|
||||||
Revision: {{.GitRepository.Status.Artifact.Revision}}
|
Revision: {{.GitRepository.Status.Artifact.Revision}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if .GitRepositoryReady }}
|
{{- if .RepositoryReady }}
|
||||||
{{- if eq .GitRepositoryReady.Status "False" }}
|
{{- if eq .RepositoryReady.Status "False" }}
|
||||||
Status: Last reconciliation failed at {{.GitRepositoryReady.LastTransitionTime}}
|
Status: Last reconciliation failed at {{.RepositoryReady.LastTransitionTime}}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
Status: Last reconciled at {{.GitRepositoryReady.LastTransitionTime}}
|
Status: Last reconciled at {{.RepositoryReady.LastTransitionTime}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
Message: {{.GitRepositoryReady.Message}}
|
Message: {{.RepositoryReady.Message}}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
Status: Unknown
|
Status: Unknown
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .OCIRepository }}
|
||||||
|
---
|
||||||
|
OCIRepository: {{.OCIRepository.Name}}
|
||||||
|
Namespace: {{.OCIRepository.Namespace}}
|
||||||
|
URL: {{.OCIRepository.Spec.URL}}
|
||||||
|
{{- if .OCIRepository.Spec.Reference }}
|
||||||
|
{{- if .OCIRepository.Spec.Reference.Tag }}
|
||||||
|
Tag: {{.OCIRepository.Spec.Reference.Tag}}
|
||||||
|
{{- else if .OCIRepository.Spec.Reference.SemVer }}
|
||||||
|
Tag: {{.OCIRepository.Spec.Reference.SemVer}}
|
||||||
|
{{- else if .OCIRepository.Spec.Reference.Digest }}
|
||||||
|
Digest: {{.OCIRepository.Spec.Reference.Digest}}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .OCIRepository.Status.Artifact }}
|
||||||
|
Revision: {{.OCIRepository.Status.Artifact.Revision}}
|
||||||
|
{{- if .OCIRepository.Status.Artifact.Metadata }}
|
||||||
|
{{- $metadata := .OCIRepository.Status.Artifact.Metadata }}
|
||||||
|
{{- range $k, $v := .Annotations }}
|
||||||
|
{{ with (index $metadata $v) }}{{ $k }}{{ . }}{{ end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .RepositoryReady }}
|
||||||
|
{{- if eq .RepositoryReady.Status "False" }}
|
||||||
|
Status: Last reconciliation failed at {{.RepositoryReady.LastTransitionTime}}
|
||||||
|
{{- else }}
|
||||||
|
Status: Last reconciled at {{.RepositoryReady.LastTransitionTime}}
|
||||||
|
{{- end }}
|
||||||
|
Message: {{.RepositoryReady.Message}}
|
||||||
|
{{- else }}
|
||||||
|
Status: Unknown
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
`
|
`
|
||||||
@@ -295,14 +346,18 @@ Status: Unknown
|
|||||||
Kustomization *kustomizev1.Kustomization
|
Kustomization *kustomizev1.Kustomization
|
||||||
KustomizationReady *metav1.Condition
|
KustomizationReady *metav1.Condition
|
||||||
GitRepository *sourcev1.GitRepository
|
GitRepository *sourcev1.GitRepository
|
||||||
GitRepositoryReady *metav1.Condition
|
OCIRepository *sourcev1.OCIRepository
|
||||||
|
RepositoryReady *metav1.Condition
|
||||||
|
Annotations map[string]string
|
||||||
}{
|
}{
|
||||||
ObjectName: obj.GetKind() + "/" + obj.GetName(),
|
ObjectName: obj.GetKind() + "/" + obj.GetName(),
|
||||||
ObjectNamespace: obj.GetNamespace(),
|
ObjectNamespace: obj.GetNamespace(),
|
||||||
Kustomization: ks,
|
Kustomization: ks,
|
||||||
KustomizationReady: ksReady,
|
KustomizationReady: ksReady,
|
||||||
GitRepository: ksRepository,
|
GitRepository: gitRepository,
|
||||||
GitRepositoryReady: ksRepositoryReady,
|
OCIRepository: ociRepository,
|
||||||
|
RepositoryReady: ksRepositoryReady,
|
||||||
|
Annotations: map[string]string{"Origin Source: ": oci.SourceAnnotation, "Origin Revision: ": oci.RevisionAnnotation},
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := template.New("tmpl").Parse(traceTmpl)
|
t, err := template.New("tmpl").Parse(traceTmpl)
|
||||||
|
|||||||
@@ -57,6 +57,18 @@ func TestTrace(t *testing.T) {
|
|||||||
"gitRepositoryLastReconcile": toLocalTime(t, "2021-07-20T00:48:16Z"),
|
"gitRepositoryLastReconcile": toLocalTime(t, "2021-07-20T00:48:16Z"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"HelmRelease from OCI registry",
|
||||||
|
"trace podinfo --kind HelmRelease --api-version=helm.toolkit.fluxcd.io/v2beta1",
|
||||||
|
"testdata/trace/helmrelease-oci.yaml",
|
||||||
|
"testdata/trace/helmrelease-oci.golden",
|
||||||
|
map[string]string{
|
||||||
|
"ns": allocateNamespace("podinfo"),
|
||||||
|
"fluxns": allocateNamespace("flux-system"),
|
||||||
|
"kustomizationLastReconcile": toLocalTime(t, "2021-08-01T04:52:56Z"),
|
||||||
|
"ociRepositoryLastReconcile": toLocalTime(t, "2021-07-20T00:48:16Z"),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ import (
|
|||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
"github.com/fluxcd/flux2/pkg/manifestgen"
|
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||||
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
|
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
|
||||||
|
autov1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
|
||||||
|
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
||||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
@@ -261,6 +263,45 @@ func uninstallFinalizers(ctx context.Context, kubeClient client.Client, dryRun b
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
var list imagev1.ImagePolicyList
|
||||||
|
if err := kubeClient.List(ctx, &list, client.InNamespace("")); err == nil {
|
||||||
|
for _, r := range list.Items {
|
||||||
|
r.Finalizers = []string{}
|
||||||
|
if err := kubeClient.Update(ctx, &r, opts); err != nil {
|
||||||
|
logger.Failuref("%s/%s/%s removing finalizers failed: %s", r.Kind, r.Namespace, r.Name, err.Error())
|
||||||
|
} else {
|
||||||
|
logger.Successf("%s/%s/%s finalizers deleted %s", r.Kind, r.Namespace, r.Name, dryRunStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var list imagev1.ImageRepositoryList
|
||||||
|
if err := kubeClient.List(ctx, &list, client.InNamespace("")); err == nil {
|
||||||
|
for _, r := range list.Items {
|
||||||
|
r.Finalizers = []string{}
|
||||||
|
if err := kubeClient.Update(ctx, &r, opts); err != nil {
|
||||||
|
logger.Failuref("%s/%s/%s removing finalizers failed: %s", r.Kind, r.Namespace, r.Name, err.Error())
|
||||||
|
} else {
|
||||||
|
logger.Successf("%s/%s/%s finalizers deleted %s", r.Kind, r.Namespace, r.Name, dryRunStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var list autov1.ImageUpdateAutomationList
|
||||||
|
if err := kubeClient.List(ctx, &list, client.InNamespace("")); err == nil {
|
||||||
|
for _, r := range list.Items {
|
||||||
|
r.Finalizers = []string{}
|
||||||
|
if err := kubeClient.Update(ctx, &r, opts); err != nil {
|
||||||
|
logger.Failuref("%s/%s/%s removing finalizers failed: %s", r.Kind, r.Namespace, r.Name, err.Error())
|
||||||
|
} else {
|
||||||
|
logger.Successf("%s/%s/%s finalizers deleted %s", r.Kind, r.Namespace, r.Name, dryRunStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func uninstallCustomResourceDefinitions(ctx context.Context, kubeClient client.Client, dryRun bool) {
|
func uninstallCustomResourceDefinitions(ctx context.Context, kubeClient client.Client, dryRun bool) {
|
||||||
|
|||||||
135
go.mod
135
go.mod
@@ -4,90 +4,98 @@ go 1.17
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Masterminds/semver/v3 v3.1.1
|
github.com/Masterminds/semver/v3 v3.1.1
|
||||||
github.com/ProtonMail/go-crypto v0.0.0-20220407094043-a94812496cf5
|
github.com/ProtonMail/go-crypto v0.0.0-20220517143526-88bb52951d5b
|
||||||
github.com/cyphar/filepath-securejoin v0.2.3
|
github.com/cyphar/filepath-securejoin v0.2.3
|
||||||
github.com/fluxcd/go-git-providers v0.5.4
|
github.com/fluxcd/go-git-providers v0.6.0
|
||||||
github.com/fluxcd/helm-controller/api v0.20.1
|
github.com/fluxcd/helm-controller/api v0.22.2
|
||||||
github.com/fluxcd/image-automation-controller/api v0.22.0
|
github.com/fluxcd/image-automation-controller/api v0.24.1
|
||||||
github.com/fluxcd/image-reflector-controller/api v0.17.2
|
github.com/fluxcd/image-reflector-controller/api v0.20.0
|
||||||
github.com/fluxcd/kustomize-controller/api v0.24.2
|
github.com/fluxcd/kustomize-controller/api v0.27.0
|
||||||
github.com/fluxcd/notification-controller/api v0.23.4
|
github.com/fluxcd/notification-controller/api v0.25.1
|
||||||
github.com/fluxcd/pkg/apis/meta v0.12.2
|
github.com/fluxcd/pkg/apis/meta v0.14.2
|
||||||
github.com/fluxcd/pkg/kustomize v0.2.0
|
github.com/fluxcd/pkg/kustomize v0.5.2
|
||||||
github.com/fluxcd/pkg/runtime v0.14.1
|
github.com/fluxcd/pkg/oci v0.3.0
|
||||||
github.com/fluxcd/pkg/ssa v0.15.2
|
github.com/fluxcd/pkg/runtime v0.16.2
|
||||||
github.com/fluxcd/pkg/ssh v0.3.2
|
github.com/fluxcd/pkg/ssa v0.17.0
|
||||||
|
github.com/fluxcd/pkg/ssh v0.5.0
|
||||||
github.com/fluxcd/pkg/untar v0.1.0
|
github.com/fluxcd/pkg/untar v0.1.0
|
||||||
github.com/fluxcd/pkg/version v0.1.0
|
github.com/fluxcd/pkg/version v0.1.0
|
||||||
github.com/fluxcd/source-controller/api v0.24.0
|
github.com/fluxcd/source-controller/api v0.26.1
|
||||||
github.com/go-git/go-git/v5 v5.4.2
|
github.com/go-git/go-git/v5 v5.4.2
|
||||||
github.com/gonvenience/bunt v1.3.3
|
github.com/gonvenience/bunt v1.3.4
|
||||||
github.com/gonvenience/ytbx v1.4.4
|
github.com/gonvenience/ytbx v1.4.4
|
||||||
github.com/google/go-cmp v0.5.7
|
github.com/google/go-cmp v0.5.8
|
||||||
github.com/google/go-containerregistry v0.8.0
|
github.com/google/go-containerregistry v0.10.0
|
||||||
github.com/hashicorp/go-multierror v1.1.1
|
github.com/hashicorp/go-multierror v1.1.1
|
||||||
github.com/homeport/dyff v1.5.2
|
github.com/homeport/dyff v1.5.4
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0
|
github.com/lucasb-eyer/go-colorful v1.2.0
|
||||||
github.com/manifoldco/promptui v0.9.0
|
github.com/manifoldco/promptui v0.9.0
|
||||||
github.com/mattn/go-shellwords v1.0.12
|
github.com/mattn/go-shellwords v1.0.12
|
||||||
github.com/olekukonko/tablewriter v0.0.5
|
github.com/olekukonko/tablewriter v0.0.5
|
||||||
|
github.com/onsi/gomega v1.19.0
|
||||||
github.com/spf13/cobra v1.4.0
|
github.com/spf13/cobra v1.4.0
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
github.com/theckman/yacspin v0.13.12
|
github.com/theckman/yacspin v0.13.12
|
||||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
|
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
|
||||||
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171
|
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467
|
||||||
k8s.io/api v0.23.5
|
k8s.io/api v0.24.3
|
||||||
k8s.io/apiextensions-apiserver v0.23.5
|
k8s.io/apiextensions-apiserver v0.24.3
|
||||||
k8s.io/apimachinery v0.23.5
|
k8s.io/apimachinery v0.24.3
|
||||||
k8s.io/cli-runtime v0.23.5
|
k8s.io/cli-runtime v0.24.1
|
||||||
k8s.io/client-go v0.23.5
|
k8s.io/client-go v0.24.3
|
||||||
k8s.io/kubectl v0.23.5
|
k8s.io/kubectl v0.24.1
|
||||||
sigs.k8s.io/cli-utils v0.29.4
|
sigs.k8s.io/cli-utils v0.32.0
|
||||||
sigs.k8s.io/controller-runtime v0.11.2
|
sigs.k8s.io/controller-runtime v0.11.2
|
||||||
sigs.k8s.io/kustomize/api v0.11.4
|
sigs.k8s.io/kustomize/api v0.12.1
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.6
|
sigs.k8s.io/kustomize/kyaml v0.13.9
|
||||||
sigs.k8s.io/yaml v1.3.0
|
sigs.k8s.io/yaml v1.3.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Fix CVE-2022-28948
|
||||||
|
replace gopkg.in/yaml.v3 => gopkg.in/yaml.v3 v3.0.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
cloud.google.com/go v0.99.0 // indirect
|
cloud.google.com/go v0.99.0 // indirect
|
||||||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
|
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
|
||||||
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
|
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
|
||||||
github.com/Azure/go-autorest/autorest v0.11.18 // indirect
|
github.com/Azure/go-autorest/autorest v0.11.24 // indirect
|
||||||
github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect
|
github.com/Azure/go-autorest/autorest/adal v0.9.18 // indirect
|
||||||
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
|
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
|
||||||
github.com/Azure/go-autorest/logger v0.2.1 // indirect
|
github.com/Azure/go-autorest/logger v0.2.1 // indirect
|
||||||
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
|
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
|
||||||
github.com/BurntSushi/toml v1.0.0 // indirect
|
github.com/BurntSushi/toml v1.0.0 // indirect
|
||||||
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd // indirect
|
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd // indirect
|
||||||
github.com/Microsoft/go-winio v0.5.1 // indirect
|
github.com/Microsoft/go-winio v0.5.2 // indirect
|
||||||
github.com/PuerkitoBio/purell v1.1.1 // indirect
|
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
|
|
||||||
github.com/acomagu/bufpipe v1.0.3 // indirect
|
github.com/acomagu/bufpipe v1.0.3 // indirect
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||||
github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5 // indirect
|
github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5 // indirect
|
||||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
|
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
|
github.com/containerd/stargz-snapshotter/estargz v0.11.4 // indirect
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/docker/cli v20.10.17+incompatible // indirect
|
||||||
|
github.com/docker/distribution v2.8.1+incompatible // indirect
|
||||||
|
github.com/docker/docker v20.10.17+incompatible // indirect
|
||||||
|
github.com/docker/docker-credential-helpers v0.6.4 // indirect
|
||||||
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46 // indirect
|
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46 // indirect
|
||||||
|
github.com/emicklei/go-restful v2.15.0+incompatible // indirect
|
||||||
github.com/emirpasic/gods v1.12.0 // indirect
|
github.com/emirpasic/gods v1.12.0 // indirect
|
||||||
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
|
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
|
||||||
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
|
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
|
||||||
github.com/fatih/color v1.13.0 // indirect
|
github.com/fatih/color v1.13.0 // indirect
|
||||||
github.com/fluxcd/pkg/apis/acl v0.0.3 // indirect
|
github.com/fluxcd/pkg/apis/acl v0.0.3 // indirect
|
||||||
github.com/fluxcd/pkg/apis/kustomize v0.3.3 // indirect
|
github.com/fluxcd/pkg/apis/kustomize v0.4.2 // indirect
|
||||||
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
|
|
||||||
github.com/fsnotify/fsnotify v1.5.1 // indirect
|
github.com/fsnotify/fsnotify v1.5.1 // indirect
|
||||||
github.com/fvbommel/sortorder v1.0.1 // indirect
|
|
||||||
github.com/go-errors/errors v1.0.1 // indirect
|
github.com/go-errors/errors v1.0.1 // indirect
|
||||||
github.com/go-git/gcfg v1.5.0 // indirect
|
github.com/go-git/gcfg v1.5.0 // indirect
|
||||||
github.com/go-git/go-billy/v5 v5.3.1 // indirect
|
github.com/go-git/go-billy/v5 v5.3.1 // indirect
|
||||||
github.com/go-logr/logr v1.2.2 // indirect
|
github.com/go-logr/logr v1.2.3 // indirect
|
||||||
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
||||||
github.com/go-openapi/jsonreference v0.19.5 // indirect
|
github.com/go-openapi/jsonreference v0.20.0 // indirect
|
||||||
github.com/go-openapi/swag v0.19.14 // indirect
|
github.com/go-openapi/swag v0.21.1 // indirect
|
||||||
github.com/gogo/protobuf v1.3.2 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
|
github.com/golang-jwt/jwt/v4 v4.4.1 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
github.com/golang/protobuf v1.5.2 // indirect
|
github.com/golang/protobuf v1.5.2 // indirect
|
||||||
github.com/gonvenience/neat v1.3.10 // indirect
|
github.com/gonvenience/neat v1.3.10 // indirect
|
||||||
@@ -95,24 +103,25 @@ require (
|
|||||||
github.com/gonvenience/text v1.0.7 // indirect
|
github.com/gonvenience/text v1.0.7 // indirect
|
||||||
github.com/gonvenience/wrap v1.1.1 // indirect
|
github.com/gonvenience/wrap v1.1.1 // indirect
|
||||||
github.com/google/btree v1.0.1 // indirect
|
github.com/google/btree v1.0.1 // indirect
|
||||||
github.com/google/go-github/v41 v41.0.0 // indirect
|
github.com/google/gnostic v0.6.9 // indirect
|
||||||
|
github.com/google/go-github/v42 v42.0.0 // indirect
|
||||||
github.com/google/go-querystring v1.1.0 // indirect
|
github.com/google/go-querystring v1.1.0 // indirect
|
||||||
github.com/google/gofuzz v1.2.0 // indirect
|
github.com/google/gofuzz v1.2.0 // indirect
|
||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
github.com/googleapis/gnostic v0.5.5 // indirect
|
|
||||||
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
|
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
|
||||||
github.com/hashicorp/errwrap v1.0.0 // indirect
|
github.com/hashicorp/errwrap v1.0.0 // indirect
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||||
github.com/hashicorp/go-retryablehttp v0.7.0 // indirect
|
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
|
||||||
github.com/imdario/mergo v0.3.12 // indirect
|
github.com/imdario/mergo v0.3.12 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
||||||
github.com/josharian/intern v1.0.0 // indirect
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
|
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
|
||||||
|
github.com/klauspost/compress v1.15.4 // indirect
|
||||||
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
|
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
|
||||||
github.com/mailru/easyjson v0.7.6 // indirect
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
github.com/mattn/go-ciede2000 v0.0.0-20170301095244-782e8c62fec3 // indirect
|
github.com/mattn/go-ciede2000 v0.0.0-20170301095244-782e8c62fec3 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||||
@@ -123,46 +132,48 @@ require (
|
|||||||
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
|
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
|
||||||
github.com/mitchellh/hashstructure v1.1.0 // indirect
|
github.com/mitchellh/hashstructure v1.1.0 // indirect
|
||||||
github.com/moby/spdystream v0.2.0 // indirect
|
github.com/moby/spdystream v0.2.0 // indirect
|
||||||
github.com/moby/term v0.0.0-20210610120745-9d4ed1856297 // indirect
|
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
|
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
|
||||||
github.com/onsi/gomega v1.19.0 // indirect
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
|
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||||
|
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198 // indirect
|
||||||
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
|
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
|
||||||
github.com/prometheus/client_golang v1.12.1 // indirect
|
github.com/prometheus/client_golang v1.12.1 // indirect
|
||||||
github.com/prometheus/client_model v0.2.0 // indirect
|
github.com/prometheus/client_model v0.2.0 // indirect
|
||||||
github.com/prometheus/common v0.32.1 // indirect
|
github.com/prometheus/common v0.32.1 // indirect
|
||||||
github.com/prometheus/procfs v0.7.3 // indirect
|
github.com/prometheus/procfs v0.7.3 // indirect
|
||||||
github.com/rivo/uniseg v0.2.0 // indirect
|
github.com/rivo/uniseg v0.2.0 // indirect
|
||||||
github.com/russross/blackfriday v1.5.2 // indirect
|
github.com/russross/blackfriday v1.6.0 // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
github.com/sergi/go-diff v1.2.0 // indirect
|
github.com/sergi/go-diff v1.2.0 // indirect
|
||||||
github.com/stretchr/testify v1.7.1 // indirect
|
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||||
github.com/texttheater/golang-levenshtein v1.0.1 // indirect
|
github.com/texttheater/golang-levenshtein v1.0.1 // indirect
|
||||||
|
github.com/vbatts/tar-split v0.11.2 // indirect
|
||||||
github.com/virtuald/go-ordered-json v0.0.0-20170621173500-b18e6e673d74 // indirect
|
github.com/virtuald/go-ordered-json v0.0.0-20170621173500-b18e6e673d74 // indirect
|
||||||
github.com/xanzy/go-gitlab v0.54.3 // indirect
|
github.com/xanzy/go-gitlab v0.58.0 // indirect
|
||||||
github.com/xanzy/ssh-agent v0.3.0 // indirect
|
github.com/xanzy/ssh-agent v0.3.0 // indirect
|
||||||
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
|
github.com/xlab/treeprint v1.1.0 // indirect
|
||||||
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
|
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
|
||||||
golang.org/x/net v0.0.0-20220325170049-de3da57026de // indirect
|
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
|
||||||
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
|
golang.org/x/oauth2 v0.0.0-20220718184931-c8730f7fcb92 // indirect
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
|
||||||
golang.org/x/sys v0.0.0-20220325203850-36772127a21f // indirect
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
||||||
golang.org/x/text v0.3.7 // indirect
|
golang.org/x/text v0.3.7 // indirect
|
||||||
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
|
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
|
||||||
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
|
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
|
||||||
google.golang.org/appengine v1.6.7 // indirect
|
google.golang.org/appengine v1.6.7 // indirect
|
||||||
google.golang.org/protobuf v1.27.1 // indirect
|
google.golang.org/protobuf v1.28.0 // indirect
|
||||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||||
gopkg.in/warnings.v0 v0.1.2 // indirect
|
gopkg.in/warnings.v0 v0.1.2 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
k8s.io/component-base v0.23.5 // indirect
|
k8s.io/component-base v0.24.3 // indirect
|
||||||
k8s.io/klog/v2 v2.50.0 // indirect
|
k8s.io/klog/v2 v2.60.1 // indirect
|
||||||
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
|
k8s.io/kube-openapi v0.0.0-20220413171646-5e7f5fdc6da6 // indirect
|
||||||
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
|
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
|
||||||
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
|
sigs.k8s.io/json v0.0.0-20220525155127-227cbc7cc124 // indirect
|
||||||
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
|
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -31,11 +31,11 @@ import (
|
|||||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
"sigs.k8s.io/cli-utils/pkg/object"
|
"sigs.k8s.io/cli-utils/pkg/object"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
"sigs.k8s.io/kustomize/api/filesys"
|
|
||||||
"sigs.k8s.io/kustomize/api/konfig"
|
"sigs.k8s.io/kustomize/api/konfig"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||||
|
"github.com/fluxcd/pkg/kustomize/filesys"
|
||||||
runclient "github.com/fluxcd/pkg/runtime/client"
|
runclient "github.com/fluxcd/pkg/runtime/client"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/bootstrap/git"
|
"github.com/fluxcd/flux2/internal/bootstrap/git"
|
||||||
@@ -105,7 +105,7 @@ func NewPlainGitProvider(git git.Git, kube client.Client, opts ...GitOption) (*P
|
|||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *PlainGitBootstrapper) ReconcileComponents(ctx context.Context, manifestsBase string, options install.Options, secretOpts sourcesecret.Options) error {
|
func (b *PlainGitBootstrapper) ReconcileComponents(ctx context.Context, manifestsBase string, options install.Options, _ sourcesecret.Options) error {
|
||||||
// Clone if not already
|
// Clone if not already
|
||||||
if _, err := b.git.Status(); err != nil {
|
if _, err := b.git.Status(); err != nil {
|
||||||
if err != git.ErrNoGitRepository {
|
if err != git.ErrNoGitRepository {
|
||||||
@@ -163,19 +163,18 @@ func (b *PlainGitBootstrapper) ReconcileComponents(ctx context.Context, manifest
|
|||||||
|
|
||||||
// Conditionally install manifests
|
// Conditionally install manifests
|
||||||
if mustInstallManifests(ctx, b.kube, options.Namespace) {
|
if mustInstallManifests(ctx, b.kube, options.Namespace) {
|
||||||
componentsYAML := filepath.Join(b.git.Path(), manifests.Path)
|
b.logger.Actionf("installing components in %q namespace", options.Namespace)
|
||||||
|
|
||||||
// Apply components using any existing customisations
|
componentsYAML := filepath.Join(b.git.Path(), manifests.Path)
|
||||||
kfile := filepath.Join(filepath.Dir(componentsYAML), konfig.DefaultKustomizationFileName())
|
kfile := filepath.Join(filepath.Dir(componentsYAML), konfig.DefaultKustomizationFileName())
|
||||||
if _, err := os.Stat(kfile); err == nil {
|
if _, err := os.Stat(kfile); err == nil {
|
||||||
// Apply the components and their patches
|
// Apply the components and their patches
|
||||||
b.logger.Actionf("installing components in %q namespace", options.Namespace)
|
if _, err := utils.Apply(ctx, b.restClientGetter, b.restClientOptions, b.git.Path(), kfile); err != nil {
|
||||||
if _, err := utils.Apply(ctx, b.restClientGetter, b.restClientOptions, kfile); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Apply the CRDs and controllers
|
// Apply the CRDs and controllers
|
||||||
if _, err := utils.Apply(ctx, b.restClientGetter, b.restClientOptions, componentsYAML); err != nil {
|
if _, err := utils.Apply(ctx, b.restClientGetter, b.restClientOptions, b.git.Path(), componentsYAML); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -263,13 +262,21 @@ func (b *PlainGitBootstrapper) ReconcileSyncConfig(ctx context.Context, options
|
|||||||
if err = b.git.Write(manifests.Path, strings.NewReader(manifests.Content)); err != nil {
|
if err = b.git.Write(manifests.Path, strings.NewReader(manifests.Content)); err != nil {
|
||||||
return fmt.Errorf("failed to write manifest %q: %w", manifests.Path, err)
|
return fmt.Errorf("failed to write manifest %q: %w", manifests.Path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create secure Kustomize FS
|
||||||
|
fs, err := filesys.MakeFsOnDiskSecureBuild(b.git.Path())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to initialize Kustomize file system: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate Kustomization
|
||||||
kusManifests, err := kustomization.Generate(kustomization.Options{
|
kusManifests, err := kustomization.Generate(kustomization.Options{
|
||||||
FileSystem: filesys.MakeFsOnDisk(),
|
FileSystem: fs,
|
||||||
BaseDir: b.git.Path(),
|
BaseDir: b.git.Path(),
|
||||||
TargetPath: filepath.Dir(manifests.Path),
|
TargetPath: filepath.Dir(manifests.Path),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("kustomization.yaml generation failed: %w", err)
|
return fmt.Errorf("%s generation failed: %w", konfig.DefaultKustomizationFileName(), err)
|
||||||
}
|
}
|
||||||
if err = b.git.Write(kusManifests.Path, strings.NewReader(kusManifests.Content)); err != nil {
|
if err = b.git.Write(kusManifests.Path, strings.NewReader(kusManifests.Content)); err != nil {
|
||||||
return fmt.Errorf("failed to write manifest %q: %w", kusManifests.Path, err)
|
return fmt.Errorf("failed to write manifest %q: %w", kusManifests.Path, err)
|
||||||
@@ -320,7 +327,7 @@ func (b *PlainGitBootstrapper) ReconcileSyncConfig(ctx context.Context, options
|
|||||||
|
|
||||||
// Apply to cluster
|
// Apply to cluster
|
||||||
b.logger.Actionf("applying sync manifests")
|
b.logger.Actionf("applying sync manifests")
|
||||||
if _, err := utils.Apply(ctx, b.restClientGetter, b.restClientOptions, filepath.Join(b.git.Path(), kusManifests.Path)); err != nil {
|
if _, err := utils.Apply(ctx, b.restClientGetter, b.restClientOptions, b.git.Path(), filepath.Join(b.git.Path(), kusManifests.Path)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -37,11 +38,11 @@ import (
|
|||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
|
||||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
|
|
||||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||||
"github.com/fluxcd/pkg/kustomize"
|
"github.com/fluxcd/pkg/kustomize"
|
||||||
|
"github.com/fluxcd/pkg/kustomize/filesys"
|
||||||
runclient "github.com/fluxcd/pkg/runtime/client"
|
runclient "github.com/fluxcd/pkg/runtime/client"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
@@ -250,12 +251,19 @@ func (b *Builder) unMarshallKustomization() (*kustomizev1.Kustomization, error)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read kustomization file %s: %w", b.kustomizationFile, err)
|
return nil, fmt.Errorf("failed to read kustomization file %s: %w", b.kustomizationFile, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
k := &kustomizev1.Kustomization{}
|
k := &kustomizev1.Kustomization{}
|
||||||
decoder := k8syaml.NewYAMLOrJSONDecoder(bytes.NewBuffer(data), len(data))
|
decoder := k8syaml.NewYAMLOrJSONDecoder(bytes.NewBuffer(data), len(data))
|
||||||
err = decoder.Decode(k)
|
// check for kustomization in yaml with the same name and namespace
|
||||||
if err != nil {
|
for !(k.Name == b.name && (k.Namespace == b.namespace || k.Namespace == "")) {
|
||||||
return nil, fmt.Errorf("failed to unmarshall kustomization file %s: %w", b.kustomizationFile, err)
|
err = decoder.Decode(k)
|
||||||
|
if err != nil {
|
||||||
|
if err == io.EOF {
|
||||||
|
return nil, fmt.Errorf("failed find kustomization with name '%s' and namespace '%s' in file '%s'",
|
||||||
|
b.name, b.namespace, b.kustomizationFile)
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("failed to unmarshall kustomization file %s: %w", b.kustomizationFile, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return k, nil
|
return k, nil
|
||||||
}
|
}
|
||||||
@@ -275,7 +283,11 @@ func (b *Builder) generate(kustomization kustomizev1.Kustomization, dirPath stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) do(ctx context.Context, kustomization kustomizev1.Kustomization, dirPath string) (resmap.ResMap, error) {
|
func (b *Builder) do(ctx context.Context, kustomization kustomizev1.Kustomization, dirPath string) (resmap.ResMap, error) {
|
||||||
fs := filesys.MakeFsOnDisk()
|
// TODO(hidde): provide option to enforce FS boundaries of local build
|
||||||
|
fs, err := filesys.MakeFsOnDiskSecureBuild("/")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("kustomization build failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
// acuire the lock
|
// acuire the lock
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
@@ -157,3 +158,60 @@ type: kubernetes.io/dockerconfigjson
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_unMarshallKustomization(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
localKsFile string
|
||||||
|
wantErr bool
|
||||||
|
errString string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "valid kustomization",
|
||||||
|
localKsFile: "testdata/local-kustomization/valid.yaml",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Multi-doc yaml containing kustomization and other resources",
|
||||||
|
localKsFile: "testdata/local-kustomization/multi-doc-valid.yaml",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "no namespace",
|
||||||
|
localKsFile: "testdata/local-kustomization/no-ns.yaml",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "kustomization with a different name",
|
||||||
|
localKsFile: "testdata/local-kustomization/different-name.yaml",
|
||||||
|
wantErr: true,
|
||||||
|
errString: "failed find kustomization with name",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
b := &Builder{
|
||||||
|
name: "podinfo",
|
||||||
|
namespace: "flux-system",
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
b.kustomizationFile = tt.localKsFile
|
||||||
|
ks, err := b.unMarshallKustomization()
|
||||||
|
if !tt.wantErr {
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected err '%s'", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ks.Name != b.name && ks.Namespace != b.namespace {
|
||||||
|
t.Errorf("expected kustomization '%s/%s' to match '%s/%s'",
|
||||||
|
ks.Name, ks.Namespace, b.name, b.namespace)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected error but got nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(err.Error(), tt.errString) {
|
||||||
|
t.Errorf("expected error '%s' to contain string '%s'", err.Error(), tt.errString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
7
internal/build/testdata/local-kustomization/different-name.yaml
vendored
Normal file
7
internal/build/testdata/local-kustomization/different-name.yaml
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: Kustomization
|
||||||
|
metadata:
|
||||||
|
name: infra
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
path: "./clusters/test-build"
|
||||||
32
internal/build/testdata/local-kustomization/multi-doc-valid.yaml
vendored
Normal file
32
internal/build/testdata/local-kustomization/multi-doc-valid.yaml
vendored
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
---
|
||||||
|
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: Kustomization
|
||||||
|
metadata:
|
||||||
|
name: infra-namespace
|
||||||
|
namespace: flux-system
|
||||||
|
labels:
|
||||||
|
component.kutara.io/part-of: definitions
|
||||||
|
spec:
|
||||||
|
path: "./k8s/base/infra"
|
||||||
|
prune: true
|
||||||
|
---
|
||||||
|
---
|
||||||
|
apiVersion: source.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: GitRepository
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
interval: 30s
|
||||||
|
ref:
|
||||||
|
branch: master
|
||||||
|
url: https://github.com/stefanprodan/podinfo
|
||||||
|
---
|
||||||
|
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: Kustomization
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
path: "./clusters/test-build"
|
||||||
|
---
|
||||||
6
internal/build/testdata/local-kustomization/no-ns.yaml
vendored
Normal file
6
internal/build/testdata/local-kustomization/no-ns.yaml
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: Kustomization
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
spec:
|
||||||
|
path: "./clusters/test-build"
|
||||||
7
internal/build/testdata/local-kustomization/valid.yaml
vendored
Normal file
7
internal/build/testdata/local-kustomization/valid.yaml
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: Kustomization
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
path: "./clusters/test-build"
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package flags
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
|
||||||
)
|
|
||||||
|
|
||||||
var supportedHelmReleaseValuesFromKinds = []string{"Secret", "ConfigMap"}
|
|
||||||
|
|
||||||
type HelmReleaseValuesFrom struct {
|
|
||||||
Kind string
|
|
||||||
Name string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *HelmReleaseValuesFrom) String() string {
|
|
||||||
if v.Name == "" {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%s/%s", v.Kind, v.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *HelmReleaseValuesFrom) Set(str string) error {
|
|
||||||
if strings.TrimSpace(str) == "" {
|
|
||||||
return fmt.Errorf("no values given, please specify %s",
|
|
||||||
v.Description())
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceKind, sourceName := utils.ParseObjectKindName(str)
|
|
||||||
if sourceKind == "" {
|
|
||||||
return fmt.Errorf("invalid Kubernetes object reference '%s', must be in format <kind>/<name>", str)
|
|
||||||
}
|
|
||||||
cleanSourceKind, ok := utils.ContainsEqualFoldItemString(supportedHelmReleaseValuesFromKinds, sourceKind)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("reference kind '%s' is not supported, must be one of: %s",
|
|
||||||
sourceKind, strings.Join(supportedHelmReleaseValuesFromKinds, ", "))
|
|
||||||
}
|
|
||||||
|
|
||||||
v.Name = sourceName
|
|
||||||
v.Kind = cleanSourceKind
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *HelmReleaseValuesFrom) Type() string {
|
|
||||||
return "helmReleaseValuesFrom"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *HelmReleaseValuesFrom) Description() string {
|
|
||||||
return fmt.Sprintf(
|
|
||||||
"Kubernetes object reference that contains the values.yaml data key in the format '<kind>/<name>', "+
|
|
||||||
"where kind must be one of: (%s)",
|
|
||||||
strings.Join(supportedHelmReleaseValuesFromKinds, ", "),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
//go:build !e2e
|
|
||||||
// +build !e2e
|
|
||||||
|
|
||||||
/*
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package flags
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestHelmReleaseValuesFrom_Set(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
str string
|
|
||||||
expect string
|
|
||||||
expectErr bool
|
|
||||||
}{
|
|
||||||
{"supported", "Secret/foo", "Secret/foo", false},
|
|
||||||
{"lower case kind", "secret/foo", "Secret/foo", false},
|
|
||||||
{"unsupported", "Unsupported/kind", "", true},
|
|
||||||
{"invalid format", "Secret", "", true},
|
|
||||||
{"empty", "", "", true},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
var h HelmReleaseValuesFrom
|
|
||||||
if err := h.Set(tt.str); (err != nil) != tt.expectErr {
|
|
||||||
t.Errorf("Set() error = %v, expectErr %v", err, tt.expectErr)
|
|
||||||
}
|
|
||||||
if str := h.String(); str != tt.expect {
|
|
||||||
t.Errorf("Set() = %v, expect %v", str, tt.expect)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var supportedKustomizationSourceKinds = []string{sourcev1.GitRepositoryKind, sourcev1.BucketKind}
|
var supportedKustomizationSourceKinds = []string{sourcev1.OCIRepositoryKind, sourcev1.GitRepositoryKind, sourcev1.BucketKind}
|
||||||
|
|
||||||
type KustomizationSource struct {
|
type KustomizationSource struct {
|
||||||
Kind string
|
Kind string
|
||||||
|
|||||||
@@ -24,7 +24,12 @@ import (
|
|||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var supportedSourceBucketProviders = []string{sourcev1.GenericBucketProvider, sourcev1.AmazonBucketProvider}
|
var supportedSourceBucketProviders = []string{
|
||||||
|
sourcev1.GenericBucketProvider,
|
||||||
|
sourcev1.AmazonBucketProvider,
|
||||||
|
sourcev1.AzureBucketProvider,
|
||||||
|
sourcev1.GoogleBucketProvider,
|
||||||
|
}
|
||||||
|
|
||||||
type SourceBucketProvider string
|
type SourceBucketProvider string
|
||||||
|
|
||||||
|
|||||||
62
internal/flags/source_oci_provider.go
Normal file
62
internal/flags/source_oci_provider.go
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Flux authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package flags
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var supportedSourceOCIProviders = []string{
|
||||||
|
sourcev1.GenericOCIProvider,
|
||||||
|
sourcev1.AmazonOCIProvider,
|
||||||
|
sourcev1.AzureOCIProvider,
|
||||||
|
sourcev1.GoogleOCIProvider,
|
||||||
|
}
|
||||||
|
|
||||||
|
type SourceOCIProvider string
|
||||||
|
|
||||||
|
func (p *SourceOCIProvider) String() string {
|
||||||
|
return string(*p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *SourceOCIProvider) Set(str string) error {
|
||||||
|
if strings.TrimSpace(str) == "" {
|
||||||
|
return fmt.Errorf("no source OCI provider given, please specify %s",
|
||||||
|
p.Description())
|
||||||
|
}
|
||||||
|
if !utils.ContainsItemString(supportedSourceOCIProviders, str) {
|
||||||
|
return fmt.Errorf("source OCI provider '%s' is not supported, must be one of: %v",
|
||||||
|
str, strings.Join(supportedSourceOCIProviders, ", "))
|
||||||
|
}
|
||||||
|
*p = SourceOCIProvider(str)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *SourceOCIProvider) Type() string {
|
||||||
|
return "sourceOCIProvider"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *SourceOCIProvider) Description() string {
|
||||||
|
return fmt.Sprintf(
|
||||||
|
"the OCI provider name, available options are: (%s)",
|
||||||
|
strings.Join(supportedSourceOCIProviders, ", "),
|
||||||
|
)
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user