Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASMINST-6821: goss-k8s-pods-ips-in-nmn-pool: Backport fixes to CSM 1.4.5 #569

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions goss-testing/scripts/check_goss_k8s_pods_ips_in_nmn_pool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash
#
# MIT License
#
# (C) Copyright 2023-2024 Hewlett Packard Enterprise Development LP
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#

out=$(cray sls search networks list --name NMN --format json 2>&1)
if [ "$?" -eq 0 ]; then
echo "Successfully called sls search networks..."
network=$(echo "$out" | jq -r '.[].ExtraProperties.Subnets[] | select(.FullName == "NMN Bootstrap DHCP Subnet") | .CIDR')
else
echo "Failed to talk to sls, looking for sls_input_file.json on the filesystem..."
#
# We are unable to talk to sls, let's see if can find the sls_input_file.json
# on the filesystem in either of these locations:
#
# /var/www/ephemeral/prep/SYSTEM-NAME/sls_input_file.json
# /metal/bootstrap/prep/SYSTEM-NAME/sls_input_file.json
#
system_name=$(craysys metadata get system-name)
if [ "$?" -ne 0 ]; then
echo "FAIL: Unable to call craysys to get system name"
exit 1
fi

pit_file="/var/www/ephemeral/prep/${system_name}/sls_input_file.json"
post_pit_file="/metal/bootstrap/prep/${system_name}/sls_input_file.json"
if test -f "$pit_file"; then
echo "Found sls_input_file.json at $pit_file, proceeding..."
network=$(cat $pit_file | jq -r '.Networks.NMN.ExtraProperties.Subnets[] | select(.FullName == "NMN Bootstrap DHCP Subnet") | .CIDR')
elif test -f "$post_pit_file"; then
echo "Found sls_input_file.json at $post_pit_file, proceeding..."
network=$(cat $post_pit_file | jq -r '.Networks.NMN.ExtraProperties.Subnets[] | select(.FullName == "NMN Bootstrap DHCP Subnet") | .CIDR')
else
#
# Couldn't talk to SLS, or find the sls_input_file.json file
# anywhere, without valid data, we'll skip this test.
#
echo "PASS: Unable to determine NMN subnet, skipping test..."
exit 0
fi
fi

ips=$(kubectl -n kube-system get pods -o wide | grep -E '^kube-apiserver|^kube-controller-manager|^kube-multus-ds|^kube-proxy|^kube-scheduler|^weave-net' | awk '{print $(NF-3)}')

valid_ips=$(nmap -sL -n $network)
bad_ip=0
for ip in $ips
do
echo "$valid_ips" | grep -q $ip
if [ "$?" -ne 0 ]; then
bad_ip=1
echo "ERROR: The following IP: $ip is not in the NMN subnet ($network)"
fi
done

if [ "$bad_ip" -eq 1 ]; then
echo "FAIL: At least one IP was not in the correct NMN Bootstrap DHCP Subnet"
exit 1
fi

echo "PASS: All K8S pod IPs are in the NMN Bootstrap DHCP Subnet"
exit 0
14 changes: 10 additions & 4 deletions goss-testing/tests/ncn/goss-k8s-pods-ips-in-nmn-pool.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# MIT License
#
# (C) Copyright 2014-2022 Hewlett Packard Enterprise Development LP
# (C) Copyright 2014-2024 Hewlett Packard Enterprise Development LP
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
Expand All @@ -21,13 +21,19 @@
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
{{ $scripts := .Env.GOSS_BASE | printf "%s/scripts" }}
{{ $logrun := $scripts | printf "%s/log_run.sh" }}
{{ $k8s_pods_ips_in_nmn_pool_check := $scripts | printf "%s/check_goss_k8s_pods_ips_in_nmn_pool.sh" }}
command:
check_k8s_pods_ips_in_nmn_pool:
{{ $testlabel := "check_k8s_pods_ips_in_nmn_pool" }}
{{$testlabel}}:
title: Kubernetes Pod IPs in NMN Pool
meta:
desc: Correct pods in kube-system namespace exist and are on the right network.
desc: If this test fails, run the script "{{$k8s_pods_ips_in_nmn_pool_check}}" to see a description of the offending IPs.
sev: 0
exec: "kubectl -n kube-system get pods -o wide | grep -E '^kube-apiserver|^kube-controller-manager|^kube-multus-ds|^kube-proxy|^kube-scheduler|^weave-net' | awk '{print $6}' | grep -v '10\\.252\\.' || echo PASS"
exec: |-
"{{$logrun}}" -l "{{$testlabel}}" \
"{{$k8s_pods_ips_in_nmn_pool_check}}"
stdout:
- PASS
exit-status: 0
Expand Down
Loading