@ -17,10 +17,11 @@ import (
)
const (
messageReady = "All components ready"
messageFailed = "Some LokiStack components failed"
messagePending = "Some LokiStack components pending on dependencies"
messageDegradedNodeLabels = "Cluster contains no nodes matching the labels used for zone-awareness"
messageReady = "All components ready"
messageFailed = "Some LokiStack components failed"
messagePending = "Some LokiStack components pending on dependencies"
messageDegradedMissingNodes = "Cluster contains no nodes matching the labels used for zone-awareness"
messageDegradedEmptyNodeLabel = "No value for the labels used for zone-awareness"
)
var (
@ -41,8 +42,13 @@ var (
}
conditionDegradedNodeLabels = metav1 . Condition {
Type : string ( lokiv1 . ConditionDegraded ) ,
Message : messageDegradedNodeLabels ,
Reason : string ( lokiv1 . ReasonNoZoneAwareNodes ) ,
Message : messageDegradedMissingNodes ,
Reason : string ( lokiv1 . ReasonZoneAwareNodesMissing ) ,
}
conditionDegradedEmptyNodeLabel = metav1 . Condition {
Type : string ( lokiv1 . ConditionDegraded ) ,
Message : messageDegradedEmptyNodeLabel ,
Reason : string ( lokiv1 . ReasonZoneAwareEmptyLabel ) ,
}
)
@ -97,7 +103,7 @@ func generateCondition(ctx context.Context, cs *lokiv1.LokiStackComponentStatus,
if stack . Spec . Replication != nil && len ( stack . Spec . Replication . Zones ) > 0 {
// When there are pending pods and zone-awareness is enabled check if there are any nodes
// that can satisfy the constraints and emit a condition if not.
nodesOk , err := checkForZoneawareNodes ( ctx , k , stack . Spec . Replication . Zones )
nodesOk , labelsOk , err := checkForZoneawareNodes ( ctx , k , stack . Spec . Replication . Zones )
if err != nil {
return metav1 . Condition { } , err
}
@ -105,6 +111,10 @@ func generateCondition(ctx context.Context, cs *lokiv1.LokiStackComponentStatus,
if ! nodesOk {
return conditionDegradedNodeLabels , nil
}
if ! labelsOk {
return conditionDegradedEmptyNodeLabel , nil
}
}
return conditionPending , nil
@ -113,7 +123,7 @@ func generateCondition(ctx context.Context, cs *lokiv1.LokiStackComponentStatus,
return conditionReady , nil
}
func checkForZoneawareNodes ( ctx context . Context , k client . Client , zones [ ] lokiv1 . ZoneSpec ) ( bool , error ) {
func checkForZoneawareNodes ( ctx context . Context , k client . Client , zones [ ] lokiv1 . ZoneSpec ) ( nodesOk bool , labelsOk bool , err error ) {
nodeLabels := client . HasLabels { }
for _ , z := range zones {
nodeLabels = append ( nodeLabels , z . TopologyKey )
@ -121,10 +131,22 @@ func checkForZoneawareNodes(ctx context.Context, k client.Client, zones []lokiv1
nodeList := & corev1 . NodeList { }
if err := k . List ( ctx , nodeList , nodeLabels ) ; err != nil {
return false , err
return false , false , err
}
if len ( nodeList . Items ) == 0 {
return false , false , nil
}
for _ , node := range nodeList . Items {
for _ , nodeLabel := range nodeLabels {
if node . Labels [ nodeLabel ] == "" {
return true , false , nil
}
}
}
return len ( nodeList . Items ) > 0 , nil
return true , true , nil
}
func updateCondition ( ctx context . Context , k k8s . Client , req ctrl . Request , condition metav1 . Condition ) error {