Skip to content

Commit

Permalink
Manage generics
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Saratura committed May 28, 2024
1 parent beba052 commit ac7e7a5
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion operator/iamkeycontroller/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions operator/iamkeycontroller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions operator/kafkacontroller/observe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -200,15 +200,15 @@ 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,
},
IPFilter: actualIPFilter,
},
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)
Expand Down
36 changes: 18 additions & 18 deletions operator/kafkacontroller/observe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand Down Expand Up @@ -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",
Expand All @@ -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:[email protected]: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:[email protected]:21701")
mockGetKafkaCall(exoMock, "foo", found, nil)
mockGetKafkaSettingsCall(exoMock, nil)
mockCACall(exoMock)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions operator/mapper/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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))}
}

Expand All @@ -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,
},
Expand Down
6 changes: 3 additions & 3 deletions operator/mysqlcontroller/observe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
}

Expand Down Expand Up @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion operator/opensearchcontroller/observe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down
10 changes: 5 additions & 5 deletions operator/postgresqlcontroller/observe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions operator/rediscontroller/observe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit ac7e7a5

Please sign in to comment.