Skip to content

Commit 1e858ed

Browse files
authored
Merge pull request #8567 from dims/fix-nginx-configuration-and-add-a-verify-script
fix nginx configuration and add a verify script
2 parents 9634524 + ce0d7f4 commit 1e858ed

File tree

2 files changed

+78
-5
lines changed

2 files changed

+78
-5
lines changed

apps/k8s-io/configmap-nginx.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ data:
345345
server_name releases.k8s.io rel.k8s.io releases.kubernetes.io rel.kubernetes.io;
346346
listen 80;
347347
348+
location / {
348349
rewrite ^/$ https://github.com/kubernetes/kubernetes/releases redirect;
349350
rewrite ^/k8s-release-cal https://calendar.google.com/calendar/embed?src=kipmnllvl17vl9m98jen6ujcrs%40group.calendar.google.com redirect;
350351
rewrite ^/k8s-sig-release-videos https://youtube.com/playlist?list=PL69nYSiGNLP3QKkOsDsO6A0Y1rhgP84iZ&si=Mi095CYuJuz8LjN- redirect;
@@ -354,20 +355,20 @@ data:
354355
}
355356
356357
server {
357-
server_name sbom.k8s.io sbom.kubernetes.io
358+
server_name sbom.k8s.io sbom.kubernetes.io;
358359
listen 80;
359360
360361
rewrite ^/(.*)?/release(\.cert|\.sig|\.sha256|\.sha512)?$ https://dl.k8s.io/release/$1/kubernetes-release.spdx$2 redirect;
361362
rewrite ^/(.*)?/source(\.cert|\.sig|\.sha256|\.sha512)?$ https://dl.k8s.io/release/$1/kubernetes-source.spdx$2 redirect;
362363
}
363364
364365
server {
365-
server_name slack.k8s.io slack.kubernetes.io
366+
server_name slack.k8s.io slack.kubernetes.io;
366367
listen 80;
367368
368-
location / {
369-
rewrite ^/.*$ https://communityinviter.com/apps/kubernetes/community permanent;
370-
}
369+
location / {
370+
rewrite ^/.*$ https://communityinviter.com/apps/kubernetes/community permanent;
371+
}
371372
}
372373
373374
server {

hack/verify-nginx.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2025 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
20+
CONFIGMAP_FILE="${SCRIPT_DIR}/../apps/k8s-io/configmap-nginx.yaml"
21+
TEMP_DIR=$(mktemp -d)
22+
NGINX_CONF="${TEMP_DIR}/nginx.conf"
23+
24+
cleanup() {
25+
rm -rf "${TEMP_DIR}"
26+
}
27+
trap cleanup EXIT
28+
29+
echo "Extracting nginx.conf from ConfigMap..."
30+
31+
# Extract the nginx.conf section from the ConfigMap YAML
32+
awk '
33+
/^ nginx\.conf: \|/ {
34+
# Found the start, skip this line and start collecting
35+
found = 1
36+
next
37+
}
38+
found && /^ / {
39+
# Line starts with 4 spaces (indented content), remove the leading 4 spaces and print
40+
print substr($0, 5)
41+
next
42+
}
43+
found && !/^ / && !/^[[:space:]]*$/ {
44+
# Hit a non-indented line that is not empty, stop collecting
45+
exit
46+
}
47+
' "${CONFIGMAP_FILE}" > "${NGINX_CONF}"
48+
49+
echo "Extracted nginx.conf to: ${NGINX_CONF}"
50+
echo "Config file size: $(wc -l < "${NGINX_CONF}") lines"
51+
52+
echo "Validating nginx configuration..."
53+
54+
# Check if we can use Docker for validation
55+
if command -v docker >/dev/null 2>&1; then
56+
# Use the same nginx version as specified in the deployment
57+
NGINX_IMAGE="nginx:1.26-alpine@sha256:5b44a5ab8ab467854f2bf7b835a32f850f32eb414b749fbf7ed506b139cd8d6b"
58+
docker run --rm \
59+
-v "${TEMP_DIR}:/etc/nginx:ro" \
60+
"${NGINX_IMAGE}" \
61+
nginx -c /etc/nginx/nginx.conf -t
62+
else
63+
# Check if nginx is already installed
64+
if ! command -v nginx >/dev/null 2>&1; then
65+
if apt-get update -qq && apt-get install -y -qq nginx; then
66+
echo "Installed nginx via apt"
67+
fi
68+
fi
69+
nginx -c "${NGINX_CONF}" -t
70+
fi
71+
72+
echo "✅ Nginx configuration validation completed successfully!"

0 commit comments

Comments
 (0)