This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
/
conditionready.go
57 lines (47 loc) · 1.94 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
package azureclusterconditions
import (
"context"
azureconditions "github.com/giantswarm/apiextensions/v6/pkg/conditions/azure"
"github.com/giantswarm/microerror"
corev1 "k8s.io/api/core/v1"
capz "sigs.k8s.io/cluster-api-provider-azure/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, azureCluster *capz.AzureCluster) error {
r.logger.Debugf(ctx, "setting condition Ready")
// Note: This is an incomplete implementation that checks only resource
// group, because it's created in the beginning, and the VPN Gateway,
// because it's created at the end. Final implementation should include
// checking of other Azure resources as well. and it will be done in
// AzureCluster controller.
err := r.ensureVNetPeeringReadyCondition(ctx, azureCluster)
if err != nil {
return microerror.Mask(err)
}
// List of conditions that all need to be True for the Ready condition to
// be True.
conditionsToSummarize := capiconditions.WithConditions(
azureconditions.ResourceGroupReadyCondition,
VNetPeeringReadyCondition)
capiconditions.SetSummary(
azureCluster,
conditionsToSummarize,
capiconditions.AddSourceRef())
readyCondition := capiconditions.Get(azureCluster, capi.ReadyCondition)
if readyCondition == nil {
r.logger.Debugf(ctx, "condition Ready not set")
} else {
messageFormat := "condition Ready set to %s"
messageArgs := []interface{}{readyCondition.Status}
if readyCondition.Status != corev1.ConditionTrue {
messageFormat += ", Reason=%s, Severity=%s, Message=%s"
messageArgs = append(messageArgs, readyCondition.Reason)
messageArgs = append(messageArgs, readyCondition.Severity)
messageArgs = append(messageArgs, readyCondition.Message)
}
r.logger.Debugf(ctx, messageFormat, messageArgs...)
azureCluster.Status.Ready = capiconditions.IsTrue(azureCluster, capi.ReadyCondition)
}
return nil
}