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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/Kptfile b/Kptfile
index 2336da4..c1090e8 100644
index 2336da4..ca2bcea 100644
--- a/Kptfile
+++ b/Kptfile
@@ -2,13 +2,34 @@ apiVersion: kpt.dev/v1
Expand Down Expand Up @@ -27,14 +27,14 @@ index 2336da4..c1090e8 100644
+ reason: RenderSuccess
+ renderStatus:
+ mutationSteps:
+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace
+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.4.3
+ exitCode: 0
+ results:
+ - message: namespace [default] updated to "staging", 1 value(s) changed
+ severity: info
+ - message: all `depends-on` annotations are up-to-date. no `namespace` changed
+ severity: info
+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels
+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.2.4
+ exitCode: 0
+ results:
+ - message: set 4 labels in total
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/Kptfile b/Kptfile
index 2985a1a..1cc880e 100644
index 2985a1a..30b4376 100644
--- a/Kptfile
+++ b/Kptfile
@@ -2,8 +2,19 @@ apiVersion: kpt.dev/v1
Expand All @@ -20,7 +20,7 @@ index 2985a1a..1cc880e 100644
+ reason: RenderSuccess
+ renderStatus:
+ mutationSteps:
+ - image: set-labels:v0.1.5
+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5
+ exitCode: 0
diff --git a/kustomization.yaml b/kustomization.yaml
index f3f0207..6c517af 100644
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/Kptfile b/Kptfile
index 11012de..9fadb6e 100644
index 11012de..a0f4634 100644
--- a/Kptfile
+++ b/Kptfile
@@ -7,6 +7,26 @@ pipeline:
Expand All @@ -22,11 +22,11 @@ index 11012de..9fadb6e 100644
+ mutationSteps:
+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0
+ exitCode: 0
+ - image: ghcr.io/kptdev/krm-functions-catalog/dne
+ - image: ghcr.io/kptdev/krm-functions-catalog/dne:latest
+ stderr: |-
+ docker: Error response from daemon: error from registry: denied
+ denied
+
+ Run 'docker run --help' for more information
+ exitCode: 125
+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/dne: exit code 125'
+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/dne:latest: exit code 125'
4 changes: 2 additions & 2 deletions e2e/testdata/fn-render/no-op/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/Kptfile b/Kptfile
index a7a2d0b..ed39ce3 100644
index a7a2d0b..3dbfee4 100644
--- a/Kptfile
+++ b/Kptfile
@@ -5,3 +5,12 @@ metadata:
Expand All @@ -13,5 +13,5 @@ index a7a2d0b..ed39ce3 100644
+ reason: RenderSuccess
+ renderStatus:
+ mutationSteps:
+ - image: ghcr.io/kptdev/krm-functions-catalog/no-op
+ - image: ghcr.io/kptdev/krm-functions-catalog/no-op:latest
+ exitCode: 0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/Kptfile b/Kptfile
index d4e5935..0759cb0 100644
index d4e5935..24022da 100644
--- a/Kptfile
+++ b/Kptfile
@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1
Expand All @@ -23,9 +23,9 @@ index d4e5935..0759cb0 100644
+ reason: RenderSuccess
+ renderStatus:
+ mutationSteps:
+ - image: set-namespace:v0.2.0
+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0
+ exitCode: 0
+ - image: set-labels:v0.1.5
+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5
+ exitCode: 0
diff --git a/resources.yaml b/resources.yaml
index f2eec52..84cfb26 100644
Expand Down
16 changes: 0 additions & 16 deletions internal/fnruntime/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ type ContainerFn struct {

// Image is the container image to run
Image string
Tag string
// ImagePullPolicy controls the image pulling behavior.
ImagePullPolicy runneroptions.ImagePullPolicy
// Container function will be killed after this timeour.
Expand Down Expand Up @@ -152,21 +151,6 @@ func (f *ContainerFn) Run(reader io.Reader, writer io.Writer) error {
return err
}

if f.Tag != "" {
tagResolver := &TagResolver{
lister: &RegClientLister{
client: regclient.New(
regclient.WithUserAgent(UserAgent),
regclient.WithDockerCreds(),
),
},
}
f.Image, err = tagResolver.ResolveFunctionImage(f.Ctx, f.Image, f.Tag)
if err != nil {
return err
}
}

switch runtime {
case Podman:
return f.runCLI(reader, writer, podmanBin, filterPodmanCLIOutput)
Expand Down
31 changes: 30 additions & 1 deletion internal/fnruntime/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/kptdev/kpt/pkg/lib/errors"
"github.com/kptdev/kpt/pkg/lib/runneroptions"
"github.com/kptdev/kpt/pkg/printer"
"github.com/regclient/regclient"
"sigs.k8s.io/kustomize/kyaml/filesys"
"sigs.k8s.io/kustomize/kyaml/fn/framework"
"sigs.k8s.io/kustomize/kyaml/fn/runtime/runtimeutil"
Expand All @@ -60,6 +61,23 @@ func NewRunner(
if f.Image != "" {
img := opts.ResolveToImage(f.Image)
f.Image = img

if f.Tag != "" {
tagResolver := &TagResolver{
lister: &RegClientLister{
client: regclient.New(
regclient.WithUserAgent(UserAgent),
regclient.WithDockerCreds(),
),
},
}
f.Image, err = tagResolver.ResolveFunctionImage(ctx, f.Image, f.Tag)
if err != nil {
return nil, err
}
} else if !hasTagOrDigest(f.Image) {
f.Image += ":latest"
}
}

fnResult := &fnresult.Result{
Expand Down Expand Up @@ -103,7 +121,6 @@ func NewRunner(
} else {
cfn := &ContainerFn{
Image: f.Image,
Tag: f.Tag,
ImagePullPolicy: opts.ImagePullPolicy,
Perm: ContainerFnPermission{
AllowNetwork: opts.AllowNetwork,
Expand Down Expand Up @@ -505,3 +522,15 @@ func newFnConfig(fsys filesys.FileSystem, f *kptfilev1.Function, pkgPath types.U
// no need to return ConfigMap if no config given
return nil, nil
}

// hasTagOrDigest reports whether the image reference contains an explicit tag or digest.
func hasTagOrDigest(image string) bool {
if strings.Contains(image, "@") {
return true
}
lastSlash := strings.LastIndex(image, "/")
if lastSlash == -1 {
return strings.Contains(image, ":")
}
return strings.Contains(image[lastSlash:], ":")
}
35 changes: 35 additions & 0 deletions internal/fnruntime/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,3 +658,38 @@ func getExpectedPrefix(prefix string) string {
}
return prefix
}

func TestHasTagOrDigest(t *testing.T) {
tests := []struct {
name string
image string
want bool
}{
// With explicit tag
{"tag", "nginx:1.25", true},
{"latest tag", "nginx:latest", true},
{"full path with tag", "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5", true},

// With digest
{"digest only", "nginx@sha256:abc123", true},
{"full path with digest", "ghcr.io/kptdev/krm-functions-catalog/set-labels@sha256:abc123", true},
{"tag and digest", "nginx:1.25@sha256:abc123", true},

// Without tag or digest
{"bare image", "nginx", false},
{"full path no tag", "ghcr.io/kptdev/krm-functions-catalog/set-labels", false},
{"two-part no tag", "library/nginx", false},

// Registry with port (should not confuse port colon with tag colon)
{"registry port no tag", "localhost:5000/myimage", false},
{"registry port with tag", "localhost:5000/myimage:v1", true},
{"registry port with digest", "localhost:5000/myimage@sha256:abc123", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := hasTagOrDigest(tt.image); got != tt.want {
t.Errorf("hasTagOrDigest(%q) = %v, want %v", tt.image, got, tt.want)
}
})
}
}
7 changes: 3 additions & 4 deletions internal/util/render/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,18 +982,17 @@ func fnChain(ctx context.Context, hctx *hydrationContext, pkgPath types.UniquePa
for i := range fns {
var err error
var runner *fnruntime.FunctionRunner
function := fns[i]
displayResourceCount := false
if len(function.Selectors) > 0 || len(function.Exclusions) > 0 {
if len(fns[i].Selectors) > 0 || len(fns[i].Exclusions) > 0 {
displayResourceCount = true
}
if function.Exec != "" && !hctx.runnerOptions.AllowExec {
if fns[i].Exec != "" && !hctx.runnerOptions.AllowExec {
return nil, i, errAllowedExecNotSpecified
}
opts := hctx.runnerOptions
opts.SetPkgPathAnnotation = true
opts.DisplayResourceCount = displayResourceCount
runner, err = fnruntime.NewRunner(ctx, hctx.fileSystem, &function, pkgPath, hctx.fnResults, opts, hctx.runtime)
runner, err = fnruntime.NewRunner(ctx, hctx.fileSystem, &fns[i], pkgPath, hctx.fnResults, opts, hctx.runtime)
if err != nil {
return nil, i, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/kptfile/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ type PipelineStepResult struct {

// ResultItem mirrors framework.Result with only the fields needed for Kptfile status.
type ResultItem struct {
Message string `yaml:"message,omitempty" json:"message,omitempty"`
Severity string `yaml:"severity,omitempty" json:"severity,omitempty"`
Message string `yaml:"message,omitempty" json:"message,omitempty"`
Severity string `yaml:"severity,omitempty" json:"severity,omitempty"`
ResourceRef *ResourceRef `yaml:"resourceRef,omitempty" json:"resourceRef,omitempty"`
Field *FieldRef `yaml:"field,omitempty" json:"field,omitempty"`
File *FileRef `yaml:"file,omitempty" json:"file,omitempty"`
Expand Down
Loading