Skip to content

Commit 1aa7af6

Browse files
committed
fix: handle empty CRD directories in Makefile install/uninstall
- Gracefully no-op install/uninstall when no CRDs exist - Update sample Makefiles accordingly and add CI job to validate empty project - Revert Dockerfile and .dockerignore changes; keep templates and samples matching upstream
1 parent 1aa2168 commit 1aa7af6

File tree

8 files changed

+83
-29
lines changed

8 files changed

+83
-29
lines changed

.github/workflows/test-e2e-samples.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,44 @@ jobs:
120120
- name: Testing make test-e2e for project-v4-multigroup
121121
working-directory: testdata/project-v4-multigroup/
122122
run: |
123-
make test-e2e
123+
make test-e2e
124+
125+
# Test to validate e2e integration when no APIs are scaffolded
126+
e2e-test-basic-project:
127+
runs-on: ubuntu-latest
128+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
129+
steps:
130+
- name: Checkout repository
131+
uses: actions/checkout@v5
132+
133+
- name: Setup Go
134+
uses: actions/setup-go@v6
135+
with:
136+
go-version-file: go.mod
137+
138+
- name: Install the latest version of kind
139+
run: |
140+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
141+
chmod +x ./kind
142+
sudo mv ./kind /usr/local/bin/kind
143+
144+
- name: Verify kind installation
145+
run: kind version
146+
147+
- name: Create kind cluster
148+
run: kind create cluster
149+
150+
- name: Build kubebuilder CLI from this repo
151+
run: make install
152+
153+
- name: Scaffold empty go/v4 project
154+
run: |
155+
mkdir -p /tmp/basic-project-v4
156+
cd /tmp/basic-project-v4
157+
kubebuilder init --plugins go/v4 --domain example.com --repo example.com/empty-operator
158+
go mod tidy
159+
make
160+
161+
- name: Run make test-e2e on empty project
162+
working-directory: /tmp/basic-project-v4
163+
run: make test-e2e

docs/book/src/cronjob-tutorial/testdata/project/Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,14 @@ ifndef ignore-not-found
157157
endif
158158

159159
.PHONY: install
160-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
161-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
160+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. No-op if none exist.
161+
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
162+
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) apply -f -; else echo "No CRDs to install; skipping."; fi
162163

163164
.PHONY: uninstall
164-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
165-
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
165+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. No-op if none exist.
166+
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
167+
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -; else echo "No CRDs to delete; skipping."; fi
166168

167169
.PHONY: deploy
168170
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.

docs/book/src/getting-started/testdata/project/Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,14 @@ ifndef ignore-not-found
153153
endif
154154

155155
.PHONY: install
156-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
157-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
156+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. No-op if none exist.
157+
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
158+
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) apply -f -; else echo "No CRDs to install; skipping."; fi
158159

159160
.PHONY: uninstall
160-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
161-
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
161+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. No-op if none exist.
162+
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
163+
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -; else echo "No CRDs to delete; skipping."; fi
162164

163165
.PHONY: deploy
164166
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.

docs/book/src/multiversion-tutorial/testdata/project/Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,14 @@ ifndef ignore-not-found
157157
endif
158158

159159
.PHONY: install
160-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
161-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
160+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. No-op if none exist.
161+
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
162+
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) apply -f -; else echo "No CRDs to install; skipping."; fi
162163

163164
.PHONY: uninstall
164-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
165-
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
165+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. No-op if none exist.
166+
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
167+
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -; else echo "No CRDs to delete; skipping."; fi
166168

167169
.PHONY: deploy
168170
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.

pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,14 @@ ifndef ignore-not-found
232232
endif
233233
234234
.PHONY: install
235-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
236-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
235+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. No-op if none exist.
236+
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
237+
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) apply -f -; else echo "No CRDs to install; skipping."; fi
237238
238239
.PHONY: uninstall
239-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
240-
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
240+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. No-op if none exist.
241+
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
242+
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -; else echo "No CRDs to delete; skipping."; fi
241243
242244
.PHONY: deploy
243245
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.

testdata/project-v4-multigroup/Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,14 @@ ifndef ignore-not-found
153153
endif
154154

155155
.PHONY: install
156-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
157-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
156+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. No-op if none exist.
157+
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
158+
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) apply -f -; else echo "No CRDs to install; skipping."; fi
158159

159160
.PHONY: uninstall
160-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
161-
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
161+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. No-op if none exist.
162+
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
163+
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -; else echo "No CRDs to delete; skipping."; fi
162164

163165
.PHONY: deploy
164166
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.

testdata/project-v4-with-plugins/Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,14 @@ ifndef ignore-not-found
153153
endif
154154

155155
.PHONY: install
156-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
157-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
156+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. No-op if none exist.
157+
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
158+
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) apply -f -; else echo "No CRDs to install; skipping."; fi
158159

159160
.PHONY: uninstall
160-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
161-
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
161+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. No-op if none exist.
162+
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
163+
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -; else echo "No CRDs to delete; skipping."; fi
162164

163165
.PHONY: deploy
164166
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.

testdata/project-v4/Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,14 @@ ifndef ignore-not-found
153153
endif
154154

155155
.PHONY: install
156-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
157-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
156+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. No-op if none exist.
157+
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
158+
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) apply -f -; else echo "No CRDs to install; skipping."; fi
158159

159160
.PHONY: uninstall
160-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
161-
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
161+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. No-op if none exist.
162+
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
163+
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -; else echo "No CRDs to delete; skipping."; fi
162164

163165
.PHONY: deploy
164166
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.

0 commit comments

Comments
 (0)