From 11c84377f6dff5d930f5c22bd74e3d8b8c5faef3 Mon Sep 17 00:00:00 2001 From: Nic Cope Date: Wed, 1 Nov 2023 14:07:17 -0700 Subject: [PATCH] Bump k8s.io/utils Including replacing the newly deprecated pointer package with the ptr package. Signed-off-by: Nic Cope --- connection_test.go | 14 +++---- fn_test.go | 34 ++++++++-------- go.mod | 2 +- go.sum | 4 +- patches_test.go | 96 +++++++++++++++++++++++----------------------- ready_test.go | 44 ++++++++++----------- transforms.go | 4 +- transforms_test.go | 38 +++++++++--------- validate_test.go | 38 +++++++++--------- 9 files changed, 137 insertions(+), 137 deletions(-) diff --git a/connection_test.go b/connection_test.go index 3ebd1c0..4ae6f63 100644 --- a/connection_test.go +++ b/connection_test.go @@ -6,7 +6,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "github.com/crossplane/crossplane-runtime/pkg/errors" "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" @@ -64,32 +64,32 @@ func TestExtractConnectionDetails(t *testing.T) { { Type: v1beta1.ConnectionDetailTypeFromConnectionSecretKey, Name: "bar", - FromConnectionSecretKey: pointer.String("bar"), + FromConnectionSecretKey: ptr.To[string]("bar"), }, { Type: v1beta1.ConnectionDetailTypeFromConnectionSecretKey, Name: "none", - FromConnectionSecretKey: pointer.String("none"), + FromConnectionSecretKey: ptr.To[string]("none"), }, { Type: v1beta1.ConnectionDetailTypeFromConnectionSecretKey, Name: "convfoo", - FromConnectionSecretKey: pointer.String("foo"), + FromConnectionSecretKey: ptr.To[string]("foo"), }, { Type: v1beta1.ConnectionDetailTypeFromValue, Name: "fixed", - Value: pointer.String("value"), + Value: ptr.To[string]("value"), }, { Type: v1beta1.ConnectionDetailTypeFromFieldPath, Name: "name", - FromFieldPath: pointer.String("objectMeta.name"), + FromFieldPath: ptr.To[string]("objectMeta.name"), }, { Type: v1beta1.ConnectionDetailTypeFromFieldPath, Name: "generation", - FromFieldPath: pointer.String("objectMeta.generation"), + FromFieldPath: ptr.To[string]("objectMeta.generation"), }, }, }, diff --git a/fn_test.go b/fn_test.go index f0cfde8..ea1fa3e 100644 --- a/fn_test.go +++ b/fn_test.go @@ -11,7 +11,7 @@ import ( "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/structpb" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "github.com/crossplane/crossplane-runtime/pkg/logging" @@ -159,8 +159,8 @@ func TestRunFunction(t *testing.T) { Patches: []v1beta1.Patch{ { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("spec.widgets"), - ToFieldPath: pointer.String("spec.watchers"), + FromFieldPath: ptr.To[string]("spec.widgets"), + ToFieldPath: ptr.To[string]("spec.watchers"), Transforms: []v1beta1.Transform{ { Type: v1beta1.TransformTypeConvert, @@ -172,7 +172,7 @@ func TestRunFunction(t *testing.T) { Type: v1beta1.TransformTypeMath, Math: &v1beta1.MathTransform{ Type: v1beta1.MathTransformTypeMultiply, - Multiply: pointer.Int64(3), + Multiply: ptr.To[int64](3), }, }, }, @@ -224,8 +224,8 @@ func TestRunFunction(t *testing.T) { Patches: []v1beta1.Patch{ { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("spec.widgets"), - ToFieldPath: pointer.String("spec.watchers"), + FromFieldPath: ptr.To[string]("spec.widgets"), + ToFieldPath: ptr.To[string]("spec.watchers"), Transforms: []v1beta1.Transform{ { Type: v1beta1.TransformTypeConvert, @@ -237,7 +237,7 @@ func TestRunFunction(t *testing.T) { Type: v1beta1.TransformTypeMath, Math: &v1beta1.MathTransform{ Type: v1beta1.MathTransformTypeMultiply, - Multiply: pointer.Int64(3), + Multiply: ptr.To[int64](3), }, }, }, @@ -294,8 +294,8 @@ func TestRunFunction(t *testing.T) { Patches: []v1beta1.Patch{ { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("spec.widgets"), - ToFieldPath: pointer.String("spec.watchers"), + FromFieldPath: ptr.To[string]("spec.widgets"), + ToFieldPath: ptr.To[string]("spec.watchers"), }, }, }, @@ -391,16 +391,16 @@ func TestRunFunction(t *testing.T) { { // This patch should work. Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("spec.widgets"), - ToFieldPath: pointer.String("spec.watchers"), + FromFieldPath: ptr.To[string]("spec.widgets"), + ToFieldPath: ptr.To[string]("spec.watchers"), }, { // This patch should return an error, // because the required path does not // exist. Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("spec.doesNotExist"), - ToFieldPath: pointer.String("spec.explode"), + FromFieldPath: ptr.To[string]("spec.doesNotExist"), + ToFieldPath: ptr.To[string]("spec.explode"), Policy: &v1beta1.PatchPolicy{ FromFieldPath: func() *v1beta1.FromFieldPathPolicy { r := v1beta1.FromFieldPathPolicyRequired @@ -513,7 +513,7 @@ func TestRunFunction(t *testing.T) { { Type: v1beta1.ConnectionDetailTypeFromConnectionSecretKey, Name: "very", - FromConnectionSecretKey: pointer.String("very"), + FromConnectionSecretKey: ptr.To[string]("very"), }, }, }, @@ -575,8 +575,8 @@ func TestRunFunction(t *testing.T) { Patches: []v1beta1.Patch{ { Type: v1beta1.PatchTypeToCompositeFieldPath, - FromFieldPath: pointer.String("spec.widgets"), - ToFieldPath: pointer.String("spec.watchers"), + FromFieldPath: ptr.To[string]("spec.widgets"), + ToFieldPath: ptr.To[string]("spec.watchers"), Transforms: []v1beta1.Transform{ { Type: v1beta1.TransformTypeConvert, @@ -588,7 +588,7 @@ func TestRunFunction(t *testing.T) { Type: v1beta1.TransformTypeMath, Math: &v1beta1.MathTransform{ Type: v1beta1.MathTransformTypeMultiply, - Multiply: pointer.Int64(3), + Multiply: ptr.To[int64](3), }, }, }, diff --git a/go.mod b/go.mod index 787be9a..3e79a84 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( k8s.io/api v0.28.2 k8s.io/apiextensions-apiserver v0.27.3 k8s.io/apimachinery v0.28.2 - k8s.io/utils v0.0.0-20230505201702-9f6742963106 + k8s.io/utils v0.0.0-20230726121419-3b25d923346b sigs.k8s.io/controller-tools v0.12.1 ) diff --git a/go.sum b/go.sum index 513b374..5a90bca 100644 --- a/go.sum +++ b/go.sum @@ -622,8 +622,8 @@ k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5OhxCKlKJy0sHc+PcDwFB24dQ= k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM= -k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU= -k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI= +k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/patches_test.go b/patches_test.go index 9c702af..b6f6986 100644 --- a/patches_test.go +++ b/patches_test.go @@ -8,7 +8,7 @@ import ( "github.com/pkg/errors" extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "github.com/crossplane/crossplane-runtime/pkg/fieldpath" "github.com/crossplane/crossplane-runtime/pkg/resource" @@ -76,8 +76,8 @@ func TestPatchApply(t *testing.T) { args: args{ patch: v1beta1.Patch{ Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.labels"), - ToFieldPath: pointer.String("metadata.labels"), + FromFieldPath: ptr.To[string]("metadata.labels"), + ToFieldPath: ptr.To[string]("metadata.labels"), }, xr: &composite.Unstructured{ Unstructured: unstructured.Unstructured{Object: MustObject(`{ @@ -121,8 +121,8 @@ func TestPatchApply(t *testing.T) { args: args{ patch: v1beta1.Patch{ Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.name"), - ToFieldPath: pointer.String("metadata.ownerReferences[*].name"), + FromFieldPath: ptr.To[string]("metadata.name"), + ToFieldPath: ptr.To[string]("metadata.ownerReferences[*].name"), }, xr: &composite.Unstructured{ Unstructured: unstructured.Unstructured{Object: MustObject(`{ @@ -174,8 +174,8 @@ func TestPatchApply(t *testing.T) { args: args{ patch: v1beta1.Patch{ Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.name"), - ToFieldPath: pointer.String("metadata.ownerReferences[*].badField"), + FromFieldPath: ptr.To[string]("metadata.name"), + ToFieldPath: ptr.To[string]("metadata.ownerReferences[*].badField"), }, xr: &composite.Unstructured{ Unstructured: unstructured.Unstructured{Object: MustObject(`{ @@ -212,8 +212,8 @@ func TestPatchApply(t *testing.T) { args: args{ patch: v1beta1.Patch{ Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.labels"), - ToFieldPath: pointer.String("metadata.labels"), + FromFieldPath: ptr.To[string]("metadata.labels"), + ToFieldPath: ptr.To[string]("metadata.labels"), }, xr: &composite.Unstructured{ Unstructured: unstructured.Unstructured{Object: MustObject(`{ @@ -252,14 +252,14 @@ func TestPatchApply(t *testing.T) { args: args{ patch: v1beta1.Patch{ Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("wat"), + FromFieldPath: ptr.To[string]("wat"), Policy: &v1beta1.PatchPolicy{ FromFieldPath: func() *v1beta1.FromFieldPathPolicy { s := v1beta1.FromFieldPathPolicyRequired return &s }(), }, - ToFieldPath: pointer.String("wat"), + ToFieldPath: ptr.To[string]("wat"), }, xr: &composite.Unstructured{ Unstructured: unstructured.Unstructured{Object: MustObject(`{ @@ -298,8 +298,8 @@ func TestPatchApply(t *testing.T) { args: args{ patch: v1beta1.Patch{ Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.labels"), - ToFieldPath: pointer.String("metadata.labels"), + FromFieldPath: ptr.To[string]("metadata.labels"), + ToFieldPath: ptr.To[string]("metadata.labels"), }, xr: &composite.Unstructured{ Unstructured: unstructured.Unstructured{Object: MustObject(`{ @@ -325,8 +325,8 @@ func TestPatchApply(t *testing.T) { args: args{ patch: v1beta1.Patch{ Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.labels"), - ToFieldPath: pointer.String("metadata.labels"), + FromFieldPath: ptr.To[string]("metadata.labels"), + ToFieldPath: ptr.To[string]("metadata.labels"), }, xr: &composite.Unstructured{ Unstructured: unstructured.Unstructured{Object: MustObject(`{ @@ -367,7 +367,7 @@ func TestPatchApply(t *testing.T) { args: args{ patch: v1beta1.Patch{ Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.labels"), + FromFieldPath: ptr.To[string]("metadata.labels"), }, xr: &composite.Unstructured{ Unstructured: unstructured.Unstructured{Object: MustObject(`{ @@ -407,8 +407,8 @@ func TestPatchApply(t *testing.T) { args: args{ patch: v1beta1.Patch{ Type: v1beta1.PatchTypeToCompositeFieldPath, - FromFieldPath: pointer.String("metadata.labels"), - ToFieldPath: pointer.String("metadata.labels"), + FromFieldPath: ptr.To[string]("metadata.labels"), + ToFieldPath: ptr.To[string]("metadata.labels"), }, xr: &composite.Unstructured{ Unstructured: unstructured.Unstructured{Object: MustObject(`{ @@ -448,8 +448,8 @@ func TestPatchApply(t *testing.T) { args: args{ patch: v1beta1.Patch{ Type: v1beta1.PatchTypeToCompositeFieldPath, - FromFieldPath: pointer.String("metadata.name"), - ToFieldPath: pointer.String("metadata.ownerReferences[*].name"), + FromFieldPath: ptr.To[string]("metadata.name"), + ToFieldPath: ptr.To[string]("metadata.ownerReferences[*].name"), }, xr: &composite.Unstructured{ Unstructured: unstructured.Unstructured{Object: MustObject(`{ @@ -501,7 +501,7 @@ func TestPatchApply(t *testing.T) { args: args{ patch: v1beta1.Patch{ Type: v1beta1.PatchTypeCombineFromComposite, - ToFieldPath: pointer.String("metadata.labels.destination"), + ToFieldPath: ptr.To[string]("metadata.labels.destination"), // Missing a Combine field }, xr: &composite.Unstructured{}, @@ -526,7 +526,7 @@ func TestPatchApply(t *testing.T) { Strategy: v1beta1.CombineStrategyString, // Missing a String combine config. }, - ToFieldPath: pointer.String("metadata.labels.destination"), + ToFieldPath: ptr.To[string]("metadata.labels.destination"), }, xr: &composite.Unstructured{ Unstructured: unstructured.Unstructured{Object: MustObject(`{ @@ -556,7 +556,7 @@ func TestPatchApply(t *testing.T) { Strategy: v1beta1.CombineStrategyString, String: &v1beta1.StringCombine{Format: "%s-%s"}, }, - ToFieldPath: pointer.String("objectMeta.labels.destination"), + ToFieldPath: ptr.To[string]("objectMeta.labels.destination"), }, }, want: want{ @@ -580,7 +580,7 @@ func TestPatchApply(t *testing.T) { Strategy: v1beta1.CombineStrategyString, String: &v1beta1.StringCombine{Format: "%s-%s"}, }, - ToFieldPath: pointer.String("metadata.labels.destination"), + ToFieldPath: ptr.To[string]("metadata.labels.destination"), }, xr: &composite.Unstructured{ Unstructured: unstructured.Unstructured{Object: MustObject(`{ @@ -612,7 +612,7 @@ func TestPatchApply(t *testing.T) { Strategy: v1beta1.CombineStrategyString, String: &v1beta1.StringCombine{Format: "%s-%s"}, }, - ToFieldPath: pointer.String("metadata.labels.destination"), + ToFieldPath: ptr.To[string]("metadata.labels.destination"), }, xr: &composite.Unstructured{ Unstructured: unstructured.Unstructured{Object: MustObject(`{ @@ -667,7 +667,7 @@ func TestPatchApply(t *testing.T) { Strategy: v1beta1.CombineStrategyString, String: &v1beta1.StringCombine{Format: "%s-%s"}, }, - ToFieldPath: pointer.String("metadata.labels.destination"), + ToFieldPath: ptr.To[string]("metadata.labels.destination"), }, xr: &composite.Unstructured{ Unstructured: unstructured.Unstructured{Object: MustObject(`{ @@ -854,11 +854,11 @@ func TestComposedTemplates(t *testing.T) { Patches: []v1beta1.Patch{ { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.name"), + FromFieldPath: ptr.To[string]("metadata.name"), }, { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.namespace"), + FromFieldPath: ptr.To[string]("metadata.namespace"), }, }, }, @@ -870,11 +870,11 @@ func TestComposedTemplates(t *testing.T) { Patches: []v1beta1.Patch{ { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.name"), + FromFieldPath: ptr.To[string]("metadata.name"), }, { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.namespace"), + FromFieldPath: ptr.To[string]("metadata.namespace"), }, }, }, @@ -888,7 +888,7 @@ func TestComposedTemplates(t *testing.T) { Patches: []v1beta1.Patch{ { Type: v1beta1.PatchTypePatchSet, - PatchSetName: pointer.String("patch-set-1"), + PatchSetName: ptr.To[string]("patch-set-1"), }, }, }}, @@ -908,11 +908,11 @@ func TestComposedTemplates(t *testing.T) { Patches: []v1beta1.Patch{ { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.namespace"), + FromFieldPath: ptr.To[string]("metadata.namespace"), }, { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("spec.parameters.test"), + FromFieldPath: ptr.To[string]("spec.parameters.test"), }, }, }, @@ -921,11 +921,11 @@ func TestComposedTemplates(t *testing.T) { Patches: []v1beta1.Patch{ { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.annotations.patch-test-1"), + FromFieldPath: ptr.To[string]("metadata.annotations.patch-test-1"), }, { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.annotations.patch-test-2"), + FromFieldPath: ptr.To[string]("metadata.annotations.patch-test-2"), Transforms: []v1beta1.Transform{{ Type: v1beta1.TransformTypeMap, Map: &v1beta1.MapTransform{ @@ -944,15 +944,15 @@ func TestComposedTemplates(t *testing.T) { Patches: []v1beta1.Patch{ { Type: v1beta1.PatchTypePatchSet, - PatchSetName: pointer.String("patch-set-2"), + PatchSetName: ptr.To[string]("patch-set-2"), }, { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.name"), + FromFieldPath: ptr.To[string]("metadata.name"), }, { Type: v1beta1.PatchTypePatchSet, - PatchSetName: pointer.String("patch-set-1"), + PatchSetName: ptr.To[string]("patch-set-1"), }, }, }, @@ -960,7 +960,7 @@ func TestComposedTemplates(t *testing.T) { Patches: []v1beta1.Patch{ { Type: v1beta1.PatchTypePatchSet, - PatchSetName: pointer.String("patch-set-1"), + PatchSetName: ptr.To[string]("patch-set-1"), }, }, }, @@ -973,11 +973,11 @@ func TestComposedTemplates(t *testing.T) { Patches: []v1beta1.Patch{ { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.annotations.patch-test-1"), + FromFieldPath: ptr.To[string]("metadata.annotations.patch-test-1"), }, { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.annotations.patch-test-2"), + FromFieldPath: ptr.To[string]("metadata.annotations.patch-test-2"), Transforms: []v1beta1.Transform{{ Type: v1beta1.TransformTypeMap, Map: &v1beta1.MapTransform{ @@ -990,15 +990,15 @@ func TestComposedTemplates(t *testing.T) { }, { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.name"), + FromFieldPath: ptr.To[string]("metadata.name"), }, { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.namespace"), + FromFieldPath: ptr.To[string]("metadata.namespace"), }, { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("spec.parameters.test"), + FromFieldPath: ptr.To[string]("spec.parameters.test"), }, }, }, @@ -1006,11 +1006,11 @@ func TestComposedTemplates(t *testing.T) { Patches: []v1beta1.Patch{ { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("metadata.namespace"), + FromFieldPath: ptr.To[string]("metadata.namespace"), }, { Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("spec.parameters.test"), + FromFieldPath: ptr.To[string]("spec.parameters.test"), }, }, }, @@ -1081,7 +1081,7 @@ func TestResolveTransforms(t *testing.T) { Type: v1beta1.TransformTypeMath, Math: &v1beta1.MathTransform{ Type: v1beta1.MathTransformTypeMultiply, - Multiply: pointer.Int64(2), + Multiply: ptr.To[int64](2), }, }}, input: int64(2), @@ -1102,7 +1102,7 @@ func TestResolveTransforms(t *testing.T) { Type: v1beta1.TransformTypeMath, Math: &v1beta1.MathTransform{ Type: v1beta1.MathTransformTypeMultiply, - Multiply: pointer.Int64(2), + Multiply: ptr.To[int64](2), }, }}, input: int64(2), diff --git a/ready_test.go b/ready_test.go index baf88f4..5d3bad8 100644 --- a/ready_test.go +++ b/ready_test.go @@ -6,7 +6,7 @@ import ( "github.com/google/go-cmp/cmp" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" "github.com/crossplane/crossplane-runtime/pkg/errors" @@ -101,7 +101,7 @@ func TestIsReady(t *testing.T) { o: composed.New(), rc: []v1beta1.ReadinessCheck{{ Type: v1beta1.ReadinessCheckTypeNonEmpty, - FieldPath: pointer.String("metadata..uid"), + FieldPath: ptr.To[string]("metadata..uid"), }}, }, want: want{ @@ -114,7 +114,7 @@ func TestIsReady(t *testing.T) { o: composed.New(), rc: []v1beta1.ReadinessCheck{{ Type: v1beta1.ReadinessCheckTypeNonEmpty, - FieldPath: pointer.String("metadata.uid"), + FieldPath: ptr.To[string]("metadata.uid"), }}, }, want: want{ @@ -129,7 +129,7 @@ func TestIsReady(t *testing.T) { }), rc: []v1beta1.ReadinessCheck{{ Type: v1beta1.ReadinessCheckTypeNonEmpty, - FieldPath: pointer.String("metadata.uid"), + FieldPath: ptr.To[string]("metadata.uid"), }}, }, want: want{ @@ -142,8 +142,8 @@ func TestIsReady(t *testing.T) { o: composed.New(), rc: []v1beta1.ReadinessCheck{{ Type: v1beta1.ReadinessCheckTypeMatchString, - FieldPath: pointer.String("metadata..uid"), - MatchString: pointer.String("cool"), + FieldPath: ptr.To[string]("metadata..uid"), + MatchString: ptr.To[string]("cool"), }}, }, want: want{ @@ -156,8 +156,8 @@ func TestIsReady(t *testing.T) { o: composed.New(), rc: []v1beta1.ReadinessCheck{{ Type: v1beta1.ReadinessCheckTypeMatchString, - FieldPath: pointer.String("metadata.uid"), - MatchString: pointer.String("olala"), + FieldPath: ptr.To[string]("metadata.uid"), + MatchString: ptr.To[string]("olala"), }}, }, want: want{ @@ -172,8 +172,8 @@ func TestIsReady(t *testing.T) { }), rc: []v1beta1.ReadinessCheck{{ Type: v1beta1.ReadinessCheckTypeMatchString, - FieldPath: pointer.String("metadata.uid"), - MatchString: pointer.String("olala"), + FieldPath: ptr.To[string]("metadata.uid"), + MatchString: ptr.To[string]("olala"), }}, }, want: want{ @@ -186,8 +186,8 @@ func TestIsReady(t *testing.T) { o: composed.New(), rc: []v1beta1.ReadinessCheck{{ Type: v1beta1.ReadinessCheckTypeMatchInteger, - FieldPath: pointer.String("metadata..uid"), - MatchInteger: pointer.Int64(42), + FieldPath: ptr.To[string]("metadata..uid"), + MatchInteger: ptr.To[int64](42), }}, }, want: want{ @@ -206,8 +206,8 @@ func TestIsReady(t *testing.T) { }), rc: []v1beta1.ReadinessCheck{{ Type: v1beta1.ReadinessCheckTypeMatchInteger, - FieldPath: pointer.String("spec.someNum"), - MatchInteger: pointer.Int64(5), + FieldPath: ptr.To[string]("spec.someNum"), + MatchInteger: ptr.To[int64](5), }}, }, want: want{ @@ -226,8 +226,8 @@ func TestIsReady(t *testing.T) { }), rc: []v1beta1.ReadinessCheck{{ Type: v1beta1.ReadinessCheckTypeMatchInteger, - FieldPath: pointer.String("spec.someNum"), - MatchInteger: pointer.Int64(5), + FieldPath: ptr.To[string]("spec.someNum"), + MatchInteger: ptr.To[int64](5), }}, }, want: want{ @@ -244,7 +244,7 @@ func TestIsReady(t *testing.T) { }), rc: []v1beta1.ReadinessCheck{{ Type: v1beta1.ReadinessCheckTypeMatchTrue, - FieldPath: pointer.String("spec.someBool"), + FieldPath: ptr.To[string]("spec.someBool"), }}, }, want: want{ @@ -263,7 +263,7 @@ func TestIsReady(t *testing.T) { }), rc: []v1beta1.ReadinessCheck{{ Type: v1beta1.ReadinessCheckTypeMatchTrue, - FieldPath: pointer.String("spec.someBool"), + FieldPath: ptr.To[string]("spec.someBool"), }}, }, want: want{ @@ -282,7 +282,7 @@ func TestIsReady(t *testing.T) { }), rc: []v1beta1.ReadinessCheck{{ Type: v1beta1.ReadinessCheckTypeMatchTrue, - FieldPath: pointer.String("spec.someBool"), + FieldPath: ptr.To[string]("spec.someBool"), }}, }, want: want{ @@ -299,7 +299,7 @@ func TestIsReady(t *testing.T) { }), rc: []v1beta1.ReadinessCheck{{ Type: v1beta1.ReadinessCheckTypeMatchFalse, - FieldPath: pointer.String("spec.someBool"), + FieldPath: ptr.To[string]("spec.someBool"), }}, }, want: want{ @@ -318,7 +318,7 @@ func TestIsReady(t *testing.T) { }), rc: []v1beta1.ReadinessCheck{{ Type: v1beta1.ReadinessCheckTypeMatchFalse, - FieldPath: pointer.String("spec.someBool"), + FieldPath: ptr.To[string]("spec.someBool"), }}, }, want: want{ @@ -337,7 +337,7 @@ func TestIsReady(t *testing.T) { }), rc: []v1beta1.ReadinessCheck{{ Type: v1beta1.ReadinessCheckTypeMatchFalse, - FieldPath: pointer.String("spec.someBool"), + FieldPath: ptr.To[string]("spec.someBool"), }}, }, want: want{ diff --git a/transforms.go b/transforms.go index ada99cf..c1a20c5 100644 --- a/transforms.go +++ b/transforms.go @@ -15,7 +15,7 @@ import ( extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "github.com/crossplane/crossplane-runtime/pkg/errors" @@ -360,7 +360,7 @@ func stringRegexpTransform(input any, r v1beta1.StringTransformRegexp) (string, groups := re.FindStringSubmatch(fmt.Sprintf("%v", input)) // Return the entire match (group zero) by default. - g := pointer.IntDeref(r.Group, 0) + g := ptr.Deref[int](r.Group, 0) if len(groups) == 0 || g >= len(groups) { return "", errors.Errorf(errStringTransformTypeRegexpNoMatch, r.Match, g) } diff --git a/transforms_test.go b/transforms_test.go index e1b0937..be328e1 100644 --- a/transforms_test.go +++ b/transforms_test.go @@ -9,7 +9,7 @@ import ( extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/validation/field" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "github.com/crossplane/crossplane-runtime/pkg/errors" "github.com/crossplane/crossplane-runtime/pkg/test" @@ -153,7 +153,7 @@ func TestMatchResolve(t *testing.T) { Patterns: []v1beta1.MatchTransformPattern{ { Type: v1beta1.MatchTransformPatternTypeLiteral, - Literal: pointer.String("5"), + Literal: ptr.To[string]("5"), }, }, }, @@ -242,7 +242,7 @@ func TestMatchResolve(t *testing.T) { Patterns: []v1beta1.MatchTransformPattern{ { Type: v1beta1.MatchTransformPatternTypeLiteral, - Literal: pointer.String("foo"), + Literal: ptr.To[string]("foo"), Result: asJSON("bar"), }, }, @@ -259,12 +259,12 @@ func TestMatchResolve(t *testing.T) { Patterns: []v1beta1.MatchTransformPattern{ { Type: v1beta1.MatchTransformPatternTypeLiteral, - Literal: pointer.String("foo"), + Literal: ptr.To[string]("foo"), Result: asJSON("bar"), }, { Type: v1beta1.MatchTransformPatternTypeLiteral, - Literal: pointer.String("foo"), + Literal: ptr.To[string]("foo"), Result: asJSON("not this"), }, }, @@ -281,7 +281,7 @@ func TestMatchResolve(t *testing.T) { Patterns: []v1beta1.MatchTransformPattern{ { Type: v1beta1.MatchTransformPatternTypeLiteral, - Literal: pointer.String("foo"), + Literal: ptr.To[string]("foo"), Result: asJSON(map[string]interface{}{ "Hello": "World", }), @@ -302,7 +302,7 @@ func TestMatchResolve(t *testing.T) { Patterns: []v1beta1.MatchTransformPattern{ { Type: v1beta1.MatchTransformPatternTypeLiteral, - Literal: pointer.String("foo"), + Literal: ptr.To[string]("foo"), Result: asJSON([]string{ "Hello", "World", }), @@ -323,7 +323,7 @@ func TestMatchResolve(t *testing.T) { Patterns: []v1beta1.MatchTransformPattern{ { Type: v1beta1.MatchTransformPatternTypeLiteral, - Literal: pointer.String("foo"), + Literal: ptr.To[string]("foo"), Result: asJSON(5), }, }, @@ -340,7 +340,7 @@ func TestMatchResolve(t *testing.T) { Patterns: []v1beta1.MatchTransformPattern{ { Type: v1beta1.MatchTransformPatternTypeLiteral, - Literal: pointer.String("foo"), + Literal: ptr.To[string]("foo"), Result: asJSON(true), }, }, @@ -357,7 +357,7 @@ func TestMatchResolve(t *testing.T) { Patterns: []v1beta1.MatchTransformPattern{ { Type: v1beta1.MatchTransformPatternTypeLiteral, - Literal: pointer.String("foo"), + Literal: ptr.To[string]("foo"), Result: asJSON(nil), }, }, @@ -372,7 +372,7 @@ func TestMatchResolve(t *testing.T) { Patterns: []v1beta1.MatchTransformPattern{ { Type: v1beta1.MatchTransformPatternTypeRegexp, - Regexp: pointer.String("^foo.*$"), + Regexp: ptr.To[string]("^foo.*$"), Result: asJSON("Hello World"), }, }, @@ -403,7 +403,7 @@ func TestMatchResolve(t *testing.T) { Patterns: []v1beta1.MatchTransformPattern{ { Type: v1beta1.MatchTransformPatternTypeRegexp, - Regexp: pointer.String("?="), + Regexp: ptr.To[string]("?="), }, }, }, @@ -957,7 +957,7 @@ func TestStringResolve(t *testing.T) { stype: v1beta1.StringTransformTypeRegexp, regexp: &v1beta1.StringTransformRegexp{ Match: "my-([0-9]+)-string", - Group: pointer.Int(1), + Group: ptr.To[int](1), }, i: "my-1-string", }, @@ -970,7 +970,7 @@ func TestStringResolve(t *testing.T) { stype: v1beta1.StringTransformTypeRegexp, regexp: &v1beta1.StringTransformRegexp{ Match: "my-([0-9]+)-string", - Group: pointer.Int(2), + Group: ptr.To[int](2), }, i: "my-1-string", }, @@ -1063,7 +1063,7 @@ func TestConvertResolve(t *testing.T) { args: args{ i: "1000m", to: v1beta1.TransformIOTypeFloat64, - format: (*v1beta1.ConvertTransformFormat)(pointer.String(string(v1beta1.ConvertTransformFormatQuantity))), + format: (*v1beta1.ConvertTransformFormat)(ptr.To[string](string(v1beta1.ConvertTransformFormatQuantity))), }, want: want{ o: 1.0, @@ -1073,7 +1073,7 @@ func TestConvertResolve(t *testing.T) { args: args{ i: "1000 blabla", to: v1beta1.TransformIOTypeFloat64, - format: (*v1beta1.ConvertTransformFormat)(pointer.String(string(v1beta1.ConvertTransformFormatQuantity))), + format: (*v1beta1.ConvertTransformFormat)(ptr.To[string](string(v1beta1.ConvertTransformFormatQuantity))), }, want: want{ err: resource.ErrFormatWrong, @@ -1101,7 +1101,7 @@ func TestConvertResolve(t *testing.T) { args: args{ i: "{\"foo\":\"bar\"}", to: v1beta1.TransformIOTypeObject, - format: (*v1beta1.ConvertTransformFormat)(pointer.String(string(v1beta1.ConvertTransformFormatJSON))), + format: (*v1beta1.ConvertTransformFormat)(ptr.To[string](string(v1beta1.ConvertTransformFormatJSON))), }, want: want{ o: map[string]any{ @@ -1113,7 +1113,7 @@ func TestConvertResolve(t *testing.T) { args: args{ i: "[\"foo\", \"bar\", \"baz\"]", to: v1beta1.TransformIOTypeArray, - format: (*v1beta1.ConvertTransformFormat)(pointer.String(string(v1beta1.ConvertTransformFormatJSON))), + format: (*v1beta1.ConvertTransformFormat)(ptr.To[string](string(v1beta1.ConvertTransformFormatJSON))), }, want: want{ o: []any{ @@ -1134,7 +1134,7 @@ func TestConvertResolve(t *testing.T) { args: args{ i: 100, to: v1beta1.TransformIOTypeString, - format: (*v1beta1.ConvertTransformFormat)(pointer.String(string(v1beta1.ConvertTransformFormatQuantity))), + format: (*v1beta1.ConvertTransformFormat)(ptr.To[string](string(v1beta1.ConvertTransformFormatQuantity))), }, want: want{ err: errors.Errorf(errFmtConvertFormatPairNotSupported, "int", "string", string(v1beta1.ConvertTransformFormatQuantity)), diff --git a/validate_test.go b/validate_test.go index c16d951..69e7c52 100644 --- a/validate_test.go +++ b/validate_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/util/validation/field" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "github.com/crossplane-contrib/function-patch-and-transform/input/v1beta1" ) @@ -38,8 +38,8 @@ func TestValidateReadinessCheck(t *testing.T) { args: args{ r: v1beta1.ReadinessCheck{ Type: v1beta1.ReadinessCheckTypeMatchString, - MatchString: pointer.String("foo"), - FieldPath: pointer.String("spec.foo"), + MatchString: ptr.To[string]("foo"), + FieldPath: ptr.To[string]("spec.foo"), }, }, }, @@ -52,7 +52,7 @@ func TestValidateReadinessCheck(t *testing.T) { Type: "someType", Status: "someStatus", }, - FieldPath: pointer.String("spec.foo"), + FieldPath: ptr.To[string]("spec.foo"), }, }, }, @@ -61,7 +61,7 @@ func TestValidateReadinessCheck(t *testing.T) { args: args{ r: v1beta1.ReadinessCheck{ Type: v1beta1.ReadinessCheckTypeMatchTrue, - FieldPath: pointer.String("spec.foo"), + FieldPath: ptr.To[string]("spec.foo"), }, }, }, @@ -70,7 +70,7 @@ func TestValidateReadinessCheck(t *testing.T) { args: args{ r: v1beta1.ReadinessCheck{ Type: v1beta1.ReadinessCheckTypeMatchFalse, - FieldPath: pointer.String("spec.foo"), + FieldPath: ptr.To[string]("spec.foo"), }, }, }, @@ -191,7 +191,7 @@ func TestValidateConnectionDetail(t *testing.T) { cd: v1beta1.ConnectionDetail{ Type: v1beta1.ConnectionDetailTypeFromValue, Name: "cool", - Value: pointer.String("cooler"), + Value: ptr.To[string]("cooler"), }, }, want: want{ @@ -204,7 +204,7 @@ func TestValidateConnectionDetail(t *testing.T) { cd: v1beta1.ConnectionDetail{ Type: v1beta1.ConnectionDetailTypeFromConnectionSecretKey, Name: "cool", - FromConnectionSecretKey: pointer.String("key"), + FromConnectionSecretKey: ptr.To[string]("key"), }, }, want: want{ @@ -217,7 +217,7 @@ func TestValidateConnectionDetail(t *testing.T) { cd: v1beta1.ConnectionDetail{ Type: v1beta1.ConnectionDetailTypeFromFieldPath, Name: "cool", - FromFieldPath: pointer.String("status.coolness"), + FromFieldPath: ptr.To[string]("status.coolness"), }, }, want: want{ @@ -254,7 +254,7 @@ func TestValidatePatch(t *testing.T) { args: args{ patch: v1beta1.Patch{ Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("spec.forProvider.foo"), + FromFieldPath: ptr.To[string]("spec.forProvider.foo"), }, }, }, @@ -263,7 +263,7 @@ func TestValidatePatch(t *testing.T) { args: args{ patch: v1beta1.Patch{ Type: v1beta1.PatchTypeFromCompositeFieldPath, - FromFieldPath: pointer.String("spec.forProvider.foo"), + FromFieldPath: ptr.To[string]("spec.forProvider.foo"), Transforms: []v1beta1.Transform{ { Type: v1beta1.TransformTypeMath, @@ -390,7 +390,7 @@ func TestValidateTransform(t *testing.T) { Type: v1beta1.TransformTypeMath, Math: &v1beta1.MathTransform{ Type: v1beta1.MathTransformTypeMultiply, - Multiply: pointer.Int64(2), + Multiply: ptr.To[int64](2), }, }, }, @@ -402,7 +402,7 @@ func TestValidateTransform(t *testing.T) { Type: v1beta1.TransformTypeMath, Math: &v1beta1.MathTransform{ Type: v1beta1.MathTransformTypeClampMin, - ClampMin: pointer.Int64(10), + ClampMin: ptr.To[int64](10), }, }, }, @@ -414,7 +414,7 @@ func TestValidateTransform(t *testing.T) { Type: v1beta1.TransformTypeMath, Math: &v1beta1.MathTransform{ Type: v1beta1.MathTransformTypeMultiply, - ClampMin: pointer.Int64(10), + ClampMin: ptr.To[int64](10), }, }, }, @@ -522,7 +522,7 @@ func TestValidateTransform(t *testing.T) { Patterns: []v1beta1.MatchTransformPattern{ { Type: v1beta1.MatchTransformPatternTypeRegexp, - Regexp: pointer.String(".*"), + Regexp: ptr.To[string](".*"), }, }, }, @@ -538,7 +538,7 @@ func TestValidateTransform(t *testing.T) { Patterns: []v1beta1.MatchTransformPattern{ { Type: v1beta1.MatchTransformPatternTypeRegexp, - Regexp: pointer.String("?"), + Regexp: ptr.To[string]("?"), }, }, }, @@ -560,10 +560,10 @@ func TestValidateTransform(t *testing.T) { Patterns: []v1beta1.MatchTransformPattern{ { Type: v1beta1.MatchTransformPatternTypeLiteral, - Literal: pointer.String("foo"), + Literal: ptr.To[string]("foo"), }, { - Literal: pointer.String("bar"), + Literal: ptr.To[string]("bar"), }, }, }, @@ -592,7 +592,7 @@ func TestValidateTransform(t *testing.T) { Type: v1beta1.TransformTypeString, String: &v1beta1.StringTransform{ Type: v1beta1.StringTransformTypeFormat, - Format: pointer.String("foo"), + Format: ptr.To[string]("foo"), }, }, },