Skip to content

Commit

Permalink
Fix egress interfaces script to work on IPI clusters
Browse files Browse the repository at this point in the history
We adjust the script to use the external API DNS record
(api.<cluster-domain>) instead of api-int, so that it works without any
problems on IPI clusters which provide the api-int record via in-cluster
CoreDNS which isn't running yet before the kubelet is started.
  • Loading branch information
simu committed Sep 2, 2024
1 parent 9511c13 commit 0425f8a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
15 changes: 13 additions & 2 deletions component/scripts/create-egress-interfaces.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@

set -eo pipefail

export KUBECONFIG="%(kubelet_kubeconfig)s"
readonly patched_kubeconfig="/tmp/kubeconfig"

readonly shadow_data=$(kubectl -n "%(cm_namespace)s" get configmap "%(cm_name)s" -ojsonpath="{.data.${HOSTNAME}}")
# Patch node kubeconfig to use api.<cluster-domain> instead of
# `api-int.<cluster-domain>` so that the script works on clusters which
# provide the api-int record via in-cluster CoreDNS. This assumes that the
# public API endpoint has a certificate that's issued by a public CA that's
# part of the node's trusted CA certs.
sed -e 's/api-int/api/;/certificate-authority-data/d' "%(kubelet_kubeconfig)s" > "$patched_kubeconfig"
export KUBECONFIG="${patched_kubeconfig}"

shadow_data=$(kubectl -n "%(cm_namespace)s" get configmap "%(cm_name)s" -ojsonpath="{.data.${HOSTNAME}}")
readonly shadow_data

for prefix in $(echo "$shadow_data" | jq -r '.|keys[]'); do
base=$(echo "$shadow_data" | jq -r ".${prefix}.base")
Expand All @@ -20,4 +29,6 @@ for prefix in $(echo "$shadow_data" | jq -r '.|keys[]'); do
done
done

rm "${patched_kubeconfig}"

exit 0
10 changes: 10 additions & 0 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,16 @@ The script uses the file indicated in field `nodeKubeconfig` to fetch the Config
If the default value is used, the script will use the node's Kubelet kubeconfig to access the cluster.
To ensure the Kubelet can access the configmap, users should ensure that a pod which mounts the ConfigMap is running on the node.

[NOTE]
====
The script will apply the following changes to the provided kubeconfig:
* Occurrences of `api-int` will be replaced with `api` (once per line)
* Lines containing the string `certificate-authority-data` will be deleted
This is done to ensure that the script works correctly on IPI clusters which only provide the `api-int` DNS record via the in-cluster CoreDNS which isn't running before the kubelet is started.
====

[TIP]
====
Component cilium can deploy a suitable ConfigMap and DaemonSets which ensure that the Kubelets on all nodes that need to create egress dummy interfaces can access the ConfigMap.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ metadata:
set -eo pipefail
export KUBECONFIG="/var/lib/kubelet/kubeconfig"
readonly patched_kubeconfig="/tmp/kubeconfig"
readonly shadow_data=$(kubectl -n "cilium" get configmap "eip-shadow-ranges" -ojsonpath="{.data.${HOSTNAME}}")
# Patch node kubeconfig to use api.<cluster-domain> instead of
# `api-int.<cluster-domain>` so that the script works on clusters which
# provide the api-int record via in-cluster CoreDNS. This assumes that the
# public API endpoint has a certificate that's issued by a public CA that's
# part of the node's trusted CA certs.
sed -e 's/api-int/api/;/certificate-authority-data/d' "/var/lib/kubelet/kubeconfig" > "$patched_kubeconfig"
export KUBECONFIG="${patched_kubeconfig}"
shadow_data=$(kubectl -n "cilium" get configmap "eip-shadow-ranges" -ojsonpath="{.data.${HOSTNAME}}")
readonly shadow_data
for prefix in $(echo "$shadow_data" | jq -r '.|keys[]'); do
base=$(echo "$shadow_data" | jq -r ".${prefix}.base")
Expand All @@ -25,6 +34,8 @@ metadata:
done
done
rm "${patched_kubeconfig}"
exit 0
labels:
app.kubernetes.io/component: openshift4-nodes
Expand All @@ -40,7 +51,7 @@ spec:
storage:
files:
- contents:
source: data:text/plain;charset=utf-8;base64,IyEvYmluL2Jhc2gKCnNldCAtZW8gcGlwZWZhaWwKCmV4cG9ydCBLVUJFQ09ORklHPSIvdmFyL2xpYi9rdWJlbGV0L2t1YmVjb25maWciCgpyZWFkb25seSBzaGFkb3dfZGF0YT0kKGt1YmVjdGwgLW4gImNpbGl1bSIgZ2V0IGNvbmZp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lfSwgZnJvbT0ke2Zyb219LCB0bz0ke3RvfSIKICBmb3Igc3VmZml4IGluICQoc2VxICIkZnJvbSIgIiR0byIpOyBkbwogICAgaWR4PSQoKCIkc3VmZml4IiAtICIkZnJvbSIpKQogICAgaWZhY2U9IiR7cHJlZml4fV8ke2lkeH0iCiAgICBpcCBsIGRlbCAiJGlmYWNlIiAyPi9kZXYvbnVsbCB8fCB0cnVlCiAgICBpcCBsIGFkZCAiJGlmYWNlIiB0eXBlIGR1bW15CiAgICBpcCBhIGFkZCAiJHtiYXNlfS4ke3N1ZmZpeH0iIGRldiAiJGlmYWNlIgogIGRvbmUKZG9uZQoKcm0gIiR7cGF0Y2hlZF9rdWJlY29uZmlnfSIKCmV4aXQgMAo=
mode: 493
path: /usr/local/bin/appuio-create-egress-interfaces.sh
systemd:
Expand Down

0 comments on commit 0425f8a

Please sign in to comment.