Skip to content

Commit 8b89f81

Browse files
fmountclaude
andcommitted
Modernize Go code with latest style conventions
Applied automated modernization using gopls modernize tool to update: - Replace interface{} with any type alias (Go 1.18+) - Update range loops to use idiomatic range syntax - Replace fmt.Sprintf with fmt.Appendf where appropriate These changes improve code readability and align with current Go best practices. Co-Authored-By: Claude <[email protected]> Signed-off-by: Francesco Pantano <[email protected]>
1 parent 4c24024 commit 8b89f81

File tree

26 files changed

+99
-108
lines changed

26 files changed

+99
-108
lines changed

modules/ansible/inventory.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ import "gopkg.in/yaml.v3"
2121
// Host represents ansible host
2222
type Host struct {
2323
name string
24-
Vars map[string]interface{} `yaml:",inline"`
24+
Vars map[string]any `yaml:",inline"`
2525
}
2626

2727
// MakeHost instatiates an Host object
2828
func MakeHost(name string) Host {
2929
return Host{
3030
name: name,
31-
Vars: make(map[string]interface{}),
31+
Vars: make(map[string]any),
3232
}
3333
}
3434

3535
// Group represents ansible group
3636
type Group struct {
3737
name string
38-
Vars map[string]interface{} `yaml:",omitempty"`
39-
Hosts map[string]Host `yaml:",omitempty"`
40-
Children map[string]Group `yaml:",omitempty"`
38+
Vars map[string]any `yaml:",omitempty"`
39+
Hosts map[string]Host `yaml:",omitempty"`
40+
Children map[string]Group `yaml:",omitempty"`
4141
}
4242

4343
// AddHost adds a host to the current group
@@ -51,7 +51,7 @@ func (group Group) AddHost(name string) Host {
5151
func MakeGroup(name string) Group {
5252
return Group{
5353
name: name,
54-
Vars: make(map[string]interface{}),
54+
Vars: make(map[string]any),
5555
Hosts: make(map[string]Host),
5656
Children: make(map[string]Group),
5757
}

modules/certmanager/test/helpers/certmanager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ func (tc *TestHelper) AssertIssuerDoesNotExist(name types.NamespacedName) {
7575
//
7676
// cm := th.CreateIssuer(types.NamespacedName{Namespace: "default", Name: "example-configmap"})
7777
func (tc *TestHelper) CreateIssuer(name types.NamespacedName) client.Object {
78-
raw := map[string]interface{}{
78+
raw := map[string]any{
7979
"apiVersion": "cert-manager.io/v1",
8080
"kind": "Issuer",
81-
"metadata": map[string]interface{}{
81+
"metadata": map[string]any{
8282
"name": name.Name,
8383
"namespace": name.Namespace,
8484
},
85-
"spec": map[string]interface{}{
86-
"ca": map[string]interface{}{
85+
"spec": map[string]any{
86+
"ca": map[string]any{
8787
"secretName": name.Name,
8888
},
8989
},

modules/common/condition/funcs.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,17 @@ func (conditions *Conditions) Has(t Type) bool {
125125
}
126126

127127
// MarkTrue sets Status=True for the condition with the given type.
128-
func (conditions *Conditions) MarkTrue(t Type, messageFormat string, messageArgs ...interface{}) {
128+
func (conditions *Conditions) MarkTrue(t Type, messageFormat string, messageArgs ...any) {
129129
conditions.Set(TrueCondition(t, messageFormat, messageArgs...))
130130
}
131131

132132
// MarkFalse sets Status=False for the condition with the given type.
133-
func (conditions *Conditions) MarkFalse(t Type, reason Reason, severity Severity, messageFormat string, messageArgs ...interface{}) {
133+
func (conditions *Conditions) MarkFalse(t Type, reason Reason, severity Severity, messageFormat string, messageArgs ...any) {
134134
conditions.Set(FalseCondition(t, reason, severity, messageFormat, messageArgs...))
135135
}
136136

137137
// MarkUnknown sets Status=Unknown for the condition with the given type.
138-
func (conditions *Conditions) MarkUnknown(t Type, reason Reason, messageFormat string, messageArgs ...interface{}) {
138+
func (conditions *Conditions) MarkUnknown(t Type, reason Reason, messageFormat string, messageArgs ...any) {
139139
conditions.Set(UnknownCondition(t, reason, messageFormat, messageArgs...))
140140
}
141141

@@ -225,7 +225,7 @@ func HasSameState(i, j *Condition) bool {
225225
}
226226

227227
// TrueCondition returns a condition with Status=True and the given type.
228-
func TrueCondition(t Type, messageFormat string, messageArgs ...interface{}) *Condition {
228+
func TrueCondition(t Type, messageFormat string, messageArgs ...any) *Condition {
229229
return &Condition{
230230
Type: t,
231231
Status: corev1.ConditionTrue,
@@ -236,7 +236,7 @@ func TrueCondition(t Type, messageFormat string, messageArgs ...interface{}) *Co
236236
}
237237

238238
// FalseCondition returns a condition with Status=False and the given type.
239-
func FalseCondition(t Type, reason Reason, severity Severity, messageFormat string, messageArgs ...interface{}) *Condition {
239+
func FalseCondition(t Type, reason Reason, severity Severity, messageFormat string, messageArgs ...any) *Condition {
240240
return &Condition{
241241
Type: t,
242242
Status: corev1.ConditionFalse,
@@ -247,7 +247,7 @@ func FalseCondition(t Type, reason Reason, severity Severity, messageFormat stri
247247
}
248248

249249
// UnknownCondition returns a condition with Status=Unknown and the given type.
250-
func UnknownCondition(t Type, reason Reason, messageFormat string, messageArgs ...interface{}) *Condition {
250+
func UnknownCondition(t Type, reason Reason, messageFormat string, messageArgs ...any) *Condition {
251251
return &Condition{
252252
Type: t,
253253
Status: corev1.ConditionUnknown,

modules/common/condition/funcs_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ type conditionsMatcher struct {
687687
Expected Conditions
688688
}
689689

690-
func (matcher *conditionsMatcher) Match(actual interface{}) (success bool, err error) {
690+
func (matcher *conditionsMatcher) Match(actual any) (success bool, err error) {
691691
actualConditions, ok := actual.(Conditions)
692692
if !ok {
693693
return false, errors.New("Value should be a conditions list")
@@ -705,11 +705,11 @@ func (matcher *conditionsMatcher) Match(actual interface{}) (success bool, err e
705705
return true, nil
706706
}
707707

708-
func (matcher *conditionsMatcher) FailureMessage(actual interface{}) (message string) {
708+
func (matcher *conditionsMatcher) FailureMessage(actual any) (message string) {
709709
return format.Message(actual, "to have the same conditions of", matcher.Expected)
710710
}
711711

712-
func (matcher *conditionsMatcher) NegatedFailureMessage(actual interface{}) (message string) {
712+
func (matcher *conditionsMatcher) NegatedFailureMessage(actual any) (message string) {
713713
return format.Message(actual, "not to have the same conditions of", matcher.Expected)
714714
}
715715

@@ -724,7 +724,7 @@ type conditionMatcher struct {
724724
Expected *Condition
725725
}
726726

727-
func (matcher *conditionMatcher) Match(actual interface{}) (success bool, err error) {
727+
func (matcher *conditionMatcher) Match(actual any) (success bool, err error) {
728728
actualCondition, ok := actual.(*Condition)
729729
if !ok {
730730
return false, errors.New("value should be a condition")
@@ -733,10 +733,10 @@ func (matcher *conditionMatcher) Match(actual interface{}) (success bool, err er
733733
return HasSameState(actualCondition, matcher.Expected), nil
734734
}
735735

736-
func (matcher *conditionMatcher) FailureMessage(actual interface{}) (message string) {
736+
func (matcher *conditionMatcher) FailureMessage(actual any) (message string) {
737737
return format.Message(actual, "to have the same state of", matcher.Expected)
738738
}
739739

740-
func (matcher *conditionMatcher) NegatedFailureMessage(actual interface{}) (message string) {
740+
func (matcher *conditionMatcher) NegatedFailureMessage(actual any) (message string) {
741741
return format.Message(actual, "not to have the same state of", matcher.Expected)
742742
}

modules/common/helper/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (h *Helper) calculateChanges(after client.Object) (map[string]bool, error)
157157
}
158158

159159
// Unmarshal patch data into a local map.
160-
patchDiff := map[string]interface{}{}
160+
patchDiff := map[string]any{}
161161
if err := json.Unmarshal(diff, &patchDiff); err != nil {
162162
return nil, errors.Wrapf(err, "failed to unmarshal patch data into a map")
163163
}

modules/common/helper/helper_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ func TestToUnstructured(t *testing.T) {
5454
g := NewWithT(t)
5555

5656
obj := &unstructured.Unstructured{
57-
Object: map[string]interface{}{
57+
Object: map[string]any{
5858
"apiVersion": "test.x.y.z/v1",
59-
"metadata": map[string]interface{}{
59+
"metadata": map[string]any{
6060
"name": "keystone",
6161
"namespace": "openstack",
6262
},
63-
"spec": map[string]interface{}{
63+
"spec": map[string]any{
6464
"databaseHostname": "dbhost",
6565
},
6666
},

modules/common/networkattachment/networkattachment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func EnsureNetworksAnnotation(
157157
gatewayReq := []net.IP{}
158158
if nad.Spec.Config != "" {
159159

160-
var data interface{}
160+
var data any
161161
if err := json.Unmarshal([]byte(nad.Spec.Config), &data); err != nil {
162162
return nil, fmt.Errorf("failed to unmarshal JSON data: %w", err)
163163
}
@@ -213,7 +213,7 @@ func EnsureNetworksAnnotation(
213213
// if the NAD has no config, an empty string is returned.
214214
// The jsonPath must be in the format e.g. ".ipam"
215215
func GetJSONPathFromConfig(netAtt networkv1.NetworkAttachmentDefinition, path string) (string, error) {
216-
var data interface{}
216+
var data any
217217
buf := new(bytes.Buffer)
218218

219219
if netAtt.Spec.Config == "" {

modules/common/object/metadata.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func PatchOwnerRef(
5353
owner client.Object,
5454
object client.Object,
5555
scheme *runtime.Scheme,
56-
) (map[string]interface{}, client.Patch, error) {
56+
) (map[string]any, client.Patch, error) {
5757
beforeObject := object.DeepCopyObject().(client.Object)
5858

5959
// add owner ref to the object
@@ -70,7 +70,7 @@ func PatchOwnerRef(
7070
}
7171

7272
// Unmarshal patch data into a local map for logging
73-
patchDiff := map[string]interface{}{}
73+
patchDiff := map[string]any{}
7474
if err := json.Unmarshal(diff, &patchDiff); err != nil {
7575
return nil, nil, err
7676
}

modules/common/ocp/ocp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func IsFipsCluster(ctx context.Context, h *helper.Helper) (bool, error) {
3737
return false, err
3838
}
3939

40-
var installConfig map[string]interface{}
40+
var installConfig map[string]any
4141
installConfigYAML := configMap.Data["install-config"]
4242
err = yaml.Unmarshal([]byte(installConfigYAML), &installConfig)
4343
if err != nil {

modules/common/test/functional/object_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var _ = Describe("object package", func() {
4545
Name: "test-cm",
4646
}
4747

48-
cm := th.CreateConfigMap(cmName, map[string]interface{}{})
48+
cm := th.CreateConfigMap(cmName, map[string]any{})
4949

5050
err := object.EnsureOwnerRef(th.Ctx, h, cm, cm)
5151
Expect(err).ShouldNot(HaveOccurred())
@@ -59,14 +59,14 @@ var _ = Describe("object package", func() {
5959
Namespace: namespace,
6060
Name: "test-owner",
6161
}
62-
ownerCM := th.CreateConfigMap(owner, map[string]interface{}{})
62+
ownerCM := th.CreateConfigMap(owner, map[string]any{})
6363

6464
// create target obj we add the owner ref to
6565
cmName := types.NamespacedName{
6666
Namespace: namespace,
6767
Name: "test-cm",
6868
}
69-
cm := th.CreateConfigMap(cmName, map[string]interface{}{})
69+
cm := th.CreateConfigMap(cmName, map[string]any{})
7070

7171
err := object.EnsureOwnerRef(th.Ctx, h, ownerCM, cm)
7272
Expect(err).ShouldNot(HaveOccurred())

0 commit comments

Comments
 (0)