Skip to content

Commit 305fe22

Browse files
committed
add -omitempty=false to go fix, run fix-all
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
1 parent a18df63 commit 305fe22

53 files changed

Lines changed: 169 additions & 237 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ vet: ## Run go vet against the module
2727

2828
.PHONY: fix
2929
fix: ## Run go fix against the module
30-
go fix ./...
30+
go fix -omitzero=false ./...
3131

3232
.PHONY: tidy
3333
tidy: ## Run go tidy against the module

controllers/functionconfigs/functionconfigreconciler_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ func TestFunctionConfigReconciler(t *testing.T) {
192192
t.Fatalf("unable to add configapi to scheme: %v", err)
193193
}
194194
for _, tt := range tests {
195-
tt := tt // pin for closure
196195
t.Run(tt.name, func(t *testing.T) {
197196
c := fake.NewClientBuilder().WithObjects(tt.objs...).WithScheme(scheme).WithStatusSubresource(&configapi.FunctionConfig{}).Build()
198197

@@ -468,13 +467,13 @@ func TestConcurrentAccessSafety(t *testing.T) {
468467
// Writer goroutine
469468
go func() {
470469
defer close(done)
471-
for i := 0; i < 100; i++ {
470+
for range 100 {
472471
store.UpdateExecCache(obj.Name, obj)
473472
}
474473
}()
475474

476475
// Reader goroutine (concurrent with writer)
477-
for i := 0; i < 100; i++ {
476+
for range 100 {
478477
store.GetProcessorFromCache("ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.4.1")
479478
}
480479

controllers/packagerevisions/integration/packagerevision_integration_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ var _ = Describe("PackageRevision Controller Integration", func() {
126126
}
127127

128128
for _, tc := range transitions {
129-
tc := tc
130129
It(fmt.Sprintf("Should transition %s -> %s and set Ready=True", tc.current, tc.desired), func() {
131130
var fetched porchv1alpha2.PackageRevision
132131
Expect(k8sClient.Get(ctx, nn, &fetched)).To(Succeed())

controllers/packagerevisions/pkg/controllers/packagerevision/mergekey.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package packagerevision
2121
import (
2222
"bytes"
2323
"fmt"
24+
"maps"
2425
"path"
2526
"strings"
2627

@@ -50,9 +51,7 @@ func ensureMergeKey(resources map[string]string) (map[string]string, error) {
5051
return nil, fmt.Errorf("failed to add merge-key directive: %w", err)
5152
}
5253

53-
for k, v := range pr.extra {
54-
result[k] = v
55-
}
54+
maps.Copy(result, pr.extra)
5655

5756
return result, nil
5857
}

controllers/packagerevisions/pkg/webhooks/packagerevision_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ func (v *PackageRevisionValidator) unmarshalPackageRevision(raw []byte, fieldNam
503503
}
504504

505505
// unmarshalInto unmarshals raw bytes into a target object, handling empty and malformed data.
506-
func (v *PackageRevisionValidator) unmarshalInto(raw []byte, target interface{}, fieldName string) *admission.Response {
506+
func (v *PackageRevisionValidator) unmarshalInto(raw []byte, target any, fieldName string) *admission.Response {
507507
if len(raw) == 0 {
508508
resp := admission.Errored(http.StatusBadRequest, fmt.Errorf("%s is empty", fieldName))
509509
return &resp

controllers/packagerevisions/pkg/webhooks/packagerevision_webhook_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ func TestUnmarshalInto(t *testing.T) {
11741174
tests := []struct {
11751175
name string
11761176
raw []byte
1177-
target interface{}
1177+
target any
11781178
fieldName string
11791179
wantErr bool
11801180
errMsg string

controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller-with-workspacename_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,11 +784,11 @@ status:
784784
t.Run(tn, func(t *testing.T) {
785785
var pv api.PackageVariant
786786
require.NoError(t, yaml.Unmarshal(
787-
[]byte(fmt.Sprintf(pvStr, tc.deletionPolicy)), &pv))
787+
fmt.Appendf(nil, pvStr, tc.deletionPolicy), &pv))
788788

789789
var pr porchapi.PackageRevision
790790
require.NoError(t, yaml.Unmarshal(
791-
[]byte(fmt.Sprintf(prStr, tc.prLifecycle)), &pr))
791+
fmt.Appendf(nil, prStr, tc.prLifecycle), &pr))
792792

793793
fc := &fakeClient{}
794794
reconciler := &PackageVariantReconciler{Client: fc}
@@ -963,7 +963,7 @@ items:
963963

964964
var pv api.PackageVariant
965965
require.NoError(t, yaml.Unmarshal(
966-
[]byte(fmt.Sprintf(pvStr, tc.adoptionPolicy)), &pv))
966+
fmt.Appendf(nil, pvStr, tc.adoptionPolicy), &pv))
967967

968968
actualStr := reconciler.getDownstreamPRs(context.TODO(), &pv, &prList)
969969
var actual []string

controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"flag"
2020
"fmt"
21+
"maps"
2122
"strconv"
2223
"strings"
2324

@@ -601,15 +602,11 @@ func (r *PackageVariantReconciler) adoptPackageRevision(ctx context.Context,
601602
if len(pv.Spec.Labels) > 0 && pr.Labels == nil {
602603
pr.Labels = make(map[string]string)
603604
}
604-
for k, v := range pv.Spec.Labels {
605-
pr.Labels[k] = v
606-
}
605+
maps.Copy(pr.Labels, pv.Spec.Labels)
607606
if len(pv.Spec.Annotations) > 0 && pr.Annotations == nil {
608607
pr.Annotations = make(map[string]string)
609608
}
610-
for k, v := range pv.Spec.Annotations {
611-
pr.Annotations[k] = v
612-
}
609+
maps.Copy(pr.Annotations, pv.Spec.Annotations)
613610
return r.Update(ctx, pr)
614611
}
615612

@@ -872,9 +869,7 @@ func (r *PackageVariantReconciler) calculateDraftResources(ctx context.Context,
872869
}
873870

874871
origResources := make(map[string]string, len(prr.Spec.Resources))
875-
for k, v := range prr.Spec.Resources {
876-
origResources[k] = v
877-
}
872+
maps.Copy(origResources, prr.Spec.Resources)
878873

879874
// Apply our mutations
880875
if err := ensurePackageContext(pv, &prr); err != nil {
@@ -985,9 +980,7 @@ func ensurePackageContext(pv *configapi.PackageVariant,
985980
}
986981

987982
// set or add keys that should be there
988-
for k, v := range pv.Spec.PackageContext.Data {
989-
data[k] = v
990-
}
983+
maps.Copy(data, pv.Spec.PackageContext.Data)
991984

992985
// remove any keys that should go
993986
for _, k := range pv.Spec.PackageContext.RemoveKeys {

controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,11 +787,11 @@ status:
787787
t.Run(tn, func(t *testing.T) {
788788
var pv api.PackageVariant
789789
require.NoError(t, yaml.Unmarshal(
790-
[]byte(fmt.Sprintf(pvStr, tc.deletionPolicy)), &pv))
790+
fmt.Appendf(nil, pvStr, tc.deletionPolicy), &pv))
791791

792792
var pr porchapi.PackageRevision
793793
require.NoError(t, yaml.Unmarshal(
794-
[]byte(fmt.Sprintf(prStr, tc.prLifecycle)), &pr))
794+
fmt.Appendf(nil, prStr, tc.prLifecycle), &pr))
795795

796796
fc := &fakeClient{}
797797
reconciler := &PackageVariantReconciler{Client: fc}
@@ -966,7 +966,7 @@ items:
966966

967967
var pv api.PackageVariant
968968
require.NoError(t, yaml.Unmarshal(
969-
[]byte(fmt.Sprintf(pvStr, tc.adoptionPolicy)), &pv))
969+
fmt.Appendf(nil, pvStr, tc.adoptionPolicy), &pv))
970970

971971
actualStr := reconciler.getDownstreamPRs(context.TODO(), &pv, &prList)
972972
var actual []string

controllers/packagevariantsets/pkg/controllers/packagevariantset/render.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package packagevariantset
1717
import (
1818
"context"
1919
"fmt"
20+
"maps"
2021
"reflect"
2122
"slices"
2223

@@ -245,9 +246,7 @@ func objectToInput(obj any) (map[string]any, error) {
245246

246247
func copyAndOverlayMapExpr(fieldName string, inMap map[string]string, mapExprs []api.MapExpr, inputs map[string]any) (map[string]string, error) {
247248
outMap := make(map[string]string, len(inMap))
248-
for k, v := range inMap {
249-
outMap[k] = v
250-
}
249+
maps.Copy(outMap, inMap)
251250

252251
var err error
253252
for i, me := range mapExprs {

0 commit comments

Comments
 (0)