diff --git a/go.mod b/go.mod index 56e844845..1f26e242e 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( k8s.io/client-go v0.26.9 k8s.io/code-generator v0.26.9 k8s.io/kubectl v0.26.9 - k8s.io/utils v0.0.0-20230726121419-3b25d923346b + k8s.io/utils v0.0.0-20230209194617-a36077c30491 knative.dev/pkg v0.0.0-20230221145627-8efb3485adcf sigs.k8s.io/controller-runtime v0.14.6 sigs.k8s.io/yaml v1.3.0 diff --git a/go.sum b/go.sum index 66a5197ec..ffe23f26c 100644 --- a/go.sum +++ b/go.sum @@ -817,8 +817,8 @@ k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a h1:gmovKNur38vgoWfGtP5QOG k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a/go.mod h1:y5VtZWM9sHHc2ZodIH/6SHzXj+TPU5USoA8lcIeKEKY= k8s.io/kubectl v0.26.9 h1:0Z8wEFQoXqWbWfT7G9si5EKVjYf5KG4hocSB7B8Jkbc= k8s.io/kubectl v0.26.9/go.mod h1:Rl9W561iyUZtzwgstHcKChzUo2xMaGqb7Za6jUDMKP4= -k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI= -k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +k8s.io/utils v0.0.0-20230209194617-a36077c30491 h1:r0BAOLElQnnFhE/ApUsg3iHdVYYPBjNSSOMowRZxxsY= +k8s.io/utils v0.0.0-20230209194617-a36077c30491/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= knative.dev/pkg v0.0.0-20230221145627-8efb3485adcf h1:TwvZFDpkyqpK2OCAwvNGV2Zjk14FzIh8X8Ci/du3jYI= knative.dev/pkg v0.0.0-20230221145627-8efb3485adcf/go.mod h1:VO/fcEsq43seuONRQxZyftWHjpMabYzRHDtpSEQ/eoQ= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/pkg/apis/build/v1beta1/build_conversion.go b/pkg/apis/build/v1beta1/build_conversion.go index 14f878295..11ceb95ea 100644 --- a/pkg/apis/build/v1beta1/build_conversion.go +++ b/pkg/apis/build/v1beta1/build_conversion.go @@ -14,7 +14,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" runtime "k8s.io/apimachinery/pkg/runtime" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" ) const ( @@ -90,7 +90,7 @@ func (src *Build) ConvertFrom(ctx context.Context, obj *unstructured.Unstructure if src.Spec.Retention == nil { src.Spec.Retention = &BuildRetention{} } - src.Spec.Retention.AtBuildDeletion = ptr.To[bool](value == "true") + src.Spec.Retention.AtBuildDeletion = pointer.Bool(value == "true") delete(src.ObjectMeta.Annotations, v1alpha1.AnnotationBuildRunDeletion) } diff --git a/pkg/apis/build/v1beta1/buildrun_conversion.go b/pkg/apis/build/v1beta1/buildrun_conversion.go index 637f83500..d55b7dad9 100644 --- a/pkg/apis/build/v1beta1/buildrun_conversion.go +++ b/pkg/apis/build/v1beta1/buildrun_conversion.go @@ -13,7 +13,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" runtime "k8s.io/apimachinery/pkg/runtime" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" ) // ensure v1beta1 implements the Conversion interface @@ -47,7 +47,7 @@ func (src *BuildRun) ConvertTo(ctx context.Context, obj *unstructured.Unstructur if src.Spec.ServiceAccount != nil && *src.Spec.ServiceAccount == ".generate" { alphaBuildRun.Spec.ServiceAccount = &v1alpha1.ServiceAccount{ Name: &src.ObjectMeta.Name, - Generate: ptr.To[bool](true), + Generate: pointer.Bool(true), } } else { alphaBuildRun.Spec.ServiceAccount = &v1alpha1.ServiceAccount{ diff --git a/pkg/apis/build/v1beta1/buildstrategy_conversion.go b/pkg/apis/build/v1beta1/buildstrategy_conversion.go index 8957cd7bb..cd3155a8a 100644 --- a/pkg/apis/build/v1beta1/buildstrategy_conversion.go +++ b/pkg/apis/build/v1beta1/buildstrategy_conversion.go @@ -14,7 +14,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" runtime "k8s.io/apimachinery/pkg/runtime" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" ) // ensure v1beta1 implements the Conversion interface @@ -252,7 +252,7 @@ func (src *BuildStrategySpec) ConvertFrom(bs v1alpha1.BuildStrategySpec) { Name: "dockerfile", Description: "The Dockerfile to be built.", Type: ParameterTypeString, - Default: ptr.To[string]("Dockerfile"), + Default: pointer.String("Dockerfile"), }) } diff --git a/pkg/config/config.go b/pkg/config/config.go index 830532e2c..fde2657ea 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -14,7 +14,7 @@ import ( "github.com/prometheus/client_golang/prometheus" pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" ) const ( @@ -85,8 +85,8 @@ var ( metricBuildRunEstablishDurationBuckets = []float64{0, 1, 2, 3, 5, 7, 10, 15, 20, 30} metricBuildRunRampUpDurationBuckets = prometheus.LinearBuckets(0, 1, 10) - root = ptr.To[int64](0) - nonRoot = ptr.To[int64](1000) + root = pointer.Int64(0) + nonRoot = pointer.Int64(1000) ) // Config hosts different parameters that @@ -162,7 +162,7 @@ func NewDefaultConfig() *Config { }, }, SecurityContext: &corev1.SecurityContext{ - AllowPrivilegeEscalation: ptr.To[bool](false), + AllowPrivilegeEscalation: pointer.Bool(false), Capabilities: &corev1.Capabilities{ Drop: []corev1.Capability{ "ALL", @@ -186,7 +186,7 @@ func NewDefaultConfig() *Config { }, }, SecurityContext: &corev1.SecurityContext{ - AllowPrivilegeEscalation: ptr.To[bool](false), + AllowPrivilegeEscalation: pointer.Bool(false), Capabilities: &corev1.Capabilities{ Drop: []corev1.Capability{ "ALL", @@ -214,7 +214,7 @@ func NewDefaultConfig() *Config { // in all possible scenarios, we run this step as root with DAC_OVERRIDE // capability. SecurityContext: &corev1.SecurityContext{ - AllowPrivilegeEscalation: ptr.To[bool](false), + AllowPrivilegeEscalation: pointer.Bool(false), RunAsUser: root, RunAsGroup: root, Capabilities: &corev1.Capabilities{ @@ -244,7 +244,7 @@ func NewDefaultConfig() *Config { }, }, SecurityContext: &corev1.SecurityContext{ - AllowPrivilegeEscalation: ptr.To[bool](false), + AllowPrivilegeEscalation: pointer.Bool(false), Capabilities: &corev1.Capabilities{ Drop: []corev1.Capability{ "ALL", diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index c5b3c50f6..9520c87c3 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -13,7 +13,7 @@ import ( pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" . "github.com/shipwright-io/build/pkg/config" ) @@ -126,7 +126,7 @@ var _ = Describe("Config", func() { } configWithEnvVariableOverrides(overrides, func(config *Config) { - nonRoot := ptr.To[int64](1000) + nonRoot := pointer.Int64(1000) Expect(config.GitContainerTemplate).To(Equal(pipeline.Step{ Image: "myregistry/custom/git-image", Command: []string{ @@ -134,7 +134,7 @@ var _ = Describe("Config", func() { }, Env: []corev1.EnvVar{{Name: "HOME", Value: "/shared-home"}}, SecurityContext: &corev1.SecurityContext{ - AllowPrivilegeEscalation: ptr.To[bool](false), + AllowPrivilegeEscalation: pointer.Bool(false), Capabilities: &corev1.Capabilities{ Drop: []corev1.Capability{ "ALL", @@ -228,14 +228,14 @@ var _ = Describe("Config", func() { } configWithEnvVariableOverrides(overrides, func(config *Config) { - nonRoot := ptr.To[int64](1000) + nonRoot := pointer.Int64(1000) Expect(config.WaiterContainerTemplate).To(Equal(pipeline.Step{ Image: "myregistry/custom/image", Command: []string{"/ko-app/waiter"}, Args: []string{"start"}, Env: []corev1.EnvVar{{Name: "HOME", Value: "/shared-home"}}, SecurityContext: &corev1.SecurityContext{ - AllowPrivilegeEscalation: ptr.To[bool](false), + AllowPrivilegeEscalation: pointer.Bool(false), Capabilities: &corev1.Capabilities{ Drop: []corev1.Capability{ "ALL", diff --git a/pkg/reconciler/build/build.go b/pkg/reconciler/build/build.go index c203e556e..ba9b2a9d2 100644 --- a/pkg/reconciler/build/build.go +++ b/pkg/reconciler/build/build.go @@ -10,7 +10,7 @@ import ( corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -113,7 +113,7 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques } b.Status.Registered = build.ConditionStatusPtr(corev1.ConditionTrue) - b.Status.Message = ptr.To[string](build.AllValidationsSucceeded) + b.Status.Message = pointer.String(build.AllValidationsSucceeded) if err := r.client.Status().Update(ctx, b); err != nil { return reconcile.Result{}, err } diff --git a/pkg/reconciler/build/build_test.go b/pkg/reconciler/build/build_test.go index 3de36f0ec..c399ee49e 100644 --- a/pkg/reconciler/build/build_test.go +++ b/pkg/reconciler/build/build_test.go @@ -15,7 +15,7 @@ import ( "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" crc "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -371,7 +371,7 @@ var _ = Describe("Reconcile Build", func() { Context("when source URL is specified", func() { // validate file protocol It("fails when source URL is invalid", func() { - buildSample.Spec.Source.URL = ptr.To[string]("foobar") + buildSample.Spec.Source.URL = pointer.String("foobar") buildSample.SetAnnotations(map[string]string{ build.AnnotationBuildVerifyRepository: "true", }) @@ -385,7 +385,7 @@ var _ = Describe("Reconcile Build", func() { // validate https protocol It("fails when public source URL is unreachable", func() { - buildSample.Spec.Source.URL = ptr.To[string]("https://github.com/shipwright-io/sample-go-fake") + buildSample.Spec.Source.URL = pointer.String("https://github.com/shipwright-io/sample-go-fake") buildSample.SetAnnotations(map[string]string{ build.AnnotationBuildVerifyRepository: "true", }) @@ -400,7 +400,7 @@ var _ = Describe("Reconcile Build", func() { // skip validation because of empty sourceURL annotation It("succeed when source URL is invalid because source annotation is empty", func() { - buildSample.Spec.Source.URL = ptr.To[string]("foobar") + buildSample.Spec.Source.URL = pointer.String("foobar") // Fake some client Get calls and ensure we populate all // different resources we could get during reconciliation @@ -451,7 +451,7 @@ var _ = Describe("Reconcile Build", func() { // skip validation because build references a sourceURL secret It("succeed when source URL is fake private URL because build reference a sourceURL secret", func() { buildSample := ctl.BuildWithClusterBuildStrategyAndSourceSecret(buildName, namespace, buildStrategyName) - buildSample.Spec.Source.URL = ptr.To[string]("https://github.yourco.com/org/build-fake") + buildSample.Spec.Source.URL = pointer.String("https://github.yourco.com/org/build-fake") buildSample.Spec.Source.Credentials.Name = registrySecret // Fake some client Get calls and ensure we populate all diff --git a/pkg/reconciler/buildrun/buildrun.go b/pkg/reconciler/buildrun/buildrun.go index 82e730385..7c6840d52 100644 --- a/pkg/reconciler/buildrun/buildrun.go +++ b/pkg/reconciler/buildrun/buildrun.go @@ -21,7 +21,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/validation" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -182,7 +182,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req // mark transient build as "registered" and validated build.Status.Registered = buildv1alpha1.ConditionStatusPtr(corev1.ConditionTrue) build.Status.Reason = buildv1alpha1.BuildReasonPtr(buildv1alpha1.SucceedStatus) - build.Status.Message = ptr.To[string](buildv1alpha1.AllValidationsSucceeded) + build.Status.Message = pointer.String(buildv1alpha1.AllValidationsSucceeded) } } @@ -220,7 +220,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req if build.GetAnnotations()[buildv1alpha1.AnnotationBuildRunDeletion] == "true" && !resources.IsOwnedByBuild(build, buildRun.OwnerReferences) { if err := r.setOwnerReferenceFunc(build, buildRun, r.scheme); err != nil { build.Status.Reason = buildv1alpha1.BuildReasonPtr(buildv1alpha1.SetOwnerReferenceFailed) - build.Status.Message = ptr.To[string](fmt.Sprintf("unexpected error when trying to set the ownerreference: %v", err)) + build.Status.Message = pointer.String(fmt.Sprintf("unexpected error when trying to set the ownerreference: %v", err)) if err := r.client.Status().Update(ctx, build); err != nil { return reconcile.Result{}, err } diff --git a/pkg/reconciler/buildrun/buildrun_test.go b/pkg/reconciler/buildrun/buildrun_test.go index 3eb3f499d..ffba2168e 100644 --- a/pkg/reconciler/buildrun/buildrun_test.go +++ b/pkg/reconciler/buildrun/buildrun_test.go @@ -21,7 +21,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" knativeapi "knative.dev/pkg/apis" knativev1 "knative.dev/pkg/apis/duck/v1" crc "sigs.k8s.io/controller-runtime/pkg/client" @@ -1177,8 +1177,8 @@ var _ = Describe("Reconcile BuildRun", func() { // in the build clientUpdateCalls := ctl.StubBuildUpdateOwnerReferences("Build", buildName, - ptr.To[bool](true), - ptr.To[bool](true), + pointer.Bool(true), + pointer.Bool(true), ) client.UpdateCalls(clientUpdateCalls) @@ -1365,7 +1365,7 @@ var _ = Describe("Reconcile BuildRun", func() { Spec: build.BuildRunSpec{ ParamValues: []build.ParamValue{{ Name: "foo", - SingleValue: &build.SingleValue{Value: ptr.To[string]("bar")}, + SingleValue: &build.SingleValue{Value: pointer.String("bar")}, }}, BuildSpec: &build.BuildSpec{}, }, @@ -1421,8 +1421,8 @@ var _ = Describe("Reconcile BuildRun", func() { Spec: build.BuildRunSpec{ BuildSpec: &build.BuildSpec{ Source: build.Source{ - URL: ptr.To[string]("https://github.com/shipwright-io/sample-go.git"), - ContextDir: ptr.To[string]("source-build"), + URL: pointer.String("https://github.com/shipwright-io/sample-go.git"), + ContextDir: pointer.String("source-build"), }, Strategy: build.Strategy{ Kind: &clusterBuildStrategy, @@ -1433,7 +1433,7 @@ var _ = Describe("Reconcile BuildRun", func() { }, }, ServiceAccount: &build.ServiceAccount{ - Generate: ptr.To[bool](true), + Generate: pointer.Bool(true), }, }, } diff --git a/pkg/reconciler/buildrun/resources/credentials_test.go b/pkg/reconciler/buildrun/resources/credentials_test.go index 361d96b4b..95d02aafa 100644 --- a/pkg/reconciler/buildrun/resources/credentials_test.go +++ b/pkg/reconciler/buildrun/resources/credentials_test.go @@ -11,7 +11,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" @@ -38,7 +38,7 @@ var _ = Describe("Credentials", func() { build = &buildv1alpha1.Build{ Spec: buildv1alpha1.BuildSpec{ Source: buildv1alpha1.Source{ - URL: ptr.To[string]("a/b/c"), + URL: pointer.String("a/b/c"), Credentials: &corev1.LocalObjectReference{ Name: "secret_a", }, @@ -94,7 +94,7 @@ var _ = Describe("Credentials", func() { build = &buildv1alpha1.Build{ Spec: buildv1alpha1.BuildSpec{ Source: buildv1alpha1.Source{ - URL: ptr.To[string]("a/b/c"), + URL: pointer.String("a/b/c"), }, Output: buildv1alpha1.Image{ Credentials: &corev1.LocalObjectReference{ @@ -131,7 +131,7 @@ var _ = Describe("Credentials", func() { build = &buildv1alpha1.Build{ Spec: buildv1alpha1.BuildSpec{ Source: buildv1alpha1.Source{ - URL: ptr.To[string]("a/b/c"), + URL: pointer.String("a/b/c"), Credentials: nil, }, }, diff --git a/pkg/reconciler/buildrun/resources/params_test.go b/pkg/reconciler/buildrun/resources/params_test.go index 5dd805a01..ad61c6183 100644 --- a/pkg/reconciler/buildrun/resources/params_test.go +++ b/pkg/reconciler/buildrun/resources/params_test.go @@ -12,7 +12,7 @@ import ( "github.com/onsi/gomega/types" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" @@ -28,22 +28,22 @@ var _ = Describe("Params overrides", func() { Entry("override a single parameter", []buildv1alpha1.ParamValue{ {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("2"), + Value: pointer.String("2"), }}, }, []buildv1alpha1.ParamValue{ {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("3"), + Value: pointer.String("3"), }}, }, ContainElements([]buildv1alpha1.ParamValue{ {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("3"), + Value: pointer.String("3"), }}, })), Entry("override two parameters", []buildv1alpha1.ParamValue{ {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("2"), + Value: pointer.String("2"), }}, {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ SecretValue: &buildv1alpha1.ObjectKeyRef{ @@ -53,7 +53,7 @@ var _ = Describe("Params overrides", func() { }}, }, []buildv1alpha1.ParamValue{ {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("3"), + Value: pointer.String("3"), }}, {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ @@ -63,7 +63,7 @@ var _ = Describe("Params overrides", func() { }}, }, ContainElements([]buildv1alpha1.ParamValue{ {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("3"), + Value: pointer.String("3"), }}, {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ @@ -76,43 +76,43 @@ var _ = Describe("Params overrides", func() { Entry("override multiple parameters", []buildv1alpha1.ParamValue{ {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("2"), + Value: pointer.String("2"), }}, {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("2"), + Value: pointer.String("2"), }}, {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("2"), + Value: pointer.String("2"), }}, }, []buildv1alpha1.ParamValue{ {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("6"), + Value: pointer.String("6"), }}, {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("6"), + Value: pointer.String("6"), }}, }, ContainElements([]buildv1alpha1.ParamValue{ {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("6"), + Value: pointer.String("6"), }}, {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("2"), + Value: pointer.String("2"), }}, {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("6"), + Value: pointer.String("6"), }}, })), Entry("dont override when second list is empty", []buildv1alpha1.ParamValue{ {Name: "t", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("2"), + Value: pointer.String("2"), }}, {Name: "z", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("2"), + Value: pointer.String("2"), }}, {Name: "g", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("2"), + Value: pointer.String("2"), }}, }, []buildv1alpha1.ParamValue{ @@ -120,13 +120,13 @@ var _ = Describe("Params overrides", func() { }, ContainElements([]buildv1alpha1.ParamValue{ {Name: "t", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("2"), + Value: pointer.String("2"), }}, {Name: "z", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("2"), + Value: pointer.String("2"), }}, {Name: "g", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("2"), + Value: pointer.String("2"), }}, })), @@ -135,56 +135,56 @@ var _ = Describe("Params overrides", func() { // no original values }, []buildv1alpha1.ParamValue{ {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("6"), + Value: pointer.String("6"), }}, {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("6"), + Value: pointer.String("6"), }}, }, ContainElements([]buildv1alpha1.ParamValue{ {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("6"), + Value: pointer.String("6"), }}, {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("6"), + Value: pointer.String("6"), }}, })), Entry("override multiple parameters if the match and add them if not present in first list", []buildv1alpha1.ParamValue{ {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("2"), + Value: pointer.String("2"), }}, }, []buildv1alpha1.ParamValue{ {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("22"), + Value: pointer.String("22"), }}, {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("20"), + Value: pointer.String("20"), }}, {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("10"), + Value: pointer.String("10"), }}, {Name: "d", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("8"), + Value: pointer.String("8"), }}, {Name: "e", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("4"), + Value: pointer.String("4"), }}, }, ContainElements([]buildv1alpha1.ParamValue{ {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("22"), + Value: pointer.String("22"), }}, {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("20"), + Value: pointer.String("20"), }}, {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("10"), + Value: pointer.String("10"), }}, {Name: "d", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("8"), + Value: pointer.String("8"), }}, {Name: "e", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("4"), + Value: pointer.String("4"), }}, })), ) @@ -244,13 +244,13 @@ var _ = Describe("FindParamValueByName", func() { paramValues := []buildv1alpha1.ParamValue{{ Name: "some-parameter", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("some-value"), + Value: pointer.String("some-value"), }, }, { Name: "another-parameter", Values: []buildv1alpha1.SingleValue{ { - Value: ptr.To[string]("item"), + Value: pointer.String("item"), }, { ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ @@ -262,7 +262,7 @@ var _ = Describe("FindParamValueByName", func() { }, { Name: "last-parameter", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("last-value"), + Value: pointer.String("last-value"), }, }} @@ -277,7 +277,7 @@ var _ = Describe("FindParamValueByName", func() { Name: "another-parameter", Values: []buildv1alpha1.SingleValue{ { - Value: ptr.To[string]("item"), + Value: pointer.String("item"), }, { ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ @@ -383,7 +383,7 @@ var _ = Describe("HandleTaskRunParam", func() { err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1alpha1.ParamValue{ Name: "string-parameter", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("My value"), + Value: pointer.String("My value"), }, }) Expect(err).ToNot(HaveOccurred()) @@ -449,7 +449,7 @@ var _ = Describe("HandleTaskRunParam", func() { ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ Name: "config-map-name", Key: "my-key", - Format: ptr.To[string]("The value from the config map is '${CONFIGMAP_VALUE}'."), + Format: pointer.String("The value from the config map is '${CONFIGMAP_VALUE}'."), }, }, }) @@ -536,7 +536,7 @@ var _ = Describe("HandleTaskRunParam", func() { SecretValue: &buildv1alpha1.ObjectKeyRef{ Name: "secret-name", Key: "secret-key", - Format: ptr.To[string]("secret-value: ${SECRET_VALUE}"), + Format: pointer.String("secret-value: ${SECRET_VALUE}"), }, }, }) @@ -586,13 +586,13 @@ var _ = Describe("HandleTaskRunParam", func() { Name: "array-parameter", Values: []buildv1alpha1.SingleValue{ { - Value: ptr.To[string]("first entry"), + Value: pointer.String("first entry"), }, { - Value: ptr.To[string](""), + Value: pointer.String(""), }, { - Value: ptr.To[string]("third entry"), + Value: pointer.String("third entry"), }, }, }) @@ -621,7 +621,7 @@ var _ = Describe("HandleTaskRunParam", func() { Name: "array-parameter", Values: []buildv1alpha1.SingleValue{ { - Value: ptr.To[string]("first entry"), + Value: pointer.String("first entry"), }, { SecretValue: &buildv1alpha1.ObjectKeyRef{ @@ -633,7 +633,7 @@ var _ = Describe("HandleTaskRunParam", func() { SecretValue: &buildv1alpha1.ObjectKeyRef{ Name: "secret-name", Key: "secret-key", - Format: ptr.To[string]("The secret value is ${SECRET_VALUE}"), + Format: pointer.String("The secret value is ${SECRET_VALUE}"), }, }, }, diff --git a/pkg/reconciler/buildrun/resources/results_test.go b/pkg/reconciler/buildrun/resources/results_test.go index 1bf4f45f1..13966611c 100644 --- a/pkg/reconciler/buildrun/resources/results_test.go +++ b/pkg/reconciler/buildrun/resources/results_test.go @@ -16,7 +16,7 @@ import ( pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -50,7 +50,7 @@ var _ = Describe("TaskRun results to BuildRun", func() { It("should surface the TaskRun results emitting from default(git) source step", func() { commitSha := "0e0583421a5e4bf562ffe33f3651e16ba0c78591" - br.Status.BuildSpec.Source.URL = ptr.To[string]("https://github.com/shipwright-io/sample-go") + br.Status.BuildSpec.Source.URL = pointer.String("https://github.com/shipwright-io/sample-go") tr.Status.TaskRunResults = append(tr.Status.TaskRunResults, pipelinev1beta1.TaskRunResult{ @@ -124,7 +124,7 @@ var _ = Describe("TaskRun results to BuildRun", func() { It("should surface the TaskRun results emitting from source and output step", func() { commitSha := "0e0583421a5e4bf562ffe33f3651e16ba0c78591" imageDigest := "sha256:fe1b73cd25ac3f11dec752755e2" - br.Status.BuildSpec.Source.URL = ptr.To[string]("https://github.com/shipwright-io/sample-go") + br.Status.BuildSpec.Source.URL = pointer.String("https://github.com/shipwright-io/sample-go") tr.Status.TaskRunResults = append(tr.Status.TaskRunResults, pipelinev1beta1.TaskRunResult{ diff --git a/pkg/reconciler/buildrun/resources/service_accounts.go b/pkg/reconciler/buildrun/resources/service_accounts.go index 4cf400cb0..38cd815f3 100644 --- a/pkg/reconciler/buildrun/resources/service_accounts.go +++ b/pkg/reconciler/buildrun/resources/service_accounts.go @@ -14,7 +14,7 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -65,7 +65,7 @@ func GenerateSA(ctx context.Context, client client.Client, build *buildv1alpha1. *metav1.NewControllerRef(buildRun, buildv1alpha1.SchemeGroupVersion.WithKind("BuildRun")), }, }, - AutomountServiceAccountToken: ptr.To[bool](false), + AutomountServiceAccountToken: pointer.Bool(false), } ctxlog.Debug(ctx, "automatic generation of service account", namespace, serviceAccount.Namespace, name, serviceAccount.Name) diff --git a/pkg/reconciler/buildrun/resources/sources/git_test.go b/pkg/reconciler/buildrun/resources/sources/git_test.go index 3d5ef09da..19df2a68d 100644 --- a/pkg/reconciler/buildrun/resources/sources/git_test.go +++ b/pkg/reconciler/buildrun/resources/sources/git_test.go @@ -14,7 +14,7 @@ import ( tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" ) var _ = Describe("Git", func() { @@ -31,7 +31,7 @@ var _ = Describe("Git", func() { JustBeforeEach(func() { sources.AppendGitStep(cfg, taskSpec, buildv1alpha1.Source{ - URL: ptr.To[string]("https://github.com/shipwright-io/build"), + URL: pointer.String("https://github.com/shipwright-io/build"), }, "default") }) @@ -75,7 +75,7 @@ var _ = Describe("Git", func() { JustBeforeEach(func() { sources.AppendGitStep(cfg, taskSpec, buildv1alpha1.Source{ - URL: ptr.To[string]("git@github.com:shipwright-io/build.git"), + URL: pointer.String("git@github.com:shipwright-io/build.git"), Credentials: &corev1.LocalObjectReference{ Name: "a.secret", }, diff --git a/pkg/reconciler/buildrun/resources/sources/utils.go b/pkg/reconciler/buildrun/resources/sources/utils.go index 1e8a346c0..72d837fe6 100644 --- a/pkg/reconciler/buildrun/resources/sources/utils.go +++ b/pkg/reconciler/buildrun/resources/sources/utils.go @@ -11,7 +11,7 @@ import ( tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" ) const ( @@ -24,7 +24,7 @@ var ( dnsLabel1123Forbidden = regexp.MustCompile("[^a-zA-Z0-9-]+") // secrets are volumes and volumes are mounted as root, as we run as non-root, we must use 0444 to allow non-root to read it - secretMountMode = ptr.To[int32](0444) + secretMountMode = pointer.Int32(0444) ) // AppendSecretVolume checks if a volume for a secret already exists, if not it appends it to the TaskSpec diff --git a/pkg/reconciler/buildrun/resources/steps/security_context.go b/pkg/reconciler/buildrun/resources/steps/security_context.go index 8518d21b4..4a866e16c 100644 --- a/pkg/reconciler/buildrun/resources/steps/security_context.go +++ b/pkg/reconciler/buildrun/resources/steps/security_context.go @@ -10,7 +10,7 @@ import ( buildapi "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" tektonapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" "k8s.io/utils/strings/slices" ) @@ -66,7 +66,7 @@ func UpdateSecurityContext(taskSpec *tektonapi.TaskSpec, taskRunAnnotations map[ Name: VolumeNameSecurityContext, VolumeSource: corev1.VolumeSource{ DownwardAPI: &corev1.DownwardAPIVolumeSource{ - DefaultMode: ptr.To[int32](0444), + DefaultMode: pointer.Int32(0444), Items: []corev1.DownwardAPIVolumeFile{{ Path: "group", diff --git a/pkg/reconciler/buildrun/resources/steps/security_context_test.go b/pkg/reconciler/buildrun/resources/steps/security_context_test.go index 62b3c7300..64eda83c5 100644 --- a/pkg/reconciler/buildrun/resources/steps/security_context_test.go +++ b/pkg/reconciler/buildrun/resources/steps/security_context_test.go @@ -12,7 +12,7 @@ import ( buildapi "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" tektonapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -30,15 +30,15 @@ var _ = Describe("UpdateSecurityContext", func() { Container: corev1.Container{ Name: "first-step", SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.To[int64](891), - RunAsGroup: ptr.To[int64](1210), + RunAsUser: pointer.Int64(891), + RunAsGroup: pointer.Int64(1210), }, }, }, { Container: corev1.Container{ Name: "second-step", SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.To[int64](891), + RunAsUser: pointer.Int64(891), }, }, }, { @@ -51,19 +51,19 @@ var _ = Describe("UpdateSecurityContext", func() { Steps: []tektonapi.Step{{ Name: "shp-source-default", SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.To[int64](1000), - RunAsGroup: ptr.To[int64](1000), + RunAsUser: pointer.Int64(1000), + RunAsGroup: pointer.Int64(1000), }, }, { Name: "first-step", SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.To[int64](891), - RunAsGroup: ptr.To[int64](1210), + RunAsUser: pointer.Int64(891), + RunAsGroup: pointer.Int64(1210), }, }, { Name: "second-step", SecurityContext: &corev1.SecurityContext{ - RunAsUser: ptr.To[int64](891), + RunAsUser: pointer.Int64(891), }, }, { Name: "third-step", @@ -83,11 +83,11 @@ var _ = Describe("UpdateSecurityContext", func() { }) It("does not change the step's securityContext", func() { - Expect(taskRunSpec.Steps[0].SecurityContext.RunAsUser).To(Equal(ptr.To[int64](1000))) - Expect(taskRunSpec.Steps[0].SecurityContext.RunAsGroup).To(Equal(ptr.To[int64](1000))) - Expect(taskRunSpec.Steps[1].SecurityContext.RunAsUser).To(Equal(ptr.To[int64](891))) - Expect(taskRunSpec.Steps[1].SecurityContext.RunAsGroup).To(Equal(ptr.To[int64](1210))) - Expect(taskRunSpec.Steps[2].SecurityContext.RunAsUser).To(Equal(ptr.To[int64](891))) + Expect(taskRunSpec.Steps[0].SecurityContext.RunAsUser).To(Equal(pointer.Int64(1000))) + Expect(taskRunSpec.Steps[0].SecurityContext.RunAsGroup).To(Equal(pointer.Int64(1000))) + Expect(taskRunSpec.Steps[1].SecurityContext.RunAsUser).To(Equal(pointer.Int64(891))) + Expect(taskRunSpec.Steps[1].SecurityContext.RunAsGroup).To(Equal(pointer.Int64(1210))) + Expect(taskRunSpec.Steps[2].SecurityContext.RunAsUser).To(Equal(pointer.Int64(891))) Expect(taskRunSpec.Steps[2].SecurityContext.RunAsGroup).To(BeNil()) Expect(taskRunSpec.Steps[3].SecurityContext).To(BeNil()) }) @@ -115,24 +115,24 @@ var _ = Describe("UpdateSecurityContext", func() { }) It("changes the securityContext of shipwright-managed steps", func() { - Expect(taskRunSpec.Steps[0].SecurityContext.RunAsUser).To(Equal(ptr.To[int64](123))) - Expect(taskRunSpec.Steps[0].SecurityContext.RunAsGroup).To(Equal(ptr.To[int64](456))) + Expect(taskRunSpec.Steps[0].SecurityContext.RunAsUser).To(Equal(pointer.Int64(123))) + Expect(taskRunSpec.Steps[0].SecurityContext.RunAsGroup).To(Equal(pointer.Int64(456))) }) It("does not change the securityContext of a strategy step that has runAsUser and runAsGroup set", func() { - Expect(taskRunSpec.Steps[1].SecurityContext.RunAsUser).To(Equal(ptr.To[int64](891))) - Expect(taskRunSpec.Steps[1].SecurityContext.RunAsGroup).To(Equal(ptr.To[int64](1210))) + Expect(taskRunSpec.Steps[1].SecurityContext.RunAsUser).To(Equal(pointer.Int64(891))) + Expect(taskRunSpec.Steps[1].SecurityContext.RunAsGroup).To(Equal(pointer.Int64(1210))) }) It("changes the securityContext of a strategy step that does not have both runAsUser and runAsGroup set", func() { - Expect(taskRunSpec.Steps[2].SecurityContext.RunAsUser).To(Equal(ptr.To[int64](891))) - Expect(taskRunSpec.Steps[2].SecurityContext.RunAsGroup).To(Equal(ptr.To[int64](456))) + Expect(taskRunSpec.Steps[2].SecurityContext.RunAsUser).To(Equal(pointer.Int64(891))) + Expect(taskRunSpec.Steps[2].SecurityContext.RunAsGroup).To(Equal(pointer.Int64(456))) }) It("introduces a securityContext for a strategy step that does not have one", func() { Expect(taskRunSpec.Steps[3].SecurityContext).ToNot(BeNil()) - Expect(taskRunSpec.Steps[3].SecurityContext.RunAsUser).To(Equal(ptr.To[int64](123))) - Expect(taskRunSpec.Steps[3].SecurityContext.RunAsGroup).To(Equal(ptr.To[int64](456))) + Expect(taskRunSpec.Steps[3].SecurityContext.RunAsUser).To(Equal(pointer.Int64(123))) + Expect(taskRunSpec.Steps[3].SecurityContext.RunAsGroup).To(Equal(pointer.Int64(456))) }) It("adds annotations", func() { @@ -147,7 +147,7 @@ var _ = Describe("UpdateSecurityContext", func() { Name: steps.VolumeNameSecurityContext, VolumeSource: corev1.VolumeSource{ DownwardAPI: &corev1.DownwardAPIVolumeSource{ - DefaultMode: ptr.To[int32](0444), + DefaultMode: pointer.Int32(0444), Items: []corev1.DownwardAPIVolumeFile{{ Path: "group", diff --git a/pkg/validate/buildname.go b/pkg/validate/buildname.go index 2bac3686a..1eaa83c1f 100644 --- a/pkg/validate/buildname.go +++ b/pkg/validate/buildname.go @@ -9,7 +9,7 @@ import ( "strings" "k8s.io/apimachinery/pkg/util/validation" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" ) @@ -29,7 +29,7 @@ func NewBuildName(build *build.Build) *BuildNameRef { func (b *BuildNameRef) ValidatePath(_ context.Context) error { if errs := validation.IsValidLabelValue(b.Build.Name); len(errs) > 0 { b.Build.Status.Reason = build.BuildReasonPtr(build.BuildNameInvalid) - b.Build.Status.Message = ptr.To[string](strings.Join(errs, ", ")) + b.Build.Status.Message = pointer.String(strings.Join(errs, ", ")) } return nil diff --git a/pkg/validate/envvars.go b/pkg/validate/envvars.go index fb23a2d2e..6d116b78a 100644 --- a/pkg/validate/envvars.go +++ b/pkg/validate/envvars.go @@ -10,7 +10,7 @@ import ( corev1 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/util/errors" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" ) @@ -47,13 +47,13 @@ func (e *Env) validate(envVar corev1.EnvVar) []error { if envVar.Name == "" { e.Build.Status.Reason = build.BuildReasonPtr(build.SpecEnvNameCanNotBeBlank) - e.Build.Status.Message = ptr.To[string]("name for environment variable must not be blank") + e.Build.Status.Message = pointer.String("name for environment variable must not be blank") allErrs = append(allErrs, fmt.Errorf("%s", *e.Build.Status.Message)) } if envVar.Value != "" && envVar.ValueFrom != nil { e.Build.Status.Reason = build.BuildReasonPtr(build.SpecEnvOnlyOneOfValueOrValueFromMustBeSpecified) - e.Build.Status.Message = ptr.To[string]("only one of value or valueFrom must be specified") + e.Build.Status.Message = pointer.String("only one of value or valueFrom must be specified") allErrs = append(allErrs, fmt.Errorf("%s", *e.Build.Status.Message)) } diff --git a/pkg/validate/envvars_test.go b/pkg/validate/envvars_test.go index f548238ea..293de3e5a 100644 --- a/pkg/validate/envvars_test.go +++ b/pkg/validate/envvars_test.go @@ -11,7 +11,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" "github.com/shipwright-io/build/pkg/validate" @@ -34,7 +34,7 @@ var _ = Describe("Env", func() { err := validate.NewEnv(b).ValidatePath(context.TODO()) Expect(err).To(HaveOccurred()) Expect(b.Status.Reason).To(Equal(build.BuildReasonPtr(build.SpecEnvNameCanNotBeBlank))) - Expect(b.Status.Message).To(Equal(ptr.To[string]("name for environment variable must not be blank"))) + Expect(b.Status.Message).To(Equal(pointer.String("name for environment variable must not be blank"))) }) It("should fail in case of specifying both value and valueFrom", func() { @@ -57,7 +57,7 @@ var _ = Describe("Env", func() { err := validate.NewEnv(b).ValidatePath(context.TODO()) Expect(err).To(HaveOccurred()) Expect(b.Status.Reason).To(Equal(build.BuildReasonPtr(build.SpecEnvOnlyOneOfValueOrValueFromMustBeSpecified))) - Expect(b.Status.Message).To(Equal(ptr.To[string]("only one of value or valueFrom must be specified"))) + Expect(b.Status.Message).To(Equal(pointer.String("only one of value or valueFrom must be specified"))) }) It("should pass in case no env var are set", func() { diff --git a/pkg/validate/ownerreferences.go b/pkg/validate/ownerreferences.go index 65f8cc405..2a39c8fe8 100644 --- a/pkg/validate/ownerreferences.go +++ b/pkg/validate/ownerreferences.go @@ -11,7 +11,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" @@ -44,7 +44,7 @@ func (o OwnerRef) ValidatePath(ctx context.Context) error { if index := o.validateBuildOwnerReference(buildRun.OwnerReferences); index == -1 { if err := controllerutil.SetControllerReference(o.Build, &buildRun, o.Scheme); err != nil { o.Build.Status.Reason = build.BuildReasonPtr(build.SetOwnerReferenceFailed) - o.Build.Status.Message = ptr.To[string](fmt.Sprintf("unexpected error when trying to set the ownerreference: %v", err)) + o.Build.Status.Message = pointer.String(fmt.Sprintf("unexpected error when trying to set the ownerreference: %v", err)) } if err = o.Client.Update(ctx, &buildRun); err != nil { return err diff --git a/pkg/validate/params_test.go b/pkg/validate/params_test.go index dc5f8072d..9b97130e6 100644 --- a/pkg/validate/params_test.go +++ b/pkg/validate/params_test.go @@ -7,7 +7,7 @@ package validate_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" "github.com/shipwright-io/build/pkg/validate" @@ -22,7 +22,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { { Name: "string-param-with-default", Type: buildv1alpha1.ParameterTypeString, - Default: ptr.To[string]("default value"), + Default: pointer.String("default value"), }, { Name: "array-param-no-defaults", @@ -40,7 +40,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { { Name: "string-param-no-default", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("a value"), + Value: pointer.String("a value"), }, }, } @@ -91,7 +91,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { { Name: "string-param-with-default", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string](""), + Value: pointer.String(""), }, }, } @@ -142,7 +142,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { { Name: "string-param-no-default", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("a value"), + Value: pointer.String("a value"), }, }, { @@ -155,7 +155,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { { Name: "shp-source-context", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("/my-source"), + Value: pointer.String("/my-source"), }, }, } @@ -173,7 +173,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { { Name: "string-param-no-default", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("a value"), + Value: pointer.String("a value"), }, }, { @@ -190,7 +190,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { { Name: "non-existing-parameter", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("my value"), + Value: pointer.String("my value"), }, }, } @@ -210,7 +210,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { { Name: "string-param-no-default", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("a value"), + Value: pointer.String("a value"), ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ Name: "a-config-map", Key: "a-key", @@ -224,7 +224,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { Name: "array-param-no-defaults", Values: []buildv1alpha1.SingleValue{ { - Value: ptr.To[string]("a good item"), + Value: pointer.String("a good item"), }, { ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ @@ -256,7 +256,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { Name: "string-param-no-default", Values: []buildv1alpha1.SingleValue{ { - Value: ptr.To[string]("an item"), + Value: pointer.String("an item"), }, { ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ @@ -272,7 +272,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { { Name: "array-param-no-defaults", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string]("a value"), + Value: pointer.String("a value"), }, }, } @@ -292,7 +292,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { { Name: "string-param-no-default", SingleValue: &buildv1alpha1.SingleValue{ - Value: ptr.To[string](" some value"), + Value: pointer.String(" some value"), }, }, { @@ -310,7 +310,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { Name: "array-param-no-defaults", Values: []buildv1alpha1.SingleValue{ { - Value: ptr.To[string]("a good item"), + Value: pointer.String("a good item"), }, { // the bad item without any value @@ -352,7 +352,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { Name: "array-param-no-defaults", Values: []buildv1alpha1.SingleValue{ { - Value: ptr.To[string]("an item"), + Value: pointer.String("an item"), }, { ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ @@ -390,7 +390,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { Name: "array-param-no-defaults", Values: []buildv1alpha1.SingleValue{ { - Value: ptr.To[string]("an item"), + Value: pointer.String("an item"), }, { SecretValue: &buildv1alpha1.ObjectKeyRef{ diff --git a/pkg/validate/secrets.go b/pkg/validate/secrets.go index a124c3b0b..5e3692e0c 100644 --- a/pkg/validate/secrets.go +++ b/pkg/validate/secrets.go @@ -13,7 +13,7 @@ import ( corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" @@ -43,7 +43,7 @@ func (s Credentials) ValidatePath(ctx context.Context) error { return err } else if apierrors.IsNotFound(err) { s.Build.Status.Reason = build.BuildReasonPtr(secretType) - s.Build.Status.Message = ptr.To[string](fmt.Sprintf("referenced secret %s not found", refSecret)) + s.Build.Status.Message = pointer.String(fmt.Sprintf("referenced secret %s not found", refSecret)) missingSecrets = append(missingSecrets, refSecret) } } @@ -53,7 +53,7 @@ func (s Credentials) ValidatePath(ctx context.Context) error { if len(missingSecrets) > 1 { s.Build.Status.Reason = build.BuildReasonPtr(build.MultipleSecretRefNotFound) - s.Build.Status.Message = ptr.To[string](fmt.Sprintf("missing secrets are %s", strings.Join(missingSecrets, ","))) + s.Build.Status.Message = pointer.String(fmt.Sprintf("missing secrets are %s", strings.Join(missingSecrets, ","))) } return nil } diff --git a/pkg/validate/sourceurl.go b/pkg/validate/sourceurl.go index 7d9c21cae..c724d423b 100644 --- a/pkg/validate/sourceurl.go +++ b/pkg/validate/sourceurl.go @@ -8,7 +8,7 @@ import ( "context" "fmt" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" @@ -56,5 +56,5 @@ func (s SourceURLRef) ValidatePath(ctx context.Context) error { // MarkBuildStatus updates a Build Status fields func (s SourceURLRef) MarkBuildStatus(b *build.Build, reason build.BuildReason, msg string) { b.Status.Reason = build.BuildReasonPtr(reason) - b.Status.Message = ptr.To[string](msg) + b.Status.Message = pointer.String(msg) } diff --git a/pkg/validate/strategies.go b/pkg/validate/strategies.go index 4013c3127..56a24d253 100644 --- a/pkg/validate/strategies.go +++ b/pkg/validate/strategies.go @@ -10,7 +10,7 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" @@ -75,7 +75,7 @@ func (s Strategy) validateBuildStrategy(ctx context.Context, strategyName string return false, err } else if apierrors.IsNotFound(err) { s.Build.Status.Reason = build.BuildReasonPtr(build.BuildStrategyNotFound) - s.Build.Status.Message = ptr.To[string](fmt.Sprintf("buildStrategy %s does not exist in namespace %s", s.Build.Spec.Strategy.Name, s.Build.Namespace)) + s.Build.Status.Message = pointer.String(fmt.Sprintf("buildStrategy %s does not exist in namespace %s", s.Build.Spec.Strategy.Name, s.Build.Namespace)) return false, nil } return true, nil @@ -86,7 +86,7 @@ func (s Strategy) validateClusterBuildStrategy(ctx context.Context, strategyName return false, err } else if apierrors.IsNotFound(err) { s.Build.Status.Reason = build.BuildReasonPtr(build.ClusterBuildStrategyNotFound) - s.Build.Status.Message = ptr.To[string](fmt.Sprintf("clusterBuildStrategy %s does not exist", s.Build.Spec.Strategy.Name)) + s.Build.Status.Message = pointer.String(fmt.Sprintf("clusterBuildStrategy %s does not exist", s.Build.Spec.Strategy.Name)) return false, nil } return true, nil @@ -97,7 +97,7 @@ func (s Strategy) validateBuildParams(parameterDefinitions []build.Parameter) { if !valid { s.Build.Status.Reason = build.BuildReasonPtr(reason) - s.Build.Status.Message = ptr.To[string](message) + s.Build.Status.Message = pointer.String(message) } } @@ -106,6 +106,6 @@ func (s Strategy) validateBuildVolumes(strategyVolumes []build.BuildStrategyVolu if !valid { s.Build.Status.Reason = build.BuildReasonPtr(reason) - s.Build.Status.Message = ptr.To[string](message) + s.Build.Status.Message = pointer.String(message) } } diff --git a/pkg/validate/trigger.go b/pkg/validate/trigger.go index bd3160f20..562aafea1 100644 --- a/pkg/validate/trigger.go +++ b/pkg/validate/trigger.go @@ -9,7 +9,7 @@ import ( build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" kerrors "k8s.io/apimachinery/pkg/util/errors" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" ) // Trigger implements the interface BuildPath with the objective of applying validations against the @@ -24,7 +24,7 @@ func (t *Trigger) validate(triggerWhen []build.TriggerWhen) []error { for _, when := range triggerWhen { if when.Name == "" { t.build.Status.Reason = build.BuildReasonPtr(build.TriggerNameCanNotBeBlank) - t.build.Status.Message = ptr.To[string]("name is not set on when trigger condition") + t.build.Status.Message = pointer.String("name is not set on when trigger condition") allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) } @@ -32,14 +32,14 @@ func (t *Trigger) validate(triggerWhen []build.TriggerWhen) []error { case build.GitHubWebHookTrigger: if when.GitHub == nil { t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidGitHubWebHook) - t.build.Status.Message = ptr.To[string](fmt.Sprintf( + t.build.Status.Message = pointer.String(fmt.Sprintf( "%q is missing required attribute `.github`", when.Name, )) allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) } else { if len(when.GitHub.Events) == 0 { t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidGitHubWebHook) - t.build.Status.Message = ptr.To[string](fmt.Sprintf( + t.build.Status.Message = pointer.String(fmt.Sprintf( "%q is missing required attribute `.github.events`", when.Name, )) allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) @@ -48,14 +48,14 @@ func (t *Trigger) validate(triggerWhen []build.TriggerWhen) []error { case build.ImageTrigger: if when.Image == nil { t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidImage) - t.build.Status.Message = ptr.To[string](fmt.Sprintf( + t.build.Status.Message = pointer.String(fmt.Sprintf( "%q is missing required attribute `.image`", when.Name, )) allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) } else { if len(when.Image.Names) == 0 { t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidImage) - t.build.Status.Message = ptr.To[string](fmt.Sprintf( + t.build.Status.Message = pointer.String(fmt.Sprintf( "%q is missing required attribute `.image.names`", when.Name, )) allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) @@ -64,21 +64,21 @@ func (t *Trigger) validate(triggerWhen []build.TriggerWhen) []error { case build.PipelineTrigger: if when.ObjectRef == nil { t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidPipeline) - t.build.Status.Message = ptr.To[string](fmt.Sprintf( + t.build.Status.Message = pointer.String(fmt.Sprintf( "%q is missing required attribute `.objectRef`", when.Name, )) allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) } else { if len(when.ObjectRef.Status) == 0 { t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidPipeline) - t.build.Status.Message = ptr.To[string](fmt.Sprintf( + t.build.Status.Message = pointer.String(fmt.Sprintf( "%q is missing required attribute `.objectRef.status`", when.Name, )) allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) } if when.ObjectRef.Name == "" && len(when.ObjectRef.Selector) == 0 { t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidPipeline) - t.build.Status.Message = ptr.To[string](fmt.Sprintf( + t.build.Status.Message = pointer.String(fmt.Sprintf( "%q is missing required attributes `.objectRef.name` or `.objectRef.selector`", when.Name, )) @@ -86,7 +86,7 @@ func (t *Trigger) validate(triggerWhen []build.TriggerWhen) []error { } if when.ObjectRef.Name != "" && len(when.ObjectRef.Selector) > 0 { t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidPipeline) - t.build.Status.Message = ptr.To[string](fmt.Sprintf( + t.build.Status.Message = pointer.String(fmt.Sprintf( "%q contains `.objectRef.name` and `.objectRef.selector`, must be only one", when.Name, )) @@ -95,7 +95,7 @@ func (t *Trigger) validate(triggerWhen []build.TriggerWhen) []error { } default: t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidType) - t.build.Status.Message = ptr.To[string]( + t.build.Status.Message = pointer.String( fmt.Sprintf("%q contains an invalid type %q", when.Name, when.Type)) allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) } diff --git a/pkg/webhook/conversion/converter_test.go b/pkg/webhook/conversion/converter_test.go index 6ecdc7e40..f9d378038 100644 --- a/pkg/webhook/conversion/converter_test.go +++ b/pkg/webhook/conversion/converter_test.go @@ -22,7 +22,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer/json" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" ) func getConversionReview(o string) (apiextensionsv1.ConversionReview, error) { @@ -497,7 +497,7 @@ request: }, }, Retention: &v1beta1.BuildRetention{ - AtBuildDeletion: ptr.To[bool](true), + AtBuildDeletion: pointer.Bool(true), }, Trigger: &v1beta1.Trigger{ When: []v1beta1.TriggerWhen{ @@ -1157,7 +1157,7 @@ request: Name: "dockerfile", Description: "The Dockerfile to be built.", Type: v1beta1.ParameterTypeString, - Default: ptr.To[string]("Dockerfile"), + Default: pointer.String("Dockerfile"), }, }, SecurityContext: &v1beta1.BuildStrategySecurityContext{ diff --git a/test/e2e/v1alpha1/common_suite_test.go b/test/e2e/v1alpha1/common_suite_test.go index b4b453d21..14a166fc4 100644 --- a/test/e2e/v1alpha1/common_suite_test.go +++ b/test/e2e/v1alpha1/common_suite_test.go @@ -17,7 +17,7 @@ import ( core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" ) @@ -73,7 +73,7 @@ func (b *buildPrototype) SourceCredentials(name string) *buildPrototype { } func (b *buildPrototype) SourceGit(repository string) *buildPrototype { - b.build.Spec.Source.URL = ptr.To[string](repository) + b.build.Spec.Source.URL = pointer.String(repository) b.build.Spec.Source.BundleContainer = nil return b } @@ -95,7 +95,7 @@ func (b *buildPrototype) SourceBundlePrune(prune buildv1alpha1.PruneOption) *bui } func (b *buildPrototype) SourceContextDir(contextDir string) *buildPrototype { - b.build.Spec.Source.ContextDir = ptr.To[string](contextDir) + b.build.Spec.Source.ContextDir = pointer.String(contextDir) return b } @@ -280,7 +280,7 @@ func (b *buildRunPrototype) GenerateServiceAccount() *buildRunPrototype { if b.buildRun.Spec.ServiceAccount == nil { b.buildRun.Spec.ServiceAccount = &buildv1alpha1.ServiceAccount{} } - b.buildRun.Spec.ServiceAccount.Generate = ptr.To[bool](true) + b.buildRun.Spec.ServiceAccount.Generate = pointer.Bool(true) return b } diff --git a/test/e2e/v1alpha1/e2e_params_test.go b/test/e2e/v1alpha1/e2e_params_test.go index 608b5adf2..de46de58d 100644 --- a/test/e2e/v1alpha1/e2e_params_test.go +++ b/test/e2e/v1alpha1/e2e_params_test.go @@ -12,7 +12,7 @@ import ( test "github.com/shipwright-io/build/test/v1alpha1_samples" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" ) var _ = Describe("For a Kubernetes cluster with Tekton and build installed", func() { @@ -101,7 +101,7 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun OutputImage("dummy"). // The parameters StringParamValue("env1", "13"). - StringParamValueFromConfigMap("env2", "a-configmap", "number1", ptr.To[string]("2${CONFIGMAP_VALUE}")). + StringParamValueFromConfigMap("env2", "a-configmap", "number1", pointer.String("2${CONFIGMAP_VALUE}")). ArrayParamValueFromConfigMap("commands", "a-configmap", "shell", nil). ArrayParamValue("commands", "-c"). Create() @@ -115,7 +115,7 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun GenerateServiceAccount(). StringParamValue("image", "registry.access.redhat.com/ubi9/ubi-minimal"). StringParamValueFromSecret("env3", "a-secret", "number2", nil). - ArrayParamValueFromSecret("args", "a-secret", "number3", ptr.To[string]("${SECRET_VALUE}9")). + ArrayParamValueFromSecret("args", "a-secret", "number3", pointer.String("${SECRET_VALUE}9")). ArrayParamValue("args", "47"). Create() Expect(err).ToNot(HaveOccurred()) diff --git a/test/e2e/v1alpha1/validators_test.go b/test/e2e/v1alpha1/validators_test.go index ba68b0a58..a2d3c677b 100644 --- a/test/e2e/v1alpha1/validators_test.go +++ b/test/e2e/v1alpha1/validators_test.go @@ -20,7 +20,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/kubectl/pkg/scheme" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" "github.com/shipwright-io/build/pkg/apis" buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" @@ -337,7 +337,7 @@ func buildRunTestData(ns string, identifier string, filePath string) (*buildv1al serviceAccountName := os.Getenv(EnvVarServiceAccountName) if serviceAccountName == "generated" { buildRun.Spec.ServiceAccount = &buildv1alpha1.ServiceAccount{ - Generate: ptr.To[bool](true), + Generate: pointer.Bool(true), } } else { buildRun.Spec.ServiceAccount = &buildv1alpha1.ServiceAccount{ diff --git a/test/e2e/v1beta1/common_suite_test.go b/test/e2e/v1beta1/common_suite_test.go index 21b5fbc52..2cb4c1638 100644 --- a/test/e2e/v1beta1/common_suite_test.go +++ b/test/e2e/v1beta1/common_suite_test.go @@ -17,7 +17,7 @@ import ( core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) @@ -79,7 +79,7 @@ func (b *buildPrototype) SourceGit(repository string) *buildPrototype { if b.build.Spec.Source.GitSource == nil { b.build.Spec.Source.GitSource = &buildv1beta1.Git{} } - b.build.Spec.Source.GitSource.URL = ptr.To[string](repository) + b.build.Spec.Source.GitSource.URL = pointer.String(repository) b.build.Spec.Source.OCIArtifact = nil return b } @@ -102,7 +102,7 @@ func (b *buildPrototype) SourceBundlePrune(prune buildv1beta1.PruneOption) *buil } func (b *buildPrototype) SourceContextDir(contextDir string) *buildPrototype { - b.build.Spec.Source.ContextDir = ptr.To[string](contextDir) + b.build.Spec.Source.ContextDir = pointer.String(contextDir) return b } diff --git a/test/e2e/v1beta1/e2e_params_test.go b/test/e2e/v1beta1/e2e_params_test.go index 9f018e945..a4ed64b2d 100644 --- a/test/e2e/v1beta1/e2e_params_test.go +++ b/test/e2e/v1beta1/e2e_params_test.go @@ -12,7 +12,7 @@ import ( test "github.com/shipwright-io/build/test/v1beta1_samples" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" ) var _ = Describe("For a Kubernetes cluster with Tekton and build installed", func() { @@ -101,7 +101,7 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun OutputImage("dummy"). // The parameters StringParamValue("env1", "13"). - StringParamValueFromConfigMap("env2", "a-configmap", "number1", ptr.To[string]("2${CONFIGMAP_VALUE}")). + StringParamValueFromConfigMap("env2", "a-configmap", "number1", pointer.String("2${CONFIGMAP_VALUE}")). ArrayParamValueFromConfigMap("commands", "a-configmap", "shell", nil). ArrayParamValue("commands", "-c"). Create() @@ -115,7 +115,7 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun GenerateServiceAccount(). StringParamValue("image", "registry.access.redhat.com/ubi9/ubi-minimal"). StringParamValueFromSecret("env3", "a-secret", "number2", nil). - ArrayParamValueFromSecret("args", "a-secret", "number3", ptr.To[string]("${SECRET_VALUE}9")). + ArrayParamValueFromSecret("args", "a-secret", "number3", pointer.String("${SECRET_VALUE}9")). ArrayParamValue("args", "47"). Create() Expect(err).ToNot(HaveOccurred()) diff --git a/test/integration/build_to_git_test.go b/test/integration/build_to_git_test.go index 0dc6f3777..0f0cefdc8 100644 --- a/test/integration/build_to_git_test.go +++ b/test/integration/build_to_git_test.go @@ -10,7 +10,7 @@ import ( "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" test "github.com/shipwright-io/build/test/v1alpha1_samples" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" ) var _ = Describe("Integration tests Build and referenced Source url", func() { @@ -47,7 +47,7 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "true" - buildObject.Spec.Source.URL = ptr.To[string]("http://github.com/shipwright-io/sample-go") + buildObject.Spec.Source.URL = pointer.String("http://github.com/shipwright-io/sample-go") Expect(tb.CreateBuild(buildObject)).To(BeNil()) @@ -72,7 +72,7 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { ) Expect(err).To(BeNil()) - buildObject.Spec.Source.URL = ptr.To[string]("http://github.com/shipwright-io/sample-go-fake") + buildObject.Spec.Source.URL = pointer.String("http://github.com/shipwright-io/sample-go-fake") Expect(tb.CreateBuild(buildObject)).To(BeNil()) // wait until the Build finish the validation @@ -98,7 +98,7 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "true" - buildObject.Spec.Source.URL = ptr.To[string]("https://github.com/shipwright-io/sample-go") + buildObject.Spec.Source.URL = pointer.String("https://github.com/shipwright-io/sample-go") Expect(tb.CreateBuild(buildObject)).To(BeNil()) @@ -123,7 +123,7 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { ) Expect(err).To(BeNil()) - buildObject.Spec.Source.URL = ptr.To[string]("https://github.com/shipwright-io/sample-go-fake") + buildObject.Spec.Source.URL = pointer.String("https://github.com/shipwright-io/sample-go-fake") Expect(tb.CreateBuild(buildObject)).To(BeNil()) // wait until the Build finish the validation @@ -149,7 +149,7 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "true" - buildObject.Spec.Source.URL = ptr.To[string]("foobar") + buildObject.Spec.Source.URL = pointer.String("foobar") Expect(tb.CreateBuild(buildObject)).To(BeNil()) @@ -176,7 +176,7 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "false" - buildObject.Spec.Source.URL = ptr.To[string]("foobar") + buildObject.Spec.Source.URL = pointer.String("foobar") Expect(tb.CreateBuild(buildObject)).To(BeNil()) // wait until the Build finish the validation @@ -202,7 +202,7 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "true" - buildObject.Spec.Source.URL = ptr.To[string]("https://github.yourco.com/org/build-fake") + buildObject.Spec.Source.URL = pointer.String("https://github.yourco.com/org/build-fake") Expect(tb.CreateBuild(buildObject)).To(BeNil()) @@ -228,7 +228,7 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "true" - buildObject.Spec.Source.URL = ptr.To[string]("https://github.yourco.com/org/build-fake") + buildObject.Spec.Source.URL = pointer.String("https://github.yourco.com/org/build-fake") buildObject.Spec.Source.Credentials = &corev1.LocalObjectReference{Name: "foobar"} sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Source.Credentials.Name, buildObject.Namespace) @@ -260,7 +260,7 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "true" - buildObject.Spec.Source.URL = ptr.To[string]("git@github.com:shipwright-io/build-fake.git") + buildObject.Spec.Source.URL = pointer.String("git@github.com:shipwright-io/build-fake.git") Expect(tb.CreateBuild(buildObject)).To(BeNil()) @@ -288,7 +288,7 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "true" - buildObject.Spec.Source.URL = ptr.To[string]("ssh://github.com/shipwright-io/build-fake.git") + buildObject.Spec.Source.URL = pointer.String("ssh://github.com/shipwright-io/build-fake.git") Expect(tb.CreateBuild(buildObject)).To(BeNil()) diff --git a/test/v1alpha1_samples/catalog.go b/test/v1alpha1_samples/catalog.go index f8f700df3..beab9e356 100644 --- a/test/v1alpha1_samples/catalog.go +++ b/test/v1alpha1_samples/catalog.go @@ -21,7 +21,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/yaml" @@ -99,7 +99,7 @@ func (c *Catalog) BuildWithClusterBuildStrategyAndFalseSourceAnnotation(name str }, Spec: build.BuildSpec{ Source: build.Source{ - URL: ptr.To[string]("foobar"), + URL: pointer.String("foobar"), }, Strategy: build.Strategy{ Name: strategyName, @@ -122,7 +122,7 @@ func (c *Catalog) BuildWithClusterBuildStrategy(name string, ns string, strategy }, Spec: build.BuildSpec{ Source: build.Source{ - URL: ptr.To[string]("https://github.com/shipwright-io/sample-go"), + URL: pointer.String("https://github.com/shipwright-io/sample-go"), }, Strategy: build.Strategy{ Name: strategyName, @@ -148,7 +148,7 @@ func (c *Catalog) BuildWithClusterBuildStrategyAndSourceSecret(name string, ns s }, Spec: build.BuildSpec{ Source: build.Source{ - URL: ptr.To[string]("https://github.com/shipwright-io/sample-go"), + URL: pointer.String("https://github.com/shipwright-io/sample-go"), Credentials: &corev1.LocalObjectReference{ Name: "foobar", }, @@ -174,7 +174,7 @@ func (c *Catalog) BuildWithBuildStrategy(name string, ns string, strategyName st }, Spec: build.BuildSpec{ Source: build.Source{ - URL: ptr.To[string]("https://github.com/shipwright-io/sample-go"), + URL: pointer.String("https://github.com/shipwright-io/sample-go"), }, Strategy: build.Strategy{ Name: strategyName, @@ -193,7 +193,7 @@ func (c *Catalog) BuildWithNilBuildStrategyKind(name string, ns string, strategy }, Spec: build.BuildSpec{ Source: build.Source{ - URL: ptr.To[string]("https://github.com/shipwright-io/sample-go"), + URL: pointer.String("https://github.com/shipwright-io/sample-go"), }, Strategy: build.Strategy{ Name: strategyName, @@ -211,7 +211,7 @@ func (c *Catalog) BuildWithOutputSecret(name string, ns string, secretName strin }, Spec: build.BuildSpec{ Source: build.Source{ - URL: ptr.To[string]("https://github.com/shipwright-io/sample-go"), + URL: pointer.String("https://github.com/shipwright-io/sample-go"), }, Output: build.Image{ Credentials: &corev1.LocalObjectReference{ @@ -953,7 +953,7 @@ func (c *Catalog) BuildRunWithSA(buildRunName string, buildName string, saName s }, ServiceAccount: &build.ServiceAccount{ Name: &saName, - Generate: ptr.To[bool](false), + Generate: pointer.Bool(false), }, }, Status: build.BuildRunStatus{}, @@ -971,7 +971,7 @@ func (c *Catalog) BuildRunWithoutSA(buildRunName string, buildName string) *buil Name: buildName, }, ServiceAccount: &build.ServiceAccount{ - Generate: ptr.To[bool](false), + Generate: pointer.Bool(false), }, }, } @@ -989,7 +989,7 @@ func (c *Catalog) BuildRunWithSAGenerate(buildRunName string, buildName string) Name: buildName, }, ServiceAccount: &build.ServiceAccount{ - Generate: ptr.To[bool](true), + Generate: pointer.Bool(true), }, }, } diff --git a/test/v1beta1_samples/catalog.go b/test/v1beta1_samples/catalog.go index 675ec595f..029aa2b25 100644 --- a/test/v1beta1_samples/catalog.go +++ b/test/v1beta1_samples/catalog.go @@ -21,7 +21,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/ptr" + "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/yaml" @@ -100,7 +100,7 @@ func (c *Catalog) BuildWithClusterBuildStrategyAndFalseSourceAnnotation(name str Spec: build.BuildSpec{ Source: build.Source{ GitSource: &build.Git{ - URL: ptr.To[string]("foobar"), + URL: pointer.String("foobar"), }, }, Strategy: build.Strategy{ @@ -125,7 +125,7 @@ func (c *Catalog) BuildWithClusterBuildStrategy(name string, ns string, strategy Spec: build.BuildSpec{ Source: build.Source{ GitSource: &build.Git{ - URL: ptr.To[string]("https://github.com/shipwright-io/sample-go"), + URL: pointer.String("https://github.com/shipwright-io/sample-go"), }, }, Strategy: build.Strategy{ @@ -152,7 +152,7 @@ func (c *Catalog) BuildWithClusterBuildStrategyAndSourceSecret(name string, ns s Spec: build.BuildSpec{ Source: build.Source{ GitSource: &build.Git{ - URL: ptr.To[string]("https://github.com/shipwright-io/sample-go"), + URL: pointer.String("https://github.com/shipwright-io/sample-go"), CloneSecret: &secret, }, }, @@ -178,7 +178,7 @@ func (c *Catalog) BuildWithBuildStrategy(name string, ns string, strategyName st Spec: build.BuildSpec{ Source: build.Source{ GitSource: &build.Git{ - URL: ptr.To[string]("https://github.com/shipwright-io/sample-go"), + URL: pointer.String("https://github.com/shipwright-io/sample-go"), }, }, Strategy: build.Strategy{ @@ -199,7 +199,7 @@ func (c *Catalog) BuildWithNilBuildStrategyKind(name string, ns string, strategy Spec: build.BuildSpec{ Source: build.Source{ GitSource: &build.Git{ - URL: ptr.To[string]("https://github.com/shipwright-io/sample-go"), + URL: pointer.String("https://github.com/shipwright-io/sample-go"), }, }, Strategy: build.Strategy{ @@ -219,7 +219,7 @@ func (c *Catalog) BuildWithOutputSecret(name string, ns string, secretName strin Spec: build.BuildSpec{ Source: build.Source{ GitSource: &build.Git{ - URL: ptr.To[string]("https://github.com/shipwright-io/sample-go"), + URL: pointer.String("https://github.com/shipwright-io/sample-go"), }, }, Output: build.Image{ @@ -725,7 +725,7 @@ func (c *Catalog) BuildWithBuildRunDeletions(buildName string, strategyName stri Kind: &strategyKind, }, Retention: &build.BuildRetention{ - AtBuildDeletion: ptr.To[bool](true), + AtBuildDeletion: pointer.Bool(true), }, }, Status: build.BuildStatus{ @@ -748,7 +748,7 @@ func (c *Catalog) BuildWithBuildRunDeletionsAndFakeNS(buildName string, strategy Kind: &strategyKind, }, Retention: &build.BuildRetention{ - AtBuildDeletion: ptr.To[bool](true), + AtBuildDeletion: pointer.Bool(true), }, }, Status: build.BuildStatus{ @@ -994,7 +994,7 @@ func (c *Catalog) BuildRunWithSAGenerate(buildRunName string, buildName string) Build: &build.ReferencedBuild{ Name: buildName, }, - ServiceAccount: ptr.To[string](".generate"), + ServiceAccount: pointer.String(".generate"), }, } } diff --git a/vendor/k8s.io/utils/pointer/pointer.go b/vendor/k8s.io/utils/pointer/pointer.go index b673a6425..b8103223a 100644 --- a/vendor/k8s.io/utils/pointer/pointer.go +++ b/vendor/k8s.io/utils/pointer/pointer.go @@ -14,15 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Deprecated: Use functions in k8s.io/utils/ptr instead: ptr.To to obtain -// a pointer, ptr.Deref to dereference a pointer, ptr.Equal to compare -// dereferenced pointers. package pointer import ( + "fmt" + "reflect" "time" - - "k8s.io/utils/ptr" ) // AllPtrFieldsNil tests whether all pointer fields in a struct are nil. This is useful when, @@ -31,219 +28,383 @@ import ( // // This function is only valid for structs and pointers to structs. Any other // type will cause a panic. Passing a typed nil pointer will return true. -// -// Deprecated: Use ptr.AllPtrFieldsNil instead. -var AllPtrFieldsNil = ptr.AllPtrFieldsNil - -// Int returns a pointer to an int. -var Int = ptr.To[int] +func AllPtrFieldsNil(obj interface{}) bool { + v := reflect.ValueOf(obj) + if !v.IsValid() { + panic(fmt.Sprintf("reflect.ValueOf() produced a non-valid Value for %#v", obj)) + } + if v.Kind() == reflect.Ptr { + if v.IsNil() { + return true + } + v = v.Elem() + } + for i := 0; i < v.NumField(); i++ { + if v.Field(i).Kind() == reflect.Ptr && !v.Field(i).IsNil() { + return false + } + } + return true +} + +// Int returns a pointer to an int +func Int(i int) *int { + return &i +} // IntPtr is a function variable referring to Int. // -// Deprecated: Use ptr.To instead. +// Deprecated: Use Int instead. var IntPtr = Int // for back-compat // IntDeref dereferences the int ptr and returns it if not nil, or else // returns def. -var IntDeref = ptr.Deref[int] +func IntDeref(ptr *int, def int) int { + if ptr != nil { + return *ptr + } + return def +} // IntPtrDerefOr is a function variable referring to IntDeref. // -// Deprecated: Use ptr.Deref instead. +// Deprecated: Use IntDeref instead. var IntPtrDerefOr = IntDeref // for back-compat // Int32 returns a pointer to an int32. -var Int32 = ptr.To[int32] +func Int32(i int32) *int32 { + return &i +} // Int32Ptr is a function variable referring to Int32. // -// Deprecated: Use ptr.To instead. +// Deprecated: Use Int32 instead. var Int32Ptr = Int32 // for back-compat // Int32Deref dereferences the int32 ptr and returns it if not nil, or else // returns def. -var Int32Deref = ptr.Deref[int32] +func Int32Deref(ptr *int32, def int32) int32 { + if ptr != nil { + return *ptr + } + return def +} // Int32PtrDerefOr is a function variable referring to Int32Deref. // -// Deprecated: Use ptr.Deref instead. +// Deprecated: Use Int32Deref instead. var Int32PtrDerefOr = Int32Deref // for back-compat // Int32Equal returns true if both arguments are nil or both arguments // dereference to the same value. -var Int32Equal = ptr.Equal[int32] +func Int32Equal(a, b *int32) bool { + if (a == nil) != (b == nil) { + return false + } + if a == nil { + return true + } + return *a == *b +} // Uint returns a pointer to an uint -var Uint = ptr.To[uint] +func Uint(i uint) *uint { + return &i +} // UintPtr is a function variable referring to Uint. // -// Deprecated: Use ptr.To instead. +// Deprecated: Use Uint instead. var UintPtr = Uint // for back-compat // UintDeref dereferences the uint ptr and returns it if not nil, or else // returns def. -var UintDeref = ptr.Deref[uint] +func UintDeref(ptr *uint, def uint) uint { + if ptr != nil { + return *ptr + } + return def +} // UintPtrDerefOr is a function variable referring to UintDeref. // -// Deprecated: Use ptr.Deref instead. +// Deprecated: Use UintDeref instead. var UintPtrDerefOr = UintDeref // for back-compat // Uint32 returns a pointer to an uint32. -var Uint32 = ptr.To[uint32] +func Uint32(i uint32) *uint32 { + return &i +} // Uint32Ptr is a function variable referring to Uint32. // -// Deprecated: Use ptr.To instead. +// Deprecated: Use Uint32 instead. var Uint32Ptr = Uint32 // for back-compat // Uint32Deref dereferences the uint32 ptr and returns it if not nil, or else // returns def. -var Uint32Deref = ptr.Deref[uint32] +func Uint32Deref(ptr *uint32, def uint32) uint32 { + if ptr != nil { + return *ptr + } + return def +} // Uint32PtrDerefOr is a function variable referring to Uint32Deref. // -// Deprecated: Use ptr.Deref instead. +// Deprecated: Use Uint32Deref instead. var Uint32PtrDerefOr = Uint32Deref // for back-compat // Uint32Equal returns true if both arguments are nil or both arguments // dereference to the same value. -var Uint32Equal = ptr.Equal[uint32] +func Uint32Equal(a, b *uint32) bool { + if (a == nil) != (b == nil) { + return false + } + if a == nil { + return true + } + return *a == *b +} // Int64 returns a pointer to an int64. -var Int64 = ptr.To[int64] +func Int64(i int64) *int64 { + return &i +} // Int64Ptr is a function variable referring to Int64. // -// Deprecated: Use ptr.To instead. +// Deprecated: Use Int64 instead. var Int64Ptr = Int64 // for back-compat // Int64Deref dereferences the int64 ptr and returns it if not nil, or else // returns def. -var Int64Deref = ptr.Deref[int64] +func Int64Deref(ptr *int64, def int64) int64 { + if ptr != nil { + return *ptr + } + return def +} // Int64PtrDerefOr is a function variable referring to Int64Deref. // -// Deprecated: Use ptr.Deref instead. +// Deprecated: Use Int64Deref instead. var Int64PtrDerefOr = Int64Deref // for back-compat // Int64Equal returns true if both arguments are nil or both arguments // dereference to the same value. -var Int64Equal = ptr.Equal[int64] +func Int64Equal(a, b *int64) bool { + if (a == nil) != (b == nil) { + return false + } + if a == nil { + return true + } + return *a == *b +} // Uint64 returns a pointer to an uint64. -var Uint64 = ptr.To[uint64] +func Uint64(i uint64) *uint64 { + return &i +} // Uint64Ptr is a function variable referring to Uint64. // -// Deprecated: Use ptr.To instead. +// Deprecated: Use Uint64 instead. var Uint64Ptr = Uint64 // for back-compat // Uint64Deref dereferences the uint64 ptr and returns it if not nil, or else // returns def. -var Uint64Deref = ptr.Deref[uint64] +func Uint64Deref(ptr *uint64, def uint64) uint64 { + if ptr != nil { + return *ptr + } + return def +} // Uint64PtrDerefOr is a function variable referring to Uint64Deref. // -// Deprecated: Use ptr.Deref instead. +// Deprecated: Use Uint64Deref instead. var Uint64PtrDerefOr = Uint64Deref // for back-compat // Uint64Equal returns true if both arguments are nil or both arguments // dereference to the same value. -var Uint64Equal = ptr.Equal[uint64] +func Uint64Equal(a, b *uint64) bool { + if (a == nil) != (b == nil) { + return false + } + if a == nil { + return true + } + return *a == *b +} // Bool returns a pointer to a bool. -var Bool = ptr.To[bool] +func Bool(b bool) *bool { + return &b +} // BoolPtr is a function variable referring to Bool. // -// Deprecated: Use ptr.To instead. +// Deprecated: Use Bool instead. var BoolPtr = Bool // for back-compat // BoolDeref dereferences the bool ptr and returns it if not nil, or else // returns def. -var BoolDeref = ptr.Deref[bool] +func BoolDeref(ptr *bool, def bool) bool { + if ptr != nil { + return *ptr + } + return def +} // BoolPtrDerefOr is a function variable referring to BoolDeref. // -// Deprecated: Use ptr.Deref instead. +// Deprecated: Use BoolDeref instead. var BoolPtrDerefOr = BoolDeref // for back-compat // BoolEqual returns true if both arguments are nil or both arguments // dereference to the same value. -var BoolEqual = ptr.Equal[bool] +func BoolEqual(a, b *bool) bool { + if (a == nil) != (b == nil) { + return false + } + if a == nil { + return true + } + return *a == *b +} // String returns a pointer to a string. -var String = ptr.To[string] +func String(s string) *string { + return &s +} // StringPtr is a function variable referring to String. // -// Deprecated: Use ptr.To instead. +// Deprecated: Use String instead. var StringPtr = String // for back-compat // StringDeref dereferences the string ptr and returns it if not nil, or else // returns def. -var StringDeref = ptr.Deref[string] +func StringDeref(ptr *string, def string) string { + if ptr != nil { + return *ptr + } + return def +} // StringPtrDerefOr is a function variable referring to StringDeref. // -// Deprecated: Use ptr.Deref instead. +// Deprecated: Use StringDeref instead. var StringPtrDerefOr = StringDeref // for back-compat // StringEqual returns true if both arguments are nil or both arguments // dereference to the same value. -var StringEqual = ptr.Equal[string] +func StringEqual(a, b *string) bool { + if (a == nil) != (b == nil) { + return false + } + if a == nil { + return true + } + return *a == *b +} // Float32 returns a pointer to a float32. -var Float32 = ptr.To[float32] +func Float32(i float32) *float32 { + return &i +} // Float32Ptr is a function variable referring to Float32. // -// Deprecated: Use ptr.To instead. +// Deprecated: Use Float32 instead. var Float32Ptr = Float32 // Float32Deref dereferences the float32 ptr and returns it if not nil, or else // returns def. -var Float32Deref = ptr.Deref[float32] +func Float32Deref(ptr *float32, def float32) float32 { + if ptr != nil { + return *ptr + } + return def +} // Float32PtrDerefOr is a function variable referring to Float32Deref. // -// Deprecated: Use ptr.Deref instead. +// Deprecated: Use Float32Deref instead. var Float32PtrDerefOr = Float32Deref // for back-compat // Float32Equal returns true if both arguments are nil or both arguments // dereference to the same value. -var Float32Equal = ptr.Equal[float32] +func Float32Equal(a, b *float32) bool { + if (a == nil) != (b == nil) { + return false + } + if a == nil { + return true + } + return *a == *b +} // Float64 returns a pointer to a float64. -var Float64 = ptr.To[float64] +func Float64(i float64) *float64 { + return &i +} // Float64Ptr is a function variable referring to Float64. // -// Deprecated: Use ptr.To instead. +// Deprecated: Use Float64 instead. var Float64Ptr = Float64 // Float64Deref dereferences the float64 ptr and returns it if not nil, or else // returns def. -var Float64Deref = ptr.Deref[float64] +func Float64Deref(ptr *float64, def float64) float64 { + if ptr != nil { + return *ptr + } + return def +} // Float64PtrDerefOr is a function variable referring to Float64Deref. // -// Deprecated: Use ptr.Deref instead. +// Deprecated: Use Float64Deref instead. var Float64PtrDerefOr = Float64Deref // for back-compat // Float64Equal returns true if both arguments are nil or both arguments // dereference to the same value. -var Float64Equal = ptr.Equal[float64] +func Float64Equal(a, b *float64) bool { + if (a == nil) != (b == nil) { + return false + } + if a == nil { + return true + } + return *a == *b +} // Duration returns a pointer to a time.Duration. -var Duration = ptr.To[time.Duration] +func Duration(d time.Duration) *time.Duration { + return &d +} // DurationDeref dereferences the time.Duration ptr and returns it if not nil, or else // returns def. -var DurationDeref = ptr.Deref[time.Duration] +func DurationDeref(ptr *time.Duration, def time.Duration) time.Duration { + if ptr != nil { + return *ptr + } + return def +} // DurationEqual returns true if both arguments are nil or both arguments // dereference to the same value. -var DurationEqual = ptr.Equal[time.Duration] +func DurationEqual(a, b *time.Duration) bool { + if (a == nil) != (b == nil) { + return false + } + if a == nil { + return true + } + return *a == *b +} diff --git a/vendor/k8s.io/utils/ptr/OWNERS b/vendor/k8s.io/utils/ptr/OWNERS deleted file mode 100644 index 0d6392752..000000000 --- a/vendor/k8s.io/utils/ptr/OWNERS +++ /dev/null @@ -1,10 +0,0 @@ -# See the OWNERS docs at https://go.k8s.io/owners - -approvers: -- apelisse -- stewart-yu -- thockin -reviewers: -- apelisse -- stewart-yu -- thockin diff --git a/vendor/k8s.io/utils/ptr/README.md b/vendor/k8s.io/utils/ptr/README.md deleted file mode 100644 index 2ca8073dc..000000000 --- a/vendor/k8s.io/utils/ptr/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Pointer - -This package provides some functions for pointer-based operations. diff --git a/vendor/k8s.io/utils/ptr/ptr.go b/vendor/k8s.io/utils/ptr/ptr.go deleted file mode 100644 index 659ed3b9e..000000000 --- a/vendor/k8s.io/utils/ptr/ptr.go +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright 2023 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package ptr - -import ( - "fmt" - "reflect" -) - -// AllPtrFieldsNil tests whether all pointer fields in a struct are nil. This is useful when, -// for example, an API struct is handled by plugins which need to distinguish -// "no plugin accepted this spec" from "this spec is empty". -// -// This function is only valid for structs and pointers to structs. Any other -// type will cause a panic. Passing a typed nil pointer will return true. -func AllPtrFieldsNil(obj interface{}) bool { - v := reflect.ValueOf(obj) - if !v.IsValid() { - panic(fmt.Sprintf("reflect.ValueOf() produced a non-valid Value for %#v", obj)) - } - if v.Kind() == reflect.Ptr { - if v.IsNil() { - return true - } - v = v.Elem() - } - for i := 0; i < v.NumField(); i++ { - if v.Field(i).Kind() == reflect.Ptr && !v.Field(i).IsNil() { - return false - } - } - return true -} - -// To returns a pointer to the given value. -func To[T any](v T) *T { - return &v -} - -// Deref dereferences ptr and returns the value it points to if no nil, or else -// returns def. -func Deref[T any](ptr *T, def T) T { - if ptr != nil { - return *ptr - } - return def -} - -// Equal returns true if both arguments are nil or both arguments -// dereference to the same value. -func Equal[T comparable](a, b *T) bool { - if (a == nil) != (b == nil) { - return false - } - if a == nil { - return true - } - return *a == *b -} diff --git a/vendor/k8s.io/utils/trace/trace.go b/vendor/k8s.io/utils/trace/trace.go index 187eb5d8c..a0b07a6d7 100644 --- a/vendor/k8s.io/utils/trace/trace.go +++ b/vendor/k8s.io/utils/trace/trace.go @@ -65,11 +65,6 @@ func durationToMilliseconds(timeDuration time.Duration) int64 { } type traceItem interface { - // rLock must be called before invoking time or writeItem. - rLock() - // rUnlock must be called after processing the item is complete. - rUnlock() - // time returns when the trace was recorded as completed. time() time.Time // writeItem outputs the traceItem to the buffer. If stepThreshold is non-nil, only output the @@ -84,10 +79,6 @@ type traceStep struct { fields []Field } -// rLock doesn't need to do anything because traceStep instances are immutable. -func (s traceStep) rLock() {} -func (s traceStep) rUnlock() {} - func (s traceStep) time() time.Time { return s.stepTime } @@ -115,14 +106,6 @@ type Trace struct { traceItems []traceItem } -func (t *Trace) rLock() { - t.lock.RLock() -} - -func (t *Trace) rUnlock() { - t.lock.RUnlock() -} - func (t *Trace) time() time.Time { if t.endTime != nil { return *t.endTime @@ -248,10 +231,8 @@ func (t *Trace) logTrace() { func (t *Trace) writeTraceSteps(b *bytes.Buffer, formatter string, stepThreshold *time.Duration) { lastStepTime := t.startTime for _, stepOrTrace := range t.traceItems { - stepOrTrace.rLock() stepOrTrace.writeItem(b, formatter, lastStepTime, stepThreshold) lastStepTime = stepOrTrace.time() - stepOrTrace.rUnlock() } } diff --git a/vendor/modules.txt b/vendor/modules.txt index 57814a08d..51a4da31d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1049,7 +1049,7 @@ k8s.io/kube-openapi/pkg/validation/spec # k8s.io/kubectl v0.26.9 ## explicit; go 1.19 k8s.io/kubectl/pkg/scheme -# k8s.io/utils v0.0.0-20230726121419-3b25d923346b +# k8s.io/utils v0.0.0-20230209194617-a36077c30491 ## explicit; go 1.18 k8s.io/utils/buffer k8s.io/utils/clock @@ -1058,7 +1058,6 @@ k8s.io/utils/integer k8s.io/utils/internal/third_party/forked/golang/net k8s.io/utils/net k8s.io/utils/pointer -k8s.io/utils/ptr k8s.io/utils/strings/slices k8s.io/utils/trace # knative.dev/pkg v0.0.0-20230221145627-8efb3485adcf