This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
/
conditionready.go
66 lines (56 loc) · 2.16 KB
/
conditionready.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package azuremachinepoolconditions
import (
"context"
azureconditions "github.com/giantswarm/apiextensions/v6/pkg/conditions/azure"
"github.com/giantswarm/microerror"
corev1 "k8s.io/api/core/v1"
capzexp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1"
capi "sigs.k8s.io/cluster-api/api/v1beta1"
capiconditions "sigs.k8s.io/cluster-api/util/conditions"
)
func (r *Resource) ensureReadyCondition(ctx context.Context, azureMachinePool *capzexp.AzureMachinePool) error {
r.logger.Debugf(ctx, "ensuring condition Ready")
var err error
// Ensure VMMSReady condition
err = r.ensureSubnetReadyCondition(ctx, azureMachinePool)
if err != nil {
return microerror.Mask(err)
}
// Ensure VMMSReady condition
err = r.ensureVMSSReadyCondition(ctx, azureMachinePool)
if err != nil {
return microerror.Mask(err)
}
// List of conditions that all need to be True for the Ready condition to
// be True:
// - VMSSReady: node pool VMSS is ready
// - SubnetReady: node pool subnet is ready
conditionsToSummarize := capiconditions.WithConditions(
azureconditions.SubnetReadyCondition,
azureconditions.VMSSReadyCondition)
// Update Ready condition
capiconditions.SetSummary(
azureMachinePool,
conditionsToSummarize,
capiconditions.AddSourceRef())
// Now check current Ready condition so we can log the value
r.logConditionStatus(ctx, azureMachinePool, capi.ReadyCondition)
r.logger.Debugf(ctx, "ensured condition Ready")
return nil
}
func (r *Resource) logConditionStatus(ctx context.Context, azureMachinePool *capzexp.AzureMachinePool, conditionType capi.ConditionType) {
condition := capiconditions.Get(azureMachinePool, conditionType)
if condition == nil {
r.logger.Debugf(ctx, "condition %s not set", conditionType)
} else {
messageFormat := "condition %s set to %s"
messageArgs := []interface{}{conditionType, condition.Status}
if condition.Status != corev1.ConditionTrue {
messageFormat += ", Reason=%s, Severity=%s, Message=%s"
messageArgs = append(messageArgs, condition.Reason)
messageArgs = append(messageArgs, condition.Severity)
messageArgs = append(messageArgs, condition.Message)
}
r.logger.Debugf(ctx, messageFormat, messageArgs...)
}
}