feat(health): Implement k8s.mariadb.com CRD health checks (#17995)

* 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>
This commit is contained in:
Mikael Sennerholm
2024-05-08 18:22:05 +02:00
committed by GitHub
parent 1cd6fcac4f
commit 440fbac12b
25 changed files with 565 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,5 @@
tests:
- healthStatus:
status: Healthy
message: "Created"
inputPath: testdata/database-ready.yaml

View File

@@ -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

View File

@@ -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

View File

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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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-05T14:18:01Z"
message: Not ready
reason: StatefulSetNotReady
status: "False"
type: Ready

View File

@@ -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-05T14:18:01Z"
message: Running
reason: StatefulSetReady
status: "True"
type: Ready

View File

@@ -0,0 +1,21 @@
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.reason .. " " .. condition.message
if condition.reason == "JobComplete" and condition.status == "True" then
health_status.status = "Healthy"
return health_status
end
if condition.reason == "JobFailed" and condition.status == "True" then
health_status.status = "Degraded"
return health_status
end
end
end
return health_status

View File

@@ -0,0 +1,9 @@
tests:
- healthStatus:
status: Healthy
message: "JobComplete Success"
inputPath: testdata/sqljobs-ok.yaml
- healthStatus:
status: Degraded
message: "JobFailed Failed"
inputPath: testdata/sqljobs-failed.yaml

View File

@@ -0,0 +1,24 @@
apiVersion: k8s.mariadb.com/v1alpha1
kind: SqlJob
metadata:
name: jobname
spec:
backoffLimit: 5
database: dbname
mariaDbRef:
name: mariadb
waitForIt: true
passwordSecretKeyRef:
key: password
name: mariadb-root
restartPolicy: OnFailure
serviceAccountName: jobname
sql: "Some SQL"
username: root
status:
conditions:
- lastTransitionTime: "2024-03-19T11:39:00Z"
message: Failed
reason: JobFailed
status: "True"
type: Complete

View File

@@ -0,0 +1,23 @@
apiVersion: k8s.mariadb.com/v1alpha1
kind: SqlJob
metadata:
name: jobname
spec:
backoffLimit: 5
database: dbname
mariaDbRef:
name: mariadb
waitForIt: true
passwordSecretKeyRef:
key: password
name: mariadb-root
restartPolicy: Never
serviceAccountName: jobname
sql: "some SQL;"
status:
conditions:
- lastTransitionTime: "2024-04-22T14:08:49Z"
message: Success
reason: JobComplete
status: "True"
type: Complete

View File

@@ -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

View File

@@ -0,0 +1,5 @@
tests:
- healthStatus:
status: Healthy
message: "Created"
inputPath: testdata/user-created.yaml

View File

@@ -0,0 +1,37 @@
apiVersion: k8s.mariadb.com/v1alpha1
kind: User
metadata:
creationTimestamp: "2024-04-12T13:43:56Z"
finalizers:
- user.k8s.mariadb.com/finalizer
generation: 1
labels:
db.bridge.a3p.com: mariadb
name: mariadb-metrics
namespace: bridge
ownerReferences:
- apiVersion: k8s.mariadb.com/v1alpha1
blockOwnerDeletion: true
controller: true
kind: MariaDB
name: mariadb
uid: a29fc76f-66a5-4612-9b15-16c405f7edd9
resourceVersion: "345121483"
uid: ecce1099-7b71-418b-b386-893db5fd7e59
spec:
mariaDbRef:
name: mariadb
namespace: bridge
waitForIt: false
maxUserConnections: 3
name: mariadb-metrics
passwordSecretKeyRef:
key: password
name: mariadb-metrics-password
status:
conditions:
- lastTransitionTime: "2024-04-12T13:43:57Z"
message: Created
reason: Created
status: "True"
type: Ready