Skip to content

Instantly share code, notes, and snippets.

@drazul
Last active November 4, 2021 14:22
Show Gist options
  • Save drazul/f18681e8f598e153d9b344863423c2fd to your computer and use it in GitHub Desktop.
Save drazul/f18681e8f598e153d9b344863423c2fd to your computer and use it in GitHub Desktop.
Script to run a SparkApplication from a ScheduledSparkApplication
#!/bin/bash
namespace=${namespace:-default}
scheduledsparkapp=${scheduledsparkapp}
name=${name}
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
param="${1/--/}"
declare $param="$2"
fi
shift
done
if [ -z ${name} ] || [ -z ${namespace} ] || [ -z ${scheduledsparkapp} ];
then
echo "Wrong parameters."
echo "Usage:"
echo " --namespace <namespace where the scheduledsparkapp is defined and where the new sparkapp will be defined>"
echo " --name <name of the new sparkapp to trigger>"
echo " --scheduledsparkapp <name of the scheduledsparkapp to use a template>"
echo ""
echo " run-sparkapp --namespace <namespace> --scheduledsparkapp <scheduledsparkapp_name> --name <name>"
exit 1
fi
scheduledsparkapp_file=$(mktemp)
kubectl --namespace ${namespace} get scheduledsparkapp ${scheduledsparkapp} -o json > ${scheduledsparkapp_file}
cat <<'EOF' |\
jq '.metadata.name="'${name}'"' |\
jq '.metadata.namespace="'${namespace}'"' |\
jq ".metadata.labels=$(cat ${scheduledsparkapp_file} | jq -cr '.metadata.labels')" |\
jq ".spec=$(cat ${scheduledsparkapp_file} | jq -cr '.spec.template')" |\
kubectl apply -f -
{
"apiVersion": "sparkoperator.k8s.io/v1beta2",
"kind": "SparkApplication",
"metadata": {
"name": [],
"namespace": [],
"labels": []
},
"spec": []
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment