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 Mar 1, 2023
1 parent 88a7b48 commit ebfcabf
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ jobs:
- tools/setup-envtest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3.5.0
with:
go-version: "1.19"
check-latest: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ $(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder.
$(GOLANGCI_LINT): .github/workflows/golangci-lint.yml # Download golanci-lint using hack script into tools folder.
hack/ensure-golangci-lint.sh \
-b $(TOOLS_BIN_DIR) \
$(shell cat .github/workflows/golangci-lint.yml | grep version | sed 's/.*version: //')
$(shell cat .github/workflows/golangci-lint.yml | grep "version: v" | sed 's/.*version: //')

## --------------------------------------
## Linting
Expand Down
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 hack/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if [[ -n ${ARTIFACTS:-} ]]; then
fi

result=0
go test -v -race ${P_FLAG} ${MOD_OPT} ./... --ginkgo.fail-fast --ginkgo.v ${GINKGO_ARGS} || result=$?
go test -v -race ${P_FLAG} ${MOD_OPT} ./... --ginkgo.fail-fast ${GINKGO_ARGS} || result=$?

if [[ -n ${ARTIFACTS:-} ]]; then
mkdir -p ${ARTIFACTS}
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
7 changes: 4 additions & 3 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,13 +365,14 @@ 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
if err := wait.PollImmediateUntilWithContext(ctx, 1*time.Second, func(ctx context.Context) (done bool, err error) {
cfg, watchErr = cm.logicalAdapter.RESTConfig(name)
if watchErr != nil {
return false, nil // retry
return false, nil //nolint:nilerr // We want to keep trying.
}
return true, nil
}); err != nil {
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 ebfcabf

Please sign in to comment.