Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
This adds a Finalizer to the Link controller. For now, this just handles deleting the hcp-config directory.
Testing & Reproduction steps
In addition to automated unit tests, I performed the following manual test.
Run consul like so:
go run . agent -dev --log-level trace --data-dir /tmp/consul-test
Verify that hcp-config directory is created
➜ consul git:(nickcellino/CC-7338/add-link-finalizer) ls /tmp/consul-test
checkpoint-signature hcp-config node-id serf
➜ consul git:(nickcellino/CC-7338/add-link-finalizer) ls /tmp/consul-test/hcp-config
hcp-management-token server-config.json successful-bootstrap
➜ consul git:(nickcellino/CC-7338/add-link-finalizer)
Create a Link:
➜ consul git:(nickcellino/CC-7338/add-link-finalizer) http PUT localhost:8500/api/hcp/v2/link/global data[resourceId]=$RESOURCE_ID data[clientSecret]=$CLIENT_SECRET data[clientId]=$CLIENT_ID X-Consul-Token:$CONSUL_HTTP_TOKEN
HTTP/1.1 200 OK
Content-Length: 617
Content-Type: text/plain; charset=utf-8
Date: Tue, 23 Jan 2024 21:27:06 GMT
Verify that hcp-config directory no longer exists ✅
➜ consul git:(nickcellino/CC-7338/add-link-finalizer) ls /tmp/consul-test
checkpoint-signature node-id serf
Verify that Link no longer exists:
➜ consul git:(nickcellino/CC-7338/add-link-finalizer) http GET localhost:8500/api/hcp/v2/link/global
HTTP/1.1 404 Not Found
Content-Length: 52
Content-Type: text/plain; charset=utf-8
Date: Tue, 23 Jan 2024 21:34:14 GMT
rpc error: code = NotFound desc = resource not found
### Links
https://hashicorp.atlassian.net/browse/CC-7338
<!--
Include any links here that might be helpful for people reviewing your PR (Tickets, GH issues, API docs, external benchmarks, tools docs, etc). If there are none, feel free to delete this section.
Please be mindful not to leak any customer or confidential information. HashiCorp employees may want to use our internal URL shortener to obfuscate links.
-->
### PR Checklist
* [x] updated test coverage
* [ ] external facing docs updated
* [ ] appropriate backport labels added
* [ ] not a security concern
Description
This adds a
Finalizer
to the Link controller. For now, this just handles deleting thehcp-config
directory.Testing & Reproduction steps
In addition to automated unit tests, I performed the following manual test.
Run consul like so:
Verify that
hcp-config
directory is createdCreate a Link:
{ "data": { "clientId": "...", "clientSecret": "...", "resourceId": "organization/d95434ef-1f14-4b17-b23e-1eb608bb9fda/project/e263159f-b9ea-468e-8dc5-ee3d23403fe2/hashicorp.consul.global-network-manager.cluster/my-cluster" }, "generation": "01HMW3GFRA65WXEG75PEQ4734K", "id": { "name": "global", "tenancy": { "peerName": "local" }, "type": { "group": "hcp", "groupVersion": "v2", "kind": "Link" }, "uid": "01HMW3GFRA65WXEG75PDFC5YQP" }, "version": "29" }
2024-01-23T16:27:06.763-0500 [TRACE] agent.server.controller-runtime: added finalizer: controller=consul.io/hcp/link managed_type=hcp.v2.Link resource-id="uid:\"01HMW3GFRA65WXEG75PDFC5YQP\" name:\"global\" type:{group:\"hcp\" group_version:\"v2\" kind:\"Link\"} tenancy:{peer_name:\"local\"}"
Verify from logs that cleanup has been called ✅ :
Verify that
hcp-config
directory no longer exists ✅Verify that Link no longer exists:
rpc error: code = NotFound desc = resource not found