cshuo commented on code in PR #20737:
URL: https://github.com/apache/hudi/pull/20737#discussion_r4643248905
##########
hudi-lakehouse/local-dev/scripts/down.sh:
##########
@@ -15,16 +15,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Tears down everything up.sh created (the whole hudi-lakehouse namespace).
+# Stop local-dev workloads without deleting PVCs or Helm configuration.
set -euo pipefail
NS=hudi-lakehouse
-
-# Delete SparkApplications FIRST, while the operator is still alive to
-# process their finalizers -- otherwise the namespace hangs in Terminating.
-kubectl -n "$NS" delete sparkapplications --all --timeout=120s 2>/dev/null ||
true
-
-helm uninstall hudi-trino -n "$NS" 2>/dev/null || true
-helm uninstall hudi-spark-connect -n "$NS" 2>/dev/null || true
-helm uninstall spark-kubernetes-operator -n "$NS" 2>/dev/null || true
-kubectl delete namespace "$NS" --ignore-not-found --timeout=300s
-echo ">>> local-dev lakehouse removed"
+kubectl() {
+ if [[ -n "${HUDI_KUBE_CONTEXT:-}" ]]; then
+ command kubectl --context "$HUDI_KUBE_CONTEXT" "$@"
+ else
+ command kubectl "$@"
+ fi
+}
+if [[ $# -ne 0 ]]; then
+ echo 'Usage: down.sh (stops workloads and preserves data; no deletion
flags)' >&2
Review Comment:
I added the reset commands to the local-dev README and linked them from the
top-level README. Both steps use the same Kubernetes context, and the namespace
is deleted only after `down.sh` succeeds. I also clarified that rerunning
`--run-example` rewrites `trips`.
##########
hudi-lakehouse/local-dev/scripts/down.sh:
##########
@@ -15,16 +15,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Tears down everything up.sh created (the whole hudi-lakehouse namespace).
+# Stop local-dev workloads without deleting PVCs or Helm configuration.
set -euo pipefail
NS=hudi-lakehouse
-
-# Delete SparkApplications FIRST, while the operator is still alive to
-# process their finalizers -- otherwise the namespace hangs in Terminating.
-kubectl -n "$NS" delete sparkapplications --all --timeout=120s 2>/dev/null ||
true
-
-helm uninstall hudi-trino -n "$NS" 2>/dev/null || true
-helm uninstall hudi-spark-connect -n "$NS" 2>/dev/null || true
-helm uninstall spark-kubernetes-operator -n "$NS" 2>/dev/null || true
-kubectl delete namespace "$NS" --ignore-not-found --timeout=300s
-echo ">>> local-dev lakehouse removed"
+kubectl() {
+ if [[ -n "${HUDI_KUBE_CONTEXT:-}" ]]; then
+ command kubectl --context "$HUDI_KUBE_CONTEXT" "$@"
+ else
+ command kubectl "$@"
+ fi
+}
+if [[ $# -ne 0 ]]; then
+ echo 'Usage: down.sh (stops workloads and preserves data; no deletion
flags)' >&2
+ exit 2
+fi
+# SparkApplication finalizers need the running operator. Preserve the original
+# developer cleanup ordering; application objects are disposable, PVCs are not.
+if kubectl api-resources --api-group=spark.apache.org -o name | grep -q
'^sparkapplications'; then
Review Comment:
`down.sh` now captures the output of `kubectl api-resources` before checking
for the SparkApplication resource. This avoids the SIGPIPE race and lets
discovery failures propagate.
##########
hudi-lakehouse/local-dev/manifests/hive-metastore.yaml:
##########
@@ -126,41 +59,21 @@ spec:
containers:
- name: metastore
image: apache/hive:3.1.3
- command:
- - /bin/bash
- - -c
- - |
- set -e
- # Put the S3A filesystem (bundled with the image's Hadoop, but
- # not on the metastore classpath) onto the classpath. The image
- # runs as a non-root user, so $HIVE_HOME/lib is not writable --
- # HADOOP_CLASSPATH is the supported non-root mechanism.
- export HADOOP_CLASSPATH="$(echo
"$HADOOP_HOME"/share/hadoop/tools/lib/hadoop-aws-*.jar):$(echo
"$HADOOP_HOME"/share/hadoop/tools/lib/aws-java-sdk-bundle-*.jar)${HADOOP_CLASSPATH:+:$HADOOP_CLASSPATH}"
- # Single init authority: initialize the Derby schema at the
- # PVC-backed location on first boot (schematool reads the
- # ConnectionURL from the mounted hive-site.xml), and tell the
- # image entrypoint to skip its own schema init.
- if [ ! -d /opt/hive/data/metastore_db ]; then
- "$HIVE_HOME/bin/schematool" -dbType derby -initSchema
- fi
- export IS_RESUME=true
- exec /entrypoint.sh
+ imagePullPolicy: IfNotPresent
+ command: ["/bin/bash", "/lakehouse/start-metastore.sh"]
Review Comment:
Yes, I tested this on minikube using a PVC created by the old manifest, with
`metastore_db/` present and no `.schema-initialized` marker. `schematool
-validate` passed, both PVCs retained their UIDs, and Spark Connect read back a
Hudi row written before the upgrade. I’ve added the result to the PR
description.
##########
hudi-lakehouse/local-dev/scripts/install.py:
##########
@@ -0,0 +1,286 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Local minikube installation; Python standard library only on the host."""
+import argparse
+import json
+import os
+from pathlib import Path
+import re
+import shutil
+import subprocess
+import sys
+import tempfile
+
+HERE = Path(__file__).resolve().parents[1]
+ROOT = HERE.parent
+NS = 'hudi-lakehouse'
+CONNECT_IMAGE = 'hudi-lakehouse-spark-connect:4.1.3-hudi1.2.0'
+GATEWAY_IMAGE = 'hudi-lakehouse-agent-gateway:0.1.0'
+
+
+def run(args, *, capture=False, check=True, **kwargs):
+ return subprocess.run([str(a) for a in args], text=True, check=check,
+ stdout=subprocess.PIPE if capture else None,
**kwargs)
+
+
+def image_values(image, policy):
+ if '@' in image or not re.fullmatch(r'[\w./:-]+:[\w.-]+', image) or ':'
not in image.rsplit('/', 1)[-1]:
+ raise ValueError('Application images require an explicit
repository:tag: ' + image)
+ repository, tag = image.rsplit(':', 1)
+ return {'repository': repository, 'tag': tag, 'pullPolicy': policy}
+
+
+class Installation:
+ def __init__(self, args):
+ self.args = args
+ self.profile = args.profile
+ self.kube = ['kubectl', '--context', self.profile, '-n', NS]
+ self.mini = ['minikube', '-p', self.profile]
+ self.env = dict(os.environ, HUDI_KUBE_CONTEXT=self.profile)
+
+ def kubectl(self, *args, **kwargs):
+ return run([*self.kube, *args], **kwargs)
+
+ def exec_script(self, deployment, script, *args, check=True):
+ return self.kubectl('exec', '-i', 'deploy/' + deployment, '--',
'python3', '-', *args,
+ input=script.read_text(), check=check)
+
+ def assert_gateway_backend(self):
+ # Do not repoint an existing Trino gateway when selecting an old
profile.
+ result = self.kubectl('get', 'deployment', 'hudi-agent-gateway',
+ '--ignore-not-found', '-o', 'json', capture=True)
+ if result.stdout.strip():
+ containers =
json.loads(result.stdout)['spec']['template']['spec']['containers']
+ env = {e['name']: e.get('value') for c in containers for e in
c.get('env', [])}
+ if env.get('GATEWAY_SQL_BACKEND') != 'spark-connect':
+ raise ValueError('Existing gateway does not use Spark Connect.
Use a different --profile to preserve it.')
+
+ def images(self):
+ args = self.args
+ if args.build:
+ run([ROOT / 'scripts/build-connect-image.sh'])
+ if args.connect_image != CONNECT_IMAGE:
+ run(['docker', 'tag', CONNECT_IMAGE, args.connect_image])
+ run(['docker', 'build', '-t', args.gateway_image, ROOT.parent /
'hudi-agent-gateway'])
+ if args.pull_images:
+ print('Using registry application images (IfNotPresent)',
flush=True)
+ return
+ cached = json.loads(run([*self.mini, 'image', 'ls', '--format=json'],
capture=True).stdout)
+
+ def normalize(name):
+ return re.sub(r'^(docker.io/)?library/|^docker.io/', '', name)
+
+ def load_image(image, required):
+ entries = [entry for entry in cached if any(normalize(tag) ==
normalize(image)
+ for tag in
entry.get('repoTags', []))]
+ local = run(['docker', 'image', 'inspect', image], capture=True,
+ stderr=subprocess.DEVNULL, check=False)
+ if local.returncode == 0:
+ identity = json.loads(local.stdout)[0]['Id'].split(':')[-1]
+ if any(entry['id'].split(':')[-1] == identity for entry in
entries):
+ print(f'Reusing unchanged cluster image {image}',
flush=True)
+ return
+ print(f'Loading local image {image}', flush=True)
+ run([*self.mini, 'image', 'load', '--daemon',
'--overwrite=true', image])
+ elif entries:
+ print(f'Reusing cluster image {image}', flush=True)
+ elif required:
+ raise ValueError(f'Image {image} is absent locally and in this
profile. '
+ 'Use up --build, or explicit registry images
with --pull-images. '
+ 'Default application tags are not published
releases.')
+
+ for image in (args.connect_image, args.gateway_image):
+ load_image(image, required=True)
+ # Infrastructure can be pulled by Kubernetes if not present locally.
+ for image in (args.minio_image, args.mc_image, args.hms_image):
+ load_image(image, required=False)
+
+ def up(self):
+ args = self.args
+ # Validate files/images before starting any workloads.
+ policy = 'IfNotPresent' if args.pull_images else 'Never'
+ connect = {'image': image_values(args.connect_image, policy)}
+ gateway = {'image': image_values(args.gateway_image, policy)}
+ for path in (args.connect_values, args.gateway_values):
+ if path and not Path(path).is_file():
+ raise ValueError('Values file does not exist: ' + path)
+ status = run([*self.mini, 'status'], capture=True, check=False,
stderr=subprocess.DEVNULL)
+ if status.returncode:
+ run([*self.mini, 'start', '--driver', args.driver, '--cpus',
args.cpus,
+ '--memory', args.memory, '--keep-context'])
+ else:
+ print(f'Reusing running minikube profile {self.profile}',
flush=True)
+ self.assert_gateway_backend()
+ self.images()
+ with tempfile.TemporaryDirectory(prefix='hudi-minikube-') as directory:
+ temp = Path(directory)
+ for name, values in (('connect', connect), ('gateway', gateway)):
+ # Helm merges the user's file before installer-owned image
selection.
+ source = getattr(args, name + '_values')
+ files = ['-f', str(Path(source).resolve())] if source else []
+ image_file = temp / (name + '-image.json')
+ image_file.write_text(json.dumps(values))
+ chart = ROOT / 'charts' / ('hudi-spark-connect' if name ==
'connect' else 'hudi-agent-gateway')
+ image_file = temp / (name + '-image.json')
+ image_file.write_text(json.dumps(values))
+ chart = ROOT / 'charts' / ('hudi-spark-connect' if name ==
'connect' else 'hudi-agent-gateway')
+ # Reject malformed values before applying Kubernetes resources.
+ run(['helm', 'template', 'preflight', chart,
+ '-f', chart / 'values-local-dev.yaml', *files, '-f',
image_file], capture=True)
+ prefix = 'SPARK_CONNECT' if name == 'connect' else 'GATEWAY'
+ self.env[prefix + '_VALUES'] = str(Path(source).resolve()) if
source else ''
+ self.env[prefix + '_IMAGE_VALUES'] = str(image_file)
+ manifests = temp / 'manifests'
+ shutil.copytree(HERE / 'manifests', manifests)
+ for name, old, new in (
+ ('minio.yaml', 'cgr.dev/chainguard/minio:latest',
args.minio_image),
+ ('minio-bucket-job.yaml',
'cgr.dev/chainguard/minio-client:latest-dev', args.mc_image),
+ ('hive-metastore.yaml', 'apache/hive:3.1.3', args.hms_image),
+ ):
+ if not re.fullmatch(r'[\w./:@-]+', new):
+ raise ValueError('Invalid infrastructure image: ' + new)
+ path = manifests / name
+ path.write_text(path.read_text().replace('image: ' + old,
+ 'image: ' + new))
+ self.env['LOCAL_DEV_MANIFEST_DIR'] = str(manifests)
+ run(['bash', HERE / 'scripts/up.sh', '--spark-connect',
'--with-agent-gateway'], env=self.env)
+ if args.build:
Review Comment:
A plain `up` now records the local image ID in the Deployment’s pod
template. I verified that rebuilding the Gateway under the same tag rolled out
the Gateway while the Spark Connect pod kept its UID. Running `up` again with
unchanged images kept both pods running.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]