Skip to content

feat(spanner): Add custom user-managed CreateInstanceConfig sample - #14970

Open
iennae wants to merge 2 commits into
feat/spanner-create-instance-asymmetric-autoscalingfrom
feat/spanner-create-instance-config
Open

iennae wants to merge 2 commits into
feat/spanner-create-instance-asymmetric-autoscalingfrom
feat/spanner-create-instance-config

Conversation

@iennae

@iennae iennae commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Description

Adds spanner_create_instance_config creating a custom-* user-managed Spanner instance configuration.

Note: Stacked on #14853 (feat/spanner-create-instance-asymmetric-autoscaling) so this PR shows only this sample's diff. It will merge into main after #14853.

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended. Unit and live integration tests pass on Python 3.13.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved
Custom Spanner topologies extend a Google-managed base configuration with optional read-only replicas via InstanceAdminClient.create_instance_config. Add spanner_create_instance_config.
@iennae
iennae requested review from a team as code owners November 18, 2026 22:19
@snippet-bot

snippet-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment
@product-auto-label product-auto-label Bot added api: spanner Issues related to the Spanner API. samples Issues that are directly related to samples. labels Nov 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new script and associated tests for creating custom Spanner instance configurations. The review feedback highlights a potential IndexError when accessing the first element of optional_replicas without verifying if the list is non-empty. It is recommended to add a safety check to prevent crashes when a base configuration lacks optional replicas.


try:
base_config = client.get_instance_config(name=base_config_path)
replicas = list(base_config.replicas) + [base_config.optional_replicas[0]]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If the retrieved base_config does not contain any optional replicas, accessing base_config.optional_replicas[0] will raise an unhandled IndexError and crash the sample. It is safer to check if optional_replicas is non-empty before attempting to access its first element.

        if not base_config.optional_replicas:
            print(
                f"error: base config '{base_config_id}' has no optional replicas.",
                file=sys.stderr,
            )
            return
        replicas = list(base_config.replicas) + [base_config.optional_replicas[0]]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, done: the sample now reports a clear error on stderr when the base config has no optional replicas, and a unit test covers it (a5d1c65).

Problem: review of this sample identified correctness and robustness
improvements in the sample and its tests.

Solution: apply the accepted review suggestions and extend the tests to
cover the updated behavior. Details are in the review thread replies.

Files updated:
  - spanner/instance_admin/src/spanner_instance_admin/create_instance_config.py
  - spanner/instance_admin/tests/create_instance_config_test.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API. samples Issues that are directly related to samples.

1 participant