Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
kubernetes: Renaming kubernetes prefix
Browse files Browse the repository at this point in the history
Renaming k8s_* functions to kubernetes_* to match the
rest of the functions.

Fixes: #5593

Signed-Off-By: Unmesh Deodhar <[email protected]>
  • Loading branch information
UnmeshDeodhar committed Jul 7, 2023
1 parent c040815 commit 280e0f2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
38 changes: 19 additions & 19 deletions integration/kubernetes/confidential/sev.bats
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ k8s_delete_all() {
for file in $(ls "${TEST_DIR}/*.yaml") ; do
# Removing extension to get the pod name
local pod_name="${file%.*}"
k8s_delete_by_yaml "${pod_name}" "${TEST_DIR}/${file}"
kubernetes_delete_by_yaml "${pod_name}" "${TEST_DIR}/${file}"
done
}

Expand Down Expand Up @@ -71,24 +71,24 @@ setup_file() {
local kbs_uri="${kbs_ip}:44444"

# SEV unencrypted service yaml generation
k8s_generate_service_yaml "${TEST_DIR}/sev-unencrypted.yaml" "${IMAGE_REPO}:unencrypted"
k8s_yaml_set_annotation "${TEST_DIR}/sev-unencrypted.yaml" "io.katacontainers.config.guest_pre_attestation.enabled" "false"
kubernetes_generate_service_yaml "${TEST_DIR}/sev-unencrypted.yaml" "${IMAGE_REPO}:unencrypted"
kubernetes_yaml_set_annotation "${TEST_DIR}/sev-unencrypted.yaml" "io.katacontainers.config.guest_pre_attestation.enabled" "false"

# SEV encrypted service yaml generation
# SEV policy is 3 (default):
# - NODBG (1): Debugging of the guest is disallowed when set
# - NOKS (2): Sharing keys with other guests is disallowed when set
k8s_generate_service_yaml "${TEST_DIR}/sev-encrypted.yaml" "${IMAGE_REPO}:multi-arch-encrypted"
k8s_yaml_set_annotation "${TEST_DIR}/sev-encrypted.yaml" "io.katacontainers.config.pre_attestation.uri" "${kbs_uri}"
k8s_yaml_set_annotation "${TEST_DIR}/sev-encrypted.yaml" "io.katacontainers.config.sev.policy" "3"
kubernetes_generate_service_yaml "${TEST_DIR}/sev-encrypted.yaml" "${IMAGE_REPO}:multi-arch-encrypted"
kubernetes_yaml_set_annotation "${TEST_DIR}/sev-encrypted.yaml" "io.katacontainers.config.pre_attestation.uri" "${kbs_uri}"
kubernetes_yaml_set_annotation "${TEST_DIR}/sev-encrypted.yaml" "io.katacontainers.config.sev.policy" "3"

# SEV-ES policy is 7:
# - NODBG (1): Debugging of the guest is disallowed when set
# - NOKS (2): Sharing keys with other guests is disallowed when set
# - ES (4): SEV-ES is required when set
k8s_generate_service_yaml "${TEST_DIR}/sev-es-encrypted.yaml" "${IMAGE_REPO}:multi-arch-encrypted"
k8s_yaml_set_annotation "${TEST_DIR}/sev-es-encrypted.yaml" "io.katacontainers.config.pre_attestation.uri" "${kbs_uri}"
k8s_yaml_set_annotation "${TEST_DIR}/sev-es-encrypted.yaml" "io.katacontainers.config.sev.policy" "7"
kubernetes_generate_service_yaml "${TEST_DIR}/sev-es-encrypted.yaml" "${IMAGE_REPO}:multi-arch-encrypted"
kubernetes_yaml_set_annotation "${TEST_DIR}/sev-es-encrypted.yaml" "io.katacontainers.config.pre_attestation.uri" "${kbs_uri}"
kubernetes_yaml_set_annotation "${TEST_DIR}/sev-es-encrypted.yaml" "io.katacontainers.config.sev.policy" "7"
}

teardown_file() {
Expand Down Expand Up @@ -125,10 +125,10 @@ setup() {

# Retrieve pod name, wait for it to come up, retrieve pod ip
local pod_name=$(esudo kubectl get pod -o wide | grep sev-unencrypted | awk '{print $1;}')
k8s_wait_for_pod_ready_state "$pod_name" 20
kubernetes_wait_for_pod_ready_state "$pod_name" 20
local pod_ip=$(esudo kubectl get pod -o wide | grep sev-unencrypted | awk '{print $6;}')

k8s_print_info "sev-unencrypted"
kubernetes_print_info "sev-unencrypted"

# Look for SEV enabled in container dmesg output
local sev_enabled=$(ssh_dmesg_grep \
Expand Down Expand Up @@ -159,9 +159,9 @@ setup() {

# Retrieve pod name, wait for it to fail
local pod_name=$(esudo kubectl get pod -o wide | grep sev-encrypted | awk '{print $1;}')
k8s_wait_for_pod_ready_state "$pod_name" 20 || true
kubernetes_wait_for_pod_ready_state "$pod_name" 20 || true

k8s_print_info "sev-encrypted"
kubernetes_print_info "sev-encrypted"

# Save guest qemu kernel append to file
local kernel_append=$(kata_get_guest_kernel_append "${pod_name}")
Expand Down Expand Up @@ -190,10 +190,10 @@ setup() {

# Retrieve pod name, wait for it to come up, retrieve pod ip
local pod_name=$(esudo kubectl get pod -o wide | grep sev-encrypted | awk '{print $1;}')
k8s_wait_for_pod_ready_state "$pod_name" 20
kubernetes_wait_for_pod_ready_state "$pod_name" 20
local pod_ip=$(esudo kubectl get pod -o wide | grep sev-encrypted | awk '{print $6;}')

k8s_print_info "sev-encrypted"
kubernetes_print_info "sev-encrypted"

# Look for SEV enabled in container dmesg output
local sev_enabled=$(ssh_dmesg_grep \
Expand Down Expand Up @@ -225,10 +225,10 @@ setup() {

# Retrieve pod name, wait for it to come up, retrieve pod ip
local pod_name=$(esudo kubectl get pod -o wide | grep sev-encrypted | awk '{print $1;}')
k8s_wait_for_pod_ready_state "$pod_name" 20
kubernetes_wait_for_pod_ready_state "$pod_name" 20
local pod_ip=$(esudo kubectl get pod -o wide | grep sev-encrypted | awk '{print $6;}')

k8s_print_info "sev-encrypted"
kubernetes_print_info "sev-encrypted"

# Look for SEV enabled in container dmesg output
local sev_enabled=$(ssh_dmesg_grep \
Expand Down Expand Up @@ -260,10 +260,10 @@ setup() {

# Retrieve pod name, wait for it to come up, retrieve pod ip
local pod_name=$(esudo kubectl get pod -o wide | grep sev-es-encrypted | awk '{print $1;}')
k8s_wait_for_pod_ready_state "$pod_name" 20
kubernetes_wait_for_pod_ready_state "$pod_name" 20
local pod_ip=$(esudo kubectl get pod -o wide | grep sev-es-encrypted | awk '{print $6;}')

k8s_print_info "sev-es-encrypted"
kubernetes_print_info "sev-es-encrypted"

# Look for SEV-ES enabled in container dmesg output
local sev_es_enabled=$(ssh_dmesg_grep \
Expand Down
8 changes: 4 additions & 4 deletions integration/kubernetes/confidential/snp.bats
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ load "${TESTS_REPO_DIR}/integration/kubernetes/lib.sh"

# Delete all test services
k8s_delete_all() {
k8s_delete_by_yaml "snp-unencrypted" "${TEST_DIR}/snp-unencrypted.yaml"
kubernetes_delete_by_yaml "snp-unencrypted" "${TEST_DIR}/snp-unencrypted.yaml"
}

setup_file() {
Expand All @@ -44,7 +44,7 @@ setup_file() {
docker_image_label_save_ssh_key "${UNENCRYPTED_IMAGE_URL}" "${SSH_KEY_FILE}"

# SEV service yaml generation
k8s_generate_service_yaml "${TEST_DIR}/snp-unencrypted.yaml" "${IMAGE_REPO}:unencrypted"
kubernetes_generate_service_yaml "${TEST_DIR}/snp-unencrypted.yaml" "${IMAGE_REPO}:unencrypted"
}

teardown_file() {
Expand Down Expand Up @@ -74,10 +74,10 @@ setup() {

# Retrieve pod name, wait for it to come up, retrieve pod ip
local pod_name=$(esudo kubectl get pod -o wide | grep snp-unencrypted | awk '{print $1;}')
k8s_wait_for_pod_ready_state "$pod_name" 20
kubernetes_wait_for_pod_ready_state "$pod_name" 20
local pod_ip=$(esudo kubectl get pod -o wide | grep snp-unencrypted | awk '{print $6;}')

k8s_print_info "snp-unencrypted"
kubernetes_print_info "snp-unencrypted"

# Look for SEV enabled in container dmesg output
local snp_enabled=$(ssh_dmesg_grep \
Expand Down
16 changes: 8 additions & 8 deletions integration/kubernetes/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ TESTS_REPO_DIR=$(realpath $(dirname "${BASH_SOURCE[0]}")/../..)
FIXTURES_DIR="${TESTS_REPO_DIR}/integration/kubernetes/confidential/fixtures"

# Generate kubernetes service yaml from template
k8s_generate_service_yaml() {
kubernetes_generate_service_yaml() {
local service_yaml="${1}"
local image="${2}"

Expand All @@ -22,7 +22,7 @@ k8s_generate_service_yaml() {
}

# Set annotation for yaml
k8s_yaml_set_annotation() {
kubernetes_yaml_set_annotation() {
local yaml="${1}"
local key="${2}"
local value="${3}"
Expand All @@ -35,23 +35,23 @@ k8s_yaml_set_annotation() {
}

# Wait until the pod is 'Ready'. Fail if it hits the timeout.
k8s_wait_for_pod_ready_state() {
kubernetes_wait_for_pod_ready_state() {
local pod_name="${1}"
local wait_time="${2:-10}"

kubectl wait --for=condition=ready "pod/${pod_name}" --timeout=${wait_time}s
}

# Wait until the pod is 'Deleted'. Fail if it hits the timeout.
k8s_wait_for_pod_delete_state() {
kubernetes_wait_for_pod_delete_state() {
local pod_name="${1}"
local wait_time="${2:-10}"

kubectl wait --for=delete "pod/${pod_name}" --timeout=${wait_time}s
}

# Find container id
k8s_get_container_id() {
kubernetes_get_container_id() {
local pod_name="${1}"

# Get container id from pod info
Expand All @@ -63,7 +63,7 @@ k8s_get_container_id() {
}

# Delete k8s entity by yaml
k8s_delete_by_yaml() {
kubernetes_delete_by_yaml() {
local partial_pod_name="${1}"
local yaml="${2}"

Expand All @@ -74,12 +74,12 @@ k8s_delete_by_yaml() {
kubectl delete -f "${yaml}" 2>/dev/null || true

# Verify pod deleted
[ -z "${pod_name}" ] || (k8s_wait_for_pod_delete_state "${pod_name}" || true)
[ -z "${pod_name}" ] || (kubernetes_wait_for_pod_delete_state "${pod_name}" || true)
}

# Retrieve pod name and log kubernetes environment information:
# nodes, services, deployments, pods
k8s_print_info() {
kubernetes_print_info() {
local partial_pod_name="${1}"

echo "-------------------------------------------------------------------------------"
Expand Down
2 changes: 1 addition & 1 deletion lib/common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ kata_get_guest_kernel_append() {

# Attempt to get qemu command line from qemu process
while [ $SECONDS -lt $duration ]; do
container_id=$(k8s_get_container_id "${pod_name}")
container_id=$(kubernetes_get_container_id "${pod_name}")
sandbox_id=$(kata_get_sandbox_id "${container_id}")
qemu_process=$(ps aux | grep qemu | grep ${sandbox_id} | grep append || true)
if [ -n "${qemu_process}" ]; then
Expand Down

0 comments on commit 280e0f2

Please sign in to comment.