diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 80c2cd3689..edb3fc6762 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -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: diff --git a/Makefile b/Makefile index e7e167d10b..71ec644de0 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/examples/fleet/main.go b/examples/fleet/main.go index 6b16639867..2eb0303d08 100644 --- a/examples/fleet/main.go +++ b/examples/fleet/main.go @@ -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 } diff --git a/hack/test-all.sh b/hack/test-all.sh index 8485da08f4..34d841cfd0 100755 --- a/hack/test-all.sh +++ b/hack/test-all.sh @@ -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} diff --git a/pkg/builder/controller_test.go b/pkg/builder/controller_test.go index b84ede92e9..9676da0a0c 100644 --- a/pkg/builder/controller_test.go +++ b/pkg/builder/controller_test.go @@ -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()) diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index ca29da9f5f..7577e02980 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -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 { diff --git a/pkg/manager/internal.go b/pkg/manager/internal.go index 15782c65c6..8bc0df5938 100644 --- a/pkg/manager/internal.go +++ b/pkg/manager/internal.go @@ -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 { @@ -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 { diff --git a/pkg/manager/manager.go b/pkg/manager/manager.go index 492d5d9173..6b36a7dded 100644 --- a/pkg/manager/manager.go +++ b/pkg/manager/manager.go @@ -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