Skip to content

Commit

Permalink
fix(Slack): Fixed slack error messages when no scaling up and down ar…
Browse files Browse the repository at this point in the history
…e posible
  • Loading branch information
dfradehubs committed Nov 6, 2024
1 parent 4643fa2 commit acee7bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func RunCommand(cmd *cobra.Command, args []string) {
continue
}
// Notify via Slack that a node has been added
if ctx.Config.Notifications.Slack.WebhookURL != "" {
if ctx.Config.Notifications.Slack.WebhookURL != "" && currentSize != -1 {
message := fmt.Sprintf("Added new node to MIG %s. Current size is %d nodes and the maximum nodes to create are %d", ctx.Config.Infrastructure.GCP.MIGName, currentSize, maxSize)
err = slack.NotifySlack(message, ctx.Config.Notifications.Slack.WebhookURL)
if err != nil {
Expand Down Expand Up @@ -161,7 +161,7 @@ func RunCommand(cmd *cobra.Command, args []string) {
continue
}
// Notify via Slack that a node has been removed
if ctx.Config.Notifications.Slack.WebhookURL != "" {
if ctx.Config.Notifications.Slack.WebhookURL != "" && nodeRemoved != "" {
message := fmt.Sprintf("Removed node %s from MIG %s. Current size is %d nodes and the minimum nodes to exist are %d", nodeRemoved, ctx.Config.Infrastructure.GCP.MIGName, currentSize, minSize)
err = slack.NotifySlack(message, ctx.Config.Notifications.Slack.WebhookURL)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions internal/google/mig.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func AddNodeToMIG(ctx *v1alpha1.Context) (int32, int32, error) {

// Check if the MIG has reached its maximum size
if targetSize >= maxSize {
return 0, 0, fmt.Errorf("MIG has reached its maximum size (%d/%d), no further scaling is possible", targetSize, maxSize)
log.Printf("MIG has reached its maximum size (%d/%d), no further scaling is possible", targetSize, maxSize)
return -1, -1, nil
}

// Create a request to resize the MIG by increasing the target size by 1
Expand Down Expand Up @@ -88,7 +89,8 @@ func RemoveNodeFromMIG(ctx *v1alpha1.Context) (int32, int32, string, error) {

// Check if the MIG has reached its minimum size
if targetSize <= minSize {
return 0, 0, "", fmt.Errorf("MIG has reached its minimum size (%d/%d), no further scaling down is possible", targetSize, minSize)
log.Printf("MIG has reached its minimum size (%d/%d), no further scaling down is possible", targetSize, minSize)
return -1, -1, "", nil
}

// Get a random instance from the MIG to remove
Expand Down

0 comments on commit acee7bd

Please sign in to comment.