Skip to content

Commit

Permalink
feat: support oracle standalone (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
1aal authored Nov 27, 2023
1 parent 16479f8 commit e8f4b71
Show file tree
Hide file tree
Showing 16 changed files with 405 additions and 0 deletions.
23 changes: 23 additions & 0 deletions addons/oracle-cluster/.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/
30 changes: 30 additions & 0 deletions addons/oracle-cluster/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: v2
name: oracle-cluster
description: A Helm chart for Kubernetes

dependencies:
- name: kblib
version: 0.1.0
repository: file://../kblib
alias: extra

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.7.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "19.3.0-ee"
3 changes: 3 additions & 0 deletions addons/oracle-cluster/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
KubeBlocks Oracle 19.3.0-ee cluster helm chart.

Using `kubectl port-forward services/<service-name> 1521:1521 && sqlplus sys/$ORACLE_PWD@//localhost:1521/$ORACLE_SID as sysdba` or `kbcli cluster connect <cluster-name>` to connect with Oracle cluster.
12 changes: 12 additions & 0 deletions addons/oracle-cluster/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{/*
Define replica count.
standalone mode: 1
replication mode: 2
*/}}
{{- define "oracle-cluster.replicaCount" }}
{{- if eq .Values.mode "standalone" }}
replicas: 1
{{- else if eq .Values.mode "replication" }}
replicas: {{ max .Values.replicas 2 }}
{{- end }}
{{- end }}
11 changes: 11 additions & 0 deletions addons/oracle-cluster/templates/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- include "kblib.clusterCommon" . }}
clusterDefinitionRef: oracle
componentSpecs:
- name: oracle
componentDefRef: oracle
{{- include "kblib.componentMonitor" . | indent 6 }}
{{- include "oracle-cluster.replicaCount" . | indent 6 }}
serviceAccountName: {{ include "kblib.serviceAccountName" . }}
{{- include "kblib.componentResources" . | indent 6 }}
{{- include "kblib.componentStorages" . | indent 6 }}
{{- include "kblib.componentServices" . | indent 6 }}
1 change: 1 addition & 0 deletions addons/oracle-cluster/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- include "kblib.rbac" . }}
15 changes: 15 additions & 0 deletions addons/oracle-cluster/templates/validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{/*
Validate cpu, memory and storage
*/}}
{{- $cpu := (float64 .Values.cpu) }}
{{- $memory := (float64 .Values.memory) }}
{{- $storage := (float64 .Values.storage) }}
{{- if or (lt $cpu 1.0) (gt $cpu 64.0) }}
{{- fail (print "cpu must be between 1.0 and 64, got " $cpu) }}
{{- end }}
{{- if or (lt $memory 4.0) (gt $memory 1000.0) }}
{{- fail (print "memory must be between 4.0 and 1000, got " $memory) }}
{{- end }}
{{- if or (lt $storage 1.0 ) (gt $storage 10000.0) }}
{{- fail (print "storage must be between 1 and 10000, got " $storage) }}
{{- end }}
57 changes: 57 additions & 0 deletions addons/oracle-cluster/values.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"properties": {
"version": {
"type": "string",
"default": "oracle-19.3.0-ee"
},
"mode": {
"type": "string",
"default": "standalone",
"enum": [
"standalone"
]
},
"replicas": {
"type": "integer",
"default": 1,
"minimum": 1,
"maximum": 5
},
"cpu": {
"title": "CPU",
"description": "CPU cores.",
"type": [
"number",
"string"
],
"default": 1,
"minimum": 1,
"maximum": 64,
"multipleOf": 0.5
},
"memory": {
"title": "Memory(Gi)",
"description": "Memory, the unit is Gi.",
"type": [
"number",
"string"
],
"default": 4,
"minimum": 4,
"maximum": 1000
},
"storage": {
"title": "Storage(Gi)",
"description": "Storage size, the unit is Gi.",
"type": [
"number",
"string"
],
"default": 20,
"minimum": 1,
"maximum": 10000
}
}
}
34 changes: 34 additions & 0 deletions addons/oracle-cluster/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Default values for OpenGauss standalone Mode
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

## @param version OpenGauss cluster version
##
version: oracle-19.3.0-ee

## @param mode postgresql cluster topology mode, standalone, replication
##
mode: standalone

## @param replicas specify cluster replicas
##
replicas: 1

## @param cpu
##
cpu: 2.0

## @param memory, the unit is Gi
##
memory: 4.0

## @param requests.cpu if not set, use cpu
## @param requests.memory, if not set, use memory
##
requests:
cpu: 1.0
memory: 4.0

## @param storage size, the unit is Gi
##
storage: 20
23 changes: 23 additions & 0 deletions addons/oracle/.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/
24 changes: 24 additions & 0 deletions addons/oracle/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: oracle
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.7.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "19.3.0-ee"
4 changes: 4 additions & 0 deletions addons/oracle/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Standalone Oracle cluster-definition and cluster-version in Kubeblocks

Note: Oracle database requires a minimum of 2GiB of memory.
Using `kbcli cluster create --cluster-definition oracle --set memory=4Gi` to create a Oracle cluster
62 changes: 62 additions & 0 deletions addons/oracle/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "oracle.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 "oracle.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 "oracle.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "oracle.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "oracle.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
67 changes: 67 additions & 0 deletions addons/oracle/templates/clusterdefinition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: ClusterDefinition
metadata:
name: oracle
labels:
{{- include "oracle.labels" . | nindent 4 }}
spec:
type: oracle
connectionCredential:
username: kbadmin
password: "$(RANDOM_PASSWD)"
endpoint: "$(SVC_FQDN):$(SVC_PORT_tcp-oracle)"
host: "$(SVC_FQDN)"
port: "$(SVC_PORT_tcp-oracle)"
componentDefs:
- name: oracle
workloadType: Stateful
characterType: oracle
service:
ports:
- name: tcp-oracle
port: 1521
targetPort: tcp-oracle
- name: oem-express
port: 5500
targetPort: oem-express
volumeTypes:
- name: data
type: data
podSpec:
securityContext:
runAsUser: 0
fsGroup: 103
runAsGroup: 103
containers:
- name: oracle
imagePullPolicy: {{ default .Values.image.pullPolicy "IfNotPresent" }}
securityContext:
runAsUser: 54321
ports:
- name: tcp-oracle
containerPort: 1521
- name: oem-express
containerPort: 5500
env:
- name: ORACLE_SID
value: "ORCLCDB"
- name: ORACLE_PDB
value: "ORCLPDB1"
- name: ORACLE_PWD
valueFrom:
secretKeyRef:
name: $(CONN_CREDENTIAL_SECRET_NAME)
key: password
- name: AUTO_MEM_CALCULATION
value: "TRUE"
- name: INIT_CPU_COUNT
- name: INIT_PROCESSES
- name: ORACLE_EDITION
value: "enterprise"
volumes:
- name: dshm
emptyDir:
medium: Memory
{{- with .Values.shmVolume.sizeLimit }}
sizeLimit: {{ . }}
{{- end }}
Loading

0 comments on commit e8f4b71

Please sign in to comment.