Skip to content

Commit

Permalink
feat(helm): init
Browse files Browse the repository at this point in the history
  • Loading branch information
unknowntpo committed Aug 26, 2024
1 parent fd68dd2 commit 37df5e5
Show file tree
Hide file tree
Showing 24 changed files with 937 additions and 59 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Install Git and Docker Compose.
The playground runs a number of services. The TCP ports used may clash with existing services you run, such as MySQL or Postgres.

| Docker container | Ports used |
|-----------------------|----------------------|
| --------------------- | -------------------- |
| playground-gravitino | 8090 9001 |
| playground-hive | 3307 9003 9084 50071 |
| playground-mysql | 13306 |
Expand Down Expand Up @@ -243,3 +243,9 @@ os.environ["OPENAI_API_BASE"] = ""
Apache Gravitino is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
<sub>Apache®, Apache Gravitino&trade;, Apache Hive&trade;, Apache Iceberg&trade;, and Apache Spark&trade; are either registered trademarks or trademarks of the Apache Software Foundation in the United States and/or other countries.</sub>
## Kubernetes
```
$ helm upgrade --install gravitino-playground ./gravitino-playground --create-namespace --namespace gravitino-playground
```
35 changes: 35 additions & 0 deletions healthcheck/hive-healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
#
# 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.
#
set -ex

# Set Hive connection details
HIVE_PORT="10000"

# Attempt to connect to Hive using curl
curl -s -o /dev/null -w "%{http_code}" http://${HIVE_HOST_IP}:${HIVE_PORT}

# Check the HTTP status code
if [ $? -eq 0 ]; then
echo "Hive connection successful"
exit 0
else
echo "Hive connection failed"
exit 1
fi
23 changes: 23 additions & 0 deletions helm-chart/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
9 changes: 9 additions & 0 deletions helm-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v2
name: gravitino-playground
description: A Helm chart for Gravitino Playground
type: application
version: 0.1.0
appVersion: "1.0.0"
maintainers:
- name: Your Name
email: [email protected]
1 change: 1 addition & 0 deletions helm-chart/healthcheck
1 change: 1 addition & 0 deletions helm-chart/init
22 changes: 22 additions & 0 deletions helm-chart/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "gravitino-playground.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "gravitino-playground.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "gravitino-playground.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "gravitino-playground.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
62 changes: 62 additions & 0 deletions helm-chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "gravitino-playground.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "gravitino-playground.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "gravitino-playground.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "gravitino-playground.labels" -}}
helm.sh/chart: {{ include "gravitino-playground.chart" . }}
{{ include "gravitino-playground.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "gravitino-playground.selectorLabels" -}}
app.kubernetes.io/name: {{ include "gravitino-playground.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "gravitino-playground.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "gravitino-playground.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
84 changes: 84 additions & 0 deletions helm-chart/templates/gravitino.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.gravitino.serviceName }}
namespace: {{ .Values.global.namespace }}
labels:
app: {{ .Values.gravitino.serviceName }}
spec:
replicas: 1
selector:
matchLabels:
app: {{ .Values.gravitino.serviceName }}
template:
metadata:
labels:
app: {{ .Values.gravitino.serviceName }}
spec:
containers:
- name: gravitino
image: "{{ .Values.gravitino.image.repository }}:{{ .Values.gravitino.image.tag }}"
ports:
- containerPort: 8090
- containerPort: 9001
command: ["/bin/bash", "/tmp/gravitino/init.sh"]
env:
{{- toYaml .Values.gravitino.env | nindent 12 }}
volumeMounts:
- name: init-script
mountPath: /tmp/gravitino
- name: healthcheck-script
mountPath: /tmp/healthcheck
readinessProbe:
exec:
command:
- /bin/sh
- -c
- /tmp/healthcheck/gravitino-healthcheck.sh
initialDelaySeconds: 10
periodSeconds: 5
failureThreshold: 3
resources:
{{- toYaml .Values.gravitino.resources | nindent 12 }}
volumes:
- name: init-script
configMap:
name: gravitino-init-script
defaultMode: 0755
- name: healthcheck-script
configMap:
name: gravitino-healthcheck-script
defaultMode: 0755
---
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.gravitino.serviceName }}
spec:
selector:
app: {{ .Values.gravitino.serviceName }}
ports:
- port: 8090
targetPort: 8090
name: api
- port: 9001
targetPort: 9001
name: debug
---
apiVersion: v1
kind: ConfigMap
metadata:
name: gravitino-init-script
data:
{{- range $path, $_ := .Files.Glob "init/gravitino/*" }}
{{ base $path }}: |-
{{- $.Files.Get $path | nindent 4 }}
{{- end }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: gravitino-healthcheck-script
data:
gravitino-healthcheck.sh: |-
{{ .Files.Get "healthcheck/gravitino-healthcheck.sh" | indent 4 }}
77 changes: 77 additions & 0 deletions helm-chart/templates/hive.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# templates/hive.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.hive.serviceName }}
namespace: {{ .Values.global.namespace }}
labels:
app: {{ .Values.hive.serviceName }}
spec:
replicas: 1
selector:
matchLabels:
app: {{ .Values.hive.serviceName }}
template:
metadata:
labels:
app: {{ .Values.hive.serviceName }}
spec:
containers:
- name: hive
image: "{{ .Values.hive.image.repository }}:{{ .Values.hive.image.tag }}"
ports:
- containerPort: 3306
- containerPort: 9000
- containerPort: 9083
- containerPort: 50070
readinessProbe:
exec:
command: ["/tmp/check-status.sh"]
periodSeconds: 10
timeoutSeconds: 60
failureThreshold: 5
env:
{{- toYaml .Values.hive.env | nindent 12 }}
volumeMounts:
- name: hive-init-script
mountPath: /tmp/hive
resources:
{{- toYaml .Values.hive.resources | nindent 12 }}
command: ["/bin/bash", "/tmp/hive/init.sh"]
volumes:
- name: hive-init-script
configMap:
name: hive-init-script
defaultMode: 0755
---
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.hive.serviceName }}
spec:
selector:
app: {{ .Values.hive.serviceName }}
ports:
- port: 3306
targetPort: 3306
name: mysql
- port: 9000
targetPort: 9000
name: hdfs
- port: 9083
targetPort: 9083
name: metastore
- port: 50070
targetPort: 50070
name: namenode
---
apiVersion: v1
kind: ConfigMap
metadata:
name: hive-init-script
data:
{{- range $path, $_ := .Files.Glob "init/hive/*" }}
{{ base $path }}: |-
{{- $.Files.Get $path | nindent 4 }}
{{- end }}
Loading

0 comments on commit 37df5e5

Please sign in to comment.