github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/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  issue="https://github.com/kata-containers/runtime/issues/1674"
    12  
    13  setup() {
    14  	skip "test not working see: ${issue}"
    15  
    16  	export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}"
    17  	pod_name="footubuntu"
    18  	config_name="ssh-config-map"
    19  	get_pod_config_dir
    20  
    21  	# Creates ssh-key
    22  	key_path=$(mktemp --tmpdir)
    23  	public_key_path="${key_path}.pub"
    24  	echo -e 'y\n' | sudo ssh-keygen -t rsa -N "" -f "$key_path"
    25  
    26  	# Create ConfigMap.yaml
    27  	configmap_yaml="${pod_config_dir}/footloose-rsa-configmap.yaml"
    28  	sed -e "/\${ssh_key}/r ${public_key_path}" -e "/\${ssh_key}/d" \
    29  		"${pod_config_dir}/footloose-configmap.yaml" > "$configmap_yaml"
    30  	sed -i 's/ssh-rsa/      ssh-rsa/' "$configmap_yaml"
    31  }
    32  
    33  @test "Footloose pod" {
    34  	skip "test not working see: ${issue}"
    35  
    36  	cmd="uname -r"
    37  	sleep_connect="10"
    38  
    39  	# Create ConfigMap
    40  	kubectl create -f "$configmap_yaml"
    41  
    42  	# Create pod
    43  	kubectl create -f "${pod_config_dir}/pod-footloose.yaml"
    44  
    45  	# Check pod creation
    46  	kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
    47  
    48  	# Get pod ip
    49  	pod_ip=$(kubectl get pod $pod_name --template={{.status.podIP}})
    50  
    51  	# Exec to the pod
    52  	kubectl exec $pod_name -- sh -c "$cmd"
    53  
    54  	# Connect to the VM
    55  	sleep "$sleep_connect"
    56  	ssh -i "$key_path" -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no 2>/dev/null root@"$pod_ip" "$cmd"
    57  }
    58  
    59  teardown() {
    60  	skip "test not working see: ${issue}"
    61  
    62  	kubectl delete pod "$pod_name"
    63  	kubectl delete configmap "$config_name"
    64  	sudo rm -rf "$public_key_path"
    65  	sudo rm -rf "$key_path"
    66  	sudo rm -rf "$configmap_yaml"
    67  }