From 6edec72009be801f7f348098c3b0b76fc15b3973 Mon Sep 17 00:00:00 2001 From: Christopher Haar Date: Wed, 18 Nov 2026 14:44:03 +0100 Subject: [PATCH 1/4] Strip the null creationTimestamp when writing project files The zero metadata.creationTimestamp marshals as an explicit null, so every dependency add or composition generate rewrote the project file with a creationTimestamp: null line. Signed-off-by: Christopher Haar --- internal/project/projectfile/projectfile.go | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/internal/project/projectfile/projectfile.go b/internal/project/projectfile/projectfile.go index b79fc5a3..ffd6a7e5 100644 --- a/internal/project/projectfile/projectfile.go +++ b/internal/project/projectfile/projectfile.go @@ -112,5 +112,28 @@ func Update(projFS afero.Fs, projFile string, fn func(*v1alpha1.Project)) error if err != nil { return errors.Wrap(err, "failed to marshal project") } + bs = stripNullCreationTimestamp(bs) return afero.WriteFile(projFS, projFile, bs, 0o644) } + +// stripNullCreationTimestamp removes the explicit null creationTimestamp the +// zero ObjectMeta marshals with, so it doesn't accumulate in project files. +func stripNullCreationTimestamp(bs []byte) []byte { + var doc map[string]any + if err := yaml.Unmarshal(bs, &doc); err != nil { + return bs + } + md, ok := doc["metadata"].(map[string]any) + if !ok { + return bs + } + if ts, exists := md["creationTimestamp"]; !exists || ts != nil { + return bs + } + delete(md, "creationTimestamp") + clean, err := yaml.Marshal(doc) + if err != nil { + return bs + } + return clean +} From 7647cd1ee8ba2c4b672555257d11a6060d030df9 Mon Sep 17 00:00:00 2001 From: Christopher Haar Date: Tue, 17 Nov 2026 15:22:58 +0100 Subject: [PATCH 2/4] Sort generated KCL imports for deterministic output The import statements were built by ranging over a map, so the order of imports in a generated function's main.k varied between runs. Signed-off-by: Christopher Haar --- cmd/crossplane/function/generate.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/crossplane/function/generate.go b/cmd/crossplane/function/generate.go index cb7585a4..1460f753 100644 --- a/cmd/crossplane/function/generate.go +++ b/cmd/crossplane/function/generate.go @@ -292,6 +292,10 @@ func (c *generateCmd) generateKCLFiles(fs afero.Fs) error { Alias: alias, }) } + // Sort for deterministic output; imports is a map. + slices.SortFunc(importStatements, func(a, b kclImportStatement) int { + return strings.Compare(a.ImportPath, b.ImportPath) + }) tmplData := kclTemplateData{ ModName: c.Name, From 48e3c10afa29fbdd8a14d670b9c292086d22289c Mon Sep 17 00:00:00 2001 From: Christopher Haar Date: Tue, 17 Nov 2026 18:14:33 +0100 Subject: [PATCH 3/4] Bump function-kcl base image to v0.12.3 function-kcl v0.12.1 returns duplicate composed resources when the composition function is invoked with observed resources, failing with 'multiple composed resources with name ... returned'. v0.12.3 behaves correctly. Signed-off-by: Christopher Haar --- internal/project/functions/kcl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/project/functions/kcl.go b/internal/project/functions/kcl.go index a6e268b3..5227278f 100644 --- a/internal/project/functions/kcl.go +++ b/internal/project/functions/kcl.go @@ -224,7 +224,7 @@ func setImageEnvvars(image v1.Image, envVars map[string]string) (v1.Image, error func newKCLBuilder(imageConfigs []v1beta1.ImageConfig) *kclBuilder { return &kclBuilder{ - baseImage: "xpkg.crossplane.io/crossplane-contrib/function-kcl:v0.12.1", + baseImage: "xpkg.crossplane.io/crossplane-contrib/function-kcl:v0.12.3", transport: http.DefaultTransport, configStore: clixpkg.NewStaticImageConfigStore(imageConfigs), } From 9d2644ab7a66cde35f76725b65f4b00beba65184 Mon Sep 17 00:00:00 2001 From: Christopher Haar Date: Tue, 17 Nov 2026 17:10:00 +0100 Subject: [PATCH 4/4] Generate project API schemas during dependency update-cache update-cache regenerated schemas for dependencies but not for the project's own APIs, which were only generated during build. Language tooling that imports the project's XRD models (functions, tests, editors) therefore saw incomplete models after update-cache - e.g. go mod tidy in an embedded function failed before the first build. Signed-off-by: Christopher Haar --- cmd/crossplane/dependency/cache.go | 43 ++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/cmd/crossplane/dependency/cache.go b/cmd/crossplane/dependency/cache.go index c31b09f3..3cee514b 100644 --- a/cmd/crossplane/dependency/cache.go +++ b/cmd/crossplane/dependency/cache.go @@ -34,6 +34,8 @@ import ( "github.com/crossplane/cli/v2/internal/git" "github.com/crossplane/cli/v2/internal/project/projectfile" "github.com/crossplane/cli/v2/internal/schemas/generator" + "github.com/crossplane/cli/v2/internal/schemas/manager" + "github.com/crossplane/cli/v2/internal/schemas/runner" "github.com/crossplane/cli/v2/internal/terminal" clixpkg "github.com/crossplane/cli/v2/internal/xpkg" @@ -76,15 +78,17 @@ func (c *updateCacheCmd) Run(logger logging.Logger, sp terminal.SpinnerPrinter, return errors.Wrap(err, "cannot create xpkg client") } + generators := generator.Filter( + generator.AllLanguages( + generator.WithGoModelAccessors(cfg.Features.GenerateGoModelAccessors), + generator.WithGoRuntimeObjects(cfg.Features.GenerateGoRuntimeObjects), + ), + proj.Spec.Schemas.GetLanguages(), + ) + opts := []dependency.ManagerOption{ dependency.WithProjectFile(c.ProjectFile), - dependency.WithSchemaGenerators(generator.Filter( - generator.AllLanguages( - generator.WithGoModelAccessors(cfg.Features.GenerateGoModelAccessors), - generator.WithGoRuntimeObjects(cfg.Features.GenerateGoRuntimeObjects), - ), - proj.Spec.Schemas.GetLanguages(), - )), + dependency.WithSchemaGenerators(generators), dependency.WithXpkgClient(client), } @@ -99,7 +103,30 @@ func (c *updateCacheCmd) Run(logger logging.Logger, sp terminal.SpinnerPrinter, logger.Debug("Updating all dependencies") return sp.WrapAsyncWithSuccessSpinners(func(ch async.EventChannel) error { - return m.RefreshAll(ctx, ch) + if err := m.RefreshAll(ctx, ch); err != nil { + return err + } + + // Also regenerate schemas for the project's own APIs, so the models + // are complete without a build (e.g. for language tooling in + // functions and tests that import them). + apisExist, err := afero.DirExists(projFS, proj.Spec.Paths.APIs) + if err != nil || !apisExist { + return err + } + + ch.SendEvent("Generating project API schemas", async.EventStatusStarted) + schemasFS := afero.NewBasePathFs(projFS, proj.Spec.Paths.Schemas) + schemaRunner := runner.NewRealSchemaRunner(runner.WithImageConfig(proj.Spec.ImageConfigs)) + schemaMgr := manager.New(schemasFS, generators, schemaRunner) + apisFS := afero.NewBasePathFs(projFS, proj.Spec.Paths.APIs) + if _, err := schemaMgr.Generate(ctx, manager.NewFSSource(proj.Spec.Paths.APIs, apisFS)); err != nil { + ch.SendEvent("Generating project API schemas", async.EventStatusFailure) + return errors.Wrap(err, "failed to generate project API schemas") + } + ch.SendEvent("Generating project API schemas", async.EventStatusSuccess) + + return nil }) }