Skip to content

Commit beba052

Browse files
author
Gabriel Saratura
committed
Fix linting issues
1 parent e2bbb1c commit beba052

File tree

10 files changed

+57
-58
lines changed

10 files changed

+57
-58
lines changed

operator/iamkeycontroller/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
"k8s.io/apimachinery/pkg/labels"
2424

25-
"k8s.io/utils/pointer"
25+
"k8s.io/utils/ptr"
2626
controllerruntime "sigs.k8s.io/controller-runtime"
2727
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2828
)
@@ -162,7 +162,7 @@ func (p *IAMKeyPipeline) createCredentialsSecret(ctx *pipelineContext) error {
162162
for k, v := range connDetails {
163163
secret.Data[k] = v
164164
}
165-
secret.Immutable = pointer.Bool(true)
165+
secret.Immutable = ptr.To[bool](true)
166166

167167
err = controllerutil.SetOwnerReference(ctx.iamKey, secret, p.kube.Scheme())
168168
if err != nil {

operator/iamkeycontroller/util.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package iamkeycontroller
22

33
import (
44
exooapi "github.com/exoscale/egoscale/v2/oapi"
5-
"k8s.io/utils/pointer"
5+
"k8s.io/utils/ptr"
66
)
77

88
var (
@@ -16,11 +16,11 @@ func createRole(keyName string, buckets []string) *exooapi.IamRole {
1616

1717
iamRole := &exooapi.IamRole{
1818
Name: &keyName,
19-
Description: pointer.String("IAM Role for SOS+IAM creation, it was autogenerated by provider-exoscale"),
19+
Description: ptr.To[string]("IAM Role for SOS+IAM creation, it was autogenerated by provider-exoscale"),
2020
Permissions: &[]exooapi.IamRolePermissions{
2121
exooapi.IamRolePermissionsBypassGovernanceRetention,
2222
},
23-
Editable: pointer.Bool(true),
23+
Editable: ptr.To[bool](true),
2424
Policy: &exooapi.IamPolicy{
2525
DefaultServiceStrategy: exooapi.IamPolicyDefaultServiceStrategyDeny,
2626
Services: exooapi.IamPolicy_Services{
@@ -37,20 +37,20 @@ func createRole(keyName string, buckets []string) *exooapi.IamRole {
3737
// We specifically need to deny the listing of buckets, or the customer is able to see all of them
3838
*iamRole.Policy.Services.AdditionalProperties["sos"].Rules = append(*iamRole.Policy.Services.AdditionalProperties["sos"].Rules, exooapi.IamServicePolicyRule{
3939
Action: &policyDeny,
40-
Expression: pointer.String("operation in ['list-sos-buckets-usage', 'list-buckets']"),
40+
Expression: ptr.To[string]("operation in ['list-sos-buckets-usage', 'list-buckets']"),
4141
})
4242

4343
// we must first add buckets to deny list and then add the allow rule, otherwise it will not work
4444
for _, bucket := range buckets {
4545
*iamRole.Policy.Services.AdditionalProperties["sos"].Rules = append(*iamRole.Policy.Services.AdditionalProperties["sos"].Rules, exooapi.IamServicePolicyRule{
4646
Action: &policyDeny,
47-
Expression: pointer.String("resources.bucket != " + "'" + bucket + "'"),
47+
Expression: ptr.To[string]("resources.bucket != " + "'" + bucket + "'"),
4848
})
4949
}
5050

5151
*iamRole.Policy.Services.AdditionalProperties["sos"].Rules = append(*iamRole.Policy.Services.AdditionalProperties["sos"].Rules, exooapi.IamServicePolicyRule{
5252
Action: &policyAllow,
53-
Expression: pointer.String("true"),
53+
Expression: ptr.To[string]("true"),
5454
})
5555

5656
return iamRole

operator/kafkacontroller/observe.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"k8s.io/utils/ptr"
78
"strings"
89

910
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
@@ -12,7 +13,6 @@ import (
1213
exoscaleapi "github.com/exoscale/egoscale/v2/api"
1314
"github.com/exoscale/egoscale/v2/oapi"
1415
"github.com/google/go-cmp/cmp"
15-
"k8s.io/utils/pointer"
1616
controllerruntime "sigs.k8s.io/controller-runtime"
1717

1818
exoscalev1 "github.com/vshn/provider-exoscale/apis/exoscale/v1"
@@ -103,9 +103,9 @@ func getObservation(external *oapi.DbaasServiceKafka) (exoscalev1.KafkaObservati
103103
}
104104

105105
return exoscalev1.KafkaObservation{
106-
Version: pointer.StringDeref(external.Version, ""),
106+
Version: ptr.Deref[string](external.Version, ""),
107107
KafkaSettings: settings,
108-
KafkaRestEnabled: pointer.BoolDeref(external.KafkaRestEnabled, false),
108+
KafkaRestEnabled: ptr.Deref[bool](external.KafkaRestEnabled, false),
109109
KafkaRestSettings: restSettings,
110110
NodeStates: nodeStates,
111111
Notifications: notifications,
@@ -200,15 +200,15 @@ func diffParameters(external *oapi.DbaasServiceKafka, expected exoscalev1.KafkaP
200200
},
201201
Zone: expected.Zone,
202202
DBaaSParameters: exoscalev1.DBaaSParameters{
203-
TerminationProtection: pointer.BoolDeref(external.TerminationProtection, false),
203+
TerminationProtection: ptr.Deref[bool](external.TerminationProtection, false),
204204
Size: exoscalev1.SizeSpec{
205205
Plan: external.Plan,
206206
},
207207
IPFilter: actualIPFilter,
208208
},
209209
Version: expected.Version, // We should never mark somthing as out of date if the versions don't match as update can't modify the version anyway
210210
KafkaSettings: actualKafkaSettings,
211-
KafkaRestEnabled: pointer.BoolDeref(external.KafkaRestEnabled, false),
211+
KafkaRestEnabled: ptr.Deref[bool](external.KafkaRestEnabled, false),
212212
KafkaRestSettings: actualKafkaRestSettings,
213213
}
214214
settingComparer := cmp.Comparer(mapper.CompareSettings)

operator/kafkacontroller/observe_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package kafkacontroller
22

33
import (
44
"context"
5+
"k8s.io/utils/ptr"
56
"testing"
67

78
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
@@ -17,7 +18,6 @@ import (
1718
corev1 "k8s.io/api/core/v1"
1819
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1920
"k8s.io/apimachinery/pkg/runtime"
20-
"k8s.io/utils/pointer"
2121
)
2222

2323
func TestObserve_NotExits(t *testing.T) {
@@ -46,7 +46,7 @@ func TestObserve_UpToDate_ConnectionDetails(t *testing.T) {
4646

4747
instance := sampleKafka("foo")
4848
found := sampleAPIKafka("foo")
49-
found.Uri = pointer.String("foobar.com:21701")
49+
found.Uri = ptr.To[string]("foobar.com:21701")
5050
found.UriParams = &map[string]interface{}{
5151
"host": "foobar.com",
5252
"port": "21701",
@@ -56,8 +56,8 @@ func TestObserve_UpToDate_ConnectionDetails(t *testing.T) {
5656
"10.10.1.2:21701",
5757
"10.10.1.3:21701",
5858
}
59-
found.ConnectionInfo.AccessCert = pointer.String("CERT")
60-
found.ConnectionInfo.AccessKey = pointer.String("KEY")
59+
found.ConnectionInfo.AccessCert = ptr.To[string]("CERT")
60+
found.ConnectionInfo.AccessKey = ptr.To[string]("KEY")
6161

6262
mockGetKafkaCall(exoMock, "foo", found, nil)
6363
mockGetKafkaSettingsCall(exoMock, nil)
@@ -94,7 +94,7 @@ func TestObserve_UpToDate_ConnectionDetails_with_REST(t *testing.T) {
9494
instance := sampleKafka("foo")
9595
instance.Spec.ForProvider.KafkaRestEnabled = true
9696
found := sampleAPIKafka("foo")
97-
found.Uri = pointer.String("foobar.com:21701")
97+
found.Uri = ptr.To[string]("foobar.com:21701")
9898
found.UriParams = &map[string]interface{}{
9999
"host": "foobar.com",
100100
"port": "21701",
@@ -104,10 +104,10 @@ func TestObserve_UpToDate_ConnectionDetails_with_REST(t *testing.T) {
104104
"10.10.1.2:21701",
105105
"10.10.1.3:21701",
106106
}
107-
found.ConnectionInfo.AccessCert = pointer.String("CERT")
108-
found.ConnectionInfo.AccessKey = pointer.String("KEY")
109-
found.KafkaRestEnabled = pointer.Bool(true)
110-
found.ConnectionInfo.RestUri = pointer.String("https://admin:BGAUNBS2afjwQ@test.foobar.com:21701")
107+
found.ConnectionInfo.AccessCert = ptr.To[string]("CERT")
108+
found.ConnectionInfo.AccessKey = ptr.To[string]("KEY")
109+
found.KafkaRestEnabled = ptr.To[bool](true)
110+
found.ConnectionInfo.RestUri = ptr.To[string]("https://admin:BGAUNBS2afjwQ@test.foobar.com:21701")
111111
mockGetKafkaCall(exoMock, "foo", found, nil)
112112
mockGetKafkaSettingsCall(exoMock, nil)
113113
mockCACall(exoMock)
@@ -142,7 +142,7 @@ func TestObserve_UpToDate_Status(t *testing.T) {
142142
}
143143
instance := sampleKafka("foo")
144144
found := sampleAPIKafka("foo")
145-
found.Version = pointer.String("3.2.1")
145+
found.Version = ptr.To[string]("3.2.1")
146146
found.NodeStates = &[]oapi.DbaasNodeState{
147147
{
148148
Name: "node-1",
@@ -240,7 +240,7 @@ func TestObserve_UpToDate_WithVersion(t *testing.T) {
240240
instance := sampleKafka("foo")
241241
instance.Spec.ForProvider.Version = "3.2"
242242
found := sampleAPIKafka("foo")
243-
found.Version = pointer.String("3.2.1")
243+
found.Version = ptr.To[string]("3.2.1")
244244

245245
mockGetKafkaCall(exoMock, "foo", found, nil)
246246
mockGetKafkaSettingsCall(exoMock, nil)
@@ -265,7 +265,7 @@ func TestObserve_UpToDate_EmptyRestSettings(t *testing.T) {
265265
instance.Spec.ForProvider.KafkaRestEnabled = true
266266
instance.Spec.ForProvider.KafkaRestSettings = runtime.RawExtension{}
267267
found := sampleAPIKafka("foo")
268-
found.KafkaRestEnabled = pointer.Bool(true)
268+
found.KafkaRestEnabled = ptr.To[bool](true)
269269

270270
mockGetKafkaCall(exoMock, "foo", found, nil)
271271
mockGetKafkaSettingsCall(exoMock, nil)
@@ -295,7 +295,7 @@ func TestObserve_UpToDate_RestSettings(t *testing.T) {
295295
instance.Spec.ForProvider.KafkaRestEnabled = true
296296
instance.Spec.ForProvider.KafkaRestSettings = restsetting
297297
found := sampleAPIKafka("foo")
298-
found.KafkaRestEnabled = pointer.Bool(true)
298+
found.KafkaRestEnabled = ptr.To[bool](true)
299299

300300
mockGetKafkaCall(exoMock, "foo", found, nil)
301301
mockGetKafkaSettingsCall(exoMock, nil)
@@ -378,7 +378,7 @@ func TestObserve_Outdated_RestSettings(t *testing.T) {
378378
instance.Spec.ForProvider.KafkaRestEnabled = true
379379
instance.Spec.ForProvider.KafkaRestSettings = restsetting
380380
found := sampleAPIKafka("foo")
381-
found.KafkaRestEnabled = pointer.Bool(true)
381+
found.KafkaRestEnabled = ptr.To[bool](true)
382382

383383
mockGetKafkaCall(exoMock, "foo", found, nil)
384384
mockGetKafkaSettingsCall(exoMock, nil)
@@ -444,15 +444,15 @@ func sampleAPIKafka(name string) *oapi.DbaasServiceKafka {
444444
RegistryUri *string "json:\"registry-uri,omitempty\""
445445
RestUri *string "json:\"rest-uri,omitempty\""
446446
}{
447-
AccessCert: pointer.String("SOME ACCESS CERT"),
448-
AccessKey: pointer.String("SOME ACCESS KEY"),
447+
AccessCert: ptr.To[string]("SOME ACCESS CERT"),
448+
AccessKey: ptr.To[string]("SOME ACCESS KEY"),
449449
Nodes: &nodes,
450450
}
451451

452-
res.Uri = pointer.String("foo-exoscale-8fa13713-1027-4b9c-bca7-4c14f9ff9928.aivencloud.com")
452+
res.Uri = ptr.To[string]("foo-exoscale-8fa13713-1027-4b9c-bca7-4c14f9ff9928.aivencloud.com")
453453
res.UriParams = &map[string]interface{}{}
454454

455-
res.Version = pointer.String("3.2.1")
455+
res.Version = ptr.To[string]("3.2.1")
456456

457457
return &res
458458
}
@@ -488,7 +488,7 @@ func mockCACall(m *operatortest.ClientWithResponsesInterface) {
488488
JSON200: &struct {
489489
Certificate *string "json:\"certificate,omitempty\""
490490
}{
491-
Certificate: pointer.String("CA"),
491+
Certificate: ptr.To[string]("CA"),
492492
},
493493
}, nil).
494494
Once()

operator/mapper/alias.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package mapper
22

33
import (
44
"fmt"
5-
65
"github.com/exoscale/egoscale/v2/oapi"
76
exoscalev1 "github.com/vshn/provider-exoscale/apis/exoscale/v1"
87
"k8s.io/apimachinery/pkg/runtime"
98
"k8s.io/apimachinery/pkg/util/json"
10-
"k8s.io/utils/pointer"
9+
"k8s.io/utils/ptr"
1110
)
1211

1312
// BackupSchedule is a type alias for the embedded struct in opai.CreateDbaasServicePgJSONRequestBody.
@@ -19,8 +18,8 @@ type BackupSchedule = struct {
1918
func ToBackupSchedule(day exoscalev1.TimeOfDay) (BackupSchedule, error) {
2019
backupHour, backupMin, _, err := day.Parse()
2120
return BackupSchedule{
22-
BackupHour: pointer.Int64(backupHour),
23-
BackupMinute: pointer.Int64(backupMin),
21+
BackupHour: ptr.To[int64](backupHour),
22+
BackupMinute: ptr.To[int64](backupMin),
2423
}, err
2524
}
2625

@@ -80,7 +79,7 @@ func ToBackupSpec(schedule *BackupSchedule) exoscalev1.BackupSpec {
8079
if schedule == nil {
8180
return exoscalev1.BackupSpec{}
8281
}
83-
hour, min := pointer.Int64Deref(schedule.BackupHour, 0), pointer.Int64Deref(schedule.BackupMinute, 0)
82+
hour, min := ptr.Deref[int64](schedule.BackupHour, 0), ptr.Deref[int64](schedule.BackupMinute, 0)
8483
return exoscalev1.BackupSpec{TimeOfDay: exoscalev1.TimeOfDay(fmt.Sprintf("%02d:%02d:00", hour, min))}
8584
}
8685

@@ -103,7 +102,7 @@ func ToRawExtension(m *map[string]interface{}) (runtime.RawExtension, error) {
103102

104103
func ToDBaaSParameters(tp *bool, plan string, ipf *[]string) exoscalev1.DBaaSParameters {
105104
return exoscalev1.DBaaSParameters{
106-
TerminationProtection: pointer.BoolDeref(tp, false),
105+
TerminationProtection: ptr.Deref[bool](tp, false),
107106
Size: exoscalev1.SizeSpec{
108107
Plan: plan,
109108
},

operator/mapper/alias_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/exoscale/egoscale/v2/oapi"
77
"github.com/stretchr/testify/assert"
88
exoscalev1 "github.com/vshn/provider-exoscale/apis/exoscale/v1"
9-
"k8s.io/utils/pointer"
9+
"k8s.io/utils/ptr"
1010
)
1111

1212
func TestToBackupSpec(t *testing.T) {
@@ -19,15 +19,15 @@ func TestToBackupSpec(t *testing.T) {
1919
expectedSpec: exoscalev1.BackupSpec{},
2020
},
2121
"ScheduleWithZero": {
22-
givenSchedule: &BackupSchedule{BackupHour: pointer.Int64(0), BackupMinute: pointer.Int64(0)},
22+
givenSchedule: &BackupSchedule{BackupHour: ptr.To[int64](0), BackupMinute: ptr.To[int64](0)},
2323
expectedSpec: exoscalev1.BackupSpec{TimeOfDay: exoscalev1.TimeOfDay("00:00:00")},
2424
},
2525
"ScheduleWithoutNumbers": {
2626
givenSchedule: &BackupSchedule{},
2727
expectedSpec: exoscalev1.BackupSpec{TimeOfDay: exoscalev1.TimeOfDay("00:00:00")},
2828
},
2929
"ScheduleWithNumbers": {
30-
givenSchedule: &BackupSchedule{BackupHour: pointer.Int64(12), BackupMinute: pointer.Int64(34)},
30+
givenSchedule: &BackupSchedule{BackupHour: ptr.To[int64](12), BackupMinute: ptr.To[int64](34)},
3131
expectedSpec: exoscalev1.BackupSpec{TimeOfDay: exoscalev1.TimeOfDay("12:34:00")},
3232
},
3333
}
@@ -46,11 +46,11 @@ func TestToBackupSchedule(t *testing.T) {
4646
}{
4747
"EmptyTime": {
4848
givenTime: "0:00:00",
49-
expectedSchedule: BackupSchedule{BackupHour: pointer.Int64(0), BackupMinute: pointer.Int64(0)},
49+
expectedSchedule: BackupSchedule{BackupHour: ptr.To[int64](0), BackupMinute: ptr.To[int64](0)},
5050
},
5151
"TimeGiven": {
5252
givenTime: "12:34:56",
53-
expectedSchedule: BackupSchedule{BackupHour: pointer.Int64(12), BackupMinute: pointer.Int64(34)},
53+
expectedSchedule: BackupSchedule{BackupHour: ptr.To[int64](12), BackupMinute: ptr.To[int64](34)},
5454
},
5555
}
5656
for name, tc := range tests {

operator/mysqlcontroller/observe.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"k8s.io/utils/ptr"
78
"net/url"
89
"strings"
910

@@ -14,7 +15,6 @@ import (
1415
"github.com/go-logr/logr"
1516
exoscalev1 "github.com/vshn/provider-exoscale/apis/exoscale/v1"
1617
"github.com/vshn/provider-exoscale/operator/mapper"
17-
"k8s.io/utils/pointer"
1818
controllerruntime "sigs.k8s.io/controller-runtime"
1919
)
2020

@@ -86,7 +86,7 @@ func (p *pipeline) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
8686
}
8787

8888
func connectionDetails(in oapi.DbaasServiceMysql, ca string) (managed.ConnectionDetails, error) {
89-
uri := pointer.StringDeref(in.Uri, "")
89+
uri := ptr.Deref[string](in.Uri, "")
9090
// uri may be absent
9191
if uri == "" {
9292
if in.ConnectionInfo == nil || in.ConnectionInfo.Uri == nil || len(*in.ConnectionInfo.Uri) == 0 {
@@ -141,7 +141,7 @@ func isUpToDate(current, external *exoscalev1.MySQLParameters, log logr.Logger)
141141

142142
func mapObservation(instance oapi.DbaasServiceMysql) (exoscalev1.MySQLObservation, error) {
143143
observation := exoscalev1.MySQLObservation{
144-
Version: pointer.StringDeref(instance.Version, ""),
144+
Version: ptr.Deref[string](instance.Version, ""),
145145
NodeStates: mapper.ToNodeStates(instance.NodeStates),
146146
}
147147

@@ -178,7 +178,7 @@ func mapParameters(in oapi.DbaasServiceMysql, zone string) (*exoscalev1.MySQLPar
178178
Zone: exoscalev1.Zone(zone),
179179
Version: *in.Version,
180180
DBaaSParameters: exoscalev1.DBaaSParameters{
181-
TerminationProtection: pointer.BoolDeref(in.TerminationProtection, false),
181+
TerminationProtection: ptr.Deref[bool](in.TerminationProtection, false),
182182
Size: exoscalev1.SizeSpec{
183183
Plan: in.Plan,
184184
},

operator/opensearchcontroller/observe.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/go-logr/logr"
1313
exoscalev1 "github.com/vshn/provider-exoscale/apis/exoscale/v1"
1414
"github.com/vshn/provider-exoscale/operator/mapper"
15-
"k8s.io/utils/pointer"
15+
"k8s.io/utils/ptr"
1616
controllerruntime "sigs.k8s.io/controller-runtime"
1717
)
1818

@@ -118,7 +118,7 @@ func isUpToDate(current, external *exoscalev1.OpenSearchParameters, log logr.Log
118118

119119
func mapObservation(instance oapi.DbaasServiceOpensearch) (exoscalev1.OpenSearchObservation, error) {
120120
observation := exoscalev1.OpenSearchObservation{
121-
MajorVersion: pointer.StringDeref(instance.Version, ""),
121+
MajorVersion: ptr.Deref[string](instance.Version, ""),
122122
NodeStates: mapper.ToNodeStates(instance.NodeStates),
123123
}
124124

0 commit comments

Comments
 (0)