Skip to content

Instantly share code, notes, and snippets.

@vasu1124
Last active January 7, 2022 19:41
Show Gist options
  • Save vasu1124/4eb100fc47d319cfe37ab8a3ad89ef53 to your computer and use it in GitHub Desktop.
Save vasu1124/4eb100fc47d319cfe37ab8a3ad89ef53 to your computer and use it in GitHub Desktop.
integrating flux + landscaper with an ocm example
take a look at my test project https://github.com/vasu1124/introspect
Assuming a K8s application, you need. the follwing
1. container image in an oci registry
2. helm chart in an oci registry
3. landscaper blueprint, either in an oci registry or inline in the ocm descriptor
4. ocm descriptor in an oci registry
More in-depth
1. build your container image and push it into your favorite oci registry
```
make build docker-push
```
2. provide a helm helm chart and pushh it also to the oci registry
(this helm feature is still experimental)
```
make helm-push
# executes
# export HELM_EXPERIMENTAL_OCI=1
# helm package ./kubernetes/helm/introspect/ --app-version ${gitVersion}
# helm push introspect-helm-0.1.0.tgz oci://${OCIREPO}/introspect
```
3. create an ocm/blueprint folder and provide a landscaper blueprint.
In my example I am using a helm deployItem:
[blueprint.yaml](https://github.com/vasu1124/introspect/blob/main/ocm/blueprint/blueprint.yaml)
4. assemble the ocm descriptor and also push it to the oci registry
First, you need to download the [component-cli](https://github.com/gardener/component-cli/releases) executable onto your laptop.
The ocm needs to refer to [resources.yaml](https://github.com/vasu1124/introspect/blob/main/ocm/resources.yaml) and
[sources](https://github.com/vasu1124/introspect/blob/main/ocm/sources.yaml).
Assembling the descriptor into the ocm/.gen/component folder and pushing the result into the oci registry:
```
make cd ctf ctf-push
```
under the hood the following steps are run:
```
# skaffolding, set the component-name and version
component-cli component-archive create --component-name github.com/vasu1124/introspect --component-version ${gitVersion} ./ocm/.gen/component
# add resources and sources
component-cli component-archive resource add ./ocm/.gen/component OCI=ghcr.io ORG=vasu1124 gitVersion=${gitVersion} ./ocm/resources.yaml
component-cli component-archive sources add ./ocm/.gen/component OCI=ghcr.io ORG=vasu1124 gitVersion=${gitVersion} ./ocm/sources.yaml
# create a transport file
component-cli ctf add ./ocm/.gen/ctf -f ./ocm/.gen/component
# push the transport file to an oci
component-cli ctf push ./ocm/.gen/ctf --repo-ctx ghcr.io/vasu1124/ocm
```
If you already have a a K8s application with a helm chart, you can easily adopt the above steps.
follow the fluxcd documentation at https://fluxcd.io/docs/installation/
I used the flux bootstrap with my personal access token (PAT) with a locally running docker-desktop cluster as follows:
```
flux bootstrap github --owner=vasu1124 --repository=flux-test --branch=main --path=./clusters/docker-desktop --personal
```
This will create a github repo `flex-test` with a prepopulated GitOps folder `/clusters/docker-desktop/flux-system` for flux.
We will now add the following files to automate the installation of landscaper with flux:
```
.
├── clusters
│   └── docker-desktop
│      ├── flux-system
│      │   ├── gotk-components.yaml
│      │   ├── gotk-sync.yaml
│      │   └── kustomization.yaml
│      └── landscaper
│      ├── k-landscaper.yaml
│      └── ns-ls-system.yaml
└── landscaper
   ├── gr-landscaper.yaml
└── hr-landscaper.yaml
```
/clusters/docker-desktop/landscaper/ns-ls-system.yaml
```
apiVersion: v1
kind: Namespace
metadata:
name: ls-system
```
/clusters/docker-desktop/landscaper/k-landscaper.yaml
```
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
name: landscaper
namespace: ls-system
spec:
interval: 10m0s
path: ./landscaper
prune: true
sourceRef:
kind: GitRepository
name: flux-system
namespace: flux-system
```
/landscaper/gr-landscaper.yaml
```
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: GitRepository
metadata:
name: landscaper
namespace: ls-system
spec:
interval: 1h
ref:
tag: v0.17.0
url: https://github.com/gardener/landscaper
ignore: |
# exclude all
/*
# include charts directory
!/charts
```
/landscaper/hr-landscaper.yaml
```
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: landscaper
namespace: ls-system
spec:
interval: 5m
targetNamespace: ls-system
chart:
spec:
chart: ./charts/landscaper
sourceRef:
kind: GitRepository
name: landscaper
namespace: ls-system
interval: 5m
install:
createNamespace: true
crds: CreateReplace
upgrade:
crds: CreateReplace
values:
landscaper:
landscaper:
registryConfig:
cache: {}
allowPlainHttpRegistries: false
insecureSkipVerify: false
deployers:
- container
- helm
- manifest
deployerManagement:
disable: false
namespace: ls-system
agent:
disable: false
namespace: ls-system
```
After syncing/pushing the files to the git repo, flux within a few minutes will have installed landscaper into the cluster.
We will now add the following files:
```
.
├── clusters
│   └── docker-desktop
│      └── introspect
│      ├── k-introspect.yaml
│      └── ns-example.yaml
└── introspect
└── installation.yaml
```
/clusters/docker-desktop/landscaper/ns-example.yaml
```
apiVersion: v1
kind: Namespace
metadata:
name: example
```
/clusters/docker-desktop/landscaper/k-introspect.yaml
```
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
name: introspect
namespace: example
spec:
dependsOn:
- name: landscaper
namespace: ls-system
interval: 10m0s
path: ./introspect
prune: true
sourceRef:
kind: GitRepository
name: flux-system
namespace: flux-system
```
/introspect/installation.yaml
```
apiVersion: landscaper.gardener.cloud/v1alpha1
kind: Installation
metadata:
name: introspect
namespace: ls-system
spec:
componentDescriptor:
ref:
repositoryContext:
type: ociRegistry
baseUrl: ghcr.io/vasu1124/ocm
componentName: github.com/vasu1124/introspect
version: 1.0.0
blueprint:
ref:
resourceName: introspect-blueprint
imports:
targets:
- name: cluster
# the "#" forces the landscaper to use the target with the name in the same namespace
target: "#default"
importDataMappings:
namespace: example
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment