CNTRLPLANE-3237: operator/encryption: add FlatEntry and FormatKMSSecretDataKey helpers for secret data keys#2269
Conversation
…or secret data keys
|
@p0lyn0mial: This pull request references CNTRLPLANE-3237 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set. DetailsIn response to this: Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
WalkthroughThis PR refactors KMS secret data key handling by extracting string formatting logic into dedicated helpers. The changes introduce ChangesKMS Secret Data Key Helpers Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 14 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (14 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
| // | ||
| // It does not validate inputs. The callers are expected to use Set, | ||
| // which rejects empty values and underscores in secretName. | ||
| func (d *KMSSecretData) FlatEntry(secretName, dataKey string) string { |
There was a problem hiding this comment.
Is there a particular reason to locate it under KMSSecretData? or just to follow the convention of FlatEntries?
There was a problem hiding this comment.
It belongs to KMSSecretData semantically.
It's the encoding convention that Set, SetFromRawKey, and FlatEntries all revolve around.
Keeping it on the type makes it discoverable alongside those methods.
Does it make sense ?
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/operator/encryption/encryptiondata/secret.go (1)
213-214: 💤 Low valueConsider using
+concatenation for consistency and performance.Using
fmt.Sprintffor simple string concatenation is slightly less efficient than the+operator. TheFlatEntryhelper intypes.go(line 136) uses+for similar concatenation, so using+here would maintain consistency.♻️ Proposed refactor
func FormatKMSSecretDataKey(rawKey, keyID string) string { - return fmt.Sprintf("%s%s-%s", encryptionConfigSecretDataPrefix, rawKey, keyID) + return encryptionConfigSecretDataPrefix + rawKey + "-" + keyID }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/operator/encryption/encryptiondata/secret.go` around lines 213 - 214, The function FormatKMSSecretDataKey currently builds the key string with fmt.Sprintf which is unnecessary for simple concatenation; replace the fmt.Sprintf usage with direct string concatenation using the + operator (use encryptionConfigSecretDataPrefix + rawKey + "-" + keyID) in FormatKMSSecretDataKey so it matches the FlatEntry helper's style and avoids fmt import/overhead.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/operator/encryption/encryptiondata/secret.go`:
- Around line 213-214: The function FormatKMSSecretDataKey currently builds the
key string with fmt.Sprintf which is unnecessary for simple concatenation;
replace the fmt.Sprintf usage with direct string concatenation using the +
operator (use encryptionConfigSecretDataPrefix + rawKey + "-" + keyID) in
FormatKMSSecretDataKey so it matches the FlatEntry helper's style and avoids fmt
import/overhead.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: bd8e4c72-9b03-429f-8592-ed7843278ae6
📒 Files selected for processing (3)
pkg/operator/encryption/encryptiondata/secret.gopkg/operator/encryption/encryptiondata/secret_test.gopkg/operator/encryption/state/types.go
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ardaguclu, p0lyn0mial The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
@p0lyn0mial: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
Summary by CodeRabbit
Refactor
Tests