-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from irfanhakim-as/mariadb-agent
New chart and general improvements
- Loading branch information
Showing
21 changed files
with
336 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: v2 | ||
name: mariadb-agent | ||
description: Easily create or delete multiple pairs of databases and users in a remote MariaDB instance. | ||
type: application | ||
version: 0.1.0 | ||
appVersion: "11.1.3-debian-11-r0" | ||
keywords: | ||
- "mariadb" | ||
- "mysql" | ||
- "agent" | ||
- "job" | ||
home: "https://github.com/irfanhakim-as/charts" | ||
icon: "https://irfanhakim-as.github.io/charts/logos/mariadb.png" | ||
sources: | ||
- "https://github.com/irfanhakim-as/charts" | ||
maintainers: | ||
- name: "Irfan Hakim" | ||
email: "[email protected]" | ||
url: "https://github.com/irfanhakim-as" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# [`mariadb-agent`](https://github.com/mariadb/mariadb) | ||
|
||
## Prerequisites | ||
|
||
- Kubernetes 1.19+ | ||
- Helm 3.2.0+ | ||
|
||
## Preflight checklist | ||
|
||
## How to add repo | ||
|
||
Add the repo to your local helm client. | ||
|
||
```sh | ||
helm repo add mika https://irfanhakim-as.github.io/charts | ||
``` | ||
|
||
Update the repo to retrieve the latest versions of the packages. | ||
|
||
```sh | ||
helm repo update | ||
``` | ||
|
||
## How to install | ||
|
||
### Prepare MariaDB host | ||
|
||
Install [`bitnami/mariadb`](https://github.com/bitnami/charts/tree/main/bitnami/mariadb). This step can be skipped if you have an existing MariaDB server. | ||
|
||
### Prepare chart values | ||
|
||
Copy `values.yaml` from the chart you would like to install. Refer to the [Configurations](#configurations) section for more information. | ||
|
||
```sh | ||
cp mika/mariadb-agent/values.yaml . | ||
``` | ||
|
||
Edit `values.yaml` with the appropriate values. Refer to the [Configurations](#Configurations) section for available options. | ||
|
||
```sh | ||
nano values.yaml | ||
``` | ||
|
||
### Perform installation | ||
|
||
Install the desired chart. Replace `$release_name` and `$namespace` accordingly. | ||
|
||
```sh | ||
helm install $release_name mika/mariadb-agent --namespace $namespace --create-namespace --values values.yaml --wait | ||
``` | ||
|
||
Verify that your chart has been installed. Replace `$namespace` and `$release_name` accordingly. | ||
|
||
```sh | ||
helm ls --namespace $namespace | grep "$release_name" | ||
``` | ||
|
||
## How to upgrade | ||
|
||
After making any necessary changes to the `values.yaml` file, upgrade the desired chart. Replace `$release_name` and `$namespace` accordingly. | ||
|
||
```sh | ||
helm upgrade $release_name mika/mariadb-agent --namespace $namespace --values values.yaml --wait | ||
``` | ||
|
||
## How to uninstall | ||
|
||
Uninstall the desired chart. Replace `$release_name` and `$namespace` accordingly. | ||
|
||
```sh | ||
helm uninstall $release_name --namespace $namespace --wait | ||
``` | ||
|
||
## Configurations | ||
|
||
| Key | Type | Default | Description | | ||
|-----|------|---------|-------------| | ||
| image.mariadb.pullPolicy | string | `""` | The policy that determines when Kubernetes should pull the MariaDB container image. Default: `"IfNotPresent"`. | | ||
| image.mariadb.registry | string | `""` | The registry where the MariaDB container image is hosted. Default: `"docker.io"`. | | ||
| image.mariadb.repository | string | `""` | The name of the repository that contains the MariaDB container image used. Default: `"bitnami/mariadb"`. | | ||
| image.mariadb.tag | string | `""` | The tag that specifies the version of the MariaDB container image used. Default: `Chart appVersion`. | | ||
| mariadb.databases | list | `[]` | Database configurations array. Elements: `.name`, `.user`, `.password`, `.create`, `.drop`, `.custom_command`. | | ||
| mariadb.host | string | `""` | The hostname or IP address of the MariaDB database server. | | ||
| mariadb.root.password | string | `""` | The password associated with the MariaDB database server root user. | | ||
| mariadb.root.user | string | `""` | The username or user account for accessing the MariaDB database server as root. Default: `"root"`. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mariadb-agent job has been deployed for {{ .Release.Name | toString }}. | ||
|
||
See the values.yaml file of this chart for more configuration options. | ||
|
||
Please refer to the official documentation for more information on how to use mariadb-agent. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{{/* | ||
Expand the name of the chart. | ||
*/}} | ||
{{- define "mariadb-agent.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 "mariadb-agent.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 "mariadb-agent.chart" -}} | ||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Common labels | ||
*/}} | ||
{{- define "mariadb-agent.labels" -}} | ||
helm.sh/chart: {{ include "mariadb-agent.chart" . }} | ||
{{ include "mariadb-agent.selectorLabels" . }} | ||
{{- if .Chart.AppVersion }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||
{{- end }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
{{- end }} | ||
|
||
{{/* | ||
Selector labels | ||
*/}} | ||
{{- define "mariadb-agent.selectorLabels" -}} | ||
app.kubernetes.io/name: {{ include "mariadb-agent.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create the name of the service account to use | ||
*/}} | ||
{{- define "mariadb-agent.serviceAccountName" -}} | ||
{{- if .Values.serviceAccount.create }} | ||
{{- default (include "mariadb-agent.fullname" .) .Values.serviceAccount.name }} | ||
{{- else }} | ||
{{- default "default" .Values.serviceAccount.name }} | ||
{{- end }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{{- $host := .Values.mariadb.host | default "mariadb" | toString }} | ||
{{- $registry := .Values.image.mariadb.registry | default "docker.io" | toString }} | ||
{{- $repository := .Values.image.mariadb.repository | default "bitnami/mariadb" | toString }} | ||
{{- $tag := .Values.image.mariadb.tag | default .Chart.AppVersion | toString }} | ||
{{- $pullPolicy := .Values.image.mariadb.pullPolicy | default "IfNotPresent" | toString | quote }} | ||
{{- $databases := .Values.mariadb.databases }} | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: {{ printf "%s-%s-%s" (index (splitList "." $host) 0) .Release.Name "mariadb-agent" }} | ||
labels: | ||
{{- include "mariadb-agent.labels" . | nindent 4 }} | ||
spec: | ||
ttlSecondsAfterFinished: 120 | ||
backoffLimit: 0 | ||
template: | ||
metadata: | ||
{{- with .Values.podAnnotations }} | ||
annotations: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
labels: | ||
{{- include "mariadb-agent.selectorLabels" . | nindent 8 }} | ||
spec: | ||
containers: | ||
- name: mariadb-agent | ||
image: {{ printf "%s/%s:%s" $registry $repository $tag | quote }} | ||
imagePullPolicy: {{ $pullPolicy }} | ||
resources: | ||
{{- toYaml .Values.resources | nindent 12 }} | ||
command: ["/bin/bash"] | ||
args: | ||
- -c | ||
- >- | ||
mysql -h $(DB_HOST) -u $(ROOT_USER) -e ' | ||
{{- range $databases }} | ||
{{- if .create }} | ||
CREATE DATABASE IF NOT EXISTS {{ .name }}; | ||
CREATE USER IF NOT EXISTS "{{ .user }}"@"%"; | ||
SET PASSWORD FOR "{{ .user }}"@"%" = PASSWORD("{{ .password }}"); | ||
GRANT ALL PRIVILEGES ON {{ .name }}.* TO "{{ .user }}"@"%"; | ||
{{- else if .drop }} | ||
DROP DATABASE IF EXISTS {{ .name }}; | ||
DROP USER IF EXISTS "{{ .user }}"@"%"; | ||
{{- end }} | ||
{{- if .custom_command }} | ||
{{- .custom_command | replace "$.name" .name | replace "$.user" .user | replace "$.password" .password | nindent 16 }} | ||
{{- end }} | ||
{{- end }} | ||
FLUSH PRIVILEGES; | ||
' | ||
envFrom: | ||
- secretRef: | ||
name: {{ .Release.Name }}-mariadb-agent-secret | ||
restartPolicy: Never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{{- $db_host := .Values.mariadb.host | toString | b64enc }} | ||
{{- $root_user := .Values.mariadb.root.user | default "root" | toString | b64enc }} | ||
{{- $root_password := .Values.mariadb.root.password | toString | b64enc }} | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: {{ .Release.Name }}-mariadb-agent-secret | ||
labels: | ||
{{- include "mariadb-agent.labels" . | nindent 4 }} | ||
type: Opaque | ||
data: | ||
DB_HOST: {{ $db_host }} | ||
ROOT_USER: {{ $root_user }} | ||
MYSQL_PWD: {{ $root_password }} |
Oops, something went wrong.