github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/integration/kubernetes/k8s-footloose.bats (about)

     1  #!/usr/bin/env bats
     2  #
     3  # Copyright (c) 2019 Intel Corporation
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  #
     7  
     8  load "${BATS_TEST_DIRNAME}/../../.ci/lib.sh"
     9  load "${BATS_TEST_DIRNAME}/tests_common.sh"
    10  
    11  setup() {
    12  	pod_name="footubuntu"
    13  	config_name="ssh-config-map"
    14  	get_pod_config_dir
    15  
    16  	# Creates ssh-key
    17  	key_path=$(mktemp --tmpdir)
    18  	public_key_path="${key_path}.pub"
    19  	echo -e 'y\n' | sudo ssh-keygen -t rsa -N "" -f "$key_path"
    20  
    21  	# Create ConfigMap.yaml
    22  	configmap_yaml="${pod_config_dir}/footloose-rsa-configmap.yaml"
    23  	sed -e "/\${ssh_key}/r ${public_key_path}" -e "/\${ssh_key}/d" \
    24  		"${pod_config_dir}/footloose-configmap.yaml" > "$configmap_yaml"
    25  	sed -i 's/ssh-rsa/      ssh-rsa/' "$configmap_yaml"
    26  }
    27  
    28  @test "Footloose pod" {
    29  	cmd="uname -r"
    30  	sleep_connect="10"
    31  
    32  	# Create ConfigMap
    33  	kubectl create -f "$configmap_yaml"
    34  
    35  	# Create pod
    36  	kubectl create -f "${pod_config_dir}/pod-footloose.yaml"
    37  
    38  	# Check pod creation
    39  	kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
    40  
    41  	# Get pod ip
    42  	pod_ip=$(kubectl get pod $pod_name --template={{.status.podIP}})
    43  
    44  	# Exec to the pod
    45  	kubectl exec $pod_name -- sh -c "$cmd"
    46  
    47  	# Connect to the VM
    48  	sleep "$sleep_connect"
    49  	ssh -i "$key_path" -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no 2>/dev/null root@"$pod_ip" "$cmd"
    50  }
    51  
    52  teardown() {
    53  	kubectl delete pod "$pod_name"
    54  	kubectl delete configmap "$config_name"
    55  	sudo rm -rf "$public_key_path"
    56  	sudo rm -rf "$key_path"
    57  	sudo rm -rf "$configmap_yaml"
    58  }