apiVersion: v1 kind: ConfigMap metadata: labels: app: hive-metastore name: sidecar-hms-conf-templates namespace: emr data: core-site.xml.tpl: "\n {{- if index .Env \"HIVE_WAREHOUSE_S3LOCATION\" \ }}\n \n fs.defaultFS\n s3://{{ .Env.HIVE_WAREHOUSE_S3LOCATION }}\n \n {{- end }}\n \n fs.s3a.impl\n org.apache.hadoop.fs.s3a.S3AFileSystem\n \ \n \n fs.s3.impl\n org.apache.hadoop.fs.s3a.S3AFileSystem\n \ \n \n fs.s3n.impl\n org.apache.hadoop.fs.s3a.S3AFileSystem\n \ \n \n fs.s3a.aws.credentials.provider\n com.amazonaws.auth.DefaultAWSCredentialsProviderChain\n \ \n \n" metastore-site.xml.tpl: "\n {{- if eq .Env.HIVE_DB_EXTERNAL \"true\" }}\n \ \n \ javax.jdo.option.ConnectionURL\n jdbc:mysql://{{.Env.HIVE_DB_HOST}}:{{.Env.HIVE_DB_PORT}}/{{.Env.HIVE_DB_NAME}}?createDatabaseIfNotExist=true\n \n \n javax.jdo.option.ConnectionDriverName\n \ {{ .Env.HIVE_DB_DRIVER}}\n \n \n \ javax.jdo.option.ConnectionUserName\n {{ .Env.HIVE_DB_USER }}\n \n \n javax.jdo.option.ConnectionPassword\n {{ .Env.HIVE_DB_PASS }}\n \n {{- end }}\n \n metastore.expression.proxy\n \ org.apache.hadoop.hive.metastore.DefaultPartitionExpressionProxy\n \ \n \n metastore.task.threads.always\n \ org.apache.hadoop.hive.metastore.events.EventCleanerTask,org.apache.hadoop.hive.metastore.MaterializationsCacheCleanerTask\n \ \n \n hive.metastore.uris\n \ thrift:localhost:9083\n \n {{- if not (index .Env \"HIVE_WAREHOUSE_DIR\") }}\n \n hive.metastore.warehouse.dir\n \ file:///tmp/\n \n {{- else }}\n \ {{- $hive_warehouse_dir := regexp.Replace \"(.*)\" \"s3:\\\\$1\" .Env.HIVE_WAREHOUSE_DIR }}\n \ \n hive.metastore.warehouse.dir\n {{ $hive_warehouse_dir }}\n \n {{- end }}\n \ {{- if (index .Env \"HIVE_CONF_PARAMS\") }}\n {{- $conf_list := .Env.HIVE_CONF_PARAMS | strings.Split \";\" }}\n {{- range $parameter := $conf_list}}\n \ {{- $key := regexp.Replace \"(.*):.*\" \"$1\" $parameter }}\n {{- $value := regexp.Replace \".*:(.*)\" \"$1\" $parameter }}\n \n \ {{ $key }}\n {{ $value }}\n \n {{- end }}\n {{- end }}\n\n" --- apiVersion: v1 kind: ConfigMap metadata: labels: app: hive-metastore name: sidecar-terminate-script namespace: emr data: self-terminate.sh: |- #!/bin/bash # FILE_TO_WATCH="/var/log/fluentd/main-container-terminated" FILE_TO_WATCH=$1 INITIAL_HEARTBEAT_TIMEOUT_THREASHOLD=60 HEARBEAT_TIMEOUT_THRESHOLD=16 SLEEP_DURATION=10 function terminate_main_process() { echo "terminating the HMS process.." pid=$(ps aux | grep HiveMetaStore | grep -v grep | awk '{print $2}') kill -SIGTERM $pid } # Waiting for the first heartbeat sent by Spark main container echo "Waiting for file $FILE_TO_WATCH to appear..." start_wait=$(date +%s) while ! [[ -f "$FILE_TO_WATCH" ]]; do elapsed_wait=$(expr $(date +%s) - $start_wait) if [ "$elapsed_wait" -gt "$INITIAL_HEARTBEAT_TIMEOUT_THREASHOLD" ]; then echo "File $FILE_TO_WATCH not found after $INITIAL_HEARTBEAT_TIMEOUT_THREASHOLD seconds; aborting" terminate_main_process exit 1 fi sleep $SLEEP_DURATION; done; echo "Found file $FILE_TO_WATCH; watching for heartbeats..." while [[ -f "$FILE_TO_WATCH" ]]; do LAST_HEARTBEAT=$(stat -c %Y $FILE_TO_WATCH) ELAPSED_TIME_SINCE_AFTER_HEARTBEAT=$(expr $(date +%s) - $LAST_HEARTBEAT) if [ "$ELAPSED_TIME_SINCE_AFTER_HEARTBEAT" -gt "$HEARBEAT_TIMEOUT_THRESHOLD" ]; then echo "Last heartbeat to file $FILE_TO_WATCH was more than $HEARBEAT_TIMEOUT_THRESHOLD seconds ago at $LAST_HEARTBEAT; terminating" terminate_main_process exit 0 fi sleep $SLEEP_DURATION; done; # the file will be deleted once the fluentd container is terminated echo "The file $FILE_TO_WATCH doesn't exist anymore;" terminate_main_process exit 0 --- apiVersion: kubernetes-client.io/v1 kind: ExternalSecret metadata: labels: app: hive-metastore name: rds-hms-secret namespace: emr spec: backendType: secretsManager dataFrom: - {SECRET_MANAGER_NAME}