Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add finalizer to link resource #1294

Open
1 of 4 tasks
dhiaayachi opened this issue Sep 28, 2024 · 0 comments
Open
1 of 4 tasks

Add finalizer to link resource #1294

dhiaayachi opened this issue Sep 28, 2024 · 0 comments

Comments

@dhiaayachi
Copy link
Owner

Description

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.

  1. Run consul like so:
go run . agent -dev --log-level trace --data-dir /tmp/consul-test
  1. 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)
  1. 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

{
    "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"
}

Verify from logs that finalizer has been added ✅ :

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\"}"
  1. Delete the Link:
➜  consul git:(nickcellino/CC-7338/add-link-finalizer) http DELETE localhost:8500/api/hcp/v2/link/global
HTTP/1.1 204 No Content
Date: Tue, 23 Jan 2024 21:32:45 GMT

Verify from logs that cleanup has been called ✅ :

2024-01-23T16:32:45.578-0500 [TRACE] agent.server.controller-runtime: cleaning up link resource: 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\"}"
2024-01-23T16:32:45.578-0500 [DEBUG] agent.server.controller-runtime: deleting hcp-config dir: 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\"}" dir=/tmp/consul-test/hcp-config
2024-01-23T16:32:45.579-0500 [TRACE] agent.server.controller-runtime: removed 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\"}"
2024-01-23T16:32:45.579-0500 [TRACE] agent.server.controller-runtime: finally deleted: 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\"}"
  1. 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
  1. 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

PR Checklist

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern
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

No branches or pull requests

1 participant