Skip to content

Commit

Permalink
feat(health): Implement k8s.mariadb.com CRD health checks (#17995)
Browse files Browse the repository at this point in the history
* Copied MariaDB from old name and change to new name
Adding Backup, SqlJobs, Grant, Database and User

Signed-off-by: Mikael Sennerholm <mikael@sennerholm.net>

* Set progressing as default

Signed-off-by: Mikael Sennerholm <mikael@sennerholm.net>

---------

Signed-off-by: Mikael Sennerholm <mikael@sennerholm.net>
Co-authored-by: pasha-codefresh <pavel@codefresh.io>
  • Loading branch information
sennerholm and pasha-codefresh committed May 8, 2024
1 parent 1cd6fca commit 440fbac
Show file tree
Hide file tree
Showing 25 changed files with 565 additions and 0 deletions.
25 changes: 25 additions & 0 deletions resource_customizations/k8s.mariadb.com/Backup/health.lua
@@ -0,0 +1,25 @@
local health_status = {}

if obj.status ~= nil and obj.status.conditions ~= nil then

for i, condition in ipairs(obj.status.conditions) do

health_status.message = condition.reason .. " " .. condition.message

if condition.status == "False" then
if condition.reason == "CronJobScheduled" and condition.message == "Failed" then
health_status.status = "Degraded"
return health_status
end
health_status.status = "Progressing"
return health_status
end
end

health_status.status = "Healthy"
return health_status
end

health_status.status = "Progressing"
health_status.message = "No status info available"
return health_status
@@ -0,0 +1,9 @@
tests:
- healthStatus:
status: Healthy
message: "CronJobSucess Success"
inputPath: testdata/ok.yaml
- healthStatus:
status: Degraded
message: "CronJobScheduled Failed"
inputPath: testdata/failed.yaml
@@ -0,0 +1,30 @@
apiVersion: k8s.mariadb.com/v1alpha1
kind: Backup
metadata:
name: backup-local
spec:
backoffLimit: 5
logLevel: info
mariaDbRef:
name: mariadb
waitForIt: true
maxRetention: 168h
restartPolicy: OnFailure
schedule:
cron: 0 */2 * * *
suspend: false
serviceAccountName: backup-local
storage:
persistentVolumeClaim:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 80Gi
status:
conditions:
- lastTransitionTime: "2024-04-22T20:00:00Z"
message: Failed
reason: CronJobScheduled
status: "False"
type: Complete
41 changes: 41 additions & 0 deletions resource_customizations/k8s.mariadb.com/Backup/testdata/ok.yaml
@@ -0,0 +1,41 @@
apiVersion: k8s.mariadb.com/v1alpha1
kind: Backup
metadata:
annotations:
argocd.argoproj.io/tracking-id: apps-bridge-demo-de1:k8s.mariadb.com/Backup:bridge/backup-local-bridge
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"k8s.mariadb.com/v1alpha1","kind":"Backup","metadata":{"annotations":{"argocd.argoproj.io/tracking-id":"apps-bridge-demo-de1:k8s.mariadb.com/Backup:bridge/backup-local-bridge"},"name":"backup-local-bridge","namespace":"bridge"},"spec":{"args":["--databases bridge"],"mariaDbRef":{"name":"mariadb"},"maxRetention":"168h","schedule":{"cron":"0 1-23/2 * * *","suspend":false},"storage":{"persistentVolumeClaim":{"accessModes":["ReadWriteOnce"],"resources":{"requests":{"storage":"80Gi"}}}}}}
creationTimestamp: "2024-04-12T12:35:41Z"
generation: 2
name: backup-local-bridge
namespace: bridge
resourceVersion: "506591405"
uid: 67364d0a-6da9-4369-97fd-45ea468dbbea
spec:
args:
- --databases bridge
backoffLimit: 5
logLevel: info
mariaDbRef:
name: mariadb
waitForIt: true
maxRetention: 168h
restartPolicy: OnFailure
schedule:
cron: 0 1-23/2 * * *
suspend: false
serviceAccountName: backup-local-bridge
storage:
persistentVolumeClaim:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 80Gi
status:
conditions:
- lastTransitionTime: "2024-04-24T15:00:23Z"
message: Success
reason: CronJobSucess
status: "True"
type: Complete
23 changes: 23 additions & 0 deletions resource_customizations/k8s.mariadb.com/Database/health.lua
@@ -0,0 +1,23 @@
local health_status = {}
health_status.status = "Progressing"
health_status.message = "No status info available"

if obj.status ~= nil and obj.status.conditions ~= nil then

for i, condition in ipairs(obj.status.conditions) do

health_status.message = condition.message

if condition.type == "Ready" then
if condition.status == "True" then
health_status.status = "Healthy"
else
health_status.status = "Degraded"
end
return health_status
end
end
end


return health_status
@@ -0,0 +1,5 @@
tests:
- healthStatus:
status: Healthy
message: "Created"
inputPath: testdata/database-ready.yaml
@@ -0,0 +1,19 @@
apiVersion: k8s.mariadb.com/v1alpha1
kind: Database
metadata:
name: dbname
spec:
characterSet: utf8
collate: utf8_general_ci
mariaDbRef:
name: mariadb
waitForIt: true
requeueInterval: 30s
retryInterval: 5s
status:
conditions:
- lastTransitionTime: "2024-04-12T13:43:57Z"
message: Created
reason: Created
status: "True"
type: Ready
22 changes: 22 additions & 0 deletions resource_customizations/k8s.mariadb.com/Grant/health.lua
@@ -0,0 +1,22 @@
local health_status = {}
health_status.status = "Progressing"
health_status.message = "No status info available"
if obj.status ~= nil and obj.status.conditions ~= nil then

for i, condition in ipairs(obj.status.conditions) do

health_status.message = condition.message

if condition.type == "Ready" then
if condition.status == "True" then
health_status.status = "Healthy"
else
health_status.status = "Degraded"
end
return health_status
end
end
end


return health_status
@@ -0,0 +1,6 @@
tests:
- healthStatus:
status: Healthy
message: "Created"
inputPath: testdata/grant-ready.yaml

@@ -0,0 +1,26 @@
apiVersion: k8s.mariadb.com/v1alpha1
kind: Grant
metadata:
name: mariadb-metrics
spec:
database: '*'
grantOption: false
mariaDbRef:
name: mariadb
namespace: bridge
waitForIt: false
privileges:
- SELECT
- PROCESS
- REPLICATION CLIENT
- REPLICA MONITOR
- SLAVE MONITOR
table: '*'
username: mariadb-metrics
status:
conditions:
- lastTransitionTime: "2024-04-20T20:45:02Z"
message: Created
reason: Created
status: "True"
type: Ready
25 changes: 25 additions & 0 deletions resource_customizations/k8s.mariadb.com/MariaDB/health.lua
@@ -0,0 +1,25 @@
local health_status = {}

if obj.status ~= nil and obj.status.conditions ~= nil then

for i, condition in ipairs(obj.status.conditions) do

health_status.message = condition.message

if condition.status == "False" then
if condition.reason == "Failed" then
health_status.status = "Degraded"
return health_status
end
health_status.status = "Progressing"
return health_status
end
end

health_status.status = "Healthy"
return health_status
end

health_status.status = "Progressing"
health_status.message = "No status info available"
return health_status
25 changes: 25 additions & 0 deletions resource_customizations/k8s.mariadb.com/MariaDB/health_test.yaml
@@ -0,0 +1,25 @@
tests:
- healthStatus:
status: Progressing
message: "No status info available"
inputPath: testdata/no_status.yaml
- healthStatus:
status: Healthy
message: "Running"
inputPath: testdata/statefulset_ready.yaml
- healthStatus:
status: Progressing
message: "Not ready"
inputPath: testdata/statefulset_not_ready.yaml
- healthStatus:
status: Healthy
message: "Running"
inputPath: testdata/restore_complete.yaml
- healthStatus:
status: Progressing
message: "Restoring backup"
inputPath: testdata/restore_not_complete.yaml
- healthStatus:
status: Degraded
message: "Error creating ConfigMap"
inputPath: testdata/mariadb_error.yaml
@@ -0,0 +1,27 @@
apiVersion: k8s.mariadb.com/v1alpha1
kind: MariaDB
metadata:
name: mariadb-server
spec:
rootPasswordSecretKeyRef:
name: mariadb
key: root-password
image:
repository: mariadb
tag: "10.7.4"
pullPolicy: IfNotPresent
port: 3306
volumeClaimTemplate:
resources:
requests:
storage: 100Mi
storageClassName: standard
accessModes:
- ReadWriteOnce
status:
conditions:
- lastTransitionTime: '2023-04-20T15:31:15Z'
message: Error creating ConfigMap
reason: Failed
status: 'False'
type: Ready
@@ -0,0 +1,22 @@
apiVersion: k8s.mariadb.com/v1alpha1
kind: MariaDB
metadata:
name: mariadb-server
spec:
rootPasswordSecretKeyRef:
name: mariadb
key: root-password
image:
repository: mariadb
tag: "10.7.4"
pullPolicy: IfNotPresent
port: 3306
volumeClaimTemplate:
resources:
requests:
storage: 100Mi
storageClassName: standard
accessModes:
- ReadWriteOnce
status:
revision: 0
@@ -0,0 +1,32 @@
apiVersion: k8s.mariadb.com/v1alpha1
kind: MariaDB
metadata:
name: mariadb-server
spec:
rootPasswordSecretKeyRef:
name: mariadb
key: root-password
image:
repository: mariadb
tag: "10.7.4"
pullPolicy: IfNotPresent
port: 3306
volumeClaimTemplate:
resources:
requests:
storage: 100Mi
storageClassName: standard
accessModes:
- ReadWriteOnce
status:
conditions:
- lastTransitionTime: "2023-04-05T14:18:01Z"
message: Ready
reason: RestoreComplete
status: "True"
type: Bootstrapped
- lastTransitionTime: "2023-04-05T14:18:02Z"
message: Running
reason: RestoreComplete
status: "True"
type: Ready
@@ -0,0 +1,32 @@
apiVersion: k8s.mariadb.com/v1alpha1
kind: MariaDB
metadata:
name: mariadb-server
spec:
rootPasswordSecretKeyRef:
name: mariadb
key: root-password
image:
repository: mariadb
tag: "10.7.4"
pullPolicy: IfNotPresent
port: 3306
volumeClaimTemplate:
resources:
requests:
storage: 100Mi
storageClassName: standard
accessModes:
- ReadWriteOnce
status:
conditions:
- lastTransitionTime: "2023-04-05T14:18:01Z"
message: Restoring backup
reason: RestoreNotComplete
status: "False"
type: Ready
- lastTransitionTime: "2023-04-05T14:18:02Z"
message: Not ready
reason: RestoreNotComplete
status: "False"
type: Bootstrapped

0 comments on commit 440fbac

Please sign in to comment.