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

docs: cluster scanner first commit #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

caroldelwing
Copy link

Describe the Change

This PR adds a tool that uses the Palette Go SDK to find clusters running for more than 24 hours.

Checklist

  • README updated?

  • Content added contains comments that explain the purpose of the script and usage.

@caroldelwing caroldelwing requested a review from a team as a code owner October 29, 2024 14:11
Copy link

@addetz addetz left a comment

Choose a reason for hiding this comment

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

Left you comments around style and organization, but I'm so impressed with your Go knowledge. Let me know if you want to chat about anything ❤️

scripts/cluster-scanner/README.md Outdated Show resolved Hide resolved
scripts/cluster-scanner/README.md Outdated Show resolved Hide resolved
scripts/cluster-scanner/README.md Outdated Show resolved Hide resolved
scripts/cluster-scanner/internal/format_age.go Outdated Show resolved Hide resolved
scripts/cluster-scanner/internal/format_age.go Outdated Show resolved Hide resolved
scripts/cluster-scanner/internal/search_old_clusters.go Outdated Show resolved Hide resolved
scripts/cluster-scanner/internal/search_old_clusters.go Outdated Show resolved Hide resolved
scripts/cluster-scanner/internal/search_old_clusters.go Outdated Show resolved Hide resolved
scripts/cluster-scanner/main.go Outdated Show resolved Hide resolved
scripts/cluster-scanner/internal/search_clusters.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@karl-cardenas-coding karl-cardenas-coding left a comment

Choose a reason for hiding this comment

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

Great work here @caroldelwing

if err != nil {
return nil, err
}
message := fmt.Sprintf("The %s cluster named %s has been running for %s. Are you sure you need this cluster?", cluster.SpecSummary.CloudConfig.CloudType, cluster.Metadata.Name, *age)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Food for thought. Say you have lots of clusters that are past 24 hrs in age. Do you want the output to include the "Are you sure you need this cluster?" in every line?

Comment on lines +19 to +27
weeks := hoursAge / hoursPerWeek
remainingHours := hoursAge - weeks*hoursPerWeek
days := remainingHours / 24
hours := remainingHours % 24
return &FormattedAge{
Days: days,
Weeks: weeks,
Hours: hours,
}, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Clever 🤓

found := false
for _, want := range value.output {
if got == want {
found = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could make the argument the assignment here plays no purpose. The reason I say that is because you immediately return, so nothing ever uses it if it's ever true.

Suggested change
found = true
found = true

// Iterate through the clusters to find those running for more than 24 hours
for _, cluster := range clusters {
timeValue := time.Time(cluster.Metadata.CreationTimestamp)
clusterAge := time.Now().Sub(timeValue)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is 100% valid - but if you want to be hip ✨, then you can use the new function released recently time.Since(t)

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.

3 participants