Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
1cd6fca
commit 440fbac
Showing
25 changed files
with
565 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
9 changes: 9 additions & 0 deletions
9
resource_customizations/k8s.mariadb.com/Backup/health_test.yaml
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,9 @@ | ||
tests: | ||
- healthStatus: | ||
status: Healthy | ||
message: "CronJobSucess Success" | ||
inputPath: testdata/ok.yaml | ||
- healthStatus: | ||
status: Degraded | ||
message: "CronJobScheduled Failed" | ||
inputPath: testdata/failed.yaml |
30 changes: 30 additions & 0 deletions
30
resource_customizations/k8s.mariadb.com/Backup/testdata/failed.yaml
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,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
41
resource_customizations/k8s.mariadb.com/Backup/testdata/ok.yaml
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,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
23
resource_customizations/k8s.mariadb.com/Database/health.lua
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 @@ | ||
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 |
5 changes: 5 additions & 0 deletions
5
resource_customizations/k8s.mariadb.com/Database/health_test.yaml
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 @@ | ||
tests: | ||
- healthStatus: | ||
status: Healthy | ||
message: "Created" | ||
inputPath: testdata/database-ready.yaml |
19 changes: 19 additions & 0 deletions
19
resource_customizations/k8s.mariadb.com/Database/testdata/database-ready.yaml
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: 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 |
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,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 |
6 changes: 6 additions & 0 deletions
6
resource_customizations/k8s.mariadb.com/Grant/health_test.yaml
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,6 @@ | ||
tests: | ||
- healthStatus: | ||
status: Healthy | ||
message: "Created" | ||
inputPath: testdata/grant-ready.yaml | ||
|
26 changes: 26 additions & 0 deletions
26
resource_customizations/k8s.mariadb.com/Grant/testdata/grant-ready.yaml
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,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
25
resource_customizations/k8s.mariadb.com/MariaDB/health.lua
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,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
25
resource_customizations/k8s.mariadb.com/MariaDB/health_test.yaml
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,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 |
27 changes: 27 additions & 0 deletions
27
resource_customizations/k8s.mariadb.com/MariaDB/testdata/mariadb_error.yaml
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,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 |
22 changes: 22 additions & 0 deletions
22
resource_customizations/k8s.mariadb.com/MariaDB/testdata/no_status.yaml
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,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 |
32 changes: 32 additions & 0 deletions
32
resource_customizations/k8s.mariadb.com/MariaDB/testdata/restore_complete.yaml
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,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 |
32 changes: 32 additions & 0 deletions
32
resource_customizations/k8s.mariadb.com/MariaDB/testdata/restore_not_complete.yaml
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,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 |
Oops, something went wrong.