Code generation plays a growing role in software engineering, a trend now strengthened by the rise of generative artificial intelligence. According to the GitHub Octoverse 2026 report, more than 40% of Pull Requests were started with an agent in September 2026, compared with 17% six months earlier. This change shows us the growing importance of automation in development practices.
A factory driven by contracts
In this context, the ability to produce code is no longer the main challenge on its own. The focus is shifting towards defining expected behaviour, writing clear contracts and checking that they are followed. Spec-Driven Development approaches reflect this change by placing specifications at the heart of the generation process.
In our architectures, we increasingly find ourselves defining contracts and generating code from them. Whether these are OpenAPI clients, Protocol Buffers definitions or types linked to Kubernetes resources, many projects now rely on artefacts produced automatically from these contracts. None of this is new, it is simply becoming hard to treat as optional, and the tools to do it are fairly mature.
To give a bit of context, I am working on setting up a software factory where I expose contracts for custom operators such as NexusWorkspace and HarborWorkspace. They define the declarative interface between the Kubernetes platform, the projects and the operators that manage Nexus and Harbor (and the same applies to the other components of the factory).
The idea is that a platform admin can declare a simple Kubernetes custom resource (CR) to manage a project workspace, while benefiting from the Kubernetes reconciliation loop: S3 quotas per project tenant, a choice of hosted or proxy type for Nexus repos, artefact types, the number of repos allowed per workspace…
The diagram below shows how this works:
- We have a code repo,
/project-manager, hosted on Forgejo, which lets us keep our workspace definitions in version control in files such asworkspaceA.yaml,workspaceB.yaml… - Argo CD watches the
/project-managerrepo, fetches the related Helm charts and automatically synchronises the cluster state with the configuration declared in Git. - Once Argo CD has deployed the resources, the Kubernetes operator’s controller constantly compares the desired state declared in the resources with the actual state and acts to correct any differences.
- To act, the controller fetches credentials from the vault with the right level of permissions.
- The controller makes API calls to third-party solutions in the factory, such as Nexus, to reconcile their actual state with the desired state. During the build process, we also check the compatibility of the Nexus API contract to detect possible breaking changes early, using solutions such as openapi-changes.

From specifications to CRDs
Until then, I had not had any problems compiling my Kubernetes operators written in Go. The development of these operators relies on tools such as OpenAPI, CRD2Go and yq. I wanted to keep a contract-first approach, as I do when defining my RESTful APIs, where part of the code is generated automatically from contracts kept in version control in Git.
I build my contracts in three layers:
specs/operator/openapi.yamldefines the fields, types, validations and constraints that describe the structure and declarative business rules.specs/operator/*.envelope.yamlidentifies the group, version, kind, scope and status subresource attributes that describe how this structure becomes a Kubernetes resource.config/crd/*.generated.yaml, produced bymake generate, generates the CRD to install on the cluster. It represents the contract used by the Kubernetes API, linked to the Go controller that implements the behaviour defined by that contract.
In practice, an administrator can configure a project workspace on Nexus by working only with a YAML file like this one. The operator hides the underlying complexity:
apiVersion: nexus.gluendo.internal/v1alpha1
kind: NexusWorkspace
metadata:
name: gluendo
spec:
projectRef:
name: gluendo
repositoryPolicy:
allowedFormats:
- maven2
- npm
allowedTypes:
- hosted
maxRepositories: 5
Using Renovate
A little later in our workflow, we introduced Renovate.
A quick word about Renovate: we use it to detect new versions of the libraries, frameworks and other software components used in our projects. The tool automatically proposes updates through Pull Requests, following configurable rules, and integrates with CI/CD pipelines to check compatibility. This helps us reduce manual work, keep dependencies from becoming outdated and make security patches easier to apply. Renovate is an important part of our factory, whose smooth running depends on its ability to analyse project dependencies correctly.
But I ended up with some Pull Requests that caused CI failures, even though the projects had compiled correctly before.
Diagnosing the CI failures
When I looked into the problem, I found that Renovate was trying to resolve Go dependencies before some generated packages were available.
In Go, go.mod defines the dependencies required by the project, and go.sum records cryptographic hashes used to check the integrity of downloaded modules.
In the workflow in question, Renovate ran the go get -t ./... command to update go.sum after changing go.mod. The problem is that this command fails when it cannot find the local packages, because go generate has not yet been run.
As a result, go.sum is not updated. The Pull Request created by Renovate only contains the changes to go.mod.
An example of a CI error:
missing go.sum entry for module providing package
golang.org/x/net/html/charset
(imported by github.com/mikefarah/yq/v4/pkg/yqlib)
While searching online, I came across a discussion describing exactly this problem: Renovate #35144: How to use Renovate on Go modules with generated files in the project?.
Why I was not keeping generated code in version control
I had assumed that generated artefacts should not be kept in version control in Git, for several reasons.
The first was that I wanted to keep the spec as the single source of truth. To me, the OpenAPI contracts and Kubernetes resource definitions were the references from which the code should be rebuilt. I saw keeping derived artefacts in version control as a risk of the two representations falling out of sync. How could we make sure that a developer had regenerated the files after each change to the contracts?
I also wanted to limit noise in the Git history. Generated code can involve a large number of files and changes, without necessarily adding useful information to a code review, making the diffs noisier to read.
Then, perhaps naively, I felt that generation should be the responsibility of the build pipeline, rather than runs tied to local environments. By always including this step in the build, I wanted to make sure that the artefacts would be produced from the contracts kept in version control, using tools with controlled versions.
This choice seemed more consistent with the nature of our Kubernetes operators, which are distributed as OCI images rather than Go libraries meant to be imported directly.
But what I had not expected was that generated code creates a dependency between the generation phase and the tools that use the dependency graph. Unless this order of execution is clearly defined, the compilation pipeline can work but fail when automation tools such as Renovate are used.
My operators use dependencies that are only referenced in the generated code, such as github.com/oapi-codegen/runtime. I end up with a difference between the source code in Git and the compiled software: their dependency graphs are not the same.
This problem led me to ask: who should make sure that the generated code is available?
The trade-offs I identified
When thinking about design, we often have to think in terms of trade-offs. I explored several strategies to keep dependencies consistent between the source code and the generated code. The first and most obvious option was to keep the generated files in version control alongside the source code in Git. This would have made the packages and their imports available straight away, so they would not have blocked tools such as Renovate.
However, doing this brings back the drawbacks I described earlier: increasing the size of the code repo and making some changes harder to read, while introducing a risk of the source contracts and generated files falling out of sync if a developer pushes a contract change without the matching regenerated file. We can still reduce this risk with a CI check that regenerates the files and checks that there are no differences from the committed versions.
Another approach was to leave generated code out of version control while explicitly declaring the dependencies it introduces. In Go, this can be done with blank imports, which let us reference a package without directly using its features. These imports make the required modules visible to go mod tidy, even when the generated code is absent. They can also be kept behind a build tag so that they are not included in the project’s standard builds.
This solution fits with how I thought dependencies should be managed, but it means maintaining these declarations as the imports in the generated code change. It also does not replace the generated local packages that the rest of the code imports: their absence can still cause go get -t ./... to fail. So it seems neither very satisfactory nor easy to scale, as it means separately maintaining dependencies that are normally explicit in the generated code.
Practices in the Go community
Looking into it, there is no universal agreement on keeping generated code in version control, even though some long-standing recommendations from the Go community are very clear. In his article Generating code, Rob Pike, co-creator of Go, explains that go generate is deliberately separate from go build and recommends keeping generated code in version control when a package is meant to be used by other projects. This position rests on a simple principle: generation is the responsibility of the package provider, rather than its consumers.
I found this practice in Kubernetes, which keeps some of its generated code in version control and automatically checks that it is consistent with the sources. Its hack/verify-codegen.sh script checks that the generated files still match what the generators produce.
The solution
I finally solved the problems I had with Renovate by keeping the generated code in version control and adding a safeguard in CI with a script similar to verify-codegen.sh. With this solution, I can check that the contracts and the generated code are consistent, while making sure that the packages and their dependencies are available to third-party tools as soon as the repo is checked out.