Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PostgreSQLServerConfiguration managed resource #285

Merged
merged 3 commits into from
Aug 27, 2021

Conversation

ulucinar
Copy link
Collaborator

@ulucinar ulucinar commented Aug 25, 2021

Description of your changes

Support for configuring PostgreSQLServer parameters. If the configuration has been applied successfully, the PostgreSQLServerConfiguration MR will have the Ready condition in its status.

Setting the external-name annotation
When you run az postgres server configuration list to list available configurations for a psql instance, you will observe a JSON array of configuration objects similar to the following:

{
    "dataType": "Boolean",
    "defaultValue": "on",
    "description": "Enable input of NULL elements in arrays.",
    "id": "/subscriptions/.../resourceGroups/alper/providers/Microsoft.DBforPostgreSQL/servers/example-psql/configurations/array_nulls",
    "name": "array_nulls",
    "type": "Microsoft.DBforPostgreSQL/servers/configurations",
    "value": "on"
    ...
  }

My observation is that for a psql (server) configuration that has not been manipulated previously, the postgresql.ConfigurationsClient.Get will report a 404 and for the MR, postgresqlserverconfiguration/external.Create will be called accordingly. However, if it has previously been manipulated, and even if it's set to its default value and its source is reset to system-default, I have observed that postgresql.ConfigurationsClient.Get returns the configuration object and postgresqlserverconfiguration/external.Create is thus not called. For this reason, we also set the external-name during postgresqlserverconfiguration/external.Observe if it's not already set. The external name takes the following form:
/subscriptions/<subscription id>/resourceGroups/<resource group name>/providers/Microsoft.DBforPostgreSQL/servers/<psql server name>/configurations/<configuration name>

Deletion Semantics
postgresql.ConfigurationsClient does not have a delete method, probably because these configuration objects somewhat always exist for a psql instance (their sources being set to system-managed), but as explained above, this behavior is not consistent. While deciding on what to do when a PostgreSQLServerConfiguration MR is deleted, I took a look at how Terraform's azurerm_postgresql_configuration resource behaves, and as revealed by an az postgres server configuration show, it resets the configuration value to the default value but does not reset its source. I've chosen to implement a similar behavior of resetting to the default value but also its source is reset to system-managed. As explained above, my observation is that the configuration object still exists in ARM and thus I had to observe the deletionTimestamp on the MR together with its source being system-managed and its value being equal to its defaultValue for removing the finalizer on the MR.

Fixes #281

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.
  • Add automated test

How has this code been tested

I've manually configured an existing PostgreSQLServer instance's max_wal_senders parameter using a PostgreSQLServerConfiguration MR.

- Support for configuring PostgreSQLServer parameters
- Fixes crossplane-contrib#281

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
Copy link
Member

@muvaf muvaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @ulucinar for working on this challenging resource! I have a few comments but it mostly looks good.

// Delete deletes the given PostgreSQL Server Configuration
func (c *PostgreSQLConfigurationClient) Delete(ctx context.Context, cr *azuredbv1beta1.PostgreSQLServerConfiguration) error {
source := SourceSystemManaged
return c.update(ctx, cr, &cr.Status.AtProvider.DefaultValue, &source)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth to have a code comment about why we call update.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

apis/database/v1beta1/register.go Show resolved Hide resolved
pkg/clients/database/configuration/postgresql.go Outdated Show resolved Hide resolved
apis/database/v1beta1/configuration_types.go Outdated Show resolved Hide resolved
apis/database/v1beta1/configuration_types.go Show resolved Hide resolved
Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
- Add tests

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
Copy link
Member

@muvaf muvaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @ulucinar !

@ulucinar
Copy link
Collaborator Author

Thanks @muvaf for the support.

@ulucinar ulucinar merged commit 33f728d into crossplane-contrib:master Aug 27, 2021
@ulucinar ulucinar deleted the postgresql-config branch August 27, 2021 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No option to configure the azure postgresql server parameters
2 participants