[ -d "$CURR_DIR"]||{echo"FATAL: no current dir (maybe running in zsh?)";exit 1;}
shopt -s nullglob # nullglob expands non-matching globs to zero arguments, rather than to themselves -> empty array when used to get array of filepaths
check_multi_node "$clustername"5|| failed "failed to verify number of nodes"
check_multi_node "$clustername"5|| failed_with_logfile"failed to verify number of nodes""$LOG_FILE"
# 2. check some config settings
## Environment Variables
info "Ensuring that environment variables are present in the node containers as set in the config (with comma)"
exec_in_node "k3d-$clustername-server-0""env"| grep -q "bar=baz,bob"|| failed "Expected env var 'bar=baz,bob' is not present in node k3d-$clustername-server-0"
exec_in_node "k3d-$clustername-server-0""env"| grep -q "bar=baz,bob"|| failed_with_logfile"Expected env var 'bar=baz,bob' is not present in node k3d-$clustername-server-0""$LOG_FILE"
## Container Labels
info "Ensuring that container labels have been set as stated in the config"
docker_assert_container_label "k3d-$clustername-server-0""foo=bar"|| failed "Expected label 'foo=bar' not present on container/node k3d-$clustername-server-0"
docker_assert_container_label "k3d-$clustername-server-0""foo=bar"|| failed_with_logfile"Expected label 'foo=bar' not present on container/node k3d-$clustername-server-0""$LOG_FILE"
## K3s Node Labels
info "Ensuring that k3s node labels have been set as stated in the config"
k3s_assert_node_label "k3d-$clustername-server-0""foo=bar"|| failed "Expected label 'foo=bar' not present on node k3d-$clustername-server-0"
k3s_assert_node_label "k3d-$clustername-server-0""foo=bar"|| failed_with_logfile"Expected label 'foo=bar' not present on node k3d-$clustername-server-0""$LOG_FILE"
## Registry Node
registryname="registry.localhost"
info "Ensuring, that we have a registry node present"
$EXE node list "$registryname"|| failed "Expected registry node $registryname to be present"
$EXE node list "$registryname"|| failed_with_logfile"Expected registry node $registryname to be present""$LOG_FILE"
## merged registries.yaml
info "Ensuring, that the registries.yaml file contains both registries"
exec_in_node "k3d-$clustername-server-0""cat /etc/rancher/k3s/registries.yaml"| grep -qi "my.company.registry"|| failed "Expected 'my.company.registry' to be in the /etc/rancher/k3s/registries.yaml"
exec_in_node "k3d-$clustername-server-0""cat /etc/rancher/k3s/registries.yaml"| grep -qi "$registryname"|| failed "Expected '$registryname' to be in the /etc/rancher/k3s/registries.yaml"
exec_in_node "k3d-$clustername-server-0""cat /etc/rancher/k3s/registries.yaml"| grep -qi "my.company.registry"|| failed_with_logfile"Expected 'my.company.registry' to be in the /etc/rancher/k3s/registries.yaml""$LOG_FILE"
exec_in_node "k3d-$clustername-server-0""cat /etc/rancher/k3s/registries.yaml"| grep -qi "$registryname"|| failed_with_logfile"Expected '$registryname' to be in the /etc/rancher/k3s/registries.yaml""$LOG_FILE"
# Cleanup
info "Deleting cluster $clustername (using config file)..."
$EXE cluster delete --config "$configfile"|| failed "could not delete the cluster $clustername"
$EXE cluster delete --config "$configfile"|| failed_with_logfile"could not delete the cluster $clustername""$LOG_FILE"
info "Ensuring, that we DO NOT have a registry node present"
$EXE node list "k3d-$clustername-registry"&& failed "Expected k3d-$clustername-registry to NOT be present"
## merged registries.yaml
info "Ensuring, that the registries.yaml file contains both registries"
exec_in_node "k3d-$clustername-server-0""cat /etc/rancher/k3s/registries.yaml"| grep -qi "my.company.registry"|| failed "Expected 'my.company.registry' to be in the /etc/rancher/k3s/registries.yaml"