Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Adelina Simion <[email protected]>
  • Loading branch information
caroldelwing and addetz authored Oct 30, 2024
1 parent 5b16fd7 commit 167608b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
4 changes: 2 additions & 2 deletions scripts/cluster-scanner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The **Cluster Scanner** tool uses the Palette Go SDK to scan your Palette enviro

## Prerequisites

- Go version 1.22.5 or later
- Go version 1.22 or later
- Git
- The `palette-samples` repository available locally
- A Palette acount
Expand Down Expand Up @@ -39,7 +39,7 @@ The **Cluster Scanner** tool uses the Palette Go SDK to scan your Palette enviro
5. Issue the command below to download the required Palette SDK modules.

```shell
go get
go get ./...
```

6. Execute the `cluster-scanner` application.
Expand Down
18 changes: 9 additions & 9 deletions scripts/cluster-scanner/internal/format_age.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ import (

// Format the cluster age using weeks, days, and hours
func FormatAge (clusterAge time.Duration) (int, int, int) {
const hoursPerWeek = 168
weeks := int(clusterAge.Hours() / hoursPerWeek)
remainingHours := int(clusterAge.Hours() - float64((weeks * hoursPerWeek)))
days := int(remainingHours / 24)
hours := int(remainingHours % 24)
const hoursPerWeek int = 168
weeks := int(clusterAge.Hours()) / hoursPerWeek
remainingHours := int(clusterAge.Hours()) - weeks * hoursPerWeek
days := remainingHours / 24
hours := remainingHours % 24
return weeks, days, hours
}

// Return the cluster age as a formatted string
func PrintFormattedAge (clusterAge time.Duration) (string) {
weeks, days, hours := FormatAge(clusterAge)
formattedString := ""
var formattedString string
if weeks > 0 {
formattedString += fmt.Sprint(weeks) + " weeks "
formattedString = fmt.Sprintf("%d weeks ", weeks)
}
if days > 0 {
formattedString += fmt.Sprint(days) + " days "
formattedString = fmt.Sprintf("%s %d days ", formattedString, days)
}
if hours > 0 {
formattedString += fmt.Sprint(hours) + " hours"
formattedString = fmt.Sprintf("%s %d hours", formattedString, hours)
}
return formattedString
}
3 changes: 1 addition & 2 deletions scripts/cluster-scanner/internal/search_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
func SearchClusters (paletteClient *client.V1Client, logger *slog.Logger) ([]*models.V1SpectroClusterSummary, error) {
// Search for clusters
logger.Info("Searching for clusters...")
clusters, err := paletteClient.SearchClusterSummaries(&models.V1SearchFilterSpec{}, []*models.V1SearchFilterSortSpec{})
return paletteClient.SearchClusterSummaries(&models.V1SearchFilterSpec{}, []*models.V1SearchFilterSortSpec{})

return clusters, err
}
10 changes: 4 additions & 6 deletions scripts/cluster-scanner/internal/search_old_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ import (
"github.com/spectrocloud/palette-sdk-go/api/models"
)

func SearchOldClusters (clusters []*models.V1SpectroClusterSummary, logger *slog.Logger) bool {
func SearchOldClusters (clusters []*models.V1SpectroClusterSummary, logger *slog.Logger) (bool, string) {
// Variable to keep track of any found clusters older than 24h
foundOldCluster := false

// List the clusters that are running for more than 24h
for _, cluster := range clusters {
creationTime := cluster.Metadata.CreationTimestamp
timeValue := time.Time(creationTime)
timeNow := time.Now()
clusterAge := timeNow.Sub(timeValue)
timeValue := time.Time(cluster.Metadata.CreationTimestamp)
clusterAge := time.Now().Sub(timeValue)

if clusterAge.Hours() >= 24 {
foundOldCluster = true
Expand All @@ -26,5 +24,5 @@ func SearchOldClusters (clusters []*models.V1SpectroClusterSummary, logger *slog
}
}

return foundOldCluster
return foundOldCluster, message
}

0 comments on commit 167608b

Please sign in to comment.