Skip to content

Commit

Permalink
do a vcluster health check before starting informer
Browse files Browse the repository at this point in the history
  • Loading branch information
isaaguilar committed Jul 18, 2023
1 parent 04bdc2e commit c05f166
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/tfhandler/tfhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions pkg/tfoapiclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down

0 comments on commit c05f166

Please sign in to comment.