From c05f166fae2620b6b13339738a4fb895195e3b34 Mon Sep 17 00:00:00 2001 From: isaaguilar Date: Tue, 18 Jul 2023 12:00:14 -0400 Subject: [PATCH] do a vcluster health check before starting informer --- internal/tfhandler/tfhandler.go | 25 +++++++++++++++++++++++++ pkg/tfoapiclient/client.go | 8 ++++++++ 2 files changed, 33 insertions(+) diff --git a/internal/tfhandler/tfhandler.go b/internal/tfhandler/tfhandler.go index 9470d58..5763f96 100644 --- a/internal/tfhandler/tfhandler.go +++ b/internal/tfhandler/tfhandler.go @@ -59,6 +59,29 @@ func NewInformer(config *rest.Config, clientSetup tfoapiclient.ClientSetup, host log.Fatal(err) } + // A first time vcluster can take a minute to be available. Wait until the vcluster is available. + vclusterReady := false + for { + if !vclusterReady { + clusterHealthResult, err := clientset.Cluster(clientSetup.ClusterName).Health().Read(context.TODO(), nil) + if err != nil || !clusterHealthResult.IsSuccess { + time.Sleep(60 * time.Second) + continue + } + vclusterReady = true + log.Println("VCluster is ready!") + } + + tfoHealthResult, err := clientset.Cluster(clientSetup.ClusterName).TFOHealth().Read(context.TODO(), nil) + if err != nil || !tfoHealthResult.IsSuccess { + time.Sleep(60 * time.Second) + continue + } + log.Println("TFO is ready!") + // Both vcluster and tfo are ready + break + } + tfhandler := informer{ ctx: context.TODO(), config: config, @@ -84,6 +107,8 @@ func (i informer) Run() { stopCh := make(chan struct{}) defer close(stopCh) i.backgroundQueueWorker() + + // Start the informer i.Start(stopCh) <-stopCh log.Println("Stopped informer") diff --git a/pkg/tfoapiclient/client.go b/pkg/tfoapiclient/client.go index 228797e..d978d5b 100644 --- a/pkg/tfoapiclient/client.go +++ b/pkg/tfoapiclient/client.go @@ -224,6 +224,14 @@ func (c ClusterClient) SyncDependencies() crudResource { return newCRUDResource(c.Clientset, fmt.Sprintf("%s/api/v1/cluster/%s/sync-dependencies", c.config.Host, c.clientName)) } +func (c ClusterClient) Health() crudResource { + return newCRUDResource(c.Clientset, fmt.Sprintf("%s/api/v1/cluster/%s/health", c.config.Host, c.clientName)) +} + +func (c ClusterClient) TFOHealth() crudResource { + return newCRUDResource(c.Clientset, fmt.Sprintf("%s/api/v1/cluster/%s/tfohealth", c.config.Host, c.clientName)) +} + func newCRUDResource(c Clientset, url string) crudResource { return crudResource{Clientset: c, url: url} }