1
0
mirror of synced 2026-03-01 11:16:56 +00:00

Compare commits

..

83 Commits

Author SHA1 Message Date
Hidde Beydals
cc9bcbaefd Merge pull request #2668 from fluxcd/update-components 2022-04-22 12:26:17 +02:00
Hidde Beydals
787d491bd5 tests/azure: update toolkit components
Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-22 12:09:27 +02:00
fluxcdbot
5c4991299c Update toolkit components
- kustomize-controller to v0.24.3
  https://github.com/fluxcd/kustomize-controller/blob/v0.24.3/CHANGELOG.md
- source-controller to v0.24.1
  https://github.com/fluxcd/source-controller/blob/v0.24.1/CHANGELOG.md

Signed-off-by: GitHub <noreply@github.com>
2022-04-22 10:09:00 +00:00
Hidde Beydals
33ac3ef2c6 Merge pull request #2662 from fluxcd/update-components 2022-04-21 11:52:23 +02:00
Hidde Beydals
c7504442bd tests/azure: update toolkit components
Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-21 11:31:07 +02:00
fluxcdbot
1a546a1d82 Update toolkit components
- kustomize-controller to v0.24.2
  https://github.com/fluxcd/kustomize-controller/blob/v0.24.2/CHANGELOG.md
- notification-controller to v0.23.4
  https://github.com/fluxcd/notification-controller/blob/v0.23.4/CHANGELOG.md

Signed-off-by: GitHub <noreply@github.com>
2022-04-21 09:29:20 +00:00
Hidde Beydals
713365a12c Merge pull request #2657 from fluxcd/update-kc 2022-04-20 18:08:22 +02:00
Hidde Beydals
5d8248d31d Update kustomize-controller to v0.24.1
Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-20 17:34:12 +02:00
Hidde Beydals
5346c1cca3 Merge pull request #2652 from fluxcd/update-components 2022-04-20 12:28:48 +02:00
Hidde Beydals
baadaa05d2 tests/azure: Update toolkit components
Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-20 11:49:49 +02:00
fluxcdbot
224a1ce941 Update toolkit components
- helm-controller to v0.20.1
  https://github.com/fluxcd/helm-controller/blob/v0.20.1/CHANGELOG.md

Signed-off-by: GitHub <noreply@github.com>
2022-04-20 09:46:28 +00:00
Hidde Beydals
52f1bfed4c Merge pull request #2646 from aryan9600/fix-mask-sops 2022-04-19 20:05:14 +02:00
Sanskar Jaiswal
5c9cbe676d handle secret types properly while masking sops data
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2022-04-19 23:12:00 +05:30
Hidde Beydals
e25bb74c05 Merge pull request #2649 from fluxcd/update-deps 2022-04-19 19:21:45 +02:00
Hidde Beydals
c2f465e246 Update dependencies
- github.com/ProtonMail/go-crypto to v0.0.0-20220407094043-a94812496cf5
- github.com/fluxcd/pkg/kustomize to v0.2.0
- github.com/fluxcd/pkg/runtime to v0.14.1
- github.com/fluxcd/pkg/ssa to v0.15.2
- golang.org/x/crypto to v0.0.0-20220411220226-7b82a4e95df4
- golang.org/x/term to v0.0.0-20220411215600-e5f449aeb171
- k8s.io/cli-runtime to v0.23.5
- k8s.io/kubectl to v0.23.5
- sigs.k8s.io/cli-utils to v0.29.4
- sigs.k8s.io/kustomize/api to v0.11.4
- sigs.k8s.io/kustomize/kyaml to v0.13.6

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-19 18:27:33 +02:00
Hidde Beydals
6bbbf16140 tests/azure: update dependencies
This does not include an update of `github.com/hashicorp/terraform-exec`
to `v0.16.1`, as it contains a breaking change. `tfinstall` has been
removed and needs to be replaced with `github.com/hashicorp/hc-install`.

- github.com/fluxcd/helm-controller/api to v0.20.0
- github.com/fluxcd/image-automation-controller/api to v0.22.0
- github.com/fluxcd/image-reflector-controller/api to v0.17.2
- github.com/fluxcd/kustomize-controller/api to v0.24.0
- github.com/fluxcd/notification-controller/api to v0.23.3
- github.com/fluxcd/pkg/apis/meta to v0.12.2
- github.com/fluxcd/pkg/runtime to v0.14.1
- github.com/fluxcd/source-controller/api to v0.24.0
- k8s.io/api to v0.23.5
- k8s.io/apimachinery to v0.23.5
- k8s.io/client-go to v0.23.5
- sigs.k8s.io/controller-runtime to v0.11.2

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-19 18:23:42 +02:00
Hidde Beydals
c5cdb70031 Merge pull request #2617 from fluxcd/update-components 2022-04-19 18:20:30 +02:00
fluxcdbot
2955cd70a8 Update toolkit components
- helm-controller to v0.20.0
  https://github.com/fluxcd/helm-controller/blob/v0.20.0/CHANGELOG.md
- kustomize-controller to v0.24.0
  https://github.com/fluxcd/kustomize-controller/blob/v0.24.0/CHANGELOG.md
- source-controller to v0.24.0
  https://github.com/fluxcd/source-controller/blob/v0.24.0/CHANGELOG.md
- notification-controller to v0.23.3
  https://github.com/fluxcd/notification-controller/blob/v0.23.3/CHANGELOG.md
- image-reflector-controller to v0.17.2
  https://github.com/fluxcd/image-reflector-controller/blob/v0.17.2/CHANGELOG.md
- image-automation-controller to v0.22.0
  https://github.com/fluxcd/image-automation-controller/blob/v0.22.0/CHANGELOG.md

Signed-off-by: GitHub <noreply@github.com>
2022-04-19 15:45:35 +00:00
Stefan Prodan
7b4940914c Merge pull request #2597 from fluxcd/rfc-helm-oci
[RFC-0002] Flux OCI support for Helm
2022-04-13 11:01:25 +03:00
Stefan Prodan
30f977a7cb Assign RFC-0002 to Helm OCI proposal
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2022-04-13 10:27:11 +03:00
Stefan Prodan
e06fa24616 Add dedicated reconcilers to the design docs
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2022-04-12 15:09:51 +03:00
Stefan Prodan
20d7d0c78a Add image registry example to story 2
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2022-04-12 15:08:31 +03:00
Stefan Prodan
606078c1b3 Add chart update automation to Git
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2022-04-12 15:08:31 +03:00
Stefan Prodan
0135eb19d4 Add proposal for adding Helm OCI support to Flux Source API
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2022-04-12 15:08:30 +03:00
Stefan Prodan
8b989190c4 Merge pull request #2631 from canidam/add-bootstrap-git-pass-from-stdin-and-env
bootstrap git: Allow the password to be specified with GIT_PASSWORD env var
2022-04-12 14:59:17 +03:00
Chen Anidam
a85ea59824 Read password of generic git bootstrap command from env or stdin
Signed-off-by: Chen Anidam <canidam@gmail.com>
2022-04-12 12:17:11 +03:00
Stefan Prodan
d012f0f2bc Merge pull request #2624 from kingdonb/docs-when-prune-enabled
Add detail to delete docs
2022-04-07 19:47:22 +03:00
Kingdon Barrett
7e2b63ea5d add detail to delete docs
Signed-off-by: Kingdon Barrett <kingdon@weave.works>
2022-04-07 08:29:57 -04:00
Stefan Prodan
cb53243fc1 Merge pull request #2611 from souleb/diff-local-kustomization
Add an option to diff with a local Flux Kustomization file
2022-04-05 19:40:11 +03:00
Soule BA
5536af9756 Add an option to diff with a local kustomization file
If implemented, users will be able to provide a local kustomization file
to `flux build/diff`.

Signed-off-by: Soule BA <soule@weave.works>
2022-04-05 17:21:11 +02:00
Stefan Prodan
28087c1d76 Merge pull request #2616 from SomtochiAma/resume-all-wait
Add cli flags for chart interval and reconcile strategy
2022-04-05 17:19:07 +03:00
Somtochi Onyekwere
b80f32ce7d Add cli flags for chart interval and reconcile strategy
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
2022-04-05 12:56:50 +01:00
Stefan Prodan
8bad59ebde Merge pull request #2609 from darkowlzz/grafana-dashboard-labelvalues
monitoring-config: set grafana dashboards labelValues
2022-04-03 09:46:23 +03:00
Sunny
b44e4617e0 monitoring-config: grafana dashboards labelValue
Since kube-prometheus-stack helm chart v32.2.0, the `labelValue` has to
be set to "1" for the default grafana dashboard label selector to select
the flux dashboard configuration.

Also, update kube-prometheus-stack to v34.7.0, latest.

Refer: eba5b198f5

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-04-02 23:55:11 +05:30
Stefan Prodan
5d99e3d191 Merge pull request #2607 from souleb/issue-2598
[Diff] Update pkg/kustomize to v0.1.0
2022-04-01 17:45:01 +03:00
Soule BA
1807852b6b Update pkg/kustomize to v0.1.0
If implemented this fixes a bug where retrieving the groupVersion.Group
of a kustomization were returning an empty string.

Signed-off-by: Soule BA <soule@weave.works>
2022-04-01 10:27:37 +02:00
Hidde Beydals
4f4a5c0ba0 Merge pull request #2594 from fluxcd/update-components 2022-03-30 20:41:16 +02:00
fluxcdbot
24188e58ff Update toolkit components
- kustomize-controller to v0.22.3
  https://github.com/fluxcd/kustomize-controller/blob/v0.22.3/CHANGELOG.md
- source-controller to v0.22.5
  https://github.com/fluxcd/source-controller/blob/v0.22.5/CHANGELOG.md
- notification-controller to v0.23.2
  https://github.com/fluxcd/notification-controller/blob/v0.23.2/CHANGELOG.md
- image-automation-controller to v0.21.3
  https://github.com/fluxcd/image-automation-controller/blob/v0.21.3/CHANGELOG.md

Signed-off-by: GitHub <noreply@github.com>
2022-03-30 17:39:09 +00:00
Stefan Prodan
e2be598988 Merge pull request #2584 from souleb/update-homeport-dyff
Diff: Update homeport/Dyff to v1.5.2
2022-03-29 10:16:39 +03:00
Soule BA
9e2a4f329b Update homeport/Dyff to v1.5.2
If implmented, this will provide an inline diff for configmaps with the
command `flux diff``.

Signed-off-by: Soule BA <soule@weave.works>
2022-03-29 08:52:53 +02:00
Stefan Prodan
574b86cbca Merge pull request #2534 from jooooel/joel/update_docs
Add coreutils (for Mac OS) as a dependency
2022-03-29 08:26:45 +03:00
jooooel
4b7042cc46 Add coreutils (for Mac OS) as a dependency
Signed-off-by: jooooel <jooooel@users.noreply.github.com>
2022-03-28 20:34:07 +02:00
Sunny
5ae4711f7b Merge pull request #2583 from fluxcd/update-components
Update toolkit components
2022-03-28 22:41:58 +05:30
fluxcdbot
97a53b1536 Update toolkit components
- source-controller to v0.22.4
  https://github.com/fluxcd/source-controller/blob/v0.22.4/CHANGELOG.md
- image-automation-controller to v0.21.2
  https://github.com/fluxcd/image-automation-controller/blob/v0.21.2/CHANGELOG.md

Signed-off-by: GitHub <noreply@github.com>
2022-03-28 16:52:13 +00:00
Hidde Beydals
cc982cf3b1 Merge pull request #2577 from fluxcd/update-components 2022-03-25 19:10:52 +01:00
fluxcdbot
3f652f8b05 Update toolkit components
- helm-controller to v0.18.2
  https://github.com/fluxcd/helm-controller/blob/v0.18.2/CHANGELOG.md
- kustomize-controller to v0.22.2
  https://github.com/fluxcd/kustomize-controller/blob/v0.22.2/CHANGELOG.md
- source-controller to v0.22.3
  https://github.com/fluxcd/source-controller/blob/v0.22.3/CHANGELOG.md

Signed-off-by: GitHub <noreply@github.com>
2022-03-25 17:50:26 +00:00
Hidde Beydals
dcd86dec6e Merge pull request #2572 from fluxcd/client-rate-limit-args 2022-03-25 11:08:07 +01:00
Stefan Prodan
0d8194c800 Add the kube client qps and burst to the global args
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2022-03-25 10:43:59 +01:00
Stefan Prodan
150d9d7ae6 Merge pull request #2570 from fluxcd/update-components
Update toolkit components
2022-03-24 09:45:29 +02:00
Stefan Prodan
694f1797d2 Update packages for Azure e2e testing
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2022-03-24 09:23:35 +02:00
fluxcdbot
116be0cfed Update toolkit components
- kustomize-controller to v0.22.1
  https://github.com/fluxcd/kustomize-controller/blob/v0.22.1/CHANGELOG.md

Signed-off-by: GitHub <noreply@github.com>
2022-03-24 07:01:20 +00:00
Hidde Beydals
aa2b5ae18d Merge pull request #2569 from fluxcd/update-components 2022-03-23 21:47:35 +01:00
Hidde Beydals
e2ccbe2088 tests/azure: update toolkit components
- helm-controller to v0.18.1
  https://github.com/fluxcd/helm-controller/blob/v0.18.1/CHANGELOG.md
- source-controller to v0.22.2
  https://github.com/fluxcd/source-controller/blob/v0.22.2/CHANGELOG.md
- notification-controller to v0.23.1
  https://github.com/fluxcd/notification-controller/blob/v0.23.1/CHANGELOG.md
- image-reflector-controller to v0.17.1
  https://github.com/fluxcd/image-reflector-controller/blob/v0.17.1/CHANGELOG.md
- image-automation-controller to v0.21.1
  https://github.com/fluxcd/image-automation-controller/blob/v0.21.1/CHANGELOG.md

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-03-23 21:33:34 +01:00
Hidde Beydals
775891fc88 build: ensure component update runs with make tidy
This to include the `-compat` flag.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-03-23 21:32:00 +01:00
fluxcdbot
c85954ddef Update toolkit components
- helm-controller to v0.18.1
  https://github.com/fluxcd/helm-controller/blob/v0.18.1/CHANGELOG.md
- source-controller to v0.22.2
  https://github.com/fluxcd/source-controller/blob/v0.22.2/CHANGELOG.md
- notification-controller to v0.23.1
  https://github.com/fluxcd/notification-controller/blob/v0.23.1/CHANGELOG.md
- image-reflector-controller to v0.17.1
  https://github.com/fluxcd/image-reflector-controller/blob/v0.17.1/CHANGELOG.md
- image-automation-controller to v0.21.1
  https://github.com/fluxcd/image-automation-controller/blob/v0.21.1/CHANGELOG.md

Signed-off-by: GitHub <noreply@github.com>
2022-03-23 21:30:38 +01:00
Hidde Beydals
dd6db2cbd9 Merge pull request #2566 from fluxcd/fix-resume-bucket 2022-03-23 14:50:41 +01:00
Stefan Prodan
5f74c7d294 Fix resume source bucket panic
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2022-03-23 15:33:57 +02:00
Hidde Beydals
ed87a632b0 Merge pull request #2565 from fluxcd/source-create-wait 2022-03-23 12:55:08 +01:00
Hidde Beydals
3edcd16b62 fix: wait for Source objects observed generation
This ensures the command will wait for the object to report a Ready
Condition with an ObservedGeneration matching the Generation of the
resource. Ensuring that when a "create" is actually a mutation, it waits
instead of prematurely assuming the Source to be Ready.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-03-23 12:38:42 +01:00
Hidde Beydals
b01d3aeecd Merge pull request #2561 from fluxcd/update-deps 2022-03-23 11:55:57 +01:00
Hidde Beydals
0717c8bdbb Update fluxcd/source-controller to v0.22.1
Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-03-23 11:33:35 +01:00
Hidde Beydals
f1e4561bdd tests/azure: update dependencies
- github.com/Azure/azure-event-hubs-go/v3 to v3.3.17
- github.com/fluxcd/helm-controller/api to v0.18.0
- github.com/fluxcd/image-automation-controller/api to v0.21.0
- github.com/fluxcd/image-reflector-controller/api to v0.17.0
- github.com/fluxcd/kustomize-controller/api to v0.22.0
- github.com/fluxcd/notification-controller/api to v0.23.0
- github.com/fluxcd/pkg/runtime to v0.13.2
- github.com/hashicorp/terraform-exec to v0.15.0
- github.com/libgit2/git2go/v31 to v31.7.9
- github.com/stretchr/testify to v1.7.1
- go.uber.org/multierr to v1.8.0
- k8s.io/api to v0.23.4
- k8s.io/client-go to v0.23.4

For `github.com/hashicorp/terraform-exec`, a newer version (v0.16.0)
is availabe. This version however contains a breaking change (as it
removes the `tfinstall` module), which I did not want to deal with at
the moment.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-03-23 11:33:35 +01:00
Hidde Beydals
efe9a30523 Update dependencies
- github.com/Masterminds/semver/v3 to v3.1.1
- github.com/ProtonMail/go-crypto to v0.0.0-20220113124808-70ae35bab23f
- github.com/cyphar/filepath-securejoin to v0.2.3
- github.com/fluxcd/pkg/kustomize to v0.0.3
- github.com/fluxcd/pkg/runtime to v0.13.2
- github.com/fluxcd/pkg/ssa to v0.15.1
- github.com/fluxcd/pkg/ssh to v0.3.2
- github.com/fluxcd/pkg/untar to v0.1.0
- github.com/fluxcd/pkg/version to v0.1.0
- github.com/gonvenience/bunt to v1.3.3
- github.com/gonvenience/ytbx to v1.4.4
- github.com/google/go-containerregistry to v0.8.0
- github.com/homeport/dyff to v1.5.1
- github.com/olekukonko/tablewriter to v0.0.5
- github.com/spf13/cobra to v1.4.0
- golang.org/x/crypto to v0.0.0-20220321153916-2c7772ba3064
- k8s.io/kubectl to v0.23.4
- k8s.io/cli-runtime to v0.23.4
- sigs.k8s.io/cli-utils to v0.29.3

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-03-23 11:33:35 +01:00
Paulo Gomes
e5ede275f8 Update Source API to v1beta2
The creation of oldConditions, statusableConditions and
reconcilableConditions is an adhoc solution to deal with the upstream
changes on `pkg/apis/meta`, which are yet to be replicated across other
Flux API components.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-03-23 11:33:35 +01:00
fluxcdbot
a929d24924 Update toolkit components
- helm-controller to v0.18.0
  https://github.com/fluxcd/helm-controller/blob/v0.18.0/CHANGELOG.md
- kustomize-controller to v0.22.0
  https://github.com/fluxcd/kustomize-controller/blob/v0.22.0/CHANGELOG.md
- source-controller to v0.22.0
  https://github.com/fluxcd/source-controller/blob/v0.22.0/CHANGELOG.md
- notification-controller to v0.23.0
  https://github.com/fluxcd/notification-controller/blob/v0.23.0/CHANGELOG.md
- image-reflector-controller to v0.17.0
  https://github.com/fluxcd/image-reflector-controller/blob/v0.17.0/CHANGELOG.md
- image-automation-controller to v0.21.0
  https://github.com/fluxcd/image-automation-controller/blob/v0.21.0/CHANGELOG.md

Signed-off-by: GitHub <noreply@github.com>
2022-03-23 11:33:35 +01:00
Stefan Prodan
368f2d3542 Merge pull request #2564 from fluxcd/dot-domain-nc
Use absolute domain name for the events address
2022-03-23 12:17:35 +02:00
Stefan Prodan
139bbbb87c Use absolute domain name for the events address
Add ending dot to the events address to be consistent with source controller address.
This will affect bootstrap and install by setting `--events-addr=http://notification-controller.flux-system.svc.cluster.local./`.

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2022-03-23 11:57:46 +02:00
Stefan Prodan
51f5d85861 Merge pull request #2559 from fluxcd/fix-non-fast-forward
Retry bootstrap operations on Git conflict errors
2022-03-22 17:12:31 +02:00
Stefan Prodan
7756faec1f Retry bootstrap operations on Git conflict errors
When running bootstrap in-parallel for many clusters that target the same repository, the 2nd commit with the sync files fails with ` non-fast-forward update`. We now detect the conflict, and we retry the operations by creating a fresh clone from upstream.

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2022-03-22 16:09:31 +02:00
Sunny
d9e3e3aa95 Merge pull request #2542 from fluxcd/update-components
Update toolkit components
2022-03-16 03:16:19 +05:30
fluxcdbot
ff65491bb6 Update toolkit components
- helm-controller to v0.17.2
  https://github.com/fluxcd/helm-controller/blob/v0.17.2/CHANGELOG.md
- notification-controller to v0.22.3
  https://github.com/fluxcd/notification-controller/blob/v0.22.3/CHANGELOG.md

Signed-off-by: GitHub <noreply@github.com>
2022-03-15 20:41:25 +00:00
Stefan Prodan
8f514d8991 Merge pull request #2530 from fluxcd/components-extra-example
Add components-extra example usage to CLI help
2022-03-11 11:34:22 +02:00
Stefan Prodan
2e1000c31a Add components-extra example usage to CLI help
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2022-03-11 09:19:56 +02:00
Stefan Prodan
c5171a1f2e Merge pull request #2512 from souleb/introduce-printer-interface
Introduce a printer interface for flux resources
2022-03-07 13:55:33 +02:00
Soule BA
7359e63960 Introduce a printer interface for flux resource
If implemented, there will a common interface to print flux resource.

We are adding new way to print resource information e.g. diff of
objects.

Signed-off-by: Soule BA <soule@weave.works>
2022-03-07 12:15:35 +01:00
Stefan Prodan
307309504b Merge pull request #2484 from cuishuang/main
all: fix some typos
2022-03-02 14:23:04 +02:00
cuishuang
1fda202cf9 all: fix some typos
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-03-02 19:36:08 +08:00
Sunny
7e634c154f Merge pull request #2483 from fluxcd/update-components
Update toolkit components
2022-03-01 21:18:05 +05:30
fluxcdbot
3c72e35381 Update toolkit components
- image-automation-controller to v0.20.1
  https://github.com/fluxcd/image-automation-controller/blob/v0.20.1/CHANGELOG.md

Signed-off-by: GitHub <noreply@github.com>
2022-03-01 15:07:34 +00:00
Stefan Prodan
7e23430882 Merge pull request #2467 from fluxcd/update-get-column-order
Update `get` subcommand column order
2022-02-28 15:34:38 +02:00
Sunny
2c4c3fd749 test: ignore golden template files with -update
Add a template values check in the `assertGoldenTemplateFile()` function
to only update golden files if they aren't templates. A note is printed
when an update to a template golden file is needed and `-update` flag
can't update it.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-02-28 08:56:08 +05:30
Sunny
edaf6ca522 Add test flag -update to update the golden files
Test flag `-update` can be used to update all the golden files whenever
the CLI output changes.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-02-24 08:58:19 +05:30
Sunny
21f0d5d82c Move MESSAGE to the end of get subcommand output
Message content could be long compared to other fields. Moving it to
the end helps improve the visibility of the other fields.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-02-24 04:21:47 +05:30
136 changed files with 2072 additions and 775 deletions

View File

@@ -42,8 +42,7 @@ jobs:
if [[ "${MOD_VERSION}" != "${LATEST_VERSION}" ]]; then if [[ "${MOD_VERSION}" != "${LATEST_VERSION}" ]]; then
go mod edit -require="github.com/fluxcd/$1/api@${LATEST_VERSION}" go mod edit -require="github.com/fluxcd/$1/api@${LATEST_VERSION}"
rm go.sum make tidy
go mod tidy
changed=true changed=true
fi fi

View File

@@ -70,6 +70,7 @@ Prerequisites:
* go >= 1.17 * go >= 1.17
* kubectl >= 1.20 * kubectl >= 1.20
* kustomize >= 4.4 * kustomize >= 4.4
* coreutils (on Mac OS)
Install the [controller-runtime/envtest](https://github.com/kubernetes-sigs/controller-runtime/tree/master/tools/setup-envtest) binaries with: Install the [controller-runtime/envtest](https://github.com/kubernetes-sigs/controller-runtime/tree/master/tools/setup-envtest) binaries with:
@@ -96,6 +97,25 @@ Then you can run the end-to-end tests with:
make e2e make e2e
``` ```
When the output of the Flux CLI changes, to automatically update the golden
files used in the test, pass `-update` flag to the test as:
```bash
make e2e TEST_ARGS="-update"
```
Since not all packages use golden files for testing, `-update` argument must be
passed only for the packages that use golden files. Use the variables
`TEST_PKG_PATH` for unit tests and `E2E_TEST_PKG_PATH` for e2e tests, to set the
path of the target test package:
```bash
# Unit test
make test TEST_PKG_PATH="./cmd/flux" TEST_ARGS="-update"
# e2e test
make e2e E2E_TEST_PKG_PATH="./cmd/flux" TEST_ARGS="-update"
```
Teardown the e2e environment with: Teardown the e2e environment with:
```bash ```bash

View File

@@ -16,8 +16,8 @@ rwildcard=$(foreach d,$(wildcard $(addsuffix *,$(1))),$(call rwildcard,$(d)/,$(2
all: test build all: test build
tidy: tidy:
go mod tidy go mod tidy -compat=1.17
cd tests/azure && go mod tidy cd tests/azure && go mod tidy -compat=1.17
fmt: fmt:
go fmt ./... go fmt ./...
@@ -35,11 +35,13 @@ cleanup-kind:
rm $(TEST_KUBECONFIG) rm $(TEST_KUBECONFIG)
KUBEBUILDER_ASSETS?="$(shell $(ENVTEST) --arch=$(ENVTEST_ARCH) use -i $(ENVTEST_KUBERNETES_VERSION) --bin-dir=$(ENVTEST_ASSETS_DIR) -p path)" KUBEBUILDER_ASSETS?="$(shell $(ENVTEST) --arch=$(ENVTEST_ARCH) use -i $(ENVTEST_KUBERNETES_VERSION) --bin-dir=$(ENVTEST_ASSETS_DIR) -p path)"
TEST_PKG_PATH="./..."
test: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet install-envtest test: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet install-envtest
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... -coverprofile cover.out --tags=unit KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test $(TEST_PKG_PATH) -coverprofile cover.out --tags=unit $(TEST_ARGS)
E2E_TEST_PKG_PATH="./cmd/flux/..."
e2e: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet e2e: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet
TEST_KUBECONFIG=$(TEST_KUBECONFIG) go test ./cmd/flux/... -coverprofile e2e.cover.out --tags=e2e -v -failfast TEST_KUBECONFIG=$(TEST_KUBECONFIG) go test $(E2E_TEST_PKG_PATH) -coverprofile e2e.cover.out --tags=e2e -v -failfast $(TEST_ARGS)
test-with-kind: install-envtest test-with-kind: install-envtest
make setup-kind make setup-kind

Binary file not shown.

View File

@@ -88,7 +88,7 @@ func init() {
bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapArgs.defaultComponents, "components", rootArgs.defaults.Components, bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapArgs.defaultComponents, "components", rootArgs.defaults.Components,
"list of components, accepts comma-separated values") "list of components, accepts comma-separated values")
bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapArgs.extraComponents, "components-extra", nil, bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapArgs.extraComponents, "components-extra", nil,
"list of components in addition to those supplied or defaulted, accepts comma-separated values") "list of components in addition to those supplied or defaulted, accepts values such as 'image-reflector-controller,image-automation-controller'")
bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.registry, "registry", "ghcr.io/fluxcd", bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.registry, "registry", "ghcr.io/fluxcd",
"container registry where the toolkit images are published") "container registry where the toolkit images are published")

View File

@@ -121,7 +121,7 @@ func bootstrapBServerCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }
@@ -251,7 +251,7 @@ func bootstrapBServerCmdRun(cmd *cobra.Command, args []string) error {
bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix), bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix),
bootstrap.WithProviderTeamPermissions(mapTeamSlice(bServerArgs.teams, bServerDefaultPermission)), bootstrap.WithProviderTeamPermissions(mapTeamSlice(bServerArgs.teams, bServerDefaultPermission)),
bootstrap.WithReadWriteKeyPermissions(bServerArgs.readWriteKey), bootstrap.WithReadWriteKeyPermissions(bServerArgs.readWriteKey),
bootstrap.WithKubeconfig(kubeconfigArgs), bootstrap.WithKubeconfig(kubeconfigArgs, kubeclientOptions),
bootstrap.WithLogger(logger), bootstrap.WithLogger(logger),
bootstrap.WithCABundle(caBundle), bootstrap.WithCABundle(caBundle),
bootstrap.WithGitCommitSigning(bootstrapArgs.gpgKeyRingPath, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID), bootstrap.WithGitCommitSigning(bootstrapArgs.gpgKeyRingPath, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID),

View File

@@ -53,6 +53,9 @@ command will perform an upgrade if needed.`,
# Run bootstrap for a Git repository and authenticate using a password # Run bootstrap for a Git repository and authenticate using a password
flux bootstrap git --url=https://example.com/repository.git --password=<password> flux bootstrap git --url=https://example.com/repository.git --password=<password>
# Run bootstrap for a Git repository and authenticate using a password from environment variable
GIT_PASSWORD=<password> && flux bootstrap git --url=https://example.com/repository.git
# Run bootstrap for a Git repository with a passwordless private key # Run bootstrap for a Git repository with a passwordless private key
flux bootstrap git --url=ssh://git@example.com/repository.git --private-key-file=<path/to/private.key> flux bootstrap git --url=ssh://git@example.com/repository.git --private-key-file=<path/to/private.key>
@@ -71,6 +74,10 @@ type gitFlags struct {
silent bool silent bool
} }
const (
gitPasswordEnvVar = "GIT_PASSWORD"
)
var gitArgs gitFlags var gitArgs gitFlags
func init() { func init() {
@@ -85,6 +92,19 @@ func init() {
} }
func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error { func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
gitPassword := os.Getenv(gitPasswordEnvVar)
if gitPassword != "" && gitArgs.password == "" {
gitArgs.password = gitPassword
}
if bootstrapArgs.tokenAuth && gitArgs.password == "" {
var err error
gitPassword, err = readPasswordFromStdin("Please enter your Git repository password: ")
if err != nil {
return fmt.Errorf("could not read token: %w", err)
}
gitArgs.password = gitPassword
}
if err := bootstrapValidate(); err != nil { if err := bootstrapValidate(); err != nil {
return err return err
} }
@@ -101,7 +121,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }
@@ -225,7 +245,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
bootstrap.WithBranch(bootstrapArgs.branch), bootstrap.WithBranch(bootstrapArgs.branch),
bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail), bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail),
bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix), bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix),
bootstrap.WithKubeconfig(kubeconfigArgs), bootstrap.WithKubeconfig(kubeconfigArgs, kubeclientOptions),
bootstrap.WithPostGenerateSecretFunc(promptPublicKey), bootstrap.WithPostGenerateSecretFunc(promptPublicKey),
bootstrap.WithLogger(logger), bootstrap.WithLogger(logger),
bootstrap.WithCABundle(caBundle), bootstrap.WithCABundle(caBundle),

View File

@@ -125,7 +125,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }
@@ -240,7 +240,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix), bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix),
bootstrap.WithProviderTeamPermissions(mapTeamSlice(githubArgs.teams, ghDefaultPermission)), bootstrap.WithProviderTeamPermissions(mapTeamSlice(githubArgs.teams, ghDefaultPermission)),
bootstrap.WithReadWriteKeyPermissions(githubArgs.readWriteKey), bootstrap.WithReadWriteKeyPermissions(githubArgs.readWriteKey),
bootstrap.WithKubeconfig(kubeconfigArgs), bootstrap.WithKubeconfig(kubeconfigArgs, kubeclientOptions),
bootstrap.WithLogger(logger), bootstrap.WithLogger(logger),
bootstrap.WithCABundle(caBundle), bootstrap.WithCABundle(caBundle),
bootstrap.WithGitCommitSigning(bootstrapArgs.gpgKeyRingPath, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID), bootstrap.WithGitCommitSigning(bootstrapArgs.gpgKeyRingPath, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID),

View File

@@ -129,7 +129,7 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }
@@ -254,7 +254,7 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix), bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix),
bootstrap.WithProviderTeamPermissions(mapTeamSlice(gitlabArgs.teams, glDefaultPermission)), bootstrap.WithProviderTeamPermissions(mapTeamSlice(gitlabArgs.teams, glDefaultPermission)),
bootstrap.WithReadWriteKeyPermissions(gitlabArgs.readWriteKey), bootstrap.WithReadWriteKeyPermissions(gitlabArgs.readWriteKey),
bootstrap.WithKubeconfig(kubeconfigArgs), bootstrap.WithKubeconfig(kubeconfigArgs, kubeclientOptions),
bootstrap.WithLogger(logger), bootstrap.WithLogger(logger),
bootstrap.WithCABundle(caBundle), bootstrap.WithCABundle(caBundle),
bootstrap.WithGitCommitSigning(bootstrapArgs.gpgKeyRingPath, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID), bootstrap.WithGitCommitSigning(bootstrapArgs.gpgKeyRingPath, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID),

View File

@@ -33,21 +33,28 @@ var buildKsCmd = &cobra.Command{
Short: "Build Kustomization", Short: "Build Kustomization",
Long: `The build command queries the Kubernetes API and fetches the specified Flux Kustomization. Long: `The build command queries the Kubernetes API and fetches the specified Flux Kustomization.
It then uses the fetched in cluster flux kustomization to perform needed transformation on the local kustomization.yaml It then uses the fetched in cluster flux kustomization to perform needed transformation on the local kustomization.yaml
pointed at by --path. The local kustomization.yaml is generated if it does not exist. Finally it builds the overlays using the local kustomization.yaml, and write the resulting multi-doc YAML to stdout.`, pointed at by --path. The local kustomization.yaml is generated if it does not exist. Finally it builds the overlays using the local kustomization.yaml, and write the resulting multi-doc YAML to stdout.
It is possible to specify a Flux kustomization file using --kustomization-file.`,
Example: `# Build the local manifests as they were built on the cluster Example: `# Build the local manifests as they were built on the cluster
flux build kustomization my-app --path ./path/to/local/manifests`, flux build kustomization my-app --path ./path/to/local/manifests
# Build using a local flux kustomization file
flux build kustomization my-app --path ./path/to/local/manifests --kustomization-file ./path/to/local/my-app.yaml`,
ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)), ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)),
RunE: buildKsCmdRun, RunE: buildKsCmdRun,
} }
type buildKsFlags struct { type buildKsFlags struct {
path string kustomizationFile string
path string
} }
var buildKsArgs buildKsFlags var buildKsArgs buildKsFlags
func init() { func init() {
buildKsCmd.Flags().StringVar(&buildKsArgs.path, "path", "", "Path to the manifests location.)") buildKsCmd.Flags().StringVar(&buildKsArgs.path, "path", "", "Path to the manifests location.")
buildKsCmd.Flags().StringVar(&buildKsArgs.kustomizationFile, "kustomization-file", "", "Path to the Flux Kustomization YAML file.")
buildCmd.AddCommand(buildKsCmd) buildCmd.AddCommand(buildKsCmd)
} }
@@ -65,7 +72,13 @@ func buildKsCmdRun(cmd *cobra.Command, args []string) error {
return fmt.Errorf("invalid resource path %q", buildKsArgs.path) return fmt.Errorf("invalid resource path %q", buildKsArgs.path)
} }
builder, err := build.NewBuilder(kubeconfigArgs, name, buildKsArgs.path, build.WithTimeout(rootArgs.timeout)) if buildKsArgs.kustomizationFile != "" {
if fs, err := os.Stat(buildKsArgs.kustomizationFile); os.IsNotExist(err) || fs.IsDir() {
return fmt.Errorf("invalid kustomization file %q", buildKsArgs.kustomizationFile)
}
}
builder, err := build.NewBuilder(kubeconfigArgs, kubeclientOptions, name, buildKsArgs.path, build.WithTimeout(rootArgs.timeout), build.WithKustomizationFile(buildKsArgs.kustomizationFile))
if err != nil { if err != nil {
return err return err
} }

View File

@@ -20,7 +20,10 @@ limitations under the License.
package main package main
import ( import (
"bytes"
"os"
"testing" "testing"
"text/template"
) )
func setup(t *testing.T, tmpl map[string]string) { func setup(t *testing.T, tmpl map[string]string) {
@@ -54,6 +57,12 @@ func TestBuildKustomization(t *testing.T) {
resultFile: "./testdata/build-kustomization/podinfo-without-service-result.yaml", resultFile: "./testdata/build-kustomization/podinfo-without-service-result.yaml",
assertFunc: "assertGoldenTemplateFile", assertFunc: "assertGoldenTemplateFile",
}, },
{
name: "build deployment and configmap with var substitution",
args: "build kustomization podinfo --path ./testdata/build-kustomization/var-substitution",
resultFile: "./testdata/build-kustomization/podinfo-with-var-substitution-result.yaml",
assertFunc: "assertGoldenTemplateFile",
},
} }
tmpl := map[string]string{ tmpl := map[string]string{
@@ -81,3 +90,101 @@ func TestBuildKustomization(t *testing.T) {
}) })
} }
} }
func TestBuildLocalKustomization(t *testing.T) {
podinfo := `apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
name: podinfo
namespace: {{ .fluxns }}
spec:
interval: 5m0s
path: ./kustomize
force: true
prune: true
sourceRef:
kind: GitRepository
name: podinfo
targetNamespace: default
postBuild:
substitute:
cluster_env: "prod"
cluster_region: "eu-central-1"
`
tests := []struct {
name string
args string
resultFile string
assertFunc string
}{
{
name: "no args",
args: "build kustomization podinfo --kustomization-file ./wrongfile/ --path ./testdata/build-kustomization/podinfo",
resultFile: "invalid kustomization file \"./wrongfile/\"",
assertFunc: "assertError",
},
{
name: "build podinfo",
args: "build kustomization podinfo --kustomization-file ./testdata/build-kustomization/podinfo.yaml --path ./testdata/build-kustomization/podinfo",
resultFile: "./testdata/build-kustomization/podinfo-result.yaml",
assertFunc: "assertGoldenTemplateFile",
},
{
name: "build podinfo without service",
args: "build kustomization podinfo --kustomization-file ./testdata/build-kustomization/podinfo.yaml --path ./testdata/build-kustomization/delete-service",
resultFile: "./testdata/build-kustomization/podinfo-without-service-result.yaml",
assertFunc: "assertGoldenTemplateFile",
},
{
name: "build deployment and configmap with var substitution",
args: "build kustomization podinfo --kustomization-file ./testdata/build-kustomization/podinfo.yaml --path ./testdata/build-kustomization/var-substitution",
resultFile: "./testdata/build-kustomization/podinfo-with-var-substitution-result.yaml",
assertFunc: "assertGoldenTemplateFile",
},
}
tmpl := map[string]string{
"fluxns": allocateNamespace("flux-system"),
}
testEnv.CreateObjectFile("./testdata/build-kustomization/podinfo-source.yaml", tmpl, t)
temp, err := template.New("podinfo").Parse(podinfo)
if err != nil {
t.Fatal(err)
}
var b bytes.Buffer
err = temp.Execute(&b, tmpl)
if err != nil {
t.Fatal(err)
}
err = os.WriteFile("./testdata/build-kustomization/podinfo.yaml", b.Bytes(), 0666)
if err != nil {
t.Fatal(err)
}
defer os.Remove("./testdata/build-kustomization/podinfo.yaml")
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var assert assertFunc
switch tt.assertFunc {
case "assertGoldenTemplateFile":
assert = assertGoldenTemplateFile(tt.resultFile, tmpl)
case "assertError":
assert = assertError(tt.resultFile)
}
cmd := cmdTestCase{
args: tt.args + " -n " + tmpl["fluxns"],
assert: assert,
}
cmd.runTestCmd(t)
})
}
}

View File

@@ -125,7 +125,7 @@ func fluxCheck() {
} }
func kubernetesCheck(constraints []string) bool { func kubernetesCheck(constraints []string) bool {
cfg, err := utils.KubeConfig(kubeconfigArgs) cfg, err := utils.KubeConfig(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
logger.Failuref("Kubernetes client initialization failed: %s", err.Error()) logger.Failuref("Kubernetes client initialization failed: %s", err.Error())
return false return false
@@ -173,7 +173,7 @@ func componentsCheck() bool {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeConfig, err := utils.KubeConfig(kubeconfigArgs) kubeConfig, err := utils.KubeConfig(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return false return false
} }
@@ -183,7 +183,7 @@ func componentsCheck() bool {
return false return false
} }
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return false return false
} }

View File

@@ -60,7 +60,7 @@ func resourceNamesCompletionFunc(gvk schema.GroupVersionKind) func(cmd *cobra.Co
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
cfg, err := utils.KubeConfig(kubeconfigArgs) cfg, err := utils.KubeConfig(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return completionError(err) return completionError(err)
} }

View File

@@ -117,7 +117,7 @@ func (names apiType) upsertAndWait(object upsertWaitable, mutate func() error) e
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) // NB globals kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) // NB globals
if err != nil { if err != nil {
return err return err
} }

View File

@@ -119,7 +119,7 @@ func createAlertCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -115,7 +115,7 @@ func createAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -21,6 +21,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"time"
"github.com/fluxcd/flux2/internal/flags" "github.com/fluxcd/flux2/internal/flags"
"github.com/fluxcd/flux2/internal/utils" "github.com/fluxcd/flux2/internal/utils"
@@ -108,17 +109,19 @@ 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 flags.HelmReleaseValuesFrom
saName string saName string
crds flags.CRDsPolicy crds flags.CRDsPolicy
reconcileStrategy string
chartInterval time.Duration
} }
var helmReleaseArgs helmReleaseFlags var helmReleaseArgs helmReleaseFlags
@@ -132,6 +135,8 @@ func init() {
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.targetNamespace, "target-namespace", "", "namespace to install this release, defaults to the HelmRelease namespace") createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.targetNamespace, "target-namespace", "", "namespace to install this release, defaults to the HelmRelease namespace")
createHelmReleaseCmd.Flags().BoolVar(&helmReleaseArgs.createNamespace, "create-target-namespace", false, "create the target namespace if it does not exist") createHelmReleaseCmd.Flags().BoolVar(&helmReleaseArgs.createNamespace, "create-target-namespace", false, "create the target namespace if it does not exist")
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.saName, "service-account", "", "the name of the service account to impersonate when reconciling this HelmRelease") createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.saName, "service-account", "", "the name of the service account to impersonate when reconciling this HelmRelease")
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.reconcileStrategy, "reconcile-strategy", "ChartVersion", "the reconcile strategy for helm chart created by the helm release(accepted values: Revision and ChartRevision)")
createHelmReleaseCmd.Flags().DurationVarP(&helmReleaseArgs.chartInterval, "chart-interval", "", 0, "the interval of which to check for new chart versions")
createHelmReleaseCmd.Flags().StringSliceVar(&helmReleaseArgs.valuesFiles, "values", nil, "local path to values.yaml files, also accepts comma-separated values") createHelmReleaseCmd.Flags().StringSliceVar(&helmReleaseArgs.valuesFiles, "values", nil, "local path to values.yaml files, also accepts comma-separated values")
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.valuesFrom, "values-from", helmReleaseArgs.valuesFrom.Description()) createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.valuesFrom, "values-from", helmReleaseArgs.valuesFrom.Description())
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.crds, "crds", helmReleaseArgs.crds.Description()) createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.crds, "crds", helmReleaseArgs.crds.Description())
@@ -154,6 +159,11 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
logger.Generatef("generating HelmRelease") logger.Generatef("generating HelmRelease")
} }
if !validateStrategy(helmReleaseArgs.reconcileStrategy) {
return fmt.Errorf("'%s' is an invalid reconcile strategy(valid: Revision, ChartVersion)",
helmReleaseArgs.reconcileStrategy)
}
helmRelease := helmv2.HelmRelease{ helmRelease := helmv2.HelmRelease{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
@@ -177,12 +187,19 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
Name: helmReleaseArgs.source.Name, Name: helmReleaseArgs.source.Name,
Namespace: helmReleaseArgs.source.Namespace, Namespace: helmReleaseArgs.source.Namespace,
}, },
ReconcileStrategy: helmReleaseArgs.reconcileStrategy,
}, },
}, },
Suspend: false, Suspend: false,
}, },
} }
if helmReleaseArgs.chartInterval != 0 {
helmRelease.Spec.Chart.Spec.Interval = &metav1.Duration{
Duration: helmReleaseArgs.chartInterval,
}
}
if helmReleaseArgs.createNamespace { if helmReleaseArgs.createNamespace {
if helmRelease.Spec.Install == nil { if helmRelease.Spec.Install == nil {
helmRelease.Spec.Install = &helmv2.Install{} helmRelease.Spec.Install = &helmv2.Install{}
@@ -247,7 +264,7 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }
@@ -316,3 +333,15 @@ func isHelmReleaseReady(ctx context.Context, kubeClient client.Client,
return apimeta.IsStatusConditionTrue(helmRelease.Status.Conditions, meta.ReadyCondition), nil return apimeta.IsStatusConditionTrue(helmRelease.Status.Conditions, meta.ReadyCondition), nil
} }
} }
func validateStrategy(input string) bool {
allowedStrategy := []string{"Revision", "ChartVersion"}
for _, strategy := range allowedStrategy {
if strategy == input {
return true
}
}
return false
}

View File

@@ -23,7 +23,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
autov1 "github.com/fluxcd/image-automation-controller/api/v1beta1" autov1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var createImageUpdateCmd = &cobra.Command{ var createImageUpdateCmd = &cobra.Command{

View File

@@ -229,7 +229,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -127,7 +127,7 @@ func createReceiverCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -173,7 +173,7 @@ func createSecretGitCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -96,7 +96,7 @@ func createSecretHelmCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -93,7 +93,7 @@ func createSecretTLSCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -30,7 +30,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" "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/flags"
"github.com/fluxcd/flux2/internal/utils" "github.com/fluxcd/flux2/internal/utils"
@@ -149,7 +151,7 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }
@@ -235,3 +237,30 @@ func upsertBucket(ctx context.Context, kubeClient client.Client,
logger.Successf("Bucket source updated") logger.Successf("Bucket source updated")
return namespacedName, nil return namespacedName, nil
} }
func isBucketReady(ctx context.Context, kubeClient client.Client,
namespacedName types.NamespacedName, bucket *sourcev1.Bucket) wait.ConditionFunc {
return func() (bool, error) {
err := kubeClient.Get(ctx, namespacedName, bucket)
if err != nil {
return false, err
}
if c := conditions.Get(bucket, meta.ReadyCondition); c != nil {
// Confirm the Ready condition we are observing is for the
// current generation
if c.ObservedGeneration != bucket.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
}
}

View File

@@ -23,19 +23,21 @@ import (
"net/url" "net/url"
"os" "os"
"github.com/fluxcd/pkg/apis/meta"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/manifoldco/promptui" "github.com/manifoldco/promptui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/errors"
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
"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/flags"
"github.com/fluxcd/flux2/internal/utils" "github.com/fluxcd/flux2/internal/utils"
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret" "github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
@@ -169,7 +171,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
} }
if sourceGitArgs.caFile != "" && u.Scheme == "ssh" { if sourceGitArgs.caFile != "" && u.Scheme == "ssh" {
return fmt.Errorf("specifing a CA file is not supported for Git over SSH") return fmt.Errorf("specifying a CA file is not supported for Git over SSH")
} }
if sourceGitArgs.recurseSubmodules && sourceGitArgs.gitImplementation == sourcev1.LibGit2Implementation { if sourceGitArgs.recurseSubmodules && sourceGitArgs.gitImplementation == sourcev1.LibGit2Implementation {
@@ -232,7 +234,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }
@@ -355,7 +357,14 @@ func isGitRepositoryReady(ctx context.Context, kubeClient client.Client,
return false, err return false, err
} }
if c := apimeta.FindStatusCondition(gitRepository.Status.Conditions, meta.ReadyCondition); c != nil { if c := conditions.Get(gitRepository, meta.ReadyCondition); c != nil {
// Confirm the Ready condition we are observing is for the
// current generation
if c.ObservedGeneration != gitRepository.GetGeneration() {
return false, nil
}
// Further check the Status
switch c.Status { switch c.Status {
case metav1.ConditionTrue: case metav1.ConditionTrue:
return true, nil return true, nil

View File

@@ -21,15 +21,17 @@ package main
import ( import (
"context" "context"
"testing"
"time"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
"k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/errors"
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
"testing"
"time"
) )
var pollInterval = 50 * time.Millisecond var pollInterval = 50 * time.Millisecond
@@ -103,7 +105,14 @@ func TestCreateSourceGit(t *testing.T) {
command, command,
assertGoldenFile("testdata/create_source_git/success.golden"), assertGoldenFile("testdata/create_source_git/success.golden"),
func(repo *sourcev1.GitRepository) { func(repo *sourcev1.GitRepository) {
meta.SetResourceCondition(repo, meta.ReadyCondition, metav1.ConditionTrue, sourcev1.GitOperationSucceedReason, "succeeded message") newCondition := metav1.Condition{
Type: meta.ReadyCondition,
Status: metav1.ConditionTrue,
Reason: sourcev1.GitOperationSucceedReason,
Message: "succeeded message",
ObservedGeneration: repo.GetGeneration(),
}
apimeta.SetStatusCondition(&repo.Status.Conditions, newCondition)
repo.Status.Artifact = &sourcev1.Artifact{ repo.Status.Artifact = &sourcev1.Artifact{
Path: "some-path", Path: "some-path",
Revision: "v1", Revision: "v1",
@@ -114,7 +123,14 @@ func TestCreateSourceGit(t *testing.T) {
command, command,
assertError("failed message"), assertError("failed message"),
func(repo *sourcev1.GitRepository) { func(repo *sourcev1.GitRepository) {
meta.SetResourceCondition(repo, meta.ReadyCondition, metav1.ConditionFalse, sourcev1.URLInvalidReason, "failed message") newCondition := metav1.Condition{
Type: meta.ReadyCondition,
Status: metav1.ConditionFalse,
Reason: sourcev1.URLInvalidReason,
Message: "failed message",
ObservedGeneration: repo.GetGeneration(),
}
apimeta.SetStatusCondition(&repo.Status.Conditions, newCondition)
}, },
}, { }, {
"NoArtifact", "NoArtifact",
@@ -122,7 +138,14 @@ func TestCreateSourceGit(t *testing.T) {
assertError("GitRepository source reconciliation completed but no artifact was found"), assertError("GitRepository source reconciliation completed but no artifact was found"),
func(repo *sourcev1.GitRepository) { func(repo *sourcev1.GitRepository) {
// Updated with no artifact // Updated with no artifact
meta.SetResourceCondition(repo, meta.ReadyCondition, metav1.ConditionTrue, sourcev1.GitOperationSucceedReason, "succeeded message") newCondition := metav1.Condition{
Type: meta.ReadyCondition,
Status: metav1.ConditionTrue,
Reason: sourcev1.GitOperationSucceedReason,
Message: "succeeded message",
ObservedGeneration: repo.GetGeneration(),
}
apimeta.SetStatusCondition(&repo.Status.Conditions, newCondition)
}, },
}, },
} }

View File

@@ -23,17 +23,17 @@ import (
"os" "os"
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/pkg/runtime/conditions"
"github.com/spf13/cobra" "github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/errors"
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
"github.com/fluxcd/flux2/internal/utils" "github.com/fluxcd/flux2/internal/utils"
"github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret" "github.com/fluxcd/flux2/pkg/manifestgen/sourcesecret"
@@ -144,7 +144,7 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }
@@ -242,12 +242,14 @@ func isHelmRepositoryReady(ctx context.Context, kubeClient client.Client,
return false, err return false, err
} }
// Confirm the state we are observing is for the current generation if c := conditions.Get(helmRepository, meta.ReadyCondition); c != nil {
if helmRepository.Generation != helmRepository.Status.ObservedGeneration { // Confirm the Ready condition we are observing is for the
return false, nil // current generation
} if c.ObservedGeneration != helmRepository.GetGeneration() {
return false, nil
}
if c := apimeta.FindStatusCondition(helmRepository.Status.Conditions, meta.ReadyCondition); c != nil { // Further check the Status
switch c.Status { switch c.Status {
case metav1.ConditionTrue: case metav1.ConditionTrue:
return true, nil return true, nil

View File

@@ -156,7 +156,7 @@ func createTenantCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -60,7 +60,7 @@ func (del deleteCommand) run(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -27,7 +27,7 @@ var deleteKsCmd = &cobra.Command{
Aliases: []string{"ks"}, Aliases: []string{"ks"},
Short: "Delete a Kustomization resource", Short: "Delete a Kustomization resource",
Long: "The delete kustomization command deletes the given Kustomization from the cluster.", Long: "The delete kustomization command deletes the given Kustomization from the cluster.",
Example: ` # Delete a kustomization and the Kubernetes resources created by it Example: ` # Delete a kustomization and the Kubernetes resources created by it when prune is enabled
flux delete kustomization podinfo`, flux delete kustomization podinfo`,
ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)), ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)),
RunE: deleteCommand{ RunE: deleteCommand{

View File

@@ -19,7 +19,7 @@ package main
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var deleteSourceBucketCmd = &cobra.Command{ var deleteSourceBucketCmd = &cobra.Command{

View File

@@ -19,7 +19,7 @@ package main
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var deleteSourceGitCmd = &cobra.Command{ var deleteSourceGitCmd = &cobra.Command{

View File

@@ -19,7 +19,7 @@ package main
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var deleteSourceHelmCmd = &cobra.Command{ var deleteSourceHelmCmd = &cobra.Command{

View File

@@ -34,21 +34,26 @@ var diffKsCmd = &cobra.Command{
Long: `The diff command does a build, then it performs a server-side dry-run and prints the diff. Long: `The diff command does a build, then it performs a server-side dry-run and prints the diff.
Exit status: 0 No differences were found. 1 Differences were found. >1 diff failed with an error.`, Exit status: 0 No differences were found. 1 Differences were found. >1 diff failed with an error.`,
Example: `# Preview local changes as they were applied on the cluster Example: `# Preview local changes as they were applied on the cluster
flux diff kustomization my-app --path ./path/to/local/manifests`, flux diff kustomization my-app --path ./path/to/local/manifests
# Preview using a local flux kustomization file
flux diff kustomization my-app --path ./path/to/local/manifests --kustomization-file ./path/to/local/my-app.yaml`,
ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)), ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)),
RunE: diffKsCmdRun, RunE: diffKsCmdRun,
} }
type diffKsFlags struct { type diffKsFlags struct {
path string kustomizationFile string
progressBar bool path string
progressBar bool
} }
var diffKsArgs diffKsFlags var diffKsArgs diffKsFlags
func init() { func init() {
diffKsCmd.Flags().StringVar(&diffKsArgs.path, "path", "", "Path to a local directory that matches the specified Kustomization.spec.path.)") diffKsCmd.Flags().StringVar(&diffKsArgs.path, "path", "", "Path to a local directory that matches the specified Kustomization.spec.path.")
diffKsCmd.Flags().BoolVar(&diffKsArgs.progressBar, "progress-bar", true, "Boolean to set the progress bar. The default value is true.") diffKsCmd.Flags().BoolVar(&diffKsArgs.progressBar, "progress-bar", true, "Boolean to set the progress bar. The default value is true.")
diffKsCmd.Flags().StringVar(&diffKsArgs.kustomizationFile, "kustomization-file", "", "Path to the Flux Kustomization YAML file.")
diffCmd.AddCommand(diffKsCmd) diffCmd.AddCommand(diffKsCmd)
} }
@@ -66,12 +71,18 @@ func diffKsCmdRun(cmd *cobra.Command, args []string) error {
return &RequestError{StatusCode: 2, Err: fmt.Errorf("invalid resource path %q", diffKsArgs.path)} return &RequestError{StatusCode: 2, Err: fmt.Errorf("invalid resource path %q", diffKsArgs.path)}
} }
if diffKsArgs.kustomizationFile != "" {
if fs, err := os.Stat(diffKsArgs.kustomizationFile); os.IsNotExist(err) || fs.IsDir() {
return fmt.Errorf("invalid kustomization file %q", diffKsArgs.kustomizationFile)
}
}
var builder *build.Builder var builder *build.Builder
var err error var err error
if diffKsArgs.progressBar { if diffKsArgs.progressBar {
builder, err = build.NewBuilder(kubeconfigArgs, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout), build.WithProgressBar()) builder, err = build.NewBuilder(kubeconfigArgs, kubeclientOptions, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout), build.WithKustomizationFile(diffKsArgs.kustomizationFile), build.WithProgressBar())
} else { } else {
builder, err = build.NewBuilder(kubeconfigArgs, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout)) builder, err = build.NewBuilder(kubeconfigArgs, kubeclientOptions, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout), build.WithKustomizationFile(diffKsArgs.kustomizationFile))
} }
if err != nil { if err != nil {

View File

@@ -97,7 +97,7 @@ func TestDiffKustomization(t *testing.T) {
"fluxns": allocateNamespace("flux-system"), "fluxns": allocateNamespace("flux-system"),
} }
b, _ := build.NewBuilder(kubeconfigArgs, "podinfo", "") b, _ := build.NewBuilder(kubeconfigArgs, kubeclientOptions, "podinfo", "")
resourceManager, err := b.Manager() resourceManager, err := b.Manager()
if err != nil { if err != nil {

View File

@@ -74,7 +74,7 @@ func (export exportCommand) run(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -59,7 +59,7 @@ func (export exportWithSecretCommand) run(cmd *cobra.Command, args []string) err
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -21,7 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var exportSourceBucketCmd = &cobra.Command{ var exportSourceBucketCmd = &cobra.Command{

View File

@@ -21,7 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var exportSourceGitCmd = &cobra.Command{ var exportSourceGitCmd = &cobra.Command{

View File

@@ -21,7 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var exportSourceHelmCmd = &cobra.Command{ var exportSourceHelmCmd = &cobra.Command{

View File

@@ -33,6 +33,7 @@ import (
"github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/flux2/internal/utils" "github.com/fluxcd/flux2/internal/utils"
"github.com/fluxcd/flux2/pkg/printers"
) )
type deriveType func(runtime.Object) (summarisable, error) type deriveType func(runtime.Object) (summarisable, error)
@@ -135,7 +136,7 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }
@@ -177,7 +178,10 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
return err return err
} }
utils.PrintTable(cmd.OutOrStdout(), header, rows) err = printers.TablePrinter(header).Print(cmd.OutOrStdout(), rows)
if err != nil {
return err
}
if getAll { if getAll {
fmt.Println() fmt.Println()
@@ -242,10 +246,16 @@ func watchUntil(ctx context.Context, w watch.Interface, get *getCommand) (bool,
return false, err return false, err
} }
if firstIteration { if firstIteration {
utils.PrintTable(os.Stdout, header, rows) err = printers.TablePrinter(header).Print(os.Stdout, rows)
if err != nil {
return false, err
}
firstIteration = false firstIteration = false
} else { } else {
utils.PrintTable(os.Stdout, []string{}, rows) err = printers.TablePrinter([]string{}).Print(os.Stdout, rows)
if err != nil {
return false, err
}
} }
return false, nil return false, nil

View File

@@ -77,11 +77,11 @@ func init() {
func (s alertListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string { func (s alertListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
item := s.Items[i] item := s.Items[i]
status, msg := statusAndMessage(item.Status.Conditions) status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace, includeKind), status, msg, strings.Title(strconv.FormatBool(item.Spec.Suspend))) return append(nameColumns(&item, includeNamespace, includeKind), strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
} }
func (s alertListAdapter) headers(includeNamespace bool) []string { func (s alertListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Suspended"} headers := []string{"Name", "Suspended", "Ready", "Message"}
if includeNamespace { if includeNamespace {
return append(namespaceHeader, headers...) return append(namespaceHeader, headers...)
} }

View File

@@ -75,11 +75,11 @@ func (a helmReleaseListAdapter) summariseItem(i int, includeNamespace bool, incl
revision := item.Status.LastAppliedRevision revision := item.Status.LastAppliedRevision
status, msg := statusAndMessage(item.Status.Conditions) status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace, includeKind), return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend))) revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
} }
func (a helmReleaseListAdapter) headers(includeNamespace bool) []string { func (a helmReleaseListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Revision", "Suspended"} headers := []string{"Name", "Revision", "Suspended", "Ready", "Message"}
if includeNamespace { if includeNamespace {
headers = append([]string{"Namespace"}, headers...) headers = append([]string{"Namespace"}, headers...)
} }

View File

@@ -74,11 +74,11 @@ func init() {
func (s imagePolicyListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string { func (s imagePolicyListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
item := s.Items[i] item := s.Items[i]
status, msg := statusAndMessage(item.Status.Conditions) status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace, includeKind), status, msg, item.Status.LatestImage) return append(nameColumns(&item, includeNamespace, includeKind), item.Status.LatestImage, status, msg)
} }
func (s imagePolicyListAdapter) headers(includeNamespace bool) []string { func (s imagePolicyListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Latest image"} headers := []string{"Name", "Latest image", "Ready", "Message"}
if includeNamespace { if includeNamespace {
return append(namespaceHeader, headers...) return append(namespaceHeader, headers...)
} }

View File

@@ -82,11 +82,11 @@ func (s imageRepositoryListAdapter) summariseItem(i int, includeNamespace bool,
lastScan = item.Status.LastScanResult.ScanTime.Time.Format(time.RFC3339) lastScan = item.Status.LastScanResult.ScanTime.Time.Format(time.RFC3339)
} }
return append(nameColumns(&item, includeNamespace, includeKind), return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, lastScan, strings.Title(strconv.FormatBool(item.Spec.Suspend))) lastScan, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
} }
func (s imageRepositoryListAdapter) headers(includeNamespace bool) []string { func (s imageRepositoryListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Last scan", "Suspended"} headers := []string{"Name", "Last scan", "Suspended", "Ready", "Message"}
if includeNamespace { if includeNamespace {
return append(namespaceHeader, headers...) return append(namespaceHeader, headers...)
} }

View File

@@ -81,11 +81,11 @@ func (s imageUpdateAutomationListAdapter) summariseItem(i int, includeNamespace
if item.Status.LastAutomationRunTime != nil { if item.Status.LastAutomationRunTime != nil {
lastRun = item.Status.LastAutomationRunTime.Time.Format(time.RFC3339) lastRun = item.Status.LastAutomationRunTime.Time.Format(time.RFC3339)
} }
return append(nameColumns(&item, includeNamespace, includeKind), status, msg, lastRun, strings.Title(strconv.FormatBool(item.Spec.Suspend))) return append(nameColumns(&item, includeNamespace, includeKind), lastRun, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
} }
func (s imageUpdateAutomationListAdapter) headers(includeNamespace bool) []string { func (s imageUpdateAutomationListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Last run", "Suspended"} headers := []string{"Name", "Last run", "Suspended", "Ready", "Message"}
if includeNamespace { if includeNamespace {
return append(namespaceHeader, headers...) return append(namespaceHeader, headers...)
} }

View File

@@ -85,11 +85,11 @@ func (a kustomizationListAdapter) summariseItem(i int, includeNamespace bool, in
msg = shortenCommitSha(msg) msg = shortenCommitSha(msg)
} }
return append(nameColumns(&item, includeNamespace, includeKind), return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend))) revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
} }
func (a kustomizationListAdapter) headers(includeNamespace bool) []string { func (a kustomizationListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Revision", "Suspended"} headers := []string{"Name", "Revision", "Suspended", "Ready", "Message"}
if includeNamespace { if includeNamespace {
headers = append([]string{"Namespace"}, headers...) headers = append([]string{"Namespace"}, headers...)
} }

View File

@@ -74,11 +74,11 @@ func init() {
func (s receiverListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string { func (s receiverListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
item := s.Items[i] item := s.Items[i]
status, msg := statusAndMessage(item.Status.Conditions) status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace, includeKind), status, msg, strings.Title(strconv.FormatBool(item.Spec.Suspend))) return append(nameColumns(&item, includeNamespace, includeKind), strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
} }
func (s receiverListAdapter) headers(includeNamespace bool) []string { func (s receiverListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Suspended"} headers := []string{"Name", "Suspended", "Ready", "Message"}
if includeNamespace { if includeNamespace {
return append(namespaceHeader, headers...) return append(namespaceHeader, headers...)
} }

View File

@@ -21,7 +21,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var getSourceAllCmd = &cobra.Command{ var getSourceAllCmd = &cobra.Command{

View File

@@ -24,7 +24,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var getSourceBucketCmd = &cobra.Command{ var getSourceBucketCmd = &cobra.Command{
@@ -81,11 +81,11 @@ func (a *bucketListAdapter) summariseItem(i int, includeNamespace bool, includeK
} }
status, msg := statusAndMessage(item.Status.Conditions) status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace, includeKind), return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend))) revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
} }
func (a bucketListAdapter) headers(includeNamespace bool) []string { func (a bucketListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Revision", "Suspended"} headers := []string{"Name", "Revision", "Suspended", "Ready", "Message"}
if includeNamespace { if includeNamespace {
headers = append([]string{"Namespace"}, headers...) headers = append([]string{"Namespace"}, headers...)
} }

View File

@@ -24,7 +24,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var getSourceHelmChartCmd = &cobra.Command{ var getSourceHelmChartCmd = &cobra.Command{
@@ -81,11 +81,11 @@ func (a *helmChartListAdapter) summariseItem(i int, includeNamespace bool, inclu
} }
status, msg := statusAndMessage(item.Status.Conditions) status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace, includeKind), return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend))) revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
} }
func (a helmChartListAdapter) headers(includeNamespace bool) []string { func (a helmChartListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Revision", "Suspended"} headers := []string{"Name", "Revision", "Suspended", "Ready", "Message"}
if includeNamespace { if includeNamespace {
headers = append([]string{"Namespace"}, headers...) headers = append([]string{"Namespace"}, headers...)
} }

View File

@@ -25,7 +25,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var getSourceGitCmd = &cobra.Command{ var getSourceGitCmd = &cobra.Command{
@@ -86,11 +86,11 @@ func (a *gitRepositoryListAdapter) summariseItem(i int, includeNamespace bool, i
msg = shortenCommitSha(msg) msg = shortenCommitSha(msg)
} }
return append(nameColumns(&item, includeNamespace, includeKind), return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend))) revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
} }
func (a gitRepositoryListAdapter) headers(includeNamespace bool) []string { func (a gitRepositoryListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Revision", "Suspended"} headers := []string{"Name", "Revision", "Suspended", "Ready", "Message"}
if includeNamespace { if includeNamespace {
headers = append([]string{"Namespace"}, headers...) headers = append([]string{"Namespace"}, headers...)
} }

View File

@@ -24,7 +24,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var getSourceHelmCmd = &cobra.Command{ var getSourceHelmCmd = &cobra.Command{
@@ -81,11 +81,11 @@ func (a *helmRepositoryListAdapter) summariseItem(i int, includeNamespace bool,
} }
status, msg := statusAndMessage(item.Status.Conditions) status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace, includeKind), return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend))) revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
} }
func (a helmRepositoryListAdapter) headers(includeNamespace bool) []string { func (a helmRepositoryListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Revision", "Suspended"} headers := []string{"Name", "Revision", "Suspended", "Ready", "Message"}
if includeNamespace { if includeNamespace {
headers = append([]string{"Namespace"}, headers...) headers = append([]string{"Namespace"}, headers...)
} }

View File

@@ -37,10 +37,13 @@ var installCmd = &cobra.Command{
Long: `The install command deploys Flux in the specified namespace. Long: `The install command deploys Flux in the specified namespace.
If a previous version is installed, then an in-place upgrade will be performed.`, If a previous version is installed, then an in-place upgrade will be performed.`,
Example: ` # Install the latest version in the flux-system namespace Example: ` # Install the latest version in the flux-system namespace
flux install --version=latest --namespace=flux-system flux install --namespace=flux-system
# Install a specific version and a series of components # Install a specific series of components
flux install --version=v0.0.7 --components="source-controller,kustomize-controller" flux install --components="source-controller,kustomize-controller"
# Install all components including the image automation ones
flux install --components-extra="image-reflector-controller,image-automation-controller"
# Install Flux onto tainted Kubernetes nodes # Install Flux onto tainted Kubernetes nodes
flux install --toleration-keys=node.kubernetes.io/dedicated-to-flux flux install --toleration-keys=node.kubernetes.io/dedicated-to-flux
@@ -84,7 +87,7 @@ func init() {
installCmd.Flags().StringSliceVar(&installArgs.defaultComponents, "components", rootArgs.defaults.Components, installCmd.Flags().StringSliceVar(&installArgs.defaultComponents, "components", rootArgs.defaults.Components,
"list of components, accepts comma-separated values") "list of components, accepts comma-separated values")
installCmd.Flags().StringSliceVar(&installArgs.extraComponents, "components-extra", nil, installCmd.Flags().StringSliceVar(&installArgs.extraComponents, "components-extra", nil,
"list of components in addition to those supplied or defaulted, accepts comma-separated values") "list of components in addition to those supplied or defaulted, accepts values such as 'image-reflector-controller,image-automation-controller'")
installCmd.Flags().StringVar(&installArgs.manifestsPath, "manifests", "", "path to the manifest directory") installCmd.Flags().StringVar(&installArgs.manifestsPath, "manifests", "", "path to the manifest directory")
installCmd.Flags().StringVar(&installArgs.registry, "registry", rootArgs.defaults.Registry, installCmd.Flags().StringVar(&installArgs.registry, "registry", rootArgs.defaults.Registry,
"container registry where the toolkit images are published") "container registry where the toolkit images are published")
@@ -190,14 +193,14 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
return nil return nil
} }
applyOutput, err := utils.Apply(ctx, kubeconfigArgs, filepath.Join(tmpDir, manifest.Path)) applyOutput, err := utils.Apply(ctx, kubeconfigArgs, kubeclientOptions, filepath.Join(tmpDir, manifest.Path))
if err != nil { if err != nil {
return fmt.Errorf("install failed: %w", err) return fmt.Errorf("install failed: %w", err)
} }
fmt.Fprintln(os.Stderr, applyOutput) fmt.Fprintln(os.Stderr, applyOutput)
kubeConfig, err := utils.KubeConfig(kubeconfigArgs) kubeConfig, err := utils.KubeConfig(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return fmt.Errorf("install failed: %w", err) return fmt.Errorf("install failed: %w", err)
} }

View File

@@ -99,7 +99,7 @@ func logsCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
cfg, err := utils.KubeConfig(kubeconfigArgs) cfg, err := utils.KubeConfig(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -30,6 +30,8 @@ import (
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
_ "k8s.io/client-go/plugin/pkg/client/auth" _ "k8s.io/client-go/plugin/pkg/client/auth"
runclient "github.com/fluxcd/pkg/runtime/client"
"github.com/fluxcd/flux2/pkg/manifestgen/install" "github.com/fluxcd/flux2/pkg/manifestgen/install"
) )
@@ -117,6 +119,7 @@ func (r *RequestError) Error() string {
var rootArgs = NewRootFlags() var rootArgs = NewRootFlags()
var kubeconfigArgs = genericclioptions.NewConfigFlags(false) var kubeconfigArgs = genericclioptions.NewConfigFlags(false)
var kubeclientOptions = new(runclient.Options)
func init() { func init() {
rootCmd.PersistentFlags().DurationVar(&rootArgs.timeout, "timeout", 5*time.Minute, "timeout for this operation") rootCmd.PersistentFlags().DurationVar(&rootArgs.timeout, "timeout", 5*time.Minute, "timeout for this operation")
@@ -134,6 +137,8 @@ func init() {
kubeconfigArgs.APIServer = &apiServer kubeconfigArgs.APIServer = &apiServer
rootCmd.PersistentFlags().StringVar(kubeconfigArgs.APIServer, "server", *kubeconfigArgs.APIServer, "The address and port of the Kubernetes API server") rootCmd.PersistentFlags().StringVar(kubeconfigArgs.APIServer, "server", *kubeconfigArgs.APIServer, "The address and port of the Kubernetes API server")
kubeclientOptions.BindFlags(rootCmd.PersistentFlags())
rootCmd.RegisterFlagCompletionFunc("context", contextsCompletionFunc) rootCmd.RegisterFlagCompletionFunc("context", contextsCompletionFunc)
rootCmd.RegisterFlagCompletionFunc("namespace", resourceNamesCompletionFunc(corev1.SchemeGroupVersion.WithKind("Namespace"))) rootCmd.RegisterFlagCompletionFunc("namespace", resourceNamesCompletionFunc(corev1.SchemeGroupVersion.WithKind("Namespace")))

View File

@@ -20,6 +20,7 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"context" "context"
"flag"
"fmt" "fmt"
"io" "io"
"os" "os"
@@ -42,6 +43,9 @@ import (
var nextNamespaceId int64 var nextNamespaceId int64
// update allows golden files to be updated based on the current output.
var update = flag.Bool("update", false, "update golden files")
// Return a unique namespace with the specified prefix, for tests to create // Return a unique namespace with the specified prefix, for tests to create
// objects that won't collide with each other. // objects that won't collide with each other.
func allocateNamespace(prefix string) string { func allocateNamespace(prefix string) string {
@@ -298,6 +302,18 @@ func assertGoldenTemplateFile(goldenFile string, templateValues map[string]strin
expectedOutput = string(goldenFileContents) expectedOutput = string(goldenFileContents)
} }
if assertErr := assertGoldenValue(expectedOutput)(output, err); assertErr != nil { if assertErr := assertGoldenValue(expectedOutput)(output, err); assertErr != nil {
// Update the golden files if comparison fails and the update flag is set.
if *update && output != "" {
// Skip update if there are template values.
if len(templateValues) > 0 {
fmt.Println("NOTE: -update flag passed but golden template files can't be updated, please update it manually")
} else {
if err := os.WriteFile(goldenFile, []byte(output), 0644); err != nil {
return fmt.Errorf("failed to update golden file '%s': %v", goldenFile, err)
}
return nil
}
}
return fmt.Errorf("Mismatch from golden file '%s': %v", goldenFile, assertErr) return fmt.Errorf("Mismatch from golden file '%s': %v", goldenFile, assertErr)
} }
return nil return nil

View File

@@ -60,13 +60,22 @@ type reconcilable interface {
GetAnnotations() map[string]string GetAnnotations() map[string]string
SetAnnotations(map[string]string) SetAnnotations(map[string]string)
// this is usually implemented by GOTK types, since it's used for meta.SetResourceCondition
GetStatusConditions() *[]metav1.Condition
lastHandledReconcileRequest() string // what was the last handled reconcile request? lastHandledReconcileRequest() string // what was the last handled reconcile request?
successMessage() string // what do you want to tell people when successfully reconciled? successMessage() string // what do you want to tell people when successfully reconciled?
} }
func reconcilableConditions(object reconcilable) []metav1.Condition {
if s, ok := object.(meta.ObjectWithConditions); ok {
return s.GetConditions()
}
if s, ok := object.(oldConditions); ok {
return *s.GetStatusConditions()
}
return []metav1.Condition{}
}
func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error { func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error {
if len(args) < 1 { if len(args) < 1 {
return fmt.Errorf("%s name is required", reconcile.kind) return fmt.Errorf("%s name is required", reconcile.kind)
@@ -76,7 +85,7 @@ func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }
@@ -118,7 +127,7 @@ func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error {
reconciliationHandled(ctx, kubeClient, namespacedName, reconcile.object, lastHandledReconcileAt)); err != nil { reconciliationHandled(ctx, kubeClient, namespacedName, reconcile.object, lastHandledReconcileAt)); err != nil {
return err return err
} }
readyCond := apimeta.FindStatusCondition(*reconcile.object.GetStatusConditions(), meta.ReadyCondition) readyCond := apimeta.FindStatusCondition(reconcilableConditions(reconcile.object), meta.ReadyCondition)
if readyCond == nil { if readyCond == nil {
return fmt.Errorf("status can't be determined") return fmt.Errorf("status can't be determined")
} }
@@ -137,7 +146,7 @@ func reconciliationHandled(ctx context.Context, kubeClient client.Client,
if err != nil { if err != nil {
return false, err return false, err
} }
isProgressing := apimeta.IsStatusConditionPresentAndEqual(*obj.GetStatusConditions(), isProgressing := apimeta.IsStatusConditionPresentAndEqual(reconcilableConditions(obj),
meta.ReadyCondition, metav1.ConditionUnknown) meta.ReadyCondition, metav1.ConditionUnknown)
return obj.lastHandledReconcileRequest() != lastHandledReconcileAt && !isProgressing, nil return obj.lastHandledReconcileRequest() != lastHandledReconcileAt && !isProgressing, nil
} }
@@ -174,7 +183,7 @@ func isReconcileReady(ctx context.Context, kubeClient client.Client,
return false, err return false, err
} }
if c := apimeta.FindStatusCondition(*obj.GetStatusConditions(), meta.ReadyCondition); c != nil { if c := apimeta.FindStatusCondition(reconcilableConditions(obj), meta.ReadyCondition); c != nil {
switch c.Status { switch c.Status {
case metav1.ConditionTrue: case metav1.ConditionTrue:
return true, nil return true, nil

View File

@@ -54,7 +54,7 @@ func reconcileAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -21,7 +21,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1" helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var reconcileHrCmd = &cobra.Command{ var reconcileHrCmd = &cobra.Command{

View File

@@ -21,7 +21,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var reconcileKsCmd = &cobra.Command{ var reconcileKsCmd = &cobra.Command{

View File

@@ -54,7 +54,7 @@ func reconcileReceiverCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -17,18 +17,11 @@ limitations under the License.
package main package main
import ( import (
"context"
"fmt" "fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
apimeta "k8s.io/apimachinery/pkg/api/meta"
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" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
) )
var reconcileSourceBucketCmd = &cobra.Command{ var reconcileSourceBucketCmd = &cobra.Command{
@@ -48,31 +41,6 @@ func init() {
reconcileSourceCmd.AddCommand(reconcileSourceBucketCmd) reconcileSourceCmd.AddCommand(reconcileSourceBucketCmd)
} }
func isBucketReady(ctx context.Context, kubeClient client.Client,
namespacedName types.NamespacedName, bucket *sourcev1.Bucket) wait.ConditionFunc {
return func() (bool, error) {
err := kubeClient.Get(ctx, namespacedName, bucket)
if err != nil {
return false, err
}
// Confirm the state we are observing is for the current generation
if bucket.Generation != bucket.Status.ObservedGeneration {
return false, nil
}
if c := apimeta.FindStatusCondition(bucket.Status.Conditions, meta.ReadyCondition); c != nil {
switch c.Status {
case metav1.ConditionTrue:
return true, nil
case metav1.ConditionFalse:
return false, fmt.Errorf(c.Message)
}
}
return false, nil
}
}
func (obj bucketAdapter) lastHandledReconcileRequest() string { func (obj bucketAdapter) lastHandledReconcileRequest() string {
return obj.Status.GetLastHandledReconcileRequest() return obj.Status.GetLastHandledReconcileRequest()
} }

View File

@@ -21,7 +21,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var reconcileSourceGitCmd = &cobra.Command{ var reconcileSourceGitCmd = &cobra.Command{

View File

@@ -21,7 +21,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var reconcileSourceHelmCmd = &cobra.Command{ var reconcileSourceHelmCmd = &cobra.Command{

View File

@@ -10,9 +10,8 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/flux2/internal/utils" "github.com/fluxcd/flux2/internal/utils"
"github.com/fluxcd/pkg/apis/meta"
) )
type reconcileWithSource interface { type reconcileWithSource interface {
@@ -36,7 +35,7 @@ func (reconcile reconcileWithSourceCommand) run(cmd *cobra.Command, args []strin
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }
@@ -83,7 +82,7 @@ func (reconcile reconcileWithSourceCommand) run(cmd *cobra.Command, args []strin
return err return err
} }
readyCond := apimeta.FindStatusCondition(*reconcile.object.GetStatusConditions(), meta.ReadyCondition) readyCond := apimeta.FindStatusCondition(reconcilableConditions(reconcile.object), meta.ReadyCondition)
if readyCond == nil { if readyCond == nil {
return fmt.Errorf("status can't be determined") return fmt.Errorf("status can't be determined")
} }

View File

@@ -76,7 +76,7 @@ func (resume resumeCommand) run(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -19,7 +19,7 @@ package main
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var resumeSourceBucketCmd = &cobra.Command{ var resumeSourceBucketCmd = &cobra.Command{
@@ -31,7 +31,8 @@ var resumeSourceBucketCmd = &cobra.Command{
ValidArgsFunction: resourceNamesCompletionFunc(sourcev1.GroupVersion.WithKind(sourcev1.BucketKind)), ValidArgsFunction: resourceNamesCompletionFunc(sourcev1.GroupVersion.WithKind(sourcev1.BucketKind)),
RunE: resumeCommand{ RunE: resumeCommand{
apiType: bucketType, apiType: bucketType,
object: &bucketAdapter{&sourcev1.Bucket{}}, object: bucketAdapter{&sourcev1.Bucket{}},
list: bucketListAdapter{&sourcev1.BucketList{}},
}.run, }.run,
} }

View File

@@ -21,7 +21,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var resumeSourceHelmChartCmd = &cobra.Command{ var resumeSourceHelmChartCmd = &cobra.Command{

View File

@@ -19,7 +19,7 @@ package main
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var resumeSourceGitCmd = &cobra.Command{ var resumeSourceGitCmd = &cobra.Command{

View File

@@ -19,7 +19,7 @@ package main
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var resumeSourceHelmCmd = &cobra.Command{ var resumeSourceHelmCmd = &cobra.Command{

View File

@@ -19,7 +19,7 @@ package main
import ( import (
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
// These are general-purpose adapters for attaching methods to, for // These are general-purpose adapters for attaching methods to, for

View File

@@ -20,6 +20,7 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/fluxcd/pkg/apis/meta"
apimeta "k8s.io/apimachinery/pkg/api/meta" apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
@@ -27,8 +28,6 @@ import (
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"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"
"github.com/fluxcd/pkg/apis/meta"
) )
// statusable is used to see if a resource is considered ready in the usual way // statusable is used to see if a resource is considered ready in the usual way
@@ -37,10 +36,26 @@ type statusable interface {
// this is implemented by ObjectMeta // this is implemented by ObjectMeta
GetGeneration() int64 GetGeneration() int64
getObservedGeneration() int64 getObservedGeneration() int64
}
// oldConditions represents the deprecated API which is sunsetting.
type oldConditions interface {
// this is usually implemented by GOTK API objects because it's used by pkg/apis/meta // this is usually implemented by GOTK API objects because it's used by pkg/apis/meta
GetStatusConditions() *[]metav1.Condition GetStatusConditions() *[]metav1.Condition
} }
func statusableConditions(object statusable) []metav1.Condition {
if s, ok := object.(meta.ObjectWithConditions); ok {
return s.GetConditions()
}
if s, ok := object.(oldConditions); ok {
return *s.GetStatusConditions()
}
return []metav1.Condition{}
}
func isReady(ctx context.Context, kubeClient client.Client, func isReady(ctx context.Context, kubeClient client.Client,
namespacedName types.NamespacedName, object statusable) wait.ConditionFunc { namespacedName types.NamespacedName, object statusable) wait.ConditionFunc {
return func() (bool, error) { return func() (bool, error) {
@@ -54,7 +69,7 @@ func isReady(ctx context.Context, kubeClient client.Client,
return false, nil return false, nil
} }
if c := apimeta.FindStatusCondition(*object.GetStatusConditions(), meta.ReadyCondition); c != nil { if c := apimeta.FindStatusCondition(statusableConditions(object), meta.ReadyCondition); c != nil {
switch c.Status { switch c.Status {
case metav1.ConditionTrue: case metav1.ConditionTrue:
return true, nil return true, nil

View File

@@ -70,7 +70,7 @@ func (suspend suspendCommand) run(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -19,7 +19,7 @@ package main
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var suspendSourceBucketCmd = &cobra.Command{ var suspendSourceBucketCmd = &cobra.Command{

View File

@@ -19,7 +19,7 @@ package main
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var suspendSourceHelmChartCmd = &cobra.Command{ var suspendSourceHelmChartCmd = &cobra.Command{

View File

@@ -19,7 +19,7 @@ package main
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var suspendSourceGitCmd = &cobra.Command{ var suspendSourceGitCmd = &cobra.Command{

View File

@@ -19,7 +19,7 @@ package main
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var suspendSourceHelmCmd = &cobra.Command{ var suspendSourceHelmCmd = &cobra.Command{

View File

@@ -13,3 +13,7 @@ spec:
kind: GitRepository kind: GitRepository
name: podinfo name: podinfo
targetNamespace: default targetNamespace: default
postBuild:
substitute:
cluster_env: "prod"
cluster_region: "eu-central-1"

View File

@@ -0,0 +1,216 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
environment: prod
kustomize.toolkit.fluxcd.io/name: podinfo
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
region: eu-central-1
name: podinfo
namespace: default
spec:
minReadySeconds: 3
progressDeadlineSeconds: 60
revisionHistoryLimit: 5
selector:
matchLabels:
app: podinfo
strategy:
rollingUpdate:
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
annotations:
prometheus.io/port: "9797"
prometheus.io/scrape: "true"
labels:
app: podinfo
spec:
containers:
- command:
- ./podinfo
- --port=9898
- --port-metrics=9797
- --grpc-port=9999
- --grpc-service-name=podinfo
- --level=info
- --random-delay=false
- --random-error=false
env:
- name: PODINFO_UI_COLOR
value: '#34577c'
image: ghcr.io/stefanprodan/podinfo:6.0.10
imagePullPolicy: IfNotPresent
livenessProbe:
exec:
command:
- podcli
- check
- http
- localhost:9898/healthz
initialDelaySeconds: 5
timeoutSeconds: 5
name: podinfod
ports:
- containerPort: 9898
name: http
protocol: TCP
- containerPort: 9797
name: http-metrics
protocol: TCP
- containerPort: 9999
name: grpc
protocol: TCP
readinessProbe:
exec:
command:
- podcli
- check
- http
- localhost:9898/readyz
initialDelaySeconds: 5
timeoutSeconds: 5
resources:
limits:
cpu: 2000m
memory: 512Mi
requests:
cpu: 100m
memory: 64Mi
---
apiVersion: v1
data:
cluster.json: |
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"iteration": 1636369574387,
"links": [],
"panels": [
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"fieldConfig": {
"defaults": {
"decimals": 0,
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "blue",
"value": null
},
{
"color": "red",
"value": 100
}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 5,
"w": 6,
"x": 0,
"y": 0
},
"id": 24,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
"last"
],
"fields": "",
"values": false
},
"text": {},
"textMode": "value"
},
"pluginVersion": "7.5.5",
"targets": [
{
"exemplar": true,
"expr": "count(gotk_reconcile_condition{namespace=~\"$operator_namespace\",exported_namespace=~\"$namespace\",type=\"Ready\",status=\"True\",kind=~\"Kustomization|HelmRelease\"})\n-\nsum(gotk_reconcile_condition{namespace=~\"$operator_namespace\",exported_namespace=~\"$namespace\",type=\"Ready\",status=\"Deleted\",kind=~\"Kustomization|HelmRelease\"})",
"interval": "",
"legendFormat": "",
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "Cluster Reconcilers",
"type": "stat"
},
{
"collapsed": false,
"datasource": "${DS_PROMETHEUS}",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 9
},
"id": 15,
"panels": [],
"title": "Status",
"type": "row"
}
],
"refresh": "",
"schemaVersion": 27,
"style": "light",
"tags": [
"flux"
],
"time": {
"from": "now-15m",
"to": "now"
},
"timepicker": {
"refresh_intervals": [
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
]
},
"timezone": "",
"title": "Flux Cluster Stats",
"uid": "flux-cluster",
"version": 1
}
kind: ConfigMap
metadata:
labels:
kustomize.toolkit.fluxcd.io/name: podinfo
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
kustomize.toolkit.fluxcd.io/substitute: disabled
name: flux-grafana-dashboards-kt8md725kf
namespace: default

View File

@@ -0,0 +1,124 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"iteration": 1636369574387,
"links": [],
"panels": [
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"fieldConfig": {
"defaults": {
"decimals": 0,
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "blue",
"value": null
},
{
"color": "red",
"value": 100
}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 5,
"w": 6,
"x": 0,
"y": 0
},
"id": 24,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
"last"
],
"fields": "",
"values": false
},
"text": {},
"textMode": "value"
},
"pluginVersion": "7.5.5",
"targets": [
{
"exemplar": true,
"expr": "count(gotk_reconcile_condition{namespace=~\"$operator_namespace\",exported_namespace=~\"$namespace\",type=\"Ready\",status=\"True\",kind=~\"Kustomization|HelmRelease\"})\n-\nsum(gotk_reconcile_condition{namespace=~\"$operator_namespace\",exported_namespace=~\"$namespace\",type=\"Ready\",status=\"Deleted\",kind=~\"Kustomization|HelmRelease\"})",
"interval": "",
"legendFormat": "",
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "Cluster Reconcilers",
"type": "stat"
},
{
"collapsed": false,
"datasource": "${DS_PROMETHEUS}",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 9
},
"id": 15,
"panels": [],
"title": "Status",
"type": "row"
}
],
"refresh": "",
"schemaVersion": 27,
"style": "light",
"tags": [
"flux"
],
"time": {
"from": "now-15m",
"to": "now"
},
"timepicker": {
"refresh_intervals": [
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
]
},
"timezone": "",
"title": "Flux Cluster Stats",
"uid": "flux-cluster",
"version": 1
}

View File

@@ -0,0 +1,77 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
environment: ${cluster_env:=dev}
region: ${cluster_region}
name: podinfo
spec:
minReadySeconds: 3
revisionHistoryLimit: 5
progressDeadlineSeconds: 60
strategy:
rollingUpdate:
maxUnavailable: 0
type: RollingUpdate
selector:
matchLabels:
app: podinfo
template:
metadata:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9797"
labels:
app: podinfo
spec:
containers:
- name: podinfod
image: ghcr.io/stefanprodan/podinfo:6.0.10
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 9898
protocol: TCP
- name: http-metrics
containerPort: 9797
protocol: TCP
- name: grpc
containerPort: 9999
protocol: TCP
command:
- ./podinfo
- --port=9898
- --port-metrics=9797
- --grpc-port=9999
- --grpc-service-name=podinfo
- --level=info
- --random-delay=false
- --random-error=false
env:
- name: PODINFO_UI_COLOR
value: "#34577c"
livenessProbe:
exec:
command:
- podcli
- check
- http
- localhost:9898/healthz
initialDelaySeconds: 5
timeoutSeconds: 5
readinessProbe:
exec:
command:
- podcli
- check
- http
- localhost:9898/readyz
initialDelaySeconds: 5
timeoutSeconds: 5
resources:
limits:
cpu: 2000m
memory: 512Mi
requests:
cpu: 100m
memory: 64Mi

View File

@@ -0,0 +1,11 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./deployment.yaml
generatorOptions:
labels:
kustomize.toolkit.fluxcd.io/substitute: disabled
configMapGenerator:
- name: flux-grafana-dashboards
files:
- cluster.json

View File

@@ -1,5 +1,5 @@
--- ---
apiVersion: source.toolkit.fluxcd.io/v1beta1 apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: Bucket kind: Bucket
metadata: metadata:
name: flux-system name: flux-system

View File

@@ -1,5 +1,5 @@
--- ---
apiVersion: source.toolkit.fluxcd.io/v1beta1 apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: GitRepository kind: GitRepository
metadata: metadata:
name: flux-system name: flux-system

View File

@@ -1,5 +1,5 @@
--- ---
apiVersion: source.toolkit.fluxcd.io/v1beta1 apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository kind: HelmRepository
metadata: metadata:
name: flux-system name: flux-system

View File

@@ -1,2 +1,2 @@
NAME READY MESSAGE REVISION SUSPENDED NAME REVISION SUSPENDED READY MESSAGE
thrfg True Release reconciliation succeeded 6.0.0 False thrfg 6.0.0 False True Release reconciliation succeeded

View File

@@ -1,2 +1,2 @@
NAME READY MESSAGE LATEST IMAGE NAME LATEST IMAGE READY MESSAGE
podinfo-regex True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to: 5.0.0 ghcr.io/stefanprodan/podinfo:5.0.0 podinfo-regex ghcr.io/stefanprodan/podinfo:5.0.0 True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to: 5.0.0

View File

@@ -1,2 +1,2 @@
NAME READY MESSAGE LATEST IMAGE NAME LATEST IMAGE READY MESSAGE
podinfo-semver True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to: 5.0.3 ghcr.io/stefanprodan/podinfo:5.0.3 podinfo-semver ghcr.io/stefanprodan/podinfo:5.0.3 True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to: 5.0.3

View File

@@ -1,2 +1,2 @@
NAME READY MESSAGE REVISION SUSPENDED NAME REVISION SUSPENDED READY MESSAGE
tkfg True Applied revision: 6.0.0/627d5c4 6.0.0/627d5c4 False tkfg 6.0.0/627d5c4 False True Applied revision: 6.0.0/627d5c4

View File

@@ -37,7 +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"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var traceCmd = &cobra.Command{ var traceCmd = &cobra.Command{
@@ -84,7 +84,7 @@ func traceCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -77,7 +77,7 @@ func treeKsCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -34,7 +34,7 @@ import (
"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"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
) )
var uninstallCmd = &cobra.Command{ var uninstallCmd = &cobra.Command{
@@ -82,7 +82,7 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel() defer cancel()
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -74,7 +74,7 @@ func versionCmdRun(cmd *cobra.Command, args []string) error {
info["flux"] = rootArgs.defaults.Version info["flux"] = rootArgs.defaults.Version
if !versionArgs.client { if !versionArgs.client {
kubeClient, err := utils.KubeClient(kubeconfigArgs) kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil { if err != nil {
return err return err
} }

109
go.mod
View File

@@ -3,49 +3,49 @@ module github.com/fluxcd/flux2
go 1.17 go 1.17
require ( require (
github.com/Masterminds/semver/v3 v3.1.0 github.com/Masterminds/semver/v3 v3.1.1
github.com/ProtonMail/go-crypto v0.0.0-20211221144345-a4f6767435ab github.com/ProtonMail/go-crypto v0.0.0-20220407094043-a94812496cf5
github.com/cyphar/filepath-securejoin v0.2.2 github.com/cyphar/filepath-securejoin v0.2.3
github.com/fluxcd/go-git-providers v0.5.4 github.com/fluxcd/go-git-providers v0.5.4
github.com/fluxcd/helm-controller/api v0.17.1 github.com/fluxcd/helm-controller/api v0.20.1
github.com/fluxcd/image-automation-controller/api v0.20.1 github.com/fluxcd/image-automation-controller/api v0.22.0
github.com/fluxcd/image-reflector-controller/api v0.16.0 github.com/fluxcd/image-reflector-controller/api v0.17.2
github.com/fluxcd/kustomize-controller/api v0.21.1 github.com/fluxcd/kustomize-controller/api v0.24.3
github.com/fluxcd/notification-controller/api v0.22.2 github.com/fluxcd/notification-controller/api v0.23.4
github.com/fluxcd/pkg/apis/meta v0.10.2 github.com/fluxcd/pkg/apis/meta v0.12.2
github.com/fluxcd/pkg/kustomize v0.0.2 github.com/fluxcd/pkg/kustomize v0.2.0
github.com/fluxcd/pkg/runtime v0.12.5 github.com/fluxcd/pkg/runtime v0.14.1
github.com/fluxcd/pkg/ssa v0.14.1 github.com/fluxcd/pkg/ssa v0.15.2
github.com/fluxcd/pkg/ssh v0.3.1 github.com/fluxcd/pkg/ssh v0.3.2
github.com/fluxcd/pkg/untar v0.0.5 github.com/fluxcd/pkg/untar v0.1.0
github.com/fluxcd/pkg/version v0.0.1 github.com/fluxcd/pkg/version v0.1.0
github.com/fluxcd/source-controller/api v0.21.2 github.com/fluxcd/source-controller/api v0.24.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.2 github.com/gonvenience/bunt v1.3.3
github.com/gonvenience/ytbx v1.4.2 github.com/gonvenience/ytbx v1.4.4
github.com/google/go-cmp v0.5.6 github.com/google/go-cmp v0.5.7
github.com/google/go-containerregistry v0.2.0 github.com/google/go-containerregistry v0.8.0
github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/go-multierror v1.1.1
github.com/homeport/dyff v1.4.6 github.com/homeport/dyff v1.5.2
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.4 github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.3.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-20211215153901-e495a2d5b3d3 golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 golang.org/x/term v0.0.0-20220411215600-e5f449aeb171
k8s.io/api v0.23.2 k8s.io/api v0.23.5
k8s.io/apiextensions-apiserver v0.23.2 k8s.io/apiextensions-apiserver v0.23.5
k8s.io/apimachinery v0.23.2 k8s.io/apimachinery v0.23.5
k8s.io/cli-runtime v0.23.2 k8s.io/cli-runtime v0.23.5
k8s.io/client-go v0.23.2 k8s.io/client-go v0.23.5
k8s.io/kubectl v0.23.2 k8s.io/kubectl v0.23.5
sigs.k8s.io/cli-utils v0.28.0 sigs.k8s.io/cli-utils v0.29.4
sigs.k8s.io/controller-runtime v0.11.1 sigs.k8s.io/controller-runtime v0.11.2
sigs.k8s.io/kustomize/api v0.11.2 sigs.k8s.io/kustomize/api v0.11.4
sigs.k8s.io/kustomize/kyaml v0.13.3 sigs.k8s.io/kustomize/kyaml v0.13.6
sigs.k8s.io/yaml v1.3.0 sigs.k8s.io/yaml v1.3.0
) )
@@ -58,12 +58,14 @@ require (
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 v0.4.1 // 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.4.16 // indirect github.com/Microsoft/go-winio v0.5.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // 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/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/cpuguy83/go-md2man/v2 v2.0.1 // indirect
@@ -74,8 +76,9 @@ require (
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.1 // indirect github.com/fluxcd/pkg/apis/kustomize v0.3.3 // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/fvbommel/sortorder v1.0.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
@@ -85,11 +88,12 @@ require (
github.com/go-openapi/jsonreference v0.19.5 // indirect github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect github.com/gogo/protobuf v1.3.2 // 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.7 // indirect github.com/gonvenience/neat v1.3.10 // indirect
github.com/gonvenience/term v1.0.1 // indirect github.com/gonvenience/term v1.0.2 // indirect
github.com/gonvenience/text v1.0.6 // indirect github.com/gonvenience/text v1.0.7 // indirect
github.com/gonvenience/wrap v1.1.0 // 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/go-github/v41 v41.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect github.com/google/go-querystring v1.1.0 // indirect
@@ -113,6 +117,7 @@ require (
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
github.com/mattn/go-runewidth v0.0.13 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect github.com/mitchellh/go-wordwrap v1.0.0 // indirect
@@ -122,42 +127,42 @@ require (
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/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/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.1 // 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.5.2 // 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.0 // indirect github.com/stretchr/testify v1.7.1 // indirect
github.com/texttheater/golang-levenshtein v1.0.1 // indirect github.com/texttheater/golang-levenshtein v1.0.1 // 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.54.3 // 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 v0.0.0-20181112141820-a009c3971eca // 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-20211216030914-fe4d6282115f // indirect golang.org/x/net v0.0.0-20220325170049-de3da57026de // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect golang.org/x/sys v0.0.0-20220325203850-36772127a21f // 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-20210723032227-1f47c861a9ac // 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.27.1 // 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.0-20210107192922-496545a6307b // indirect
k8s.io/component-base v0.23.2 // indirect k8s.io/component-base v0.23.5 // indirect
k8s.io/klog/v2 v2.30.0 // indirect k8s.io/klog/v2 v2.50.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20211208161948-7d6a63dca704 // 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-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
) )
// Fix for CVE-2020-29652: https://github.com/golang/crypto/commit/8b5274cf687fd9316b4108863654cc57385531e8
// Fix for CVE-2021-43565: https://github.com/golang/crypto/commit/5770296d904e90f15f38f77dfc2e43fdf5efc083
replace golang.org/x/crypto => golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3

740
go.sum

File diff suppressed because it is too large Load Diff

View File

@@ -24,6 +24,7 @@ import (
"strings" "strings"
"time" "time"
gogit "github.com/go-git/go-git/v5"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
@@ -35,6 +36,7 @@ import (
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
runclient "github.com/fluxcd/pkg/runtime/client"
"github.com/fluxcd/flux2/internal/bootstrap/git" "github.com/fluxcd/flux2/internal/bootstrap/git"
"github.com/fluxcd/flux2/internal/utils" "github.com/fluxcd/flux2/internal/utils"
@@ -58,7 +60,8 @@ type PlainGitBootstrapper struct {
gpgPassphrase string gpgPassphrase string
gpgKeyID string gpgKeyID string
restClientGetter genericclioptions.RESTClientGetter restClientGetter genericclioptions.RESTClientGetter
restClientOptions *runclient.Options
postGenerateSecret []PostGenerateSecretFunc postGenerateSecret []PostGenerateSecretFunc
@@ -167,12 +170,12 @@ func (b *PlainGitBootstrapper) ReconcileComponents(ctx context.Context, manifest
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) b.logger.Actionf("installing components in %q namespace", options.Namespace)
if _, err := utils.Apply(ctx, b.restClientGetter, 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, componentsYAML); err != nil { if _, err := utils.Apply(ctx, b.restClientGetter, b.restClientOptions, componentsYAML); err != nil {
return err return err
} }
} }
@@ -287,10 +290,28 @@ func (b *PlainGitBootstrapper) ReconcileSyncConfig(ctx context.Context, options
if err != nil && err != git.ErrNoStagedFiles { if err != nil && err != git.ErrNoStagedFiles {
return fmt.Errorf("failed to commit sync manifests: %w", err) return fmt.Errorf("failed to commit sync manifests: %w", err)
} }
if err == nil { if err == nil {
b.logger.Successf("committed sync manifests to %q (%q)", b.branch, commit) b.logger.Successf("committed sync manifests to %q (%q)", b.branch, commit)
b.logger.Actionf("pushing sync manifests to %q", b.url) b.logger.Actionf("pushing sync manifests to %q", b.url)
if err = b.git.Push(ctx, b.caBundle); err != nil { err = b.git.Push(ctx, b.caBundle)
if err != nil {
if strings.HasPrefix(err.Error(), gogit.ErrNonFastForwardUpdate.Error()) {
b.logger.Waitingf("git conflict detected, retrying with a fresh clone")
if err := os.RemoveAll(b.git.Path()); err != nil {
return fmt.Errorf("failed to remove tmp dir: %w", err)
}
if err := os.Mkdir(b.git.Path(), 0o700); err != nil {
return fmt.Errorf("failed to recreate tmp dir: %w", err)
}
if err = retry(1, 2*time.Second, func() (err error) {
_, err = b.git.Clone(ctx, b.url, b.branch, b.caBundle)
return
}); err != nil {
return fmt.Errorf("failed to clone repository: %w", err)
}
return b.ReconcileSyncConfig(ctx, options)
}
return fmt.Errorf("failed to push sync manifests: %w", err) return fmt.Errorf("failed to push sync manifests: %w", err)
} }
} else { } else {
@@ -299,7 +320,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, filepath.Join(b.git.Path(), kusManifests.Path)); err != nil { if _, err := utils.Apply(ctx, b.restClientGetter, b.restClientOptions, filepath.Join(b.git.Path(), kusManifests.Path)); err != nil {
return err return err
} }
@@ -332,7 +353,7 @@ func (b *PlainGitBootstrapper) ReportKustomizationHealth(ctx context.Context, op
} }
func (b *PlainGitBootstrapper) ReportComponentsHealth(ctx context.Context, install install.Options, timeout time.Duration) error { func (b *PlainGitBootstrapper) ReportComponentsHealth(ctx context.Context, install install.Options, timeout time.Duration) error {
cfg, err := utils.KubeConfig(b.restClientGetter) cfg, err := utils.KubeConfig(b.restClientGetter, b.restClientOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -17,9 +17,12 @@ limitations under the License.
package bootstrap package bootstrap
import ( import (
"k8s.io/cli-runtime/pkg/genericclioptions"
runclient "github.com/fluxcd/pkg/runtime/client"
"github.com/fluxcd/flux2/internal/bootstrap/git" "github.com/fluxcd/flux2/internal/bootstrap/git"
"github.com/fluxcd/flux2/pkg/log" "github.com/fluxcd/flux2/pkg/log"
"k8s.io/cli-runtime/pkg/genericclioptions"
) )
type Option interface { type Option interface {
@@ -91,18 +94,21 @@ func (o commitMessageAppendixOption) applyGitProvider(b *GitProviderBootstrapper
o.applyGit(b.PlainGitBootstrapper) o.applyGit(b.PlainGitBootstrapper)
} }
func WithKubeconfig(rcg genericclioptions.RESTClientGetter) Option { func WithKubeconfig(rcg genericclioptions.RESTClientGetter, opts *runclient.Options) Option {
return kubeconfigOption{ return kubeconfigOption{
rcg: rcg, rcg: rcg,
opts: opts,
} }
} }
type kubeconfigOption struct { type kubeconfigOption struct {
rcg genericclioptions.RESTClientGetter rcg genericclioptions.RESTClientGetter
opts *runclient.Options
} }
func (o kubeconfigOption) applyGit(b *PlainGitBootstrapper) { func (o kubeconfigOption) applyGit(b *PlainGitBootstrapper) {
b.restClientGetter = o.rcg b.restClientGetter = o.rcg
b.restClientOptions = o.opts
} }
func (o kubeconfigOption) applyGitProvider(b *GitProviderBootstrapper) { func (o kubeconfigOption) applyGitProvider(b *GitProviderBootstrapper) {

View File

@@ -21,24 +21,30 @@ import (
"context" "context"
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"os"
"sync" "sync"
"time" "time"
"github.com/fluxcd/flux2/internal/utils"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
"github.com/fluxcd/pkg/kustomize"
"github.com/theckman/yacspin" "github.com/theckman/yacspin"
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
k8syaml "k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"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/filesys"
"sigs.k8s.io/kustomize/kyaml/yaml" "sigs.k8s.io/kustomize/kyaml/yaml"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
"github.com/fluxcd/pkg/kustomize"
runclient "github.com/fluxcd/pkg/runtime/client"
"github.com/fluxcd/flux2/internal/utils"
) )
const ( const (
@@ -57,11 +63,12 @@ var defaultTimeout = 80 * time.Second
// It retrieves the kustomization object from the k8s cluster // It retrieves the kustomization object from the k8s cluster
// and overlays the manifests with the resources specified in the resourcesPath // and overlays the manifests with the resources specified in the resourcesPath
type Builder struct { type Builder struct {
client client.WithWatch client client.WithWatch
restMapper meta.RESTMapper restMapper meta.RESTMapper
name string name string
namespace string namespace string
resourcesPath string resourcesPath string
kustomizationFile string
// mu is used to synchronize access to the kustomization file // mu is used to synchronize access to the kustomization file
mu sync.Mutex mu sync.Mutex
action kustomize.Action action kustomize.Action
@@ -72,6 +79,13 @@ type Builder struct {
type BuilderOptionFunc func(b *Builder) error type BuilderOptionFunc func(b *Builder) error
func WithKustomizationFile(file string) BuilderOptionFunc {
return func(b *Builder) error {
b.kustomizationFile = file
return nil
}
}
func WithTimeout(timeout time.Duration) BuilderOptionFunc { func WithTimeout(timeout time.Duration) BuilderOptionFunc {
return func(b *Builder) error { return func(b *Builder) error {
b.timeout = timeout b.timeout = timeout
@@ -103,8 +117,8 @@ func WithProgressBar() BuilderOptionFunc {
// NewBuilder returns a new Builder // NewBuilder returns a new Builder
// to dp : create functional options // to dp : create functional options
func NewBuilder(rcg *genericclioptions.ConfigFlags, name, resources string, opts ...BuilderOptionFunc) (*Builder, error) { func NewBuilder(rcg *genericclioptions.ConfigFlags, clientOpts *runclient.Options, name, resources string, opts ...BuilderOptionFunc) (*Builder, error) {
kubeClient, err := utils.KubeClient(rcg) kubeClient, err := utils.KubeClient(rcg, clientOpts)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -173,9 +187,18 @@ func (b *Builder) build() (m resmap.ResMap, err error) {
defer cancel() defer cancel()
// Get the kustomization object // Get the kustomization object
k, err := b.getKustomization(ctx) k := &kustomizev1.Kustomization{}
if err != nil { if b.kustomizationFile != "" {
return k, err = b.unMarshallKustomization()
if err != nil {
return
}
} else {
k, err = b.getKustomization(ctx)
if err != nil {
err = fmt.Errorf("failed to get kustomization object: %w", err)
return
}
} }
// store the kustomization object // store the kustomization object
@@ -222,6 +245,21 @@ func (b *Builder) build() (m resmap.ResMap, err error) {
} }
func (b *Builder) unMarshallKustomization() (*kustomizev1.Kustomization, error) {
data, err := os.ReadFile(b.kustomizationFile)
if err != nil {
return nil, fmt.Errorf("failed to read kustomization file %s: %w", b.kustomizationFile, err)
}
k := &kustomizev1.Kustomization{}
decoder := k8syaml.NewYAMLOrJSONDecoder(bytes.NewBuffer(data), len(data))
err = decoder.Decode(k)
if err != nil {
return nil, fmt.Errorf("failed to unmarshall kustomization file %s: %w", b.kustomizationFile, err)
}
return k, nil
}
func (b *Builder) generate(kustomization kustomizev1.Kustomization, dirPath string) (kustomize.Action, error) { func (b *Builder) generate(kustomization kustomizev1.Kustomization, dirPath string) (kustomize.Action, error) {
data, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&kustomization) data, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&kustomization)
if err != nil { if err != nil {
@@ -306,7 +344,11 @@ func maskSopsData(res *resource.Resource) error {
res.PipeE(yaml.FieldClearer{Name: "sops"}) res.PipeE(yaml.FieldClearer{Name: "sops"})
secretType, err := res.GetFieldValue(typeField) secretType, err := res.GetFieldValue(typeField)
if err != nil { // If the intented type is Opaque, then it can be omitted from the manifest, since it's the default
// Ref: https://kubernetes.io/docs/concepts/configuration/secret/#opaque-secrets
if errors.As(err, &yaml.NoFieldError{}) {
secretType = "Opaque"
} else if err != nil {
return fmt.Errorf("failed to mask secret %s sops data: %w", res.GetName(), err) return fmt.Errorf("failed to mask secret %s sops data: %w", res.GetName(), err)
} }

View File

@@ -27,6 +27,7 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/fluxcd/flux2/pkg/printers"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
"github.com/fluxcd/pkg/ssa" "github.com/fluxcd/pkg/ssa"
"github.com/gonvenience/bunt" "github.com/gonvenience/bunt"
@@ -112,7 +113,7 @@ func (b *Builder) Diff() (string, bool, error) {
} }
if change.Action == string(ssa.ConfiguredAction) { if change.Action == string(ssa.ConfiguredAction) {
output.WriteString(writeString(fmt.Sprintf("► %s drifted\n", change.Subject), bunt.WhiteSmoke)) output.WriteString(bunt.Sprint(fmt.Sprintf("► %s drifted\n", change.Subject)))
liveFile, mergedFile, tmpDir, err := writeYamls(liveObject, mergedObject) liveFile, mergedFile, tmpDir, err := writeYamls(liveObject, mergedObject)
if err != nil { if err != nil {
return "", createdOrDrifted, err return "", createdOrDrifted, err
@@ -204,14 +205,9 @@ func diff(liveFile, mergedFile string, output io.Writer) error {
return fmt.Errorf("failed to compare input files: %w", err) return fmt.Errorf("failed to compare input files: %w", err)
} }
reportWriter := &dyff.HumanReport{ printer := printers.NewDyffPrinter()
Report: report,
OmitHeader: true,
}
if err := reportWriter.WriteReport(output); err != nil { printer.Print(output, report)
return fmt.Errorf("failed to print report: %w", err)
}
return nil return nil
} }

Some files were not shown because too many files have changed in this diff Show More