diff --git a/providers/amazon/src/airflow/providers/amazon/aws/hooks/eks.py b/providers/amazon/src/airflow/providers/amazon/aws/hooks/eks.py index 60d3b5bb7a078..210301590ee1e 100644 --- a/providers/amazon/src/airflow/providers/amazon/aws/hooks/eks.py +++ b/providers/amazon/src/airflow/providers/amazon/aws/hooks/eks.py @@ -79,16 +79,25 @@ class NodegroupStates(Enum): COMMAND = """ + export PYTHON_OPERATORS_VIRTUAL_ENV_MODE=1 output=$({python_executable} -m airflow.providers.amazon.aws.utils.eks_get_token \ --cluster-name {eks_cluster_name} {args} 2>&1) - if [ $? -ne 0 ]; then - echo "Error running the script" - exit 1 + status=$? + + if [ "$status" -ne 0 ]; then + printf '%s' "$output" >&2 + exit "$status" fi - expiration_timestamp=$(echo "$output" | grep -oP 'expirationTimestamp: \\K[^,]+') - token=$(echo "$output" | grep -oP 'token: \\K[^,]+') + # Use pure bash below to parse so that it's posix compliant + + last_line=${{output##*$'\\n'}} # strip everything up to the last newline + + timestamp=${{last_line#expirationTimestamp: }} # drop the label + timestamp=${{timestamp%%,*}} # keep up to the first comma + + token=${{last_line##*, token: }} # text after ", token: " json_string=$(printf '{{"kind": "ExecCredential","apiVersion": \ "client.authentication.k8s.io/v1alpha1","spec": {{}},"status": \