Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3fd0419

Browse files
authored
Merge pull request #5042 from nerdeveloper/fix/make-install-no-crd
πŸ› (go/v4) Handle empty CRD directories in Makefile install/uninstall targets
2 parents c9018ef + 03fddac commit 3fd0419

File tree

8 files changed

+69
-15
lines changed

8 files changed

+69
-15
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,13 @@ endif
158158

159159
.PHONY: install
160160
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
161-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
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
164165
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 -
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ endif
154154

155155
.PHONY: install
156156
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
157-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
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
160161
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 -
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,13 @@ endif
158158

159159
.PHONY: install
160160
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
161-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
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
164165
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 -
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,13 @@ endif
233233
234234
.PHONY: install
235235
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
236-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
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
239240
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 -
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ endif
154154

155155
.PHONY: install
156156
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
157-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
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
160161
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 -
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ endif
154154

155155
.PHONY: install
156156
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
157-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
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
160161
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 -
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ endif
154154

155155
.PHONY: install
156156
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
157-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
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
160161
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 -
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)