Repository: crossplane/crossplane-runtime

Issue:
Deprecate the reference pointer helper functions
From @negz comment in: https://github.com/crossplane/crossplane-runtime/pull/754#discussion_r1710367975, copied here for convenience:

> Huh, I actually forgot we had these pointer helpers in runtime.
>
> We usually use https://pkg.go.dev/k8s.io/utils/ptr instead these days. I'd suggest that. We should probably deprecate the ones we have in runtime, but that can happen in a separate PR.

Source location: https://github.com/crossplane/crossplane-runtime/blob/master/pkg/reference/reference.go 

Discussion:

Solution patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 1ac43ed..5f31702 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -35,14 +35,14 @@ jobs:
           version: ${{ env.EARTHLY_VERSION }}
 
       - name: Login to DockerHub
-        uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3
+        uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
         if: env.DOCKER_USR != ''
         with:
           username: ${{ secrets.DOCKER_USR }}
           password: ${{ secrets.DOCKER_PSW }}
 
       - name: Login to GitHub Container Registry
-        uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3
+        uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
         with:
           registry: ghcr.io
           username: ${{ github.actor }}
@@ -81,14 +81,14 @@ jobs:
           version: ${{ env.EARTHLY_VERSION }}
 
       - name: Login to DockerHub
-        uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3
+        uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
         if: env.DOCKER_USR != ''
         with:
           username: ${{ secrets.DOCKER_USR }}
           password: ${{ secrets.DOCKER_PSW }}
 
       - name: Login to GitHub Container Registry
-        uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3
+        uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
         with:
           registry: ghcr.io
           username: ${{ github.actor }}
@@ -117,14 +117,14 @@ jobs:
           version: ${{ env.EARTHLY_VERSION }}
 
       - name: Login to DockerHub
-        uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3
+        uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
         if: env.DOCKER_USR != ''
         with:
           username: ${{ secrets.DOCKER_USR }}
           password: ${{ secrets.DOCKER_PSW }}
 
       - name: Login to GitHub Container Registry
-        uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3
+        uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
         with:
           registry: ghcr.io
           username: ${{ github.actor }}
@@ -152,7 +152,7 @@ jobs:
         uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
 
       - name: Run Trivy vulnerability scanner in fs mode
-        uses: aquasecurity/trivy-action@fd25fed6972e341ff0007ddb61f77e88103953c2 # 0.21.0
+        uses: aquasecurity/trivy-action@915b19bbe73b92a6cf82a1bc12b087c9a19a5fe2 # 0.28.0
         with:
           scan-type: 'fs'
           ignore-unfixed: true
@@ -181,14 +181,14 @@ jobs:
           version: ${{ env.EARTHLY_VERSION }}
 
       - name: Login to DockerHub
-        uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3
+        uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
         if: env.DOCKER_USR != ''
         with:
           username: ${{ secrets.DOCKER_USR }}
           password: ${{ secrets.DOCKER_PSW }}
 
       - name: Login to GitHub Container Registry
-        uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3
+        uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
         with:
           registry: ghcr.io
           username: ${{ github.actor }}
diff --git a/.github/workflows/renovate.yml b/.github/workflows/renovate.yml
index 0a1c498..94a3650 100644
--- a/.github/workflows/renovate.yml
+++ b/.github/workflows/renovate.yml
@@ -33,7 +33,7 @@ jobs:
 
       - name: Get token
         id: get-github-app-token
-        uses: actions/create-github-app-token@31c86eb3b33c9b601a1f60f98dcbfd1d70f379b4 # v1
+        uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1
         with:
           app-id: ${{ secrets.RENOVATE_GITHUB_APP_ID }}
           private-key: ${{ secrets.RENOVATE_GITHUB_APP_PRIVATE_KEY }}
diff --git a/Earthfile b/Earthfile
index 77c6e55..378bf8b 100644
--- a/Earthfile
+++ b/Earthfile
@@ -128,7 +128,7 @@ go-lint:
 
 # ci-codeql-setup sets up CodeQL for the ci-codeql target.
 ci-codeql-setup:
-  ARG CODEQL_VERSION=v2.17.3
+  ARG CODEQL_VERSION=v2.19.2
   FROM curlimages/curl:8.8.0
   RUN curl -fsSL https://github.com/github/codeql-action/releases/download/codeql-bundle-${CODEQL_VERSION}/codeql-bundle-linux64.tar.gz|tar zx
   SAVE ARTIFACT codeql
diff --git a/pkg/reconciler/managed/reconciler_typed.go b/pkg/reconciler/managed/reconciler_typed.go
index 1ca2772..3db15a9 100644
--- a/pkg/reconciler/managed/reconciler_typed.go
+++ b/pkg/reconciler/managed/reconciler_typed.go
@@ -52,6 +52,7 @@ func (c *typedExternalClientWrapper[managed]) Create(ctx context.Context, mg res
 	}
 	return c.c.Create(ctx, cr)
 }
+
 func (c *typedExternalClientWrapper[managed]) Update(ctx context.Context, mg resource.Managed) (ExternalUpdate, error) {
 	cr, ok := mg.(managed)
 	if !ok {
diff --git a/pkg/reference/reference.go b/pkg/reference/reference.go
index 3248e21..3c36d90 100644
--- a/pkg/reference/reference.go
+++ b/pkg/reference/reference.go
@@ -20,7 +20,6 @@ package reference
 
 import (
 	"context"
-	"strconv"
 
 	kerrors "k8s.io/apimachinery/pkg/api/errors"
 	"k8s.io/apimachinery/pkg/types"
@@ -40,128 +39,6 @@ const (
 	errNoValue     = "referenced field was empty (referenced resource may not yet be ready)"
 )
 
-// NOTE(negz): There are many equivalents of FromPtrValue and ToPtrValue
-// throughout the Crossplane codebase. We duplicate them here to reduce the
-// number of packages our API types have to import to support references.
-
-// FromPtrValue adapts a string pointer field for use as a CurrentValue.
-func FromPtrValue(v *string) string {
-	if v == nil {
-		return ""
-	}
-	return *v
-}
-
-// FromFloatPtrValue adapts a float pointer field for use as a CurrentValue.
-func FromFloatPtrValue(v *float64) string {
-	if v == nil {
-		return ""
-	}
-	return strconv.FormatFloat(*v, 'f', 0, 64)
-}
-
-// FromIntPtrValue adapts an int pointer field for use as a CurrentValue.
-func FromIntPtrValue(v *int64) string {
-	if v == nil {
-		return ""
-	}
-	return strconv.FormatInt(*v, 10)
-}
-
-// ToPtrValue adapts a ResolvedValue for use as a string pointer field.
-func ToPtrValue(v string) *string {
-	if v == "" {
-		return nil
-	}
-	return &v
-}
-
-// ToFloatPtrValue adapts a ResolvedValue for use as a float64 pointer field.
-func ToFloatPtrValue(v string) *float64 {
-	if v == "" {
-		return nil
-	}
-	vParsed, err := strconv.ParseFloat(v, 64)
-	if err != nil {
-		return nil
-	}
-	return &vParsed
-}
-
-// ToIntPtrValue adapts a ResolvedValue for use as an int pointer field.
-func ToIntPtrValue(v string) *int64 {
-	if v == "" {
-		return nil
-	}
-	vParsed, err := strconv.ParseInt(v, 10, 64)
-	if err != nil {
-		return nil
-	}
-	return &vParsed
-}
-
-// FromPtrValues adapts a slice of string pointer fields for use as CurrentValues.
-// NOTE: Do not use this utility function unless you have to.
-// Using pointer slices does not adhere to our current API practices.
-// The current use case is where generated code creates reference-able fields in a provider which are
-// string pointers and need to be resolved as part of `ResolveMultiple`.
-func FromPtrValues(v []*string) []string {
-	res := make([]string, len(v))
-	for i := range len(v) {
-		res[i] = FromPtrValue(v[i])
-	}
-	return res
-}
-
-// FromFloatPtrValues adapts a slice of float64 pointer fields for use as CurrentValues.
-func FromFloatPtrValues(v []*float64) []string {
-	res := make([]string, len(v))
-	for i := range len(v) {
-		res[i] = FromFloatPtrValue(v[i])
-	}
-	return res
-}
-
-// FromIntPtrValues adapts a slice of int64 pointer fields for use as CurrentValues.
-func FromIntPtrValues(v []*int64) []string {
-	res := make([]string, len(v))
-	for i := range len(v) {
-		res[i] = FromIntPtrValue(v[i])
-	}
-	return res
-}
-
-// ToPtrValues adapts ResolvedValues for use as a slice of string pointer fields.
-// NOTE: Do not use this utility function unless you have to.
-// Using pointer slices does not adhere to our current API practices.
-// The current use case is where generated code creates reference-able fields in a provider which are
-// string pointers and need to be resolved as part of `ResolveMultiple`.
-func ToPtrValues(v []string) []*string {
-	res := make([]*string, len(v))
-	for i := range len(v) {
-		res[i] = ToPtrValue(v[i])
-	}
-	return res
-}
-
-// ToFloatPtrValues adapts ResolvedValues for use as a slice of float64 pointer fields.
-func ToFloatPtrValues(v []string) []*float64 {
-	res := make([]*float64, len(v))
-	for i := range len(v) {
-		res[i] = ToFloatPtrValue(v[i])
-	}
-	return res
-}
-
-// ToIntPtrValues adapts ResolvedValues for use as a slice of int64 pointer fields.
-func ToIntPtrValues(v []string) []*int64 {
-	res := make([]*int64, len(v))
-	for i := range len(v) {
-		res[i] = ToIntPtrValue(v[i])
-	}
-	return res
-}
-
 // To indicates the kind of managed resource a reference is to.
 type To struct {
 	Managed resource.Managed



Test patch:
diff --git a/pkg/reference/reference_test.go b/pkg/reference/reference_test.go
index 6697d25..67106c4 100644
--- a/pkg/reference/reference_test.go
+++ b/pkg/reference/reference_test.go
@@ -47,97 +47,6 @@ func (fml *FakeManagedList) GetItems() []resource.Managed {
 	return fml.Items
 }
 
-func TestToAndFromPtr(t *testing.T) {
-	cases := map[string]struct {
-		want string
-	}{
-		"Zero":    {want: ""},
-		"NonZero": {want: "pointy"},
-	}
-	for name, tc := range cases {
-		t.Run(name, func(t *testing.T) {
-			got := FromPtrValue(ToPtrValue(tc.want))
-			if diff := cmp.Diff(tc.want, got); diff != "" {
-				t.Errorf("FromPtrValue(ToPtrValue(%s): -want, +got: %s", tc.want, diff)
-			}
-		})
-	}
-}
-
-func TestToAndFromFloatPtr(t *testing.T) {
-	cases := map[string]struct {
-		want string
-	}{
-		"Zero":    {want: ""},
-		"NonZero": {want: "1123581321"},
-	}
-	for name, tc := range cases {
-		t.Run(name, func(t *testing.T) {
-			got := FromFloatPtrValue(ToFloatPtrValue(tc.want))
-			if diff := cmp.Diff(tc.want, got); diff != "" {
-				t.Errorf("FromPtrValue(ToPtrValue(%s): -want, +got: %s", tc.want, diff)
-			}
-		})
-	}
-}
-
-func TestToAndFromPtrValues(t *testing.T) {
-	cases := map[string]struct {
-		want []string
-	}{
-		"Nil":      {want: []string{}},
-		"Zero":     {want: []string{""}},
-		"NonZero":  {want: []string{"pointy"}},
-		"Multiple": {want: []string{"pointy", "pointers"}},
-	}
-	for name, tc := range cases {
-		t.Run(name, func(t *testing.T) {
-			got := FromPtrValues(ToPtrValues(tc.want))
-			if diff := cmp.Diff(tc.want, got); diff != "" {
-				t.Errorf("FromPtrValues(ToPtrValues(%s): -want, +got: %s", tc.want, diff)
-			}
-		})
-	}
-}
-
-func TestToAndFromFloatPtrValues(t *testing.T) {
-	cases := map[string]struct {
-		want []string
-	}{
-		"Nil":      {want: []string{}},
-		"Zero":     {want: []string{""}},
-		"NonZero":  {want: []string{"1123581321"}},
-		"Multiple": {want: []string{"1123581321", "1234567890"}},
-	}
-	for name, tc := range cases {
-		t.Run(name, func(t *testing.T) {
-			got := FromFloatPtrValues(ToFloatPtrValues(tc.want))
-			if diff := cmp.Diff(tc.want, got); diff != "" {
-				t.Errorf("FromPtrValues(ToPtrValues(%s): -want, +got: %s", tc.want, diff)
-			}
-		})
-	}
-}
-
-func TestToAndFromIntPtrValues(t *testing.T) {
-	cases := map[string]struct {
-		want []string
-	}{
-		"Nil":      {want: []string{}},
-		"Zero":     {want: []string{""}},
-		"NonZero":  {want: []string{"1123581321"}},
-		"Multiple": {want: []string{"1123581321", "1234567890"}},
-	}
-	for name, tc := range cases {
-		t.Run(name, func(t *testing.T) {
-			got := FromIntPtrValues(ToIntPtrValues(tc.want))
-			if diff := cmp.Diff(tc.want, got); diff != "" {
-				t.Errorf("FromIntPtrValues(ToIntPtrValues(%s): -want, +got: %s", tc.want, diff)
-			}
-		})
-	}
-}
-
 func TestResolve(t *testing.T) {
 	errBoom := errors.New("boom")
 	now := metav1.Now()