+
Skip to content
Merged
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
11 changes: 11 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
version: "2"

linters:
enable:
- govet
- errcheck
- staticcheck
- ineffassign
- misspell
- gocritic
- revive
- gosec
- nolintlint
- gocyclo
exclusions:
warn-unused: true
presets:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Cuestomize

[![Go Reference](https://pkg.go.dev/badge/github.com/workday/cuestomize.svg)](https://pkg.go.dev/github.com/workday/cuestomize)

Cuestomize is a Kubernetes Package Manager using CUE-lang and integrated in Kustomize.

It is implemented as a Kustomize KRM function that reads a CUE model, and optionally some input resources from the Kustomize stream, and passes back to Kustomize the generated resources.
Expand Down
2 changes: 2 additions & 0 deletions api/convert.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package api provides utilities for converting Go values into CUE values and defines
// interfaces for types that can be converted to CUE format.
package api

import (
Expand Down
2 changes: 1 addition & 1 deletion api/krm.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type KRMInput struct {
// ExtractIncludes populates the includes structure from the provided KRMInput and items.
// It searches items for matches against the includes defined in the KRMInput's spec
// and returns the includes map.
func ExtractIncludes(krm *KRMInput, items []*kyaml.RNode, ctx context.Context) (Includes, error) {
func ExtractIncludes(ctx context.Context, krm *KRMInput, items []*kyaml.RNode) (Includes, error) {
log := logr.FromContextOrDiscard(ctx)

includes := make(Includes)
Expand Down
2 changes: 1 addition & 1 deletion api/krm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestKRMInput_ExtractIncludes(t *testing.T) {
krmInput := testhelpers.LoadFromFile[KRMInput](t, tt.testdataDir+"/"+TestKRMInputFileName)
items := testhelpers.LoadResourceList(t, tt.testdataDir+"/"+TestKRMInputFileName, tt.testdataDir+"/"+TestItemsFileName)

includes, err := ExtractIncludes(krmInput, items, t.Context())
includes, err := ExtractIncludes(t.Context(), krmInput, items)

if tt.expectedError {
require.Error(t, err)
Expand Down
1 change: 1 addition & 0 deletions api/remote_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import "sigs.k8s.io/kustomize/api/types"

// RemoteModule defines the structure to describe a remote CUE module to fetch from an OCI registry.
type RemoteModule struct {
Registry string `yaml:"registry" json:"registry"`
Repo string `yaml:"repo" json:"repo"`
Expand Down
1 change: 1 addition & 0 deletions e2e/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main provides an e2e test setup utility that uploads CUE modules to local registries.
package main

import (
Expand Down
1 change: 1 addition & 0 deletions hack/push-examples.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main provides a utility to push CUE module examples to an OCI registry.
package main

import (
Expand Down
9 changes: 9 additions & 0 deletions internal/pkg/cuerrors/details.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Package cuerrors provides utilities for enhanced error formatting and detailed error reporting
// when dealing with CUE language errors. It includes functionality to format errors with
// additional context and details using CUE's built-in error configuration system.
//
// The main component is the Detailer type, which wraps CUE's errors.Config to provide
// consistent error formatting.
package cuerrors

import (
Expand All @@ -6,10 +12,13 @@ import (
"cuelang.org/go/cue/errors"
)

// Detailer struct can be used to format CUE errors with additional details.
type Detailer struct {
Cfg errors.Config
}

// NewDetailerWithCwd creates a new Detailer with the specified current working directory (cwd).
// In formatted errors, file paths will be made relative to this directory.
func NewDetailerWithCwd(cwd string) Detailer {
return Detailer{
Cfg: errors.Config{
Expand Down
21 changes: 12 additions & 9 deletions internal/pkg/cuestomize/builder.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Package cuestomize provides a builder for creating KRM (Kubernetes Resource Model) functions
// that generate Kubernetes resources from CUE configurations. It enables users to define
// resource transformations using CUE language and apply them as part of a Kustomize pipeline.
package cuestomize

import (
Expand All @@ -13,8 +16,8 @@ const (
DefaultResourcesPath = "/cue-resources"
)

// CUEstomizeFuncBuilder is a builder for the CUEstomize KRM function.
type CUEstomizeFuncBuilder struct {
// KRMFuncBuilder is a builder for the Cuestomize KRM function.
type KRMFuncBuilder struct {
// resourcesPath is the path to the directory containing the CUE resources.
// If not set, it defaults to "/cue-resources".
resourcesPath string
Expand All @@ -23,29 +26,29 @@ type CUEstomizeFuncBuilder struct {
config *api.KRMInput
}

// NewBuilder creates a new CUEstomizeFuncBuilder with the default resources path.
func NewBuilder() *CUEstomizeFuncBuilder {
return &CUEstomizeFuncBuilder{
// NewBuilder creates a new KRMFuncBuilder with the default resources path.
func NewBuilder() *KRMFuncBuilder {
return &KRMFuncBuilder{
resourcesPath: DefaultResourcesPath,
}
}

// SetConfig sets the reference to the configuration object that the KRM function will receive in input.
func (b *CUEstomizeFuncBuilder) SetConfig(config *api.KRMInput) *CUEstomizeFuncBuilder {
func (b *KRMFuncBuilder) SetConfig(config *api.KRMInput) *KRMFuncBuilder {
b.config = config
return b
}

// SetResourcesPath sets the path to the directory containing the CUE resources.
func (b *CUEstomizeFuncBuilder) SetResourcesPath(resourcesPath string) *CUEstomizeFuncBuilder {
func (b *KRMFuncBuilder) SetResourcesPath(resourcesPath string) *KRMFuncBuilder {
b.resourcesPath = resourcesPath
return b
}

// Build returns a function that can be used to generate resources from a CUE configuration and some input resources.
func (b *CUEstomizeFuncBuilder) Build(ctx context.Context) (func([]*kyaml.RNode) ([]*kyaml.RNode, error), error) {
func (b *KRMFuncBuilder) Build(ctx context.Context) (func([]*kyaml.RNode) ([]*kyaml.RNode, error), error) {
if b.config == nil {
return nil, fmt.Errorf("config must be set before building the KRM function")
}
return newCuestomizeFunctionWithPath(b.config, &b.resourcesPath, ctx), nil
return newCuestomizeFunctionWithPath(ctx, b.config, &b.resourcesPath), nil
}
4 changes: 2 additions & 2 deletions internal/pkg/cuestomize/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type KRMFunction = func([]*kyaml.RNode) ([]*kyaml.RNode, error)
// * config: pointer to the configuration object
//
// * resourcesPath: path to the directory containing the CUE resources (nil to use the default)
func newCuestomizeFunctionWithPath(config *api.KRMInput, resourcesPath *string, ctx context.Context) KRMFunction {
func newCuestomizeFunctionWithPath(ctx context.Context, config *api.KRMInput, resourcesPath *string) KRMFunction {
return func(items []*kyaml.RNode) ([]*kyaml.RNode, error) {
return cuestomize.Cuestomize(items, config, *resourcesPath, ctx)
return cuestomize.Cuestomize(ctx, items, config, *resourcesPath)
}
}
4 changes: 2 additions & 2 deletions internal/pkg/cuestomize/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func TestKRMFunction(t *testing.T) {
} else {
require.NoError(t, err)
for _, res := range result {
resId := resid.FromRNode(res)
require.Contains(t, tt.Expected, resId, "Expected resource ID not found in result")
resID := resid.FromRNode(res)
require.Contains(t, tt.Expected, resID, "Expected resource ID not found in result")
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/pkg/cuestomize/oci/fetch.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package oci provides functionality for fetching CUE modules from OCI registries.
package oci

import (
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/processor/strict_processor.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package processor extends kustomize's SimpleProcessor to support strict unmarshalling of function configs.
package processor

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/pkg/registry_auth/auth.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Package registryauth provides utilities for configuring authentication
// credentials for OCI registry clients, supporting both Kubernetes Secret
// and environment variable-based credential sources.
package registryauth

import (
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/testhelpers/loaders.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package testhelpers provides utility functions for to be used in tests.
package testhelpers

import (
Expand Down
3 changes: 2 additions & 1 deletion internal/pkg/testhelpers/push_oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"oras.land/oras-go/v2/registry/remote"
)

func PushDirectoryToOCIRegistry_T(t *testing.T, reference, rootDirectory, artifactType, tag string, client remote.Client, plainHTTP bool) ocispec.Descriptor {
// PushDirectoryToOCIRegistryT is a test helper that pushes the contents of a directory to an OCI registry.
func PushDirectoryToOCIRegistryT(t *testing.T, reference, rootDirectory, artifactType, tag string, client remote.Client, plainHTTP bool) ocispec.Descriptor {
t.Helper()

descriptor, err := oci.PushDirectoryToOCIRegistry(t.Context(), reference, rootDirectory, artifactType, tag, client, plainHTTP)
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main provides the Cuestomize CLI tool for Kubernetes resource management using CUE.
package main

import (
Expand Down
3 changes: 2 additions & 1 deletion pkg/cuestomize/build_schema.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package cuestomize provides the Cuestomize functionality.
package cuestomize

import (
Expand All @@ -10,7 +11,7 @@ import (
)

// BuildCUEModelSchema builds a CUE model from the provided instances and returns the unified schema.
func BuildCUEModelSchema(ctx context.Context, cueCtx *cue.Context, instances []*build.Instance, detailers ...*cuerrors.Detailer) (*cue.Value, error) {
func BuildCUEModelSchema(ctx context.Context, cueCtx *cue.Context, instances []*build.Instance) (*cue.Value, error) {
detailer := cuerrors.FromContextOrDefault(ctx)

values, err := cueCtx.BuildInstances(instances)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cuestomize/cuestomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// Cuestomize generates (or validates) resources from the provided CUE configuration and input resources.
func Cuestomize(items []*kyaml.RNode, config *api.KRMInput, resourcesPath string, ctx context.Context) ([]*kyaml.RNode, error) {
func Cuestomize(ctx context.Context, items []*kyaml.RNode, config *api.KRMInput, resourcesPath string) ([]*kyaml.RNode, error) {
log := logr.FromContextOrDiscard(ctx)

detailer := cuerrors.NewDetailerWithCwd(resourcesPath)
Expand All @@ -29,7 +29,7 @@ func Cuestomize(items []*kyaml.RNode, config *api.KRMInput, resourcesPath string
}
}

includes, err := api.ExtractIncludes(config, items, ctx)
includes, err := api.ExtractIncludes(ctx, config, items)
if err != nil {
return nil, fmt.Errorf("failed to compute includes from KRM function inputs: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cuestomize/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
kyaml "sigs.k8s.io/kustomize/kyaml/yaml"
)

// processOutputs processes the outputs from the CUE model and appends them to the output slice.
// ProcessOutputs processes the outputs from the CUE model and appends them to the output slice.
func ProcessOutputs(ctx context.Context, unified cue.Value, items []*kyaml.RNode) ([]*kyaml.RNode, error) {
log := logr.FromContextOrDiscard(ctx)

Expand Down
1 change: 1 addition & 0 deletions pkg/oci/fetcher/fetcher.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package fetcher provides functionality for fetching artifacts from OCI registries.
package fetcher

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/oci/fetcher/fetcher_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func Test_FetchFromRegistry(t *testing.T) {
tempDir := t.TempDir() // Directory to store the fetched artifact

// push testdata/sample-module to the registry
_ = testhelpers.PushDirectoryToOCIRegistry_T(t, tc.registryHost+"/"+tc.repo+":"+tc.tag, tc.testdataDir, tc.artifactType, tc.tag, tc.client, tc.plainHTTP)
_ = testhelpers.PushDirectoryToOCIRegistryT(t, tc.registryHost+"/"+tc.repo+":"+tc.tag, tc.testdataDir, tc.artifactType, tc.tag, tc.client, tc.plainHTTP)

// Fetch the module from the registry
err := FetchFromOCIRegistry(ctx, tc.client, tempDir, tc.registryHost, tc.repo, tc.tag, tc.plainHTTP)
Expand Down
3 changes: 3 additions & 0 deletions pkg/oci/push_to.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Package oci provides utilities for working with Open Container Initiative (OCI)
// artifacts and registries, including functionality to push directory contents
// as OCI artifacts to remote repositories.
package oci

import (
Expand Down
2 changes: 1 addition & 1 deletion semver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.2
0.2.3
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载