-
Notifications
You must be signed in to change notification settings - Fork 35
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
removed names.NewRandomK8() from the project completely #580
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request modifies the job name generation process in the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (3)
pkg/traefik/traefik.go (2)
204-204
: Improve middleware naming to reflect its purposeThe current middleware naming lacks context about its purpose and association with the service. This could make troubleshooting more difficult.
Consider this pattern:
-middlewareName := fmt.Sprintf("middleware-%d", time.Now().UnixNano()) +middlewareName := fmt.Sprintf("%s-strip-prefix-%s", serviceName, uuid.New().String()[:8])This approach:
- Includes the service name for clear association
- Describes the middleware's purpose (strip-prefix)
- Uses a shortened UUID for uniqueness
295-295
: Improve ingress route naming to reflect its routing purposeThe current ingress route naming lacks context about the service and path it's routing to. This could make maintenance and debugging more challenging.
Consider this pattern:
-ingressRouteName := fmt.Sprintf("ing-route-%d", time.Now().UnixNano()) +ingressRouteName := fmt.Sprintf("%s-%s-route-%s", serviceName, prefix, uuid.New().String()[:8])This approach:
- Includes both service name and prefix for clear identification
- Makes it easier to correlate routes with services
- Uses a shortened UUID for uniqueness
pkg/instance/storage.go (1)
379-379
: LGTM! Consider extracting the temporary name format to a constant.The timestamp-based naming provides sufficient uniqueness for temporary instances and aligns with the PR objective of removing random name generation. The implementation is clean and the temporary instance is properly cleaned up.
Consider extracting the format to improve readability:
+const tmpInstanceNameFormat = "tmp-%d" - tmpName := fmt.Sprintf("tmp-%d", time.Now().UnixNano()) + tmpName := fmt.Sprintf(tmpInstanceNameFormat, time.Now().UnixNano())
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
pkg/builder/kaniko/kaniko.go
(2 hunks)pkg/instance/storage.go
(2 hunks)pkg/names/names.go
(0 hunks)pkg/traefik/traefik.go
(4 hunks)
💤 Files with no reviewable changes (1)
- pkg/names/names.go
🔇 Additional comments (4)
pkg/builder/kaniko/kaniko.go (2)
9-9
: LGTM: Clean import addition
The addition of the time package import is appropriate for the new timestamp-based naming implementation.
136-136
: LGTM with verification needed
The timestamp-based job naming is a good replacement for the random naming, providing both uniqueness and chronological ordering. However, let's verify a few aspects:
✅ Verification successful
Let me gather more information about the kanikoJobNamePrefix
constant and any test files that might be using it.
Job name generation change is safe to proceed
The verification shows:
- The job name format is used consistently, only appearing in the target file
- The prefix "kaniko-build-job" combined with timestamp results in names well within K8s limit (21 chars vs 253 max)
- No test dependencies were found that could be impacted by this change
- The chronological ordering and nanosecond precision ensure uniqueness
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify job name format and usage in tests
# Check if the job name format is used consistently across the codebase
rg "fmt\.Sprintf\(.*%s.*%d.*kanikoJobNamePrefix"
# Check for any test files that might be affected by this change
rg -t go "Test.*kaniko" -l
# Verify maximum length of generated job name (k8s has a 253 char limit)
echo "Example job name length:"
LENGTH=$(echo "${kanikoJobNamePrefix}-$(date +%s%N)" | wc -c)
echo "Current timestamp-based name length: $LENGTH chars (max allowed: 253)"
Length of output: 448
Script:
#!/bin/bash
# Check the definition of kanikoJobNamePrefix
rg "kanikoJobNamePrefix.*=" -A 1
# Look for any test files that might be using kaniko job names
rg -t go "kaniko.*job.*name" -B 2 -A 2
# Check if there are any existing tests specifically for job name generation
ast-grep --pattern 'func Test$_($_) {
$$$
job$_Name := $_
$$$
}'
Length of output: 249
pkg/traefik/traefik.go (2)
Line range hint 328-332
: LGTM: Error handling follows best practices
The error handling is well-implemented with proper error wrapping and specific error types.
Line range hint 1-359
: Verify complete removal of names.NewRandomK8()
Let's verify that the names package has been completely removed from the codebase.
✅ Verification successful
names.NewRandomK8()
has been successfully removed
The verification results show no traces of the names
package or NewRandomK8
function in the codebase:
- No imports containing "names"
- No usage of "NewRandomK8"
- No files in "pkg/names" directory
The code now uses timestamp-based naming for resources (e.g., fmt.Sprintf("traefik-service-account-%d", time.Now().UnixNano())
), confirming the complete migration away from the old naming function.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify complete removal of names.NewRandomK8()
# Check for any remaining imports of the names package
echo "Checking for remaining imports of names package..."
rg -l "\".*names\""
# Check for any remaining uses of NewRandomK8
echo "Checking for remaining uses of NewRandomK8..."
rg -l "NewRandomK8"
# Check for any remaining files in the names package
echo "Checking for remaining files in names package..."
fd -t f . "pkg/names"
Length of output: 477
if err != nil { | ||
return nil, ErrGeneratingUUID.Wrap(err) | ||
} | ||
jobName := fmt.Sprintf("%s-%d", kanikoJobNamePrefix, time.Now().UnixNano()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still random from the perspective that the user is not defining the name.
The intention behind the issue is that all names should be explicitly set by the user so that they have knowledge of them in order to reference and update things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting a PR!
The intention of the issue was to replace the NewRandomK8
function with the user passing in the name as an argument.
So for every function that had the the NewRandomK8
function being called, you have to add the name as an input and propagate that up through the call stack.
closes #573
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Chores