vitabaks / postgresql_cluster

Automated database platform for PostgreSQL® — the open-source alternative to cloud-managed databases.
https://postgresql-cluster.org
MIT License
1.84k stars 418 forks source link

GCP: Add support for bare metal instances #780

Closed vitabaks closed 1 month ago

vitabaks commented 1 month ago

This PR adds support for bare metal instances in GCP.

For these instance types, the on_host_maintenance: "TERMINATE" option is automatically set, as required by GCP. For all other standard instance types, the "MIGRATE" option is used, allowing instances to migrate during maintenance.

vitabaks commented 1 month ago

Test

result:

TASK [cloud-resources : GCP: Create or modify VM instance] *********************
failed: [localhost] (item=dedicated-test-1485184977-pgnode01) => {"ansible_index_var": "idx", "ansible_loop_var": "item", "attempts": 3, "changed": false, "idx": 0, "item": 0, "msg": "GCP returned error: {'error': {'code': 400, 'message': \"Invalid value for field 'resource.machineType': 'https://www.********/compute/v1/projects/712159250225/zones/us-east1-c/machineTypes/c3-standard-192-metal'. NetworkInterface NicType can only be set to IDPF on instances with IDPF GuestOsFeature.\", 'errors': [{'message': \"Invalid value for field 'resource.machineType': 'https://www.********/compute/v1/projects/712159250225/zones/us-east1-c/machineTypes/c3-standard-192-metal'. NetworkInterface NicType can only be set to IDPF on instances with IDPF GuestOsFeature.\", 'domain': 'global', 'reason': 'invalid'}]}}", "request": {"body": "{\"kind\": \"compute#instance\", \"disks\": [{\"autoDelete\": true, \"boot\": true, \"deviceName\": \"dedicated-test-1485184977-pgnode01-system\", \"initializeParams\": {\"diskName\": \"dedicated-test-1485184977-pgnode01-system\", \"diskSizeGb\": 100, \"diskType\": \"https://compute.********/compute/v1/projects/712159250225/zones/us-east1-c/diskTypes/hyperdisk-balanced\", \"sourceImage\": \"projects/********/global/images/ubuntu-2204-postgres-17rc1-164-158-1413-1316-1220\"}}, {\"autoDelete\": true, \"deviceName\": \"dedicated-test-1485184977-pgnode01-storage\", \"initializeParams\": {\"diskName\": \"dedicated-test-1485184977-pgnode01-storage\", \"diskSizeGb\": 100, \"diskType\": \"https://compute.********/compute/v1/projects/712159250225/zones/us-east1-c/diskTypes/hyperdisk-balanced\"}}], \"labels\": {\"cluster\": \"dedicated-test-1485184977\"}, \"metadata\": {\"items\": [{\"key\": \"ssh-keys\", \"value\": \"root:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCtsd1XDOh45MDfl1Y03PV9AM4q0QqERY6bDOaJnmH6jOamp6g5Ogf9Zc+fFLheMTSXofuUmwWSoYWcVaqqx0Xar/UZjmE6j4zC90RgamLTlYogVLAfznMBtXxHmKHUqGmLOG72HB6v5QBpIv35zVX7pLaHKdBerbg0OO/3GJniQ+87B7RusdMRN5HIIYmMGkCY0EeC2J/YlRgMef/2K1mSrgI6xE1IimnZgVwY6qBOQuM91AsyK3wDVc5dBTytb1Lls2HR4klQ4ec8N1SxZnSbm8vKmxvmQEaUcX79Yg1gEmzJ64ADlAcGBvO0aX+RY3EUEwwukdeeKZ6oJOUJ5JPJ ssh_key_tmp_syijfhw\"}]}, \"machineType\": \"https://www.********/compute/v1/projects/712159250225/zones/us-east1-c/machineTypes/c3-standard-192-metal\", \"name\": \"dedicated-test-1485184977-pgnode01\", \"networkInterfaces\": [{\"accessConfigs\": [{\"name\": \"External NAT\", \"type\": \"ONE_TO_ONE_NAT\"}], \"network\": \"global/networks/default\"}], \"scheduling\": {\"onHostMaintenance\": \"TERMINATE\", \"preemptible\": false}, \"status\": \"RUNNING\", \"tags\": {\"items\": [\"dedicated-test-1485184977\"]}}", "method": "POST", "url": "https://compute.********/compute/v1/projects/712159250225/zones/us-east1-c/instances"}}

UPD: It is necessary to use an image with IDPF support https://cloud.google.com/compute/docs/networking/using-idpf

vitabaks commented 1 month ago

Test 2: with IDPF support image

PLAY [Deploy PostgreSQL HA Cluster (based on "Patroni")] ***********************
TASK [Gathering Facts] *********************************************************
ok: [localhost]
TASK [Include main variables] **************************************************
ok: [localhost]
TASK [cloud-resources : Generate a unique temporary SSH key name] **************
ok: [localhost]
TASK [cloud-resources : Generate a new temporary SSH key to access the server for deployment] ***
changed: [localhost]
TASK [cloud-resources : Set variable: ssh_key_name and ssh_key_content] ********
ok: [localhost]
TASK [cloud-resources : Ensure that 'python3-pip' package is present on controlling host] ***
ok: [localhost -> 127.0.0.1]
TASK [cloud-resources : Ensure that 'google-auth' dependency is present on controlling host] ***
ok: [localhost -> 127.0.0.1]
TASK [cloud-resources : Lookup the GCP_SERVICE_ACCOUNT_CONTENTS environmental variable] ***
ok: [localhost]
TASK [cloud-resources : Set variable: gcp_service_account_contents (b64decode)] ***
ok: [localhost]
TASK [cloud-resources : GCP: Gather information about project] *****************
ok: [localhost]
TASK [cloud-resources : Set variable: gcp_network_name] ************************
ok: [localhost]
TASK [cloud-resources : GCP: Gather information about network] *****************
ok: [localhost]
TASK [cloud-resources : GCP: Extract ip_range for network 'default'] ***********
ok: [localhost]
TASK [cloud-resources : GCP: Create or modify SSH public firewall rule] ********
changed: [localhost]
TASK [cloud-resources : GCP: Create or modify Postgres cluster firewall rule] ***
changed: [localhost]
TASK [cloud-resources : GCP: Create or modify VM instance] *********************
changed: [localhost] => (item=dedicated-test-1485356189-pgnode01)
TASK [cloud-resources : Wait for host to be available via SSH] *****************
ok: [localhost] => (item=104.154.171.135)
TASK [cloud-resources : Server info] *******************************************
ok: [localhost] => (item=104.154.171.135) => {
    "msg": {
        "id": "8315221318562346144",
        "image": "ubuntu-2204-lts",
        "name": "dedicated-test-1485356189-pgnode01",
        "private_ip": "10.128.15.196",
        "public_ip": "104.154.171.135",
        "type": "c3-standard-192-metal",
        "volume_size": "1000 GB"
    }
}

passed