-
Notifications
You must be signed in to change notification settings - Fork 287
/
clusterapi.go
39 lines (32 loc) · 1.35 KB
/
clusterapi.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
package clusters
import (
"context"
"time"
"github.com/go-logr/logr"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/controller-runtime/pkg/client"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/clusterapi"
"github.com/aws/eks-anywhere/pkg/controller"
)
// CheckControlPlaneReady is a controller helper to check whether a CAPI cluster CP for
// an eks-a cluster is ready or not. This is intended to be used from cluster reconcilers
// due its signature and that it returns controller results with appropriate wait times whenever
// the cluster is not ready.
func CheckControlPlaneReady(ctx context.Context, client client.Client, log logr.Logger, cluster *anywherev1.Cluster) (controller.Result, error) {
capiCluster, err := controller.GetCAPICluster(ctx, client, cluster)
if err != nil {
return controller.Result{}, err
}
if capiCluster == nil {
log.Info("CAPI cluster does not exist yet, requeuing")
return controller.ResultWithRequeue(5 * time.Second), nil
}
if !conditions.IsTrue(capiCluster, clusterapi.ControlPlaneReadyCondition) {
log.Info("CAPI control plane is not ready yet, requeuing")
// TODO: eventually this can be implemented with controller watches
return controller.ResultWithRequeue(30 * time.Second), nil
}
log.Info("CAPI control plane is ready")
return controller.Result{}, nil
}