@@ -16,6 +16,16 @@ CNIS_NAME="cni-plugins"
16
16
KIND_IMAGE=" kindest/node:v1.23.0@sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac"
17
17
[ -n " $1 " ] && KIND_IMAGE=$1
18
18
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
+
19
29
# create cluster CA and policy for Kubernetes Scheduler
20
30
# CA cert & key along with will be mounted to control plane
21
31
# path /etc/kubernetes/pki. Kubeadm will utilise generated CA cert/key as root
@@ -28,49 +38,75 @@ generate_k8_scheduler_config_data() {
28
38
29
39
create_cluster () {
30
40
[ -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
+
31
74
# 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
74
110
}
75
111
76
112
retry () {
@@ -118,8 +154,7 @@ cp "${K8_ADDITIONS_PATH}/node3" "${mount_dir}"
118
154
119
155
echo " ## start Kind cluster with precreated CA key/cert"
120
156
create_cluster
121
-
122
-
157
+ install_certs_in_kind
123
158
124
159
kubectl create namespace monitoring;
125
160
helm install node-exporter " ${root} /telemetry-aware-scheduling/deploy/charts/prometheus_node_exporter_helm_chart/" ;
0 commit comments