Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanHoladay committed Sep 9, 2024
1 parent a212c11 commit a09b4ed
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pkg/api/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,28 @@ func Setup(assets *embed.FS) (*chi.Mux, error) {
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)

ctx, cancel := context.WithCancel(context.Background())
k8sClient, err := k8s.NewClient()
if err != nil {
cancel()
return nil, fmt.Errorf("failed to create k8s client: %w", err)
}

ctx, cancel := context.WithCancel(context.Background())
cache, err := resources.NewCache(ctx, k8sClient)
if err != nil {
cancel()
return nil, fmt.Errorf("failed to create cache: %w", err)
}

// Create the disconnected channel
disconnected := make(chan error)

// Create a K8sResources struct to hold the references
// K8sResources struct to hold references
k8sResources := &K8sResources{
Client: k8sClient,
Cache: cache,
Cancel: cancel,
}

// Create the disconnected channel
disconnected := make(chan error)

// Start the reconnection goroutine
go handleReconnection(disconnected, k8sResources, k8s.NewClient, resources.NewCache)

Expand Down Expand Up @@ -342,7 +341,7 @@ func handleReconnection(disconnected chan error, k8sResources *K8sResources, cre
for {
// Cancel the previous context
k8sResources.Cancel()
time.Sleep(getRetryInterval()) // Retry interval
time.Sleep(getRetryInterval())
k8sClient, err := createClient()
if err != nil {
fmt.Printf("Retrying to create k8s client: %v\n", err)
Expand Down

0 comments on commit a09b4ed

Please sign in to comment.