Skip to content

feat(managed-database): add network update support to edit command - #283

Merged
amstuta merged 2 commits into
ovh:mainfrom
AchrafHammouda:feat/network-update
Sep 24, 2026
Merged

amstuta merged 2 commits into
ovh:mainfrom
AchrafHammouda:feat/network-update

Conversation

@AchrafHammouda

@AchrafHammouda AchrafHammouda commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

feat(managed-database): add network update support to edit command

Description

Add --network-id, --subnet-id, and --public-network flags to the managed-database edit command, enabling in-place network switching between public and private networks.

Usage:

  • Switch to private: --network-id <uuid> --subnet-id <uuid>
  • Switch to public: --public-network

The --public-network flag is mutually exclusive with --network-id and --subnet-id.

Network fields are injected into the EditResource body via a new extraFields variadic parameter, bypassing the OpenAPI spec filter in a single PUT call.

Changes:

  • Added --network-id, --subnet-id, and --public-network flags to the edit command
  • Added extraFields variadic parameter to common.EditResource to inject fields after the OpenAPI filter
  • Updated auto-generated documentation with network update examples
  • Added usage examples in the command's help text

How Has This Been Tested?

Manually tested against a live PostgreSQL production cluster on OVH EU:

  • Public to private network switch (--network-id <uuid> --subnet-id <uuid>) — cluster switched to private successfully
  • Private to public network switch (--public-network) — cluster switched to public successfully
  • Mutual exclusivity (--public-network --network-id <uuid>) — properly rejected by cobra
  • Edit without network flags while on public (--description "...") — no network change triggered
  • Edit without network flags while on private (--description "...") — no network change triggered

Type of change

  • New feature (non-breaking change which adds functionality)
  • Documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have commented my code
  • I ran go mod tidy
  • I have added tests that prove my fix is effective or that my feature works

@AchrafHammouda
AchrafHammouda requested a review from a team as a code owner September 7, 2026 14:41
Add --network-id and --subnet-id flags to the managed-database edit
command, enabling in-place network switching between public and private
networks.

Usage:
- Switch to private: --network-id <uuid> --subnet-id <uuid>
- Switch to public: --network-id none --subnet-id none

Network updates are sent as a separate PUT request to properly handle
null values for the public network switch, since the OpenAPI spec filter
in EditResource strips network fields.

Signed-off-by: Achraf Hammouda <achraf.hammouda@ovhcloud.com>
Comment thread internal/services/cloud/cloud_managed_database.go Outdated
Comment thread internal/cmd/cloud_managed_database.go Outdated
- Inject network fields into EditResource via extraFields parameter
  instead of a separate PUT call
- Replace --network-id none / --subnet-id none with --public-network
  flag, mutually exclusive with --network-id and --subnet-id
- Add extraFields variadic parameter to common.EditResource to allow
  injecting fields that bypass the OpenAPI spec filter

Signed-off-by: Achraf Hammouda <achraf.hammouda@ovhcloud.com>
display.OutputError(&flags.OutputFormatConfig, "%s", err)
return
// Build extra network fields that bypass the OpenAPI filter
var networkFields map[string]any

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.

I don't get why you create an extra map of fields instead of using ManagedDatabaseSpec.CLIPublicNetwork to fill ManagedDatabaseSpec.NetworkID and ManagedDatabaseSpec.SubnetID ?

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.

The extraFields approach is needed for two reasons:

  1. OpenAPI filter strips networkId/subnetId — EditResource calls FilterEditableFields which removes any field not declared in the PUT schema. Even if we set ManagedDatabaseSpec.NetworkID and .SubnetID directly, they get filtered out before the PUT request is sent. The extraFields parameter injects them after the filter, in a single PUT call.
  2. null vs empty string — When switching to public network, the API expects "networkId": null. But NetworkID is a Go string with omitempty — an empty string is omitted from the JSON entirely, not serialized as null. The map[string]any with nil values is the only way to produce proper JSON null.

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.

For your point 1), I don't see why the API-accepted fields would be dropped before the request is sent, we already do this kind of thing here: https://github.com/ovh/ovhcloud-cli/blob/main/internal/services/cloud/cloud_managed_database.go#L235

Anyway, your solution works even if I'm not a big fan of the code, so I'll merge it.

@amstuta
amstuta merged commit d6d87bf into ovh:main Sep 24, 2026
4 checks passed
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.

2 participants