Skip to content

Commit a30bfb1

Browse files
OBaaS sample app chart (#1111)
Signed-off-by: Anders Swanson <[email protected]>
1 parent f50ca9b commit a30bfb1

File tree

13 files changed

+571
-0
lines changed

13 files changed

+571
-0
lines changed

helm/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Helm Charts
2+
3+
| Chart | Description |
4+
|-----------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
5+
| [OBaas Sample App](./charts/obaas-sample-app) | Sample application chart for [Oracle Backend for Microservices and AI](https://oracle.github.io/microservices-datadriven/obaas/) |
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: <your appliaction name> # Replace with your application name
3+
description: A Helm chart for the OBaaS Platform Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "1.16.0"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# OBaas Sample App Chart
2+
3+
This chart provides an extensible sample for applications running on [OBaaS](https://oracle.github.io/microservices-datadriven/obaas/).
4+
5+
To use this chart for a given application, download the chart and update the [Chart.name](./Chart.yaml) value to your application's name.
6+
7+
## Customizing the chart
8+
9+
The OBaaS sample app chart is meant to serve as a developer template, and is fully customizable.
10+
11+
Standard parameters for Kubernetes options like node affinity, HPAs, ingress and more are provided in the [values.yaml file](./values.yaml).
12+
13+
#### OBaaS options
14+
15+
Within the [values.yaml file](./values.yaml), the `obaas` key allows chart developers to enable or disable OBaaS integrations like database connectivity, OpenTelemetry, MicroProfile LRA, SpringBoot, and Eureka.
16+
enabled: true
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.ingress.enabled }}
3+
{{- range $host := .Values.ingress.hosts }}
4+
{{- range .paths }}
5+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
6+
{{- end }}
7+
{{- end }}
8+
{{- else if contains "NodePort" .Values.service.type }}
9+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "obaas-app.fullname" . }})
10+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
11+
echo http://$NODE_IP:$NODE_PORT
12+
{{- else if contains "LoadBalancer" .Values.service.type }}
13+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
14+
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "obaas-app.fullname" . }}'
15+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "obaas-app.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
16+
echo http://$SERVICE_IP:{{ .Values.service.port }}
17+
{{- else if contains "ClusterIP" .Values.service.type }}
18+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "obaas-app.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
19+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
20+
echo "Visit http://127.0.0.1:8080 to use your application"
21+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
22+
{{- end }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "obaas-app.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "obaas-app.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "obaas-app.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "obaas-app.labels" -}}
37+
helm.sh/chart: {{ include "obaas-app.chart" . }}
38+
{{ include "obaas-app.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "obaas-app.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "obaas-app.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "obaas-app.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "obaas-app.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Load obaas configuration
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: {{ include "obaas-app.fullname" . }}
6+
labels:
7+
{{- include "obaas-app.labels" . | nindent 4 }}
8+
obaas.framework: SPRING_BOOT
9+
spec:
10+
{{- if not .Values.autoscaling.enabled }}
11+
replicas: {{ .Values.replicaCount }}
12+
{{- end }}
13+
selector:
14+
matchLabels:
15+
{{- include "obaas-app.selectorLabels" . | nindent 6 }}
16+
template:
17+
metadata:
18+
{{- with .Values.podAnnotations }}
19+
annotations:
20+
{{- toYaml . | nindent 8 }}
21+
{{- end }}
22+
labels:
23+
{{- include "obaas-app.labels" . | nindent 8 }}
24+
{{- with .Values.podLabels }}
25+
{{- toYaml . | nindent 8 }}
26+
{{- end }}
27+
spec:
28+
{{- with .Values.imagePullSecrets }}
29+
imagePullSecrets:
30+
{{- toYaml . | nindent 8 }}
31+
{{- end }}
32+
serviceAccountName: {{ include "obaas-app.serviceAccountName" . }}
33+
{{- with .Values.podSecurityContext }}
34+
securityContext:
35+
{{- toYaml . | nindent 8 }}
36+
{{- end }}
37+
containers:
38+
- name: ku{{ .Chart.Name }}
39+
{{- with .Values.securityContext }}
40+
securityContext:
41+
{{- toYaml . | nindent 12 }}
42+
{{- end }}
43+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
44+
imagePullPolicy: {{ .Values.image.pullPolicy }}
45+
env:
46+
- name: CONNECT_STRING
47+
value: jdbc:oracle:thin:@$(SPRING_DB_SERVICE)?TNS_ADMIN=/oracle/tnsadmin
48+
# Lookup ObaaS configuration
49+
{{- $obaas := (lookup "v1" "ConfigMap" .Values.obaas.namespace "obaas-config") }}
50+
{{- $obaasObs := (lookup "v1" "ConfigMap" .Values.obaas.namespace "obaas-observability-config") }}
51+
{{- if $.Values.obaas.mp_lra.enabled }}
52+
- name: MP_LRA_COORDINATOR_URL
53+
value: {{ $obaas.data.MP_LRA_COORDINATOR_URL | quote }}
54+
- name: MP_LRA_PARTICIPANT_URL
55+
value: {{ $obaas.data.MP_LRA_PARTICIPANT_URL | quote }}
56+
{{- end }}
57+
{{- if $.Values.obaas.eureka.enabled }}
58+
- name: EUREKA_INSTANCE_PREFER_IP_ADDRESS
59+
value: "true"
60+
- name: EUREKA_CLIENT_REGISTER_WITH_EUREKA
61+
value: "true"
62+
- name: EUREKA_CLIENT_FETCH_REGISTRY
63+
value: "true"
64+
- name: EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE
65+
value: {{ $obaas.data.eureka | quote }}
66+
- name: EUREKA_INSTANCE_HOSTNAME
67+
value: {{ include "obaas-app.fullname" . }}-{{ $.Release.Namespace }}
68+
{{- end }}
69+
{{- if $.Values.obaas.otel.enabled }}
70+
- name: OTEL_EXPORTER_OTLP_ENDPOINT
71+
value: {{ $obaasObs.data.signoz-otel-colletor | quote }}
72+
{{- end }}
73+
{{- if $.Values.obaas.springboot.enabled }}
74+
- name: SPRING_PROFILES_ACTIVE
75+
value: {{ $obaas.data.SPRING_PROFILES_ACTIVE | quote }}
76+
{{- if $.Values.obaas.database.enabled }}
77+
- name: SPRING_DATASOURCE_URL
78+
value: "jdbc:oracle:thin:@${SPRING_DB_SERVICE}?TNS_ADMIN=/oracle/tnsadmin"
79+
- name: SPRING_DATASOURCE_USERNAME
80+
valueFrom:
81+
secretKeyRef:
82+
name: {{ $.Values.obaas.database.credentialsSecret }}
83+
key: db.username
84+
- name: SPRING_DATASOURCE_PASSWORD
85+
valueFrom:
86+
secretKeyRef:
87+
name: {{ $.Values.obaas.database.credentialsSecret }}
88+
key: db.password
89+
- name: LIQUIBASE_DATASOURCE_USERNAME
90+
valueFrom:
91+
secretKeyRef:
92+
name: {{ $.Values.obaas.database.credentialsSecret }}
93+
key: db.lb_username
94+
- name: LIQUIBASE_DATASOURCE_PASSWORD
95+
valueFrom:
96+
secretKeyRef:
97+
name: {{ $.Values.obaas.database.credentialsSecret }}
98+
key: db.lb_password
99+
- name: SPRING_DB_SERVICE
100+
valueFrom:
101+
secretKeyRef:
102+
name: {{ $.Values.obaas.database.credentialsSecret }}
103+
key: db.service
104+
{{- end }}
105+
{{- end }}
106+
ports:
107+
- name: http
108+
containerPort: {{ .Values.service.port }}
109+
protocol: TCP
110+
{{- with .Values.livenessProbe }}
111+
livenessProbe:
112+
{{- toYaml . | nindent 12 }}
113+
{{- end }}
114+
{{- with .Values.readinessProbe }}
115+
readinessProbe:
116+
{{- toYaml . | nindent 12 }}
117+
{{- end }}
118+
{{- with .Values.resources }}
119+
resources:
120+
{{- toYaml . | nindent 12 }}
121+
{{- end }}
122+
volumeMounts:
123+
- name: {{ $.Values.obaas.database.walletSecret }}
124+
mountPath: /oracle/tnsadmin
125+
{{- with .Values.volumeMounts }}
126+
{{- toYaml . | nindent 12 }}
127+
{{- end }}
128+
volumes:
129+
- name: {{ $.Values.obaas.database.walletSecret }}
130+
secret:
131+
secretName: {{ $.Values.obaas.database.walletSecret }}
132+
{{- with .Values.volumes }}
133+
{{- toYaml . | nindent 8 }}
134+
{{- end }}
135+
{{- with .Values.nodeSelector }}
136+
nodeSelector:
137+
{{- toYaml . | nindent 8 }}
138+
{{- end }}
139+
{{- with .Values.affinity }}
140+
affinity:
141+
{{- toYaml . | nindent 8 }}
142+
{{- end }}
143+
{{- with .Values.tolerations }}
144+
tolerations:
145+
{{- toYaml . | nindent 8 }}
146+
{{- end }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{- if .Values.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "obaas-app.fullname" . }}
6+
labels:
7+
{{- include "obaas-app.labels" . | nindent 4 }}
8+
spec:
9+
scaleTargetRef:
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
name: {{ include "obaas-app.fullname" . }}
13+
minReplicas: {{ .Values.autoscaling.minReplicas }}
14+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
15+
metrics:
16+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
target:
21+
type: Utilization
22+
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
23+
{{- end }}
24+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
25+
- type: Resource
26+
resource:
27+
name: memory
28+
target:
29+
type: Utilization
30+
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
31+
{{- end }}
32+
{{- end }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{{- if .Values.ingress.enabled -}}
2+
apiVersion: networking.k8s.io/v1
3+
kind: Ingress
4+
metadata:
5+
name: {{ include "obaas-app.fullname" . }}
6+
labels:
7+
{{- include "obaas-app.labels" . | nindent 4 }}
8+
{{- with .Values.ingress.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
spec:
13+
{{- with .Values.ingress.className }}
14+
ingressClassName: {{ . }}
15+
{{- end }}
16+
{{- if .Values.ingress.tls }}
17+
tls:
18+
{{- range .Values.ingress.tls }}
19+
- hosts:
20+
{{- range .hosts }}
21+
- {{ . | quote }}
22+
{{- end }}
23+
secretName: {{ .secretName }}
24+
{{- end }}
25+
{{- end }}
26+
rules:
27+
{{- range .Values.ingress.hosts }}
28+
- host: {{ .host | quote }}
29+
http:
30+
paths:
31+
{{- range .paths }}
32+
- path: {{ .path }}
33+
{{- with .pathType }}
34+
pathType: {{ . }}
35+
{{- end }}
36+
backend:
37+
service:
38+
name: {{ include "obaas-app.fullname" $ }}
39+
port:
40+
number: {{ $.Values.service.port }}
41+
{{- end }}
42+
{{- end }}
43+
{{- end }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "obaas-app.fullname" . }}
5+
labels:
6+
{{- include "obaas-app.labels" . | nindent 4 }}
7+
spec:
8+
type: {{ .Values.service.type }}
9+
ports:
10+
- port: {{ .Values.service.port }}
11+
targetPort: http
12+
protocol: TCP
13+
name: http
14+
selector:
15+
{{- include "obaas-app.selectorLabels" . | nindent 4 }}

0 commit comments

Comments
 (0)