From a263be13c83690b221ad1845b14b7e0c1ef09381 Mon Sep 17 00:00:00 2001 From: Jonada Hoxha Date: Fri, 17 May 2024 10:02:07 +0200 Subject: [PATCH] Add Icinga states to deployment --- pkg/schema/v1/deployment.go | 18 ++++++++++++++++++ schema/mysql/schema.sql | 1 + 2 files changed, 19 insertions(+) diff --git a/pkg/schema/v1/deployment.go b/pkg/schema/v1/deployment.go index b6f1b63d..1599ba53 100644 --- a/pkg/schema/v1/deployment.go +++ b/pkg/schema/v1/deployment.go @@ -9,6 +9,11 @@ import ( "strings" ) +const Ok = "ok" +const Warning = "warning" +const Critical = "critical" +const Unknown = "unknown" + type Deployment struct { Meta Id types.Binary @@ -22,6 +27,7 @@ type Deployment struct { ReadyReplicas int32 AvailableReplicas int32 UnavailableReplicas int32 + IcingaState string Conditions []DeploymentCondition `db:"-"` Labels []Label `db:"-"` DeploymentLabels []DeploymentLabel `db:"-"` @@ -72,6 +78,7 @@ func (d *Deployment) Obtain(k8s kmetav1.Object) { d.AvailableReplicas = deployment.Status.AvailableReplicas d.ReadyReplicas = deployment.Status.ReadyReplicas d.UnavailableReplicas = deployment.Status.UnavailableReplicas + d.IcingaState = getIcingaState(d) for _, condition := range deployment.Status.Conditions { d.Conditions = append(d.Conditions, DeploymentCondition{ @@ -99,6 +106,17 @@ func (d *Deployment) Obtain(k8s kmetav1.Object) { } } +func getIcingaState(d *Deployment) string { + switch { + case d.UnavailableReplicas > 0: + return Critical + case d.AvailableReplicas < d.DesiredReplicas: + return Warning + default: + return Ok + } +} + func (d *Deployment) Relations() []database.Relation { fk := database.WithForeignKey("deployment_id") diff --git a/schema/mysql/schema.sql b/schema/mysql/schema.sql index 9f8c0229..143bc5d0 100644 --- a/schema/mysql/schema.sql +++ b/schema/mysql/schema.sql @@ -176,6 +176,7 @@ CREATE TABLE deployment ( ready_replicas int unsigned NOT NULL, available_replicas int unsigned NOT NULL, unavailable_replicas int unsigned NOT NULL, + icinga_state enum('ok', 'warning', 'critical', 'unknown') COLLATE utf8mb4_unicode_ci NOT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;