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
30 changes: 13 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ require (
github.com/google/go-cmp v0.7.0
github.com/google/go-containerregistry v0.20.6
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/kptdev/krm-functions-catalog/functions/go/apply-setters v0.2.2
github.com/kptdev/krm-functions-sdk/go/fn v1.0.2
github.com/kptdev/krm-functions-catalog/functions/go/apply-setters v0.2.4
github.com/kptdev/krm-functions-sdk/go/fn v1.0.0
github.com/otiai10/copy v1.14.1
github.com/philopon/go-toposort v0.0.0-20170620085441-9be86dbd762f
github.com/pkg/errors v0.9.1
Expand All @@ -25,19 +25,19 @@ require (
golang.org/x/text v0.31.0
gopkg.in/yaml.v2 v2.4.0
gotest.tools v2.2.0+incompatible
k8s.io/api v0.34.1
k8s.io/apiextensions-apiserver v0.34.1
k8s.io/apimachinery v0.34.1
k8s.io/cli-runtime v0.34.1
k8s.io/client-go v0.34.1
k8s.io/component-base v0.34.1
k8s.io/api v0.35.0
k8s.io/apiextensions-apiserver v0.35.0
k8s.io/apimachinery v0.35.0
k8s.io/cli-runtime v0.35.0
k8s.io/client-go v0.35.0
k8s.io/component-base v0.35.0
k8s.io/klog/v2 v2.130.1
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912
k8s.io/kubectl v0.34.1
k8s.io/kubectl v0.35.0
sigs.k8s.io/cli-utils v0.37.2
sigs.k8s.io/controller-runtime v0.22.4
sigs.k8s.io/kustomize/api v0.20.1
sigs.k8s.io/kustomize/kyaml v0.20.1
sigs.k8s.io/kustomize/api v0.21.0
sigs.k8s.io/kustomize/kyaml v0.21.0
sigs.k8s.io/yaml v1.6.0
)

Expand Down Expand Up @@ -75,11 +75,9 @@ require (
github.com/go-openapi/swag/stringutils v0.25.1 // indirect
github.com/go-openapi/swag/typeutils v0.25.1 // indirect
github.com/go-openapi/swag/yamlutils v0.25.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/gnostic-models v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jonboulle/clockwork v0.5.0 // indirect
Expand All @@ -88,14 +86,12 @@ require (
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/moby/spdystream v0.5.0 // indirect
github.com/moby/term v0.5.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/onsi/gomega v1.37.0 // indirect
github.com/onsi/gomega v1.38.2 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/otiai10/mint v1.6.3 // indirect
Expand Down Expand Up @@ -126,7 +122,7 @@ require (
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/component-helpers v0.34.1 // indirect
k8s.io/component-helpers v0.35.0 // indirect
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 // indirect
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
Expand Down
103 changes: 32 additions & 71 deletions go.sum

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion internal/builtins/pkg_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ func TestPkgContextGenerator(t *testing.T) {

exp, err := os.ReadFile(filepath.Join("testdata", test.dir, "out.yaml"))
assert.NoError(t, err)
// Normalize line endings to LF for cross-platform comparison
expNormalized := bytes.ReplaceAll(exp, []byte("\r\n"), []byte("\n"))

err = pkgCtxGenerator.Run(bytes.NewReader(in), out)
if err != test.expErr {
t.Errorf("exp: %v got: %v", test.expErr, err)
}
if diff := cmp.Diff(string(exp), out.String()); diff != "" {
if diff := cmp.Diff(string(expNormalized), out.String()); diff != "" {
t.Errorf("pkg context mistmach (-want +got):\n%s", diff)
}
})
Expand Down
2 changes: 2 additions & 0 deletions internal/kptops/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (
)

var functions map[string]framework.ResourceListProcessorFunc = map[string]framework.ResourceListProcessorFunc{
// v0.2.0 kept for backward compatibility with existing Kptfiles
"ghcr.io/kptdev/krm-functions-catalog/apply-setters:v0.2.0": applySetters,
"ghcr.io/kptdev/krm-functions-catalog/apply-setters:v0.2.4": applySetters,
"ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5": setLabels,
"ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.4.1": setNamespace,
}
Expand Down
16 changes: 11 additions & 5 deletions internal/util/render/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ import (
"sigs.k8s.io/kustomize/kyaml/yaml"
)

const rootString = "/root"
const subPkgString = "/root/subpkg"
// absPath returns a forward-slash absolute path for use with filesys.MakeFsInMemory(),
// which only understands Unix-style paths regardless of host OS.
func absPath(suffix string) string {
return "/" + strings.ReplaceAll(suffix, string(filepath.Separator), "/")
}

var rootString = "/root"
var subPkgString = "/root/subpkg"

func TestPathRelToRoot(t *testing.T) {
tests := []struct {
Expand Down Expand Up @@ -260,11 +266,11 @@ func setupRendererTest(t *testing.T, renderBfs bool) (*Renderer, *bytes.Buffer,
assert.NoError(t, err)

childPkgPath := "/root/subpkg/child"
err = mockFileSystem.Mkdir(subPkgPath)
err = mockFileSystem.Mkdir(childPkgPath)
assert.NoError(t, err)

siblingPkgPath := "/root/sibling"
err = mockFileSystem.Mkdir(subPkgPath)
err = mockFileSystem.Mkdir(siblingPkgPath)
assert.NoError(t, err)

err = mockFileSystem.WriteFile(filepath.Join(rootPkgPath, "Kptfile"), fmt.Appendf(nil, `
Expand Down Expand Up @@ -391,7 +397,7 @@ metadata:

t.Run("Error in LocalResources", func(t *testing.T) {
// Simulate an error in LocalResources by creating a package with no Kptfile
invalidPkgPath := "/invalid"
invalidPkgPath := absPath("invalid")
err := mockFileSystem.Mkdir(invalidPkgPath)
assert.NoError(t, err)

Expand Down
9 changes: 6 additions & 3 deletions pkg/api/kptfile/v1/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package v1

import (
"fmt"
"path"
"path/filepath"
"regexp"
"slices"
Expand Down Expand Up @@ -157,11 +158,13 @@ func validateFnConfigPathSyntax(p string) error {
if strings.TrimSpace(p) == "" {
return fmt.Errorf("path must not be empty")
}
p = filepath.Clean(p)
if filepath.IsAbs(p) {
// Use path.IsAbs (forward-slash based) since Kptfile paths are always
// slash-separated regardless of the host OS.
if path.IsAbs(p) {
return fmt.Errorf("path must be relative")
}
if strings.Contains(p, "..") {
cleaned := filepath.Clean(p)
if strings.Contains(cleaned, "..") {
// fn config must not live outside the package directory
// Allowing outside path opens up an attack vector that allows
// reading any YAML file on package consumer's machine.
Expand Down
21 changes: 21 additions & 0 deletions pkg/api/resourcegroup/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2026 The kpt Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package v1 contains the stable v1 API for ResourceGroup.
// This API is stable and follows semantic versioning.
// Breaking changes will only be introduced in a new major version (v2).
//
// +kubebuilder:object:generate=true
// +groupName=kpt.dev
package v1
63 changes: 63 additions & 0 deletions pkg/api/resourcegroup/v1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2021,2026 The kpt Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package v1 defines ResourceGroup schema.
// Version: v1 (stable)
// swagger:meta
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/cli-utils/pkg/common"
"sigs.k8s.io/kustomize/kyaml/yaml"
)

const (
RGFileName = "resourcegroup.yaml"
// RGInventoryIDLabel is the label name used for storing an inventory ID.
RGInventoryIDLabel = common.InventoryLabel

// Deprecated: prefer ResourceGroupGVK
RGFileKind = "ResourceGroup"
// Deprecated: prefer ResourceGroupGVK
RGFileGroup = "kpt.dev"
// Deprecated: prefer ResourceGroupGVK
RGFileVersion = "v1"
// Deprecated: prefer ResourceGroupGVK
RGFileAPIVersion = RGFileGroup + "/" + RGFileVersion
)

// ResourceGroupGVK is the GroupVersionKind of ResourceGroup objects
func ResourceGroupGVK() schema.GroupVersionKind {
return schema.GroupVersionKind{
Group: "kpt.dev",
Version: "v1",
Kind: "ResourceGroup",
}
}

// DefaultMeta is the ResourceMeta for ResourceGroup instances.
var DefaultMeta = yaml.ResourceMeta{
TypeMeta: yaml.TypeMeta{
APIVersion: RGFileAPIVersion,
Kind: RGFileKind,
},
}

// ResourceGroup contains the inventory information about a package managed with kpt.
// This is the stable v1 API for ResourceGroup.
// swagger:model resourcegroup
type ResourceGroup struct {
yaml.ResourceMeta `yaml:",inline" json:",inline"`
}
7 changes: 6 additions & 1 deletion pkg/api/resourcegroup/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package defines ResourceGroup schema.
// Package v1alpha1 defines ResourceGroup schema.
// Version: v1alpha1
//
// Deprecated: v1alpha1 is deprecated. Use github.com/kptdev/kpt/pkg/api/resourcegroup/v1 instead.
// This package is maintained for backward compatibility only and will be removed in v2.0.0.
// swagger:meta
package v1alpha1

Expand All @@ -39,6 +42,8 @@ const (
)

// ResourceGroupGVK is the GroupVersionKind of ResourceGroup objects
//
// Deprecated: Use github.com/kptdev/kpt/pkg/api/resourcegroup/v1.ResourceGroupGVK instead.
func ResourceGroupGVK() schema.GroupVersionKind {
return schema.GroupVersionKind{
Group: "kpt.dev",
Expand Down