Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 35 additions & 8 deletions cmd/crossplane/dependency/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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),
}

Expand All @@ -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
})
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/crossplane/function/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion internal/project/functions/kcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
23 changes: 23 additions & 0 deletions internal/project/projectfile/projectfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading