Skip to content

Commit 3d15cb0

Browse files
authored
replace ref() by new(); see go 1.26 release notes (#400)
1 parent 776757d commit 3d15cb0

11 files changed

Lines changed: 28 additions & 52 deletions

File tree

clm/cmd/apply.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func newApplyCmd() *cobra.Command {
5858
}
5959

6060
reconciler := reconciler.NewReconciler(fullName, clnt, reconciler.ReconcilerOptions{
61-
UpdatePolicy: ref(reconciler.UpdatePolicySsaOverride),
61+
UpdatePolicy: new(reconciler.UpdatePolicySsaOverride),
6262
})
6363

6464
releaseClient := release.NewClient(fullName, clnt)

clm/cmd/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func newDeleteCmd() *cobra.Command {
4949
}
5050

5151
reconciler := reconciler.NewReconciler(fullName, clnt, reconciler.ReconcilerOptions{
52-
UpdatePolicy: ref(reconciler.UpdatePolicySsaOverride),
52+
UpdatePolicy: new(reconciler.UpdatePolicySsaOverride),
5353
})
5454

5555
releaseClient := release.NewClient(fullName, clnt)

clm/cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Common actions for clm:
3232

3333
func newRootCmd() *cobra.Command {
3434
configFlags := genericclioptions.NewConfigFlags(true)
35-
configFlags.Namespace = ref("default")
35+
configFlags.Namespace = new("default")
3636

3737
cmd := &cobra.Command{
3838
Use: shortName,

clm/cmd/util.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ import (
2828

2929
// TODO: consolidate all the util files into an internal reuse package
3030

31-
func ref[T any](x T) *T {
32-
return &x
33-
}
34-
3531
func must[T any](x T, err error) T {
3632
if err != nil {
3733
panic(err)

internal/kustomize/kustomization.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ func ParseKustomization(fsys fs.FS, kustomizationPath string, options Kustomizat
9292

9393
func parseKustomization(fsys fs.FS, kustomizationPath string, options KustomizationOptions, visitedKustomizationPaths []string) (*Kustomization, error) {
9494
if options.TemplateSuffix == nil {
95-
options.TemplateSuffix = ref("")
95+
options.TemplateSuffix = new("")
9696
}
9797
if options.LeftTemplateDelimiter == nil {
98-
options.LeftTemplateDelimiter = ref("")
98+
options.LeftTemplateDelimiter = new("")
9999
}
100100
if options.RightTemplateDelimiter == nil {
101-
options.RightTemplateDelimiter = ref("")
101+
options.RightTemplateDelimiter = new("")
102102
}
103103

104104
if fsys == nil {

internal/kustomize/util.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

pkg/component/reconciler.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,19 @@ func NewReconciler[T Component](name string, resourceGenerator manifests.Generat
180180
options.Finalizer = &name
181181
}
182182
if options.AdoptionPolicy == nil {
183-
options.AdoptionPolicy = ref(reconciler.AdoptionPolicyIfUnowned)
183+
options.AdoptionPolicy = new(reconciler.AdoptionPolicyIfUnowned)
184184
}
185185
if options.UpdatePolicy == nil {
186-
options.UpdatePolicy = ref(reconciler.UpdatePolicyReplace)
186+
options.UpdatePolicy = new(reconciler.UpdatePolicyReplace)
187187
}
188188
if options.DeletePolicy == nil {
189-
options.DeletePolicy = ref(reconciler.DeletePolicyDelete)
189+
options.DeletePolicy = new(reconciler.DeletePolicyDelete)
190190
}
191191
if options.MissingNamespacesPolicy == nil {
192-
options.MissingNamespacesPolicy = ref(reconciler.MissingNamespacesPolicyCreate)
192+
options.MissingNamespacesPolicy = new(reconciler.MissingNamespacesPolicyCreate)
193193
}
194194
if options.ReapplyInterval == nil {
195-
options.ReapplyInterval = ref(defaultReapplyInterval)
195+
options.ReapplyInterval = new(defaultReapplyInterval)
196196
}
197197

198198
return &Reconciler[T]{
@@ -913,7 +913,7 @@ func (r *Reconciler[T]) getOptionsForComponent(component T) reconciler.Reconcile
913913
}
914914
// TODO: formalize the following into a Configuration interface?
915915
if component.GetAnnotations()[r.name+"/"+types.AnnotationKeySuffixDisableEvents] == "true" {
916-
options.EnableEvents = ref(false)
916+
options.EnableEvents = new(false)
917917
}
918918
return options
919919
}

pkg/component/reference.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (r *ConfigMapReference) load(ctx context.Context, clnt client.Client, names
5656
if ignoreNotFound {
5757
return nil
5858
}
59-
return types.NewRetriableError(legacyerrors.Wrapf(err, "error loading configmap %s/%s", namespace, r.Name), ref(retryAfter))
59+
return types.NewRetriableError(legacyerrors.Wrapf(err, "error loading configmap %s/%s", namespace, r.Name), new(retryAfter))
6060
} else {
6161
return legacyerrors.Wrapf(err, "error loading configmap %s/%s", namespace, r.Name)
6262
}
@@ -105,7 +105,7 @@ func (r *ConfigMapKeyReference) load(ctx context.Context, clnt client.Client, na
105105
if ignoreNotFound {
106106
return nil
107107
}
108-
return types.NewRetriableError(legacyerrors.Wrapf(err, "error loading configmap %s/%s", namespace, r.Name), ref(retryAfter))
108+
return types.NewRetriableError(legacyerrors.Wrapf(err, "error loading configmap %s/%s", namespace, r.Name), new(retryAfter))
109109
} else {
110110
return legacyerrors.Wrapf(err, "error loading configmap %s/%s", namespace, r.Name)
111111
}
@@ -116,7 +116,7 @@ func (r *ConfigMapKeyReference) load(ctx context.Context, clnt client.Client, na
116116
r.loaded = true
117117
return nil
118118
} else {
119-
return types.NewRetriableError(fmt.Errorf("key %s not found in configmap %s/%s", r.Key, namespace, r.Name), ref(retryAfter))
119+
return types.NewRetriableError(fmt.Errorf("key %s not found in configmap %s/%s", r.Key, namespace, r.Name), new(retryAfter))
120120
}
121121
} else {
122122
for _, key := range fallbackKeys {
@@ -126,7 +126,7 @@ func (r *ConfigMapKeyReference) load(ctx context.Context, clnt client.Client, na
126126
return nil
127127
}
128128
}
129-
return types.NewRetriableError(fmt.Errorf("no matching key found in configmap %s/%s", namespace, r.Name), ref(retryAfter))
129+
return types.NewRetriableError(fmt.Errorf("no matching key found in configmap %s/%s", namespace, r.Name), new(retryAfter))
130130
}
131131
}
132132

@@ -166,7 +166,7 @@ func (r *SecretReference) load(ctx context.Context, clnt client.Client, namespac
166166
if ignoreNotFound {
167167
return nil
168168
}
169-
return types.NewRetriableError(legacyerrors.Wrapf(err, "error loading secret %s/%s", namespace, r.Name), ref(retryAfter))
169+
return types.NewRetriableError(legacyerrors.Wrapf(err, "error loading secret %s/%s", namespace, r.Name), new(retryAfter))
170170
} else {
171171
return legacyerrors.Wrapf(err, "error loading secret %s/%s", namespace, r.Name)
172172
}
@@ -215,7 +215,7 @@ func (r *SecretKeyReference) load(ctx context.Context, clnt client.Client, names
215215
if ignoreNotFound {
216216
return nil
217217
}
218-
return types.NewRetriableError(legacyerrors.Wrapf(err, "error loading secret %s/%s", namespace, r.Name), ref(retryAfter))
218+
return types.NewRetriableError(legacyerrors.Wrapf(err, "error loading secret %s/%s", namespace, r.Name), new(retryAfter))
219219
} else {
220220
return legacyerrors.Wrapf(err, "error loading secret %s/%s", namespace, r.Name)
221221
}
@@ -226,7 +226,7 @@ func (r *SecretKeyReference) load(ctx context.Context, clnt client.Client, names
226226
r.loaded = true
227227
return nil
228228
} else {
229-
return types.NewRetriableError(fmt.Errorf("key %s not found in secret %s/%s", r.Key, namespace, r.Name), ref(retryAfter))
229+
return types.NewRetriableError(fmt.Errorf("key %s not found in secret %s/%s", r.Key, namespace, r.Name), new(retryAfter))
230230
}
231231
} else {
232232
for _, key := range fallbackKeys {
@@ -236,7 +236,7 @@ func (r *SecretKeyReference) load(ctx context.Context, clnt client.Client, names
236236
return nil
237237
}
238238
}
239-
return types.NewRetriableError(fmt.Errorf("no matching key found in secret %s/%s", namespace, r.Name), ref(retryAfter))
239+
return types.NewRetriableError(fmt.Errorf("no matching key found in secret %s/%s", namespace, r.Name), new(retryAfter))
240240
}
241241
}
242242

pkg/component/util.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ import (
1616

1717
// TODO: consolidate all the util files into an internal reuse package
1818

19-
func ref[T any](x T) *T {
20-
return &x
21-
}
22-
2319
func must[T any](x T, err error) T {
2420
if err != nil {
2521
panic(err)

pkg/reconciler/reconciler.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,25 +181,25 @@ func NewReconciler(name string, clnt cluster.Client, options ReconcilerOptions)
181181
options.Finalizer = &name
182182
}
183183
if options.AdoptionPolicy == nil {
184-
options.AdoptionPolicy = ref(AdoptionPolicyIfUnowned)
184+
options.AdoptionPolicy = new(AdoptionPolicyIfUnowned)
185185
}
186186
if options.UpdatePolicy == nil {
187-
options.UpdatePolicy = ref(UpdatePolicyReplace)
187+
options.UpdatePolicy = new(UpdatePolicyReplace)
188188
}
189189
if options.DeletePolicy == nil {
190-
options.DeletePolicy = ref(DeletePolicyDelete)
190+
options.DeletePolicy = new(DeletePolicyDelete)
191191
}
192192
if options.MissingNamespacesPolicy == nil {
193-
options.MissingNamespacesPolicy = ref(MissingNamespacesPolicyCreate)
193+
options.MissingNamespacesPolicy = new(MissingNamespacesPolicyCreate)
194194
}
195195
if options.ReapplyInterval == nil {
196-
options.ReapplyInterval = ref(defaultReapplyInterval)
196+
options.ReapplyInterval = new(defaultReapplyInterval)
197197
}
198198
if options.StatusAnalyzer == nil {
199199
options.StatusAnalyzer = status.NewStatusAnalyzer(name)
200200
}
201201
if options.EnableEvents == nil {
202-
options.EnableEvents = ref(true)
202+
options.EnableEvents = new(true)
203203
}
204204

205205
return &Reconciler{
@@ -1290,10 +1290,10 @@ func (r *Reconciler) deleteObject(ctx context.Context, key types.ObjectKey, exis
12901290
object.SetGroupVersionKind(key.GetObjectKind().GroupVersionKind())
12911291
object.SetNamespace(key.GetNamespace())
12921292
object.SetName(key.GetName())
1293-
deleteOptions := &client.DeleteOptions{PropagationPolicy: ref(metav1.DeletePropagationBackground)}
1293+
deleteOptions := &client.DeleteOptions{PropagationPolicy: new(metav1.DeletePropagationBackground)}
12941294
if existingObject != nil {
12951295
deleteOptions.Preconditions = &metav1.Preconditions{
1296-
ResourceVersion: ref(existingObject.GetResourceVersion()),
1296+
ResourceVersion: new(existingObject.GetResourceVersion()),
12971297
}
12981298
}
12991299
if err := r.client.Delete(ctx, object, deleteOptions); err != nil {

0 commit comments

Comments
 (0)