Merge pull request #9726 from GabyCT/topic/unodeport

tests: kbs: Use nodeport deployment from upstream trustee
This commit is contained in:
Fabiano Fidêncio
2024-06-16 22:31:27 +02:00
committed by GitHub

View File

@@ -24,6 +24,8 @@ readonly KBS_NS="coco-tenant"
readonly KBS_PRIVATE_KEY="${COCO_KBS_DIR}/config/kubernetes/base/kbs.key" readonly KBS_PRIVATE_KEY="${COCO_KBS_DIR}/config/kubernetes/base/kbs.key"
# The kbs service name # The kbs service name
readonly KBS_SVC_NAME="kbs" readonly KBS_SVC_NAME="kbs"
# The kbs ingress name
readonly KBS_INGRESS_NAME="kbs"
# Set "allow all" policy to resources. # Set "allow all" policy to resources.
# #
@@ -243,7 +245,6 @@ function kbs_k8s_deploy() {
kustomize edit set image "kbs-container-image=${image}:${image_tag}" kustomize edit set image "kbs-container-image=${image}:${image_tag}"
popd popd
echo "::endgroup::" echo "::endgroup::"
[ -n "$ingress" ] && _handle_ingress "$ingress" [ -n "$ingress" ] && _handle_ingress "$ingress"
echo "::group::Deploy the KBS" echo "::group::Deploy the KBS"
@@ -259,6 +260,7 @@ function kbs_k8s_deploy() {
EOF EOF
export DEPLOYMENT_DIR=custom_pccs export DEPLOYMENT_DIR=custom_pccs
fi fi
./deploy-kbs.sh ./deploy-kbs.sh
popd popd
@@ -284,6 +286,7 @@ EOF
echo "::group::Check the service healthy" echo "::group::Check the service healthy"
kbs_ip=$(kubectl get -o jsonpath='{.spec.clusterIP}' svc "$KBS_SVC_NAME" -n "$KBS_NS" 2>/dev/null) kbs_ip=$(kubectl get -o jsonpath='{.spec.clusterIP}' svc "$KBS_SVC_NAME" -n "$KBS_NS" 2>/dev/null)
kbs_port=$(kubectl get -o jsonpath='{.spec.ports[0].port}' svc "$KBS_SVC_NAME" -n "$KBS_NS" 2>/dev/null) kbs_port=$(kubectl get -o jsonpath='{.spec.ports[0].port}' svc "$KBS_SVC_NAME" -n "$KBS_NS" 2>/dev/null)
local pod=kbs-checker-$$ local pod=kbs-checker-$$
kubectl run "$pod" --image=quay.io/prometheus/busybox --restart=Never -- \ kubectl run "$pod" --image=quay.io/prometheus/busybox --restart=Never -- \
sh -c "wget -O- --timeout=5 \"${kbs_ip}:${kbs_port}\" || true" sh -c "wget -O- --timeout=5 \"${kbs_ip}:${kbs_port}\" || true"
@@ -326,15 +329,14 @@ EOF
# #
kbs_k8s_svc_host() { kbs_k8s_svc_host() {
if kubectl get ingress -n "$KBS_NS" 2>/dev/null | grep -q kbs; then if kubectl get ingress -n "$KBS_NS" 2>/dev/null | grep -q kbs; then
kubectl get ingress kbs -n "$KBS_NS" \ kubectl get ingress "$KBS_INGRESS_NAME" -n "$KBS_NS" \
-o jsonpath='{.spec.rules[0].host}' 2>/dev/null -o jsonpath='{.spec.rules[0].host}' 2>/dev/null
elif kubectl get svc kbs-nodeport -n "$KBS_NS" &>/dev/null; then elif kubectl get svc "$KBS_SVC_NAME" -n "$KBS_NS" &>/dev/null; then
local host local host
host=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="ExternalIP")].address}' -n "$KBS_NS") host=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}' -n "$KBS_NS")
[ -z "$host"] && host=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}' -n "$KBS_NS")
echo "$host" echo "$host"
else else
kubectl get svc kbs -n "$KBS_NS" \ kubectl get svc "$KBS_SVC_NAME" -n "$KBS_NS" \
-o jsonpath='{.spec.clusterIP}' 2>/dev/null -o jsonpath='{.spec.clusterIP}' 2>/dev/null
fi fi
} }
@@ -346,10 +348,10 @@ kbs_k8s_svc_port() {
if kubectl get ingress -n "$KBS_NS" 2>/dev/null | grep -q kbs; then if kubectl get ingress -n "$KBS_NS" 2>/dev/null | grep -q kbs; then
# Assume served on default HTTP port 80 # Assume served on default HTTP port 80
echo "80" echo "80"
elif kubectl get svc kbs-nodeport -n "$KBS_NS" &>/dev/null; then elif kubectl get svc "$KBS_SVC_NAME" -n "$KBS_NS" &>/dev/null; then
kubectl get -o jsonpath='{.spec.ports[0].nodePort}' svc kbs-nodeport -n "$KBS_NS" kubectl get svc "$KBS_SVC_NAME" -n "$KBS_NS" -o jsonpath='{.spec.ports[0].nodePort}'
else else
kubectl get svc kbs -n "$KBS_NS" \ kubectl get svc "$KBS_SVC_NAME" -n "$KBS_NS" \
-o jsonpath='{.spec.ports[0].port}' 2>/dev/null -o jsonpath='{.spec.ports[0].port}' 2>/dev/null
fi fi
} }
@@ -449,28 +451,8 @@ _handle_ingress_aks() {
} }
# Implements the ingress handler for servernode # Implements the ingress handler for servernode
# this is useful on kcli or anywhere where cluster IPs are accessible
# from the testing machines.
# #
_handle_ingress_nodeport() { _handle_ingress_nodeport() {
pushd "${COCO_KBS_DIR}/config/kubernetes/overlays" # By exporting this variable the kbs deploy script will install the nodeport service
export DEPLOYMENT_DIR=nodeport
cat > nodeport_service.yaml <<EOF
# Service to expose the KBS on nodes
apiVersion: v1
kind: Service
metadata:
name: kbs-nodeport
namespace: "$KBS_NS"
spec:
selector:
app: kbs
ports:
- protocol: TCP
port: 8080
targetPort: 8080
type: NodePort
EOF
kustomize edit add resource nodeport_service.yaml
popd
} }