1
0
mirror of synced 2026-03-01 19:26:55 +00:00

Compare commits

...

96 Commits

Author SHA1 Message Date
Stefan Prodan
10cc6d7e08 Merge pull request #124 from fluxcd/helm-beta.4
Update helm-controller to v0.0.1-beta.4
2020-07-22 16:49:11 +03:00
stefanprodan
83c236c829 Update helm-controller to v0.0.1-beta.4 2020-07-22 16:36:59 +03:00
Stefan Prodan
b6ab37691f Merge pull request #120 from fluxcd/sealed-secrets
Add sealed secrets guide
2020-07-22 15:45:00 +03:00
stefanprodan
c85af78025 Add sealed secrets guide 2020-07-22 14:43:55 +03:00
Stefan Prodan
2c2fc6dd97 Merge pull request #123 from fluxcd/optional-notifications
Make notification component optional
2020-07-22 14:41:40 +03:00
stefanprodan
3620b76139 Make notification component optional 2020-07-22 14:30:39 +03:00
Stefan Prodan
ca5732e586 Merge pull request #121 from fluxcd/helm-beta.3
Update helm-controller to v0.0.1-beta.3
2020-07-21 20:31:31 +03:00
stefanprodan
2463d72f3b Update helm-controller to v0.0.1-beta.3 2020-07-21 20:18:23 +03:00
stefanprodan
d6f7474200 Add get/export HelmRelease e2e tests 2020-07-21 14:25:31 +03:00
stefanprodan
0b2bc7ab3f Implement get/export HelmRelease for Helm releases 2020-07-21 14:22:20 +03:00
Stefan Prodan
0a4fac61d4 Merge pull request #118 from fluxcd/hr-cmd
Implement create/delete for Helm releases
2020-07-21 14:10:45 +03:00
stefanprodan
797aec5528 Add create/delete HelmRelease e2e tests 2020-07-21 14:02:29 +03:00
stefanprodan
5f0b95dc59 Implement create/delete for Helm releases 2020-07-21 12:20:41 +03:00
Stefan Prodan
b384c5f14c Merge pull request #116 from fluxcd/helm-repo-cmd
Implement Helm repository commands
2020-07-21 11:09:31 +03:00
stefanprodan
5254dca9d9 Add Helm repository cmd docs 2020-07-21 10:42:05 +03:00
stefanprodan
8534ccbf37 Implement Helm repository commands 2020-07-21 10:39:17 +03:00
stefanprodan
9af874d810 Add examples to all tk commands 2020-07-21 10:38:44 +03:00
Stefan Prodan
4e3dee15ce Merge pull request #114 from fluxcd/fix-kustomize-cmd
Rename kustomization arg from validate to validation
2020-07-20 15:30:00 +03:00
stefanprodan
aaad618e20 Rename kustomization arg from validate to validation
Fix `tk create kustomization` command args inconsistency with the Kustomize API
2020-07-20 15:10:33 +03:00
Stefan Prodan
10bb50bd82 Merge pull request #113 from fluxcd/crd-v1
Drop support for Kubernetes <1.16
2020-07-20 14:56:45 +03:00
stefanprodan
6d2ff6e019 Update controllers and APIs 2020-07-20 14:41:23 +03:00
stefanprodan
670070a879 Drop support for Kubernetes <1.16 2020-07-20 14:37:50 +03:00
Stefan Prodan
dcec8007d4 Merge pull request #88 from luxas/go_git_provider
Add go-git-providers proposal
2020-07-20 11:53:36 +03:00
Michael Bridgen
3abf4a49cd Merge pull request #108 from fluxcd/link-to-image-update-discussion
Link to image update discussion
2020-07-17 13:03:03 +01:00
Michael Bridgen
38825bf96a Cosmetic: indent sublist 2020-07-17 12:55:24 +01:00
Michael Bridgen
faa69da28d Link to image update discussion
.. and rearrange the line items a little. I removed the mention of source-controller because it doesn't feature in the design as drafted.
2020-07-17 12:08:42 +01:00
Hidde Beydals
5cf524e2fd Merge pull request #106 from fluxcd/docs/update-helm-roadmap
Make nested list work correctly in roadmap
2020-07-17 12:45:44 +02:00
Hidde Beydals
88802a44e7 Make nested list work correctly in roadmap 2020-07-17 12:34:16 +02:00
Stefan Prodan
94498d862d Merge pull request #105 from fluxcd/static-manifests
Use semver manifests as kustomize base
2020-07-17 13:27:51 +03:00
Hidde Beydals
9418b24e8f Merge pull request #104 from fluxcd/docs/update-helm-roadmap
Update "Helm Operator v2" roadmap
2020-07-17 12:11:57 +02:00
stefanprodan
b92cbcd7e7 Use semver manifests as kustomize base
Instead of cloning the components repositories to download the base manifests, we build them in CI at release time and download them in tk install/bootstrap based on the provided semver. This speeds up the manifests generation from minutes to milliseconds.
2020-07-17 13:10:19 +03:00
Hidde Beydals
9ef2ff92df Update "Helm Operator v2" roadmap 2020-07-17 12:04:09 +02:00
stefanprodan
422724bd2d Publish manifests as release assets 2020-07-17 12:00:15 +03:00
Stefan Prodan
6cb7897f25 Merge pull request #99 from fluxcd/export-install-manifests
Add export option to tk install
2020-07-16 16:07:13 +03:00
stefanprodan
499ba15004 Add export option to tk install 2020-07-16 15:56:05 +03:00
Stefan Prodan
b04abe989e Merge pull request #97 from fluxcd/helm-webhooks
Add webhook receivers section to Helm guide
2020-07-16 12:46:49 +03:00
stefanprodan
ea576179f9 Add webhook receivers section to Helm guide 2020-07-16 12:39:53 +03:00
Stefan Prodan
116d53a978 Merge pull request #95 from fluxcd/docs/helm-controller-notifications
Document helm-controller notifications in guide
2020-07-16 11:56:15 +03:00
Stefan Prodan
32adbf2ec8 Merge pull request #96 from fluxcd/prep-release-v0.0.5
Update controllers and go modules
2020-07-16 11:39:36 +03:00
stefanprodan
c664484fda Update controllers and go modules
- update source-controller to v0.0.5
- update kustomize-controller to v0.0.4
- update notification-controller to v0.0.4
- update helm-controller to v0.0.1-alpha.2
2020-07-16 11:30:45 +03:00
Hidde Beydals
06906eba4c Document helm-controller notifications in guide 2020-07-16 09:50:59 +02:00
Hidde Beydals
d387ebf32d Merge pull request #92 from fluxcd/docs/helmrelease-guide
Add "Manging Helm releases" guide to menu
2020-07-14 16:12:00 +02:00
Hidde Beydals
f75556f33c Add "Manging Helm releases" guide to menu 2020-07-14 16:05:48 +02:00
Hidde Beydals
2cf09e4de6 Merge pull request #86 from fluxcd/docs/helmrelease-guide 2020-07-14 16:02:50 +02:00
Hidde Beydals
a5a3a9c586 Make existence of HelmChart visible 2020-07-14 15:55:23 +02:00
Hidde Beydals
746dfbd955 Managing Helm releases guide 2020-07-14 15:55:19 +02:00
Lucas Käldström
b1993d2fb7 Add Reconcile methods and TeamAccess struct. Mention ErrNotFound and ErrAlreadyExists. Add List() to TeamAccess. Rename GetTitle() to GetName() 2020-07-14 16:39:31 +03:00
Lucas Käldström
e8096dec88 Rename the Repository Teams and Credential clients 2020-07-14 16:39:25 +03:00
Lucas Käldström
39eee51ec8 Add extra goals of best practices 2020-07-14 16:39:14 +03:00
Lucas Käldström
7bb3a10795 Remove the URLParser, and Provider from the *Ref types 2020-07-14 16:39:02 +03:00
Stefan Prodan
a8cbe4b05f Merge pull request #91 from fluxcd/notification-v0.0.3
Update notification-controller to v0.0.3
2020-07-14 15:36:02 +03:00
stefanprodan
fe86da0cde Update notification-controller to v0.0.3 2020-07-14 15:26:10 +03:00
Stefan Prodan
4c86a2c191 Merge pull request #90 from fluxcd/helm-suspend
Add helm suspend/resume commands
2020-07-14 15:05:21 +03:00
stefanprodan
8dc5db17ac Add helm suspend/resume commands 2020-07-14 14:00:59 +03:00
Stefan Prodan
549c3a190e Merge pull request #87 from fluxcd/helm-reconcile
Add reconcile helm commands
2020-07-14 13:40:41 +03:00
stefanprodan
7a68c4ccf3 Add reconcile helm commands 2020-07-14 13:34:00 +03:00
Lucas Käldström
4c684df653 Add go-git-providers proposal 2020-07-14 12:49:29 +03:00
Stefan Prodan
bf8831b833 Merge pull request #85 from fluxcd/reconcile-cmd
Rename sync cmd to reconcile
2020-07-14 11:58:38 +03:00
stefanprodan
394227571f Rename sync cmd to reconcile 2020-07-14 11:45:15 +03:00
Stefan Prodan
bf67577073 Merge pull request #84 from fluxcd/default-components
Refactor install defaults
2020-07-14 11:19:31 +03:00
stefanprodan
e180611024 Refactor defaults
- add dedicated components flag for bootstrap/install/check
- extract defaults to vars
- update CLI docs
2020-07-14 11:02:37 +03:00
Hidde Beydals
43cfc55368 Merge pull request #83 from fluxcd/build/hc-api-spec
build: use correct v2alpha1 HelmRelease spec URL
2020-07-14 09:29:28 +02:00
Hidde Beydals
c03b7ea15d build: use correct v2alpha1 HelmRelease spec URL 2020-07-14 09:22:51 +02:00
Stefan Prodan
ddfedfb590 Merge pull request #82 from fluxcd/helm-controller
Add helm-controller installer and docs
2020-07-14 10:12:09 +03:00
stefanprodan
24418370f1 Add helm-controller docs 2020-07-14 09:33:52 +03:00
stefanprodan
02521b6964 Add helm-controller to installer 2020-07-13 18:44:54 +03:00
Stefan Prodan
16f693148b Merge pull request #81 from fluxcd/docs-source-watcher
Add source watcher dev guide
2020-07-09 09:17:51 +03:00
stefanprodan
0bf46cb63f Add source watcher dev guide 2020-07-08 17:23:09 +03:00
Stefan Prodan
2e38855396 Merge pull request #80 from fluxcd/docs-webhook-receivers
Add webhook receivers guide to docs
2020-07-07 13:20:38 +03:00
stefanprodan
97592a1387 Add webhook receivers guide to docs 2020-07-07 13:15:24 +03:00
Stefan Prodan
c61bf76c80 Merge pull request #79 from fluxcd/notification-controller-v0.0.1
Update notification controller to v0.0.1
2020-07-07 10:13:34 +03:00
stefanprodan
e95b137011 Mark events forwarding task as completed 2020-07-07 10:04:42 +03:00
stefanprodan
ad655183e0 Update notification-controller to v0.0.1 2020-07-07 10:03:34 +03:00
stefanprodan
789fd34c4a Update fluxcd/pkg to v0.0.2 2020-07-07 10:02:54 +03:00
Daniel Holbach
87bbbaa475 Merge pull request #77 from dholbach/understanding-toolkit
explain a bit more about Flux Toolkit
2020-07-03 14:18:06 +02:00
Daniel Holbach
a4ca813cf5 add symlink and make it work 2020-07-03 14:09:30 +02:00
Daniel Holbach
e8eef73212 explain a bit more about Flux Toolkit 2020-07-03 11:40:59 +02:00
Stefan Prodan
512d4a43cb Merge pull request #76 from fluxcd/source-events
Enable notifications for source events
2020-07-03 11:29:41 +03:00
stefanprodan
b9f7b1d175 Enable notifications for source events 2020-07-03 11:15:34 +03:00
Stefan Prodan
b7727e2659 Merge pull request #74 from fluxcd/docs-notifications
Add notifications guide
2020-07-02 15:13:03 +03:00
stefanprodan
229d1d8c6e Add notifications guide 2020-07-02 14:51:28 +03:00
Stefan Prodan
c0b18f85aa Merge pull request #73 from fluxcd/notification-controller
Add notification component
2020-07-02 13:43:15 +03:00
stefanprodan
b11b9588f8 Update tk docs 2020-07-02 13:35:30 +03:00
stefanprodan
633d028841 Update kustomize controller and enable events 2020-07-02 13:14:56 +03:00
stefanprodan
a744b304a0 Add notification controller to docs 2020-07-02 12:58:01 +03:00
stefanprodan
e594350307 Add notification controller to tk components 2020-07-02 12:52:55 +03:00
Stefan Prodan
ecf7a1eac1 Merge pull request #70 from fluxcd/fluxcd-pkg
Migrate to fluxcd/pkg
2020-06-30 17:32:38 +03:00
stefanprodan
4621afcb31 Migrate to fluxcd/pkg 2020-06-30 17:11:04 +03:00
Stefan Prodan
006c949941 Merge pull request #69 from fluxcd/docs-meta
Add metadata to docs website
2020-06-26 16:53:09 +03:00
stefanprodan
72e06ab337 Add metadata to docs website 2020-06-26 16:41:04 +03:00
Hidde Beydals
f4b2a32a23 Merge pull request #67 from fluxcd/log-interface
Create logger interface
2020-06-25 18:20:17 +02:00
Hidde Beydals
329e21fd78 Create logger interface 2020-06-25 18:05:15 +02:00
Hidde Beydals
5499d15402 Merge pull request #68 from fluxcd/sort-ecdsa-curves
Sort supported ECDSA curves names
2020-06-25 18:03:29 +02:00
Hidde Beydals
d7f8a05612 Sort supported ECDSA curves names
To ensure options are always printed in the same order.
2020-06-25 17:53:41 +02:00
Hidde Beydals
1f99a75049 Merge pull request #66 from fluxcd/docs/cli-examples
Improve CLI command descriptions
2020-06-25 15:58:33 +02:00
Hidde Beydals
21fd436621 Add descriptions to all CLI commands 2020-06-25 15:49:31 +02:00
141 changed files with 4877 additions and 2453 deletions

View File

@@ -14,12 +14,29 @@ jobs:
uses: actions/checkout@v1
- name: Copy assets
run: |
cp install/tk.sh docs/install.sh
# source-controller CRDs
curl https://raw.githubusercontent.com/fluxcd/source-controller/master/docs/api/source.md > docs/components/source/api.md
curl https://raw.githubusercontent.com/fluxcd/source-controller/master/docs/spec/v1alpha1/gitrepositories.md > docs/components/source/gitrepositories.md
curl https://raw.githubusercontent.com/fluxcd/source-controller/master/docs/spec/v1alpha1/helmrepositories.md > docs/components/source/helmrepositories.md
curl https://raw.githubusercontent.com/fluxcd/source-controller/master/docs/spec/v1alpha1/helmcharts.md > docs/components/source/helmcharts.md
# kustomize-controller CRDs
curl https://raw.githubusercontent.com/fluxcd/kustomize-controller/master/docs/api/kustomize.md > docs/components/kustomize/api.md
curl https://raw.githubusercontent.com/fluxcd/kustomize-controller/master/docs/spec/v1alpha1/kustomization.md > docs/components/kustomize/kustomization.md
# helm-controller CRDs
curl https://raw.githubusercontent.com/fluxcd/helm-controller/master/docs/api/helmrelease.md > docs/components/helm/api.md
curl https://raw.githubusercontent.com/fluxcd/helm-controller/master/docs/spec/v2alpha1/helmreleases.md > docs/components/helm/helmreleases.md
# notification-controller CRDs
curl https://raw.githubusercontent.com/fluxcd/notification-controller/master/docs/api/notification.md > docs/components/notification/api.md
curl https://raw.githubusercontent.com/fluxcd/notification-controller/master/docs/spec/v1alpha1/event.md > docs/components/notification/event.md
curl https://raw.githubusercontent.com/fluxcd/notification-controller/master/docs/spec/v1alpha1/alert.md > docs/components/notification/alert.md
curl https://raw.githubusercontent.com/fluxcd/notification-controller/master/docs/spec/v1alpha1/provider.md > docs/components/notification/provider.md
curl https://raw.githubusercontent.com/fluxcd/notification-controller/master/docs/spec/v1alpha1/receiver.md > docs/components/notification/receiver.md
# install script
cp install/tk.sh docs/install.sh
- name: Deploy docs
uses: mhausenblas/mkdocs-deploy-gh-pages@master
env:

View File

@@ -24,13 +24,15 @@ jobs:
with:
go-version: 1.14.x
- name: Setup Kubernetes
uses: engineerd/setup-kind@v0.3.0
uses: engineerd/setup-kind@v0.4.0
with:
image: kindest/node:v1.16.9
- name: Run test
run: make test
- name: Check if working tree is dirty
run: |
if [[ $(git diff --stat) != '' ]]; then
git diff --stat
git diff
echo 'run make test and commit changes'
exit 1
fi
@@ -41,7 +43,7 @@ jobs:
./bin/tk check --pre
- name: tk install --version
run: |
./bin/tk install --version=master --namespace=test --verbose
./bin/tk install --version=master --namespace=test --verbose --components="source-controller,kustomize-controller"
- name: tk uninstall
run: |
./bin/tk uninstall --namespace=test --crds --silent
@@ -63,13 +65,13 @@ jobs:
--path="./deploy/overlays/dev" \
--prune=true \
--interval=5m \
--validate=client \
--validation=client \
--health-check="Deployment/frontend.dev" \
--health-check="Deployment/backend.dev" \
--health-check-timeout=3m
- name: tk sync kustomization --with-source
run: |
./bin/tk sync kustomization podinfo --with-source
./bin/tk reconcile kustomization podinfo --with-source
- name: tk get kustomizations
run: |
./bin/tk get kustomizations
@@ -89,6 +91,29 @@ jobs:
- name: tk delete source git
run: |
./bin/tk delete source git podinfo --silent
- name: tk create source helm
run: |
./bin/tk create source helm podinfo \
--url https://stefanprodan.github.io/podinfo
- name: tk create helmrelease
run: |
./bin/tk create hr podinfo \
--target-namespace=default \
--source=podinfo \
--chart-name=podinfo \
--chart-version=">4.0.0 <5.0.0"
- name: tk get helmreleases
run: |
./bin/tk get helmreleases
- name: tk export helmrelease
run: |
./bin/tk export hr --all
- name: tk delete helmrelease
run: |
./bin/tk delete hr podinfo --silent
- name: tk delete source helm
run: |
./bin/tk delete source helm podinfo --silent
- name: tk check
run: |
./bin/tk check

View File

@@ -14,7 +14,7 @@ jobs:
- name: Unshallow
run: git fetch --prune --unshallow
- name: Setup Go
uses: actions/setup-go@v2-beta
uses: actions/setup-go@v2
with:
go-version: 1.14.x
- name: Download release notes utility
@@ -25,10 +25,60 @@ jobs:
run: |
echo 'CHANGELOG' > /tmp/release.txt
github-release-notes -org fluxcd -repo toolkit -since-latest-release >> /tmp/release.txt
- name: Setup Kustomize
uses: ./.github/actions/kustomize
- name: Generate manifests tarball
run: |
mkdir -p ./output
files=""
# build controllers
for controller in ./manifests/bases/*/; do
output_path="./output/$(basename $controller).yaml"
echo "building $controller to $output_path"
kustomize build $controller > $output_path
files+=" $(basename $output_path)"
done
# build rbac
rbac_path="./manifests/rbac"
rbac_output_path="./output/rbac.yaml"
echo "building $rbac_path to $rbac_output_path"
kustomize build $rbac_path > $rbac_output_path
files+=" $(basename $rbac_output_path)"
# build policies
policies_path="./manifests/policies"
policies_output_path="./output/policies.yaml"
echo "building $policies_path to $policies_output_path"
kustomize build $policies_path > $policies_output_path
files+=" $(basename $policies_output_path)"
# create tarball
cd ./output && tar -cvzf manifests.tar.gz $files
- name: Create release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
- name: Upload artifacts
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./output/manifests.tar.gz
asset_name: manifests.tar.gz
asset_content_type: application/gzip
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --release-notes=/tmp/release.txt
args: release --release-notes=/tmp/release.txt --skip-validate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

3
.gitignore vendored
View File

@@ -13,4 +13,5 @@
# Dependency directories (remove the comment below to include it)
# vendor/
bin/
bin/
output/

View File

@@ -1,8 +1,8 @@
# Contributing
FluxCD toolkit is [Apache 2.0 licensed](LICENSE) and accepts contributions
via GitHub pull requests. This document outlines some of the conventions on
to make it easier to get your contribution accepted.
The GitOps Toolkit is [Apache 2.0 licensed](https://github.com/fluxcd/toolkit/blob/master/LICENSE)
and accepts contributions via GitHub pull requests. This document outlines
some of the conventions on to make it easier to get your contribution accepted.
We gratefully welcome improvements to issues and documentation as well as to
code.
@@ -14,13 +14,13 @@ Origin (DCO). This document was created by the Linux Kernel community and is a
simple statement that you, as a contributor, have the legal right to make the
contribution. No action from you is required, but it's a good idea to see the
[DCO](DCO) file for details before you start contributing code to FluxCD
toolkit.
organization.
## Communications
The project uses Slack: To join the conversation, simply join the
[CNCF](https://slack.cncf.io/) Slack workspace and use the
[#flux](https://cloud-native.slack.com/messages/flux/) channel.
[#flux-dev](https://cloud-native.slack.com/messages/flux-dev/) channel.
The developers use a mailing list to discuss development as well.
Simply subscribe to [flux-dev on cncf.io](https://lists.cncf.io/g/cncf-flux-dev)
@@ -57,7 +57,7 @@ get asked to resubmit the PR or divide the changes into more than one PR.
### Format of the Commit Message
For Source Controller we prefer the following rules for good commit messages:
For the GitOps Toolkit controllers we prefer the following rules for good commit messages:
- Limit the subject to 50 characters and write as the continuation
of the sentence "If applied, this commit will ..."
@@ -66,3 +66,16 @@ For Source Controller we prefer the following rules for good commit messages:
The [following article](https://chris.beams.io/posts/git-commit/#seven-rules)
has some more helpful advice on documenting your work.
## Understanding the GitOps Toolkit
If you are entirely new to the GitOps Toolkit,
you might want to take a look at the [introductory talk and demo](https://www.youtube.com/watch?v=qQBtSkgl7tI).
This project is composed of:
- [/f/toolkit](https://github.com/fluxcd/toolkit): The GitOps Toolkit CLI
- [/f/source-manager](https://github.com/fluxcd/source-controller): Kubernetes operator for managing sources
- [/f/kustomize-controller](https://github.com/fluxcd/kustomize-controller): Kubernetes operator for building GitOps pipelines with Kustomize
- [/f/helm-controller](https://github.com/fluxcd/helm-controller): Kubernetes operator for building GitOps pipelines with Helm
- [/f/notification-controller](https://github.com/fluxcd/notification-controller): Kubernetes operator for handling inbound and outbound events

View File

@@ -1,4 +1,4 @@
# toolkit
# GitOps Toolkit
[![e2e](https://github.com/fluxcd/toolkit/workflows/e2e/badge.svg)](https://github.com/fluxcd/toolkit/actions)
[![report](https://goreportcard.com/badge/github.com/fluxcd/toolkit)](https://goreportcard.com/report/github.com/fluxcd/toolkit)

View File

@@ -40,11 +40,13 @@ import (
var bootstrapCmd = &cobra.Command{
Use: "bootstrap",
Short: "Bootstrap commands",
Short: "Bootstrap toolkit components",
Long: "The bootstrap sub-commands bootstrap the toolkit components on the targeted Git provider.",
}
var (
bootstrapVersion string
bootstrapVersion string
bootstrapComponents []string
)
const (
@@ -55,7 +57,10 @@ const (
)
func init() {
bootstrapCmd.PersistentFlags().StringVar(&bootstrapVersion, "version", "master", "toolkit tag or branch")
bootstrapCmd.PersistentFlags().StringVarP(&bootstrapVersion, "version", "v", defaultVersion,
"toolkit version")
bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapComponents, "components", defaultComponents,
"list of components, accepts comma-separated values")
rootCmd.AddCommand(bootstrapCmd)
}
@@ -68,7 +73,7 @@ func generateInstallManifests(targetPath, namespace, tmpDir string) (string, err
return "", fmt.Errorf("generating manifests failed: %w", err)
}
if err := genInstallManifests(bootstrapVersion, namespace, components, tkDir); err != nil {
if err := genInstallManifests(bootstrapVersion, namespace, bootstrapComponents, tkDir); err != nil {
return "", fmt.Errorf("generating manifests failed: %w", err)
}
@@ -136,7 +141,6 @@ func generateSyncManifests(url, name, namespace, targetPath, tmpDir string, inte
}
gvk = kustomizev1.GroupVersion.WithKind("Kustomization")
emptyAPIGroup := ""
kustomization := kustomizev1.Kustomization{
TypeMeta: metav1.TypeMeta{
Kind: gvk.Kind,
@@ -152,10 +156,9 @@ func generateSyncManifests(url, name, namespace, targetPath, tmpDir string, inte
},
Path: fmt.Sprintf("./%s", strings.TrimPrefix(targetPath, "./")),
Prune: true,
SourceRef: corev1.TypedLocalObjectReference{
APIGroup: &emptyAPIGroup,
Kind: "GitRepository",
Name: name,
SourceRef: kustomizev1.CrossNamespaceObjectReference{
Kind: sourcev1.GitRepositoryKind,
Name: name,
},
},
}
@@ -178,7 +181,7 @@ func applySyncManifests(ctx context.Context, kubeClient client.Client, name, nam
return err
}
logWaiting("waiting for cluster sync")
logger.Waitingf("waiting for cluster sync")
if err := wait.PollImmediate(pollInterval, timeout,
isGitRepositoryReady(ctx, kubeClient, name, namespace)); err != nil {

View File

@@ -27,35 +27,34 @@ import (
"github.com/spf13/cobra"
"github.com/fluxcd/toolkit/pkg/git"
"github.com/fluxcd/pkg/git"
)
var bootstrapGitHubCmd = &cobra.Command{
Use: "github",
Short: "Bootstrap GitHub repository",
Long: `
The bootstrap command creates the GitHub repository if it doesn't exists and
Short: "Bootstrap toolkit components in a GitHub repository",
Long: `The bootstrap github command creates the GitHub repository if it doesn't exists and
commits the toolkit components manifests to the master branch.
Then it configure the target cluster to synchronize with the repository.
Then it configures the target cluster to synchronize with the repository.
If the toolkit components are present on the cluster,
the bootstrap command will perform an upgrade if needed.`,
Example: ` # Create a GitHub personal access token and export it as an env var
export GITHUB_TOKEN=<my-token>
# Run bootstrap for a private repo owned by a GitHub organization
bootstrap github --owner=<organization> --repository=<repo name>
tk bootstrap github --owner=<organization> --repository=<repo name>
# Run bootstrap for a private repo and assign organization teams to it
bootstrap github --owner=<organization> --repository=<repo name> --team=<team1 slug> --team=<team2 slug>
tk bootstrap github --owner=<organization> --repository=<repo name> --team=<team1 slug> --team=<team2 slug>
# Run bootstrap for a repository path
bootstrap github --owner=<organization> --repository=<repo name> --path=dev-cluster
tk bootstrap github --owner=<organization> --repository=<repo name> --path=dev-cluster
# Run bootstrap for a public repository on a personal account
bootstrap github --owner=<user> --repository=<repo name> --private=false --personal=true
tk bootstrap github --owner=<user> --repository=<repo name> --private=false --personal=true
# Run bootstrap for a private repo hosted on GitHub Enterprise
bootstrap github --owner=<organization> --repository=<repo name> --hostname=<domain>
tk bootstrap github --owner=<organization> --repository=<repo name> --hostname=<domain>
`,
RunE: bootstrapGitHubCmdRun,
}
@@ -119,13 +118,13 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
defer cancel()
// create GitHub repository if doesn't exists
logAction("connecting to %s", ghHostname)
logger.Actionf("connecting to %s", ghHostname)
changed, err := provider.CreateRepository(ctx, repository)
if err != nil {
return err
}
if changed {
logSuccess("repository created")
logger.Successf("repository created")
}
withErrors := false
@@ -133,10 +132,10 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
if !ghPersonal {
for _, team := range ghTeams {
if changed, err := provider.AddTeam(ctx, repository, team, ghDefaultPermission); err != nil {
logFailure(err.Error())
logger.Failuref(err.Error())
withErrors = true
} else if changed {
logSuccess("%s team access granted", team)
logger.Successf("%s team access granted", team)
}
}
}
@@ -145,10 +144,10 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
if err := repository.Checkout(ctx, bootstrapBranch, tmpDir); err != nil {
return err
}
logSuccess("repository cloned")
logger.Successf("repository cloned")
// generate install manifests
logGenerate("generating manifests")
logger.Generatef("generating manifests")
manifest, err := generateInstallManifests(ghPath, namespace, tmpDir)
if err != nil {
return err
@@ -165,9 +164,9 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
if err := repository.Push(ctx); err != nil {
return err
}
logSuccess("components manifests pushed")
logger.Successf("components manifests pushed")
} else {
logSuccess("components are up to date")
logger.Successf("components are up to date")
}
// determine if repo synchronization is working
@@ -175,16 +174,16 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
if isInstall {
// apply install manifests
logAction("installing components in %s namespace", namespace)
if err := applyInstallManifests(ctx, manifest, components); err != nil {
logger.Actionf("installing components in %s namespace", namespace)
if err := applyInstallManifests(ctx, manifest, bootstrapComponents); err != nil {
return err
}
logSuccess("install completed")
logger.Successf("install completed")
}
// setup SSH deploy key
if shouldCreateDeployKey(ctx, kubeClient, namespace) {
logAction("configuring deploy key")
logger.Actionf("configuring deploy key")
u, err := url.Parse(repository.GetSSH())
if err != nil {
return fmt.Errorf("git URL parse failed: %w", err)
@@ -203,14 +202,14 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
if changed, err := provider.AddDeployKey(ctx, repository, key, keyName); err != nil {
return err
} else if changed {
logSuccess("deploy key configured")
logger.Successf("deploy key configured")
}
}
// configure repo synchronization
if isInstall {
// generate source and kustomization manifests
logAction("generating sync manifests")
logger.Actionf("generating sync manifests")
if err := generateSyncManifests(repository.GetSSH(), namespace, namespace, ghPath, tmpDir, ghInterval); err != nil {
return err
}
@@ -222,11 +221,11 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
if err := repository.Push(ctx); err != nil {
return err
}
logSuccess("sync manifests pushed")
logger.Successf("sync manifests pushed")
}
// apply manifests and waiting for sync
logAction("applying sync manifests")
logger.Actionf("applying sync manifests")
if err := applySyncManifests(ctx, kubeClient, namespace, namespace, ghPath, tmpDir); err != nil {
return err
}
@@ -236,6 +235,6 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
return fmt.Errorf("bootstrap completed with errors")
}
logSuccess("bootstrap finished")
logger.Successf("bootstrap finished")
return nil
}

View File

@@ -27,32 +27,31 @@ import (
"github.com/spf13/cobra"
"github.com/fluxcd/toolkit/pkg/git"
"github.com/fluxcd/pkg/git"
)
var bootstrapGitLabCmd = &cobra.Command{
Use: "gitlab",
Short: "Bootstrap GitLab repository",
Long: `
The bootstrap command creates the GitLab repository if it doesn't exists and
Short: "Bootstrap toolkit components in a GitLab repository",
Long: `The bootstrap gitlab command creates the GitLab repository if it doesn't exists and
commits the toolkit components manifests to the master branch.
Then it configure the target cluster to synchronize with the repository.
Then it configures the target cluster to synchronize with the repository.
If the toolkit components are present on the cluster,
the bootstrap command will perform an upgrade if needed.`,
Example: ` # Create a GitLab API token and export it as an env var
export GITLAB_TOKEN=<my-token>
# Run bootstrap for a private repo owned by a GitLab group
bootstrap gitlab --owner=<group> --repository=<repo name>
tk bootstrap gitlab --owner=<group> --repository=<repo name>
# Run bootstrap for a repository path
bootstrap gitlab --owner=<group> --repository=<repo name> --path=dev-cluster
tk bootstrap gitlab --owner=<group> --repository=<repo name> --path=dev-cluster
# Run bootstrap for a public repository on a personal account
bootstrap gitlab --owner=<user> --repository=<repo name> --private=false --personal=true
tk bootstrap gitlab --owner=<user> --repository=<repo name> --private=false --personal=true
# Run bootstrap for a private repo hosted on a GitLab server
bootstrap gitlab --owner=<group> --repository=<repo name> --hostname=<domain>
tk bootstrap gitlab --owner=<group> --repository=<repo name> --hostname=<domain>
`,
RunE: bootstrapGitLabCmdRun,
}
@@ -110,23 +109,23 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
defer cancel()
// create GitLab project if doesn't exists
logAction("connecting to %s", glHostname)
logger.Actionf("connecting to %s", glHostname)
changed, err := provider.CreateRepository(ctx, repository)
if err != nil {
return err
}
if changed {
logSuccess("repository created")
logger.Successf("repository created")
}
// clone repository and checkout the master branch
if err := repository.Checkout(ctx, bootstrapBranch, tmpDir); err != nil {
return err
}
logSuccess("repository cloned")
logger.Successf("repository cloned")
// generate install manifests
logGenerate("generating manifests")
logger.Generatef("generating manifests")
manifest, err := generateInstallManifests(glPath, namespace, tmpDir)
if err != nil {
return err
@@ -143,9 +142,9 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
if err := repository.Push(ctx); err != nil {
return err
}
logSuccess("components manifests pushed")
logger.Successf("components manifests pushed")
} else {
logSuccess("components are up to date")
logger.Successf("components are up to date")
}
// determine if repo synchronization is working
@@ -153,16 +152,16 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
if isInstall {
// apply install manifests
logAction("installing components in %s namespace", namespace)
if err := applyInstallManifests(ctx, manifest, components); err != nil {
logger.Actionf("installing components in %s namespace", namespace)
if err := applyInstallManifests(ctx, manifest, bootstrapComponents); err != nil {
return err
}
logSuccess("install completed")
logger.Successf("install completed")
}
// setup SSH deploy key
if shouldCreateDeployKey(ctx, kubeClient, namespace) {
logAction("configuring deploy key")
logger.Actionf("configuring deploy key")
u, err := url.Parse(repository.GetSSH())
if err != nil {
return fmt.Errorf("git URL parse failed: %w", err)
@@ -181,14 +180,14 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
if changed, err := provider.AddDeployKey(ctx, repository, key, keyName); err != nil {
return err
} else if changed {
logSuccess("deploy key configured")
logger.Successf("deploy key configured")
}
}
// configure repo synchronization
if isInstall {
// generate source and kustomization manifests
logAction("generating sync manifests")
logger.Actionf("generating sync manifests")
if err := generateSyncManifests(repository.GetSSH(), namespace, namespace, glPath, tmpDir, glInterval); err != nil {
return err
}
@@ -200,16 +199,16 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
if err := repository.Push(ctx); err != nil {
return err
}
logSuccess("sync manifests pushed")
logger.Successf("sync manifests pushed")
}
// apply manifests and waiting for sync
logAction("applying sync manifests")
logger.Actionf("applying sync manifests")
if err := applySyncManifests(ctx, kubeClient, namespace, namespace, glPath, tmpDir); err != nil {
return err
}
}
logSuccess("bootstrap finished")
logger.Successf("bootstrap finished")
return nil
}

View File

@@ -32,26 +32,27 @@ import (
var checkCmd = &cobra.Command{
Use: "check",
Short: "Check requirements and installation",
Long: `
The check command will perform a series of checks to validate that
Long: `The check command will perform a series of checks to validate that
the local environment is configured correctly and if the installed components are healthy.`,
Example: ` # Run pre-installation checks
check --pre
tk check --pre
# Run installation checks
check
tk check
`,
RunE: runCheckCmd,
}
var (
checkPre bool
checkPre bool
checkComponents []string
)
func init() {
checkCmd.Flags().BoolVarP(&checkPre, "pre", "", false,
"only run pre-installation checks")
checkCmd.Flags().StringSliceVar(&checkComponents, "components", defaultComponents,
"list of components, accepts comma-separated values")
rootCmd.AddCommand(checkCmd)
}
@@ -59,14 +60,14 @@ func runCheckCmd(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
logAction("checking prerequisites")
logger.Actionf("checking prerequisites")
checkFailed := false
if !kubectlCheck(ctx, ">=1.18.0") {
checkFailed = true
}
if !kubernetesCheck(">=1.14.0") {
if !kubernetesCheck(">=1.16.0") {
checkFailed = true
}
@@ -74,83 +75,83 @@ func runCheckCmd(cmd *cobra.Command, args []string) error {
if checkFailed {
os.Exit(1)
}
logSuccess("prerequisites checks passed")
logger.Successf("prerequisites checks passed")
return nil
}
logAction("checking controllers")
logger.Actionf("checking controllers")
if !componentsCheck() {
checkFailed = true
}
if checkFailed {
os.Exit(1)
}
logSuccess("all checks passed")
logger.Successf("all checks passed")
return nil
}
func kubectlCheck(ctx context.Context, version string) bool {
_, err := exec.LookPath("kubectl")
if err != nil {
logFailure("kubectl not found")
logger.Failuref("kubectl not found")
return false
}
command := "kubectl version --client --short | awk '{ print $3 }'"
output, err := utils.execCommand(ctx, ModeCapture, command)
if err != nil {
logFailure("kubectl version can't be determined")
logger.Failuref("kubectl version can't be determined")
return false
}
v, err := semver.ParseTolerant(output)
if err != nil {
logFailure("kubectl version can't be parsed")
logger.Failuref("kubectl version can't be parsed")
return false
}
rng, _ := semver.ParseRange(version)
if !rng(v) {
logFailure("kubectl version must be %s", version)
logger.Failuref("kubectl version must be %s", version)
return false
}
logSuccess("kubectl %s %s", v.String(), version)
logger.Successf("kubectl %s %s", v.String(), version)
return true
}
func kubernetesCheck(version string) bool {
cfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
logFailure("Kubernetes client initialization failed: %s", err.Error())
logger.Failuref("Kubernetes client initialization failed: %s", err.Error())
return false
}
client, err := kubernetes.NewForConfig(cfg)
if err != nil {
logFailure("Kubernetes client initialization failed: %s", err.Error())
logger.Failuref("Kubernetes client initialization failed: %s", err.Error())
return false
}
ver, err := client.Discovery().ServerVersion()
if err != nil {
logFailure("Kubernetes API call failed: %s", err.Error())
logger.Failuref("Kubernetes API call failed: %s", err.Error())
return false
}
v, err := semver.ParseTolerant(ver.String())
if err != nil {
logFailure("Kubernetes version can't be determined")
logger.Failuref("Kubernetes version can't be determined")
return false
}
rng, _ := semver.ParseRange(version)
if !rng(v) {
logFailure("Kubernetes version must be %s", version)
logger.Failuref("Kubernetes version must be %s", version)
return false
}
logSuccess("Kubernetes %s %s", v.String(), version)
logger.Successf("Kubernetes %s %s", v.String(), version)
return true
}
@@ -159,14 +160,14 @@ func componentsCheck() bool {
defer cancel()
ok := true
for _, deployment := range components {
for _, deployment := range checkComponents {
command := fmt.Sprintf("kubectl -n %s rollout status deployment %s --timeout=%s",
namespace, deployment, timeout.String())
if output, err := utils.execCommand(ctx, ModeCapture, command); err != nil {
logFailure("%s: %s", deployment, strings.TrimSuffix(output, "\n"))
logger.Failuref("%s: %s", deployment, strings.TrimSuffix(output, "\n"))
ok = false
} else {
logSuccess("%s is healthy", deployment)
logger.Successf("%s is healthy", deployment)
}
}
return ok

View File

@@ -24,7 +24,8 @@ import (
var createCmd = &cobra.Command{
Use: "create",
Short: "Create commands",
Short: "Create or update sources and resources",
Long: "The create sub-commands generate sources and resources.",
}
var (
@@ -34,6 +35,6 @@ var (
func init() {
createCmd.PersistentFlags().DurationVarP(&interval, "interval", "", time.Minute, "source sync interval")
createCmd.PersistentFlags().BoolVar(&export, "export", false, "export in yaml format to stdout")
createCmd.PersistentFlags().BoolVar(&export, "export", false, "export in YAML format to stdout")
rootCmd.AddCommand(createCmd)
}

View File

@@ -0,0 +1,256 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"fmt"
"io/ioutil"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"
helmv2 "github.com/fluxcd/helm-controller/api/v2alpha1"
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
)
var createHelmReleaseCmd = &cobra.Command{
Use: "helmrelease [name]",
Aliases: []string{"hr"},
Short: "Create or update a HelmRelease resource",
Long: "The helmrelease create command generates a HelmRelease resource for a given HelmRepository source.",
Example: ` # Create a HelmRelease from a source
tk create hr podinfo \
--interval=10m \
--release-name=podinfo \
--target-namespace=default \
--source=podinfo \
--chart-name=podinfo \
--chart-version=">4.0.0"
# Create a HelmRelease with values for a local YAML file
tk create hr podinfo \
--target-namespace=default \
--source=podinfo \
--chart-name=podinfo \
--chart-version=4.0.5 \
--values=./my-values.yaml
# Create a HelmRelease definition on disk without applying it on the cluster
tk create hr podinfo \
--target-namespace=default \
--source=podinfo \
--chart-name=podinfo \
--chart-version=4.0.5 \
--values=./values.yaml \
--export > podinfo-release.yaml
`,
RunE: createHelmReleaseCmdRun,
}
var (
hrName string
hrSource string
hrDependsOn []string
hrChartName string
hrChartVersion string
hrTargetNamespace string
hrValuesFile string
)
func init() {
createHelmReleaseCmd.Flags().StringVar(&hrName, "release-name", "", "name used for the Helm release, defaults to a composition of '<target-namespace>-<hr-name>'")
createHelmReleaseCmd.Flags().StringVar(&hrSource, "source", "", "HelmRepository name")
createHelmReleaseCmd.Flags().StringVar(&hrChartName, "chart-name", "", "Helm chart name")
createHelmReleaseCmd.Flags().StringVar(&hrChartVersion, "chart-version", "", "Helm chart version, accepts semver range")
createHelmReleaseCmd.Flags().StringArrayVar(&hrDependsOn, "depends-on", nil, "HelmReleases that must be ready before this release can be installed")
createHelmReleaseCmd.Flags().StringVar(&hrTargetNamespace, "target-namespace", "", "namespace to install this release, defaults to the HelmRelease namespace")
createHelmReleaseCmd.Flags().StringVar(&hrValuesFile, "values", "", "local path to the values.yaml file")
createCmd.AddCommand(createHelmReleaseCmd)
}
func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("release name is required")
}
name := args[0]
if hrSource == "" {
return fmt.Errorf("source is required")
}
if hrChartName == "" {
return fmt.Errorf("chart name is required")
}
if hrChartVersion == "" {
return fmt.Errorf("chart version is required")
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
if !export {
logger.Generatef("generating release")
}
helmRelease := helmv2.HelmRelease{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: helmv2.HelmReleaseSpec{
ReleaseName: hrName,
DependsOn: hrDependsOn,
Interval: metav1.Duration{
Duration: interval,
},
TargetNamespace: hrTargetNamespace,
Chart: helmv2.HelmChartTemplate{
Name: hrChartName,
Version: hrChartVersion,
SourceRef: helmv2.CrossNamespaceObjectReference{
Kind: sourcev1.HelmRepositoryKind,
Name: hrSource,
},
},
Suspend: false,
},
}
if hrValuesFile != "" {
data, err := ioutil.ReadFile(hrValuesFile)
if err != nil {
return fmt.Errorf("reading values from %s failed: %w", hrValuesFile, err)
}
json, err := yaml.YAMLToJSON(data)
if err != nil {
return fmt.Errorf("converting values to JSON from %s failed: %w", hrValuesFile, err)
}
helmRelease.Spec.Values = apiextensionsv1.JSON{Raw: json}
}
if export {
return exportHelmRelease(helmRelease)
}
logger.Actionf("applying release")
if err := upsertHelmRelease(ctx, kubeClient, helmRelease); err != nil {
return err
}
logger.Waitingf("waiting for reconciliation")
chartName := fmt.Sprintf("%s-%s", namespace, name)
if err := wait.PollImmediate(pollInterval, timeout,
isHelmChartReady(ctx, kubeClient, chartName, namespace)); err != nil {
return err
}
if err := wait.PollImmediate(pollInterval, timeout,
isHelmReleaseReady(ctx, kubeClient, name, namespace)); err != nil {
return err
}
logger.Successf("release %s is ready", name)
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
err = kubeClient.Get(ctx, namespacedName, &helmRelease)
if err != nil {
return fmt.Errorf("release failed: %w", err)
}
if helmRelease.Status.LastAppliedRevision != "" {
logger.Successf("applied revision %s", helmRelease.Status.LastAppliedRevision)
} else {
return fmt.Errorf("reconciliation failed")
}
return nil
}
func upsertHelmRelease(ctx context.Context, kubeClient client.Client, helmRelease helmv2.HelmRelease) error {
namespacedName := types.NamespacedName{
Namespace: helmRelease.GetNamespace(),
Name: helmRelease.GetName(),
}
var existing helmv2.HelmRelease
err := kubeClient.Get(ctx, namespacedName, &existing)
if err != nil {
if errors.IsNotFound(err) {
if err := kubeClient.Create(ctx, &helmRelease); err != nil {
return err
} else {
logger.Successf("release created")
return nil
}
}
return err
}
existing.Spec = helmRelease.Spec
if err := kubeClient.Update(ctx, &existing); err != nil {
return err
}
logger.Successf("release updated")
return nil
}
func isHelmChartReady(ctx context.Context, kubeClient client.Client, name, namespace string) wait.ConditionFunc {
return func() (bool, error) {
var helmChart sourcev1.HelmChart
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
err := kubeClient.Get(ctx, namespacedName, &helmChart)
if err != nil {
if apierrors.IsNotFound(err) {
return false, nil
}
return false, err
}
for _, condition := range helmChart.Status.Conditions {
if condition.Type == helmv2.ReadyCondition {
if condition.Status == corev1.ConditionTrue {
return true, nil
} else if condition.Status == corev1.ConditionFalse {
return false, fmt.Errorf(condition.Message)
}
}
}
return false, nil
}
}

View File

@@ -37,37 +37,35 @@ import (
var createKsCmd = &cobra.Command{
Use: "kustomization [name]",
Aliases: []string{"ks"},
Short: "Create or update a kustomization resource",
Long: `
The kustomization source command generates a kustomization.kustomize.fluxcd.io resource for a given GitRepository source.
API spec: https://github.com/fluxcd/kustomize-controller/tree/master/docs/spec/v1alpha1`,
Example: ` # Create a kustomization from a source at a given path
create kustomization contour \
Short: "Create or update a Kustomization resource",
Long: "The kustomization source create command generates a Kustomize resource for a given GitRepository source.",
Example: ` # Create a Kustomization resource from a source at a given path
tk create kustomization contour \
--source=contour \
--path="./examples/contour/" \
--prune=true \
--interval=10m \
--validate=client \
--validation=client \
--health-check="Deployment/contour.projectcontour" \
--health-check="DaemonSet/envoy.projectcontour" \
--health-check-timeout=3m
# Create a kustomization that depends on the previous one
create kustomization webapp \
# Create a Kustomization resource that depends on the previous one
tk create kustomization webapp \
--depends-on=contour \
--source=webapp \
--path="./deploy/overlays/dev" \
--prune=true \
--interval=5m \
--validate=client
--validation=client
# Create a kustomization that runs under a service account
create kustomization webapp \
# Create a Kustomization resource that runs under a service account
tk create kustomization webapp \
--source=webapp \
--path="./deploy/overlays/staging" \
--prune=true \
--interval=5m \
--validate=client \
--validation=client \
--sa-name=reconclier \
--sa-namespace=staging
`,
@@ -79,7 +77,7 @@ var (
ksPath string
ksPrune bool
ksDependsOn []string
ksValidate string
ksValidation string
ksHealthCheck []string
ksHealthTimeout time.Duration
ksSAName string
@@ -88,12 +86,12 @@ var (
func init() {
createKsCmd.Flags().StringVar(&ksSource, "source", "", "GitRepository name")
createKsCmd.Flags().StringVar(&ksPath, "path", "./", "path to the directory containing the kustomization file")
createKsCmd.Flags().StringVar(&ksPath, "path", "./", "path to the directory containing the Kustomization file")
createKsCmd.Flags().BoolVar(&ksPrune, "prune", false, "enable garbage collection")
createKsCmd.Flags().StringArrayVar(&ksHealthCheck, "health-check", nil, "workload to be included in the health assessment, in the format '<kind>/<name>.<namespace>'")
createKsCmd.Flags().DurationVar(&ksHealthTimeout, "health-check-timeout", 2*time.Minute, "timeout of health checking operations")
createKsCmd.Flags().StringVar(&ksValidate, "validate", "", "validate the manifests before applying them on the cluster, can be 'client' or 'server'")
createKsCmd.Flags().StringArrayVar(&ksDependsOn, "depends-on", nil, "kustomization that must be ready before this kustomization can be applied")
createKsCmd.Flags().StringVar(&ksValidation, "validation", "", "validate the manifests before applying them on the cluster, can be 'client' or 'server'")
createKsCmd.Flags().StringArrayVar(&ksDependsOn, "depends-on", nil, "Kustomization that must be ready before this Kustomization can be applied")
createKsCmd.Flags().StringVar(&ksSAName, "sa-name", "", "service account name")
createKsCmd.Flags().StringVar(&ksSANamespace, "sa-namespace", "", "service account namespace")
createCmd.AddCommand(createKsCmd)
@@ -124,10 +122,9 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
}
if !export {
logGenerate("generating kustomization")
logger.Generatef("generating kustomization")
}
emptyAPIGroup := ""
kustomization := kustomizev1.Kustomization{
ObjectMeta: metav1.ObjectMeta{
Name: name,
@@ -140,13 +137,12 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
},
Path: ksPath,
Prune: ksPrune,
SourceRef: corev1.TypedLocalObjectReference{
APIGroup: &emptyAPIGroup,
Kind: "GitRepository",
Name: ksSource,
SourceRef: kustomizev1.CrossNamespaceObjectReference{
Kind: sourcev1.GitRepositoryKind,
Name: ksSource,
},
Suspend: false,
Validation: ksValidate,
Validation: ksValidation,
},
}
@@ -194,18 +190,18 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
return exportKs(kustomization)
}
logAction("applying kustomization")
logger.Actionf("applying kustomization")
if err := upsertKustomization(ctx, kubeClient, kustomization); err != nil {
return err
}
logWaiting("waiting for kustomization sync")
logger.Waitingf("waiting for kustomization sync")
if err := wait.PollImmediate(pollInterval, timeout,
isKustomizationReady(ctx, kubeClient, name, namespace)); err != nil {
return err
}
logSuccess("kustomization %s is ready", name)
logger.Successf("kustomization %s is ready", name)
namespacedName := types.NamespacedName{
Namespace: namespace,
@@ -217,7 +213,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
}
if kustomization.Status.LastAppliedRevision != "" {
logSuccess("applied revision %s", kustomization.Status.LastAppliedRevision)
logger.Successf("applied revision %s", kustomization.Status.LastAppliedRevision)
} else {
return fmt.Errorf("kustomization sync failed")
}
@@ -238,7 +234,7 @@ func upsertKustomization(ctx context.Context, kubeClient client.Client, kustomiz
if err := kubeClient.Create(ctx, &kustomization); err != nil {
return err
} else {
logSuccess("kustomization created")
logger.Successf("kustomization created")
return nil
}
}
@@ -250,7 +246,7 @@ func upsertKustomization(ctx context.Context, kubeClient client.Client, kustomiz
return err
}
logSuccess("kustomization updated")
logger.Successf("kustomization updated")
return nil
}

View File

@@ -22,7 +22,8 @@ import (
var createSourceCmd = &cobra.Command{
Use: "source",
Short: "Create source commands",
Short: "Create or update sources",
Long: "The create source sub-commands generate sources.",
}
func init() {

View File

@@ -35,46 +35,46 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/fluxcd/toolkit/pkg/ssh"
"github.com/fluxcd/pkg/ssh"
)
var createSourceGitCmd = &cobra.Command{
Use: "git [name]",
Short: "Create or update a git source",
Short: "Create or update a GitRepository source",
Long: `
The create source command generates a GitRepository resource and waits for it to sync.
The create source git command generates a GitRepository resource and waits for it to sync.
For Git over SSH, host and SSH keys are automatically generated and stored in a Kubernetes secret.
For private Git repositories, the basic authentication credentials are stored in a Kubernetes secret.`,
Example: ` # Create a source from a public Git repository master branch
create source git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--branch=master
# Create a source from a Git repository pinned to specific git tag
create source git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--tag="3.2.3"
# Create a source from a public Git repository tag that matches a semver range
create source git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--tag-semver=">=3.2.0 <3.3.0"
# Create a source from a Git repository using SSH authentication
create source git podinfo \
tk create source git podinfo \
--url=ssh://git@github.com/stefanprodan/podinfo \
--branch=master
# Create a source from a Git repository using SSH authentication and an
# ECDSA P-521 curve public key
create source git podinfo \
tk create source git podinfo \
--url=ssh://git@github.com/stefanprodan/podinfo \
--branch=master \
--ssh-key-algorithm=ecdsa \
--ssh-ecdsa-curve=p521
# Create a source from a Git repository using basic authentication
create source git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--username=username \
--password=password
@@ -115,7 +115,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
name := args[0]
if sourceGitURL == "" {
return fmt.Errorf("git-url is required")
return fmt.Errorf("url is required")
}
tmpDir, err := ioutil.TempDir("", name)
@@ -166,7 +166,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
withAuth := false
// TODO(hidde): move all auth prep to separate func?
if u.Scheme == "ssh" {
logAction("generating deploy key pair")
logger.Actionf("generating deploy key pair")
pair, err := generateKeyPair(ctx)
if err != nil {
return err
@@ -181,15 +181,15 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
return fmt.Errorf("aborting")
}
logAction("collecting preferred public key from SSH server")
logger.Actionf("collecting preferred public key from SSH server")
hostKey, err := scanHostKey(ctx, u)
if err != nil {
return err
}
logSuccess("collected public key from SSH server:")
logger.Successf("collected public key from SSH server:")
fmt.Printf("%s", hostKey)
logAction("applying secret with keys")
logger.Actionf("applying secret with keys")
secret := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
@@ -206,7 +206,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
}
withAuth = true
} else if sourceGitUsername != "" && sourceGitPassword != "" {
logAction("applying secret with basic auth credentials")
logger.Actionf("applying secret with basic auth credentials")
secret := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
@@ -224,10 +224,10 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
}
if withAuth {
logSuccess("authentication configured")
logger.Successf("authentication configured")
}
logGenerate("generating source")
logger.Generatef("generating source")
if withAuth {
gitRepository.Spec.SecretRef = &corev1.LocalObjectReference{
@@ -235,18 +235,18 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
}
}
logAction("applying source")
logger.Actionf("applying source")
if err := upsertGitRepository(ctx, kubeClient, gitRepository); err != nil {
return err
}
logWaiting("waiting for git sync")
logger.Waitingf("waiting for git sync")
if err := wait.PollImmediate(pollInterval, timeout,
isGitRepositoryReady(ctx, kubeClient, name, namespace)); err != nil {
return err
}
logSuccess("git sync completed")
logger.Successf("git sync completed")
namespacedName := types.NamespacedName{
Namespace: namespace,
@@ -258,7 +258,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
}
if gitRepository.Status.Artifact != nil {
logSuccess("fetched revision: %s", gitRepository.Status.Artifact.Revision)
logger.Successf("fetched revision: %s", gitRepository.Status.Artifact.Revision)
} else {
return fmt.Errorf("git sync failed, artifact not found")
}
@@ -336,7 +336,7 @@ func upsertGitRepository(ctx context.Context, kubeClient client.Client, gitRepos
if err := kubeClient.Create(ctx, &gitRepository); err != nil {
return err
} else {
logSuccess("source created")
logger.Successf("source created")
return nil
}
}
@@ -348,7 +348,7 @@ func upsertGitRepository(ctx context.Context, kubeClient client.Client, gitRepos
return err
}
logSuccess("source updated")
logger.Successf("source updated")
return nil
}

View File

@@ -0,0 +1,229 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"fmt"
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
"github.com/spf13/cobra"
"io/ioutil"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"net/url"
"os"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"
)
var createSourceHelmCmd = &cobra.Command{
Use: "helm [name]",
Short: "Create or update a HelmRepository source",
Long: `
The create source helm command generates a HelmRepository resource and waits for it to fetch the index.
For private Helm repositories, the basic authentication credentials are stored in a Kubernetes secret.`,
Example: ` # Create a source from a public Helm repository
tk create source helm podinfo \
--url=https://stefanprodan.github.io/podinfo \
--interval=10m
# Create a source from a Helm repository using basic authentication
tk create source helm podinfo \
--url=https://stefanprodan.github.io/podinfo \
--username=username \
--password=password
`,
RunE: createSourceHelmCmdRun,
}
var (
sourceHelmURL string
sourceHelmUsername string
sourceHelmPassword string
)
func init() {
createSourceHelmCmd.Flags().StringVar(&sourceHelmURL, "url", "", "Helm repository address")
createSourceHelmCmd.Flags().StringVarP(&sourceHelmUsername, "username", "u", "", "basic authentication username")
createSourceHelmCmd.Flags().StringVarP(&sourceHelmPassword, "password", "p", "", "basic authentication password")
createSourceCmd.AddCommand(createSourceHelmCmd)
}
func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("source name is required")
}
name := args[0]
secretName := fmt.Sprintf("helm-%s", name)
if sourceHelmURL == "" {
return fmt.Errorf("url is required")
}
tmpDir, err := ioutil.TempDir("", name)
if err != nil {
return err
}
defer os.RemoveAll(tmpDir)
if _, err := url.Parse(sourceHelmURL); err != nil {
return fmt.Errorf("url parse failed: %w", err)
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
helmRepository := sourcev1.HelmRepository{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: sourcev1.HelmRepositorySpec{
URL: sourceHelmURL,
Interval: metav1.Duration{
Duration: interval,
},
},
}
if export {
return exportHelmRepository(helmRepository)
}
withAuth := false
if sourceHelmUsername != "" && sourceHelmPassword != "" {
logger.Actionf("applying secret with basic auth credentials")
secret := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: secretName,
Namespace: namespace,
},
StringData: map[string]string{
"username": sourceHelmUsername,
"password": sourceHelmPassword,
},
}
if err := upsertSecret(ctx, kubeClient, secret); err != nil {
return err
}
withAuth = true
}
if withAuth {
logger.Successf("authentication configured")
}
logger.Generatef("generating source")
if withAuth {
helmRepository.Spec.SecretRef = &corev1.LocalObjectReference{
Name: secretName,
}
}
logger.Actionf("applying source")
if err := upsertHelmRepository(ctx, kubeClient, helmRepository); err != nil {
return err
}
logger.Waitingf("waiting for index download")
if err := wait.PollImmediate(pollInterval, timeout,
isHelmRepositoryReady(ctx, kubeClient, name, namespace)); err != nil {
return err
}
logger.Successf("index download completed")
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
err = kubeClient.Get(ctx, namespacedName, &helmRepository)
if err != nil {
return fmt.Errorf("helm index failed: %w", err)
}
if helmRepository.Status.Artifact != nil {
logger.Successf("fetched revision: %s", helmRepository.Status.Artifact.Revision)
} else {
return fmt.Errorf("index download failed, artifact not found")
}
return nil
}
func upsertHelmRepository(ctx context.Context, kubeClient client.Client, helmRepository sourcev1.HelmRepository) error {
namespacedName := types.NamespacedName{
Namespace: helmRepository.GetNamespace(),
Name: helmRepository.GetName(),
}
var existing sourcev1.HelmRepository
err := kubeClient.Get(ctx, namespacedName, &existing)
if err != nil {
if errors.IsNotFound(err) {
if err := kubeClient.Create(ctx, &helmRepository); err != nil {
return err
} else {
logger.Successf("source created")
return nil
}
}
return err
}
existing.Spec = helmRepository.Spec
if err := kubeClient.Update(ctx, &existing); err != nil {
return err
}
logger.Successf("source updated")
return nil
}
func exportHelmRepository(source sourcev1.HelmRepository) error {
gvk := sourcev1.GroupVersion.WithKind(sourcev1.HelmRepositoryKind)
export := sourcev1.HelmRepository{
TypeMeta: metav1.TypeMeta{
Kind: gvk.Kind,
APIVersion: gvk.GroupVersion().String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: source.Name,
Namespace: source.Namespace,
},
Spec: source.Spec,
}
data, err := yaml.Marshal(export)
if err != nil {
return err
}
fmt.Println("---")
fmt.Println(string(data))
return nil
}

View File

@@ -22,7 +22,8 @@ import (
var deleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete commands",
Short: "Delete sources and resources",
Long: "The delete sub-commands delete sources and resources.",
}
var (

View File

@@ -0,0 +1,91 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"fmt"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types"
helmv2 "github.com/fluxcd/helm-controller/api/v2alpha1"
)
var deleteHelmReleaseCmd = &cobra.Command{
Use: "helmrelease [name]",
Aliases: []string{"hr"},
Short: "Delete a HelmRelease resource",
Long: "The delete helmrelease command removes the given HelmRelease from the cluster.",
Example: ` # Delete a Helm release and the Kubernetes resources created by it
tk delete hr podinfo
`,
RunE: deleteHelmReleaseCmdRun,
}
func init() {
deleteCmd.AddCommand(deleteHelmReleaseCmd)
}
func deleteHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("release name is required")
}
name := args[0]
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
var helmRelease helmv2.HelmRelease
err = kubeClient.Get(ctx, namespacedName, &helmRelease)
if err != nil {
return err
}
if !deleteSilent {
if !helmRelease.Spec.Suspend {
logger.Waitingf("This action will remove the Kubernetes objects previously applied by the %s Helm release!", name)
}
prompt := promptui.Prompt{
Label: "Are you sure you want to delete this Helm release",
IsConfirm: true,
}
if _, err := prompt.Run(); err != nil {
return fmt.Errorf("aborting")
}
}
logger.Actionf("deleting release %s in %s namespace", name, namespace)
err = kubeClient.Delete(ctx, &helmRelease)
if err != nil {
return err
}
logger.Successf("release deleted")
return nil
}

View File

@@ -29,8 +29,12 @@ import (
var deleteKsCmd = &cobra.Command{
Use: "kustomization [name]",
Aliases: []string{"ks"},
Short: "Delete kustomization",
RunE: deleteKsCmdRun,
Short: "Delete a Kustomization resource",
Long: "The delete kustomization command deletes the given Kustomization from the cluster.",
Example: ` # Delete a kustomization and the Kubernetes resources created by it
tk delete kustomization podinfo
`,
RunE: deleteKsCmdRun,
}
func init() {
@@ -64,7 +68,7 @@ func deleteKsCmdRun(cmd *cobra.Command, args []string) error {
if !deleteSilent {
if !kustomization.Spec.Suspend {
logWaiting("This action will remove the Kubernetes objects previously applied by the %s kustomization!", name)
logger.Waitingf("This action will remove the Kubernetes objects previously applied by the %s kustomization!", name)
}
prompt := promptui.Prompt{
Label: "Are you sure you want to delete this kustomization",
@@ -75,12 +79,12 @@ func deleteKsCmdRun(cmd *cobra.Command, args []string) error {
}
}
logAction("deleting kustomization %s in %s namespace", name, namespace)
logger.Actionf("deleting kustomization %s in %s namespace", name, namespace)
err = kubeClient.Delete(ctx, &kustomization)
if err != nil {
return err
}
logSuccess("kustomization deleted")
logger.Successf("kustomization deleted")
return nil
}

View File

@@ -22,7 +22,8 @@ import (
var deleteSourceCmd = &cobra.Command{
Use: "source",
Short: "Delete sources commands",
Short: "Delete sources",
Long: "The delete source sub-commands delete sources.",
}
func init() {

View File

@@ -28,8 +28,12 @@ import (
var deleteSourceGitCmd = &cobra.Command{
Use: "git [name]",
Short: "Delete git source",
RunE: deleteSourceGitCmdRun,
Short: "Delete a GitRepository source",
Long: "The delete source git command deletes the given GitRepository from the cluster.",
Example: ` # Delete a Git repository
tk delete source git podinfo
`,
RunE: deleteSourceGitCmdRun,
}
func init() {
@@ -71,12 +75,12 @@ func deleteSourceGitCmdRun(cmd *cobra.Command, args []string) error {
}
}
logAction("deleting source %s in %s namespace", name, namespace)
logger.Actionf("deleting source %s in %s namespace", name, namespace)
err = kubeClient.Delete(ctx, &git)
if err != nil {
return err
}
logSuccess("source deleted")
logger.Successf("source deleted")
return nil
}

View File

@@ -0,0 +1,86 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"fmt"
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types"
)
var deleteSourceHelmCmd = &cobra.Command{
Use: "helm [name]",
Short: "Delete a HelmRepository source",
Long: "The delete source helm command deletes the given HelmRepository from the cluster.",
Example: ` # Delete a Helm repository
tk delete source helm podinfo
`,
RunE: deleteSourceHelmCmdRun,
}
func init() {
deleteSourceCmd.AddCommand(deleteSourceHelmCmd)
}
func deleteSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("name is required")
}
name := args[0]
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
var helmRepository sourcev1.HelmRepository
err = kubeClient.Get(ctx, namespacedName, &helmRepository)
if err != nil {
return err
}
if !deleteSilent {
prompt := promptui.Prompt{
Label: "Are you sure you want to delete this source",
IsConfirm: true,
}
if _, err := prompt.Run(); err != nil {
return fmt.Errorf("aborting")
}
}
logger.Actionf("deleting source %s in %s namespace", name, namespace)
err = kubeClient.Delete(ctx, &helmRepository)
if err != nil {
return err
}
logger.Successf("source deleted")
return nil
}

View File

@@ -22,7 +22,8 @@ import (
var exportCmd = &cobra.Command{
Use: "export",
Short: "Export commands",
Short: "Export resources in YAML format",
Long: "The export sub-commands export resources in YAML format.",
}
var (

View File

@@ -0,0 +1,118 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"fmt"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"
helmv2 "github.com/fluxcd/helm-controller/api/v2alpha1"
)
var exportHelmReleaseCmd = &cobra.Command{
Use: "helmrelease [name]",
Aliases: []string{"hr"},
Short: "Export HelmRelease resources in YAML format",
Long: "The export helmrelease command exports one or all HelmRelease resources in YAML format.",
Example: ` # Export all HelmRelease resources
tk export helmrelease --all > kustomizations.yaml
# Export a HelmRelease
tk export hr my-app > app-release.yaml
`,
RunE: exportHelmReleaseCmdRun,
}
func init() {
exportCmd.AddCommand(exportHelmReleaseCmd)
}
func exportHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
if !exportAll && len(args) < 1 {
return fmt.Errorf("name is required")
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
if exportAll {
var list helmv2.HelmReleaseList
err = kubeClient.List(ctx, &list, client.InNamespace(namespace))
if err != nil {
return err
}
if len(list.Items) == 0 {
logger.Failuref("no kustomizations found in %s namespace", namespace)
return nil
}
for _, helmRelease := range list.Items {
if err := exportHelmRelease(helmRelease); err != nil {
return err
}
}
} else {
name := args[0]
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
var helmRelease helmv2.HelmRelease
err = kubeClient.Get(ctx, namespacedName, &helmRelease)
if err != nil {
return err
}
return exportHelmRelease(helmRelease)
}
return nil
}
func exportHelmRelease(helmRelease helmv2.HelmRelease) error {
gvk := helmv2.GroupVersion.WithKind(helmv2.HelmReleaseKind)
export := helmv2.HelmRelease{
TypeMeta: metav1.TypeMeta{
Kind: gvk.Kind,
APIVersion: gvk.GroupVersion().String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: helmRelease.Name,
Namespace: helmRelease.Namespace,
},
Spec: helmRelease.Spec,
}
data, err := yaml.Marshal(export)
if err != nil {
return err
}
fmt.Println("---")
fmt.Println(string(data))
return nil
}

View File

@@ -31,12 +31,13 @@ import (
var exportKsCmd = &cobra.Command{
Use: "kustomization [name]",
Aliases: []string{"ks"},
Short: "Export kustomization in YAML format",
Example: ` # Export all kustomizations
export kustomization --all > kustomizations.yaml
Short: "Export Kustomization resources in YAML format",
Long: "The export kustomization command exports one or all Kustomization resources in YAML format.",
Example: ` # Export all Kustomization resources
tk export kustomization --all > kustomizations.yaml
# Export a kustomization
export kustomization my-app > kustomization.yaml
# Export a Kustomization
tk export kustomization my-app > kustomization.yaml
`,
RunE: exportKsCmdRun,
}
@@ -66,7 +67,7 @@ func exportKsCmdRun(cmd *cobra.Command, args []string) error {
}
if len(list.Items) == 0 {
logFailure("no kustomizations found in %s namespace", namespace)
logger.Failuref("no kustomizations found in %s namespace", namespace)
return nil
}

View File

@@ -22,7 +22,8 @@ import (
var exportSourceCmd = &cobra.Command{
Use: "source",
Short: "Export source commands",
Short: "Export sources",
Long: "The export source sub-commands export sources in YAML format.",
}
var (

View File

@@ -31,12 +31,13 @@ import (
var exportSourceGitCmd = &cobra.Command{
Use: "git [name]",
Short: "Export git sources in YAML format",
Example: ` # Export all git sources
export source git --all > sources.yaml
Short: "Export GitRepository sources in YAML format",
Long: "The export source git command exports on or all GitRepository sources in YAML format.",
Example: ` # Export all GitRepository sources
tk export source git --all > sources.yaml
# Export a git source including the SSH keys or basic auth credentials
export source git my-private-repo --with-credentials > source.yaml
# Export a GitRepository source including the SSH key pair or basic auth credentials
tk export source git my-private-repo --with-credentials > source.yaml
`,
RunE: exportSourceGitCmdRun,
}
@@ -47,7 +48,7 @@ func init() {
func exportSourceGitCmdRun(cmd *cobra.Command, args []string) error {
if !exportAll && len(args) < 1 {
return fmt.Errorf("kustomization name is required")
return fmt.Errorf("name is required")
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
@@ -66,7 +67,7 @@ func exportSourceGitCmdRun(cmd *cobra.Command, args []string) error {
}
if len(list.Items) == 0 {
logFailure("no source found in %s namespace", namespace)
logger.Failuref("no source found in %s namespace", namespace)
return nil
}
@@ -102,7 +103,7 @@ func exportSourceGitCmdRun(cmd *cobra.Command, args []string) error {
}
func exportGit(source sourcev1.GitRepository) error {
gvk := sourcev1.GroupVersion.WithKind("GitRepository")
gvk := sourcev1.GroupVersion.WithKind(sourcev1.GitRepositoryKind)
export := sourcev1.GitRepository{
TypeMeta: metav1.TypeMeta{
Kind: gvk.Kind,

View File

@@ -0,0 +1,139 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"fmt"
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"
)
var exportSourceHelmCmd = &cobra.Command{
Use: "helm [name]",
Short: "Export HelmRepository sources in YAML format",
Long: "The export source git command exports on or all HelmRepository sources in YAML format.",
Example: ` # Export all HelmRepository sources
tk export source helm --all > sources.yaml
# Export a HelmRepository source including the basic auth credentials
tk export source helm my-private-repo --with-credentials > source.yaml
`,
RunE: exportSourceHelmCmdRun,
}
func init() {
exportSourceCmd.AddCommand(exportSourceHelmCmd)
}
func exportSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
if !exportAll && len(args) < 1 {
return fmt.Errorf("name is required")
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
if exportAll {
var list sourcev1.HelmRepositoryList
err = kubeClient.List(ctx, &list, client.InNamespace(namespace))
if err != nil {
return err
}
if len(list.Items) == 0 {
logger.Failuref("no source found in %s namespace", namespace)
return nil
}
for _, repository := range list.Items {
if err := exportHelmRepository(repository); err != nil {
return err
}
if exportSourceWithCred {
if err := exportHelmCredentials(ctx, kubeClient, repository); err != nil {
return err
}
}
}
} else {
name := args[0]
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
var repository sourcev1.HelmRepository
err = kubeClient.Get(ctx, namespacedName, &repository)
if err != nil {
return err
}
if err := exportHelmRepository(repository); err != nil {
return err
}
if exportSourceWithCred {
return exportHelmCredentials(ctx, kubeClient, repository)
}
}
return nil
}
func exportHelmCredentials(ctx context.Context, kubeClient client.Client, source sourcev1.HelmRepository) error {
if source.Spec.SecretRef != nil {
namespacedName := types.NamespacedName{
Namespace: source.Namespace,
Name: source.Spec.SecretRef.Name,
}
var cred corev1.Secret
err := kubeClient.Get(ctx, namespacedName, &cred)
if err != nil {
return fmt.Errorf("failed to retrieve secret %s, error: %w", namespacedName.Name, err)
}
exported := corev1.Secret{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Secret",
},
ObjectMeta: metav1.ObjectMeta{
Name: namespacedName.Name,
Namespace: namespacedName.Namespace,
},
Data: cred.Data,
Type: cred.Type,
}
data, err := yaml.Marshal(exported)
if err != nil {
return err
}
fmt.Println("---")
fmt.Println(string(data))
}
return nil
}

View File

@@ -19,6 +19,7 @@ package main
import (
"crypto/elliptic"
"fmt"
"sort"
"strconv"
"strings"
)
@@ -124,5 +125,6 @@ func ecdsaCurves() []string {
for k := range supportedECDSACurves {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}

View File

@@ -22,7 +22,8 @@ import (
var getCmd = &cobra.Command{
Use: "get",
Short: "Get commands",
Short: "Get sources and resources",
Long: "The get sub-commands print the statuses of sources and resources.",
}
func init() {

90
cmd/tk/get_helmrelease.go Normal file
View File

@@ -0,0 +1,90 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
helmv2 "github.com/fluxcd/helm-controller/api/v2alpha1"
)
var getHelmReleaseCmd = &cobra.Command{
Use: "helmreleases",
Aliases: []string{"hr"},
Short: "Get HelmRelease statuses",
Long: "The get helmreleases command prints the statuses of the resources.",
Example: ` # List all Helm releases and their status
tk get helmreleases
`,
RunE: getHelmReleaseCmdRun,
}
func init() {
getCmd.AddCommand(getHelmReleaseCmd)
}
func getHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
var list helmv2.HelmReleaseList
err = kubeClient.List(ctx, &list, client.InNamespace(namespace))
if err != nil {
return err
}
if len(list.Items) == 0 {
logger.Failuref("no releases found in %s namespace", namespace)
return nil
}
for _, helmRelease := range list.Items {
if helmRelease.Spec.Suspend {
logger.Successf("%s is suspended", helmRelease.GetName())
continue
}
isInitialized := false
for _, condition := range helmRelease.Status.Conditions {
if condition.Type == helmv2.ReadyCondition {
if condition.Status != corev1.ConditionFalse {
if helmRelease.Status.LastAppliedRevision != "" {
logger.Successf("%s last applied revision %s", helmRelease.GetName(), helmRelease.Status.LastAppliedRevision)
} else {
logger.Successf("%s reconciling", helmRelease.GetName())
}
} else {
logger.Failuref("%s %s", helmRelease.GetName(), condition.Message)
}
isInitialized = true
break
}
}
if !isInitialized {
logger.Failuref("%s is not ready", helmRelease.GetName())
}
}
return nil
}

View File

@@ -28,9 +28,11 @@ import (
var getKsCmd = &cobra.Command{
Use: "kustomizations",
Aliases: []string{"ks"},
Short: "Get kustomizations status",
Long: `
The get kustomizations command prints the status of the resources.`,
Short: "Get Kustomization statuses",
Long: "The get kustomizations command prints the statuses of the resources.",
Example: ` # List all kustomizations and their status
tk get kustomizations
`,
RunE: getKsCmdRun,
}
@@ -54,13 +56,13 @@ func getKsCmdRun(cmd *cobra.Command, args []string) error {
}
if len(list.Items) == 0 {
logFailure("no kustomizations found in %s namespace", namespace)
logger.Failuref("no kustomizations found in %s namespace", namespace)
return nil
}
for _, kustomization := range list.Items {
if kustomization.Spec.Suspend {
logSuccess("%s is suspended", kustomization.GetName())
logger.Successf("%s is suspended", kustomization.GetName())
continue
}
isInitialized := false
@@ -68,19 +70,19 @@ func getKsCmdRun(cmd *cobra.Command, args []string) error {
if condition.Type == kustomizev1.ReadyCondition {
if condition.Status != corev1.ConditionFalse {
if kustomization.Status.LastAppliedRevision != "" {
logSuccess("%s last applied revision %s", kustomization.GetName(), kustomization.Status.LastAppliedRevision)
logger.Successf("%s last applied revision %s", kustomization.GetName(), kustomization.Status.LastAppliedRevision)
} else {
logSuccess("%s reconciling", kustomization.GetName())
logger.Successf("%s reconciling", kustomization.GetName())
}
} else {
logFailure("%s %s", kustomization.GetName(), condition.Message)
logger.Failuref("%s %s", kustomization.GetName(), condition.Message)
}
isInitialized = true
break
}
}
if !isInitialized {
logFailure("%s is not ready", kustomization.GetName())
logger.Failuref("%s is not ready", kustomization.GetName())
}
}
return nil

View File

@@ -22,7 +22,8 @@ import (
var getSourceCmd = &cobra.Command{
Use: "sources",
Short: "Get sources commands",
Short: "Get source statuses",
Long: "The get source sub-commands print the statuses of the sources.",
}
func init() {

View File

@@ -27,9 +27,11 @@ import (
var getSourceGitCmd = &cobra.Command{
Use: "git",
Short: "Get git sources status",
Long: `
The get sources command prints the status of the git resources.`,
Short: "Get GitRepository source statuses",
Long: "The get sources git command prints the status of the GitRepository sources.",
Example: ` # List all Git repositories and their status
tk get sources git
`,
RunE: getSourceGitCmdRun,
}
@@ -53,7 +55,7 @@ func getSourceGitCmdRun(cmd *cobra.Command, args []string) error {
}
if len(list.Items) == 0 {
logFailure("no sources found in %s namespace", namespace)
logger.Failuref("no sources found in %s namespace", namespace)
return nil
}
@@ -62,16 +64,16 @@ func getSourceGitCmdRun(cmd *cobra.Command, args []string) error {
for _, condition := range source.Status.Conditions {
if condition.Type == sourcev1.ReadyCondition {
if condition.Status != corev1.ConditionFalse {
logSuccess("%s last fetched revision: %s", source.GetName(), source.Status.Artifact.Revision)
logger.Successf("%s last fetched revision: %s", source.GetName(), source.Status.Artifact.Revision)
} else {
logFailure("%s %s", source.GetName(), condition.Message)
logger.Failuref("%s %s", source.GetName(), condition.Message)
}
isInitialized = true
break
}
}
if !isInitialized {
logFailure("%s is not ready", source.GetName())
logger.Failuref("%s is not ready", source.GetName())
}
}
return nil

80
cmd/tk/get_source_helm.go Normal file
View File

@@ -0,0 +1,80 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
var getSourceHelmCmd = &cobra.Command{
Use: "helm",
Short: "Get HelmRepository source statuses",
Long: "The get sources helm command prints the status of the HelmRepository sources.",
Example: ` # List all Helm repositories and their status
tk get sources helm
`,
RunE: getSourceHelmCmdRun,
}
func init() {
getSourceCmd.AddCommand(getSourceHelmCmd)
}
func getSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
var list sourcev1.HelmRepositoryList
err = kubeClient.List(ctx, &list, client.InNamespace(namespace))
if err != nil {
return err
}
if len(list.Items) == 0 {
logger.Failuref("no sources found in %s namespace", namespace)
return nil
}
for _, source := range list.Items {
isInitialized := false
for _, condition := range source.Status.Conditions {
if condition.Type == sourcev1.ReadyCondition {
if condition.Status != corev1.ConditionFalse {
logger.Successf("%s last fetched revision: %s", source.GetName(), source.Status.Artifact.Revision)
} else {
logger.Failuref("%s %s", source.GetName(), condition.Message)
}
isInitialized = true
break
}
}
if !isInitialized {
logger.Failuref("%s is not ready", source.GetName())
}
}
return nil
}

View File

@@ -19,11 +19,14 @@ package main
import (
"context"
"fmt"
"github.com/fluxcd/pkg/untar"
"io/ioutil"
"net/http"
"os"
"path"
"path/filepath"
"strings"
"time"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/api/filesys"
@@ -33,32 +36,40 @@ import (
var installCmd = &cobra.Command{
Use: "install",
Short: "Install the toolkit components",
Long: `
The install command deploys the toolkit components in the specified namespace.
Long: `The install command deploys the toolkit components in the specified namespace.
If a previous version is installed, then an in-place upgrade will be performed.`,
Example: ` # Install the latest version in the gitops-systems namespace
install --version=master --namespace=gitops-systems
tk install --version=latest --namespace=gitops-systems
# Dry-run install for a specific version and a series of components
install --dry-run --version=0.0.1 --components="source-controller,kustomize-controller"
tk install --dry-run --version=v0.0.7 --components="source-controller,kustomize-controller"
# Dry-run install with manifests preview
install --dry-run --verbose
tk install --dry-run --verbose
# Write install manifests to file
tk install --export > gitops-system.yaml
`,
RunE: installCmdRun,
}
var (
installExport bool
installDryRun bool
installManifestsPath string
installVersion string
installComponents []string
)
func init() {
installCmd.Flags().BoolVar(&installExport, "export", false,
"write the install manifests to stdout and exit")
installCmd.Flags().BoolVarP(&installDryRun, "dry-run", "", false,
"only print the object that would be applied")
installCmd.Flags().StringVarP(&installVersion, "version", "v", "master",
"toolkit tag or branch")
installCmd.Flags().StringVarP(&installVersion, "version", "v", defaultVersion,
"toolkit version")
installCmd.Flags().StringSliceVar(&installComponents, "components", defaultComponents,
"list of components, accepts comma-separated values")
installCmd.Flags().StringVarP(&installManifestsPath, "manifests", "", "",
"path to the manifest directory, dev only")
rootCmd.AddCommand(installCmd)
@@ -82,9 +93,11 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
}
defer os.RemoveAll(tmpDir)
logGenerate("generating manifests")
if !installExport {
logger.Generatef("generating manifests")
}
if kustomizePath == "" {
err = genInstallManifests(installVersion, namespace, components, tmpDir)
err = genInstallManifests(installVersion, namespace, installComponents, tmpDir)
if err != nil {
return fmt.Errorf("install failed: %w", err)
}
@@ -102,11 +115,18 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
} else {
if verbose {
fmt.Print(yaml)
} else if installExport {
fmt.Println("---")
fmt.Println("# GitOps Toolkit revision", installVersion, time.Now().Format(time.RFC3339))
fmt.Println("# Components:", strings.Join(installComponents, ","))
fmt.Print(yaml)
fmt.Println("---")
return nil
}
}
logSuccess("manifests build completed")
logger.Successf("manifests build completed")
logAction("installing components in %s namespace", namespace)
logger.Actionf("installing components in %s namespace", namespace)
applyOutput := ModeStderrOS
if verbose {
applyOutput = ModeOS
@@ -122,24 +142,24 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
}
if installDryRun {
logSuccess("install dry-run finished")
logger.Successf("install dry-run finished")
return nil
} else {
logSuccess("install completed")
logger.Successf("install completed")
}
logWaiting("verifying installation")
for _, deployment := range components {
logger.Waitingf("verifying installation")
for _, deployment := range installComponents {
command = fmt.Sprintf("kubectl -n %s rollout status deployment %s --timeout=%s",
namespace, deployment, timeout.String())
if _, err := utils.execCommand(ctx, applyOutput, command); err != nil {
return fmt.Errorf("install failed")
} else {
logSuccess("%s ready", deployment)
logger.Successf("%s ready", deployment)
}
}
logSuccess("install finished")
logger.Successf("install finished")
return nil
}
@@ -164,7 +184,7 @@ fieldSpecs:
`
var kustomizationTmpl = `---
{{- $version := .Version }}
{{- $eventsAddr := .EventsAddr }}
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: {{.Namespace}}
@@ -172,10 +192,25 @@ transformers:
- labels.yaml
resources:
- namespace.yaml
- policies.yaml
- roles
- github.com/fluxcd/toolkit/manifests/policies?ref={{$version}}
{{- range .Components }}
- github.com/fluxcd/toolkit/manifests/bases/{{.}}?ref={{$version}}
- {{.}}.yaml
{{- end }}
patchesJson6902:
{{- range $i, $v := .Components }}
{{- if ne $v "notification-controller" }}
- target:
group: apps
version: v1
kind: Deployment
name: {{$v}}
patch: |-
- op: replace
path: /spec/template/spec/containers/0/args/0
value: --events-addr={{$eventsAddr}}
{{- end }}
{{- end }}
`
@@ -183,19 +218,64 @@ var kustomizationRolesTmpl = `---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- github.com/fluxcd/toolkit/manifests/rbac?ref={{.Version}}
- rbac.yaml
nameSuffix: -{{.Namespace}}
`
func downloadManifests(version string, tmpDir string) error {
ghURL := "https://github.com/fluxcd/toolkit/releases/latest/download/manifests.tar.gz"
if strings.HasPrefix(version, "v") {
ghURL = fmt.Sprintf("https://github.com/fluxcd/toolkit/releases/download/%s/manifests.tar.gz", version)
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
req, err := http.NewRequest("GET", ghURL, nil)
if err != nil {
return fmt.Errorf("failed to create HTTP request for %s, error: %w", ghURL, err)
}
// download
resp, err := http.DefaultClient.Do(req.WithContext(ctx))
if err != nil {
return fmt.Errorf("failed to download artifact from %s, error: %w", ghURL, err)
}
defer resp.Body.Close()
// check response
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("faild to download artifact from %s, status: %s", ghURL, resp.Status)
}
// extract
if _, err = untar.Untar(resp.Body, tmpDir); err != nil {
return fmt.Errorf("faild to untar manifests from %s, error: %w", ghURL, err)
}
return nil
}
func genInstallManifests(version string, namespace string, components []string, tmpDir string) error {
eventsAddr := ""
if utils.containsItemString(components, defaultNotification) {
eventsAddr = fmt.Sprintf("http://%s/", defaultNotification)
}
model := struct {
Version string
Namespace string
Components []string
EventsAddr string
}{
Version: version,
Namespace: namespace,
Components: components,
EventsAddr: eventsAddr,
}
if err := downloadManifests(version, tmpDir); err != nil {
return err
}
if err := utils.execTemplate(model, namespaceTmpl, path.Join(tmpDir, "namespace.yaml")); err != nil {
@@ -218,6 +298,10 @@ func genInstallManifests(version string, namespace string, components []string,
return fmt.Errorf("generate roles failed: %w", err)
}
if err := utils.copyFile(filepath.Join(tmpDir, "rbac.yaml"), filepath.Join(tmpDir, "roles/rbac.yaml")); err != nil {
return fmt.Errorf("generate rbac failed: %w", err)
}
return nil
}

View File

@@ -18,22 +18,24 @@ package main
import "fmt"
func logAction(format string, a ...interface{}) {
type printLogger struct{}
func (l printLogger) Actionf(format string, a ...interface{}) {
fmt.Println(``, fmt.Sprintf(format, a...))
}
func logGenerate(format string, a ...interface{}) {
func (l printLogger) Generatef(format string, a ...interface{}) {
fmt.Println(``, fmt.Sprintf(format, a...))
}
func logWaiting(format string, a ...interface{}) {
func (l printLogger) Waitingf(format string, a ...interface{}) {
fmt.Println(``, fmt.Sprintf(format, a...))
}
func logSuccess(format string, a ...interface{}) {
func (l printLogger) Successf(format string, a ...interface{}) {
fmt.Println(``, fmt.Sprintf(format, a...))
}
func logFailure(format string, a ...interface{}) {
func (l printLogger) Failuref(format string, a ...interface{}) {
fmt.Println(``, fmt.Sprintf(format, a...))
}

View File

@@ -25,6 +25,8 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
_ "k8s.io/client-go/plugin/pkg/client/auth"
tklog "github.com/fluxcd/toolkit/pkg/log"
)
var VERSION = "0.0.0-dev.0"
@@ -48,42 +50,42 @@ var rootCmd = &cobra.Command{
--branch=master \
--interval=3m
# List git sources and their status
# List GitRepository sources and their status
tk get sources git
# Trigger a git sync
# Trigger a GitRepository source sync
tk sync source git webapp-latest
# Export git sources in YAML format
# Export GitRepository sources in YAML format
tk export source git --all > sources.yaml
# Create a kustomization for deploying a series of microservices
# Create a Kustomization for deploying a series of microservices
tk create kustomization webapp-dev \
--source=webapp-latest \
--path="./deploy/webapp/" \
--prune=true \
--interval=5m \
--validate=client \
--validation=client \
--health-check="Deployment/backend.webapp" \
--health-check="Deployment/frontend.webapp" \
--health-check-timeout=2m
# Trigger a git sync and apply changes if any
tk sync kustomization webapp-dev --with-source
# Trigger a git sync of the Kustomization's source and apply changes
tk reconcile kustomization webapp-dev --with-source
# Suspend a kustomization reconciliation
# Suspend a Kustomization reconciliation
tk suspend kustomization webapp-dev
# Export kustomizations in YAML format
# Export Kustomizations in YAML format
tk export kustomization --all > kustomizations.yaml
# Resume a kustomization reconciliation
# Resume a Kustomization reconciliation
tk resume kustomization webapp-dev
# Delete a kustomization
# Delete a Kustomization
tk delete kustomization webapp-dev
# Delete a git source
# Delete a GitRepository source
tk delete source git webapp-latest
# Uninstall the toolkit and delete CRDs
@@ -96,21 +98,25 @@ var (
namespace string
timeout time.Duration
verbose bool
components []string
utils Utils
pollInterval = 2 * time.Second
pollInterval = 2 * time.Second
logger tklog.Logger = printLogger{}
)
var (
defaultComponents = []string{"source-controller", "kustomize-controller", "helm-controller", "notification-controller"}
defaultVersion = "latest"
defaultNamespace = "gitops-system"
defaultNotification = "notification-controller"
)
func init() {
rootCmd.PersistentFlags().StringVarP(&namespace, "namespace", "", "gitops-system",
rootCmd.PersistentFlags().StringVar(&namespace, "namespace", defaultNamespace,
"the namespace scope for this operation")
rootCmd.PersistentFlags().DurationVarP(&timeout, "timeout", "", 5*time.Minute,
"timeout for this operation")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "", false,
"print generated objects")
rootCmd.PersistentFlags().StringSliceVar(&components, "components",
[]string{"source-controller", "kustomize-controller"},
"list of components, accepts comma-separated values")
}
func main() {
@@ -118,7 +124,7 @@ func main() {
generateDocs()
kubeconfigFlag()
if err := rootCmd.Execute(); err != nil {
logFailure("%v", err)
logger.Failuref("%v", err)
os.Exit(1)
}
}

View File

@@ -20,11 +20,12 @@ import (
"github.com/spf13/cobra"
)
var syncCmd = &cobra.Command{
Use: "sync",
Short: "Synchronize commands",
var reconcileCmd = &cobra.Command{
Use: "reconcile",
Short: "Reconcile sources and resources",
Long: "The reconcile sub-commands trigger a reconciliation of sources and resources.",
}
func init() {
rootCmd.AddCommand(syncCmd)
rootCmd.AddCommand(reconcileCmd)
}

View File

@@ -0,0 +1,148 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"fmt"
"time"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"
helmv2 "github.com/fluxcd/helm-controller/api/v2alpha1"
)
var reconcileHrCmd = &cobra.Command{
Use: "helmrelease [name]",
Aliases: []string{"hr"},
Short: "Reconcile a HelmRelease resource",
Long: `
The reconcile kustomization command triggers a reconciliation of a HelmRelease resource and waits for it to finish.`,
Example: ` # Trigger a HelmRelease apply outside of the reconciliation interval
tk reconcile hr podinfo
# Trigger a reconciliation of the HelmRelease's source and apply changes
tk reconcile hr podinfo --with-source
`,
RunE: reconcileHrCmdRun,
}
var (
syncHrWithSource bool
)
func init() {
reconcileHrCmd.Flags().BoolVar(&syncHrWithSource, "with-source", false, "reconcile HelmRelease source")
reconcileCmd.AddCommand(reconcileHrCmd)
}
func reconcileHrCmdRun(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("HelmRelease name is required")
}
name := args[0]
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
var helmRelease helmv2.HelmRelease
err = kubeClient.Get(ctx, namespacedName, &helmRelease)
if err != nil {
return err
}
if syncHrWithSource {
err := syncSourceHelmCmdRun(nil, []string{helmRelease.Spec.Chart.SourceRef.Name})
if err != nil {
return err
}
} else {
logger.Actionf("annotating HelmRelease %s in %s namespace", name, namespace)
if helmRelease.Annotations == nil {
helmRelease.Annotations = map[string]string{
helmv2.ReconcileAtAnnotation: time.Now().Format(time.RFC3339Nano),
}
} else {
helmRelease.Annotations[helmv2.ReconcileAtAnnotation] = time.Now().Format(time.RFC3339Nano)
}
if err := kubeClient.Update(ctx, &helmRelease); err != nil {
return err
}
logger.Successf("HelmRelease annotated")
}
logger.Waitingf("waiting for HelmRelease reconciliation")
if err := wait.PollImmediate(pollInterval, timeout,
isHelmReleaseReady(ctx, kubeClient, name, namespace)); err != nil {
return err
}
logger.Successf("HelmRelease reconciliation completed")
err = kubeClient.Get(ctx, namespacedName, &helmRelease)
if err != nil {
return err
}
if helmRelease.Status.LastAppliedRevision != "" {
logger.Successf("reconciled revision %s", helmRelease.Status.LastAppliedRevision)
} else {
return fmt.Errorf("HelmRelease reconciliation failed")
}
return nil
}
func isHelmReleaseReady(ctx context.Context, kubeClient client.Client, name, namespace string) wait.ConditionFunc {
return func() (bool, error) {
var helmRelease helmv2.HelmRelease
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
err := kubeClient.Get(ctx, namespacedName, &helmRelease)
if err != nil {
return false, err
}
for _, condition := range helmRelease.Status.Conditions {
if condition.Type == helmv2.ReadyCondition {
if condition.Status == corev1.ConditionTrue {
return true, nil
} else if condition.Status == corev1.ConditionFalse {
return false, fmt.Errorf(condition.Message)
}
}
}
return false, nil
}
}

View File

@@ -27,19 +27,19 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
)
var syncKsCmd = &cobra.Command{
var reconcileKsCmd = &cobra.Command{
Use: "kustomization [name]",
Aliases: []string{"ks"},
Short: "Synchronize kustomization",
Short: "Reconcile a Kustomization resource",
Long: `
The sync kustomization command triggers a reconciliation of a Kustomization resource and waits for it to finish.`,
Example: ` # Trigger a kustomization apply outside of the reconciliation interval
sync kustomization podinfo
The reconcile kustomization command triggers a reconciliation of a Kustomization resource and waits for it to finish.`,
Example: ` # Trigger a Kustomization apply outside of the reconciliation interval
tk reconcile kustomization podinfo
# Trigger a git sync of the kustomization source and apply changes
sync kustomization podinfo --with-source
# Trigger a sync of the Kustomization's source and apply changes
tk reconcile kustomization podinfo --with-source
`,
RunE: syncKsCmdRun,
RunE: reconcileKsCmdRun,
}
var (
@@ -47,12 +47,12 @@ var (
)
func init() {
syncKsCmd.Flags().BoolVar(&syncKsWithSource, "with-source", false, "synchronize kustomization source")
reconcileKsCmd.Flags().BoolVar(&syncKsWithSource, "with-source", false, "reconcile kustomization source")
syncCmd.AddCommand(syncKsCmd)
reconcileCmd.AddCommand(reconcileKsCmd)
}
func syncKsCmdRun(cmd *cobra.Command, args []string) error {
func reconcileKsCmdRun(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("kustomization name is required")
}
@@ -83,27 +83,27 @@ func syncKsCmdRun(cmd *cobra.Command, args []string) error {
return err
}
} else {
logAction("annotating kustomization %s in %s namespace", name, namespace)
logger.Actionf("annotating kustomization %s in %s namespace", name, namespace)
if kustomization.Annotations == nil {
kustomization.Annotations = map[string]string{
kustomizev1.SyncAtAnnotation: time.Now().String(),
kustomizev1.ReconcileAtAnnotation: time.Now().Format(time.RFC3339Nano),
}
} else {
kustomization.Annotations[kustomizev1.SyncAtAnnotation] = time.Now().String()
kustomization.Annotations[kustomizev1.ReconcileAtAnnotation] = time.Now().Format(time.RFC3339Nano)
}
if err := kubeClient.Update(ctx, &kustomization); err != nil {
return err
}
logSuccess("kustomization annotated")
logger.Successf("kustomization annotated")
}
logWaiting("waiting for kustomization sync")
logger.Waitingf("waiting for kustomization reconciliation")
if err := wait.PollImmediate(pollInterval, timeout,
isKustomizationReady(ctx, kubeClient, name, namespace)); err != nil {
return err
}
logSuccess("kustomization sync completed")
logger.Successf("kustomization reconciliation completed")
err = kubeClient.Get(ctx, namespacedName, &kustomization)
if err != nil {
@@ -111,7 +111,7 @@ func syncKsCmdRun(cmd *cobra.Command, args []string) error {
}
if kustomization.Status.LastAppliedRevision != "" {
logSuccess("applied revision %s", kustomization.Status.LastAppliedRevision)
logger.Successf("reconciled revision %s", kustomization.Status.LastAppliedRevision)
} else {
return fmt.Errorf("kustomization sync failed")
}

View File

@@ -20,11 +20,12 @@ import (
"github.com/spf13/cobra"
)
var syncSourceCmd = &cobra.Command{
var reconcileSourceCmd = &cobra.Command{
Use: "source",
Short: "Synchronize source commands",
Short: "Reconcile sources",
Long: "The reconcile source sub-commands trigger a reconciliation of sources.",
}
func init() {
syncCmd.AddCommand(syncSourceCmd)
reconcileCmd.AddCommand(reconcileSourceCmd)
}

View File

@@ -26,19 +26,18 @@ import (
"time"
)
var syncSourceGitCmd = &cobra.Command{
var reconcileSourceGitCmd = &cobra.Command{
Use: "git [name]",
Short: "Synchronize git source",
Long: `
The sync source command triggers a reconciliation of a GitRepository resource and waits for it to finish.`,
Short: "Reconcile a GitRepository source",
Long: `The reconcile source command triggers a reconciliation of a GitRepository resource and waits for it to finish.`,
Example: ` # Trigger a git pull for an existing source
sync source git podinfo
tk reconcile source git podinfo
`,
RunE: syncSourceGitCmdRun,
}
func init() {
syncSourceCmd.AddCommand(syncSourceGitCmd)
reconcileSourceCmd.AddCommand(reconcileSourceGitCmd)
}
func syncSourceGitCmdRun(cmd *cobra.Command, args []string) error {
@@ -60,7 +59,7 @@ func syncSourceGitCmdRun(cmd *cobra.Command, args []string) error {
Name: name,
}
logAction("annotating source %s in %s namespace", name, namespace)
logger.Actionf("annotating source %s in %s namespace", name, namespace)
var gitRepository sourcev1.GitRepository
err = kubeClient.Get(ctx, namespacedName, &gitRepository)
if err != nil {
@@ -69,23 +68,23 @@ func syncSourceGitCmdRun(cmd *cobra.Command, args []string) error {
if gitRepository.Annotations == nil {
gitRepository.Annotations = map[string]string{
sourcev1.SyncAtAnnotation: time.Now().String(),
sourcev1.ReconcileAtAnnotation: time.Now().Format(time.RFC3339Nano),
}
} else {
gitRepository.Annotations[sourcev1.SyncAtAnnotation] = time.Now().String()
gitRepository.Annotations[sourcev1.ReconcileAtAnnotation] = time.Now().Format(time.RFC3339Nano)
}
if err := kubeClient.Update(ctx, &gitRepository); err != nil {
return err
}
logSuccess("source annotated")
logger.Successf("source annotated")
logWaiting("waiting for git sync")
logger.Waitingf("waiting for reconciliation")
if err := wait.PollImmediate(pollInterval, timeout,
isGitRepositoryReady(ctx, kubeClient, name, namespace)); err != nil {
return err
}
logSuccess("git sync completed")
logger.Successf("git reconciliation completed")
err = kubeClient.Get(ctx, namespacedName, &gitRepository)
if err != nil {
@@ -93,9 +92,9 @@ func syncSourceGitCmdRun(cmd *cobra.Command, args []string) error {
}
if gitRepository.Status.Artifact != nil {
logSuccess("fetched revision: %s", gitRepository.Status.Artifact.Revision)
logger.Successf("fetched revision %s", gitRepository.Status.Artifact.Revision)
} else {
return fmt.Errorf("git sync failed, artifact not found")
return fmt.Errorf("git reconciliation failed, artifact not found")
}
return nil
}

View File

@@ -0,0 +1,130 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"fmt"
"time"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
)
var reconcileSourceHelmCmd = &cobra.Command{
Use: "helm [name]",
Short: "Reconcile a HelmRepository source",
Long: `The reconcile source command triggers a reconciliation of a HelmRepository resource and waits for it to finish.`,
Example: ` # Trigger a reconciliation for an existing source
tk reconcile source helm podinfo
`,
RunE: syncSourceHelmCmdRun,
}
func init() {
reconcileSourceCmd.AddCommand(reconcileSourceHelmCmd)
}
func syncSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("source name is required")
}
name := args[0]
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
logger.Actionf("annotating source %s in %s namespace", name, namespace)
var helmRepository sourcev1.HelmRepository
err = kubeClient.Get(ctx, namespacedName, &helmRepository)
if err != nil {
return err
}
if helmRepository.Annotations == nil {
helmRepository.Annotations = map[string]string{
sourcev1.ReconcileAtAnnotation: time.Now().Format(time.RFC3339Nano),
}
} else {
helmRepository.Annotations[sourcev1.ReconcileAtAnnotation] = time.Now().Format(time.RFC3339Nano)
}
if err := kubeClient.Update(ctx, &helmRepository); err != nil {
return err
}
logger.Successf("source annotated")
logger.Waitingf("waiting for reconciliation")
if err := wait.PollImmediate(pollInterval, timeout,
isHelmRepositoryReady(ctx, kubeClient, name, namespace)); err != nil {
return err
}
logger.Successf("helm reconciliation completed")
err = kubeClient.Get(ctx, namespacedName, &helmRepository)
if err != nil {
return err
}
if helmRepository.Status.Artifact != nil {
logger.Successf("fetched revision %s", helmRepository.Status.Artifact.Revision)
} else {
return fmt.Errorf("helm reconciliation failed, artifact not found")
}
return nil
}
func isHelmRepositoryReady(ctx context.Context, kubeClient client.Client, name, namespace string) wait.ConditionFunc {
return func() (bool, error) {
var helmRepository sourcev1.HelmRepository
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
err := kubeClient.Get(ctx, namespacedName, &helmRepository)
if err != nil {
return false, err
}
for _, condition := range helmRepository.Status.Conditions {
if condition.Type == sourcev1.ReadyCondition {
if condition.Status == corev1.ConditionTrue {
return true, nil
} else if condition.Status == corev1.ConditionFalse {
return false, fmt.Errorf(condition.Message)
}
}
}
return false, nil
}
}

View File

@@ -22,7 +22,8 @@ import (
var resumeCmd = &cobra.Command{
Use: "resume",
Short: "Resume commands",
Short: "Resume suspended resources",
Long: "The resume sub-commands resume a suspended resource.",
}
func init() {

View File

@@ -0,0 +1,129 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"fmt"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"
helmv2 "github.com/fluxcd/helm-controller/api/v2alpha1"
)
var resumeHrCmd = &cobra.Command{
Use: "helmrelease [name]",
Aliases: []string{"hr"},
Short: "Resume a suspended HelmRelease",
Long: `The resume command marks a previously suspended HelmRelease resource for reconciliation and waits for it to
finish the apply.`,
Example: ` # Resume reconciliation for an existing Helm release
tk resume hr podinfo
`,
RunE: resumeHrCmdRun,
}
func init() {
resumeCmd.AddCommand(resumeHrCmd)
}
func resumeHrCmdRun(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("HelmRelease name is required")
}
name := args[0]
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
var helmRelease helmv2.HelmRelease
err = kubeClient.Get(ctx, namespacedName, &helmRelease)
if err != nil {
return err
}
logger.Actionf("resuming HelmRelease %s in %s namespace", name, namespace)
helmRelease.Spec.Suspend = false
if err := kubeClient.Update(ctx, &helmRelease); err != nil {
return err
}
logger.Successf("HelmRelease resumed")
logger.Waitingf("waiting for HelmRelease reconciliation")
if err := wait.PollImmediate(pollInterval, timeout,
isHelmReleaseResumed(ctx, kubeClient, name, namespace)); err != nil {
return err
}
logger.Successf("HelmRelease reconciliation completed")
err = kubeClient.Get(ctx, namespacedName, &helmRelease)
if err != nil {
return err
}
if helmRelease.Status.LastAppliedRevision != "" {
logger.Successf("applied revision %s", helmRelease.Status.LastAppliedRevision)
} else {
return fmt.Errorf("HelmRelease reconciliation failed")
}
return nil
}
func isHelmReleaseResumed(ctx context.Context, kubeClient client.Client, name, namespace string) wait.ConditionFunc {
return func() (bool, error) {
var helmRelease helmv2.HelmRelease
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
err := kubeClient.Get(ctx, namespacedName, &helmRelease)
if err != nil {
return false, err
}
for _, condition := range helmRelease.Status.Conditions {
if condition.Type == helmv2.ReadyCondition {
if condition.Status == corev1.ConditionTrue {
return true, nil
} else if condition.Status == corev1.ConditionFalse {
if condition.Reason == helmv2.SuspendedReason {
return false, nil
}
return false, fmt.Errorf(condition.Message)
}
}
}
return false, nil
}
}

View File

@@ -32,9 +32,13 @@ import (
var resumeKsCmd = &cobra.Command{
Use: "kustomization [name]",
Aliases: []string{"ks"},
Short: "Resume kustomization",
Long: "The resume command marks a previously suspended Kustomization resource for reconciliation and waits for it to finish the apply.",
RunE: resumeKsCmdRun,
Short: "Resume a suspended Kustomization",
Long: `The resume command marks a previously suspended Kustomization resource for reconciliation and waits for it to
finish the apply.`,
Example: ` # Resume reconciliation for an existing Kustomization
tk resume ks podinfo
`,
RunE: resumeKsCmdRun,
}
func init() {
@@ -65,20 +69,20 @@ func resumeKsCmdRun(cmd *cobra.Command, args []string) error {
return err
}
logAction("resuming kustomization %s in %s namespace", name, namespace)
logger.Actionf("resuming kustomization %s in %s namespace", name, namespace)
kustomization.Spec.Suspend = false
if err := kubeClient.Update(ctx, &kustomization); err != nil {
return err
}
logSuccess("kustomization resumed")
logger.Successf("kustomization resumed")
logWaiting("waiting for kustomization sync")
logger.Waitingf("waiting for kustomization sync")
if err := wait.PollImmediate(pollInterval, timeout,
isKustomizationResumed(ctx, kubeClient, name, namespace)); err != nil {
return err
}
logSuccess("kustomization sync completed")
logger.Successf("kustomization sync completed")
err = kubeClient.Get(ctx, namespacedName, &kustomization)
if err != nil {
@@ -86,7 +90,7 @@ func resumeKsCmdRun(cmd *cobra.Command, args []string) error {
}
if kustomization.Status.LastAppliedRevision != "" {
logSuccess("applied revision %s", kustomization.Status.LastAppliedRevision)
logger.Successf("applied revision %s", kustomization.Status.LastAppliedRevision)
} else {
return fmt.Errorf("kustomization sync failed")
}

View File

@@ -22,7 +22,8 @@ import (
var suspendCmd = &cobra.Command{
Use: "suspend",
Short: "Suspend commands",
Short: "Suspend resources",
Long: "The suspend sub-commands suspend the reconciliation of a resource.",
}
func init() {

View File

@@ -0,0 +1,76 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"fmt"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types"
helmv2 "github.com/fluxcd/helm-controller/api/v2alpha1"
)
var suspendHrCmd = &cobra.Command{
Use: "helmrelease [name]",
Aliases: []string{"hr"},
Short: "Suspend reconciliation of HelmRelease",
Long: "The suspend command disables the reconciliation of a HelmRelease resource.",
Example: ` # Suspend reconciliation for an existing Helm release
tk suspend hr podinfo
`,
RunE: suspendHrCmdRun,
}
func init() {
suspendCmd.AddCommand(suspendHrCmd)
}
func suspendHrCmdRun(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("HelmRelease name is required")
}
name := args[0]
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
var helmRelease helmv2.HelmRelease
err = kubeClient.Get(ctx, namespacedName, &helmRelease)
if err != nil {
return err
}
logger.Actionf("suspending HelmRelease %s in %s namespace", name, namespace)
helmRelease.Spec.Suspend = true
if err := kubeClient.Update(ctx, &helmRelease); err != nil {
return err
}
logger.Successf("HelmRelease suspended")
return nil
}

View File

@@ -27,9 +27,12 @@ import (
var suspendKsCmd = &cobra.Command{
Use: "kustomization [name]",
Aliases: []string{"ks"},
Short: "Suspend kustomization",
Short: "Suspend reconciliation of Kustomization",
Long: "The suspend command disables the reconciliation of a Kustomization resource.",
RunE: suspendKsCmdRun,
Example: ` # Suspend reconciliation for an existing Kustomization
tk suspend ks podinfo
`,
RunE: suspendKsCmdRun,
}
func init() {
@@ -60,12 +63,12 @@ func suspendKsCmdRun(cmd *cobra.Command, args []string) error {
return err
}
logAction("suspending kustomization %s in %s namespace", name, namespace)
logger.Actionf("suspending kustomization %s in %s namespace", name, namespace)
kustomization.Spec.Suspend = true
if err := kubeClient.Update(ctx, &kustomization); err != nil {
return err
}
logSuccess("kustomization suspended")
logger.Successf("kustomization suspended")
return nil
}

View File

@@ -28,14 +28,12 @@ import (
var uninstallCmd = &cobra.Command{
Use: "uninstall",
Short: "Uninstall the toolkit components",
Long: `
The uninstall command removes the namespace, cluster roles,
cluster role bindings and CRDs.`,
Long: "The uninstall command removes the namespace, cluster roles, cluster role bindings and CRDs from the cluster.",
Example: ` # Dry-run uninstall of all components
uninstall --dry-run --namespace=gitops-system
tk uninstall --dry-run --namespace=gitops-system
# Uninstall all components and delete custom resource definitions
uninstall --crds --namespace=gitops-system
tk uninstall --crds --namespace=gitops-system
`,
RunE: uninstallCmdRun,
}
@@ -49,7 +47,7 @@ var (
func init() {
uninstallCmd.Flags().BoolVarP(&uninstallKustomizations, "kustomizations", "", false,
"removes all kustomizations previously installed")
"removes all Kustomizations previously installed")
uninstallCmd.Flags().BoolVarP(&uninstallCRDs, "crds", "", false,
"removes all CRDs previously installed")
uninstallCmd.Flags().BoolVarP(&uninstallDryRun, "dry-run", "", false,
@@ -78,7 +76,7 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error {
}
if uninstallKustomizations {
logAction("uninstalling kustomizations")
logger.Actionf("uninstalling kustomizations")
command := fmt.Sprintf("kubectl -n %s delete kustomizations --all --timeout=%s %s",
namespace, timeout.String(), dryRun)
if _, err := utils.execCommand(ctx, ModeOS, command); err != nil {
@@ -87,7 +85,7 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error {
// TODO: use the kustomizations snapshots to create a list of objects
// that are subject to deletion and wait for all of them to be terminated
logWaiting("waiting on GC")
logger.Waitingf("waiting on GC")
time.Sleep(30 * time.Second)
}
@@ -96,13 +94,13 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error {
kinds += ",crds"
}
logAction("uninstalling components")
logger.Actionf("uninstalling components")
command := fmt.Sprintf("kubectl delete %s -l app.kubernetes.io/instance=%s --timeout=%s %s",
kinds, namespace, timeout.String(), dryRun)
if _, err := utils.execCommand(ctx, ModeOS, command); err != nil {
return fmt.Errorf("uninstall failed")
}
logSuccess("uninstall finished")
logger.Successf("uninstall finished")
return nil
}

View File

@@ -26,12 +26,14 @@ import (
"os/exec"
"text/template"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1alpha1"
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/controller-runtime/pkg/client"
helmv2 "github.com/fluxcd/helm-controller/api/v2alpha1"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1alpha1"
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
)
type Utils struct {
@@ -118,6 +120,7 @@ func (*Utils) kubeClient(config string) (client.Client, error) {
_ = corev1.AddToScheme(scheme)
_ = sourcev1.AddToScheme(scheme)
_ = kustomizev1.AddToScheme(scheme)
_ = helmv2.AddToScheme(scheme)
kubeClient, err := client.New(cfg, client.Options{
Scheme: scheme,
@@ -143,3 +146,32 @@ func (*Utils) writeFile(content, filename string) error {
return file.Sync()
}
func (*Utils) copyFile(src, dst string) error {
in, err := os.Open(src)
if err != nil {
return err
}
defer in.Close()
out, err := os.Create(dst)
if err != nil {
return err
}
defer out.Close()
_, err = io.Copy(out, in)
if err != nil {
return err
}
return out.Close()
}
func (*Utils) containsItemString(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

View File

@@ -21,42 +21,42 @@ Command line utility for assembling Kubernetes CD pipelines the GitOps way.
--branch=master \
--interval=3m
# List git sources and their status
# List GitRepository sources and their status
tk get sources git
# Trigger a git sync
# Trigger a GitRepository source sync
tk sync source git webapp-latest
# Export git sources in YAML format
# Export GitRepository sources in YAML format
tk export source git --all > sources.yaml
# Create a kustomization for deploying a series of microservices
# Create a Kustomization for deploying a series of microservices
tk create kustomization webapp-dev \
--source=webapp-latest \
--path="./deploy/webapp/" \
--prune=true \
--interval=5m \
--validate=client \
--validation=client \
--health-check="Deployment/backend.webapp" \
--health-check="Deployment/frontend.webapp" \
--health-check-timeout=2m
# Trigger a git sync and apply changes if any
tk sync kustomization webapp-dev --with-source
# Trigger a git sync of the Kustomization's source and apply changes
tk reconcile kustomization webapp-dev --with-source
# Suspend a kustomization reconciliation
# Suspend a Kustomization reconciliation
tk suspend kustomization webapp-dev
# Export kustomizations in YAML format
# Export Kustomizations in YAML format
tk export kustomization --all > kustomizations.yaml
# Resume a kustomization reconciliation
# Resume a Kustomization reconciliation
tk resume kustomization webapp-dev
# Delete a kustomization
# Delete a Kustomization
tk delete kustomization webapp-dev
# Delete a git source
# Delete a GitRepository source
tk delete source git webapp-latest
# Uninstall the toolkit and delete CRDs
@@ -67,26 +67,25 @@ Command line utility for assembling Kubernetes CD pipelines the GitOps way.
### Options
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
-h, --help help for tk
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
-h, --help help for tk
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk bootstrap](tk_bootstrap.md) - Bootstrap commands
* [tk bootstrap](tk_bootstrap.md) - Bootstrap toolkit components
* [tk check](tk_check.md) - Check requirements and installation
* [tk completion](tk_completion.md) - Generates bash completion scripts
* [tk create](tk_create.md) - Create commands
* [tk delete](tk_delete.md) - Delete commands
* [tk export](tk_export.md) - Export commands
* [tk get](tk_get.md) - Get commands
* [tk create](tk_create.md) - Create or update sources and resources
* [tk delete](tk_delete.md) - Delete sources and resources
* [tk export](tk_export.md) - Export resources in YAML format
* [tk get](tk_get.md) - Get sources and resources
* [tk install](tk_install.md) - Install the toolkit components
* [tk resume](tk_resume.md) - Resume commands
* [tk suspend](tk_suspend.md) - Suspend commands
* [tk sync](tk_sync.md) - Synchronize commands
* [tk reconcile](tk_reconcile.md) - Reconcile sources and resources
* [tk resume](tk_resume.md) - Resume suspended resources
* [tk suspend](tk_suspend.md) - Suspend resources
* [tk uninstall](tk_uninstall.md) - Uninstall the toolkit components

View File

@@ -1,31 +1,31 @@
## tk bootstrap
Bootstrap commands
Bootstrap toolkit components
### Synopsis
Bootstrap commands
The bootstrap sub-commands bootstrap the toolkit components on the targeted Git provider.
### Options
```
-h, --help help for bootstrap
--version string toolkit tag or branch (default "master")
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
-h, --help help for bootstrap
-v, --version string toolkit version (default "latest")
```
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk](tk.md) - Command line utility for assembling Kubernetes CD pipelines
* [tk bootstrap github](tk_bootstrap_github.md) - Bootstrap GitHub repository
* [tk bootstrap gitlab](tk_bootstrap_gitlab.md) - Bootstrap GitLab repository
* [tk bootstrap github](tk_bootstrap_github.md) - Bootstrap toolkit components in a GitHub repository
* [tk bootstrap gitlab](tk_bootstrap_gitlab.md) - Bootstrap toolkit components in a GitLab repository

View File

@@ -1,13 +1,12 @@
## tk bootstrap github
Bootstrap GitHub repository
Bootstrap toolkit components in a GitHub repository
### Synopsis
The bootstrap command creates the GitHub repository if it doesn't exists and
The bootstrap github command creates the GitHub repository if it doesn't exists and
commits the toolkit components manifests to the master branch.
Then it configure the target cluster to synchronize with the repository.
Then it configures the target cluster to synchronize with the repository.
If the toolkit components are present on the cluster,
the bootstrap command will perform an upgrade if needed.
@@ -22,19 +21,19 @@ tk bootstrap github [flags]
export GITHUB_TOKEN=<my-token>
# Run bootstrap for a private repo owned by a GitHub organization
bootstrap github --owner=<organization> --repository=<repo name>
tk bootstrap github --owner=<organization> --repository=<repo name>
# Run bootstrap for a private repo and assign organization teams to it
bootstrap github --owner=<organization> --repository=<repo name> --team=<team1 slug> --team=<team2 slug>
tk bootstrap github --owner=<organization> --repository=<repo name> --team=<team1 slug> --team=<team2 slug>
# Run bootstrap for a repository path
bootstrap github --owner=<organization> --repository=<repo name> --path=dev-cluster
tk bootstrap github --owner=<organization> --repository=<repo name> --path=dev-cluster
# Run bootstrap for a public repository on a personal account
bootstrap github --owner=<user> --repository=<repo name> --private=false --personal=true
tk bootstrap github --owner=<user> --repository=<repo name> --private=false --personal=true
# Run bootstrap for a private repo hosted on GitHub Enterprise
bootstrap github --owner=<organization> --repository=<repo name> --hostname=<domain>
tk bootstrap github --owner=<organization> --repository=<repo name> --hostname=<domain>
```
@@ -55,15 +54,15 @@ tk bootstrap github [flags]
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--version string toolkit tag or branch (default "master")
-v, --version string toolkit version (default "latest")
```
### SEE ALSO
* [tk bootstrap](tk_bootstrap.md) - Bootstrap commands
* [tk bootstrap](tk_bootstrap.md) - Bootstrap toolkit components

View File

@@ -1,13 +1,12 @@
## tk bootstrap gitlab
Bootstrap GitLab repository
Bootstrap toolkit components in a GitLab repository
### Synopsis
The bootstrap command creates the GitLab repository if it doesn't exists and
The bootstrap gitlab command creates the GitLab repository if it doesn't exists and
commits the toolkit components manifests to the master branch.
Then it configure the target cluster to synchronize with the repository.
Then it configures the target cluster to synchronize with the repository.
If the toolkit components are present on the cluster,
the bootstrap command will perform an upgrade if needed.
@@ -22,16 +21,16 @@ tk bootstrap gitlab [flags]
export GITLAB_TOKEN=<my-token>
# Run bootstrap for a private repo owned by a GitLab group
bootstrap gitlab --owner=<group> --repository=<repo name>
tk bootstrap gitlab --owner=<group> --repository=<repo name>
# Run bootstrap for a repository path
bootstrap gitlab --owner=<group> --repository=<repo name> --path=dev-cluster
tk bootstrap gitlab --owner=<group> --repository=<repo name> --path=dev-cluster
# Run bootstrap for a public repository on a personal account
bootstrap gitlab --owner=<user> --repository=<repo name> --private=false --personal=true
tk bootstrap gitlab --owner=<user> --repository=<repo name> --private=false --personal=true
# Run bootstrap for a private repo hosted on a GitLab server
bootstrap gitlab --owner=<group> --repository=<repo name> --hostname=<domain>
tk bootstrap gitlab --owner=<group> --repository=<repo name> --hostname=<domain>
```
@@ -51,15 +50,15 @@ tk bootstrap gitlab [flags]
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--version string toolkit tag or branch (default "master")
-v, --version string toolkit version (default "latest")
```
### SEE ALSO
* [tk bootstrap](tk_bootstrap.md) - Bootstrap commands
* [tk bootstrap](tk_bootstrap.md) - Bootstrap toolkit components

View File

@@ -4,7 +4,6 @@ Check requirements and installation
### Synopsis
The check command will perform a series of checks to validate that
the local environment is configured correctly and if the installed components are healthy.
@@ -16,28 +15,28 @@ tk check [flags]
```
# Run pre-installation checks
check --pre
tk check --pre
# Run installation checks
check
tk check
```
### Options
```
-h, --help help for check
--pre only run pre-installation checks
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
-h, --help help for check
--pre only run pre-installation checks
```
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO

View File

@@ -33,11 +33,10 @@ To configure your bash shell to load completions for each session add to your ba
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO

View File

@@ -1,15 +1,15 @@
## tk create
Create commands
Create or update sources and resources
### Synopsis
Create commands
The create sub-commands generate sources and resources.
### Options
```
--export export in yaml format to stdout
--export export in YAML format to stdout
-h, --help help for create
--interval duration source sync interval (default 1m0s)
```
@@ -17,16 +17,16 @@ Create commands
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk](tk.md) - Command line utility for assembling Kubernetes CD pipelines
* [tk create kustomization](tk_create_kustomization.md) - Create or update a kustomization resource
* [tk create source](tk_create_source.md) - Create source commands
* [tk create helmrelease](tk_create_helmrelease.md) - Create or update a HelmRelease resource
* [tk create kustomization](tk_create_kustomization.md) - Create or update a Kustomization resource
* [tk create source](tk_create_source.md) - Create or update sources

View File

@@ -0,0 +1,71 @@
## tk create helmrelease
Create or update a HelmRelease resource
### Synopsis
The helmrelease create command generates a HelmRelease resource for a given HelmRepository source.
```
tk create helmrelease [name] [flags]
```
### Examples
```
# Create a HelmRelease from a source
tk create hr podinfo \
--interval=10m \
--release-name=podinfo \
--target-namespace=default \
--source=podinfo \
--chart-name=podinfo \
--chart-version=">4.0.0"
# Create a HelmRelease with values for a local YAML file
tk create hr podinfo \
--target-namespace=default \
--source=podinfo \
--chart-name=podinfo \
--chart-version=4.0.5 \
--values=./my-values.yaml
# Create a HelmRelease definition on disk without applying it on the cluster
tk create hr podinfo \
--target-namespace=default \
--source=podinfo \
--chart-name=podinfo \
--chart-version=4.0.5 \
--values=./values.yaml \
--export > podinfo-release.yaml
```
### Options
```
--chart-name string Helm chart name
--chart-version string Helm chart version, accepts semver range
--depends-on stringArray HelmReleases that must be ready before this release can be installed
-h, --help help for helmrelease
--release-name string name used for the Helm release, defaults to a composition of '<target-namespace>-<hr-name>'
--source string HelmRepository name
--target-namespace string namespace to install this release, defaults to the HelmRelease namespace
--values string local path to the values.yaml file
```
### Options inherited from parent commands
```
--export export in YAML format to stdout
--interval duration source sync interval (default 1m0s)
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk create](tk_create.md) - Create or update sources and resources

View File

@@ -1,12 +1,10 @@
## tk create kustomization
Create or update a kustomization resource
Create or update a Kustomization resource
### Synopsis
The kustomization source command generates a kustomization.kustomize.fluxcd.io resource for a given GitRepository source.
API spec: https://github.com/fluxcd/kustomize-controller/tree/master/docs/spec/v1alpha1
The kustomization source create command generates a Kustomize resource for a given GitRepository source.
```
tk create kustomization [name] [flags]
@@ -15,33 +13,33 @@ tk create kustomization [name] [flags]
### Examples
```
# Create a kustomization from a source at a given path
create kustomization contour \
# Create a Kustomization resource from a source at a given path
tk create kustomization contour \
--source=contour \
--path="./examples/contour/" \
--prune=true \
--interval=10m \
--validate=client \
--validation=client \
--health-check="Deployment/contour.projectcontour" \
--health-check="DaemonSet/envoy.projectcontour" \
--health-check-timeout=3m
# Create a kustomization that depends on the previous one
create kustomization webapp \
# Create a Kustomization resource that depends on the previous one
tk create kustomization webapp \
--depends-on=contour \
--source=webapp \
--path="./deploy/overlays/dev" \
--prune=true \
--interval=5m \
--validate=client
--validation=client
# Create a kustomization that runs under a service account
create kustomization webapp \
# Create a Kustomization resource that runs under a service account
tk create kustomization webapp \
--source=webapp \
--path="./deploy/overlays/staging" \
--prune=true \
--interval=5m \
--validate=client \
--validation=client \
--sa-name=reconclier \
--sa-namespace=staging
@@ -50,31 +48,30 @@ tk create kustomization [name] [flags]
### Options
```
--depends-on stringArray kustomization that must be ready before this kustomization can be applied
--depends-on stringArray Kustomization that must be ready before this Kustomization can be applied
--health-check stringArray workload to be included in the health assessment, in the format '<kind>/<name>.<namespace>'
--health-check-timeout duration timeout of health checking operations (default 2m0s)
-h, --help help for kustomization
--path string path to the directory containing the kustomization file (default "./")
--path string path to the directory containing the Kustomization file (default "./")
--prune enable garbage collection
--sa-name string service account name
--sa-namespace string service account namespace
--source string GitRepository name
--validate string validate the manifests before applying them on the cluster, can be 'client' or 'server'
--validation string validate the manifests before applying them on the cluster, can be 'client' or 'server'
```
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--export export in yaml format to stdout
--interval duration source sync interval (default 1m0s)
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--export export in YAML format to stdout
--interval duration source sync interval (default 1m0s)
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk create](tk_create.md) - Create commands
* [tk create](tk_create.md) - Create or update sources and resources

View File

@@ -1,10 +1,10 @@
## tk create source
Create source commands
Create or update sources
### Synopsis
Create source commands
The create source sub-commands generate sources.
### Options
@@ -15,17 +15,17 @@ Create source commands
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--export export in yaml format to stdout
--interval duration source sync interval (default 1m0s)
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--export export in YAML format to stdout
--interval duration source sync interval (default 1m0s)
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk create](tk_create.md) - Create commands
* [tk create source git](tk_create_source_git.md) - Create or update a git source
* [tk create](tk_create.md) - Create or update sources and resources
* [tk create source git](tk_create_source_git.md) - Create or update a GitRepository source
* [tk create source helm](tk_create_source_helm.md) - Create or update a HelmRepository source

View File

@@ -1,11 +1,11 @@
## tk create source git
Create or update a git source
Create or update a GitRepository source
### Synopsis
The create source command generates a GitRepository resource and waits for it to sync.
The create source git command generates a GitRepository resource and waits for it to sync.
For Git over SSH, host and SSH keys are automatically generated and stored in a Kubernetes secret.
For private Git repositories, the basic authentication credentials are stored in a Kubernetes secret.
@@ -17,35 +17,35 @@ tk create source git [name] [flags]
```
# Create a source from a public Git repository master branch
create source git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--branch=master
# Create a source from a Git repository pinned to specific git tag
create source git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--tag="3.2.3"
# Create a source from a public Git repository tag that matches a semver range
create source git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--tag-semver=">=3.2.0 <3.3.0"
# Create a source from a Git repository using SSH authentication
create source git podinfo \
tk create source git podinfo \
--url=ssh://git@github.com/stefanprodan/podinfo \
--branch=master
# Create a source from a Git repository using SSH authentication and an
# ECDSA P-521 curve public key
create source git podinfo \
tk create source git podinfo \
--url=ssh://git@github.com/stefanprodan/podinfo \
--branch=master \
--ssh-key-algorithm=ecdsa \
--ssh-ecdsa-curve=p521
# Create a source from a Git repository using basic authentication
create source git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--username=username \
--password=password
@@ -70,16 +70,15 @@ tk create source git [name] [flags]
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--export export in yaml format to stdout
--interval duration source sync interval (default 1m0s)
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--export export in YAML format to stdout
--interval duration source sync interval (default 1m0s)
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk create source](tk_create_source.md) - Create source commands
* [tk create source](tk_create_source.md) - Create or update sources

View File

@@ -0,0 +1,54 @@
## tk create source helm
Create or update a HelmRepository source
### Synopsis
The create source helm command generates a HelmRepository resource and waits for it to fetch the index.
For private Helm repositories, the basic authentication credentials are stored in a Kubernetes secret.
```
tk create source helm [name] [flags]
```
### Examples
```
# Create a source from a public Helm repository
tk create source helm podinfo \
--url=https://stefanprodan.github.io/podinfo \
--interval=10m
# Create a source from a Helm repository using basic authentication
tk create source helm podinfo \
--url=https://stefanprodan.github.io/podinfo \
--username=username \
--password=password
```
### Options
```
-h, --help help for helm
-p, --password string basic authentication password
--url string Helm repository address
-u, --username string basic authentication username
```
### Options inherited from parent commands
```
--export export in YAML format to stdout
--interval duration source sync interval (default 1m0s)
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk create source](tk_create_source.md) - Create or update sources

View File

@@ -1,10 +1,10 @@
## tk delete
Delete commands
Delete sources and resources
### Synopsis
Delete commands
The delete sub-commands delete sources and resources.
### Options
@@ -16,16 +16,16 @@ Delete commands
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk](tk.md) - Command line utility for assembling Kubernetes CD pipelines
* [tk delete kustomization](tk_delete_kustomization.md) - Delete kustomization
* [tk delete source](tk_delete_source.md) - Delete sources commands
* [tk delete helmrelease](tk_delete_helmrelease.md) - Delete a HelmRelease resource
* [tk delete kustomization](tk_delete_kustomization.md) - Delete a Kustomization resource
* [tk delete source](tk_delete_source.md) - Delete sources

View File

@@ -0,0 +1,40 @@
## tk delete helmrelease
Delete a HelmRelease resource
### Synopsis
The delete helmrelease command removes the given HelmRelease from the cluster.
```
tk delete helmrelease [name] [flags]
```
### Examples
```
# Delete a Helm release and the Kubernetes resources created by it
tk delete hr podinfo
```
### Options
```
-h, --help help for helmrelease
```
### Options inherited from parent commands
```
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
-s, --silent delete resource without asking for confirmation
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk delete](tk_delete.md) - Delete sources and resources

View File

@@ -1,15 +1,23 @@
## tk delete kustomization
Delete kustomization
Delete a Kustomization resource
### Synopsis
Delete kustomization
The delete kustomization command deletes the given Kustomization from the cluster.
```
tk delete kustomization [name] [flags]
```
### Examples
```
# Delete a kustomization and the Kubernetes resources created by it
tk delete kustomization podinfo
```
### Options
```
@@ -19,15 +27,14 @@ tk delete kustomization [name] [flags]
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
-s, --silent delete resource without asking for confirmation
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
-s, --silent delete resource without asking for confirmation
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk delete](tk_delete.md) - Delete commands
* [tk delete](tk_delete.md) - Delete sources and resources

View File

@@ -1,10 +1,10 @@
## tk delete source
Delete sources commands
Delete sources
### Synopsis
Delete sources commands
The delete source sub-commands delete sources.
### Options
@@ -15,16 +15,16 @@ Delete sources commands
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
-s, --silent delete resource without asking for confirmation
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
-s, --silent delete resource without asking for confirmation
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk delete](tk_delete.md) - Delete commands
* [tk delete source git](tk_delete_source_git.md) - Delete git source
* [tk delete](tk_delete.md) - Delete sources and resources
* [tk delete source git](tk_delete_source_git.md) - Delete a GitRepository source
* [tk delete source helm](tk_delete_source_helm.md) - Delete a HelmRepository source

View File

@@ -1,15 +1,23 @@
## tk delete source git
Delete git source
Delete a GitRepository source
### Synopsis
Delete git source
The delete source git command deletes the given GitRepository from the cluster.
```
tk delete source git [name] [flags]
```
### Examples
```
# Delete a Git repository
tk delete source git podinfo
```
### Options
```
@@ -19,15 +27,14 @@ tk delete source git [name] [flags]
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
-s, --silent delete resource without asking for confirmation
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
-s, --silent delete resource without asking for confirmation
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk delete source](tk_delete_source.md) - Delete sources commands
* [tk delete source](tk_delete_source.md) - Delete sources

View File

@@ -0,0 +1,40 @@
## tk delete source helm
Delete a HelmRepository source
### Synopsis
The delete source helm command deletes the given HelmRepository from the cluster.
```
tk delete source helm [name] [flags]
```
### Examples
```
# Delete a Helm repository
tk delete source helm podinfo
```
### Options
```
-h, --help help for helm
```
### Options inherited from parent commands
```
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
-s, --silent delete resource without asking for confirmation
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk delete source](tk_delete_source.md) - Delete sources

View File

@@ -1,10 +1,10 @@
## tk export
Export commands
Export resources in YAML format
### Synopsis
Export commands
The export sub-commands export resources in YAML format.
### Options
@@ -16,16 +16,16 @@ Export commands
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk](tk.md) - Command line utility for assembling Kubernetes CD pipelines
* [tk export kustomization](tk_export_kustomization.md) - Export kustomization in YAML format
* [tk export source](tk_export_source.md) - Export source commands
* [tk export helmrelease](tk_export_helmrelease.md) - Export HelmRelease resources in YAML format
* [tk export kustomization](tk_export_kustomization.md) - Export Kustomization resources in YAML format
* [tk export source](tk_export_source.md) - Export sources

View File

@@ -0,0 +1,43 @@
## tk export helmrelease
Export HelmRelease resources in YAML format
### Synopsis
The export helmrelease command exports one or all HelmRelease resources in YAML format.
```
tk export helmrelease [name] [flags]
```
### Examples
```
# Export all HelmRelease resources
tk export helmrelease --all > kustomizations.yaml
# Export a HelmRelease
tk export hr my-app > app-release.yaml
```
### Options
```
-h, --help help for helmrelease
```
### Options inherited from parent commands
```
--all select all resources
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk export](tk_export.md) - Export resources in YAML format

View File

@@ -1,10 +1,10 @@
## tk export kustomization
Export kustomization in YAML format
Export Kustomization resources in YAML format
### Synopsis
Export kustomization in YAML format
The export kustomization command exports one or all Kustomization resources in YAML format.
```
tk export kustomization [name] [flags]
@@ -13,11 +13,11 @@ tk export kustomization [name] [flags]
### Examples
```
# Export all kustomizations
export kustomization --all > kustomizations.yaml
# Export all Kustomization resources
tk export kustomization --all > kustomizations.yaml
# Export a kustomization
export kustomization my-app > kustomization.yaml
# Export a Kustomization
tk export kustomization my-app > kustomization.yaml
```
@@ -30,15 +30,14 @@ tk export kustomization [name] [flags]
### Options inherited from parent commands
```
--all select all resources
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--all select all resources
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk export](tk_export.md) - Export commands
* [tk export](tk_export.md) - Export resources in YAML format

View File

@@ -1,10 +1,10 @@
## tk export source
Export source commands
Export sources
### Synopsis
Export source commands
The export source sub-commands export sources in YAML format.
### Options
@@ -16,16 +16,16 @@ Export source commands
### Options inherited from parent commands
```
--all select all resources
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--all select all resources
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk export](tk_export.md) - Export commands
* [tk export source git](tk_export_source_git.md) - Export git sources in YAML format
* [tk export](tk_export.md) - Export resources in YAML format
* [tk export source git](tk_export_source_git.md) - Export GitRepository sources in YAML format
* [tk export source helm](tk_export_source_helm.md) - Export HelmRepository sources in YAML format

View File

@@ -1,10 +1,10 @@
## tk export source git
Export git sources in YAML format
Export GitRepository sources in YAML format
### Synopsis
Export git sources in YAML format
The export source git command exports on or all GitRepository sources in YAML format.
```
tk export source git [name] [flags]
@@ -13,11 +13,11 @@ tk export source git [name] [flags]
### Examples
```
# Export all git sources
export source git --all > sources.yaml
# Export all GitRepository sources
tk export source git --all > sources.yaml
# Export a git source including the SSH keys or basic auth credentials
export source git my-private-repo --with-credentials > source.yaml
# Export a GitRepository source including the SSH key pair or basic auth credentials
tk export source git my-private-repo --with-credentials > source.yaml
```
@@ -30,16 +30,15 @@ tk export source git [name] [flags]
### Options inherited from parent commands
```
--all select all resources
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--with-credentials include credential secrets
--all select all resources
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--with-credentials include credential secrets
```
### SEE ALSO
* [tk export source](tk_export_source.md) - Export source commands
* [tk export source](tk_export_source.md) - Export sources

View File

@@ -0,0 +1,44 @@
## tk export source helm
Export HelmRepository sources in YAML format
### Synopsis
The export source git command exports on or all HelmRepository sources in YAML format.
```
tk export source helm [name] [flags]
```
### Examples
```
# Export all HelmRepository sources
tk export source helm --all > sources.yaml
# Export a HelmRepository source including the basic auth credentials
tk export source helm my-private-repo --with-credentials > source.yaml
```
### Options
```
-h, --help help for helm
```
### Options inherited from parent commands
```
--all select all resources
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--with-credentials include credential secrets
```
### SEE ALSO
* [tk export source](tk_export_source.md) - Export sources

View File

@@ -1,10 +1,10 @@
## tk get
Get commands
Get sources and resources
### Synopsis
Get commands
The get sub-commands print the statuses of sources and resources.
### Options
@@ -15,16 +15,16 @@ Get commands
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk](tk.md) - Command line utility for assembling Kubernetes CD pipelines
* [tk get kustomizations](tk_get_kustomizations.md) - Get kustomizations status
* [tk get sources](tk_get_sources.md) - Get sources commands
* [tk get helmreleases](tk_get_helmreleases.md) - Get HelmRelease statuses
* [tk get kustomizations](tk_get_kustomizations.md) - Get Kustomization statuses
* [tk get sources](tk_get_sources.md) - Get source statuses

View File

@@ -0,0 +1,39 @@
## tk get helmreleases
Get HelmRelease statuses
### Synopsis
The get helmreleases command prints the statuses of the resources.
```
tk get helmreleases [flags]
```
### Examples
```
# List all Helm releases and their status
tk get helmreleases
```
### Options
```
-h, --help help for helmreleases
```
### Options inherited from parent commands
```
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk get](tk_get.md) - Get sources and resources

View File

@@ -1,16 +1,23 @@
## tk get kustomizations
Get kustomizations status
Get Kustomization statuses
### Synopsis
The get kustomizations command prints the status of the resources.
The get kustomizations command prints the statuses of the resources.
```
tk get kustomizations [flags]
```
### Examples
```
# List all kustomizations and their status
tk get kustomizations
```
### Options
```
@@ -20,14 +27,13 @@ tk get kustomizations [flags]
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk get](tk_get.md) - Get commands
* [tk get](tk_get.md) - Get sources and resources

View File

@@ -1,10 +1,10 @@
## tk get sources
Get sources commands
Get source statuses
### Synopsis
Get sources commands
The get source sub-commands print the statuses of the sources.
### Options
@@ -15,15 +15,15 @@ Get sources commands
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk get](tk_get.md) - Get commands
* [tk get sources git](tk_get_sources_git.md) - Get git sources status
* [tk get](tk_get.md) - Get sources and resources
* [tk get sources git](tk_get_sources_git.md) - Get GitRepository source statuses
* [tk get sources helm](tk_get_sources_helm.md) - Get HelmRepository source statuses

View File

@@ -1,16 +1,23 @@
## tk get sources git
Get git sources status
Get GitRepository source statuses
### Synopsis
The get sources command prints the status of the git resources.
The get sources git command prints the status of the GitRepository sources.
```
tk get sources git [flags]
```
### Examples
```
# List all Git repositories and their status
tk get sources git
```
### Options
```
@@ -20,14 +27,13 @@ tk get sources git [flags]
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk get sources](tk_get_sources.md) - Get sources commands
* [tk get sources](tk_get_sources.md) - Get source statuses

View File

@@ -0,0 +1,39 @@
## tk get sources helm
Get HelmRepository source statuses
### Synopsis
The get sources helm command prints the status of the HelmRepository sources.
```
tk get sources helm [flags]
```
### Examples
```
# List all Helm repositories and their status
tk get sources helm
```
### Options
```
-h, --help help for helm
```
### Options inherited from parent commands
```
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk get sources](tk_get_sources.md) - Get source statuses

View File

@@ -4,7 +4,6 @@ Install the toolkit components
### Synopsis
The install command deploys the toolkit components in the specified namespace.
If a previous version is installed, then an in-place upgrade will be performed.
@@ -16,33 +15,37 @@ tk install [flags]
```
# Install the latest version in the gitops-systems namespace
install --version=master --namespace=gitops-systems
tk install --version=latest --namespace=gitops-systems
# Dry-run install for a specific version and a series of components
install --dry-run --version=0.0.1 --components="source-controller,kustomize-controller"
tk install --dry-run --version=v0.0.7 --components="source-controller,kustomize-controller"
# Dry-run install with manifests preview
install --dry-run --verbose
tk install --dry-run --verbose
# Write install manifests to file
tk install --export > gitops-system.yaml
```
### Options
```
--dry-run only print the object that would be applied
-h, --help help for install
--manifests string path to the manifest directory, dev only
-v, --version string toolkit tag or branch (default "master")
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
--dry-run only print the object that would be applied
--export write the install manifests to stdout and exit
-h, --help help for install
--manifests string path to the manifest directory, dev only
-v, --version string toolkit version (default "latest")
```
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO

30
docs/cmd/tk_reconcile.md Normal file
View File

@@ -0,0 +1,30 @@
## tk reconcile
Reconcile sources and resources
### Synopsis
The reconcile sub-commands trigger a reconciliation of sources and resources.
### Options
```
-h, --help help for reconcile
```
### Options inherited from parent commands
```
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk](tk.md) - Command line utility for assembling Kubernetes CD pipelines
* [tk reconcile helmrelease](tk_reconcile_helmrelease.md) - Reconcile a HelmRelease resource
* [tk reconcile kustomization](tk_reconcile_kustomization.md) - Reconcile a Kustomization resource
* [tk reconcile source](tk_reconcile_source.md) - Reconcile sources

View File

@@ -0,0 +1,44 @@
## tk reconcile helmrelease
Reconcile a HelmRelease resource
### Synopsis
The reconcile kustomization command triggers a reconciliation of a HelmRelease resource and waits for it to finish.
```
tk reconcile helmrelease [name] [flags]
```
### Examples
```
# Trigger a HelmRelease apply outside of the reconciliation interval
tk reconcile hr podinfo
# Trigger a reconciliation of the HelmRelease's source and apply changes
tk reconcile hr podinfo --with-source
```
### Options
```
-h, --help help for helmrelease
--with-source reconcile HelmRelease source
```
### Options inherited from parent commands
```
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk reconcile](tk_reconcile.md) - Reconcile sources and resources

View File

@@ -0,0 +1,44 @@
## tk reconcile kustomization
Reconcile a Kustomization resource
### Synopsis
The reconcile kustomization command triggers a reconciliation of a Kustomization resource and waits for it to finish.
```
tk reconcile kustomization [name] [flags]
```
### Examples
```
# Trigger a Kustomization apply outside of the reconciliation interval
tk reconcile kustomization podinfo
# Trigger a sync of the Kustomization's source and apply changes
tk reconcile kustomization podinfo --with-source
```
### Options
```
-h, --help help for kustomization
--with-source reconcile kustomization source
```
### Options inherited from parent commands
```
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk reconcile](tk_reconcile.md) - Reconcile sources and resources

View File

@@ -0,0 +1,29 @@
## tk reconcile source
Reconcile sources
### Synopsis
The reconcile source sub-commands trigger a reconciliation of sources.
### Options
```
-h, --help help for source
```
### Options inherited from parent commands
```
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk reconcile](tk_reconcile.md) - Reconcile sources and resources
* [tk reconcile source git](tk_reconcile_source_git.md) - Reconcile a GitRepository source
* [tk reconcile source helm](tk_reconcile_source_helm.md) - Reconcile a HelmRepository source

View File

@@ -0,0 +1,39 @@
## tk reconcile source git
Reconcile a GitRepository source
### Synopsis
The reconcile source command triggers a reconciliation of a GitRepository resource and waits for it to finish.
```
tk reconcile source git [name] [flags]
```
### Examples
```
# Trigger a git pull for an existing source
tk reconcile source git podinfo
```
### Options
```
-h, --help help for git
```
### Options inherited from parent commands
```
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk reconcile source](tk_reconcile_source.md) - Reconcile sources

View File

@@ -0,0 +1,39 @@
## tk reconcile source helm
Reconcile a HelmRepository source
### Synopsis
The reconcile source command triggers a reconciliation of a HelmRepository resource and waits for it to finish.
```
tk reconcile source helm [name] [flags]
```
### Examples
```
# Trigger a reconciliation for an existing source
tk reconcile source helm podinfo
```
### Options
```
-h, --help help for helm
```
### Options inherited from parent commands
```
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk reconcile source](tk_reconcile_source.md) - Reconcile sources

View File

@@ -1,10 +1,10 @@
## tk resume
Resume commands
Resume suspended resources
### Synopsis
Resume commands
The resume sub-commands resume a suspended resource.
### Options
@@ -15,15 +15,15 @@ Resume commands
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk](tk.md) - Command line utility for assembling Kubernetes CD pipelines
* [tk resume kustomization](tk_resume_kustomization.md) - Resume kustomization
* [tk resume helmrelease](tk_resume_helmrelease.md) - Resume a suspended HelmRelease
* [tk resume kustomization](tk_resume_kustomization.md) - Resume a suspended Kustomization

View File

@@ -0,0 +1,40 @@
## tk resume helmrelease
Resume a suspended HelmRelease
### Synopsis
The resume command marks a previously suspended HelmRelease resource for reconciliation and waits for it to
finish the apply.
```
tk resume helmrelease [name] [flags]
```
### Examples
```
# Resume reconciliation for an existing Helm release
tk resume hr podinfo
```
### Options
```
-h, --help help for helmrelease
```
### Options inherited from parent commands
```
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk resume](tk_resume.md) - Resume suspended resources

View File

@@ -1,15 +1,24 @@
## tk resume kustomization
Resume kustomization
Resume a suspended Kustomization
### Synopsis
The resume command marks a previously suspended Kustomization resource for reconciliation and waits for it to finish the apply.
The resume command marks a previously suspended Kustomization resource for reconciliation and waits for it to
finish the apply.
```
tk resume kustomization [name] [flags]
```
### Examples
```
# Resume reconciliation for an existing Kustomization
tk resume ks podinfo
```
### Options
```
@@ -19,14 +28,13 @@ tk resume kustomization [name] [flags]
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk resume](tk_resume.md) - Resume commands
* [tk resume](tk_resume.md) - Resume suspended resources

View File

@@ -1,10 +1,10 @@
## tk suspend
Suspend commands
Suspend resources
### Synopsis
Suspend commands
The suspend sub-commands suspend the reconciliation of a resource.
### Options
@@ -15,15 +15,15 @@ Suspend commands
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk](tk.md) - Command line utility for assembling Kubernetes CD pipelines
* [tk suspend kustomization](tk_suspend_kustomization.md) - Suspend kustomization
* [tk suspend helmrelease](tk_suspend_helmrelease.md) - Suspend reconciliation of HelmRelease
* [tk suspend kustomization](tk_suspend_kustomization.md) - Suspend reconciliation of Kustomization

View File

@@ -0,0 +1,39 @@
## tk suspend helmrelease
Suspend reconciliation of HelmRelease
### Synopsis
The suspend command disables the reconciliation of a HelmRelease resource.
```
tk suspend helmrelease [name] [flags]
```
### Examples
```
# Suspend reconciliation for an existing Helm release
tk suspend hr podinfo
```
### Options
```
-h, --help help for helmrelease
```
### Options inherited from parent commands
```
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk suspend](tk_suspend.md) - Suspend resources

View File

@@ -1,6 +1,6 @@
## tk suspend kustomization
Suspend kustomization
Suspend reconciliation of Kustomization
### Synopsis
@@ -10,6 +10,14 @@ The suspend command disables the reconciliation of a Kustomization resource.
tk suspend kustomization [name] [flags]
```
### Examples
```
# Suspend reconciliation for an existing Kustomization
tk suspend ks podinfo
```
### Options
```
@@ -19,14 +27,13 @@ tk suspend kustomization [name] [flags]
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk suspend](tk_suspend.md) - Suspend commands
* [tk suspend](tk_suspend.md) - Suspend resources

View File

@@ -1,30 +0,0 @@
## tk sync
Synchronize commands
### Synopsis
Synchronize commands
### Options
```
-h, --help help for sync
```
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk](tk.md) - Command line utility for assembling Kubernetes CD pipelines
* [tk sync kustomization](tk_sync_kustomization.md) - Synchronize kustomization
* [tk sync source](tk_sync_source.md) - Synchronize source commands

View File

@@ -1,45 +0,0 @@
## tk sync kustomization
Synchronize kustomization
### Synopsis
The sync kustomization command triggers a reconciliation of a Kustomization resource and waits for it to finish.
```
tk sync kustomization [name] [flags]
```
### Examples
```
# Trigger a kustomization apply outside of the reconciliation interval
sync kustomization podinfo
# Trigger a git sync of the kustomization source and apply changes
sync kustomization podinfo --with-source
```
### Options
```
-h, --help help for kustomization
--with-source synchronize kustomization source
```
### Options inherited from parent commands
```
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller])
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk sync](tk_sync.md) - Synchronize commands

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