Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add a bundle for Project Calico #10

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
strategy:
matrix:
bundles:
- calico
- cert-manager
- kubevirt
- metallb
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
strategy:
matrix:
bundles:
- calico
- cert-manager
- kubevirt
- metallb
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Please note that these community bundles are not officially supported and are pr

- [Usage](#usage)
- [Bundles](#bundles)
- [Calico](#calico)
- [Cert-Manager](#cert-manager)
- [Kubevirt](#kubevirt)
- [MetalLB](#metallb)
Expand Down Expand Up @@ -61,6 +62,25 @@ k3s:

## Bundles

### Calico

The calico bundle deploys [Project Calico](https://docs.tigera.io/calico/latest/about/).

To configure the bundle, use the `calico` block:

```yaml
#cloud-config

# Specify the bundle to use
bundles:
- targets:
- run://quay.io/kairos/community-bundles:calico_latest

# Specify cert-manager settings
mudler marked this conversation as resolved.
Show resolved Hide resolved
calico:
version: 3.25.0
```

### Cert-manager

The cert-manager bundle deploys [cert-manager](https://cert-manager.io/docs/installation/).
Expand Down
4 changes: 4 additions & 0 deletions calico/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM alpine as build
FROM scratch
COPY ./run.sh /
COPY ./assets /assets
14 changes: 14 additions & 0 deletions calico/assets/calico.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Namespace
metadata:
name: tigera-operator
---
apiVersion: helm.cattle.io/v1
kind: HelmChart
metadata:
name: calico
namespace: tigera-operator
spec:
chart: calico
repo: https://docs.tigera.io/calico/charts
version: "@VERSION@"
42 changes: 42 additions & 0 deletions calico/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

set -ex

K3S_MANIFEST_DIR=${K3S_MANIFEST_DIR:-/var/lib/rancher/k3s/server/manifests/}

getConfig() {
local l=$1
key=$(kairos-agent config get $l | tr -d '\n')
if [ "$key" != "null" ]; then
echo $key
fi
echo
}

# renovate: depName=calico repoUrl=https://docs.tigera.io/calico/charts
VERSION="3.25.0"

templ() {
local file="$3"
local value="$2"
local sentinel="$1"
sed -i "s/@${sentinel}@/${value}/g" ${file}
}

readConfig() {
_version=$(getConfig calico.version)
if [ "$_version" != "" ]; then
VERSION=$_version
fi
}

mkdir -p $K3S_MANIFEST_DIR

readConfig

# Copy manifests, and template them
for FILE in assets/*; do
templ "VERSION" "${VERSION}" $FILE
done;

cp -rf assets/* $K3S_MANIFEST_DIR
9 changes: 9 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
"earthly\\/earthly:(?<currentValue>.*?)\\s"
],
"versioningTemplate": "semver-coerced"
},
{
"datasourceTemplate": "helm",
"fileMatch": [
"^run\\.sh$"
],
"matchStrings": [
"#\\s*renovate:\\s*depName=(?<depName>.*?)(\\s+repoUrl=(?<registryUrl>.*?))?\\sVERSION=\\\"(?<currentValue>.*?)\\\"\\s"
]
}
]
}
40 changes: 40 additions & 0 deletions tests/calico_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package bundles_test

import (
"os"
"path/filepath"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("calico test", Label("calico"), func() {

BeforeEach(func() {
prepareBundle()
})
AfterEach(func() {
cleanBundle()
})

It("Deploy calico with default version", func() {
runBundle()
dat, err := os.ReadFile(filepath.Join("/var/lib/rancher/k3s/server/manifests", "calico.yaml"))
content := string(dat)
Expect(err).ToNot(HaveOccurred())
Expect(content).To(ContainSubstring("version: \"3.25.0\""))
})

It("Specifiy version for calico", func() {
err := os.WriteFile("/oem/foo.yaml", []byte(`#cloud-config
calico:
version: 1`), 0655)
Expect(err).ToNot(HaveOccurred())

runBundle()
dat, err := os.ReadFile(filepath.Join("/var/lib/rancher/k3s/server/manifests", "calico.yaml"))
content := string(dat)
Expect(err).ToNot(HaveOccurred())
Expect(content).To(ContainSubstring("version: \"1\""))
})
})