Skip to content

Commit

Permalink
Add Icinga states to replica set
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoxhaa committed May 14, 2024
1 parent 230491b commit f5c148a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/schema/v1/replica_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
"strings"
)

const OK = "ok"
const Warning = "warning"
const Critical = "critical"
const Unknown = "unknown"

type ReplicaSet struct {
Meta
Id types.Binary
Expand All @@ -19,6 +24,7 @@ type ReplicaSet struct {
FullyLabeledReplicas int32
ReadyReplicas int32
AvailableReplicas int32
IcingaState string
Conditions []ReplicaSetCondition `db:"-"`
Owners []ReplicaSetOwner `db:"-"`
Labels []Label `db:"-"`
Expand Down Expand Up @@ -68,6 +74,7 @@ func (r *ReplicaSet) Obtain(k8s kmetav1.Object) {
r.FullyLabeledReplicas = replicaSet.Status.FullyLabeledReplicas
r.ReadyReplicas = replicaSet.Status.ReadyReplicas
r.AvailableReplicas = replicaSet.Status.AvailableReplicas
r.IcingaState = getReplicaSetMonitoringState(r)

for _, condition := range replicaSet.Status.Conditions {
r.Conditions = append(r.Conditions, ReplicaSetCondition{
Expand Down Expand Up @@ -118,6 +125,21 @@ func (r *ReplicaSet) Obtain(k8s kmetav1.Object) {
}
}

func getReplicaSetMonitoringState(r *ReplicaSet) string {
if r.DesiredReplicas < 1 {
return Unknown
}

switch {
case r.AvailableReplicas < 1:
return Critical
case r.AvailableReplicas < r.DesiredReplicas:
return Warning
default:
return OK
}
}

func (r *ReplicaSet) Relations() []database.Relation {
fk := database.WithForeignKey("replica_set_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 @@ -353,6 +353,7 @@ CREATE TABLE replica_set (
fully_labeled_replicas int unsigned NOT NULL,
ready_replicas int unsigned NOT NULL,
available_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 f5c148a

Please sign in to comment.