Skip to content

Commit 30c074c

Browse files
Use API v0.0.2 and SDK v1.1.0 (#4620)
* use api v0.0.2 and sdk v1.1.0 Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com> * Apply doc comment suggestions Signed-off-by: mozesl-nokia <laszlo.mozes@nokia.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * remove adding v prefix Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com> --------- Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent c5b53cc commit 30c074c

9 files changed

Lines changed: 62 additions & 27 deletions

File tree

‎go.mod‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ require (
1313
github.com/google/go-cmp v0.7.0
1414
github.com/google/go-containerregistry v0.21.6
1515
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
16-
github.com/kptdev/kpt/api v0.0.1
17-
github.com/kptdev/krm-functions-sdk/go/fn v1.0.3
16+
github.com/kptdev/kpt/api v0.0.2
17+
github.com/kptdev/krm-functions-sdk/go/fn v1.1.0
1818
github.com/otiai10/copy v1.14.1
1919
github.com/philopon/go-toposort v0.0.0-20170620085441-9be86dbd762f
2020
github.com/pkg/errors v0.9.1
@@ -24,7 +24,6 @@ require (
2424
github.com/spf13/pflag v1.0.10
2525
github.com/stretchr/testify v1.11.1
2626
github.com/xlab/treeprint v1.2.0
27-
golang.org/x/mod v0.36.0
2827
gopkg.in/yaml.v2 v2.4.0
2928
gotest.tools/v3 v3.5.2
3029
k8s.io/api v0.36.1

‎go.sum‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
110110
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
111111
github.com/klauspost/compress v1.18.6 h1:2jupLlAwFm95+YDR+NwD2MEfFO9d4z4Prjl1XXDjuao=
112112
github.com/klauspost/compress v1.18.6/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
113-
github.com/kptdev/kpt/api v0.0.1 h1:1PZ/lA0IuMYkgrSXCJqk3fcVok8tyuP6gOmHhrTETdM=
114-
github.com/kptdev/kpt/api v0.0.1/go.mod h1:JviL89EPiMTdxSSJL9sXnOuckflKVXZKKDCu9YJ5kM4=
115-
github.com/kptdev/krm-functions-sdk/go/fn v1.0.3 h1:Gmkqbc2cbwJxamVoRSs409TZinuNGZaMYmNmlQcF6Bs=
116-
github.com/kptdev/krm-functions-sdk/go/fn v1.0.3/go.mod h1:+MgNIVQMGs6WcNhQZYIbgFINnmskX8VMYcUvJBtE01M=
113+
github.com/kptdev/kpt/api v0.0.2 h1:0AWWhw8/LapkPwDwImtJXUDx81U9nW+joYIzCl3S/68=
114+
github.com/kptdev/kpt/api v0.0.2/go.mod h1:D/WM1LJ/HvHt3cHxDs2mF6mXkA37BbD1nrcsAVWgbfE=
115+
github.com/kptdev/krm-functions-sdk/go/fn v1.1.0 h1:1+N9XdER7fGimWAUm35UWyRQfpx5b92nZlQGtuYdb5c=
116+
github.com/kptdev/krm-functions-sdk/go/fn v1.1.0/go.mod h1:rPrLdh02mfqq5PjZRrMr5mhRA6dkjKm7O4bm5VZJWOg=
117117
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
118118
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
119119
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
@@ -283,6 +283,8 @@ k8s.io/kubectl v0.36.1 h1:96HqS9twIdHM0MlJLTwbo14b9kUKPkOzZ4tlRDLv4qI=
283283
k8s.io/kubectl v0.36.1/go.mod h1:/DGPAIewKsFWF9VFgGvkPhao2Ev4SNuE3BioZo8yPbk=
284284
k8s.io/utils v0.0.0-20260507154919-ff6756f316d2 h1:wU4tMEhLGgIbLvXQb1cfN+EcM0wf7zC6CPF+C79jroc=
285285
k8s.io/utils v0.0.0-20260507154919-ff6756f316d2/go.mod h1:xDxuJ0whA3d0I4mf/C4ppKHxXynQ+fxnkmQH0vTHnuk=
286+
pgregory.net/rapid v1.3.0 h1:vBvO0VSqti75J1jjYqpgPNBLKMd1+gxa9fYo7vk/Exc=
287+
pgregory.net/rapid v1.3.0/go.mod h1:dPlE4OBBxgXPqkP79flB6sJL1dx5azpI7HQ9MY9Z7uk=
286288
sigs.k8s.io/cli-utils v0.37.2 h1:GOfKw5RV2HDQZDJlru5KkfLO1tbxqMoyn1IYUxqBpNg=
287289
sigs.k8s.io/cli-utils v0.37.2/go.mod h1:V+IZZr4UoGj7gMJXklWBg6t5xbdThFBcpj4MrZuCYco=
288290
sigs.k8s.io/controller-runtime v0.24.1 h1:miPEwrmirImAvgME1L9qebGHrOnGJoVmVdtOU9fRfo4=

‎pkg/fn/runtime/container.go‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ import (
2828
"sync"
2929
"time"
3030

31+
"github.com/Masterminds/semver/v3"
3132
fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1"
3233
"github.com/kptdev/kpt/pkg/lib/runneroptions"
3334
"github.com/kptdev/kpt/pkg/printer"
34-
"golang.org/x/mod/semver"
3535
"sigs.k8s.io/kustomize/kyaml/fn/runtime/runtimeutil"
3636
)
3737

@@ -62,6 +62,8 @@ const (
6262
Nerdctl ContainerRuntime = "nerdctl"
6363
)
6464

65+
var dockerVersionConstraint, _ = semver.NewConstraint(">=" + minSupportedDockerVersion)
66+
6567
type ContainerRuntime string
6668

6769
// ContainerFnPermission contains the permission of container
@@ -418,14 +420,10 @@ To install docker, follow the instructions at https://docs.docker.com/get-docker
418420
// or is less than minSupportedDockerVersion
419421
func isSupportedDockerVersion(v string) error {
420422
suggestedText := fmt.Sprintf(`docker client version must be %s or greater`, minSupportedDockerVersion)
421-
// docker version output does not have a leading v which is required by semver, so we prefix it
422-
currentDockerVersion := fmt.Sprintf("v%s", v)
423-
if !semver.IsValid(currentDockerVersion) {
424-
return fmt.Errorf("%s: found invalid version %s", suggestedText, currentDockerVersion)
425-
}
426-
// if currentDockerVersion is less than minDockerClientVersion, compare returns +1
427-
if semver.Compare(minSupportedDockerVersion, currentDockerVersion) > 0 {
428-
return fmt.Errorf("%s: found %s", suggestedText, currentDockerVersion)
423+
if ver, err := semver.NewVersion(v); err != nil {
424+
return fmt.Errorf("%s: found invalid version %s: %w", suggestedText, v, err)
425+
} else if !dockerVersionConstraint.Check(ver) {
426+
return fmt.Errorf("%s: found %s", suggestedText, v)
429427
}
430428
return nil
431429
}

‎pkg/fn/runtime/container_test.go‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1"
2525
"github.com/kptdev/kpt/pkg/printer"
2626
"github.com/stretchr/testify/assert"
27-
"github.com/stretchr/testify/require"
2827
)
2928

3029
func TestContainerFn(t *testing.T) {
@@ -126,23 +125,21 @@ func TestIsSupportedDockerVersion(t *testing.T) {
126125
{
127126
name: "less than min version",
128127
inputV: "20.9.1",
129-
errMsg: "docker client version must be v20.10.0 or greater: found v20.9.1",
128+
errMsg: "docker client version must be v20.10.0 or greater: found 20.9.1",
130129
},
131130
{
132131
name: "invalid semver",
133132
inputV: "20..12.1",
134-
errMsg: "docker client version must be v20.10.0 or greater: found invalid version v20..12.1",
133+
errMsg: "docker client version must be v20.10.0 or greater: found invalid version 20..12.1",
135134
},
136135
}
137136
for _, tt := range tests {
138137
t.Run(tt.name, func(t *testing.T) {
139-
require := require.New(t)
140138
err := isSupportedDockerVersion(tt.inputV)
141139
if tt.errMsg != "" {
142-
require.NotNil(err)
143-
require.Contains(err.Error(), tt.errMsg)
140+
assert.ErrorContains(t, err, tt.errMsg)
144141
} else {
145-
require.NoError(err)
142+
assert.NoError(t, err)
146143
}
147144
})
148145
}

‎pkg/kptfile/kptfileutil/gvk.go‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2026 The kpt Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package kptfileutil
16+
17+
import (
18+
kptapischema "github.com/kptdev/kpt/api/schema/v1"
19+
machineryschema "k8s.io/apimachinery/pkg/runtime/schema"
20+
)
21+
22+
// ToKptGVK converts an apimachinery GroupVersionKind to the kpt API schema GroupVersionKind.
23+
func ToKptGVK(gvk machineryschema.GroupVersionKind) kptapischema.GroupVersionKind {
24+
return kptapischema.GroupVersionKind{
25+
Group: gvk.Group,
26+
Version: gvk.Version,
27+
Kind: gvk.Kind,
28+
}
29+
}
30+
31+
// FromKptGVK converts a kpt API schema GroupVersionKind to an apimachinery GroupVersionKind.
32+
func FromKptGVK(gvk kptapischema.GroupVersionKind) machineryschema.GroupVersionKind {
33+
return machineryschema.GroupVersionKind{
34+
Group: gvk.Group,
35+
Version: gvk.Version,
36+
Kind: gvk.Kind,
37+
}
38+
}

‎pkg/kptfile/kptfileutil/util.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
"strings"
2626

2727
kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1"
28+
schema "github.com/kptdev/kpt/api/schema/v1"
2829
"github.com/kptdev/kpt/pkg/lib/errors"
2930
gitutil "github.com/kptdev/kpt/pkg/lib/util/git"
30-
"k8s.io/apimachinery/pkg/runtime/schema"
3131
"sigs.k8s.io/kustomize/kyaml/filesys"
3232
"sigs.k8s.io/kustomize/kyaml/sets"
3333
"sigs.k8s.io/kustomize/kyaml/yaml"

‎pkg/live/load.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ import (
2121

2222
kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1"
2323
rgfilev1alpha1 "github.com/kptdev/kpt/api/resourcegroup/v1alpha1"
24+
schema "github.com/kptdev/kpt/api/schema/v1"
2425
"github.com/kptdev/kpt/pkg/kptfile/kptfileutil"
2526
"github.com/kptdev/kpt/pkg/lib/errors"
2627
"github.com/kptdev/kpt/pkg/lib/pkg"
2728
pathutil "github.com/kptdev/kpt/pkg/lib/util/path"
2829
"github.com/kptdev/kpt/pkg/lib/util/strings"
2930
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
30-
"k8s.io/apimachinery/pkg/runtime/schema"
3131
"k8s.io/klog/v2"
3232
"k8s.io/kubectl/pkg/cmd/util"
3333
"sigs.k8s.io/cli-utils/pkg/common"

‎pkg/live/rgpath.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020

2121
rgfilev1alpha1 "github.com/kptdev/kpt/api/resourcegroup/v1alpha1"
22+
"github.com/kptdev/kpt/pkg/kptfile/kptfileutil"
2223
pathutil "github.com/kptdev/kpt/pkg/lib/util/path"
2324
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2425
"sigs.k8s.io/cli-utils/pkg/manifestreader"
@@ -67,7 +68,7 @@ func (r *ResourceGroupPathManifestReader) Read() ([]*unstructured.Unstructured,
6768
// Skip if current file is a ResourceGroup resource. We do not want to apply/delete any ResourceGroup CRs when we
6869
// run any `kpt live` commands on a package. Instead, we have specific logic in place for handling ResourceGroups in
6970
// the live cluster.
70-
if u.GroupVersionKind() == rgfilev1alpha1.ResourceGroupGVK() {
71+
if kptfileutil.ToKptGVK(u.GroupVersionKind()) == rgfilev1alpha1.ResourceGroupGVK() {
7172
continue
7273
}
7374
objs = append(objs, u)

‎pkg/live/rgstream.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020

2121
kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1"
2222
rgfilev1alpha1 "github.com/kptdev/kpt/api/resourcegroup/v1alpha1"
23+
schema "github.com/kptdev/kpt/api/schema/v1"
2324
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
24-
"k8s.io/apimachinery/pkg/runtime/schema"
2525
"sigs.k8s.io/cli-utils/pkg/manifestreader"
2626
"sigs.k8s.io/kustomize/kyaml/kio"
2727
"sigs.k8s.io/kustomize/kyaml/kio/kioutil"

0 commit comments

Comments
 (0)