Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit 899daef

Browse files
madalazartogashidm
authored andcommitted
Updating Kind configuration to fetch images from our image registry
In this commit: - we configure the runner to have the required configuration to pull images (certs, configs) - we fetch the images from the internal registry only if this configuration exists - we configure Kind's containerd to use the internal registry
1 parent 1d5b683 commit 899daef

File tree

5 files changed

+142
-46
lines changed

5 files changed

+142
-46
lines changed

.github/scripts/e2e_get_tools.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,19 @@ echo "retrieving helm"
2525
curl --max-time 10 --retry 10 --retry-delay 5 --retry-max-time 60 -Lo "${root}/tmp/helm.tar.gz" "${HELM_STABLE_RELEASE_URL}"
2626
tar -zxvf "${root}/tmp/helm.tar.gz" && mv linux-amd64/helm "${root}/tmp/bin/helm" && rm -rf linux-amd64
2727
chmod +x "${root}/tmp/bin/helm"
28+
29+
IS_LOCAL="false"
30+
[ -n "$2" ] && IS_LOCAL=$2
31+
if [ "$IS_LOCAL" == "true" ]; then
32+
PROJECT_ROOT_DIR="${root}/../.."
33+
KIND_INTERNAL_CERTS_DIR="${PROJECT_ROOT_DIR}/kind-e2e/ca-certificates"
34+
# We expect certificates to be already present on the host, in this specific folder. If not exit with an error
35+
if [ ! -d "$KIND_INTERNAL_CERTS_DIR" ] || [ -z "$(ls -A "$KIND_INTERNAL_CERTS_DIR")" ]; then
36+
echo "$KIND_INTERNAL_CERTS_DIR doesn't exist or it's empty. Please check host set-up process as this should've happened on runner set-up. Exiting... "
37+
exit 1
38+
else
39+
echo "$KIND_INTERNAL_CERTS_DIR is not empty. Will continue and will use existing certificates..."
40+
fi
41+
fi
42+
43+

.github/scripts/e2e_setup_cluster.sh

Lines changed: 79 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ CNIS_NAME="cni-plugins"
1616
KIND_IMAGE="kindest/node:v1.23.0@sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac"
1717
[ -n "$1" ] && KIND_IMAGE=$1
1818

19+
# private registry set-up variables
20+
CHANGE_MIRROR_REPO="false"
21+
[ -n "$2" ] && CHANGE_MIRROR_REPO=$2
22+
# private registry set-up directories and files
23+
KIND_INTERNAL_CERTS_DIR="${root}/../../kind-e2e/ca-certificates"
24+
REGISTRY_MIRROR_CONFIG_FILE="${root}/../../kind-e2e/registry-mirror.config"
25+
KIND_SET_UP_CONFIG_TEMPLATE="${root}/.github/scripts/kind/config-template.yaml"
26+
KIND_SET_UP_CONFIG_FILE="${root}/.github/scripts/kind/config.yaml"
27+
UBUNTU_CERTS_DIR="/usr/local/share/ca-certificates/"
28+
1929
# create cluster CA and policy for Kubernetes Scheduler
2030
# CA cert & key along with will be mounted to control plane
2131
# path /etc/kubernetes/pki. Kubeadm will utilise generated CA cert/key as root
@@ -28,49 +38,75 @@ generate_k8_scheduler_config_data() {
2838

2939
create_cluster() {
3040
[ -z "${mount_dir}" ] && echo "### no mount directory set" && exit 1
41+
42+
# copy and fill in values in the template config file
43+
echo "Duplicating Kind cluster config template..."
44+
cp "$KIND_SET_UP_CONFIG_TEMPLATE" "$KIND_SET_UP_CONFIG_FILE"
45+
if [ ! -f "$KIND_SET_UP_CONFIG_FILE" ]; then
46+
echo "$KIND_SET_UP_CONFIG_FILE doesn't exist; Copy command above failed unexpectedly. Exiting..."
47+
exit 1
48+
fi
49+
echo "Done."
50+
echo "Updating Kind cluster config template with the corresponding parameters..."
51+
# update the mount_dir expressions. Using | for sed expecting mount_dir contains /
52+
sed -i "s|CP_MOUNT_DIR|${mount_dir:?}|g" "$KIND_SET_UP_CONFIG_FILE"
53+
sed -i "s|WORKER_MOUNT_DIR|$mount_dir|g" "$KIND_SET_UP_CONFIG_FILE"
54+
echo "Done."
55+
56+
if [ "$CHANGE_MIRROR_REPO" == "true" ]; then
57+
echo "Update Kind cluster's containerd configuration with new mirror. This is for testing/CI purposes and is not meant for production."
58+
59+
if [ ! -f "$REGISTRY_MIRROR_CONFIG_FILE" ]; then
60+
echo "$REGISTRY_MIRROR_CONFIG_FILE doesn't exist; this is needed for cluster containerd private registry config. Exiting..."
61+
exit 1
62+
fi
63+
MIRROR_ENDPOINT=$(< "$REGISTRY_MIRROR_CONFIG_FILE" cut -d "=" -f 2)
64+
{
65+
# adds new line
66+
echo ""
67+
echo 'containerdConfigPatches:'
68+
echo ' - |-'
69+
echo ' [plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]'
70+
echo " endpoint = [$MIRROR_ENDPOINT]"
71+
} >> "$KIND_SET_UP_CONFIG_FILE"
72+
fi
73+
3174
# deploy cluster with kind
32-
cat <<EOF | kind create cluster --image="$KIND_IMAGE" --config=-
33-
kind: Cluster
34-
apiVersion: kind.x-k8s.io/v1alpha4
35-
kubeadmConfigPatches:
36-
- |
37-
kind: ClusterConfiguration
38-
scheduler:
39-
dnsPolicy: ClusterFirstWithHostNet
40-
extraArgs:
41-
config: /etc/kubernetes/policy/policy.yaml
42-
extraVolumes:
43-
- name: kubeconfig
44-
hostPath: /etc/kubernetes/scheduler.conf
45-
mountPath: /etc/kubernetes/scheduler.conf
46-
- name: certs
47-
hostPath: /etc/kubernetes/pki/
48-
mountPath: /etc/kubernetes/pki/
49-
- name: schedulerconfig
50-
hostPath: /etc/kubernetes/policy/policy.yaml
51-
mountPath: /etc/kubernetes/policy/policy.yaml
52-
nodes:
53-
- role: control-plane
54-
extraMounts:
55-
- hostPath: "${mount_dir:?}"
56-
containerPath: "/etc/kubernetes/policy/"
57-
- role: worker
58-
extraMounts:
59-
- hostPath: "${mount_dir}/node1"
60-
containerPath: "/tmp/node-metrics/node1.prom"
61-
propagation: HostToContainer
62-
- role: worker
63-
extraMounts:
64-
- hostPath: "${mount_dir}/node2"
65-
containerPath: "/tmp/node-metrics/node2.prom"
66-
propagation: HostToContainer
67-
- role: worker
68-
extraMounts:
69-
- hostPath: "${mount_dir}/node3"
70-
containerPath: "/tmp/node-metrics/node3.prom"
71-
propagation: HostToContainer
72-
73-
EOF
75+
kind create cluster --image="$KIND_IMAGE" --config="$KIND_SET_UP_CONFIG_FILE"
76+
77+
# clean-up
78+
if [ -f "$KIND_SET_UP_CONFIG_FILE" ]; then
79+
echo "$KIND_SET_UP_CONFIG_FILE should be temporary. Will proceed to remove it..."
80+
rm "$KIND_SET_UP_CONFIG_FILE"
81+
echo "Removal complete."
82+
fi
83+
}
84+
85+
install_certs_in_kind() {
86+
if [ "$CHANGE_MIRROR_REPO" == "true" ]; then
87+
# install the required certificates to access the internal image registry
88+
# the first kind is the default name of the cluster if you don't provide one, and -kind is appended afterwards by Kind
89+
echo "Will proceed to install the required certs in Kind for the private registry..."
90+
kind_cluster_name="kind-kind"
91+
kind_node_names="$(kubectl get nodes -o jsonpath='{.items[*].metadata.name}')"
92+
if [ -z "$kind_node_names" ]; then
93+
echo "No nodes found for the $kind_cluster_name Kind cluster. Instead found: $kind_node_names. Exit..."
94+
exit 1
95+
fi
96+
97+
read -ra kind_node_names_array <<< "$kind_node_names"
98+
99+
for kind_node in "${kind_node_names_array[@]}"
100+
do
101+
echo "$kind_node"
102+
docker cp "$KIND_INTERNAL_CERTS_DIR/." "$kind_node:$UBUNTU_CERTS_DIR"
103+
# we need to run the remaining certificate install commands
104+
echo "Installing the necessary certificates for node $kind_node..."
105+
docker exec "$kind_node" update-ca-certificates
106+
# restart containerd on the node
107+
docker exec "$kind_node" systemctl restart containerd
108+
done
109+
fi
74110
}
75111

76112
retry() {
@@ -118,8 +154,7 @@ cp "${K8_ADDITIONS_PATH}/node3" "${mount_dir}"
118154

119155
echo "## start Kind cluster with precreated CA key/cert"
120156
create_cluster
121-
122-
157+
install_certs_in_kind
123158

124159
kubectl create namespace monitoring;
125160
helm install node-exporter "${root}/telemetry-aware-scheduling/deploy/charts/prometheus_node_exporter_helm_chart/";
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
kubeadmConfigPatches:
4+
- |
5+
kind: ClusterConfiguration
6+
scheduler:
7+
dnsPolicy: ClusterFirstWithHostNet
8+
extraArgs:
9+
config: /etc/kubernetes/policy/policy.yaml
10+
extraVolumes:
11+
- name: kubeconfig
12+
hostPath: /etc/kubernetes/scheduler.conf
13+
mountPath: /etc/kubernetes/scheduler.conf
14+
- name: certs
15+
hostPath: /etc/kubernetes/pki/
16+
mountPath: /etc/kubernetes/pki/
17+
- name: schedulerconfig
18+
hostPath: /etc/kubernetes/policy/policy.yaml
19+
mountPath: /etc/kubernetes/policy/policy.yaml
20+
nodes:
21+
- role: control-plane
22+
extraMounts:
23+
- hostPath: "CP_MOUNT_DIR"
24+
containerPath: "/etc/kubernetes/policy/"
25+
- role: worker
26+
extraMounts:
27+
- hostPath: "WORKER_MOUNT_DIR/node1"
28+
containerPath: "/tmp/node-metrics/node1.prom"
29+
propagation: HostToContainer
30+
- role: worker
31+
extraMounts:
32+
- hostPath: "WORKER_MOUNT_DIR/node2"
33+
containerPath: "/tmp/node-metrics/node2.prom"
34+
propagation: HostToContainer
35+
- role: worker
36+
extraMounts:
37+
- hostPath: "WORKER_MOUNT_DIR/node3"
38+
containerPath: "/tmp/node-metrics/node3.prom"
39+
propagation: HostToContainer
40+

.github/workflows/end-to-end-test.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ on:
2323
required: false
2424
type: string
2525
default: 'false'
26+
isLocal:
27+
required: false
28+
type: string
29+
default: 'false'
2630

2731
jobs:
2832
docker-image-cleanup:
@@ -49,9 +53,9 @@ jobs:
4953
with:
5054
go-version: ${{ inputs.goVersion}}
5155
- name: Get tools for cluster installation
52-
run: ./.github/scripts/e2e_get_tools.sh ${{ inputs.kindversion }}
56+
run: ./.github/scripts/e2e_get_tools.sh ${{ inputs.kindversion }} ${{ inputs.isLocal }}
5357
- name: Set up cluster with TAS and custom metrics
54-
run: ./.github/scripts/e2e_setup_cluster.sh
58+
run: ./.github/scripts/e2e_setup_cluster.sh ${{ inputs.imagehash }} ${{ inputs.isLocal }}
5559
- name: Run end to end tests
5660
run: cd .github/e2e/&& go test -v e2e_test.go
5761
- name: Clean up Kind cluster

.github/workflows/workflow.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ jobs:
3737
if: ( !contains(github.repository, '/platform-aware-scheduling') && github.event_name == 'pull_request' )
3838
with:
3939
runson: self-hosted-kind
40+
isLocal: "true"

0 commit comments

Comments
 (0)