diff --git a/component/scripts/create-egress-interfaces.sh b/component/scripts/create-egress-interfaces.sh index 854447a..35c932a 100644 --- a/component/scripts/create-egress-interfaces.sh +++ b/component/scripts/create-egress-interfaces.sh @@ -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. instead of +# `api-int.` 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") @@ -20,4 +29,6 @@ for prefix in $(echo "$shadow_data" | jq -r '.|keys[]'); do done done +rm "${patched_kubeconfig}" + exit 0 diff --git a/docs/modules/ROOT/pages/references/parameters.adoc b/docs/modules/ROOT/pages/references/parameters.adoc index 06c9b52..a5d7a2c 100644 --- a/docs/modules/ROOT/pages/references/parameters.adoc +++ b/docs/modules/ROOT/pages/references/parameters.adoc @@ -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. diff --git a/tests/golden/machineconfig/openshift4-nodes/openshift4-nodes/30_egress_interfaces.yaml b/tests/golden/machineconfig/openshift4-nodes/openshift4-nodes/30_egress_interfaces.yaml index 9bbdc5b..f1fbf9c 100644 --- a/tests/golden/machineconfig/openshift4-nodes/openshift4-nodes/30_egress_interfaces.yaml +++ b/tests/golden/machineconfig/openshift4-nodes/openshift4-nodes/30_egress_interfaces.yaml @@ -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. instead of + # `api-int.` 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") @@ -25,6 +34,8 @@ metadata: done done + rm "${patched_kubeconfig}" + exit 0 labels: app.kubernetes.io/component: openshift4-nodes @@ -40,7 +51,7 @@ spec: storage: files: - contents: - source: data:text/plain;charset=utf-8;base64,IyEvYmluL2Jhc2gKCnNldCAtZW8gcGlwZWZhaWwKCmV4cG9ydCBLVUJFQ09ORklHPSIvdmFyL2xpYi9rdWJlbGV0L2t1YmVjb25maWciCgpyZWFkb25seSBzaGFkb3dfZGF0YT0kKGt1YmVjdGwgLW4gImNpbGl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