holos-run / holos

Holos - The Holistic platform manager
https://holos.run
Apache License 2.0
1 stars 0 forks source link

platform service: make (#205) create platform should be idempotent #206

Closed jeffmccune closed 2 months ago

jeffmccune commented 2 months ago

Previously holos.platform.v1alpha1.PlatformService.CreatePlatform returns an error for a request to create a platform of the same name as an existing platform.

holos create platform --name k3d --display-name "Try Holos Locally"

8:00AM ERR could not execute version=0.87.2 code=failed_precondition
err="failed_precondition: platform.go:55: ent: constraint failed:
ERROR: duplicate key value violates unique constraint
\"platform_org_id_name\" (SQLSTATE 23505)" loc=client.go:138

This patch makes the CreatePlatform rpc idempotent using the upsert API. The already_exists bool field is added to CreatePlatformResponse response to indicate to the client if the platform already exists or not.

Result:

holos create platform --display-name "Holos Local" --name k3d10

11:53AM INF create.go:56 created platform k3d10 version=0.87.2
name=k3d10 id=0190c731-1808-7e7d-9ccb-3d17434d0055
org=0190c6d6-4974-7733-9f7b-5d759a3e60e7 exists=false

holos create platform --display-name "Holos Local" --name k3d10

11:53AM INF create.go:56 updated platform k3d10 version=0.87.2
name=k3d10 id=0190c731-1808-7e7d-9ccb-3d17434d0055
org=0190c6d6-4974-7733-9f7b-5d759a3e60e7 exists=true

Closes: #205