Last active
November 4, 2021 14:22
-
-
Save drazul/f18681e8f598e153d9b344863423c2fd to your computer and use it in GitHub Desktop.
Script to run a SparkApplication from a ScheduledSparkApplication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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