Skip to content

Commit

Permalink
fix(calico): fix semantic version input
Browse files Browse the repository at this point in the history
for further information check #56 (comment)

Signed-off-by: Kai Ehrhardt <[email protected]>
  • Loading branch information
kaiehrhardt authored and jimmykarily committed Nov 9, 2023
1 parent 5f7cadc commit 14745f5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
43 changes: 14 additions & 29 deletions calico/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,33 @@ set -ex

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


getConfig() {
local key=$1
_value=$(kairos-agent config get "${key} | @json" | tr -d '\n')
# Remove the quotes wrapping the value.
_value=${_value:1:${#_value}-2}
if [ "${_value}" != "null" ]; then
echo "${_value}"
fi
echo
}

VALUES="{}"
# renovate: depName=tigera-operator repoUrl=https://docs.tigera.io/calico/charts
VERSION="3.25.0"

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

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

mkdir -p "${K3S_MANIFEST_DIR}"

readConfig
_version=$(kairos-agent config get "calico.version" | tr -d '\n')
if [ "$_version" != "null" ]; then
VERSION=$_version
fi
_values=$(kairos-agent config get "calico.values | @json" | tr -d '\n')
# Remove the quotes wrapping the value.
_values=${_values:1:${#_values}-2}
if [ "$_values" != "null" ]; then
VALUES=$_values
fi

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

mkdir -p "${K3S_MANIFEST_DIR}"
cp -rf assets/* "${K3S_MANIFEST_DIR}"
15 changes: 14 additions & 1 deletion tests/calico_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var _ = Describe("calico test", Label("calico"), func() {
Expect(content).To(ContainSubstring("version: \"3.25.0\""))
})

It("Specifiy version for calico", func() {
It("Specifiy major version for calico", func() {
err := os.WriteFile("/oem/foo.yaml", []byte(`#cloud-config
calico:
version: 1`), 0655)
Expand All @@ -39,6 +39,19 @@ calico:
Expect(content).To(ContainSubstring("version: \"1\""))
})

It("Specifiy full version for calico", func() {
err := os.WriteFile("/oem/foo.yaml", []byte(`#cloud-config
calico:
version: 1.2.3`), 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.2.3\""))
})

It("Deploy calico with default values", func() {
runBundle()
dat, err := os.ReadFile(filepath.Join("/var/lib/rancher/k3s/server/manifests", "calico.yaml"))
Expand Down

0 comments on commit 14745f5

Please sign in to comment.