Skip to content

Commit d8bb392

Browse files
dkoshkinjimmidyson
authored andcommitted
fix: Make calico work with pod security standard by labelling tigera ns
1 parent f3e5868 commit d8bb392

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ clusterctl generate cluster capi-quickstart \
2424
--kubernetes-version v1.26.0 \
2525
--control-plane-machine-count=1 \
2626
--worker-machine-count=1 | \
27+
gojq --yaml-input --yaml-output --slurp \
28+
'.[] | (select( .kind=="Cluster").metadata.labels += {"capi-runtime-extensions.d2iq-labs.com/cni": "calico"})' \
2729
kubectl apply -f -
2830
```
2931

30-
Label the cluster to deploy Calico:
32+
Wait until control plane is ready:
3133

3234
```shell
33-
kubectl label cluster capi-quickstart capi-runtime-extensions.d2iq-labs.com/cni=calico
35+
kubectl wait clusters/capi-quickstart --for=condition=ControlPlaneInitialized --timeout=5m
3436
```
3537

3638
To get the kubeconfig for the new cluster, run:
@@ -47,6 +49,18 @@ kubectl config set-cluster capi-quickstart \
4749
--server=https://$(docker port capi-quickstart-lb 6443/tcp)
4850
```
4951

52+
Wait until all nodes are ready (this indicates that CNI has been deployed successfully):
53+
54+
```shell
55+
kubectl --kubeconfig capd-kubeconfig wait nodes --all --for=condition=Ready --timeout=5m
56+
```
57+
58+
Show that Calico is running successfully on the workload cluster:
59+
60+
```shell
61+
kubectl --kubeconfig capd-kubeconfig get daemonsets -n calico-system
62+
```
63+
5064
To delete the workload cluster, run:
5165

5266
```shell

hack/addons/update-calico-manifests.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ if [ -z "${CALICO_VERSION-}" ]; then
1313
echo "Missing environment variable: CALICO_VERSION"
1414
exit 1
1515
fi
16-
readonly CALICO_CNI_ASSETS_DIR="${GIT_REPO_ROOT}/.local/cni/calico/${CALICO_VERSION}"
17-
mkdir -p "${CALICO_CNI_ASSETS_DIR}"
1816

19-
curl -fsSL "https://docs.projectcalico.org/archive/${CALICO_VERSION}/manifests/tigera-operator.yaml" \
20-
-o "${CALICO_CNI_ASSETS_DIR}/tigera-operator.yaml"
17+
CALICO_CNI_ASSETS_DIR="$(mktemp -d -p "${TMPDIR:-/tmp}")"
18+
readonly CALICO_CNI_ASSETS_DIR
19+
trap 'rm -rf ${CALICO_CNI_ASSETS_DIR}' EXIT
2120

2221
# The operator manifest in YAML format is 1226666 bytes. It turns out that much of that is whitespace. Converting the
2322
# manifest to JSON without indentation allows us to remove most of the whitespace, reducing the size by more than half,
@@ -27,10 +26,10 @@ curl -fsSL "https://docs.projectcalico.org/archive/${CALICO_VERSION}/manifests/t
2726
# 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.
2827
# 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.
2928
# 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"
29+
curl -fsSL "https://docs.projectcalico.org/archive/${CALICO_VERSION}/manifests/tigera-operator.yaml" |
30+
gojq --yaml-input --slurp --indent=0 \
31+
'[ .[] | select( . != null ) | (select( .kind=="Namespace").metadata.labels += {"pod-security.kubernetes.io/enforce": "privileged", "pod-security.kubernetes.io/enforce-version": "latest"}) ]' \
32+
>"${CALICO_CNI_ASSETS_DIR}/tigera-operator.json"
3433

3534
kubectl create configmap tigera-operator --dry-run=client --output yaml \
3635
--from-file "${CALICO_CNI_ASSETS_DIR}/tigera-operator.json" \

pkg/addons/templates/cni/tigera-operator-configmap.yaml

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)