Skip to content

Conversation

nerdeveloper
Copy link

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

Fixes #5033
Addresses Scenario 1 from #4977

@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
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: nerdeveloper
Once this PR has been reviewed and has the lgtm label, please assign varshaprasad96 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 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

@@ -120,4 +120,44 @@ jobs:
- 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
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?


# Build
# the GOARCH has no default value to allow the binary to be built according to the host where the command
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scaffold bug: make install fails on fresh no-API project, breaking basic e2e
4 participants