Skip to content

Run development tools rather than install them #4172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# https://editorconfig.org
#
# https://neovim.io/doc/user/editorconfig.html
# https://github.com/editorconfig/editorconfig-emacs
# https://plugins.jetbrains.com/plugin/7294-editorconfig
# https://marketplace.visualstudio.com/items/EditorConfig.EditorConfig

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{go,sh}]
indent_size = tab
indent_style = tab

[*.{md,yml,yaml}]
indent_size = 2
indent_style = space

[Makefile]
indent_style = tab
9 changes: 6 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with: { go-version: stable }
- run: make check
- run: make check-generate

- name: Ensure go.mod is tidy
run: go mod tidy && git diff --exit-code -- go.mod
- name: Ensure generated files are committed
run: make check-generate
- run: make check

kubernetes-api:
runs-on: ubuntu-24.04
Expand All @@ -35,6 +36,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with: { go-version: stable }

- run: go mod download
- run: ENVTEST_K8S_VERSION="${KUBERNETES#default}" make check-envtest
env:
Expand Down Expand Up @@ -163,7 +165,8 @@ jobs:
echo '::group::PGO logs'; docker logs 'postgres-operator'; echo '::endgroup::'
exit $failed
env:
KUTTL_TEST: kubectl-kuttl test
KUTTL: kubectl-kuttl

- name: Stop PGO
run: docker stop 'postgres-operator' || true

Expand Down
40 changes: 14 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ BUILDAH_BUILD ?= buildah bud
GO ?= go
GO_BUILD = $(GO) build
GO_TEST ?= $(GO) test
KUTTL ?= kubectl-kuttl

# Ensure modules imported by `postgres-operator` and `controller-gen` are compatible
# by managing them together in the main module.
CONTROLLER ?= $(GO) tool sigs.k8s.io/controller-tools/cmd/controller-gen

# Run tests using the latest tools.
ENVTEST ?= $(GO) run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
KUTTL ?= $(GO) run github.com/kudobuilder/kuttl/pkg/kuttlctl/cmd/kubectl-kuttl@latest
KUTTL_TEST ?= $(KUTTL) test


##@ General

# The help target prints out all targets with their descriptions organized
Expand Down Expand Up @@ -62,7 +70,6 @@ clean: clean-deprecated
rm -f bin/postgres-operator
rm -rf licenses/*/
[ ! -d testing/kuttl/e2e-generated ] || rm -r testing/kuttl/e2e-generated
[ ! -f hack/tools/setup-envtest ] || rm hack/tools/setup-envtest
[ ! -d hack/tools/envtest ] || { chmod -R u+w hack/tools/envtest && rm -r hack/tools/envtest; }
[ ! -d hack/tools/pgmonitor ] || rm -rf hack/tools/pgmonitor
[ ! -d hack/tools/external-snapshotter ] || rm -rf hack/tools/external-snapshotter
Expand Down Expand Up @@ -90,6 +97,9 @@ clean-deprecated: ## Clean deprecated resources
[ ! -d build/crd ] || rm -r build/crd
@# Old testing directories
[ ! -d testing/kuttl/e2e-generated-other ] || rm -r testing/kuttl/e2e-generated-other
@# Tools used to be downloaded directly
[ ! -f hack/tools/controller-gen ] || rm hack/tools/controller-gen
[ ! -f hack/tools/setup-envtest ] || rm hack/tools/setup-envtest


##@ Deployment
Expand Down Expand Up @@ -199,13 +209,13 @@ check: get-pgmonitor
check-envtest: ## Run check using envtest and a mock kube api
check-envtest: ENVTEST_USE = $(ENVTEST) --bin-dir=$(CURDIR)/hack/tools/envtest use $(ENVTEST_K8S_VERSION)
check-envtest: SHELL = bash
check-envtest: get-pgmonitor tools/setup-envtest
check-envtest: get-pgmonitor
@$(ENVTEST_USE) --print=overview && echo
source <($(ENVTEST_USE) --print=env) && PGO_NAMESPACE="postgres-operator" QUERIES_CONFIG_DIR="$(CURDIR)/${QUERIES_CONFIG_DIR}" \
$(GO_TEST) -count=1 -cover ./...

# The "PGO_TEST_TIMEOUT_SCALE" environment variable (default: 1) can be set to a
# positive number that extends test timeouts. The following runs tests with
# positive number that extends test timeouts. The following runs tests with
# timeouts that are 20% longer than normal:
# make check-envtest-existing PGO_TEST_TIMEOUT_SCALE=1.2
.PHONY: check-envtest-existing
Expand Down Expand Up @@ -270,7 +280,6 @@ generate: generate-rbac

.PHONY: generate-crd
generate-crd: ## Generate Custom Resource Definitions (CRDs)
generate-crd: tools/controller-gen
$(CONTROLLER) \
crd:crdVersions='v1' \
paths='./pkg/apis/...' \
Expand All @@ -282,38 +291,17 @@ generate-collector: ## Generate OTel Collector files

.PHONY: generate-deepcopy
generate-deepcopy: ## Generate DeepCopy functions
generate-deepcopy: tools/controller-gen
$(CONTROLLER) \
object:headerFile='hack/boilerplate.go.txt' \
paths='./pkg/apis/postgres-operator.crunchydata.com/...'

.PHONY: generate-rbac
generate-rbac: ## Generate RBAC
generate-rbac: tools/controller-gen
$(CONTROLLER) \
rbac:roleName='postgres-operator' \
paths='./cmd/...' paths='./internal/...' \
output:dir='config/rbac' # {directory}/role.yaml

##@ Tools

.PHONY: tools
tools: ## Download tools like controller-gen and kustomize if necessary.

# go-get-tool will 'go install' any package $2 and install it to $1.
define go-get-tool
@[ -f '$(1)' ] || { echo Downloading '$(2)'; GOBIN='$(abspath $(dir $(1)))' $(GO) install '$(2)'; }
endef

CONTROLLER ?= hack/tools/controller-gen
tools: tools/controller-gen
tools/controller-gen:
$(call go-get-tool,$(CONTROLLER),sigs.k8s.io/controller-tools/cmd/[email protected])

ENVTEST ?= hack/tools/setup-envtest
tools: tools/setup-envtest
tools/setup-envtest:
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

##@ Release

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.17.2
controller-gen.kubebuilder.io/version: v0.17.3
name: crunchybridgeclusters.postgres-operator.crunchydata.com
spec:
group: postgres-operator.crunchydata.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.17.2
controller-gen.kubebuilder.io/version: v0.17.3
name: pgadmins.postgres-operator.crunchydata.com
spec:
group: postgres-operator.crunchydata.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.17.2
controller-gen.kubebuilder.io/version: v0.17.3
name: pgupgrades.postgres-operator.crunchydata.com
spec:
group: postgres-operator.crunchydata.com
Expand Down
Loading
Loading