Skip to content

Commit

Permalink
removes deprecated pointer references
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvajagtap committed Oct 13, 2023
1 parent 26ccd15 commit bb891a7
Show file tree
Hide file tree
Showing 26 changed files with 174 additions and 175 deletions.
4 changes: 2 additions & 2 deletions pkg/apis/build/v1beta1/build_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/pointer"
"k8s.io/utils/ptr"
)

const (
Expand Down Expand Up @@ -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 = pointer.Bool(value == "true")
src.Spec.Retention.AtBuildDeletion = ptr.To[bool](value == "true")
delete(src.ObjectMeta.Annotations, v1alpha1.AnnotationBuildRunDeletion)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/build/v1beta1/buildstrategy_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/pointer"
"k8s.io/utils/ptr"
)

// ensure v1beta1 implements the Conversion interface
Expand Down Expand Up @@ -213,7 +213,7 @@ func (src *BuildStrategySpec) ConvertFrom(bs v1alpha1.BuildStrategySpec) {
Name: "dockerfile",
Description: "The Dockerfile to be built.",
Type: ParameterTypeString,
Default: pointer.String("Dockerfile"),
Default: ptr.To[string]("Dockerfile"),
})
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/pointer"
"k8s.io/utils/ptr"
)

const (
Expand Down Expand Up @@ -85,8 +85,8 @@ var (
metricBuildRunEstablishDurationBuckets = []float64{0, 1, 2, 3, 5, 7, 10, 15, 20, 30}
metricBuildRunRampUpDurationBuckets = prometheus.LinearBuckets(0, 1, 10)

root = pointer.Int64(0)
nonRoot = pointer.Int64(1000)
root = ptr.To[int64](0)
nonRoot = ptr.To[int64](1000)
)

// Config hosts different parameters that
Expand Down Expand Up @@ -162,7 +162,7 @@ func NewDefaultConfig() *Config {
},
},
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: pointer.Bool(false),
AllowPrivilegeEscalation: ptr.To[bool](false),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{
"ALL",
Expand All @@ -186,7 +186,7 @@ func NewDefaultConfig() *Config {
},
},
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: pointer.Bool(false),
AllowPrivilegeEscalation: ptr.To[bool](false),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{
"ALL",
Expand Down Expand Up @@ -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: pointer.Bool(false),
AllowPrivilegeEscalation: ptr.To[bool](false),
RunAsUser: root,
RunAsGroup: root,
Capabilities: &corev1.Capabilities{
Expand Down Expand Up @@ -244,7 +244,7 @@ func NewDefaultConfig() *Config {
},
},
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: pointer.Bool(false),
AllowPrivilegeEscalation: ptr.To[bool](false),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{
"ALL",
Expand Down
10 changes: 5 additions & 5 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/pointer"
"k8s.io/utils/ptr"

. "github.com/shipwright-io/build/pkg/config"
)
Expand Down Expand Up @@ -126,15 +126,15 @@ var _ = Describe("Config", func() {
}

configWithEnvVariableOverrides(overrides, func(config *Config) {
nonRoot := pointer.Int64(1000)
nonRoot := ptr.To[int64](1000)
Expect(config.GitContainerTemplate).To(Equal(pipeline.Step{
Image: "myregistry/custom/git-image",
Command: []string{
"/ko-app/git",
},
Env: []corev1.EnvVar{{Name: "HOME", Value: "/shared-home"}},
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: pointer.Bool(false),
AllowPrivilegeEscalation: ptr.To[bool](false),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{
"ALL",
Expand Down Expand Up @@ -228,14 +228,14 @@ var _ = Describe("Config", func() {
}

configWithEnvVariableOverrides(overrides, func(config *Config) {
nonRoot := pointer.Int64(1000)
nonRoot := ptr.To[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: pointer.Bool(false),
AllowPrivilegeEscalation: ptr.To[bool](false),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{
"ALL",
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/pointer"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -113,7 +113,7 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques
}

b.Status.Registered = build.ConditionStatusPtr(corev1.ConditionTrue)
b.Status.Message = pointer.String(build.AllValidationsSucceeded)
b.Status.Message = ptr.To[string](build.AllValidationsSucceeded)
if err := r.client.Status().Update(ctx, b); err != nil {
return reconcile.Result{}, err
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/reconciler/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/pointer"
"k8s.io/utils/ptr"
crc "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -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 = pointer.String("foobar")
buildSample.Spec.Source.URL = ptr.To[string]("foobar")
buildSample.SetAnnotations(map[string]string{
build.AnnotationBuildVerifyRepository: "true",
})
Expand All @@ -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 = pointer.String("https://github.com/shipwright-io/sample-go-fake")
buildSample.Spec.Source.URL = ptr.To[string]("https://github.com/shipwright-io/sample-go-fake")
buildSample.SetAnnotations(map[string]string{
build.AnnotationBuildVerifyRepository: "true",
})
Expand All @@ -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 = pointer.String("foobar")
buildSample.Spec.Source.URL = ptr.To[string]("foobar")

// Fake some client Get calls and ensure we populate all
// different resources we could get during reconciliation
Expand Down Expand Up @@ -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 = pointer.String("https://github.yourco.com/org/build-fake")
buildSample.Spec.Source.URL = ptr.To[string]("https://github.yourco.com/org/build-fake")
buildSample.Spec.Source.Credentials.Name = registrySecret

// Fake some client Get calls and ensure we populate all
Expand Down
6 changes: 3 additions & 3 deletions pkg/reconciler/buildrun/buildrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -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 = pointer.String(buildv1alpha1.AllValidationsSucceeded)
build.Status.Message = ptr.To[string](buildv1alpha1.AllValidationsSucceeded)
}
}

Expand Down Expand Up @@ -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 = pointer.String(fmt.Sprintf("unexpected error when trying to set the ownerreference: %v", err))
build.Status.Message = ptr.To[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
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/reconciler/buildrun/buildrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/pointer"
"k8s.io/utils/ptr"
knativeapi "knative.dev/pkg/apis"
knativev1 "knative.dev/pkg/apis/duck/v1"
crc "sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -1177,8 +1177,8 @@ var _ = Describe("Reconcile BuildRun", func() {
// in the build
clientUpdateCalls := ctl.StubBuildUpdateOwnerReferences("Build",
buildName,
pointer.Bool(true),
pointer.Bool(true),
ptr.To[bool](true),
ptr.To[bool](true),
)
client.UpdateCalls(clientUpdateCalls)

Expand Down Expand Up @@ -1365,7 +1365,7 @@ var _ = Describe("Reconcile BuildRun", func() {
Spec: build.BuildRunSpec{
ParamValues: []build.ParamValue{{
Name: "foo",
SingleValue: &build.SingleValue{Value: pointer.String("bar")},
SingleValue: &build.SingleValue{Value: ptr.To[string]("bar")},
}},
BuildSpec: &build.BuildSpec{},
},
Expand Down Expand Up @@ -1421,8 +1421,8 @@ var _ = Describe("Reconcile BuildRun", func() {
Spec: build.BuildRunSpec{
BuildSpec: &build.BuildSpec{
Source: build.Source{
URL: pointer.String("https://github.com/shipwright-io/sample-go.git"),
ContextDir: pointer.String("source-build"),
URL: ptr.To[string]("https://github.com/shipwright-io/sample-go.git"),
ContextDir: ptr.To[string]("source-build"),
},
Strategy: build.Strategy{
Kind: &clusterBuildStrategy,
Expand All @@ -1433,7 +1433,7 @@ var _ = Describe("Reconcile BuildRun", func() {
},
},
ServiceAccount: &build.ServiceAccount{
Generate: pointer.Bool(true),
Generate: ptr.To[bool](true),
},
},
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/reconciler/buildrun/resources/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
. "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
"github.com/shipwright-io/build/pkg/reconciler/buildrun/resources"
)

var _ = Describe("Credentials", func() {
var _ = Describe("Credentials", func() {
var (
build *buildv1alpha1.Build
buildRun *buildv1alpha1.BuildRun
Expand All @@ -33,12 +33,12 @@ var _ = Describe("Credentials", func() {
}
})

Context("when secrets were not present in the service account", func() {
Context("when secrets were not present in the service account", func() {
BeforeEach(func() {
build = &buildv1alpha1.Build{
Spec: buildv1alpha1.BuildSpec{
Source: buildv1alpha1.Source{
URL: pointer.String("a/b/c"),
URL: ptr.To[string]("a/b/c"),
Credentials: &corev1.LocalObjectReference{
Name: "secret_a",
},
Expand Down Expand Up @@ -89,12 +89,12 @@ var _ = Describe("Credentials", func() {
})
})

Context("when secrets were already in the service account", func() {
Context("when secrets were already in the service account", func() {
BeforeEach(func() {
build = &buildv1alpha1.Build{
Spec: buildv1alpha1.BuildSpec{
Source: buildv1alpha1.Source{
URL: pointer.String("a/b/c"),
URL: ptr.To[string]("a/b/c"),
},
Output: buildv1alpha1.Image{
Credentials: &corev1.LocalObjectReference{
Expand Down Expand Up @@ -126,12 +126,12 @@ var _ = Describe("Credentials", func() {
})
})

Context("when build does not reference any secret", func() {
Context("when build does not reference any secret", func() {
BeforeEach(func() {
build = &buildv1alpha1.Build{
Spec: buildv1alpha1.BuildSpec{
Source: buildv1alpha1.Source{
URL: pointer.String("a/b/c"),
URL: ptr.To[string]("a/b/c"),
Credentials: nil,
},
},
Expand Down
Loading

0 comments on commit bb891a7

Please sign in to comment.