Skip to content

Commit f3edcf5

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 f3edcf5

File tree

15 files changed

+90
-35
lines changed

15 files changed

+90
-35
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/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN go mod download
1515
COPY . .
1616

1717
# Build
18-
# the GOARCH has no default value to allow the binary to be built according to the host where the command
18+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
1919
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2020
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2121
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.

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/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN go mod download
1515
COPY . .
1616

1717
# Build
18-
# the GOARCH has no default value to allow the binary to be built according to the host where the command
18+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
1919
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2020
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2121
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.

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/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN go mod download
1515
COPY . .
1616

1717
# Build
18-
# the GOARCH has no default value to allow the binary to be built according to the host where the command
18+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
1919
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2020
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2121
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.

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/dockerfile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
23
Copyright 2022 The Kubernetes Authors.
34
45
Licensed under the Apache License, Version 2.0 (the "License");

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/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN go mod download
1515
COPY . .
1616

1717
# Build
18-
# the GOARCH has no default value to allow the binary to be built according to the host where the command
18+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
1919
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2020
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2121
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.

0 commit comments

Comments
 (0)