Skip to content

Commit fd40c00

Browse files
committed
build: tooling to download Calico manifests
1 parent 6a2c2e7 commit fd40c00

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ pre-commit 3.0.2
1010
shfmt 3.6.0
1111
upx 4.0.2
1212
gcloud 416.0.0
13+
kubectl 1.26.1
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
IFS=$'\n\t'
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
readonly SCRIPT_DIR
8+
9+
# shellcheck source=hack/common.sh
10+
source "${SCRIPT_DIR}/../common.sh"
11+
12+
if [ -z "${CALICO_VERSION-}" ]; then
13+
echo "Missing environment variable: CALICO_VERSION"
14+
exit 1
15+
fi
16+
readonly CALICO_CNI_ASSETS_DIR="${GIT_REPO_ROOT}/.local/cni/calico/${CALICO_VERSION}"
17+
mkdir -p "${CALICO_CNI_ASSETS_DIR}"
18+
19+
curl -fsSL "https://docs.projectcalico.org/archive/${CALICO_VERSION}/manifests/tigera-operator.yaml" \
20+
-o "${CALICO_CNI_ASSETS_DIR}/tigera-operator.yaml"
21+
22+
# The operator manifest in YAML format is 1226666 bytes. It turns out that much of that is whitespace. Converting the
23+
# manifest to JSON without indentation allows us to remove most of the whitespace, reducing the size by more than half,
24+
# to 527614 bytes.
25+
#
26+
# Some important notes:
27+
# 1. The YAML manifest includes many documents, and the documents must become elements in a JSON array in order for the ClusterResourceController to [parse them](https://github.com/mesosphere/cluster-api//blob/65586de0080a960d085031de87ec627b2d606a6b/exp/addons/internal/controllers/clusterresourceset_helpers.go#L59). We create a JSON array with the --slurp flag.
28+
# 2. The YAML manifest has some whitespace between YAML document markers (`---`), and these become `null` entries in the JSON array. This causes the ["SortForCreate" subroutine](https://github.com/mesosphere/cluster-api//blob/65586de0080a960d085031de87ec627b2d606a6b/exp/addons/internal/controllers/clusterresourceset_helpers.go#L84) of the ClusterResourceSet controller to misbehave. We remove these null entries using a filter expression.
29+
# 3. If we indent the JSON document, it is nearly as large as the YAML document, at 1099093 bytes. We remove indentation with the --indent=0 flag.
30+
gojq --yaml-input --slurp --indent=0 \
31+
'[ .[] | select( . != null ) ]' \
32+
<"${CALICO_CNI_ASSETS_DIR}/tigera-operator.yaml" \
33+
>"${CALICO_CNI_ASSETS_DIR}/tigera-operator.json"
34+
35+
kubectl create configmap tigera-operator --dry-run=client --output yaml \
36+
--from-file "${CALICO_CNI_ASSETS_DIR}/tigera-operator.json" \
37+
>> "${GIT_REPO_ROOT}/pkg/addons/templates/cni/tigera-operator-configmap.yaml"

hack/common.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
GIT_REPO_ROOT="$(git rev-parse --show-toplevel)"
4+
export GIT_REPO_ROOT

make/addons.mk

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright 2023 D2iQ, Inc. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
export CALICO_VERSION := v3.24
5+
6+
.PHONY: update-addon.calico
7+
update-addon.calico: install-tool.gojq install-tool.kubectl ## update the Calico CNI from source files
8+
$(call print-target)
9+
./hack/addons/update-calico-manifests.sh

make/all.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ include $(INCLUDE_DIR)ci.mk
1717
include $(INCLUDE_DIR)tag.mk
1818
include $(INCLUDE_DIR)upx.mk
1919
include $(INCLUDE_DIR)kubebuilder.mk
20+
include $(INCLUDE_DIR)addons.mk

0 commit comments

Comments
 (0)