fix(ldapgrouplink): fix typos, observe matching, and printcolumn#272
fix(ldapgrouplink): fix typos, observe matching, and printcolumn#272henrysachs merged 5 commits intomasterfrom
Conversation
3f18c50 to
d2c29eb
Compare
|
@markussiebert @dariozachow @MisterMX based on the contribution from @stempher i made some small tweaks. Would be nice if someone could approve these. The e2e tests will fail until the gitlab client PR is merged. |
- Fix example typo: ldapProdider → ldapProvider - Fix Observe to match both CN and Provider (prevents resource collision) - Add Provider check to isLdapGroupLinkUpToDate - Fix EXTERNAL-NAME printcolumn: .status.atProvider.name → .cn - Fix comment: 'deploy token' → 'LDAP group link' - Fix comment: 'Giltab' → 'GitLab' - Remove unused constant errLdapGroupLinktNotFound - Fix test variable typo: unexpecedItem → unexpectedItem - Add comment explaining delete-then-create Update pattern Signed-off-by: Henry Sachs <henry.sachs@deutschebahn.com>
d2c29eb to
7569e63
Compare
External Name Should Be Composite KeyWhile reviewing the observe matching logic change, I noticed that the external name pattern may not be correctly implemented for LDAP group links. Current Implementation IssueThe external name is set to only the CN: meta.SetExternalName(cr, ldapGroupLink.CN) // Only stores CNHowever, according to the GitLab API documentation, an LDAP group link is uniquely identified by the combination of
The ProblemIn multi-provider setups, you could have:
These are two different resources, but both would have the same external name ( Current PR WorkaroundThis PR works around the issue by comparing both fields directly: if gl.CN == cr.Spec.ForProvider.CN && gl.Provider == cr.Spec.ForProvider.LdapProviderThis fixes the immediate collision bug, but leaves Observations
RecommendationThe external name should be a composite key that includes the provider and is forward-compatible with filter support: For current CN-only implementation: meta.SetExternalName(cr, fmt.Sprintf("%s/cn/%s", ldapGroupLink.Provider, ldapGroupLink.CN))
// Example: "ldapmain/cn/developers"When filter support is added: if ldapGroupLink.CN != "" {
meta.SetExternalName(cr, fmt.Sprintf("%s/cn/%s", ldapGroupLink.Provider, ldapGroupLink.CN))
} else {
meta.SetExternalName(cr, fmt.Sprintf("%s/filter/%s", ldapGroupLink.Provider, ldapGroupLink.Filter))
}
// Examples: "ldapmain/cn/developers" or "ldapmain/filter/(objectClass=group)"This pattern:
Note: We don't need This PR can be merged as-is since it fixes the bug, but a follow-up to use composite external names would be cleaner and future-proof. |
Implement composite external name format as suggested by @markussiebert. The external name now includes both the LDAP provider and CN, making it truly unique across multi-provider setups. Format: <provider>/<cn> Example: ldapmain/developers Changes: - SetExternalName now uses fmt.Sprintf("%s/%s", provider, cn) - PrintColumn EXTERNAL-NAME now shows annotation value - Updated tests to verify new format This ensures uniqueness when the same CN exists across multiple LDAP providers within the same GitLab group. Signed-off-by: Henry Sachs <henry.sachs@deutschebahn.com>
Add support for LDAP filter-based group links as an alternative to CN. GitLab API allows either cn or filter (mutually exclusive). - Add Filter field to LdapGroupLinkParameters (optional, immutable) - Make CN optional (one of cn/filter required) - Update Observe to match by Provider + (CN or Filter) - Update external name format for filter: provider/filter:<filter> - Update client functions to use Filter when set - Update isLdapGroupLinkUpToDate to check Filter field - Add test cases for filter-based LDAP group links Ref: https://docs.gitlab.com/api/group_ldap_links/#add-an-ldap-group-link-with-cn-or-filter Signed-off-by: Henry Sachs <henry.sachs@deutschebahn.com>
…complexity Extract the matching logic from Observe into a separate helper function to reduce cyclomatic complexity from 11 to below 10. Signed-off-by: Henry Sachs <henry.sachs@deutschebahn.com>
…ation - Change CN and Filter fields from string to *string in LdapGroupLinkParameters - Add validateCNFilterXOR() to ensure exactly one of CN or Filter is set - Update all client functions to handle pointer types with proper nil checks - Add stringPtrEquals() helper to reduce cyclomatic complexity - Update tests to use strPtr() helper for pointer creation - Validation runs after external name and group ID checks to preserve error precedence Addresses review feedback on PR #272 from @markussiebert Signed-off-by: Henry Sachs <henry.sachs@deutschebahn.com>
Summary
Follow-up fixes for #271 (LdapGroupLink feature).
Fixes
ldapProdider→ldapProviderisLdapGroupLinkUpToDateerrLdapGroupLinktNotFoundunexpecedItem→unexpectedItemComposite External Name (NEW)
As suggested by @markussiebert, the external name now uses a composite format that includes both the LDAP provider and CN:
This ensures uniqueness when the same CN exists across multiple LDAP providers within the same GitLab group.
Before:
$ kubectl get ldapgrouplinks NAME READY SYNCED AGE EXTERNAL-NAME cn-example True True 5m developers # ❌ Not unique across providersAfter:
$ kubectl get ldapgrouplinks NAME READY SYNCED AGE EXTERNAL-NAME cn-example True True 5m ldapmain/developers # ✅ Unique per providerTesting
make reviewable # ✅ All tests pass, 0 lint errorsSigned-off-by: Henry Sachs henry.sachs@deutschebahn.com