/
node_condition_mutator.go
38 lines (32 loc) · 1.13 KB
/
node_condition_mutator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package shoot
import (
"context"
corev1 "k8s.io/api/core/v1"
)
const (
noRouteCreated = "NoRouteCreated"
nodeCreatedWithoutRoute = "Node created without a route"
)
func (m *mutator) mutateNetworkUnavailableNodeCondition(_ context.Context, new *corev1.Node, old *corev1.Node, logMutation func()) error {
if new == nil || old == nil {
return nil
}
for i, c := range new.Status.Conditions {
if c.Type == corev1.NodeNetworkUnavailable && c.Status == corev1.ConditionTrue && c.Reason == noRouteCreated && c.Message == nodeCreatedWithoutRoute {
logMutation()
for _, oldCondition := range old.Status.Conditions {
if oldCondition.Type == corev1.NodeNetworkUnavailable && oldCondition.Status == corev1.ConditionFalse {
new.Status.Conditions[i] = oldCondition
return nil
}
}
// Did not find the condition in the old object => remove the condition
new.Status.Conditions = append(new.Status.Conditions[:i], new.Status.Conditions[i+1:]...)
return nil
}
}
return nil
}