From ac7e7a5dbb3ecd0b7faef39cccc35907398a382f Mon Sep 17 00:00:00 2001 From: Gabriel Saratura Date: Tue, 28 May 2024 10:33:35 +0200 Subject: [PATCH] Manage generics --- operator/iamkeycontroller/create.go | 2 +- operator/iamkeycontroller/util.go | 10 +++---- operator/kafkacontroller/observe.go | 8 +++--- operator/kafkacontroller/observe_test.go | 36 ++++++++++++------------ operator/mapper/alias.go | 8 +++--- operator/mysqlcontroller/observe.go | 6 ++-- operator/opensearchcontroller/observe.go | 2 +- operator/postgresqlcontroller/observe.go | 10 +++---- operator/rediscontroller/observe.go | 4 +-- 9 files changed, 43 insertions(+), 43 deletions(-) diff --git a/operator/iamkeycontroller/create.go b/operator/iamkeycontroller/create.go index e138e752..e1b6656d 100644 --- a/operator/iamkeycontroller/create.go +++ b/operator/iamkeycontroller/create.go @@ -162,7 +162,7 @@ func (p *IAMKeyPipeline) createCredentialsSecret(ctx *pipelineContext) error { for k, v := range connDetails { secret.Data[k] = v } - secret.Immutable = ptr.To[bool](true) + secret.Immutable = ptr.To(true) err = controllerutil.SetOwnerReference(ctx.iamKey, secret, p.kube.Scheme()) if err != nil { diff --git a/operator/iamkeycontroller/util.go b/operator/iamkeycontroller/util.go index bf5f0d9d..c107899c 100644 --- a/operator/iamkeycontroller/util.go +++ b/operator/iamkeycontroller/util.go @@ -16,11 +16,11 @@ func createRole(keyName string, buckets []string) *exooapi.IamRole { iamRole := &exooapi.IamRole{ Name: &keyName, - Description: ptr.To[string]("IAM Role for SOS+IAM creation, it was autogenerated by provider-exoscale"), + Description: ptr.To("IAM Role for SOS+IAM creation, it was autogenerated by provider-exoscale"), Permissions: &[]exooapi.IamRolePermissions{ exooapi.IamRolePermissionsBypassGovernanceRetention, }, - Editable: ptr.To[bool](true), + Editable: ptr.To(true), Policy: &exooapi.IamPolicy{ DefaultServiceStrategy: exooapi.IamPolicyDefaultServiceStrategyDeny, Services: exooapi.IamPolicy_Services{ @@ -37,20 +37,20 @@ func createRole(keyName string, buckets []string) *exooapi.IamRole { // We specifically need to deny the listing of buckets, or the customer is able to see all of them *iamRole.Policy.Services.AdditionalProperties["sos"].Rules = append(*iamRole.Policy.Services.AdditionalProperties["sos"].Rules, exooapi.IamServicePolicyRule{ Action: &policyDeny, - Expression: ptr.To[string]("operation in ['list-sos-buckets-usage', 'list-buckets']"), + Expression: ptr.To("operation in ['list-sos-buckets-usage', 'list-buckets']"), }) // we must first add buckets to deny list and then add the allow rule, otherwise it will not work for _, bucket := range buckets { *iamRole.Policy.Services.AdditionalProperties["sos"].Rules = append(*iamRole.Policy.Services.AdditionalProperties["sos"].Rules, exooapi.IamServicePolicyRule{ Action: &policyDeny, - Expression: ptr.To[string]("resources.bucket != " + "'" + bucket + "'"), + Expression: ptr.To("resources.bucket != " + "'" + bucket + "'"), }) } *iamRole.Policy.Services.AdditionalProperties["sos"].Rules = append(*iamRole.Policy.Services.AdditionalProperties["sos"].Rules, exooapi.IamServicePolicyRule{ Action: &policyAllow, - Expression: ptr.To[string]("true"), + Expression: ptr.To("true"), }) return iamRole diff --git a/operator/kafkacontroller/observe.go b/operator/kafkacontroller/observe.go index cbf35934..90f37072 100644 --- a/operator/kafkacontroller/observe.go +++ b/operator/kafkacontroller/observe.go @@ -103,9 +103,9 @@ func getObservation(external *oapi.DbaasServiceKafka) (exoscalev1.KafkaObservati } return exoscalev1.KafkaObservation{ - Version: ptr.Deref[string](external.Version, ""), + Version: ptr.Deref(external.Version, ""), KafkaSettings: settings, - KafkaRestEnabled: ptr.Deref[bool](external.KafkaRestEnabled, false), + KafkaRestEnabled: ptr.Deref(external.KafkaRestEnabled, false), KafkaRestSettings: restSettings, NodeStates: nodeStates, Notifications: notifications, @@ -200,7 +200,7 @@ func diffParameters(external *oapi.DbaasServiceKafka, expected exoscalev1.KafkaP }, Zone: expected.Zone, DBaaSParameters: exoscalev1.DBaaSParameters{ - TerminationProtection: ptr.Deref[bool](external.TerminationProtection, false), + TerminationProtection: ptr.Deref(external.TerminationProtection, false), Size: exoscalev1.SizeSpec{ Plan: external.Plan, }, @@ -208,7 +208,7 @@ func diffParameters(external *oapi.DbaasServiceKafka, expected exoscalev1.KafkaP }, 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 KafkaSettings: actualKafkaSettings, - KafkaRestEnabled: ptr.Deref[bool](external.KafkaRestEnabled, false), + KafkaRestEnabled: ptr.Deref(external.KafkaRestEnabled, false), KafkaRestSettings: actualKafkaRestSettings, } settingComparer := cmp.Comparer(mapper.CompareSettings) diff --git a/operator/kafkacontroller/observe_test.go b/operator/kafkacontroller/observe_test.go index 2c5ad583..64743177 100644 --- a/operator/kafkacontroller/observe_test.go +++ b/operator/kafkacontroller/observe_test.go @@ -46,7 +46,7 @@ func TestObserve_UpToDate_ConnectionDetails(t *testing.T) { instance := sampleKafka("foo") found := sampleAPIKafka("foo") - found.Uri = ptr.To[string]("foobar.com:21701") + found.Uri = ptr.To("foobar.com:21701") found.UriParams = &map[string]interface{}{ "host": "foobar.com", "port": "21701", @@ -56,8 +56,8 @@ func TestObserve_UpToDate_ConnectionDetails(t *testing.T) { "10.10.1.2:21701", "10.10.1.3:21701", } - found.ConnectionInfo.AccessCert = ptr.To[string]("CERT") - found.ConnectionInfo.AccessKey = ptr.To[string]("KEY") + found.ConnectionInfo.AccessCert = ptr.To("CERT") + found.ConnectionInfo.AccessKey = ptr.To("KEY") mockGetKafkaCall(exoMock, "foo", found, nil) mockGetKafkaSettingsCall(exoMock, nil) @@ -94,7 +94,7 @@ func TestObserve_UpToDate_ConnectionDetails_with_REST(t *testing.T) { instance := sampleKafka("foo") instance.Spec.ForProvider.KafkaRestEnabled = true found := sampleAPIKafka("foo") - found.Uri = ptr.To[string]("foobar.com:21701") + found.Uri = ptr.To("foobar.com:21701") found.UriParams = &map[string]interface{}{ "host": "foobar.com", "port": "21701", @@ -104,10 +104,10 @@ func TestObserve_UpToDate_ConnectionDetails_with_REST(t *testing.T) { "10.10.1.2:21701", "10.10.1.3:21701", } - found.ConnectionInfo.AccessCert = ptr.To[string]("CERT") - found.ConnectionInfo.AccessKey = ptr.To[string]("KEY") - found.KafkaRestEnabled = ptr.To[bool](true) - found.ConnectionInfo.RestUri = ptr.To[string]("https://admin:BGAUNBS2afjwQ@test.foobar.com:21701") + found.ConnectionInfo.AccessCert = ptr.To("CERT") + found.ConnectionInfo.AccessKey = ptr.To("KEY") + found.KafkaRestEnabled = ptr.To(true) + found.ConnectionInfo.RestUri = ptr.To("https://admin:BGAUNBS2afjwQ@test.foobar.com:21701") mockGetKafkaCall(exoMock, "foo", found, nil) mockGetKafkaSettingsCall(exoMock, nil) mockCACall(exoMock) @@ -142,7 +142,7 @@ func TestObserve_UpToDate_Status(t *testing.T) { } instance := sampleKafka("foo") found := sampleAPIKafka("foo") - found.Version = ptr.To[string]("3.2.1") + found.Version = ptr.To("3.2.1") found.NodeStates = &[]oapi.DbaasNodeState{ { Name: "node-1", @@ -240,7 +240,7 @@ func TestObserve_UpToDate_WithVersion(t *testing.T) { instance := sampleKafka("foo") instance.Spec.ForProvider.Version = "3.2" found := sampleAPIKafka("foo") - found.Version = ptr.To[string]("3.2.1") + found.Version = ptr.To("3.2.1") mockGetKafkaCall(exoMock, "foo", found, nil) mockGetKafkaSettingsCall(exoMock, nil) @@ -265,7 +265,7 @@ func TestObserve_UpToDate_EmptyRestSettings(t *testing.T) { instance.Spec.ForProvider.KafkaRestEnabled = true instance.Spec.ForProvider.KafkaRestSettings = runtime.RawExtension{} found := sampleAPIKafka("foo") - found.KafkaRestEnabled = ptr.To[bool](true) + found.KafkaRestEnabled = ptr.To(true) mockGetKafkaCall(exoMock, "foo", found, nil) mockGetKafkaSettingsCall(exoMock, nil) @@ -295,7 +295,7 @@ func TestObserve_UpToDate_RestSettings(t *testing.T) { instance.Spec.ForProvider.KafkaRestEnabled = true instance.Spec.ForProvider.KafkaRestSettings = restsetting found := sampleAPIKafka("foo") - found.KafkaRestEnabled = ptr.To[bool](true) + found.KafkaRestEnabled = ptr.To(true) mockGetKafkaCall(exoMock, "foo", found, nil) mockGetKafkaSettingsCall(exoMock, nil) @@ -378,7 +378,7 @@ func TestObserve_Outdated_RestSettings(t *testing.T) { instance.Spec.ForProvider.KafkaRestEnabled = true instance.Spec.ForProvider.KafkaRestSettings = restsetting found := sampleAPIKafka("foo") - found.KafkaRestEnabled = ptr.To[bool](true) + found.KafkaRestEnabled = ptr.To(true) mockGetKafkaCall(exoMock, "foo", found, nil) mockGetKafkaSettingsCall(exoMock, nil) @@ -444,15 +444,15 @@ func sampleAPIKafka(name string) *oapi.DbaasServiceKafka { RegistryUri *string "json:\"registry-uri,omitempty\"" RestUri *string "json:\"rest-uri,omitempty\"" }{ - AccessCert: ptr.To[string]("SOME ACCESS CERT"), - AccessKey: ptr.To[string]("SOME ACCESS KEY"), + AccessCert: ptr.To("SOME ACCESS CERT"), + AccessKey: ptr.To("SOME ACCESS KEY"), Nodes: &nodes, } - res.Uri = ptr.To[string]("foo-exoscale-8fa13713-1027-4b9c-bca7-4c14f9ff9928.aivencloud.com") + res.Uri = ptr.To("foo-exoscale-8fa13713-1027-4b9c-bca7-4c14f9ff9928.aivencloud.com") res.UriParams = &map[string]interface{}{} - res.Version = ptr.To[string]("3.2.1") + res.Version = ptr.To("3.2.1") return &res } @@ -488,7 +488,7 @@ func mockCACall(m *operatortest.ClientWithResponsesInterface) { JSON200: &struct { Certificate *string "json:\"certificate,omitempty\"" }{ - Certificate: ptr.To[string]("CA"), + Certificate: ptr.To("CA"), }, }, nil). Once() diff --git a/operator/mapper/alias.go b/operator/mapper/alias.go index 624734c9..dc0c8b6a 100644 --- a/operator/mapper/alias.go +++ b/operator/mapper/alias.go @@ -18,8 +18,8 @@ type BackupSchedule = struct { func ToBackupSchedule(day exoscalev1.TimeOfDay) (BackupSchedule, error) { backupHour, backupMin, _, err := day.Parse() return BackupSchedule{ - BackupHour: ptr.To[int64](backupHour), - BackupMinute: ptr.To[int64](backupMin), + BackupHour: ptr.To(backupHour), + BackupMinute: ptr.To(backupMin), }, err } @@ -79,7 +79,7 @@ func ToBackupSpec(schedule *BackupSchedule) exoscalev1.BackupSpec { if schedule == nil { return exoscalev1.BackupSpec{} } - hour, min := ptr.Deref[int64](schedule.BackupHour, 0), ptr.Deref[int64](schedule.BackupMinute, 0) + hour, min := ptr.Deref(schedule.BackupHour, 0), ptr.Deref(schedule.BackupMinute, 0) return exoscalev1.BackupSpec{TimeOfDay: exoscalev1.TimeOfDay(fmt.Sprintf("%02d:%02d:00", hour, min))} } @@ -102,7 +102,7 @@ func ToRawExtension(m *map[string]interface{}) (runtime.RawExtension, error) { func ToDBaaSParameters(tp *bool, plan string, ipf *[]string) exoscalev1.DBaaSParameters { return exoscalev1.DBaaSParameters{ - TerminationProtection: ptr.Deref[bool](tp, false), + TerminationProtection: ptr.Deref(tp, false), Size: exoscalev1.SizeSpec{ Plan: plan, }, diff --git a/operator/mysqlcontroller/observe.go b/operator/mysqlcontroller/observe.go index 54c8b390..06fef92a 100644 --- a/operator/mysqlcontroller/observe.go +++ b/operator/mysqlcontroller/observe.go @@ -86,7 +86,7 @@ func (p *pipeline) Observe(ctx context.Context, mg resource.Managed) (managed.Ex } func connectionDetails(in oapi.DbaasServiceMysql, ca string) (managed.ConnectionDetails, error) { - uri := ptr.Deref[string](in.Uri, "") + uri := ptr.Deref(in.Uri, "") // uri may be absent if uri == "" { 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) func mapObservation(instance oapi.DbaasServiceMysql) (exoscalev1.MySQLObservation, error) { observation := exoscalev1.MySQLObservation{ - Version: ptr.Deref[string](instance.Version, ""), + Version: ptr.Deref(instance.Version, ""), NodeStates: mapper.ToNodeStates(instance.NodeStates), } @@ -178,7 +178,7 @@ func mapParameters(in oapi.DbaasServiceMysql, zone string) (*exoscalev1.MySQLPar Zone: exoscalev1.Zone(zone), Version: *in.Version, DBaaSParameters: exoscalev1.DBaaSParameters{ - TerminationProtection: ptr.Deref[bool](in.TerminationProtection, false), + TerminationProtection: ptr.Deref(in.TerminationProtection, false), Size: exoscalev1.SizeSpec{ Plan: in.Plan, }, diff --git a/operator/opensearchcontroller/observe.go b/operator/opensearchcontroller/observe.go index 8082ea7d..47f56010 100644 --- a/operator/opensearchcontroller/observe.go +++ b/operator/opensearchcontroller/observe.go @@ -118,7 +118,7 @@ func isUpToDate(current, external *exoscalev1.OpenSearchParameters, log logr.Log func mapObservation(instance oapi.DbaasServiceOpensearch) (exoscalev1.OpenSearchObservation, error) { observation := exoscalev1.OpenSearchObservation{ - MajorVersion: ptr.Deref[string](instance.Version, ""), + MajorVersion: ptr.Deref(instance.Version, ""), NodeStates: mapper.ToNodeStates(instance.NodeStates), } diff --git a/operator/postgresqlcontroller/observe.go b/operator/postgresqlcontroller/observe.go index 56343ba6..8f37002f 100644 --- a/operator/postgresqlcontroller/observe.go +++ b/operator/postgresqlcontroller/observe.go @@ -81,13 +81,13 @@ func mapParameters(in oapi.DbaasServicePg, zone exoscalev1.Zone) (*exoscalev1.Po Backup: mapper.ToBackupSpec(in.BackupSchedule), Zone: zone, DBaaSParameters: exoscalev1.DBaaSParameters{ - TerminationProtection: ptr.Deref[bool](in.TerminationProtection, false), + TerminationProtection: ptr.Deref(in.TerminationProtection, false), Size: exoscalev1.SizeSpec{ Plan: in.Plan, }, IPFilter: *in.IpFilter, }, - Version: ptr.Deref[string](in.Version, ""), + Version: ptr.Deref(in.Version, ""), PGSettings: settings, }, nil } @@ -119,13 +119,13 @@ var variantAiven = oapi.EnumPgVariantAiven func mapObservation(pg oapi.DbaasServicePg) (exoscalev1.PostgreSQLObservation, error) { observation := exoscalev1.PostgreSQLObservation{ DBaaSParameters: exoscalev1.DBaaSParameters{ - TerminationProtection: ptr.Deref[bool](pg.TerminationProtection, false), + TerminationProtection: ptr.Deref(pg.TerminationProtection, false), Size: exoscalev1.SizeSpec{ Plan: pg.Plan, }, IPFilter: *pg.IpFilter, }, - Version: ptr.Deref[string](pg.Version, ""), + Version: ptr.Deref(pg.Version, ""), Maintenance: exoscalev1.MaintenanceSpec{ DayOfWeek: pg.Maintenance.Dow, TimeOfDay: exoscalev1.TimeOfDay(pg.Maintenance.Time), @@ -174,7 +174,7 @@ func isUpToDate(current, external *exoscalev1.PostgreSQLParameters, log logr.Log // connectionDetails parses the connection details from the given observation. func connectionDetails(pgExo oapi.DbaasServicePg, ca string) (managed.ConnectionDetails, error) { - raw := ptr.Deref[string](pgExo.Uri, "") + raw := ptr.Deref(pgExo.Uri, "") parsed, err := url.Parse(raw) if err != nil { return nil, fmt.Errorf("cannot parse connection URL: %w", err) diff --git a/operator/rediscontroller/observe.go b/operator/rediscontroller/observe.go index e6448ada..6b434aba 100644 --- a/operator/rediscontroller/observe.go +++ b/operator/rediscontroller/observe.go @@ -127,7 +127,7 @@ func connectionDetails(in oapi.DbaasServiceRedis) (map[string][]byte, error) { func mapObservation(instance oapi.DbaasServiceRedis) (exoscalev1.RedisObservation, error) { observation := exoscalev1.RedisObservation{ - Version: ptr.Deref[string](instance.Version, ""), + Version: ptr.Deref(instance.Version, ""), NodeStates: mapper.ToNodeStates(instance.NodeStates), } @@ -158,7 +158,7 @@ func mapParameters(in oapi.DbaasServiceRedis, zone exoscalev1.Zone) (*exoscalev1 }, Zone: zone, DBaaSParameters: exoscalev1.DBaaSParameters{ - TerminationProtection: ptr.Deref[bool](in.TerminationProtection, false), + TerminationProtection: ptr.Deref(in.TerminationProtection, false), Size: exoscalev1.SizeSpec{ Plan: in.Plan, },