Skip to content

Commit

Permalink
docs: Add flux example (#187)
Browse files Browse the repository at this point in the history
Co-authored-by: Giovanni Liva <giovanni.liva@dynatrace.com>
  • Loading branch information
thschue and thisthat committed Oct 19, 2022
1 parent 95e206b commit 02cceb3
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/flux/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flux-demo
70 changes: 70 additions & 0 deletions examples/flux/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
JAEGER_VERSION ?= v1.38.0
LFC_NAMESPACE ?= keptn-lifecycle-controller-system
PODTATO_NAMESPACE ?= podtato-kubectl
REPO_PATH ?= flux-demo
REPO_CLUSTER_PATH ?= clusters/demo-cluster
GITHUB_REPO ?= ""
GITHUB_BRANCH ?= "main"
GITHUB_USER ?= ""
GITHUB_TOKEN ?= ""


.PHONY: install
install: check-repo-url-empty check-github-user-empty check-flux-binary
@echo "----------------------------------------"
@echo "Preparing your flux repo and set up flux"
@echo "----------------------------------------"
@echo "(i) Make sure that you have a Personal Access Token prepared for your GitHub account (https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)"
@echo "(i) You will need all permissions under repo (according to https://fluxcd.io/flux/installation/#github-and-github-enterprise)"
@echo ""
@sleep 5
flux bootstrap github \
--owner=$(GITHUB_USER) \
--repository=$(GITHUB_REPO) \
--branch=$(GITHUB_BRANCH) \
--path=$(REPO_CLUSTER_PATH) \
--personal
rm -rf $(REPO_CLUSTER_PATH)

@echo "----------------------------------------"
@echo "Cloning your flux repo"
@echo "----------------------------------------"
git clone $(GITHUB_REPO) $(REPO_PATH)

@echo "-----------------------------------------------------------------------------"
@echo "Flux is prepared, you can find the repo at $(REPO_PATH)"
@echo "Then you can proceed with the next step: make manifests <YOUR_REPO_PATH>"
@echo "-----------------------------------------------------------------------------"

.PHONY: manifests
manifests:
cp config/flux-config.yaml $(REPO_PATH)/$(REPO_CLUSTER_PATH)
cd $(REPO_PATH) && git add . && git commit -m "Add podtatohead manifests" && git push

.PHONY: check-repo-url-empty
check-repo-url-empty:
@if [ $(GITHUB_REPO) == "" ]; then \
echo "ERROR: GITHUB_REPO has not been specified"; \
exit 1; \
fi

.PHONY: check-github-user-empty
check-github-user-empty:
@if [ $(GITHUB_USER) == "" ]; then \
echo "ERROR: GITHUB_USER has not been specified"; \
exit 1; \
fi

.PHONY: check-flux-binary
check-flux-binary:
@if ! command -v flux &> /dev/null; then \
echo "ERROR: flux binary not found. Please install flux"; \
exit 1; \
fi

.PHONY: uninstall
uninstall: check-flux-binary
@echo "----------------------------------------"
@echo "Uninstalling flux"
@echo "----------------------------------------"
flux uninstall
41 changes: 41 additions & 0 deletions examples/flux/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Use lifecycle-controller together with flux

This tutorial shows how to use the lifecycle-controller together with [Flux](https://fluxcd.io/).

## TL;DR
* Set up a Personal Access Token according to: https://fluxcd.io/flux/installation/#github-and-github-enterprise
* Set up Flux and a GitHub repository: `make install GITHUB_REPO=https://github.com/<YOUR_GITHUB_HANDLE>/flux-demo GITHUB_USER=<YOUR_GITHUB_HANDLE> GITHUB_TOKEN=<YOUR_GITHUB_TOKEN>`

* Apply manifests to the Repository: `make manifests`
* Watch the progress of the deployment using: `kubectl get keptnapplicationversions -n podtato-kubectl`
* This might take a while

## Prerequisites
The Flux CLI should be installed. See [here](https://fluxcd.io/docs/installation/) for more information.

MacOS: `brew install fluxcd/tap/flux`
bash: `curl -s https://fluxcd.io/install.sh | sudo bash`
chocolatey: `choco install flux`

## Bootstrap your repository and install flux
Follow the instructions in the quickstart guide: https://fluxcd.io/docs/get-started/

## Installing the Demo Application
To install the demo application, you can check in the configuration provided in the config-repository to the repository you created in the previous step.

You can watch the progress of the deployment using:
> `kubectl get pods -n podtato-kubectl`
* See that the pods are pending until the pre-deployment tasks have passed
* Pre-Deployment Tasks are started
* Pods get scheduled

> `kubectl get keptnworkloadinstances -n podtato-kubectl`
* Get the current status of the workloads
* See in which phase your workload deployments are at the moment

> `kubectl get keptnapplicationversions -n podtato-kubectl`
* Get the current status of the application
* See in which phase your application deployment is at the moment

After some time all resources should be in a succeeded state. Taking a look on the kustomization resource, you can see that the deployment has been updated to the latest version.
> `kubectl describe kustomizations.kustomize.toolkit.fluxcd.io podtatohead -n default`
30 changes: 30 additions & 0 deletions examples/flux/config/flux-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: GitRepository
metadata:
name: lifecycle-controller
namespace: default
spec:
interval: 5m
url: https://github.com/keptn-sandbox/lifecycle-controller
ref:
branch: main
ignore: |
# exclude all
/*
# include deploy dir
!/examples/podtatohead-deployment
---
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
name: podtatohead
namespace: default
spec:
interval: 15m
path: "./examples/podtatohead-deployment"
prune: true
sourceRef:
kind: GitRepository
name: lifecycle-controller
1 change: 1 addition & 0 deletions examples/podtatohead-deployment/post-deployment-tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: lifecycle.keptn.sh/v1alpha1
kind: KeptnTaskDefinition
metadata:
name: post-deployment-hello
namespace: podtato-kubectl
spec:
function:
inline:
Expand Down

0 comments on commit 02cceb3

Please sign in to comment.