Skip to content

Add ageing cache to dns alias driver - #1071

Open
PaulJouvanceau wants to merge 1 commit into
opensvc:mainfrom
PaulJouvanceau:fix/ageing-cache-integration
Open

Add ageing cache to dns alias driver#1071
PaulJouvanceau wants to merge 1 commit into
opensvc:mainfrom
PaulJouvanceau:fix/ageing-cache-integration

Conversation

@PaulJouvanceau

Copy link
Copy Markdown
Contributor
  • Cache getAliases responses with a configurable TTL (default 30s).
  • Use a sentinel value ("null") to cache 404 (no aliases) without poisoning the cache with nil.
  • Invalidate the cache after every mutation (create, update, delete).
  • Explicitly clear the cache before Start, Stop, and Status to ensure fresh data.
  • Expose CacheTTL on the mgr struct so tests can disable the cache (set to 0) and avoid filesystem permission issues.

Changes:

  • drivers/resipsgcp_dnsalias/main.go
  • drivers/resipsgcp_dnsalias/mgr.go
  • drivers/resipsgcp_dnsalias/main_test.go

- Cache getAliases responses with a configurable TTL (default 30s).
- Use a sentinel value ("null") to cache 404 (no aliases) without
  poisoning the cache with nil.
- Invalidate the cache after every mutation (create, update, delete).
- Explicitly clear the cache before Start, Stop, and Status to ensure
  fresh data.
- Expose CacheTTL on the mgr struct so tests can disable the cache
  (set to 0) and avoid filesystem permission issues.

Changes:
- drivers/resipsgcp_dnsalias/main.go
- drivers/resipsgcp_dnsalias/mgr.go
- drivers/resipsgcp_dnsalias/main_test.go
@PaulJouvanceau
PaulJouvanceau force-pushed the fix/ageing-cache-integration branch from 53a0b94 to 40f3543 Compare August 27, 2026 14:50
}

func (m *mgr) cacheSig() string {
return fmt.Sprintf("dnsalias:%s:%s:%s", m.alias.ZoneID, m.alias.Name, m.alias.UUID)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium - Scope the alias cache by SGCP authentication context

The cache signature is derived only from zone, name, and UUID, while each driver instance can use a different secret/SGCP account and the ageing cache is shared under the node-wide cache directory. Parallel status or reconcile operations for two such resources can therefore return one account's cached alias listing to the other; that can expose the other tenant's alias metadata and make the second resource report the wrong state or attempt an update/delete using the cached UUID. Include a stable endpoint and authenticated account/secret identity in a sanitized cache key (or otherwise isolate cache entries by API context).

Show fix

Include a stable, non-secret identity for the configured SGCP endpoint and credentials (for example the auth-info signature/account identity) in the cache signature, sanitize each component before using it in cache/lock paths, and add a parallel two-manager test proving that entries cannot be reused across authentication contexts.

More info - Reply on this comment to give feedback or ignore the issue.

Comment on lines +168 to 170
t.Log().Debugf("cache clear error: %s", err)
}
aliases, err := t.mgr.getAliases(ctx)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low - Do not invalidate the alias cache immediately before every read

Every public operation clears the current alias cache key and then performs its only getAliases call, so the entry written by one operation is deleted before the next operation can reuse it. In the scheduler's repeated Status path this leaves DNS API traffic unchanged while adding ageing-cache clear/output locking and filesystem churn, defeating the cache integration and its intended scalability benefit. Invalidate after Start/Stop mutations, and only bypass the cache for explicitly fresh, non-scheduler status requests.

Show fix

Remove the unconditional pre-read cacheClear calls from Start, Stop, and Status; invalidate the relevant key after successful create/update/delete, and use the action context to force a fresh read only for explicit non-scheduler status commands. Add a test that invokes Status twice with CacheTTL enabled and verifies the second call does not invoke GetAliases.

More info - Reply on this comment to give feedback or ignore the issue.

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.

1 participant