@@ -6,11 +6,15 @@ function enforceSELinux(){
66 echo " > Check SELinux status"
77 # Short circuit if SELinux is not being enforced.
88 getenforce | grep -q Enforcing
9- # Remove dontaudits from policy for debugging
9+ # Remove dontaudits from policy for debugging.
1010 sudo semodule -DB
11- # Install container-selinux and selinux-policy latest versions
11+ # Install extra kernel modules needed for networking/conntrack (EL10 requirement).
12+ # See: https://docs.rke2.io/install/requirements#linux
13+ # We target $(uname -r) to ensure modules match the running kernel and avoid a reboot.
14+ sudo dnf install " kernel-modules-extra-$( uname -r) " -y
15+ # Install container-selinux and selinux-policy latest versions.
1216 sudo dnf install -y container-selinux selinux-policy --best --allowerasing
13- # Install rancher-selinux policy
17+ # Install rancher-selinux policy.
1418 sudo dnf install -y /tmp/rancher-selinux.rpm
1519}
1620
@@ -40,13 +44,17 @@ function installDependencies(){
4044
4145function installRKE2(){
4246 echo " > Installing RKE2"
43- curl -sfL https://get.rke2.io | sh -
47+ # Download the official RKE2 installer script and patch the script to include EL10 in the RPM-based OS detection logic.
48+ # This changes '7|8|9)' to '7|8|9|10)' so the script doesn't fall back to a generic tarball install.
49+ # TODO: use the default install command once https://github.com/rancher/rke2/pull/9557 is merged.
50+ curl -sfL https://get.rke2.io -o install.sh
51+ sed -i ' s/7|8|9)/7|8|9|10)/g' install.sh && sh install.sh
4452 systemctl start rke2-server.service
4553 systemctl enable rke2-server.service
4654
4755 export KUBECONFIG=/etc/rancher/rke2/rke2.yaml
4856 echo " export KUBECONFIG=/etc/rancher/rke2/rke2.yaml" >> ~ /.bashrc
49- # Making the kubeconfig world-readable, as this is for tests purposes only.
57+ # Making the kubeconfig world-readable, as this is for test purposes only.
5058 chmod +r /etc/rancher/rke2/rke2.yaml
5159
5260 kubectl wait --for=create node/$( hostname) --timeout=240s
@@ -70,26 +78,24 @@ function installRancher(){
7078 --namespace cattle-system \
7179 --set hostname=rancher.local \
7280 --set replicas=1 \
73- --wait
74-
75- # Background processes, such as Fleet deployment need to take place, which
76- # may result in intermittent errors. Adding some extra verification,
77- # such as rancher-webhook deployment creation.
81+ --wait
7882
83+ # Background processes, such as Fleet deployment need to take place, which may result in intermittent errors.
84+ # Adding some extra verification, such as rancher-webhook deployment creation.
7985 kubectl wait --for=condition=ready -n cattle-system pod -l app=rancher --timeout=600s
8086 kubectl wait --for=create -n cattle-system deployment/rancher-webhook --timeout=240s
8187 kubectl wait --for=condition=ready -n cattle-system pod -l app=rancher-webhook --timeout=240s
8288}
8389
84- # Example: installRancherChart "rancher-monitoring" "cattle-monitoring-system" "rancher-monitoring-prometheus-node-exporter" "app.kubernetes.io/name=prometheus-node-exporter" "--set prometheus.prometheusSpec.maximumStartupDurationSeconds=60"
90+ # Example: installRancherChart "rancher-monitoring" "cattle-monitoring-system" "rancher-monitoring-prometheus-node-exporter" "app.kubernetes.io/name=prometheus-node-exporter" "--set ...".
8591function installRancherChart() {
8692 local CHART_NAME=" $1 "
8793 local NAMESPACE=" $2 "
8894 local DAEMONSET_NAME=" $3 "
8995 local POD_LABEL_SELECTOR=" $4 "
90- local EXTRA_HELM_ARGS=" ${@: 5} " # Collect any additional arguments
96+ local EXTRA_HELM_ARGS=" ${@: 5} " # Collect any additional arguments.
9197
92- # Add Rancher charts repository
98+ # Add Rancher charts repository.
9399 helm repo add rancher-charts https://charts.rancher.io/
94100
95101 echo " > Installing CRD chart ${CHART_NAME} -crd in namespace ${NAMESPACE} "
@@ -108,7 +114,7 @@ function installRancherChart() {
108114 --set global.seLinux.enabled=true \
109115 ${EXTRA_HELM_ARGS}
110116
111- # Wait for DaemonSet creation and Pod readiness
117+ # Wait for DaemonSet creation and Pod readiness.
112118 kubectl wait --for=create -n " ${NAMESPACE} " daemonset/" ${DAEMONSET_NAME} " --timeout=240s
113119 kubectl wait --for=condition=ready -n " ${NAMESPACE} " pod -l " ${POD_LABEL_SELECTOR} " --timeout=240s
114120}
@@ -125,12 +131,12 @@ function uninstallRancherChart() {
125131 echo " > Deleting namespace ${NAMESPACE} "
126132 kubectl delete ns " ${NAMESPACE} " --timeout=120s
127133
128- # Force-reclaim caches to provide a clean memory slate for the next chart test
129- # This was added to help mitigate time-out issues in e2e
134+ # Force-reclaim caches to provide a clean memory slate for the next chart test.
135+ # This was added to help mitigate time-out issues in e2e.
130136 sudo sync && echo 3 > /proc/sys/vm/drop_caches
131137}
132138
133- # Example: e2eSELinuxVerification "fluentbit" "fluent-bit" "cattle-logging-system" "rke_logreader_t"
139+ # Example: e2eSELinuxVerification "fluentbit" "fluent-bit" "cattle-logging-system" "rke_logreader_t".
134140function e2eSELinuxVerification(){
135141 local CONTAINER_NAME=" $1 "
136142 local CONTAINER_RUNNING_NAME=" $2 "
@@ -171,45 +177,42 @@ function main(){
171177 installRKE2
172178 installRancher
173179
174- # Note: Append this list with new components to install and test the rancher-selinux policy
175- # Value: A space-separated list of arguments:
176- # Namespace DaemonSet PodLabel ContainerName ContainerRunningName SELinuxType ExtraHelmArgs
180+ # Note: Append this list with new components to install and test the rancher-selinux policy.
181+ # Value: A space-separated list of arguments: Namespace DaemonSet PodLabel ContainerName ContainerRunningName SELinuxType ExtraHelmArgs.
177182 declare -A COMPONENTS=(
178183 [rancher-monitoring]=" cattle-monitoring-system rancher-monitoring-prometheus-node-exporter app.kubernetes.io/name=prometheus-node-exporter node-exporter node-exporter prom_node_exporter_t --set prometheus.prometheusSpec.maximumStartupDurationSeconds=60"
179184 [rancher-logging]=" cattle-logging-system rancher-logging-root-fluentbit app.kubernetes.io/name=fluentbit fluentbit fluent-bit rke_logreader_t"
180185 )
181186
182187 for CHART_NAME in " ${! COMPONENTS[@]} " ; do
183- # Read the space-separated values into individual variables
188+ # Read the space-separated values into individual variables.
184189 read -r NAMESPACE DAEMONSET_NAME POD_LABEL CONTAINER_NAME CONTAINER_RUNNING_NAME SELINUX_TYPE EXTRA_HELM_ARGS <<< " ${COMPONENTS[${CHART_NAME}]}"
185190
186191 echo " > Installing and testing Chart: ${CHART_NAME} in Namespace: ${NAMESPACE} with SELinux type ${SELINUX_TYPE} "
187192
188- # 1. Install the chart (passing the collected variables)
193+ # 1. Install the chart (passing the collected variables).
189194 installRancherChart \
190195 " ${CHART_NAME} " \
191196 " ${NAMESPACE} " \
192197 " ${DAEMONSET_NAME} " \
193198 " ${POD_LABEL} " \
194199 " ${EXTRA_HELM_ARGS} "
195200
196- # 2. Run E2E SELinux Verification
201+ # 2. Run E2E SELinux Verification.
197202 e2eSELinuxVerification \
198203 " ${CONTAINER_NAME} " \
199204 " ${CONTAINER_RUNNING_NAME} " \
200205 " ${NAMESPACE} " \
201206 " ${SELINUX_TYPE} "
202207
203- # 3. Uninstall the chart (free some resources)
208+ # 3. Uninstall the chart (free some resources).
204209 uninstallRancherChart \
205210 " ${CHART_NAME} " \
206211 " ${NAMESPACE} "
207212 done
208213}
209214
210- # This is needed as Rocky does not include it in the PATH,
211- # which is required for the Helm install.
215+ # Rocky does not include this in the PATH by default, which is required for Helm.
212216export PATH=$PATH :/usr/local/bin
213217
214218main
215-
0 commit comments