Skip to content

Commit

Permalink
GetCluster should take a context
Browse files Browse the repository at this point in the history
Signed-off-by: Vince Prignano <vincepri@redhat.com>
  • Loading branch information
vincepri committed Feb 28, 2023
1 parent 6cf984c commit e29fcad
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/fleet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func main() {
func(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx)

cluster, err := mgr.GetCluster(req.Cluster)
cluster, err := mgr.GetCluster(ctx, req.Cluster)
if err != nil {
return reconcile.Result{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ var _ = Describe("application", func() {
},
},
}
cluster1, err := mgr.GetCluster("cluster1")
cluster1, err := mgr.GetCluster(ctx, "cluster1")
Expect(err).NotTo(HaveOccurred())
Expect(cluster1.GetClient().Create(ctx, dep)).To(Succeed())

Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
)

// LogicalGetterFunc is a function that returns a cluster for a given logical cluster name.
type LogicalGetterFunc func(logical.Name) (Cluster, error)
type LogicalGetterFunc func(context.Context, logical.Name) (Cluster, error)

// Cluster provides various methods to interact with a cluster.
type Cluster interface {
Expand Down
5 changes: 3 additions & 2 deletions pkg/manager/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ func (cm *controllerManager) AddReadyzCheck(name string, check healthz.Checker)
return nil
}

func (cm *controllerManager) GetCluster(name logical.Name) (cluster.Cluster, error) {
return cm.getLogicalCluster(context.TODO(), name)
func (cm *controllerManager) GetCluster(ctx context.Context, name logical.Name) (cluster.Cluster, error) {
return cm.getLogicalCluster(ctx, name)
}

func (cm *controllerManager) GetHTTPClient() *http.Client {
Expand Down Expand Up @@ -365,6 +365,7 @@ func (cm *controllerManager) getLogicalCluster(ctx context.Context, name logical
// Create a new cluster.
var cfg *rest.Config
{
// TODO(vincepri): Make this timeout configurable.
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
var watchErr error
Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type Manager interface {
Start(ctx context.Context) error

// GetCluster retrieves a Cluster from a given logical name.
GetCluster(logical.Name) (cluster.Cluster, error)
GetCluster(context.Context, logical.Name) (cluster.Cluster, error)

// GetWebhookServer returns a webhook.Server
GetWebhookServer() *webhook.Server
Expand Down

0 comments on commit e29fcad

Please sign in to comment.