Merge pull request #132788 from ylink-lfs/chore/strptr_removal

chore: remove strPtr usage with ptr.To

Kubernetes-commit: 3d13f39f24e5533286278f04702c69fbed448c35
This commit is contained in:
Kubernetes Publisher 2025-07-08 00:35:36 -07:00
commit e824ccb0fa
4 changed files with 17 additions and 23 deletions

4
go.mod
View File

@ -49,9 +49,9 @@ require (
gopkg.in/go-jose/go-jose.v2 v2.6.3
gopkg.in/natefinch/lumberjack.v2 v2.2.1
k8s.io/api v0.0.0-20250705010445-839e6c7fb630
k8s.io/apimachinery v0.0.0-20250708031326-cd1624cbbfc1
k8s.io/apimachinery v0.0.0-20250708050202-b18bb6a9e8e6
k8s.io/client-go v0.0.0-20250707010846-6c24674413b0
k8s.io/component-base v0.0.0-20250707181532-da77161160fb
k8s.io/component-base v0.0.0-20250708051227-72837f691197
k8s.io/klog/v2 v2.130.1
k8s.io/kms v0.0.0-20250701212550-c0cb85aa532f
k8s.io/kube-openapi v0.0.0-20250628140032-d90c4fd18f59

8
go.sum
View File

@ -299,12 +299,12 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.0.0-20250705010445-839e6c7fb630 h1:pnI9Db0bmtO4qa+X6jGK8WslPvzLwW8wrAe5B2//yGU=
k8s.io/api v0.0.0-20250705010445-839e6c7fb630/go.mod h1:cQb0K/knyMnN0b7QfEoYB+YzMbFk6PMoa/XTGxEJ7iw=
k8s.io/apimachinery v0.0.0-20250708031326-cd1624cbbfc1 h1:B/LHv7kwmFTufWYHRMx6XYYJpv9tkfzrLPZjZFqzrDc=
k8s.io/apimachinery v0.0.0-20250708031326-cd1624cbbfc1/go.mod h1:Th679JJyaVRDNFk3vKPKY43ypziDeoGnbEiEgBCz8s4=
k8s.io/apimachinery v0.0.0-20250708050202-b18bb6a9e8e6 h1:yU8UMv2l/HGGPqnHLc88hXDE//i7q/fxHS+alFSlpkM=
k8s.io/apimachinery v0.0.0-20250708050202-b18bb6a9e8e6/go.mod h1:Th679JJyaVRDNFk3vKPKY43ypziDeoGnbEiEgBCz8s4=
k8s.io/client-go v0.0.0-20250707010846-6c24674413b0 h1:LuQS18G2xuonxqLmrPffyf73+ihT20j4cfEe5B+toYg=
k8s.io/client-go v0.0.0-20250707010846-6c24674413b0/go.mod h1:mM2iI4pdw3ESx6+R7SXNnZIwBxet3HJYBwSz3GMjDm4=
k8s.io/component-base v0.0.0-20250707181532-da77161160fb h1:p0fm/rXlJlAjxqo9ac+EPiQKEop32UTAgHhyp/cIbKc=
k8s.io/component-base v0.0.0-20250707181532-da77161160fb/go.mod h1:7sIX32AaUtSX061OMiJiC/+UgeKAXech484tT0jUuKs=
k8s.io/component-base v0.0.0-20250708051227-72837f691197 h1:HPpnKAvWicINIJb5H0yd7sMnvXjAcCeoN2j8NkIK+s8=
k8s.io/component-base v0.0.0-20250708051227-72837f691197/go.mod h1:U4cTVU7iRxFIlHEFNsrq7AYzG4lxdaliabhy0qPB/Ww=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kms v0.0.0-20250701212550-c0cb85aa532f h1:IiE5Db+Ha45v4GSmZtR4OLdkk8j7Nk/76SP1gvVAjnM=

View File

@ -27,12 +27,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apiserver/pkg/apis/apiserver"
"k8s.io/utils/ptr"
)
func strptr(s string) *string {
return &s
}
func TestReadEgressSelectorConfiguration(t *testing.T) {
testcases := []struct {
name string
@ -46,14 +43,14 @@ func TestReadEgressSelectorConfiguration(t *testing.T) {
createFile: true,
contents: ``,
expectedResult: nil,
expectedError: strptr("invalid service configuration object \"\""),
expectedError: ptr.To("invalid service configuration object \"\""),
},
{
name: "absent",
createFile: false,
contents: ``,
expectedResult: nil,
expectedError: strptr("errors.errorString{s:\"unable to read egress selector configuration"),
expectedError: ptr.To("errors.errorString{s:\"unable to read egress selector configuration"),
},
{
name: "unknown field causes error",
@ -69,7 +66,7 @@ egressSelections:
bar: "baz"
`,
expectedResult: nil,
expectedError: strptr("runtime.strictDecodingError"),
expectedError: ptr.To("runtime.strictDecodingError"),
},
{
name: "duplicate field causes error",
@ -85,7 +82,7 @@ egressSelections:
proxyProtocol: "Indirect"
`,
expectedResult: nil,
expectedError: strptr("runtime.strictDecodingError"),
expectedError: ptr.To("runtime.strictDecodingError"),
},
{
name: "v1beta1",
@ -303,7 +300,7 @@ spec:
mountPath: /etc/srv/kubernetes/pki/konnectivity-agent
`,
expectedResult: nil,
expectedError: strptr("invalid service configuration object \"DaemonSet\""),
expectedError: ptr.To("invalid service configuration object \"DaemonSet\""),
},
}

View File

@ -24,6 +24,7 @@ import (
"testing"
tracingapi "k8s.io/component-base/tracing/api/v1"
"k8s.io/utils/ptr"
)
var (
@ -32,10 +33,6 @@ var (
samplingRate = int32(12345)
)
func strptr(s string) *string {
return &s
}
func TestValidateTracingOptions(t *testing.T) {
testcases := []struct {
name string
@ -95,7 +92,7 @@ func TestReadTracingConfiguration(t *testing.T) {
createFile: false,
contents: ``,
expectedResult: nil,
expectedError: strptr("unable to read tracing configuration from \"test-tracing-config-absent\": open test-tracing-config-absent: no such file or directory"),
expectedError: ptr.To("unable to read tracing configuration from \"test-tracing-config-absent\": open test-tracing-config-absent: no such file or directory"),
},
{
name: "duplicate field error; strict validation",
@ -108,7 +105,7 @@ endpoint: localhost:4318
samplingRatePerMillion: 12345
`,
expectedResult: nil,
expectedError: strptr("unable to decode tracing configuration data: strict decoding error"),
expectedError: ptr.To("unable to decode tracing configuration data: strict decoding error"),
},
{
name: "unknown field error; strict validation",
@ -121,7 +118,7 @@ endpoint: localhost:4318
samplingRatePerMillion: 12345
`,
expectedResult: nil,
expectedError: strptr("unable to decode tracing configuration data: strict decoding error"),
expectedError: ptr.To("unable to decode tracing configuration data: strict decoding error"),
},
{
name: "v1alpha1",
@ -173,7 +170,7 @@ spec:
name: agent
`,
expectedResult: nil,
expectedError: strptr("unable to decode tracing configuration data: no kind \"DaemonSet\" is registered for version \"apps/v1\" in scheme"),
expectedError: ptr.To("unable to decode tracing configuration data: no kind \"DaemonSet\" is registered for version \"apps/v1\" in scheme"),
},
}