Skip to content

Commit

Permalink
Merge pull request #33 from irfanhakim-as/mariadb-agent
Browse files Browse the repository at this point in the history
New chart and general improvements
  • Loading branch information
irfanhakim-as authored Dec 4, 2023
2 parents 53428cf + 63149d2 commit 7cee183
Show file tree
Hide file tree
Showing 21 changed files with 336 additions and 45 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ Applications, developed or curated by [mika](https://github.com/irfanhakim-as),
| [cloudflareddns](https://github.com/irfanhakim-as/charts/tree/master/mika/cloudflareddns) | Access your home network remotely via a custom domain name without a static IP! |||
| [grocy](https://github.com/irfanhakim-as/charts/tree/master/mika/grocy) | Grocy is a web-based self-hosted groceries & household management solution for your home. |||
| [mango](https://github.com/irfanhakim-as/charts/tree/master/mika/mango) | Mango is an easy to use Mastodon bot framework built on top of Django. || 🔒 |
| [mariadb-agent](https://github.com/irfanhakim-as/charts/tree/master/mika/mariadb-agent) | Easily create or delete multiple pairs of databases and users in a remote MariaDB instance. |||
| [postgres](https://github.com/irfanhakim-as/charts/tree/master/mika/postgres) | Easy tool to deploy a PostgreSQL instance on Kubernetes. |||
| [postgres-agent](https://github.com/irfanhakim-as/charts/tree/master/mika/postgres-agent) | Easily deploy a database and create a user, or delete a database in a remote PostgreSQL instance. |||
| [postgres-agent](https://github.com/irfanhakim-as/charts/tree/master/mika/postgres-agent) | Easily create or delete a database and user pair in a remote PostgreSQL instance. |||
| [rizz](https://github.com/irfanhakim-as/charts/tree/master/mika/rizz) | Rizz is a simple web application that tracks and posts content from RSS Feeds to Mastodon. || 🔒 |
| [telego](https://github.com/irfanhakim-as/charts/tree/master/mika/telego) | Telego is an easy to use Telegram bot framework built on top of Django. || 🔒 |
| [vpbot](https://github.com/irfanhakim-as/charts/tree/master/mika/vpbot) | Vpbot is a Telegram bot with support for a number of useful features such as prayer time notifications, COVID-19 statistics, and more. || 🔒 |
Expand Down
Empty file modified logos/clog.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logos/mariadb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified logos/mika.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified logos/postgres.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified logos/vpbot.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions mika/clog/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: clog
description: Creative blog, Career blog, Coin blog, you name it.
type: application
version: 0.2.2
appVersion: "0.0.1-stable"
version: 0.2.3
appVersion: "0.0.2-stable-r1"
keywords:
- "clog"
- "blog"
Expand Down
28 changes: 0 additions & 28 deletions mika/clog/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,6 @@ spec:
protocol: TCP
resources:
{{- toYaml .Values.resources.clog | nindent 12 }}
env:
{{- if or $cloudflared $ingress }}
- name: ALLOWED_HOSTS
valueFrom:
configMapKeyRef:
name: {{ .Release.Name }}-clog-cm
key: DOMAIN
{{- end }}
- name: POSTGRES_HOST
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-clog-postgres-secret
key: DB_HOST
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-clog-postgres-secret
key: DB_NAME
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-clog-postgres-secret
key: DB_USER
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-clog-postgres-secret
key: DB_PASS
envFrom:
- configMapRef:
name: {{ .Release.Name }}-clog-cm
Expand Down
2 changes: 1 addition & 1 deletion mika/clog/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- $ingress := .Values.clog.ingress.enabled }}
{{- if $ingress }}
{{- $cluster_issuer := .Values.clog.ingress.clusterIssuer | default "letsencrypt-dns-prod" | toString | quote }}
{{- $domain = .Values.clog.ingress.domain | default "localhost" | toString }}
{{- $domain := .Values.clog.ingress.domain | default "localhost" | toString }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
Expand Down
9 changes: 0 additions & 9 deletions mika/clog/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ data:
{{- if $ngrok }}
NGROK_AUTH_TOKEN: {{ $token }}
{{- end }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Name }}-clog-postgres-secret
labels:
{{- include "clog.labels" . | nindent 4 }}
type: Opaque
data:
DB_TYPE: {{ $db_type }}
DB_NAME: {{ $db_name }}
DB_USER: {{ $db_user }}
Expand Down
23 changes: 23 additions & 0 deletions mika/mariadb-agent/.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/
19 changes: 19 additions & 0 deletions mika/mariadb-agent/Chart.yaml
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"
85 changes: 85 additions & 0 deletions mika/mariadb-agent/README.md
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"`. |
5 changes: 5 additions & 0 deletions mika/mariadb-agent/templates/NOTES.txt
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.
62 changes: 62 additions & 0 deletions mika/mariadb-agent/templates/_helpers.tpl
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 }}
55 changes: 55 additions & 0 deletions mika/mariadb-agent/templates/deployment.yaml
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
14 changes: 14 additions & 0 deletions mika/mariadb-agent/templates/secret.yaml
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 }}
Loading

0 comments on commit 7cee183

Please sign in to comment.