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
2 changes: 0 additions & 2 deletions .github/copilot-code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ review:
instructions: "Do not review — generated by k8s code-generator"
- path: "**/zz_generated*"
instructions: "Do not review — generated by controller-tools"
- path: "thirdparty/**"
instructions: "Do not review — vendored upstream code"
- path: "go.sum"
instructions: "Do not review"
- path: "go.mod"
Expand Down
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ linters:
- gosec
- funlen
paths:
- thirdparty/
- third_party$
- builtin$
- examples$
Expand All @@ -77,7 +76,6 @@ formatters:
exclusions:
generated: lax
paths:
- thirdparty/
- third_party$
- builtin$
- examples$
1 change: 0 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ git config --global user.name "Your Name"
* **release/**: Release automation (GoReleaser config, Homebrew formula generation)
* **hack/**: Miscellaneous development utilities
* **healthcheck/**: Separate module for health checking (Go (Go version is defined in [healthcheck/go.mod](./healthcheck/go.mod)), local Makefile)
* **thirdparty/**: Third-party code (excluded from linting)
* **Formula/**: Homebrew package definition (generated by `go run ./release/formula/main.go VERSION`)

## Linting Rules & Style
Expand Down
6 changes: 3 additions & 3 deletions commands/fn/fncmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"github.com/kptdev/kpt/commands/fn/doc"
"github.com/kptdev/kpt/commands/fn/render"
"github.com/kptdev/kpt/internal/docs/generated/fndocs"
"github.com/kptdev/kpt/thirdparty/cmdconfig/commands/cmdeval"
"github.com/kptdev/kpt/thirdparty/cmdconfig/commands/cmdsink"
"github.com/kptdev/kpt/thirdparty/cmdconfig/commands/cmdsource"
"github.com/kptdev/kpt/pkg/cmdconfig/commands/cmdeval"
"github.com/kptdev/kpt/pkg/cmdconfig/commands/cmdsink"
"github.com/kptdev/kpt/pkg/cmdconfig/commands/cmdsource"
"github.com/spf13/cobra"
)

Expand Down
4 changes: 2 additions & 2 deletions commands/pkg/pkgcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
initialization "github.com/kptdev/kpt/commands/pkg/init"
"github.com/kptdev/kpt/commands/pkg/update"
"github.com/kptdev/kpt/internal/docs/generated/pkgdocs"
"github.com/kptdev/kpt/thirdparty/cmdconfig/commands/cmdcat"
"github.com/kptdev/kpt/thirdparty/cmdconfig/commands/cmdtree"
"github.com/kptdev/kpt/pkg/cmdconfig/commands/cmdcat"
"github.com/kptdev/kpt/pkg/cmdconfig/commands/cmdtree"
"github.com/spf13/cobra"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (

kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1"
"github.com/kptdev/kpt/internal/docs/generated/pkgdocs"
"github.com/kptdev/kpt/pkg/cmdconfig/commands/runner"
argsutil "github.com/kptdev/kpt/pkg/lib/util/args"
"github.com/kptdev/kpt/thirdparty/cmdconfig/commands/runner"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/kio/filters"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,9 @@ func TestCmd_NonExistent(t *testing.T) {
d := t.TempDir()
_, err := runCat(t, filepath.Join(d, "nope.yaml"))
assert.Error(t, err)
assert.Contains(t, err.Error(), "no such file or directory")
isNotFound := os.IsNotExist(err) || strings.Contains(err.Error(), "no such file or directory") ||
strings.Contains(err.Error(), "cannot find the file")
assert.True(t, isNotFound, "expected file not found error")
}

// TestCmd_KptfileArgDisplayed: passing the Kptfile directly should display
Expand Down Expand Up @@ -826,11 +828,21 @@ metadata:
name: secret
`)
// Symlink inside the package — should be skipped.
require.NoError(t, os.Symlink(filepath.Join(d, "external.yaml"), filepath.Join(real, "link.yaml")))
if err := os.Symlink(filepath.Join(d, "external.yaml"), filepath.Join(real, "link.yaml")); err != nil {
if strings.Contains(err.Error(), "privilege is not held") {
t.Skip("skipping symlink test on Windows without symlink privileges")
}
require.NoError(t, err)
}

// Symlink as the argument — should be resolved.
link := filepath.Join(d, "pkg-link")
require.NoError(t, os.Symlink(real, link))
if err := os.Symlink(real, link); err != nil {
if strings.Contains(err.Error(), "privilege is not held") {
t.Skip("skipping symlink test on Windows without symlink privileges")
}
require.NoError(t, err)
}

got, err := runCat(t, link)
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
"github.com/google/shlex"
kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1"
docs "github.com/kptdev/kpt/internal/docs/generated/fndocs"
"github.com/kptdev/kpt/pkg/cmdconfig/commands/runner"
"github.com/kptdev/kpt/pkg/fn/runfn"
"github.com/kptdev/kpt/pkg/kptfile/kptfileutil"
"github.com/kptdev/kpt/pkg/lib/runneroptions"
argsutil "github.com/kptdev/kpt/pkg/lib/util/args"
"github.com/kptdev/kpt/pkg/lib/util/cmdutil"
pathutil "github.com/kptdev/kpt/pkg/lib/util/path"
"github.com/kptdev/kpt/pkg/printer"
"github.com/kptdev/kpt/thirdparty/cmdconfig/commands/runner"
"github.com/kptdev/kpt/thirdparty/kyaml/runfn"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/kyaml/comments"
"sigs.k8s.io/kustomize/kyaml/errors"
Expand Down Expand Up @@ -89,7 +89,8 @@
})

r.Command.Flags().BoolVar(
&r.RunnerOptions.AllowWasm, "allow-alpha-wasm", false, "allow alpha wasm functions to be run. If true, you can specify a wasm image with --image flag or a path to a wasm file (must have the .wasm file extension) with --exec flag.")
&r.RunnerOptions.AllowWasm, "allow-alpha-wasm", false,
"allow alpha wasm functions to be run. If true, you can specify a wasm image with --image flag or a path to a wasm file (must have the .wasm file extension) with --exec flag.")

Check failure on line 93 in pkg/cmdconfig/commands/cmdeval/cmdeval.go

View workflow job for this annotation

GitHub Actions / build-test-docker

The line is 178 characters long, which exceeds the maximum of 170 characters. (lll)

Check failure on line 93 in pkg/cmdconfig/commands/cmdeval/cmdeval.go

View workflow job for this annotation

GitHub Actions / build-test-podman

The line is 178 characters long, which exceeds the maximum of 170 characters. (lll)

// selector flags
r.Command.Flags().StringVar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"testing"

"github.com/kptdev/kpt/internal/testutil"
"github.com/kptdev/kpt/pkg/fn/runfn"
"github.com/kptdev/kpt/pkg/lib/runneroptions"
"github.com/kptdev/kpt/pkg/printer/fake"
"github.com/kptdev/kpt/thirdparty/kyaml/runfn"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"sigs.k8s.io/kustomize/kyaml/fn/runtime/runtimeutil"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (

kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1"
"github.com/kptdev/kpt/internal/docs/generated/fndocs"
"github.com/kptdev/kpt/pkg/cmdconfig/commands/runner"
"github.com/kptdev/kpt/pkg/lib/pkg"
argsutil "github.com/kptdev/kpt/pkg/lib/util/args"
"github.com/kptdev/kpt/pkg/lib/util/cmdutil"
"github.com/kptdev/kpt/pkg/printer"
"github.com/kptdev/kpt/thirdparty/cmdconfig/commands/runner"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/kio/kioutil"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"

"github.com/kptdev/kpt/internal/testutil"
Expand Down Expand Up @@ -497,8 +498,13 @@ func TestSourceCommand_Symlink(t *testing.T) {
err = os.MkdirAll(filepath.Join(d, "foo"), 0700)
assert.NoError(t, err)
err = os.Symlink("foo", "foo-link")
if !assert.NoError(t, err) {
return
if err != nil {
if strings.Contains(err.Error(), "privilege is not held") {
t.Skip("skipping symlink test on Windows without symlink privileges")
}
if !assert.NoError(t, err) {
return
}
}
err = os.WriteFile(filepath.Join(d, "foo", "f1.yaml"), []byte(`
kind: Deployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (

kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1"
"github.com/kptdev/kpt/internal/docs/generated/pkgdocs"
"github.com/kptdev/kpt/pkg/cmdconfig/commands/runner"
argsutil "github.com/kptdev/kpt/pkg/lib/util/args"
"github.com/kptdev/kpt/pkg/printer"
"github.com/kptdev/kpt/thirdparty/cmdconfig/commands/runner"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/kio/filters"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,13 @@ func TestTreeCommand_symlink(t *testing.T) {
err = os.MkdirAll(filepath.Join(d, "foo"), 0700)
assert.NoError(t, err)
err = os.Symlink("foo", "foo-link")
if !assert.NoError(t, err) {
return
if err != nil {
if strings.Contains(err.Error(), "privilege is not held") {
t.Skip("skipping symlink test on Windows without symlink privileges")
}
if !assert.NoError(t, err) {
return
}
}
defer os.RemoveAll(d)
err = os.WriteFile(filepath.Join(d, "foo", "f1.yaml"), []byte(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,8 @@ func (p TreeWriter) getFields(leaf *yaml.RNode) (treeFields, error) {
elem := &treeField{name: match}
field.matchingElementsAndFields = append(field.matchingElementsAndFields, elem)

// iterate over collection of queried fields for the element
for i := range subFields {
// add to the list of fields for this element
elem.matchingElementsAndFields = append(elem.matchingElementsAndFields, subFields[i])
}
// add to the list of fields for this element
elem.matchingElementsAndFields = append(elem.matchingElementsAndFields, subFields...)
}
// clear this cached data
field.subFieldByMatch = nil
Expand Down
File renamed without changes.
File renamed without changes.
53 changes: 1 addition & 52 deletions pkg/lib/kptops/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@ package kptops

import (
"context"
"fmt"
"io"
"os"

fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1"
"github.com/kptdev/kpt/pkg/fn"
"github.com/kptdev/kpt/pkg/lib/pkg"
"github.com/kptdev/kpt/pkg/lib/runneroptions"
"github.com/kptdev/kpt/pkg/printer"
"k8s.io/klog/v2"
"sigs.k8s.io/kustomize/kyaml/filesys"
)

Expand All @@ -51,51 +46,5 @@ func (r *renderer) Render(ctx context.Context, pkg filesys.FileSystem, opts fn.R
FileSystem: pkg,
RunnerOptions: r.runnerOptions,
}
return rr.Execute(printer.WithContext(ctx, &packagePrinter{}))
}

type packagePrinter struct{}

var _ printer.Printer = &packagePrinter{}

const (
packagePrefixFormat = "Package %q:"
logDepth = 2
)

func (p *packagePrinter) PrintPackage(pkg *pkg.Pkg, _ bool) {
p.printfDepth(logDepth, packagePrefixFormat, pkg.DisplayPath)
}

func (p *packagePrinter) Printf(format string, args ...any) {
p.printfDepth(logDepth, format, args...)
}

func (p *packagePrinter) printfDepth(depth int, format string, args ...any) {
klog.InfofDepth(depth, format, args...)
}

func (p *packagePrinter) OptPrintf(opt *printer.Options, format string, args ...any) {
if opt == nil {
p.Printf(format, args...)
return
}
var prefix string
switch {
case opt.PkgDisplayName != "":
prefix = fmt.Sprintf(packagePrefixFormat, opt.PkgDisplayName)
case !opt.PkgDisplayPath.Empty():
prefix = fmt.Sprintf(packagePrefixFormat, string(opt.PkgDisplayPath))
case !opt.PkgPath.Empty():
prefix = fmt.Sprintf(packagePrefixFormat, string(opt.PkgPath))
}
p.printfDepth(logDepth, prefix+format, args...)
}

func (p *packagePrinter) OutStream() io.Writer {
return os.Stdout
}

func (p *packagePrinter) ErrStream() io.Writer {
return os.Stderr
return rr.Execute(printer.WithContext(ctx, printer.NewKlogPrinter()))
}
14 changes: 7 additions & 7 deletions pkg/lib/kptops/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestPackagePrinter(t *testing.T) {

func TestPackagePrinterStub(t *testing.T) {
t.Run("PrintPackage stub", func(t *testing.T) {
p := &packagePrinter{}
p := printer.NewKlogPrinter()
testPkg := &pkg.Pkg{
DisplayPath: "test/path",
}
Expand All @@ -178,7 +178,7 @@ func TestPackagePrinterStub(t *testing.T) {
})

t.Run("Printf stub", func(t *testing.T) {
p := &packagePrinter{}
p := printer.NewKlogPrinter()

assert.NotPanics(t, func() {
p.Printf("test message")
Expand All @@ -190,15 +190,15 @@ func TestPackagePrinterStub(t *testing.T) {
})

t.Run("OptPrintf stub with nil options", func(t *testing.T) {
p := &packagePrinter{}
p := printer.NewKlogPrinter()

assert.NotPanics(t, func() {
p.OptPrintf(nil, "test message")
})
})

t.Run("OptPrintf stub with options", func(t *testing.T) {
p := &packagePrinter{}
p := printer.NewKlogPrinter()
opt := printer.NewOpt().DisplayName("my-package")

assert.NotPanics(t, func() {
Expand All @@ -207,15 +207,15 @@ func TestPackagePrinterStub(t *testing.T) {
})

t.Run("OutStream stub", func(t *testing.T) {
p := &packagePrinter{}
p := printer.NewKlogPrinter()

stream := p.OutStream()
assert.NotNil(t, stream)
assert.Equal(t, os.Stdout, stream)
})

t.Run("ErrStream stub", func(t *testing.T) {
p := &packagePrinter{}
p := printer.NewKlogPrinter()

stream := p.ErrStream()
assert.NotNil(t, stream)
Expand All @@ -236,7 +236,7 @@ func TestPrinterLoggingDepth(t *testing.T) {
}
expectedFile := filepath.Base(filename)

p := &packagePrinter{}
p := printer.NewKlogPrinter()

tests := []struct {
name string
Expand Down
19 changes: 19 additions & 0 deletions pkg/printer/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package fake
import (
"context"
"io"
"time"

"github.com/kptdev/kpt/pkg/lib/pkg"
"github.com/kptdev/kpt/pkg/printer"
Expand All @@ -29,6 +30,24 @@ type Printer struct {
errStream io.Writer
}

func (np *Printer) WithField(string, string) printer.Printer { return np }

func (np *Printer) WithFields(printer.ContextualFields) printer.Printer { return np }

func (np *Printer) WithPackage(string) printer.Printer { return np }

func (np *Printer) WithFunction(string, string) printer.Printer { return np }

func (np *Printer) PrintRunning(string, int) {}

func (np *Printer) PrintPass(string, time.Duration) {}

func (np *Printer) PrintFail(string, time.Duration, error) {}

func (np *Printer) PrintResult(string, string, string) {}

func (np *Printer) PrintSummary(int, int, time.Duration) {}

func (np *Printer) PrintPackage(*pkg.Pkg, bool) {}

func (np *Printer) OptPrintf(*printer.Options, string, ...any) {}
Expand Down
Loading
Loading