From f21a7c939bb4ce25137b6c5ba0dbe3be9caa58a9 Mon Sep 17 00:00:00 2001 From: Ivan Savciuc Date: Fri, 10 Nov 2023 17:42:22 +0200 Subject: [PATCH] fix(service_intergration): empty user config to API convertion (#526) --- controllers/common.go | 4 ++-- controllers/serviceintegration_controller.go | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/controllers/common.go b/controllers/common.go index 9cdeb90b..da1067ad 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -176,7 +176,7 @@ func getSecretPrefix(o objWithSecret) string { // userConfigurationToAPI converts user config into a map func userConfigurationToAPI(c any, groups ...string) (map[string]any, error) { if c == nil || (reflect.ValueOf(c).Kind() == reflect.Ptr && reflect.ValueOf(c).IsNil()) { - return nil, nil + return map[string]any{}, nil } o := &sheriff.Options{ @@ -192,7 +192,7 @@ func userConfigurationToAPI(c any, groups ...string) (map[string]any, error) { if !ok { // It is an empty pointer // sheriff just returned the very same object - return nil, nil + return map[string]any{}, nil } return m, nil diff --git a/controllers/serviceintegration_controller.go b/controllers/serviceintegration_controller.go index a225954f..ae7124da 100644 --- a/controllers/serviceintegration_controller.go +++ b/controllers/serviceintegration_controller.go @@ -5,6 +5,7 @@ package controllers import ( "context" "fmt" + "slices" "strconv" "strings" @@ -77,6 +78,12 @@ func (h ServiceIntegrationHandler) createOrUpdate(ctx context.Context, avn *aive reason = "Created" } else { + // Not all service integrations have user_config available; skip the update if user_config is unavailable. + withUserConfig := []string{"clickhouse_kafka", "clickhouse_postgresql", "datadog", "kafka_connect", "kafka_logs", "kafka_mirrormaker", "logs", "metrics", "external_aws_cloudwatch_metrics"} + if !slices.Contains(withUserConfig, si.Spec.IntegrationType) { + return nil + } + userConfigMap, err := UpdateUserConfiguration(userConfig) if err != nil { return err @@ -92,7 +99,7 @@ func (h ServiceIntegrationHandler) createOrUpdate(ctx context.Context, avn *aive ) reason = "Updated" if err != nil { - if strings.Contains(err.Error(), "user config not changed") { + if strings.Contains(strings.ToLower(err.Error()), "user config not changed") { return nil } return err