Skip to content

Commit 6d43456

Browse files
authored
Merge branch 'kubernetes-sigs:master' into master
2 parents 1cc251e + 3f4d5f4 commit 6d43456

File tree

13 files changed

+129
-17
lines changed

13 files changed

+129
-17
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Test Alpha Generate
2+
3+
on:
4+
push:
5+
paths:
6+
- 'pkg/cli/alpha/**'
7+
- '.github/workflows/test-alpha-generate.yml'
8+
pull_request:
9+
paths:
10+
- 'pkg/cli/alpha/**'
11+
- '.github/workflows/test-alpha-generate.yml'
12+
13+
jobs:
14+
unsupported:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: true
18+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version-file: go.mod
27+
28+
- name: Install dependencies and generate binary
29+
run: make install
30+
31+
- name: Navigate to testdata/project-v4
32+
run: cd testdata/project-v4
33+
34+
- name: Update PROJECT file
35+
run: |
36+
sed -i 's#go.kubebuilder.io/v4#go.kubebuilder.io/v3#g' testdata/project-v4/PROJECT
37+
38+
- name: Run kubebuilder alpha generate
39+
run: |
40+
cd testdata/project-v4 && kubebuilder alpha generate

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
7171
# - CERT_MANAGER_INSTALL_SKIP=true
7272
.PHONY: test-e2e
7373
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
74-
@command -v kind >/dev/null 2>&1 || { \
74+
@command -v $(KIND) >/dev/null 2>&1 || { \
7575
echo "Kind is not installed. Please install Kind manually."; \
7676
exit 1; \
7777
}
78-
@kind get clusters | grep -q 'kind' || { \
78+
@$(KIND) get clusters | grep -q 'kind' || { \
7979
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
8080
exit 1; \
8181
}
@@ -169,6 +169,7 @@ $(LOCALBIN):
169169

170170
## Tool Binaries
171171
KUBECTL ?= kubectl
172+
KIND ?= kind
172173
KUSTOMIZE ?= $(LOCALBIN)/kustomize
173174
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
174175
ENVTEST ?= $(LOCALBIN)/setup-envtest

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
6767
# - CERT_MANAGER_INSTALL_SKIP=true
6868
.PHONY: test-e2e
6969
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
70-
@command -v kind >/dev/null 2>&1 || { \
70+
@command -v $(KIND) >/dev/null 2>&1 || { \
7171
echo "Kind is not installed. Please install Kind manually."; \
7272
exit 1; \
7373
}
74-
@kind get clusters | grep -q 'kind' || { \
74+
@$(KIND) get clusters | grep -q 'kind' || { \
7575
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
7676
exit 1; \
7777
}
@@ -165,6 +165,7 @@ $(LOCALBIN):
165165

166166
## Tool Binaries
167167
KUBECTL ?= kubectl
168+
KIND ?= kind
168169
KUSTOMIZE ?= $(LOCALBIN)/kustomize
169170
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
170171
ENVTEST ?= $(LOCALBIN)/setup-envtest

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
7171
# - CERT_MANAGER_INSTALL_SKIP=true
7272
.PHONY: test-e2e
7373
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
74-
@command -v kind >/dev/null 2>&1 || { \
74+
@command -v $(KIND) >/dev/null 2>&1 || { \
7575
echo "Kind is not installed. Please install Kind manually."; \
7676
exit 1; \
7777
}
78-
@kind get clusters | grep -q 'kind' || { \
78+
@$(KIND) get clusters | grep -q 'kind' || { \
7979
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
8080
exit 1; \
8181
}
@@ -169,6 +169,7 @@ $(LOCALBIN):
169169

170170
## Tool Binaries
171171
KUBECTL ?= kubectl
172+
KIND ?= kind
172173
KUSTOMIZE ?= $(LOCALBIN)/kustomize
173174
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
174175
ENVTEST ?= $(LOCALBIN)/setup-envtest

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/onsi/ginkgo/v2 v2.23.0
1010
github.com/onsi/gomega v1.36.2
1111
github.com/sirupsen/logrus v1.9.3
12-
github.com/spf13/afero v1.12.0
12+
github.com/spf13/afero v1.14.0
1313
github.com/spf13/cobra v1.9.1
1414
github.com/spf13/pflag v1.0.6
1515
golang.org/x/text v0.23.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99
3838
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
3939
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
4040
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
41-
github.com/spf13/afero v1.12.0 h1:UcOPyRBYczmFn6yvphxkn9ZEOY65cpwGKb5mL36mrqs=
42-
github.com/spf13/afero v1.12.0/go.mod h1:ZTlWwG4/ahT8W7T0WQ5uYmjI9duaLQGy3Q2OAl4sk/4=
41+
github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA=
42+
github.com/spf13/afero v1.14.0/go.mod h1:acJQ8t0ohCGuMN3O+Pv0V0hgMxNYDlvdk+VTfyZmbYo=
4343
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
4444
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
4545
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=

pkg/cli/alpha/internal/generate.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,24 @@ func getInputPath(inputPath string) (string, error) {
256256
func getInitArgs(store store.Store) []string {
257257
var args []string
258258
plugins := store.Config().GetPluginChain()
259+
260+
// Define outdated plugin versions that need replacement
261+
outdatedPlugins := map[string]string{
262+
"go.kubebuilder.io/v3": "go.kubebuilder.io/v4",
263+
"go.kubebuilder.io/v3-alpha": "go.kubebuilder.io/v4",
264+
"go.kubebuilder.io/v2": "go.kubebuilder.io/v4",
265+
}
266+
267+
// Replace outdated plugins and exit after the first replacement
268+
for i, plugin := range plugins {
269+
if newPlugin, exists := outdatedPlugins[plugin]; exists {
270+
log.Warnf("We checked that your PROJECT file is configured with the layout '%s', which is no longer supported.\n"+
271+
"However, we will try our best to re-generate the project using '%s'.", plugin, newPlugin)
272+
plugins[i] = newPlugin
273+
break
274+
}
275+
}
276+
259277
if len(plugins) > 0 {
260278
args = append(args, "--plugins", strings.Join(plugins, ","))
261279
}

pkg/cli/cli.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ func (c *CLI) buildCmd() error {
147147

148148
var uve config.UnsupportedVersionError
149149

150+
// Workaround for kubebuilder alpha generate
151+
if len(os.Args) > 2 && os.Args[1] == "alpha" && os.Args[2] == "generate" {
152+
err := updateProjectFileForAlphaGenerate()
153+
if err != nil {
154+
return fmt.Errorf("failed to update PROJECT file: %w", err)
155+
}
156+
}
157+
150158
// Get project version and plugin keys.
151159
switch err := c.getInfo(); {
152160
case err == nil:

pkg/cli/cmd_helpers.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import (
2020
"errors"
2121
"fmt"
2222
"os"
23+
"strings"
2324

25+
log "github.com/sirupsen/logrus"
2426
"github.com/spf13/cobra"
2527

2628
"sigs.k8s.io/kubebuilder/v4/pkg/config"
@@ -336,3 +338,40 @@ func (factory *executionHooksFactory) postRunEFunc() func(*cobra.Command, []stri
336338
return nil
337339
}
338340
}
341+
342+
func updateProjectFileForAlphaGenerate() error {
343+
projectFilePath := "PROJECT"
344+
345+
content, err := os.ReadFile(projectFilePath)
346+
if err != nil {
347+
return fmt.Errorf("failed to read PROJECT file: %w", err)
348+
}
349+
350+
projectStr := string(content)
351+
352+
// Define outdated plugin versions that need replacement
353+
outdatedPlugins := []string{"go.kubebuilder.io/v3", "go.kubebuilder.io/v3-alpha", "go.kubebuilder.io/v2"}
354+
updated := false
355+
356+
for _, oldPlugin := range outdatedPlugins {
357+
if strings.Contains(projectStr, oldPlugin) {
358+
log.Warnf("Detected '%s' in PROJECT file.", oldPlugin)
359+
log.Warnf("Kubebuilder v4 no longer supports this. It will be replaced with 'go.kubebuilder.io/v4'.")
360+
361+
projectStr = strings.ReplaceAll(projectStr, oldPlugin, "go.kubebuilder.io/v4")
362+
updated = true
363+
break
364+
}
365+
}
366+
367+
// Only update the file if changes were made
368+
if updated {
369+
err = os.WriteFile(projectFilePath, []byte(projectStr), 0644)
370+
if err != nil {
371+
return fmt.Errorf("failed to update PROJECT file: %w", err)
372+
}
373+
log.Infof("PROJECT file updated successfully.")
374+
}
375+
376+
return nil
377+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
146146
# - CERT_MANAGER_INSTALL_SKIP=true
147147
.PHONY: test-e2e
148148
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
149-
@command -v kind >/dev/null 2>&1 || { \
149+
@command -v $(KIND) >/dev/null 2>&1 || { \
150150
echo "Kind is not installed. Please install Kind manually."; \
151151
exit 1; \
152152
}
153-
@kind get clusters | grep -q 'kind' || { \
153+
@$(KIND) get clusters | grep -q 'kind' || { \
154154
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
155155
exit 1; \
156156
}
@@ -244,6 +244,7 @@ $(LOCALBIN):
244244
245245
## Tool Binaries
246246
KUBECTL ?= kubectl
247+
KIND ?= kind
247248
KUSTOMIZE ?= $(LOCALBIN)/kustomize
248249
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
249250
ENVTEST ?= $(LOCALBIN)/setup-envtest

0 commit comments

Comments
 (0)