Skip to content

Conversation

@nerdeveloper
Copy link
Contributor

@nerdeveloper nerdeveloper commented Aug 23, 2025

Description

This PR fixes an issue where make install fails on freshly initialized Kubebuilder projects that have no APIs created yet. The
scaffolded Makefile now gracefully handles missing CRD directories.

Motivation

When users run kubebuilder init without creating any APIs, the config/crd directory doesn't exist. This causes make install to fail with: Error: must build at directory: not a valid directory: evalsymlink failure on 'config/crd' : lstat .../config/crd: no such file or directory

This breaks the basic e2e tests and GitHub Actions workflows for projects in their initial state.

Changes

  1. Updated Makefile template (pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go):

    • Modified install target to check if CRDs exist before attempting to install
    • Modified uninstall target with the same graceful handling
    • Both targets now output "No CRDs to install/delete; skipping" when no CRDs exist
  2. Added e2e test validation (.github/workflows/test-e2e-samples.yml):

Testing

  • Built kubebuilder locally with the changes
  • Created test project without APIs
  • Verified make install now outputs "No CRDs to install; skipping" instead of failing
  • Confirmed make uninstall works similarly

Motivation

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 23, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @nerdeveloper. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 23, 2025
@h0tbird
Copy link
Contributor

h0tbird commented Aug 24, 2025

Coincidentally, I came across this today as well. I did the following:

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
	@[ -d "$(CRD_DIR)" ] && $(KUSTOMIZE) build "$(CRD_DIR)" | $(KUBECTL) apply -f - || { \
		echo "No CRDs found in $(CRD_DIR) (skipping install)"; \
	}

.PHONY: uninstall
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.
	@[ -d "$(CRD_DIR)" ] && $(KUSTOMIZE) build "$(CRD_DIR)" | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f - || { \
		echo "No CRDs found in $(CRD_DIR) (skipping uninstall)"; \
	}

*.log
# If you use vendor, remove this ignore or whitelist it instead
vendor/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some problems here. For example:

So, we need to think in a solution that will be valid for all scenarios
Will not add files that should not be added
and is easier to keep maintained as generic enough

Copy link
Member

@camilamacedo86 camilamacedo86 Aug 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One option might keep the default scaffold with:

# Copy the go source
COPY cmd/main.go cmd/main.go

AND just add

COPY api/ api/

when we create an API

AS

COPY internal/ internal/

When we create an webhook or controller

We will need to analyse all options properly and get the best approach
We must be very very careful with ANY change that impact end users in the default scaffolds.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See: #5047

cd testdata/project-v4-multigroup
go mod tidy
- name: Testing make test-e2e for project-v4-multigroup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please rebase this PR on the master branch?
And then ensure that we have only 1 commit for the required changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

!go.mod
!go.sum
# Ignore build and test binaries.
bin/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should not be changed
Can you please revert and ensure that the PR has only the required changes?

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should not be changed
Can you please revert and ensure that the PR has only the required changes?

@nerdeveloper nerdeveloper force-pushed the fix/make-install-no-crd branch 2 times, most recently from f3edcf5 to 1aa7af6 Compare September 7, 2025 20:37
- 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
@nerdeveloper nerdeveloper force-pushed the fix/make-install-no-crd branch from 1aa7af6 to 03fddac Compare September 8, 2025 20:13
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 8, 2025
@camilamacedo86 camilamacedo86 changed the title bug: Handle empty CRD directories in Makefile install/uninstall targets 🐛 (go/v4) Handle empty CRD directories in Makefile install/uninstall targets Sep 13, 2025
@camilamacedo86
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 13, 2025
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 13, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86, nerdeveloper

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 13, 2025
@k8s-ci-robot k8s-ci-robot merged commit 3fd0419 into kubernetes-sigs:master Sep 14, 2025
96 of 107 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

4 participants