Skip to content

Commit

Permalink
Add Icinga states to deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoxhaa committed May 17, 2024
1 parent 230491b commit a263be1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/schema/v1/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +27,7 @@ type Deployment struct {
ReadyReplicas int32
AvailableReplicas int32
UnavailableReplicas int32
IcingaState string
Conditions []DeploymentCondition `db:"-"`
Labels []Label `db:"-"`
DeploymentLabels []DeploymentLabel `db:"-"`
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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")

Expand Down
1 change: 1 addition & 0 deletions schema/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a263be1

Please sign in to comment.