Skip to content

Conversation

@Joibel
Copy link
Member

@Joibel Joibel commented Feb 6, 2026

Fixes #13620

Motivation

The k8s.io code-generator tool needs to be upgraded to v0.33.1 to resolve compatibility issues with newer Kubernetes API versions and to fix issues with the module cache handling during code generation.

Modifications

  • Makefile:
    • Upgraded go-to-protobuf from v0.21.5 to v0.33.1
    • Added logic to handle v3 symlink removal before vendoring to prevent Go module confusion
    • Updated protoc perl regex to avoid double-prefixing v3 paths
    • Enhanced pkg/apis/workflow/v1alpha1/generated.proto target with:
      • Module cache write permissions for k8s.io packages
      • Symlink setup for proto imports
      • Verification checks for generated files
      • Module cache cleanup and re-download after generation
    • Updated pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go target to:
      • Use kube_codegen.sh from v0.33.1 instead of deprecated generate-groups.sh
      • Implement proper k8s.io module cache management
      • Use new code generation API with proper helper and client generation

Yes, it's a pretty horrific change.

It deliberately avoids updating nix at this stage, as @isubasinghe was working on a separate patch for that.

Verification

  • Code generation targets now properly handle k8s.io module cache permissions and cleanup
  • Generated files are verified to contain expected methods before proceeding
  • Module cache is restored to clean state after generation to prevent corruption
  • Nix flake configuration updated to match Makefile version

Documentation

No documentation changes needed - this is an internal tooling upgrade.

Summary by CodeRabbit

Release Notes

  • Chores
    • Upgraded code generation tooling and enhanced build infrastructure for improved code quality
    • Modernized client library generation to use generic implementations for better maintainability
    • Enhanced HTTP client configuration in API clients for improved flexibility
    • Refactored informers and listers to support context-aware operations

@Joibel Joibel requested a review from terrytangyuan as a code owner February 6, 2026 11:37
@Joibel Joibel marked this pull request as draft February 6, 2026 11:37
go-to-protobuf v0.33.1 uses full module paths for proto source paths, requiring
--output-dir to route generated .pb.go files to the correct locations.

The tool also writes temporary .proto files to and cleans them from package
directories. Since `go list` returns module cache paths regardless of any local
copies, we must make the module cache writable, then re-download the corrupted
k8s.io modules after generation completes.

The approach:
1. chmod module cache writable for k8s.io packages
2. Copy k8s.io to GOPATH/src for --proto-import (protoc finds .proto files)
3. Symlink argo-workflows in GOPATH/src so --output-dir routes .pb.go to project
4. Re-download k8s.io modules after, since go-to-protobuf deletes files from them

Signed-off-by: Alan Clucas <[email protected]>

https://claude.ai/code/session_01DtkvsHyL9aY9mR78yDti3Y
@Joibel Joibel force-pushed the claude/upgrade-protobuf-makefile-q7f9h branch from 67b95a0 to fc87c1f Compare February 6, 2026 13:17
Signed-off-by: Alan Clucas <[email protected]>
@Joibel Joibel marked this pull request as ready for review February 6, 2026 15:18
@Joibel Joibel requested a review from blkperl February 6, 2026 15:18
@Joibel
Copy link
Member Author

Joibel commented Feb 6, 2026

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 6, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

Updates the code-generation workflow from v0.21.5 to v0.33.1 by modifying the Makefile with expanded proto generation steps, proto package paths, and generic typed client implementations across the clientset, informers, and listers packages. Systematically replaces REST-based clients with generic client wrappers and refactors lister implementations to use generic ResourceIndexer patterns.

Changes

Cohort / File(s) Summary
Makefile and Build Configuration
Makefile
Upgrades go-to-protobuf tool from v0.21.5 to v0.33.1; expands proto generation target with explicit GOPATH handling, k8s.io module setup, symlink management, and new code-generator invocation patterns; reworks openapi/deepcopy code generation using kube_codegen.sh from code-generator v0.33.1.
Proto Definitions
pkg/apis/workflow/v1alpha1/generated.proto
Updates go_package option to full module path; systematically changes all Kubernetes type references from k8s.io.* prefix to .k8s.io.* (local namespace prefix) across numerous message field type declarations; affects Workflow, Template, CronWorkflow, and related messages.
Clientset Core
pkg/client/clientset/versioned/clientset.go, pkg/client/clientset/versioned/doc.go
Introduces HTTP client integration with NewForConfigAndClient constructor; removes deleted doc.go file.
Clientset REST-to-Generic Refactoring
pkg/client/clientset/versioned/typed/workflow/v1alpha1/clusterworkflowtemplate.go, pkg/client/clientset/versioned/typed/workflow/v1alpha1/cronworkflow.go, pkg/client/clientset/versioned/typed/workflow/v1alpha1/workflow.go, pkg/client/clientset/versioned/typed/workflow/v1alpha1/workflowartifactgctask.go, pkg/client/clientset/versioned/typed/workflow/v1alpha1/workfloweventbinding.go, pkg/client/clientset/versioned/typed/workflow/v1alpha1/workflowtaskresult.go, pkg/client/clientset/versioned/typed/workflow/v1alpha1/workflowtaskset.go, pkg/client/clientset/versioned/typed/workflow/v1alpha1/workflowtemplate.go
Replaces direct REST client usage with generic typed clients (gentype.ClientWithList); updates all interface method signatures to use workflowv1alpha1 type aliases; removes explicit CRUD method implementations in favor of generic client behavior.
Clientset HTTP Support
pkg/client/clientset/versioned/typed/workflow/v1alpha1/workflow_client.go
Adds NewForConfigAndClient with HTTP client support; refactors setConfigDefaults and default config setup; updates default GroupVersion and NegotiatedSerializer wiring.
Fake Client REST-to-Generic Refactoring
pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_clusterworkflowtemplate.go, pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_cronworkflow.go, pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflow.go, pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflowartifactgctask.go, pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workfloweventbinding.go, pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflowtaskresult.go, pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflowtaskset.go, pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflowtemplate.go
Replaces exported Fake* types with unexported implementations backed by gentype.FakeClientWithList; introduces constructor functions returning public interface types; removes explicit per-method CRUD implementations.
Fake Client Factory
pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflow_client.go
Updates method initializations to use new constructor functions instead of struct literals for fake client instantiation.
Informer Factory Enhancement
pkg/client/informers/externalversions/factory.go
Adds transform hook support (WithTransform option), shutdown mechanism (Shutdown method), and improved cancellation safety with WaitGroup tracking for started informer goroutines.
Informer Generic Support
pkg/client/informers/externalversions/generic.go
Minor import alias formatting change (no functional impact).
Informers REST-to-Generic Refactoring
pkg/client/informers/externalversions/workflow/v1alpha1/clusterworkflowtemplate.go, pkg/client/informers/externalversions/workflow/v1alpha1/cronworkflow.go, pkg/client/informers/externalversions/workflow/v1alpha1/workflow.go, pkg/client/informers/externalversions/workflow/v1alpha1/workflowartifactgctask.go, pkg/client/informers/externalversions/workflow/v1alpha1/workfloweventbinding.go, pkg/client/informers/externalversions/workflow/v1alpha1/workflowtaskresult.go, pkg/client/informers/externalversions/workflow/v1alpha1/workflowtaskset.go, pkg/client/informers/externalversions/workflow/v1alpha1/workflowtemplate.go
Updates Lister interface return types to use workflowv1alpha1 aliases; switches ListWatch to use context.Background() instead of context.TODO(); adds ListWithContextFunc and WatchFuncWithContext for context-aware operations; adjusts informer construction to use apisworkflowv1alpha1 type references.
Listers REST-to-Generic Refactoring
pkg/client/listers/workflow/v1alpha1/clusterworkflowtemplate.go, pkg/client/listers/workflow/v1alpha1/cronworkflow.go, pkg/client/listers/workflow/v1alpha1/workflow.go, pkg/client/listers/workflow/v1alpha1/workflowartifactgctask.go, pkg/client/listers/workflow/v1alpha1/workfloweventbinding.go, pkg/client/listers/workflow/v1alpha1/workflowtaskresult.go, pkg/client/listers/workflow/v1alpha1/workflowtaskset.go, pkg/client/listers/workflow/v1alpha1/workflowtemplate.go
Replaces cache.Indexer fields with generic listers.ResourceIndexer[T]; updates List and Get method signatures to return workflowv1alpha1 types; refactors namespace lister implementations to use listers.NewNamespaced pattern; removes direct k8s cache-based implementations.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Suggested labels

area/contributing

Suggested reviewers

  • isubasinghe
  • MasonM
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 79.07% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'chore: upgrade k8s code-generator to v0.33.1' clearly and concisely summarizes the main change in the PR.
Description check ✅ Passed The PR description includes Fixes reference, clear Motivation, detailed Modifications, Verification steps, and Documentation notes. Follows the template structure well.
Linked Issues check ✅ Passed The PR fully addresses issue #13620 by upgrading go-to-protobuf to v0.33.1 and fixing module cache handling to resolve permission errors during code generation.
Out of Scope Changes check ✅ Passed All changes are directly related to upgrading the code-generator tooling and its integration in the Makefile. Changes to generated files are expected outputs of the upgrade.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

Error: unknown linters: 'modernize', run 'golangci-lint help linters' to see the list of supported linters
The command is terminated due to an error: unknown linters: 'modernize', run 'golangci-lint help linters' to see the list of supported linters


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@Makefile`:
- Around line 480-498: The chmod -R +w on $(shell go env GOMODCACHE)/k8s.io
makes the entire k8s.io cache writable but only [email protected] and
[email protected] are re-downloaded, leaving other modules writable; change
the Makefile so either (A) chmod only the two affected modules (target the paths
used later: $(shell go env GOMODCACHE)/k8s.io/[email protected] and $(shell go env
GOMODCACHE)/k8s.io/[email protected]) before running $(TOOL_GO_TO_PROTOBUF),
or (B) after the cleanup steps (the rm -rf and go mod download lines) run a
chmod to remove write permission from the whole k8s.io tree to restore read-only
state; update the block around the existing chmod -R +w ... and the cleanup
lines so the chosen approach is applied.
- Around line 403-407: Make a tracked TODO in the Makefile next to the
go-to-protobuf upgrade: add a one-line TODO comment near the
$(TOOL_GO_TO_PROTOBUF) / USE_NIX block that references a follow-up issue number
to sync the Nix-pinned code-generator version with this upgrade (e.g., "TODO:
follow-up `#NNN` — update Nix pin for code-generator when bumping go-to-protobuf
to v0.33.1"); ensure it clearly mentions the target $(TOOL_GO_TO_PROTOBUF) and
the USE_NIX conditional so reviewers can find and act on it later.

In `@pkg/client/informers/externalversions/factory.go`:
- Around line 188-209: The doc example incorrectly references
factory.WaitForStop(); update the generated comment to use the actual method
name factory.Shutdown() (and keep surrounding example calls like
NewSharedInformerFactory, ForResource, Start, WaitForCacheSync intact) so the
snippet compiles; since this is a generated file, also file an upstream
informer-gen issue to correct the template that emits WaitForStop().
🧹 Nitpick comments (1)
Makefile (1)

483-484: Hardcoded @v0.33.1 version appears in multiple places — consider extracting a variable.

The version v0.33.1 for k8s.io modules is hardcoded on lines 406, 483, 484, 497, 498, and 779. If the k8s.io dependency version changes, all of these must be updated in lockstep.

Suggested improvement
+# k8s.io code-generator / API module version — keep in sync with go.mod
+K8S_CODEGEN_VERSION := v0.33.1
+
 $(TOOL_GO_TO_PROTOBUF): Makefile
 ifneq ($(USE_NIX), true)
-	go install k8s.io/code-generator/cmd/[email protected]
+	go install k8s.io/code-generator/cmd/go-to-protobuf@$(K8S_CODEGEN_VERSION)
 endif

Then use $(K8S_CODEGEN_VERSION) everywhere @v0.33.1 appears in the codegen targets.

Comment on lines +480 to +498
chmod -R +w $(shell go env GOMODCACHE)/k8s.io 2>/dev/null || true
mkdir -p $(GOPATH)/src/k8s.io
rm -rf $(GOPATH)/src/k8s.io/api $(GOPATH)/src/k8s.io/apimachinery
cp -r $(shell go env GOMODCACHE)/k8s.io/[email protected] $(GOPATH)/src/k8s.io/api
cp -r $(shell go env GOMODCACHE)/k8s.io/[email protected] $(GOPATH)/src/k8s.io/apimachinery
mkdir -p $(GOPATH)/src/github.com/argoproj/argo-workflows
rm -rf $(GOPATH)/src/github.com/argoproj/argo-workflows/v3
ln -s $(CURDIR) $(GOPATH)/src/github.com/argoproj/argo-workflows/v3
$(TOOL_GO_TO_PROTOBUF) \
--go-header-file=./hack/custom-boilerplate.go.txt \
--packages=github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1 \
--apimachinery-packages=+k8s.io/apimachinery/pkg/util/intstr,+k8s.io/apimachinery/pkg/api/resource,k8s.io/apimachinery/pkg/runtime/schema,+k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/api/core/v1,k8s.io/api/policy/v1 \
--proto-import $(GOPATH)/src
# Delete the link
[ -e ./v3 ] && rm -rf v3
--proto-import $(GOPATH)/src \
--output-dir $(GOPATH)/src
# Clean up and restore k8s.io modules that go-to-protobuf corrupted
rm -rf $(GOPATH)/src/k8s.io/api $(GOPATH)/src/k8s.io/apimachinery
rm -rf $(GOPATH)/src/github.com/argoproj/argo-workflows/v3
rm -rf $(shell go env GOMODCACHE)/k8s.io/[email protected] $(shell go env GOMODCACHE)/k8s.io/[email protected]
go mod download k8s.io/[email protected] k8s.io/[email protected]
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

chmod -R +w on all k8s.io modules leaves non-target modules writable after cleanup.

Line 480 makes the entire $(GOMODCACHE)/k8s.io directory tree writable, but lines 497–498 only delete and re-download [email protected] and [email protected]. Other k8s.io modules in the cache (e.g., client-go, kube-openapi, etc.) remain writable, which breaks Go's module cache contract (read-only = verified).

Consider either:

  • Narrowing the chmod to only the two modules that need it, or
  • Restoring read-only permissions on the entire k8s.io tree after generation.
Option A: Narrow the chmod scope
-	chmod -R +w $(shell go env GOMODCACHE)/k8s.io 2>/dev/null || true
+	chmod -R +w $(shell go env GOMODCACHE)/k8s.io/[email protected] 2>/dev/null || true
+	chmod -R +w $(shell go env GOMODCACHE)/k8s.io/[email protected] 2>/dev/null || true
Option B: Restore read-only after cleanup
 	go mod download k8s.io/[email protected] k8s.io/[email protected]
+	chmod -R a-w $(shell go env GOMODCACHE)/k8s.io 2>/dev/null || true
 	rm -rf vendor
🤖 Prompt for AI Agents
In `@Makefile` around lines 480 - 498, The chmod -R +w on $(shell go env
GOMODCACHE)/k8s.io makes the entire k8s.io cache writable but only [email protected]
and [email protected] are re-downloaded, leaving other modules writable;
change the Makefile so either (A) chmod only the two affected modules (target
the paths used later: $(shell go env GOMODCACHE)/k8s.io/[email protected] and $(shell
go env GOMODCACHE)/k8s.io/[email protected]) before running
$(TOOL_GO_TO_PROTOBUF), or (B) after the cleanup steps (the rm -rf and go mod
download lines) run a chmod to remove write permission from the whole k8s.io
tree to restore read-only state; update the block around the existing chmod -R
+w ... and the cleanup lines so the chosen approach is applied.

Comment on lines +188 to +209
//
// It is typically used like this:
//
// ctx, cancel := context.Background()
// defer cancel()
// factory := NewSharedInformerFactory(client, resyncPeriod)
// defer factory.WaitForStop() // Returns immediately if nothing was started.
// genericInformer := factory.ForResource(resource)
// typedInformer := factory.SomeAPIGroup().V1().SomeType()
// factory.Start(ctx.Done()) // Start processing these informers.
// synced := factory.WaitForCacheSync(ctx.Done())
// for v, ok := range synced {
// if !ok {
// fmt.Fprintf(os.Stderr, "caches failed to sync: %v", v)
// return
// }
// }
//
// // Creating informers can also be created after Start, but then
// // Start must be called again:
// anotherGenericInformer := factory.ForResource(resource)
// factory.Start(ctx.Done())
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Minor: generated doc comment references non-existent WaitForStop() method.

Line 194 references factory.WaitForStop() but the actual interface method is Shutdown() (Line 228). This is a documentation bug in the generated code from informer-gen. If someone copies this example, they'll get a compile error.

Since this file is generated (DO NOT EDIT), this can't be fixed here — it would need to be reported upstream to the k8s code-generator.

🤖 Prompt for AI Agents
In `@pkg/client/informers/externalversions/factory.go` around lines 188 - 209, The
doc example incorrectly references factory.WaitForStop(); update the generated
comment to use the actual method name factory.Shutdown() (and keep surrounding
example calls like NewSharedInformerFactory, ForResource, Start,
WaitForCacheSync intact) so the snippet compiles; since this is a generated
file, also file an upstream informer-gen issue to correct the template that
emits WaitForStop().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

go-to-protobuf needs to be updated to the latest version

2 participants