From e9eeba0f6b77c91a90c4e5be7036e75dc560918d Mon Sep 17 00:00:00 2001 From: dfradehubs Date: Wed, 6 Nov 2024 14:33:38 +0100 Subject: [PATCH] fix(Hotfix): Fixed bug when no settings was in exclude directive --- internal/elasticsearch/elasticsearch.go | 31 +++++++++++++++++++++---- internal/google/mig.go | 3 ++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/internal/elasticsearch/elasticsearch.go b/internal/elasticsearch/elasticsearch.go index 69b4192..eb4b0ae 100644 --- a/internal/elasticsearch/elasticsearch.go +++ b/internal/elasticsearch/elasticsearch.go @@ -80,9 +80,19 @@ func updateClusterSettings(ctx *v1alpha1.Context, es *elasticsearch.Client, node } // Check current exclude IPs - - currentExcludes, ok := currentSettings.Persistent["cluster"].(map[string]interface{})["routing"].(map[string]interface{})["allocation"].(map[string]interface{})["exclude"].(map[string]interface{})["_name"].(string) - + currentExcludes := "" + ok := true + if cluster, ok := currentSettings.Persistent["cluster"].(map[string]interface{}); ok { + if routing, ok := cluster["routing"].(map[string]interface{}); ok { + if allocation, ok := routing["allocation"].(map[string]interface{}); ok { + if exclude, ok := allocation["exclude"].(map[string]interface{}); ok { + if name, ok := exclude["_name"].(string); ok { + currentExcludes = name + } + } + } + } + } if ctx.Config.Autoscaler.DebugMode { log.Printf("Debug mode enabled. Current nodes in exclude settings elasticsearch: %s", string(currentExcludes)) } @@ -244,8 +254,19 @@ func ClearElasticsearchClusterSettings(ctx *v1alpha1.Context, nodeName string) e } // Get current excluded Names - currentExcludes, ok := currentSettings.Persistent["cluster"].(map[string]interface{})["routing"].(map[string]interface{})["allocation"].(map[string]interface{})["exclude"].(map[string]interface{})["_name"].(string) - + currentExcludes := "" + ok := true + if cluster, ok := currentSettings.Persistent["cluster"].(map[string]interface{}); ok { + if routing, ok := cluster["routing"].(map[string]interface{}); ok { + if allocation, ok := routing["allocation"].(map[string]interface{}); ok { + if exclude, ok := allocation["exclude"].(map[string]interface{}); ok { + if name, ok := exclude["_name"].(string); ok { + currentExcludes = name + } + } + } + } + } if ctx.Config.Autoscaler.DebugMode { log.Printf("Debug mode enabled. Current nodes in exclude settings elasticsearch: %s", string(currentExcludes)) } diff --git a/internal/google/mig.go b/internal/google/mig.go index 1440bea..e1b49ab 100644 --- a/internal/google/mig.go +++ b/internal/google/mig.go @@ -136,8 +136,9 @@ func RemoveNodeFromMIG(ctx *v1alpha1.Context) (int32, int32, string, error) { // Wait 90 seconds until instance is fully deleted // Google Cloud has a deletion timeout of 90 seconds max if !ctx.Config.Autoscaler.DebugMode { - log.Printf("Debug mode enabled. Skipping 90 seconds timeout until instance deletion") time.Sleep(90 * time.Second) + } else { + log.Printf("Debug mode enabled. Skipping 90 seconds timeout until instance deletion") } // Chech if elasticsearch is defined in the target